Flow123d  master-f44eb46
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  */
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
Cell accessor allow iterate over DOF handler cells.
const Input::Type::Instance & make_output_type(const string &equation_name, const string &aditional_description="")
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:92
Generic class of assemblation.
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Helper class that stores data of generic types.
Definition: type_generic.hh:89
Record type proxy class.
Definition: type_record.hh:182
Template for classes storing finite set of named values.
Definition: mesh.h:362
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:87
Reaction data.
EqFields()
Constructor.
DualPorosity data.
EqData()
Collect all fields.
std::vector< unsigned int > substance_global_idx_
Mapping from local indexing of substances to global.
std::vector< double > table_limit_
unsigned int n_substances_
number of substances that take part in the sorption mode
std::vector< std::vector< double > > max_conc
std::vector< std::vector< Isotherm > > isotherms
std::vector< double > solubility_vec_
MultiField< 3, FieldValue< 3 >::Scalar > init_conc_solid
Initial sorbed concentrations.
MultiField< 3, FieldValue< 3 >::Scalar > isotherm_other
Langmuir sorption coeficients alpha (in fraction c_s = omega * (alpha*c_a)/(1- alpha*c_a)).
FieldSet input_field_set_
Input data set - fields in this set are read from the input file.
Field< 3, FieldValue< 3 >::Scalar > scale_sorbed
FieldFEScalarVec conc_solid_fe
Underlaying FieldFE for each substance of conc_solid.
Field< 3, FieldValue< 3 >::Scalar > rock_density
Rock matrix density.
MultiField< 3, FieldValue< 3 >::Scalar > conc_solid
Calculated sorbed concentrations, for output only.
MultiField< 3, FieldValue< 3 >::Enum > sorption_type
Discrete need Selection for initialization.
Field< 3, FieldValue< 3 >::Scalar > scale_aqua
Instances of FieldModel used in assembly methods.
static const Input::Type::Selection & get_sorption_type_selection()
Field< 3, FieldValue< 3 >::Scalar > porosity
Porosity field copied from transport.
Field< 3, FieldValue< 3 >::Scalar > no_sorbing_surface_cond
MultiField< 3, FieldValue< 3 >::Scalar > distribution_coefficient
Multiplication coefficients (k, omega) for all types of isotherms.
EquationOutput output_fields
Fields indended for output, i.e. all input fields plus those representing solution.
void compute_reaction(const DHCellAccessor &dh_cell) override
Compute reaction on a single element.
void zero_time_step() override
void output_data(void) override
Output method.
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")
static const Input::Type::Record & get_input_type()
void make_reactions()
std::shared_ptr< ReactionTerm > reaction_liquid
GenericAssembly< ReactionAssemblySorp > * reaction_assembly_
void initialize() override
Prepares the object to usage.
virtual ~SorptionBase(void)
std::shared_ptr< ReactionTerm > reaction_solid
std::shared_ptr< EqData > eq_data_
Equation data.
static Input::Type::Instance make_output_type(const string &equation_name, const string &output_field_name, const string &output_field_desc)
void initialize_from_input()
Initializes private members of sorption from the input record.
unsigned int n_interpolation_steps_
void clear_max_conc()
Sets max conc to zeros on all regins.
void initialize_substance_ids()
Reads names of substances from input and creates indexing to global vector of substance.
DECLARE_INPUT_EXCEPTION(ExcSubstanceCountMatch,<< "The size of the input array "<< EI_ArrayName::qval<< " does not match the number of substances.")
GenericAssembly< InitConditionAssemblySorp > * init_condition_assembly_
general assembly objects, hold assembly objects of appropriate dimension
void update_max_conc()
Computes maximal aqueous concentration at the current step.
TYPEDEF_ERR_INFO(EI_ArrayName, std::string)
void initialize_fields()
Initializes field sets.
std::shared_ptr< EqFields > eq_fields_
Pointer to equation fields. The object is constructed in descendants.
TYPEDEF_ERR_INFO(EI_Subst, unsigned int)
virtual void init_field_models()=0
Initialize FieldModels, method is implemented in descendants.
void make_tables(void)
void update_solution(void) override
Updates the solution.
unsigned int IntDim
A dimension index type.
Definition: mixed.hh:19
Abstract linear system class.
Definition: balance.hh:40
Class ReactionTerm is an abstract class representing reaction term in transport.