Flow123d  3.9.0-29681665d
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 template<unsigned int dim> class InitConditionAssemblySorp;
56 template<unsigned int dim> class ReactionAssemblySorp;
57 template< template<IntDim...> class DimAssembly> class GenericAssembly;
58 
59 
60 
61 
62 
64 {
65 public:
66  TYPEDEF_ERR_INFO( EI_ArrayName, std::string);
67  TYPEDEF_ERR_INFO( EI_Subst, unsigned int);
68  DECLARE_INPUT_EXCEPTION( ExcSubstanceCountMatch, << "The size of the input array " << EI_ArrayName::qval
69  << " does not match the number of substances.");
70  DECLARE_EXCEPTION( ExcNotPositiveScaling,
71  << "Scaling parameter in sorption is not positive. Check the input for rock density and molar mass of " << EI_Subst::val << ". substance.\n" );
72 
73  /**
74  * Static variable for new input data types input
75  */
76  static const Input::Type::Record & get_input_type();
77 
78  static Input::Type::Instance make_output_type(const string &equation_name, const string &output_field_name, const string &output_field_desc )
79  {
80  return EqFields(output_field_name, output_field_desc).output_fields.make_output_type(equation_name, "");
81  }
82 
84  {
85  public:
86  /**
87  * Sorption type specifies a kind of equilibrial description of adsorption.
88  */
90 
91  /// Collect all fields
92  EqFields(const string &output_field_name, const string &output_field_desc);
93 
94  MultiField<3, FieldValue<3>::Enum > sorption_type; ///< Discrete need Selection for initialization.
95  Field<3, FieldValue<3>::Scalar > rock_density; ///< Rock matrix density.
96 
97  /// Multiplication coefficients (k, omega) for all types of isotherms.
98  /** Langmuir: c_s = omega * (alpha*c_a)/(1- alpha*c_a), Linear: c_s = k*c_a */
100  /// Langmuir sorption coeficients alpha (in fraction c_s = omega * (alpha*c_a)/(1- alpha*c_a)).
102 
103  MultiField<3, FieldValue<3>::Scalar> init_conc_solid; ///< Initial sorbed concentrations.
104  Field<3, FieldValue<3>::Scalar > porosity; ///< Porosity field copied from transport.
105 
106  MultiField<3, FieldValue<3>::Scalar> conc_solid; ///< Calculated sorbed concentrations, for output only.
107  FieldFEScalarVec conc_solid_fe; ///< Underlaying FieldFE for each substance of conc_solid.
108 
109  /// Input data set - fields in this set are read from the input file.
111 
112  /// Fields indended for output, i.e. all input fields plus those representing solution.
114 
115  /// Instances of FieldModel used in assembly methods
119 
120  };
121 
122 
123  /// DualPorosity data
125  {
126  public:
127 
128  /// Collect all fields
129  EqData();
130 
131  /// Mapping from local indexing of substances to global.
133 
134  unsigned int n_substances_; ///< number of substances that take part in the sorption mode
135  /**
136  * Density of the solvent.
137  * TODO: Could be done region dependent, easily.
138  */
140  /**
141  * Critical concentrations of species dissolved in water.
142  */
144  /**
145  * Concentration table limits of species dissolved in water.
146  */
148  /**
149  * Maximum concentration per region.
150  * It is used for optimization of interpolation table.
151  */
153  /**
154  * Three dimensional array contains intersections between isotherms and mass balance lines.
155  * It describes behaviour of sorbents in mobile pores of various rock matrix enviroments.
156  * Up to |nr_of_region x nr_of_substances x n_points| doubles. Because of equidistant step
157  * lenght in cocidered system of coordinates, just function values are stored.
158  */
160  };
161 
162 
163  /**
164  * Constructor with parameter for initialization of a new declared class member
165  */
166  SorptionBase(Mesh &init_mesh, Input::Record in_rec);
167  /**
168  * Destructor.
169  */
170  virtual ~SorptionBase(void);
171 
172  /// Prepares the object to usage.
173  /**
174  * Allocating memory, reading input, initialization of fields.
175  */
176  void initialize() override;
177 
178  /**
179  * Does first computation after initialization process.
180  * The time is set and initial condition is set and output.
181  */
182  void zero_time_step() override;
183 
184  /// Updates the solution.
185  /**
186  * Goes through local distribution of elements and calls @p compute_reaction.
187  */
188  void update_solution(void) override;
189 
190  void output_data(void) override;
191 
192 
193 protected:
194  /**
195  * This method disables to use constructor without parameters.
196  */
197  SorptionBase();
198 
199  /** Initializes possible following reactions from input record.
200  * It should be called after setting mesh, time_governor, distribution and concentration_matrix
201  * if there are some setting methods for reactions called (they are not at the moment, so it could be part of init_from_input).
202  */
203  void make_reactions();
204 
205  /// Reads names of substances from input and creates indexing to global vector of substance.
206  /** Also creates the local vector of molar masses. */
208 
209  /// Initializes private members of sorption from the input record.
210  void initialize_from_input();
211 
212  /// Initializes field sets.
213  void initialize_fields();
214 
215  /// Compute reaction on a single element.
216  void compute_reaction(const DHCellAccessor& dh_cell) override;
217 
218 // /// Reinitializes the isotherm.
219 // /**
220 // * On data change the isotherm is recomputed, possibly new interpolation table is made.
221 // */
222 // void isotherm_reinit(unsigned int i_subst, const ElementAccessor<3> &elm);
223 //
224 // /// Calls @p isotherm_reinit for all isotherms.
225 // void isotherm_reinit_all(const ElementAccessor<3> &elm);
226 
227  /**
228  * Creates interpolation table for isotherms.
229  */
230  void make_tables(void);
231 
232  /// Computes maximal aqueous concentration at the current step.
233  void update_max_conc();
234 
235  /// Sets max conc to zeros on all regins.
236  void clear_max_conc();
237 
238  /// Initialize FieldModels, method is implemented in descendants.
239  virtual void init_field_models() = 0;
240 
241  std::shared_ptr<EqFields> eq_fields_; ///< Pointer to equation fields. The object is constructed in descendants.
242  std::shared_ptr<EqData> eq_data_; ///< Equation data
243 
244  /**
245  * Temporary nr_of_points can be computed using step_length. Should be |nr_of_region x nr_of_substances| matrix later.
246  */
248 
249  /**
250  * Reaction model that follows the sorption.
251  */
252  std::shared_ptr<ReactionTerm> reaction_liquid;
253  std::shared_ptr<ReactionTerm> reaction_solid;
254 
255  /// general assembly objects, hold assembly objects of appropriate dimension
258 
259 
260 };
261 
262 #endif //SORPTION_BASE_H
SorptionBase::EqFields::sorption_type
MultiField< 3, FieldValue< 3 >::Enum > sorption_type
Discrete need Selection for initialization.
Definition: sorption_base.hh:94
SorptionBase::get_input_type
static const Input::Type::Record & get_input_type()
Definition: sorption_base.cc:55
SorptionBase::EqFields::conc_solid_fe
FieldFEScalarVec conc_solid_fe
Underlaying FieldFE for each substance of conc_solid.
Definition: sorption_base.hh:107
SorptionBase::EqFields::no_sorbing_surface_cond
Field< 3, FieldValue< 3 >::Scalar > no_sorbing_surface_cond
Definition: sorption_base.hh:118
SorptionBase::reaction_liquid
std::shared_ptr< ReactionTerm > reaction_liquid
Definition: sorption_base.hh:252
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:238
SorptionBase::reaction_solid
std::shared_ptr< ReactionTerm > reaction_solid
Definition: sorption_base.hh:253
vector_mpi.hh
SorptionBase::EqFields::distribution_coefficient
MultiField< 3, FieldValue< 3 >::Scalar > distribution_coefficient
Multiplication coefficients (k, omega) for all types of isotherms.
Definition: sorption_base.hh:99
SorptionBase::EqData::isotherms
std::vector< std::vector< Isotherm > > isotherms
Definition: sorption_base.hh:159
SorptionBase::DECLARE_INPUT_EXCEPTION
DECLARE_INPUT_EXCEPTION(ExcSubstanceCountMatch,<< "The size of the input array "<< EI_ArrayName::qval<< " does not match the number of substances.")
ReactionTerm::EqFields::EqFields
EqFields()
Constructor.
Definition: reaction_term.hh:69
Input
Abstract linear system class.
Definition: balance.hh:40
SorptionBase::clear_max_conc
void clear_max_conc()
Sets max conc to zeros on all regins.
Definition: sorption_base.cc:466
InitConditionAssemblySorp
Definition: assembly_reaction.hh:202
SorptionBase::init_field_models
virtual void init_field_models()=0
Initialize FieldModels, method is implemented in descendants.
SorptionBase::EqData::n_substances_
unsigned int n_substances_
number of substances that take part in the sorption mode
Definition: sorption_base.hh:134
SorptionBase::initialize_from_input
void initialize_from_input()
Initializes private members of sorption from the input record.
Definition: sorption_base.cc:284
SorptionBase::eq_fields_
std::shared_ptr< EqFields > eq_fields_
Pointer to equation fields. The object is constructed in descendants.
Definition: sorption_base.hh:241
SorptionBase::initialize_fields
void initialize_fields()
Initializes field sets.
Definition: sorption_base.cc:333
SorptionBase::n_interpolation_steps_
unsigned int n_interpolation_steps_
Definition: sorption_base.hh:247
SorptionBase::update_max_conc
void update_max_conc()
Computes maximal aqueous concentration at the current step.
Definition: sorption_base.cc:477
field_set.hh
std::vector< std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > >
ElementAccessor
Definition: dh_cell_accessor.hh:32
ReactionTerm::EqFields
Reaction data.
Definition: reaction_term.hh:65
type_base.hh
SorptionBase::EqFields
Definition: sorption_base.hh:83
SorptionBase::reaction_assembly_
GenericAssembly< ReactionAssemblySorp > * reaction_assembly_
Definition: sorption_base.hh:257
exceptions.hh
SorptionBase::compute_reaction
void compute_reaction(const DHCellAccessor &dh_cell) override
Compute reaction on a single element.
Definition: sorption_base.cc:557
SorptionBase::output_data
void output_data(void) override
Output method.
Definition: sorption_base.cc:605
SorptionBase
Definition: sorption_base.hh:63
SorptionBase::EqFields::get_sorption_type_selection
static const Input::Type::Selection & get_sorption_type_selection()
Definition: sorption_base.cc:41
EquationOutput::make_output_type
const Input::Type::Instance & make_output_type(const string &equation_name, const string &aditional_description="")
Definition: equation_output.cc:109
SorptionBase::EqFields::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:101
SorptionBase::EqFields::init_conc_solid
MultiField< 3, FieldValue< 3 >::Scalar > init_conc_solid
Initial sorbed concentrations.
Definition: sorption_base.hh:103
equation_output.hh
SorptionBase::make_reactions
void make_reactions()
Definition: sorption_base.cc:165
SorptionBase::SorptionBase
SorptionBase()
SorptionBase::EqData::table_limit_
std::vector< double > table_limit_
Definition: sorption_base.hh:147
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:78
SorptionBase::EqData
DualPorosity data.
Definition: sorption_base.hh:124
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
ReactionAssemblySorp
Definition: assembly_reaction.hh:258
type_generic.hh
SorptionBase::EqData::substance_global_idx_
std::vector< unsigned int > substance_global_idx_
Mapping from local indexing of substances to global.
Definition: sorption_base.hh:132
EquationOutput
Definition: equation_output.hh:44
SorptionBase::zero_time_step
void zero_time_step() override
Definition: sorption_base.cc:369
field_values.hh
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:159
input_exception.hh
SorptionBase::EqFields::conc_solid
MultiField< 3, FieldValue< 3 >::Scalar > conc_solid
Calculated sorbed concentrations, for output only.
Definition: sorption_base.hh:106
FieldSet
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
ReactionTerm::EqData
Reaction data.
Definition: reaction_term.hh:77
SorptionBase::eq_data_
std::shared_ptr< EqData > eq_data_
Equation data.
Definition: sorption_base.hh:242
SorptionBase::EqData::solubility_vec_
std::vector< double > solubility_vec_
Definition: sorption_base.hh:143
SorptionBase::EqData::max_conc
std::vector< std::vector< double > > max_conc
Definition: sorption_base.hh:152
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:396
SorptionBase::EqFields::rock_density
Field< 3, FieldValue< 3 >::Scalar > rock_density
Rock matrix density.
Definition: sorption_base.hh:95
SorptionBase::EqFields::output_fields
EquationOutput output_fields
Fields indended for output, i.e. all input fields plus those representing solution.
Definition: sorption_base.hh:113
SorptionBase::DECLARE_EXCEPTION
DECLARE_EXCEPTION(ExcNotPositiveScaling,<< "Scaling parameter in sorption is not positive. Check the input for rock density and molar mass of "<< EI_Subst::val<< ". substance.\n")
SorptionBase::make_tables
void make_tables(void)
Definition: sorption_base.cc:493
Mesh
Definition: mesh.h:361
SorptionBase::TYPEDEF_ERR_INFO
TYPEDEF_ERR_INFO(EI_ArrayName, std::string)
multi_field.hh
DHCellAccessor
Cell accessor allow iterate over DOF handler cells.
Definition: dh_cell_accessor.hh:43
SorptionBase::EqData::EqData
EqData()
Collect all fields.
Definition: sorption_base.cc:142
MultiField
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:87
Isotherm
Definition: isotherm.hh:158
SorptionBase::EqFields::scale_aqua
Field< 3, FieldValue< 3 >::Scalar > scale_aqua
Instances of FieldModel used in assembly methods.
Definition: sorption_base.hh:116
SorptionBase::EqData::solvent_density_
double solvent_density_
Definition: sorption_base.hh:139
SorptionBase::init_condition_assembly_
GenericAssembly< InitConditionAssemblySorp > * init_condition_assembly_
general assembly objects, hold assembly objects of appropriate dimension
Definition: sorption_base.hh:256
SorptionBase::initialize
void initialize() override
Prepares the object to usage.
Definition: sorption_base.cc:192
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:91
reaction_term.hh
Class ReactionTerm is an abstract class representing reaction term in transport.
ReactionTerm
Definition: reaction_term.hh:46
SorptionBase::EqFields::porosity
Field< 3, FieldValue< 3 >::Scalar > porosity
Porosity field copied from transport.
Definition: sorption_base.hh:104
SorptionBase::EqFields::input_field_set_
FieldSet input_field_set_
Input data set - fields in this set are read from the input file.
Definition: sorption_base.hh:110
GenericAssembly
Generic class of assemblation.
Definition: generic_assembly.hh:160
SorptionBase::EqFields::scale_sorbed
Field< 3, FieldValue< 3 >::Scalar > scale_sorbed
Definition: sorption_base.hh:117
field.hh
IntDim
unsigned int IntDim
A dimension index type.
Definition: mixed.hh:19