Flow123d  release_3.0.0-973-g92f55e826
sorption_base.hh
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_base.hh
15  * @brief Class SorptionBase is abstract class representing model of sorption in transport.
16  *
17  * The sorption is described by several types of isotherms - linear, Freundlich or Langmuir.
18  * Limited solubility can be considered.
19  *
20  * Interpolation tables are used to speed up evaluation of isotherms.
21  *
22  */
23 
24 #ifndef SORPTION_BASE_H
25 #define SORPTION_BASE_H
26 
27 
28 #include <memory> // for shared_ptr
29 #include <string> // for string
30 #include <vector>
31 #include "reaction/reaction_term.hh" // for ReactionTerm
32 #include "fields/field.hh" // for Field
33 #include "fields/field_values.hh" // for FieldValue<>::Scalar, FieldVa...
34 #include "fields/field_set.hh"
35 #include "fields/multi_field.hh"
36 #include "la/vector_mpi.hh"
38 #include "input/input_exception.hh" // for DECLARE_INPUT_EXCEPTION, Exce...
39 #include "input/type_base.hh" // for Array
40 #include "input/type_generic.hh" // for Instance
41 #include "petscvec.h" // for Vec, VecScatter, _p_VecScatter
42 //
43 #include "system/exceptions.hh" // for operator<<, ExcStream, EI
44 
45 class Isotherm;
46 class Mesh;
47 namespace Input {
48  class Record;
49  namespace Type {
50  class Record;
51  class Selection;
52  }
53 }
54 template <int spacedim> class ElementAccessor;
55 
56 
57 
58 
60 {
61 public:
62  TYPEDEF_ERR_INFO( EI_ArrayName, std::string);
63  DECLARE_INPUT_EXCEPTION( ExcSubstanceCountMatch, << "The size of the input array " << EI_ArrayName::qval
64  << " does not match the number of substances.");
65 
66  /**
67  * Static variable for new input data types input
68  */
69  static const Input::Type::Record & get_input_type();
70 
71  static Input::Type::Instance make_output_type(const string &equation_name, const string &output_field_name, const string &output_field_desc )
72  {
73  return EqData(output_field_name, output_field_desc).output_fields.make_output_type(equation_name, "");
74  }
75 
76  class EqData : public FieldSet
77  {
78  public:
79  /**
80  * Sorption type specifies a kind of equilibrial description of adsorption.
81  */
83 
84  /// Collect all fields
85  EqData(const string &output_field_name, const string &output_field_desc);
86 
87  MultiField<3, FieldValue<3>::Enum > sorption_type; ///< Discrete need Selection for initialization.
88  Field<3, FieldValue<3>::Scalar > rock_density; ///< Rock matrix density.
89 
90  /// Multiplication coefficients (k, omega) for all types of isotherms.
91  /** Langmuir: c_s = omega * (alpha*c_a)/(1- alpha*c_a), Linear: c_s = k*c_a */
93  /// Langmuir sorption coeficients alpha (in fraction c_s = omega * (alpha*c_a)/(1- alpha*c_a)).
95 
96  MultiField<3, FieldValue<3>::Scalar> init_conc_solid; ///< Initial sorbed concentrations.
97  Field<3, FieldValue<3>::Scalar > porosity; ///< Porosity field copied from transport.
98 
99  MultiField<3, FieldValue<3>::Scalar> conc_solid; ///< Calculated sorbed concentrations, for output only.
100 
101  /// Input data set - fields in this set are read from the input file.
103 
104  /// Fields indended for output, i.e. all input fields plus those representing solution.
106 
107  };
108 
109  /**
110  * Constructor with parameter for initialization of a new declared class member
111  */
112  SorptionBase(Mesh &init_mesh, Input::Record in_rec);
113  /**
114  * Destructor.
115  */
116  virtual ~SorptionBase(void);
117 
118  /// Prepares the object to usage.
119  /**
120  * Allocating memory, reading input, initialization of fields.
121  */
122  void initialize() override;
123 
124  /**
125  * Does first computation after initialization process.
126  * The time is set and initial condition is set and output.
127  */
128  void zero_time_step() override;
129 
130  /// Updates the solution.
131  /**
132  * Goes through local distribution of elements and calls @p compute_reaction.
133  */
134  void update_solution(void) override;
135 
136  void output_data(void) override;
137 
138  bool evaluate_time_constraint(double &time_constraint) override { return false; }
139 
140 
141 protected:
142  /**
143  * This method disables to use constructor without parameters.
144  */
145  SorptionBase();
146 
147  /** Initializes possible following reactions from input record.
148  * It should be called after setting mesh, time_governor, distribution and concentration_matrix
149  * if there are some setting methods for reactions called (they are not at the moment, so it could be part of init_from_input).
150  */
151  void make_reactions();
152 
153  /// Reads names of substances from input and creates indexing to global vector of substance.
154  /** Also creates the local vector of molar masses. */
156 
157  /// Initializes private members of sorption from the input record.
158  void initialize_from_input();
159 
160  /// Initializes field sets.
161  void initialize_fields();
162 
163  ///Reads and sets initial condition for concentration in solid.
164  void set_initial_condition();
165 
166  /**
167  * For simulation of sorption in just one element either inside of MOBILE or IMMOBILE pores.
168  */
169  double **compute_reaction(double **concentrations, int loc_el) override;
170 
171  /// Reinitializes the isotherm.
172  /**
173  * On data change the isotherm is recomputed, possibly new interpolation table is made.
174  * NOTE: Be sure to update common element data (porosity, rock density etc.)
175  * by @p compute_common_ele_data(), before calling reinitialization!
176  */
177  void isotherm_reinit(unsigned int i_subst, const ElementAccessor<3> &elm);
178 
179  /// Calls @p isotherm_reinit for all isotherms.
180  void isotherm_reinit_all(const ElementAccessor<3> &elm);
181 
182  /**
183  * Creates interpolation table for isotherms.
184  */
185  void make_tables(void);
186 
187  /// Computes maximal aqueous concentration at the current step.
188  void update_max_conc();
189 
190  /// Sets max conc to zeros on all regins.
191  void clear_max_conc();
192 
193  /// Pointer to equation data. The object is constructed in descendants.
195 
196  /**
197  * Temporary nr_of_points can be computed using step_length. Should be |nr_of_region x nr_of_substances| matrix later.
198  */
200  /**
201  * Density of the solvent.
202  * TODO: Could be done region dependent, easily.
203  */
205  /**
206  * Critical concentrations of species dissolved in water.
207  */
209  /**
210  * Concentration table limits of species dissolved in water.
211  */
213  /**
214  * Maximum concentration per region.
215  * It is used for optimization of interpolation table.
216  */
218  /**
219  * Three dimensional array contains intersections between isotherms and mass balance lines.
220  * It describes behaviour of sorbents in mobile pores of various rock matrix enviroments.
221  * Up to |nr_of_region x nr_of_substances x n_points| doubles. Because of equidistant step
222  * lenght in cocidered system of coordinates, just function values are stored.
223  */
225 
226  unsigned int n_substances_; //< number of substances that take part in the sorption mode
227 
228  /// Mapping from local indexing of substances to global.
230 
231  /**
232  * Array for storage infos about sorbed species concentrations.
233  */
234  double** conc_solid;
235 
236  /**
237  * Reaction model that follows the sorption.
238  */
239  std::shared_ptr<ReactionTerm> reaction_liquid;
240  std::shared_ptr<ReactionTerm> reaction_solid;
241 
242  ///@name members used in output routines
243  //@{
244  std::vector<VectorMPI> conc_solid_out; ///< sorbed concentration array output (gathered - sequential)
245  //@}
246 
247  // Temporary objects holding pointers to appropriate FieldFE
248  // TODO remove after final fix of equations
249  /// Fields correspond with \p conc_solid_out.
251 
252  /** Structure for data respectful to element, but indepedent of actual isotherm.
253  * Reads mobile/immobile porosity, rock density and then computes concentration scaling parameters.
254  * Is kind of optimization, so that these data are computed only when necessary.
255  */
257  double scale_aqua;
258  double scale_sorbed;
260  } common_ele_data;
261 
262  /** Computes @p CommonElementData.
263  * Is pure virtual, implemented differently for simple/mobile/immobile sorption class.
264  */
265  virtual void compute_common_ele_data(const ElementAccessor<3> &elem) = 0;
266 };
267 
268 #endif //SORPTION_BASE_H
SorptionBase::table_limit_
std::vector< double > table_limit_
Definition: sorption_base.hh:212
SorptionBase::get_input_type
static const Input::Type::Record & get_input_type()
Definition: sorption_base.cc:54
SorptionBase::data_
EqData * data_
Pointer to equation data. The object is constructed in descendants.
Definition: sorption_base.hh:194
SorptionBase::reaction_liquid
std::shared_ptr< ReactionTerm > reaction_liquid
Definition: sorption_base.hh:239
SorptionBase::initialize_substance_ids
void initialize_substance_ids()
Reads names of substances from input and creates indexing to global vector of substance.
Definition: sorption_base.cc:229
SorptionBase::reaction_solid
std::shared_ptr< ReactionTerm > reaction_solid
Definition: sorption_base.hh:240
vector_mpi.hh
SorptionBase::DECLARE_INPUT_EXCEPTION
DECLARE_INPUT_EXCEPTION(ExcSubstanceCountMatch,<< "The size of the input array "<< EI_ArrayName::qval<< " does not match the number of substances.")
Input
Abstract linear system class.
Definition: balance.hh:37
SorptionBase::clear_max_conc
void clear_max_conc()
Sets max conc to zeros on all regins.
Definition: sorption_base.cc:464
SorptionBase::evaluate_time_constraint
bool evaluate_time_constraint(double &time_constraint) override
Computes a constraint for time step.
Definition: sorption_base.hh:138
SorptionBase::initialize_from_input
void initialize_from_input()
Initializes private members of sorption from the input record.
Definition: sorption_base.cc:275
SorptionBase::EqData::output_fields
EquationOutput output_fields
Fields indended for output, i.e. all input fields plus those representing solution.
Definition: sorption_base.hh:105
SorptionBase::output_field_ptr
std::vector< std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > > output_field_ptr
Fields correspond with conc_solid_out.
Definition: sorption_base.hh:250
SorptionBase::initialize_fields
void initialize_fields()
Initializes field sets.
Definition: sorption_base.cc:324
SorptionBase::n_interpolation_steps_
unsigned int n_interpolation_steps_
Definition: sorption_base.hh:199
SorptionBase::update_max_conc
void update_max_conc()
Computes maximal aqueous concentration at the current step.
Definition: sorption_base.cc:475
field_set.hh
std::vector< double >
ElementAccessor
Definition: fe_value_handler.hh:29
SorptionBase::solubility_vec_
std::vector< double > solubility_vec_
Definition: sorption_base.hh:208
SorptionBase::EqData::sorption_type
MultiField< 3, FieldValue< 3 >::Enum > sorption_type
Discrete need Selection for initialization.
Definition: sorption_base.hh:87
SorptionBase::CommonElementData::no_sorbing_surface_cond
double no_sorbing_surface_cond
Definition: sorption_base.hh:259
type_base.hh
exceptions.hh
SorptionBase::isotherm_reinit
void isotherm_reinit(unsigned int i_subst, const ElementAccessor< 3 > &elm)
Reinitializes the isotherm.
Definition: sorption_base.cc:426
SorptionBase::output_data
void output_data(void) override
Output method.
Definition: sorption_base.cc:604
SorptionBase
Definition: sorption_base.hh:59
SorptionBase::compute_common_ele_data
virtual void compute_common_ele_data(const ElementAccessor< 3 > &elem)=0
EquationOutput::make_output_type
const Input::Type::Instance & make_output_type(const string &equation_name, const string &aditional_description="")
Definition: equation_output.cc:92
SorptionBase::EqData::init_conc_solid
MultiField< 3, FieldValue< 3 >::Scalar > init_conc_solid
Initial sorbed concentrations.
Definition: sorption_base.hh:96
equation_output.hh
SorptionBase::make_reactions
void make_reactions()
Definition: sorption_base.cc:145
SorptionBase::EqData::EqData
EqData(const string &output_field_name, const string &output_field_desc)
Collect all fields.
Definition: sorption_base.cc:78
SorptionBase::EqData::rock_density
Field< 3, FieldValue< 3 >::Scalar > rock_density
Rock matrix density.
Definition: sorption_base.hh:88
SorptionBase::SorptionBase
SorptionBase()
SorptionBase::make_output_type
static Input::Type::Instance make_output_type(const string &equation_name, const string &output_field_name, const string &output_field_desc)
Definition: sorption_base.hh:71
SorptionBase::EqData
Definition: sorption_base.hh:76
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
SorptionBase::set_initial_condition
void set_initial_condition()
Reads and sets initial condition for concentration in solid.
Definition: sorption_base.cc:389
type_generic.hh
EquationOutput
Definition: equation_output.hh:40
SorptionBase::zero_time_step
void zero_time_step() override
Definition: sorption_base.cc:362
SorptionBase::EqData::get_sorption_type_selection
static const Input::Type::Selection & get_sorption_type_selection()
Definition: sorption_base.cc:40
SorptionBase::EqData::porosity
Field< 3, FieldValue< 3 >::Scalar > porosity
Porosity field copied from transport.
Definition: sorption_base.hh:97
field_values.hh
SorptionBase::CommonElementData::scale_sorbed
double scale_sorbed
Definition: sorption_base.hh:258
Input::Type::Instance
Helper class that stores data of generic types.
Definition: type_generic.hh:89
SorptionBase::~SorptionBase
virtual ~SorptionBase(void)
Definition: sorption_base.cc:133
SorptionBase::compute_reaction
double ** compute_reaction(double **concentrations, int loc_el) override
Definition: sorption_base.cc:556
input_exception.hh
FieldSet
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:71
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
SorptionBase::isotherms
std::vector< std::vector< Isotherm > > isotherms
Definition: sorption_base.hh:224
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
SorptionBase::update_solution
void update_solution(void) override
Updates the solution.
Definition: sorption_base.cc:406
SorptionBase::solvent_density_
double solvent_density_
Definition: sorption_base.hh:204
SorptionBase::substance_global_idx_
std::vector< unsigned int > substance_global_idx_
Mapping from local indexing of substances to global.
Definition: sorption_base.hh:229
SorptionBase::make_tables
void make_tables(void)
Definition: sorption_base.cc:491
Mesh
Definition: mesh.h:80
SorptionBase::TYPEDEF_ERR_INFO
TYPEDEF_ERR_INFO(EI_ArrayName, std::string)
SorptionBase::CommonElementData
Definition: sorption_base.hh:256
multi_field.hh
SorptionBase::EqData::input_data_set_
FieldSet input_data_set_
Input data set - fields in this set are read from the input file.
Definition: sorption_base.hh:102
SorptionBase::n_substances_
unsigned int n_substances_
Definition: sorption_base.hh:226
MultiField
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:85
SorptionBase::conc_solid
double ** conc_solid
Definition: sorption_base.hh:234
Isotherm
Definition: isotherm.hh:158
SorptionBase::isotherm_reinit_all
void isotherm_reinit_all(const ElementAccessor< 3 > &elm)
Calls isotherm_reinit for all isotherms.
Definition: sorption_base.cc:456
SorptionBase::max_conc
std::vector< std::vector< double > > max_conc
Definition: sorption_base.hh:217
SorptionBase::EqData::conc_solid
MultiField< 3, FieldValue< 3 >::Scalar > conc_solid
Calculated sorbed concentrations, for output only.
Definition: sorption_base.hh:99
SorptionBase::CommonElementData::scale_aqua
double scale_aqua
Definition: sorption_base.hh:257
SorptionBase::conc_solid_out
std::vector< VectorMPI > conc_solid_out
sorbed concentration array output (gathered - sequential)
Definition: sorption_base.hh:244
SorptionBase::initialize
void initialize() override
Prepares the object to usage.
Definition: sorption_base.cc:172
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:83
SorptionBase::EqData::isotherm_other
MultiField< 3, FieldValue< 3 >::Scalar > isotherm_other
Langmuir sorption coeficients alpha (in fraction c_s = omega * (alpha*c_a)/(1- alpha*c_a)).
Definition: sorption_base.hh:94
reaction_term.hh
Class ReactionTerm is an abstract class representing reaction term in transport.
ReactionTerm
Definition: reaction_term.hh:44
SorptionBase::EqData::distribution_coefficient
MultiField< 3, FieldValue< 3 >::Scalar > distribution_coefficient
Multiplication coefficients (k, omega) for all types of isotherms.
Definition: sorption_base.hh:92
field.hh
SorptionBase::common_ele_data
struct SorptionBase::CommonElementData common_ele_data