Flow123d  JS_before_hm-1002-gafa1d04
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  */
82  static const Input::Type::Selection & get_sorption_type_selection();
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  FieldFEScalarVec conc_solid_fe; ///< Underlaying FieldFE for each substance of conc_solid.
101 
102  /// Input data set - fields in this set are read from the input file.
104 
105  /// Fields indended for output, i.e. all input fields plus those representing solution.
107 
108  };
109 
110  /**
111  * Constructor with parameter for initialization of a new declared class member
112  */
113  SorptionBase(Mesh &init_mesh, Input::Record in_rec);
114  /**
115  * Destructor.
116  */
117  virtual ~SorptionBase(void);
118 
119  /// Prepares the object to usage.
120  /**
121  * Allocating memory, reading input, initialization of fields.
122  */
123  void initialize() override;
124 
125  /**
126  * Does first computation after initialization process.
127  * The time is set and initial condition is set and output.
128  */
129  void zero_time_step() override;
130 
131  /// Updates the solution.
132  /**
133  * Goes through local distribution of elements and calls @p compute_reaction.
134  */
135  void update_solution(void) override;
136 
137  void output_data(void) override;
138 
139  bool evaluate_time_constraint(FMT_UNUSED double &time_constraint) override { return false; }
140 
141 
142 protected:
143  /**
144  * This method disables to use constructor without parameters.
145  */
146  SorptionBase();
147 
148  /** Initializes possible following reactions from input record.
149  * It should be called after setting mesh, time_governor, distribution and concentration_matrix
150  * if there are some setting methods for reactions called (they are not at the moment, so it could be part of init_from_input).
151  */
152  void make_reactions();
153 
154  /// Reads names of substances from input and creates indexing to global vector of substance.
155  /** Also creates the local vector of molar masses. */
156  void initialize_substance_ids();
157 
158  /// Initializes private members of sorption from the input record.
159  void initialize_from_input();
160 
161  /// Initializes field sets.
162  void initialize_fields();
163 
164  ///Reads and sets initial condition for concentration in solid.
165  void set_initial_condition();
166 
167  /// Compute reaction on a single element.
168  void compute_reaction(const DHCellAccessor& dh_cell) override;
169 
170  /// Reinitializes the isotherm.
171  /**
172  * On data change the isotherm is recomputed, possibly new interpolation table is made.
173  * NOTE: Be sure to update common element data (porosity, rock density etc.)
174  * by @p compute_common_ele_data(), before calling reinitialization!
175  */
176  void isotherm_reinit(unsigned int i_subst, const ElementAccessor<3> &elm);
177 
178  /// Calls @p isotherm_reinit for all isotherms.
179  void isotherm_reinit_all(const ElementAccessor<3> &elm);
180 
181  /**
182  * Creates interpolation table for isotherms.
183  */
184  void make_tables(void);
185 
186  /// Computes maximal aqueous concentration at the current step.
187  void update_max_conc();
188 
189  /// Sets max conc to zeros on all regins.
190  void clear_max_conc();
191 
192  /// Pointer to equation data. The object is constructed in descendants.
194 
195  /**
196  * Temporary nr_of_points can be computed using step_length. Should be |nr_of_region x nr_of_substances| matrix later.
197  */
199  /**
200  * Density of the solvent.
201  * TODO: Could be done region dependent, easily.
202  */
204  /**
205  * Critical concentrations of species dissolved in water.
206  */
208  /**
209  * Concentration table limits of species dissolved in water.
210  */
212  /**
213  * Maximum concentration per region.
214  * It is used for optimization of interpolation table.
215  */
217  /**
218  * Three dimensional array contains intersections between isotherms and mass balance lines.
219  * It describes behaviour of sorbents in mobile pores of various rock matrix enviroments.
220  * Up to |nr_of_region x nr_of_substances x n_points| doubles. Because of equidistant step
221  * lenght in cocidered system of coordinates, just function values are stored.
222  */
224 
225  unsigned int n_substances_; //< number of substances that take part in the sorption mode
226 
227  /// Mapping from local indexing of substances to global.
229 
230  /**
231  * Reaction model that follows the sorption.
232  */
233  std::shared_ptr<ReactionTerm> reaction_liquid;
234  std::shared_ptr<ReactionTerm> reaction_solid;
235 
236 
237  /** Structure for data respectful to element, but indepedent of actual isotherm.
238  * Reads mobile/immobile porosity, rock density and then computes concentration scaling parameters.
239  * Is kind of optimization, so that these data are computed only when necessary.
240  */
242  double scale_aqua;
243  double scale_sorbed;
245  } common_ele_data;
246 
247  /** Computes @p CommonElementData.
248  * Is pure virtual, implemented differently for simple/mobile/immobile sorption class.
249  */
250  virtual void compute_common_ele_data(const ElementAccessor<3> &elem) = 0;
251 };
252 
253 #endif //SORPTION_BASE_H
std::shared_ptr< ReactionTerm > reaction_solid
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:74
MultiField< 3, FieldValue< 3 >::Scalar > conc_solid
Calculated sorbed concentrations, for output only.
double solvent_density_
std::vector< std::vector< Isotherm > > isotherms
TYPEDEF_ERR_INFO(EI_KeyName, const string)
static Input::Type::Instance make_output_type(const string &equation_name, const string &output_field_name, const string &output_field_desc)
Abstract linear system class.
Definition: balance.hh:40
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:92
Field< 3, FieldValue< 3 >::Scalar > rock_density
Rock matrix density.
Definition: mesh.h:78
Cell accessor allow iterate over DOF handler cells.
EquationOutput output_fields
Fields indended for output, i.e. all input fields plus those representing solution.
Helper class that stores data of generic types.
Definition: type_generic.hh:89
std::vector< double > table_limit_
Class ReactionTerm is an abstract class representing reaction term in transport.
std::vector< unsigned int > substance_global_idx_
Mapping from local indexing of substances to global.
MultiField< 3, FieldValue< 3 >::Scalar > isotherm_other
Langmuir sorption coeficients alpha (in fraction c_s = omega * (alpha*c_a)/(1- alpha*c_a)).
FieldFEScalarVec conc_solid_fe
Underlaying FieldFE for each substance of conc_solid.
#define FMT_UNUSED
Definition: posix.h:75
Field< 3, FieldValue< 3 >::Scalar > porosity
Porosity field copied from transport.
MultiField< 3, FieldValue< 3 >::Scalar > init_conc_solid
Initial sorbed concentrations.
std::vector< double > solubility_vec_
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
unsigned int n_interpolation_steps_
MultiField< 3, FieldValue< 3 >::Enum > sorption_type
Discrete need Selection for initialization.
bool evaluate_time_constraint(FMT_UNUSED double &time_constraint) override
Record type proxy class.
Definition: type_record.hh:182
const Input::Type::Instance & make_output_type(const string &equation_name, const string &aditional_description="")
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:87
MultiField< 3, FieldValue< 3 >::Scalar > distribution_coefficient
Multiplication coefficients (k, omega) for all types of isotherms.
unsigned int n_substances_
DECLARE_INPUT_EXCEPTION(ExcInputMessage,<< EI_Message::val)
Simple input exception that accepts just string message.
EqData * data_
Pointer to equation data. The object is constructed in descendants.
std::vector< std::vector< double > > max_conc
Template for classes storing finite set of named values.
FieldSet input_data_set_
Input data set - fields in this set are read from the input file.
std::shared_ptr< ReactionTerm > reaction_liquid