Flow123d  release_3.0.0-506-g34af125
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 #include <boost/exception/info.hpp> // for operator<<, error_info::~erro...
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 "fields/vec_seq_double.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 #include "system/exceptions.hh" // for operator<<, ExcStream, EI
43 
44 class Isotherm;
45 class Mesh;
46 namespace Input {
47  class Record;
48  namespace Type {
49  class Record;
50  class Selection;
51  }
52 }
53 template <int spacedim> class ElementAccessor;
54 
55 
56 
57 
59 {
60 public:
61  TYPEDEF_ERR_INFO( EI_ArrayName, std::string);
62  DECLARE_INPUT_EXCEPTION( ExcSubstanceCountMatch, << "The size of the input array " << EI_ArrayName::qval
63  << " does not match the number of substances.");
64 
65  /**
66  * Static variable for new input data types input
67  */
68  static const Input::Type::Record & get_input_type();
69 
70  /*
71  static Input::Type::Selection make_output_selection(const string &output_field_name, const string &selection_name)
72  {
73  return EqData(output_field_name).output_fields
74  .make_output_field_selection(selection_name, "desc")
75  .close();
76  }*/
77 
78  static Input::Type::Instance make_output_type(const string &equation_name, const string &output_field_name )
79  {
80  return EqData(output_field_name).output_fields.make_output_type(equation_name, "");
81  }
82 
83  class EqData : public FieldSet
84  {
85  public:
86  /**
87  * Sorption type specifies a kind of equilibrial description of adsorption.
88  */
89  static const Input::Type::Selection & get_sorption_type_selection();
90 
91  /// Collect all fields
92  EqData(const string &output_field_name);
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 
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  };
115 
116  /**
117  * Constructor with parameter for initialization of a new declared class member
118  */
119  SorptionBase(Mesh &init_mesh, Input::Record in_rec);
120  /**
121  * Destructor.
122  */
123  virtual ~SorptionBase(void);
124 
125  /// Prepares the object to usage.
126  /**
127  * Allocating memory, reading input, initialization of fields.
128  */
129  void initialize() override;
130 
131  /**
132  * Does first computation after initialization process.
133  * The time is set and initial condition is set and output.
134  */
135  void zero_time_step() override;
136 
137  /// Updates the solution.
138  /**
139  * Goes through local distribution of elements and calls @p compute_reaction.
140  */
141  void update_solution(void) override;
142 
143  void output_data(void) override;
144 
145  bool evaluate_time_constraint(double &time_constraint) override { return false; }
146 
147 
148 protected:
149  /**
150  * This method disables to use constructor without parameters.
151  */
152  SorptionBase();
153 
154  /** Initializes possible following reactions from input record.
155  * It should be called after setting mesh, time_governor, distribution and concentration_matrix
156  * if there are some setting methods for reactions called (they are not at the moment, so it could be part of init_from_input).
157  */
158  void make_reactions();
159 
160  /// Reads names of substances from input and creates indexing to global vector of substance.
161  /** Also creates the local vector of molar masses. */
162  void initialize_substance_ids();
163 
164  /// Initializes private members of sorption from the input record.
165  void initialize_from_input();
166 
167  /// Initializes field sets.
168  void initialize_fields();
169 
170  ///Reads and sets initial condition for concentration in solid.
171  void set_initial_condition();
172 
173  /// Allocates petsc vectors, prepares them for output and creates vector scatter.
174  void allocate_output_mpi(void);
175 
176  /// Gathers all the parallel vectors to enable them to be output.
177  void output_vector_gather(void) override;
178 
179  /**
180  * For simulation of sorption in just one element either inside of MOBILE or IMMOBILE pores.
181  */
182  double **compute_reaction(double **concentrations, int loc_el) override;
183 
184  /// Reinitializes the isotherm.
185  /**
186  * On data change the isotherm is recomputed, possibly new interpolation table is made.
187  * NOTE: Be sure to update common element data (porosity, rock density etc.)
188  * by @p compute_common_ele_data(), before calling reinitialization!
189  */
190  void isotherm_reinit(unsigned int i_subst, const ElementAccessor<3> &elm);
191 
192  /// Calls @p isotherm_reinit for all isotherms.
193  void isotherm_reinit_all(const ElementAccessor<3> &elm);
194 
195  /**
196  * Creates interpolation table for isotherms.
197  */
198  void make_tables(void);
199 
200  /// Computes maximal aqueous concentration at the current step.
201  void update_max_conc();
202 
203  /// Sets max conc to zeros on all regins.
204  void clear_max_conc();
205 
206  /// Pointer to equation data. The object is constructed in descendants.
208 
209  /**
210  * Temporary nr_of_points can be computed using step_length. Should be |nr_of_region x nr_of_substances| matrix later.
211  */
213  /**
214  * Density of the solvent.
215  * TODO: Could be done region dependent, easily.
216  */
218  /**
219  * Critical concentrations of species dissolved in water.
220  */
222  /**
223  * Concentration table limits of species dissolved in water.
224  */
226  /**
227  * Maximum concentration per region.
228  * It is used for optimization of interpolation table.
229  */
231  /**
232  * Three dimensional array contains intersections between isotherms and mass balance lines.
233  * It describes behaviour of sorbents in mobile pores of various rock matrix enviroments.
234  * Up to |nr_of_region x nr_of_substances x n_points| doubles. Because of equidistant step
235  * lenght in cocidered system of coordinates, just function values are stored.
236  */
238 
239  unsigned int n_substances_; //< number of substances that take part in the sorption mode
240 
241  /// Mapping from local indexing of substances to global.
243 
244  /**
245  * Array for storage infos about sorbed species concentrations.
246  */
247  double** conc_solid;
248 
249  //Input::Array output_array;
250 
251  //Input::Type::Selection output_selection;
252 
253  /**
254  * Reaction model that follows the sorption.
255  */
256  std::shared_ptr<ReactionTerm> reaction_liquid;
257  std::shared_ptr<ReactionTerm> reaction_solid;
258 
259  ///@name members used in output routines
260  //@{
261  VecScatter vconc_out_scatter; ///< Output vector scatter.
262  // TODO: replace vconc_solid + conc_solid by VecSeqDouble, use the same principle as in 'conc_solid_out'
263  Vec *vconc_solid; ///< PETSC sorbed concentration vector (parallel).
264  std::vector<VectorSeqDouble> conc_solid_out; ///< sorbed concentration array output (gathered - sequential)
265  //@}
266 
267  // Temporary objects holding pointers to appropriate FieldFE
268  // TODO remove after final fix of equations
269  /// Fields correspond with \p conc_solid_out.
271 
272  /** Structure for data respectful to element, but indepedent of actual isotherm.
273  * Reads mobile/immobile porosity, rock density and then computes concentration scaling parameters.
274  * Is kind of optimization, so that these data are computed only when necessary.
275  */
277  double scale_aqua;
278  double scale_sorbed;
280  } common_ele_data;
281 
282  /** Computes @p CommonElementData.
283  * Is pure virtual, implemented differently for simple/mobile/immobile sorption class.
284  */
285  virtual void compute_common_ele_data(const ElementAccessor<3> &elem) = 0;
286 };
287 
288 #endif //SORPTION_BASE_H
std::shared_ptr< ReactionTerm > reaction_solid
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:71
MultiField< 3, FieldValue< 3 >::Scalar > conc_solid
Calculated sorbed concentrations, for output only.
std::vector< VectorSeqDouble > conc_solid_out
sorbed concentration array output (gathered - sequential)
double solvent_density_
std::vector< std::vector< Isotherm > > isotherms
TYPEDEF_ERR_INFO(EI_KeyName, const string)
Abstract linear system class.
Definition: balance.hh:35
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:83
Field< 3, FieldValue< 3 >::Scalar > rock_density
Rock matrix density.
Definition: mesh.h:80
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)).
Field< 3, FieldValue< 3 >::Scalar > porosity
Porosity field copied from transport.
Vec * vconc_solid
PETSC sorbed concentration vector (parallel).
std::vector< std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > > output_field_ptr
Fields correspond with conc_solid_out.
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:292
unsigned int n_interpolation_steps_
MultiField< 3, FieldValue< 3 >::Enum > sorption_type
Discrete need Selection for initialization.
static Input::Type::Instance make_output_type(const string &equation_name, const string &output_field_name)
double ** conc_solid
Record type proxy class.
Definition: type_record.hh:182
VecScatter vconc_out_scatter
Output vector scatter.
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.
bool evaluate_time_constraint(double &time_constraint) override
Computes a constraint for time step.
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