Flow123d  release_2.2.0-914-gf1a3a4f
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 <vector>
28 
30 #include "fields/field_set.hh"
31 #include "fields/multi_field.hh"
32 #include "fields/vec_seq_double.hh"
35 
36 class Isotherm;
37 class Mesh;
38 
40 {
41 public:
42  TYPEDEF_ERR_INFO( EI_ArrayName, std::string);
43  DECLARE_INPUT_EXCEPTION( ExcSubstanceCountMatch, << "The size of the input array " << EI_ArrayName::qval
44  << " does not match the number of substances.");
45 
46  /**
47  * Static variable for new input data types input
48  */
49  static const Input::Type::Record & get_input_type();
50 
51  /*
52  static Input::Type::Selection make_output_selection(const string &output_field_name, const string &selection_name)
53  {
54  return EqData(output_field_name).output_fields
55  .make_output_field_selection(selection_name, "desc")
56  .close();
57  }*/
58 
59  static Input::Type::Instance make_output_type(const string &equation_name, const string &output_field_name )
60  {
61  return EqData(output_field_name).output_fields.make_output_type(equation_name, "");
62  }
63 
64  class EqData : public FieldSet
65  {
66  public:
67  /**
68  * Sorption type specifies a kind of equilibrial description of adsorption.
69  */
71 
72  /// Collect all fields
73  EqData(const string &output_field_name);
74 
75  MultiField<3, FieldValue<3>::Enum > sorption_type; ///< Discrete need Selection for initialization.
76  Field<3, FieldValue<3>::Scalar > rock_density; ///< Rock matrix density.
77 
78  /// Multiplication coefficients (k, omega) for all types of isotherms.
79  /** Langmuir: c_s = omega * (alpha*c_a)/(1- alpha*c_a), Linear: c_s = k*c_a */
81  /// Langmuir sorption coeficients alpha (in fraction c_s = omega * (alpha*c_a)/(1- alpha*c_a)).
83 
84  MultiField<3, FieldValue<3>::Scalar> init_conc_solid; ///< Initial sorbed concentrations.
85  Field<3, FieldValue<3>::Scalar > porosity; ///< Porosity field copied from transport.
86 
87  MultiField<3, FieldValue<3>::Scalar> conc_solid; ///< Calculated sorbed concentrations, for output only.
88 
89  /// Input data set - fields in this set are read from the input file.
91 
92  /// Fields indended for output, i.e. all input fields plus those representing solution.
94 
95  };
96 
97  /**
98  * Constructor with parameter for initialization of a new declared class member
99  */
100  SorptionBase(Mesh &init_mesh, Input::Record in_rec);
101  /**
102  * Destructor.
103  */
104  virtual ~SorptionBase(void);
105 
106  /// Prepares the object to usage.
107  /**
108  * Allocating memory, reading input, initialization of fields.
109  */
110  void initialize() override;
111 
112  /**
113  * Does first computation after initialization process.
114  * The time is set and initial condition is set and output.
115  */
116  void zero_time_step() override;
117 
118  /// Updates the solution.
119  /**
120  * Goes through local distribution of elements and calls @p compute_reaction.
121  */
122  void update_solution(void) override;
123 
124  void output_data(void) override;
125 
126  bool evaluate_time_constraint(double &time_constraint) override { return false; }
127 
128 
129 protected:
130  /**
131  * This method disables to use constructor without parameters.
132  */
133  SorptionBase();
134 
135  /** Initializes possible following reactions from input record.
136  * It should be called after setting mesh, time_governor, distribution and concentration_matrix
137  * if there are some setting methods for reactions called (they are not at the moment, so it could be part of init_from_input).
138  */
139  void make_reactions();
140 
141  /// Reads names of substances from input and creates indexing to global vector of substance.
142  /** Also creates the local vector of molar masses. */
144 
145  /// Initializes private members of sorption from the input record.
146  void initialize_from_input();
147 
148  /// Initializes field sets.
149  void initialize_fields();
150 
151  ///Reads and sets initial condition for concentration in solid.
152  void set_initial_condition();
153 
154  /// Allocates petsc vectors, prepares them for output and creates vector scatter.
155  void allocate_output_mpi(void);
156 
157  /// Gathers all the parallel vectors to enable them to be output.
158  void output_vector_gather(void) override;
159 
160  /**
161  * For simulation of sorption in just one element either inside of MOBILE or IMMOBILE pores.
162  */
163  double **compute_reaction(double **concentrations, int loc_el) override;
164 
165  /// Reinitializes the isotherm.
166  /**
167  * On data change the isotherm is recomputed, possibly new interpolation table is made.
168  * Pure virtual method.
169  */
170  virtual void isotherm_reinit(std::vector<Isotherm> &isotherms, const ElementAccessor<3> &elm) = 0;
171 
172  /**
173  * Creates interpolation table for isotherms.
174  */
175  void make_tables(void);
176 
177 
178  /// Pointer to equation data. The object is constructed in descendants.
180 
181  /**
182  * Temporary nr_of_points can be computed using step_length. Should be |nr_of_region x nr_of_substances| matrix later.
183  */
185  /**
186  * Density of the solvent.
187  * TODO: Could be done region dependent, easily.
188  */
190  /**
191  * Critical concentrations of species dissolved in water.
192  */
194  /**
195  * Concentration table limits of species dissolved in water.
196  */
198  /**
199  * Three dimensional array contains intersections between isotherms and mass balance lines.
200  * It describes behaviour of sorbents in mobile pores of various rock matrix enviroments.
201  * Up to |nr_of_region x nr_of_substances x n_points| doubles. Because of equidistant step
202  * lenght in cocidered system of coordinates, just function values are stored.
203  */
205 
206  unsigned int n_substances_; //< number of substances that take part in the sorption mode
207 
208  /// Mapping from local indexing of substances to global.
210 
211  /**
212  * Array for storage infos about sorbed species concentrations.
213  */
214  double** conc_solid;
215 
216  //Input::Array output_array;
217 
218  //Input::Type::Selection output_selection;
219 
220  /**
221  * Reaction model that follows the sorption.
222  */
223  std::shared_ptr<ReactionTerm> reaction_liquid;
224  std::shared_ptr<ReactionTerm> reaction_solid;
225 
226  ///@name members used in output routines
227  //@{
228  VecScatter vconc_out_scatter; ///< Output vector scatter.
229  // TODO: replace vconc_solid + conc_solid by VecSeqDouble, use the same principle as in 'conc_solid_out'
230  Vec *vconc_solid; ///< PETSC sorbed concentration vector (parallel).
231  std::vector<VectorSeqDouble> conc_solid_out; ///< sorbed concentration array output (gathered - sequential)
232  //@}
233 };
234 
235 #endif //SORPTION_BASE_H
std::shared_ptr< ReactionTerm > reaction_solid
void allocate_output_mpi(void)
Allocates petsc vectors, prepares them for output and creates vector scatter.
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:61
MultiField< 3, FieldValue< 3 >::Scalar > conc_solid
Calculated sorbed concentrations, for output only.
void make_reactions()
std::vector< VectorSeqDouble > conc_solid_out
sorbed concentration array output (gathered - sequential)
double solvent_density_
std::vector< std::vector< Isotherm > > isotherms
virtual ~SorptionBase(void)
DECLARE_INPUT_EXCEPTION(ExcSubstanceCountMatch,<< "The size of the input array "<< EI_ArrayName::qval<< " does not match the number of substances.")
void initialize_substance_ids()
Reads names of substances from input and creates indexing to global vector of substance.
EqData(const string &output_field_name)
Collect all fields.
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:62
void zero_time_step() override
Field< 3, FieldValue< 3 >::Scalar > rock_density
Rock matrix density.
Definition: mesh.h:99
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
static const Input::Type::Selection & get_sorption_type_selection()
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.
void initialize_fields()
Initializes field sets.
MultiField< 3, FieldValue< 3 >::Scalar > isotherm_other
Langmuir sorption coeficients alpha (in fraction c_s = omega * (alpha*c_a)/(1- alpha*c_a)).
void output_data(void) override
Output method.
Field< 3, FieldValue< 3 >::Scalar > porosity
Porosity field copied from transport.
Vec * vconc_solid
PETSC sorbed concentration vector (parallel).
MultiField< 3, FieldValue< 3 >::Scalar > init_conc_solid
Initial sorbed concentrations.
void initialize_from_input()
Initializes private members of sorption from the input record.
std::vector< double > solubility_vec_
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
unsigned int n_interpolation_steps_
void make_tables(void)
virtual void isotherm_reinit(std::vector< Isotherm > &isotherms, const ElementAccessor< 3 > &elm)=0
Reinitializes the isotherm.
MultiField< 3, FieldValue< 3 >::Enum > sorption_type
Discrete need Selection for initialization.
void output_vector_gather(void) override
Gathers all the parallel vectors to enable them to be output.
void update_solution(void) override
Updates the solution.
static Input::Type::Instance make_output_type(const string &equation_name, const string &output_field_name)
double ** compute_reaction(double **concentrations, int loc_el) override
void set_initial_condition()
Reads and sets initial condition for concentration in solid.
double ** conc_solid
Record type proxy class.
Definition: type_record.hh:182
static const Input::Type::Record & get_input_type()
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:55
MultiField< 3, FieldValue< 3 >::Scalar > distribution_coefficient
Multiplication coefficients (k, omega) for all types of isotherms.
unsigned int n_substances_
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.
TYPEDEF_ERR_INFO(EI_ArrayName, std::string)
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
void initialize() override
Prepares the object to usage.