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