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