Flow123d  release_1.8.2-1603-g0109a2b
sorption.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file sorption.cc
15  * @brief
16  */
17 
18 #include <vector>
19 #include <limits>
20 
21 #include "reaction/isotherm.hh"
22 #include "reaction/sorption.hh"
23 #include "system/sys_profiler.hh"
24 #include "mesh/accessors.hh"
25 #include "input/factory.hh"
26 
27 FLOW123D_FORCE_LINK_IN_CHILD(sorptionMobile)
28 FLOW123D_FORCE_LINK_IN_CHILD(sorptionImmobile)
30 
31 
32 /********************************* SORPTION_SIMPLE *********************************************************/
33 /********************************* *********************************************************/
34 
35 const IT::Record & SorptionSimple::get_input_type() {
36  return IT::Record("Sorption", "Sorption model in the reaction term of transport.")
39  .declare_key("output_fields", IT::Array(make_output_selection("conc_solid", "Sorption_Output")),
40  IT::Default("\"conc_solid\""), "List of fields to write to output stream.")
41  .close();
42 }
43 
45  : SorptionBase(init_mesh, in_rec)
46 {
47  data_ = new EqData("conc_solid");
48  this->eq_data_ = data_;
49  //output_selection = make_output_selection(
50  // "SorptionSimple_output_fields",
51  // "Selection of field names of Simple Sorption model available for output.");
52 }
53 
54 const int SorptionSimple::registrar =
55  Input::register_class< SorptionSimple, Mesh &, Input::Record >("Sorption") +
57 
59 {}
60 
62 {
63  START_TIMER("SorptionSimple::isotherm_reinit");
64 
65  double rock_density = data_->rock_density.value(elem.centre(),elem);
66  double por_m = data_->porosity.value(elem.centre(),elem);
67 
68  // List of types of isotherms in particular regions
69  arma::uvec adsorption_type = data_->sorption_type.value(elem.centre(),elem);
70  arma::Col<double> mult_coef_vec = data_->isotherm_mult.value(elem.centre(),elem);
71  arma::Col<double> second_coef_vec = data_->isotherm_other.value(elem.centre(),elem);
72 
73  for(unsigned int i_subst = 0; i_subst < n_substances_; i_subst++)
74  {
75  double mult_coef = mult_coef_vec[i_subst];
76  double second_coef = second_coef_vec[i_subst];
77  Isotherm & isotherm = isotherms_vec[i_subst];
78 
79  //scales are different for the case of sorption in mobile and immobile pores
80  double scale_aqua = por_m,
81  scale_sorbed = (1 - por_m) * rock_density * substances_[substance_global_idx_[i_subst]].molar_mass();
82 
83  bool limited_solubility_on = false;
84  double table_limit;
85  if (solubility_vec_[i_subst] <= 0.0) {
86  limited_solubility_on = false;
87  table_limit=table_limit_[i_subst];
88  } else {
89  limited_solubility_on = true;
90  table_limit=solubility_vec_[i_subst];
91  }
92 
93  if( (1-por_m) <= std::numeric_limits<double>::epsilon()) //means there is no sorbing surface
94  {
95  isotherm.reinit(Isotherm::none, false, solvent_density_, scale_aqua, scale_sorbed,table_limit,0,0);
96  continue;
97  }
98 
99  if ( scale_sorbed <= 0.0)
100  xprintf(UsrErr, "Scaling parameter in sorption is not positive. Check the input for rock density and molar mass of %d. substance.",i_subst);
101 
102  isotherm.reinit(Isotherm::SorptionType(adsorption_type[i_subst]), limited_solubility_on,
103  solvent_density_, scale_aqua, scale_sorbed, table_limit, mult_coef, second_coef);
104 
105  }
106 
107  END_TIMER("SorptionSimple::isotherm_reinit");
108 }
109 
110 
111 /*********************************** *********************************************************/
112 /*********************************** SORPTION_DUAL *********************************************************/
113 /*********************************** *********************************************************/
114 
116  const string &output_conc_name,
117  const string &output_selection_name)
118  : SorptionBase(init_mesh, in_rec)
119 {
120  data_ = new EqData(output_conc_name);
123  .name("porosity_immobile");
124  this->eq_data_ = data_;
125  //output_selection = make_output_selection(output_conc_name, output_selection_name);
126 }
127 
129 {}
130 
131 /********************************** *******************************************************/
132 /*********************************** SORPTION_MOBILE *******************************************************/
133 /********************************** *******************************************************/
134 
136  return IT::Record("SorptionMobile", "Sorption model in the mobile zone, following the dual porosity model.")
139  .declare_key("output_fields", IT::Array(make_output_selection("conc_solid", "SorptionMobile_Output")),
140  IT::Default("\"conc_solid\""), "List of fields to write to output stream.")
141  .close();
142 }
143 
144 
145 const int SorptionMob::registrar =
146  Input::register_class< SorptionMob, Mesh &, Input::Record >("SorptionMobile") +
148 
149 
151  : SorptionDual(init_mesh, in_rec, "conc_solid", "SorptionMobile_Output")
152 {}
153 
154 
156 {}
157 
158 /*
159 double SorptionMob::compute_sorbing_scale(double por_m, double por_imm)
160 {
161  double phi = por_m/(por_m + por_imm);
162  return phi;
163 }
164 */
165 
167 {
168  START_TIMER("SorptionMob::isotherm_reinit");
169 
170  double rock_density = data_->rock_density.value(elem.centre(),elem);
171 
172  double por_m = data_->porosity.value(elem.centre(),elem);
173  double por_imm = immob_porosity_.value(elem.centre(),elem);
174  double phi = por_m/(por_m + por_imm);
175 
176  // List of types of isotherms in particular regions
177  arma::uvec adsorption_type = data_->sorption_type.value(elem.centre(),elem);
178  arma::Col<double> mult_coef_vec = data_->isotherm_mult.value(elem.centre(),elem);
179  arma::Col<double> second_coef_vec = data_->isotherm_other.value(elem.centre(),elem);
180 
181  for(unsigned int i_subst = 0; i_subst < n_substances_; i_subst++)
182  {
183  double mult_coef = mult_coef_vec[i_subst];
184  double second_coef = second_coef_vec[i_subst];
185  Isotherm & isotherm = isotherms_vec[i_subst];
186 
187  //scales are different for the case of sorption in mobile and immobile pores
188  double scale_aqua = por_m,
189  scale_sorbed = phi * (1 - por_m - por_imm) * rock_density * substances_[substance_global_idx_[i_subst]].molar_mass();
190 
191  bool limited_solubility_on;
192  double table_limit;
193  if (solubility_vec_[i_subst] <= 0.0) {
194  limited_solubility_on = false;
195  table_limit=table_limit_[i_subst];
196 
197  } else {
198  limited_solubility_on = true;
199  table_limit=solubility_vec_[i_subst];
200  }
201 
202  if( (1-por_m-por_imm) <= std::numeric_limits<double>::epsilon()) //means there is no sorbing surface
203  {
204  isotherm.reinit(Isotherm::none, false, solvent_density_, scale_aqua, scale_sorbed,table_limit,0,0);
205  continue;
206  }
207 
208  if ( scale_sorbed <= 0.0)
209  xprintf(UsrErr, "Scaling parameter in sorption is not positive. Check the input for rock density and molar mass of %d. substance.",i_subst);
210 
211  isotherm.reinit(Isotherm::SorptionType(adsorption_type[i_subst]), limited_solubility_on,
212  solvent_density_, scale_aqua, scale_sorbed, table_limit, mult_coef, second_coef);
213 
214  }
215 
216  END_TIMER("SorptionMob::isotherm_reinit");
217 }
218 
219 
220 /*********************************** *****************************************************/
221 /*********************************** SORPTION_IMMOBILE *****************************************************/
222 /*********************************** *****************************************************/
223 
225  return IT::Record("SorptionImmobile", "Sorption model in the immobile zone, following the dual porosity model.")
228  .declare_key("output_fields", IT::Array(make_output_selection("conc_immobile_solid", "SorptionImmobile_Output")),
229  IT::Default("\"conc_immobile_solid\""), "List of fields to write to output stream.")
230  .close();
231 }
232 
233 const int SorptionImmob::registrar =
234  Input::register_class< SorptionImmob, Mesh &, Input::Record >("SorptionImmobile") +
236 
238 : SorptionDual(init_mesh, in_rec, "conc_immobile_solid", "SorptionImmobile_Output")
239 {}
240 
242 {}
243 
244 /*
245 double SorptionImmob::compute_sorbing_scale(double por_m, double por_imm)
246 {
247  double phi = por_imm / (por_m + por_imm);
248  return phi;
249 }
250 */
251 
253 {
254  START_TIMER("SorptionImmob::isotherm_reinit");
255 
256  double rock_density = data_->rock_density.value(elem.centre(),elem);
257 
258  double por_m = data_->porosity.value(elem.centre(),elem);
259  double por_imm = immob_porosity_.value(elem.centre(),elem);
260  double phi = por_m/(por_m + por_imm);
261 
262  // List of types of isotherms in particular regions
263  arma::uvec adsorption_type = data_->sorption_type.value(elem.centre(),elem);
264  arma::Col<double> mult_coef_vec = data_->isotherm_mult.value(elem.centre(),elem);
265  arma::Col<double> second_coef_vec = data_->isotherm_other.value(elem.centre(),elem);
266 
267  for(unsigned int i_subst = 0; i_subst < n_substances_; i_subst++)
268  {
269  double mult_coef = mult_coef_vec[i_subst];
270  double second_coef = second_coef_vec[i_subst];
271  Isotherm & isotherm = isotherms_vec[i_subst];
272 
273  //scales are different for the case of sorption in mobile and immobile pores
274  double scale_aqua = por_imm,
275  scale_sorbed = (1 - phi) * (1 - por_m - por_imm) * rock_density * substances_[substance_global_idx_[i_subst]].molar_mass();
276 
277  bool limited_solubility_on;
278  double table_limit;
279  if (solubility_vec_[i_subst] <= 0.0) {
280  limited_solubility_on = false;
281  table_limit=table_limit_[i_subst];
282 
283  } else {
284  limited_solubility_on = true;
285  table_limit=solubility_vec_[i_subst];
286  }
287 
288  if( (1-por_m-por_imm) <= std::numeric_limits<double>::epsilon()) //means there is no sorbing surface
289  {
290  isotherm.reinit(Isotherm::none, false, solvent_density_, scale_aqua, scale_sorbed,0,0,0);
291  continue;
292  }
293 
294  if ( scale_sorbed <= 0.0)
295  xprintf(UsrErr, "Scaling parameter in sorption is not positive. Check the input for rock density and molar mass of %d. substance.",i_subst);
296 
297  isotherm.reinit(Isotherm::SorptionType(adsorption_type[i_subst]), limited_solubility_on,
298  solvent_density_, scale_aqua, scale_sorbed, table_limit, mult_coef, second_coef);
299 
300  }
301 
302  END_TIMER("SorptionImmob::isotherm_reinit");
303 }
FieldSet * eq_data_
Definition: equation.hh:230
double solvent_density_
~SorptionDual(void)
Destructor.
Definition: sorption.cc:128
unsigned int size() const
Returns number of keys in the Record.
Definition: type_record.hh:578
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:50
static Input::Type::Abstract & get_input_type()
FieldCommon & flags_add(FieldFlag::Flags::Mask mask)
~SorptionMob(void)
Destructor.
Definition: sorption.cc:155
Abstract class of sorption model in case dual porosity is considered.
Definition: sorption.hh:65
SubstanceList substances_
Names belonging to substances.
Field< 3, FieldValue< 3 >::Scalar > rock_density
Rock matrix density.
void isotherm_reinit(std::vector< Isotherm > &isotherms_vec, const ElementAccessor< 3 > &elem) override
Reinitializes the isotherm.
Definition: sorption.cc:166
Definition: mesh.h:99
static const Input::Type::Record & get_input_type()
Definition: sorption.cc:35
std::vector< double > table_limit_
void reinit(enum SorptionType sorption_type, bool limited_solubility_on, double aqua_density, double scale_aqua, double scale_sorbed, double c_aqua_limit, double mult_coef, double second_coef)
Definition: isotherm.hh:334
Class for declaration of inputs sequences.
Definition: type_base.hh:316
std::vector< unsigned int > substance_global_idx_
Mapping from local indexing of substances to global.
virtual Record & derive_from(Abstract &parent)
Method to derive new Record from an AbstractRecord parent.
Definition: type_record.cc:193
MultiField< 3, FieldValue< 3 >::Scalar > isotherm_other
Langmuir sorption coeficients alpha (in fraction c_s = omega * (alpha*c_a)/(1- alpha*c_a)).
Field< 3, FieldValue< 3 >::Scalar > porosity
Porosity field copied from transport.
Field< 3, FieldValue< 3 >::Scalar > immob_porosity_
Definition: sorption.hh:86
static constexpr Mask input_copy
A field that is input of its equation and can not read from input, thus must be set by copy...
Definition: field_flag.hh:39
std::vector< double > solubility_vec_
Accessor to the data with type Type::Record.
Definition: accessors.hh:277
#define xprintf(...)
Definition: system.hh:87
#define START_TIMER(tag)
Starts a timer with specified tag.
static const Input::Type::Record & get_input_type()
Definition: sorption.cc:135
MultiField< 3, FieldValue< 3 >::Scalar > isotherm_mult
Multiplication coefficients (k, omega) for all types of isotherms.
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm) const
Definition: field.hh:337
Record & declare_key(const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
Declares a new key of the Record.
Definition: type_record.cc:459
const Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:271
MultiField< 3, FieldValue< 3 >::Enum > sorption_type
Discrete need Selection for initialization.
static Input::Type::Selection make_output_selection(const string &output_field_name, const string &selection_name)
SorptionType
Type of adsorption isotherm.
Definition: isotherm.hh:170
Record & copy_keys(const Record &other)
Copy keys from other record.
Definition: type_record.cc:211
Definition: system.hh:59
const double epsilon
Definition: mathfce.h:23
SorptionImmob(Mesh &init_mesh, Input::Record in_rec)
Constructor.
Definition: sorption.cc:237
static const int registrar
Registrar of class to factory.
Definition: sorption.hh:58
virtual MultiFieldValue::return_type value(const Point &p, const ElementAccessor< spacedim > &elm) const
void isotherm_reinit(std::vector< Isotherm > &isotherms, const ElementAccessor< 3 > &elm) override
Reinitializes the isotherm.
Definition: sorption.cc:61
SorptionSimple(Mesh &init_mesh, Input::Record in_rec)
Constructor.
Definition: sorption.cc:44
static const int registrar
Registrar of class to factory.
Definition: sorption.hh:144
~SorptionSimple(void)
Destructor.
Definition: sorption.cc:58
FieldCommon & name(const string &name)
Definition: field_common.hh:83
static const int registrar
Registrar of class to factory.
Definition: sorption.hh:116
#define END_TIMER(tag)
Ends a timer with specified tag.
arma::vec::fixed< spacedim > centre() const
Definition: accessors.hh:91
Simple sorption model without dual porosity.
Definition: sorption.hh:39
Record type proxy class.
Definition: type_record.hh:171
static const Input::Type::Record & get_input_type()
unsigned int n_substances_
SorptionDual(Mesh &init_mesh, Input::Record in_rec, const string &output_conc_name, const string &output_selection_name)
Constructor.
Definition: sorption.cc:115
EqData * data_
Pointer to equation data. The object is constructed in descendants.
void isotherm_reinit(std::vector< Isotherm > &isotherms_vec, const ElementAccessor< 3 > &elem) override
Reinitializes the isotherm.
Definition: sorption.cc:252
Other possible transformation of coordinates:
static const Input::Type::Record & get_input_type()
Definition: sorption.cc:224
This file contains classes representing sorption model. Sorption model can be computed both in case t...
#define FLOW123D_FORCE_LINK_IN_CHILD(x)
Definition: global_defs.h:246
SorptionMob(Mesh &init_mesh, Input::Record in_rec)
Constructor.
Definition: sorption.cc:150
~SorptionImmob(void)
Destructor.
Definition: sorption.cc:241