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