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