Flow123d  release_3.0.0-973-g92f55e826
transport_operator_splitting.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 transport_operator_splitting.hh
15  * @brief
16  */
17 
18 #ifndef TRANSPORT_OPERATOR_SPLITTING_HH_
19 #define TRANSPORT_OPERATOR_SPLITTING_HH_
20 
21 
22 #include <memory> // for shared_ptr
23 #include <vector> // for vector
24 #include "coupling/equation.hh"
25 #include "fields/field.hh" // for Field
26 #include "fields/field_values.hh"
27 #include "fields/field_set.hh"
28 #include "fields/multi_field.hh"
30 #include "input/accessors.hh" // for Record
31 #include "input/type_base.hh" // for Array
32 #include "input/type_generic.hh" // for Instance
33 #include "petscvec.h" // for Vec
34 #include "tools/time_governor.hh" // for TimeGovernor, TimeGov...
35 #include "tools/time_marks.hh" // for TimeMarks
36 #include "mesh/long_idx.hh"
37 
38 /// external types:
39 class Mesh;
40 class ReactionTerm;
41 class Balance;
42 class Distribution;
43 class MH_DofHandler;
44 class OutputTime;
45 class SubstanceList;
46 namespace Input {
47  namespace Type {
48  class Abstract;
49  class Record;
50  }
51 }
52 
53 
54 
55 
56 
57 
58 /**
59  * Abstract interface class for implementations of transport equation within TransportOperatorSplitting.
60  */
62 public:
63 
64  /**
65  * Constructor.
66  */
67  ConcentrationTransportBase(Mesh &init_mesh, const Input::Record in_rec)
68  : EquationBase(init_mesh, in_rec) {};
69 
70 
71  /// Common specification of the input record for secondary equations.
73 
74 
75  /**
76  * Set time interval which is considered as one time step by TransportOperatorSplitting.
77  * In particular the velocity field dosn't change over this interval.
78  *
79  * Dependencies:
80  *
81  * velocity, porosity -> matrix, source_vector
82  * matrix -> time_step
83  *
84  * data_read_times -> time_step (not necessary if we won't stick to jump times)
85  * data -> source_vector
86  * time_step -> scaling
87  *
88  *
89  *
90  */
91  virtual void set_target_time(double target_time) = 0;
92 
93  /**
94  * Use Balance object from upstream equation (e.g. in various couplings) instead of own instance.
95  */
96  virtual void set_balance_object(std::shared_ptr<Balance> balance) = 0;
97 
98  /// Computes a constraint for time step.
99  virtual bool evaluate_time_constraint(double &time_constraint) = 0;
100 
101  /// Return substance indices used in balance.
102  virtual const vector<unsigned int> &get_subst_idx() = 0;
103 
104  /// Calculate the array of concentrations per element (for reactions).
105  virtual void calculate_concentration_matrix() = 0;
106 
107  /// Perform changes to transport solution after reaction step.
108  virtual void update_after_reactions(bool solution_changed) = 0;
109 
110  /// Setter for output stream.
111  virtual void set_output_stream(std::shared_ptr<OutputTime> stream) = 0;
112 
113  /// Getter for output stream.
114  virtual std::shared_ptr<OutputTime> output_stream() = 0;
115 
116  /// Getter for array of concentrations per element.
117  virtual double **get_concentration_matrix() = 0;
118 
119  /// Return PETSc vector with solution for sbi-th substance.
120  virtual const Vec &get_solution(unsigned int sbi) = 0;
121 
122  /// Return array of indices of local elements and parallel distribution of elements.
123  virtual void get_par_info(LongIdx * &el_4_loc, Distribution * &el_ds) = 0;
124 
125  /// Return global array of order of elements within parallel vector.
126  virtual LongIdx *get_row_4_el() = 0;
127 
128  /// Pass velocity from flow to transport.
129  virtual void set_velocity_field(const MH_DofHandler &dh) = 0;
130 
131  /// Returns number of trnasported substances.
132  virtual unsigned int n_substances() = 0;
133 
134  /// Returns reference to the vector of substnace names.
135  virtual SubstanceList &substances() = 0;
136 
137 
138 };
139 
140 
141 
142 
143 
144 /**
145  * Class with fields that are common to all transport models.
146  */
147 class TransportEqData : public FieldSet {
148 public:
149 
150  TransportEqData();
151  inline virtual ~TransportEqData() {};
152 
153  /// Mobile porosity - usually saturated water content in the case of unsaturated flow model
155 
156  /// Water content - result of unsaturated water flow model or porosity
158 
159  /// Pointer to DarcyFlow field cross_section
161 
162  /// Concentration sources - density of substance source, only positive part is used.
164  /// Concentration sources - Robin type, in_flux = sources_sigma * (sources_conc - mobile_conc)
167 
168 };
169 
170 
171 
172 
173 /**
174  * @brief Empty transport class.
175  */
177 public:
178  inline TransportNothing(Mesh &mesh_in)
179  : AdvectionProcessBase(mesh_in, Input::Record() )
180 
181  {
182  // make module solved for ever
183  auto eq_mark_type = TimeGovernor::marks().new_mark_type();
185  time_->next_time();
186  };
187 
188  inline virtual ~TransportNothing()
189  {
190  if(time_) delete time_;
191  }
192 
193  inline void set_velocity_field(const MH_DofHandler &dh) override {};
194 
195  inline virtual void output_data() override {};
196 
197 
198 };
199 
200 
201 
202 /**
203  * @brief Coupling of a transport model with a reaction model by operator splitting.
204  *
205  * Outline:
206  * Transport model is any descendant of TransportBase (even TransportOperatorSplitting itself). This
207  * should perform the transport possibly with diffusion and usually without coupling between substances and phases.
208  *
209  * Reaction is any descendant of the ReactionBase class. This represents reactions in general way of any coupling that
210  * happens between substances and phases on one element or more generally on one DoF.
211  */
212 
214 public:
216 
217  /**
218  * @brief Declare input record type for the equation TransportOperatorSplittiong.
219  *
220  * TODO: The question is if this should be a general coupling class
221  * (e.g. allow coupling TranportDG with reactions even if it is not good idea for numerical reasons.)
222  * To make this a coupling class we should modify all main input files for transport problems.
223  */
224  static const Input::Type::Record & get_input_type();
225 
226  /// Constructor.
227  TransportOperatorSplitting(Mesh &init_mesh, const Input::Record in_rec);
228  /// Destructor.
229  virtual ~TransportOperatorSplitting();
230 
231  virtual void set_velocity_field(const MH_DofHandler &dh) override;
232 
233  void initialize() override;
234  void zero_time_step() override;
235  void update_solution() override;
236 
238  void compute_internal_step();
239  void output_data() override;
240 
241 
242 
243 private:
244  /// Registrar of class to factory
245  static const int registrar;
246 
247  std::shared_ptr<ConcentrationTransportBase> convection;
248  std::shared_ptr<ReactionTerm> reaction;
249 
250  //double *** semchem_conc_ptr; //dumb 3-dim array (for phases, which are not supported any more)
251  //Semchem_interface *Semchem_reactions;
252 
253  double cfl_convection; ///< Time restriction due to transport
254  double cfl_reaction; ///< Time restriction due to reactions
255 
256 };
257 
258 
259 
260 
261 
262 #endif // TRANSPORT_OPERATOR_SPLITTING_HH_
TransportEqData::sources_sigma
MultiField< 3, FieldValue< 3 >::Scalar > sources_sigma
Concentration sources - Robin type, in_flux = sources_sigma * (sources_conc - mobile_conc)
Definition: transport_operator_splitting.hh:165
TransportOperatorSplitting::registrar
static const int registrar
Registrar of class to factory.
Definition: transport_operator_splitting.hh:245
TimeMarks::new_mark_type
TimeMark::Type new_mark_type()
Definition: time_marks.cc:68
ConcentrationTransportBase::get_solution
virtual const Vec & get_solution(unsigned int sbi)=0
Return PETSc vector with solution for sbi-th substance.
TransportEqData::sources_density
MultiField< 3, FieldValue< 3 >::Scalar > sources_density
Concentration sources - density of substance source, only positive part is used.
Definition: transport_operator_splitting.hh:163
time_governor.hh
Basic time management class.
Input
Abstract linear system class.
Definition: balance.hh:37
TransportOperatorSplitting::set_velocity_field
virtual void set_velocity_field(const MH_DofHandler &dh) override
Definition: transport_operator_splitting.cc:367
SubstanceList
Definition: substance.hh:70
TransportEqData
Definition: transport_operator_splitting.hh:147
Balance
Definition: balance.hh:116
LongIdx
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: long_idx.hh:22
TransportOperatorSplitting::zero_time_step
void zero_time_step() override
Definition: transport_operator_splitting.cc:262
ConcentrationTransportBase::n_substances
virtual unsigned int n_substances()=0
Returns number of trnasported substances.
EquationBase::time_
TimeGovernor * time_
Definition: equation.hh:222
advection_process_base.hh
TransportEqData::sources_conc
MultiField< 3, FieldValue< 3 >::Scalar > sources_conc
Definition: transport_operator_splitting.hh:166
field_set.hh
TransportOperatorSplitting::FactoryBaseType
AdvectionProcessBase FactoryBaseType
Definition: transport_operator_splitting.hh:215
ConcentrationTransportBase::calculate_concentration_matrix
virtual void calculate_concentration_matrix()=0
Calculate the array of concentrations per element (for reactions).
std::vector< unsigned int >
ConcentrationTransportBase::get_subst_idx
virtual const vector< unsigned int > & get_subst_idx()=0
Return substance indices used in balance.
type_base.hh
TransportEqData::porosity
Field< 3, FieldValue< 3 >::Scalar > porosity
Mobile porosity - usually saturated water content in the case of unsaturated flow model.
Definition: transport_operator_splitting.hh:151
ConcentrationTransportBase::get_row_4_el
virtual LongIdx * get_row_4_el()=0
Return global array of order of elements within parallel vector.
ConcentrationTransportBase::set_output_stream
virtual void set_output_stream(std::shared_ptr< OutputTime > stream)=0
Setter for output stream.
TransportOperatorSplitting::initialize
void initialize() override
Definition: transport_operator_splitting.cc:233
TransportOperatorSplitting::TransportOperatorSplitting
TransportOperatorSplitting(Mesh &init_mesh, const Input::Record in_rec)
Constructor.
Definition: transport_operator_splitting.cc:153
Distribution
Definition: distribution.hh:50
TransportEqData::TransportEqData
TransportEqData()
Definition: transport_operator_splitting.cc:107
ConcentrationTransportBase::evaluate_time_constraint
virtual bool evaluate_time_constraint(double &time_constraint)=0
Computes a constraint for time step.
ConcentrationTransportBase::get_par_info
virtual void get_par_info(LongIdx *&el_4_loc, Distribution *&el_ds)=0
Return array of indices of local elements and parallel distribution of elements.
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
AdvectionProcessBase
Definition: advection_process_base.hh:23
TransportEqData::~TransportEqData
virtual ~TransportEqData()
Definition: transport_operator_splitting.hh:151
TransportOperatorSplitting::compute_internal_step
void compute_internal_step()
type_generic.hh
TransportNothing
Empty transport class.
Definition: transport_operator_splitting.hh:176
accessors.hh
TransportOperatorSplitting::get_input_type
static const Input::Type::Record & get_input_type()
Declare input record type for the equation TransportOperatorSplittiong.
Definition: transport_operator_splitting.cc:69
TimeGovernor
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Definition: time_governor.hh:294
TransportOperatorSplitting::update_solution
void update_solution() override
Definition: transport_operator_splitting.cc:278
TransportOperatorSplitting::reaction
std::shared_ptr< ReactionTerm > reaction
Definition: transport_operator_splitting.hh:248
field_values.hh
TransportOperatorSplitting::output_data
void output_data() override
Write computed fields.
Definition: transport_operator_splitting.cc:248
Input::Type::Abstract
Class for declaration of polymorphic Record.
Definition: type_abstract.hh:62
OutputTime
The class for outputting data during time.
Definition: output_time.hh:50
TransportNothing::~TransportNothing
virtual ~TransportNothing()
Definition: transport_operator_splitting.hh:188
TransportEqData::cross_section
Field< 3, FieldValue< 3 >::Scalar > cross_section
Pointer to DarcyFlow field cross_section.
Definition: transport_operator_splitting.hh:160
FieldSet
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:71
equation.hh
Abstract base class for equation clasess.
EquationBase
Definition: equation.hh:57
ConcentrationTransportBase::get_concentration_matrix
virtual double ** get_concentration_matrix()=0
Getter for array of concentrations per element.
TransportNothing::output_data
virtual void output_data() override
Write computed fields.
Definition: transport_operator_splitting.hh:195
TransportOperatorSplitting::cfl_convection
double cfl_convection
Time restriction due to transport.
Definition: transport_operator_splitting.hh:253
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
ConcentrationTransportBase
Definition: transport_operator_splitting.hh:61
Mesh
Definition: mesh.h:80
ConcentrationTransportBase::set_target_time
virtual void set_target_time(double target_time)=0
TransportOperatorSplitting
Coupling of a transport model with a reaction model by operator splitting.
Definition: transport_operator_splitting.hh:213
multi_field.hh
ConcentrationTransportBase::set_balance_object
virtual void set_balance_object(std::shared_ptr< Balance > balance)=0
ConcentrationTransportBase::set_velocity_field
virtual void set_velocity_field(const MH_DofHandler &dh)=0
Pass velocity from flow to transport.
TimeGovernor::marks
static TimeMarks & marks()
Definition: time_governor.hh:315
TransportEqData::water_content
Field< 3, FieldValue< 3 >::Scalar > water_content
Water content - result of unsaturated water flow model or porosity.
Definition: transport_operator_splitting.hh:157
TransportOperatorSplitting::compute_until_save_time
void compute_until_save_time()
ConcentrationTransportBase::ConcentrationTransportBase
ConcentrationTransportBase(Mesh &init_mesh, const Input::Record in_rec)
Definition: transport_operator_splitting.hh:67
MultiField
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:85
TransportOperatorSplitting::convection
std::shared_ptr< ConcentrationTransportBase > convection
Definition: transport_operator_splitting.hh:247
ConcentrationTransportBase::output_stream
virtual std::shared_ptr< OutputTime > output_stream()=0
Getter for output stream.
TimeGovernor::inf_time
static const double inf_time
Infinity time used for steady case.
Definition: time_governor.hh:621
ConcentrationTransportBase::get_input_type
static Input::Type::Abstract & get_input_type()
Common specification of the input record for secondary equations.
Definition: transport_operator_splitting.cc:62
long_idx.hh
time_marks.hh
TransportOperatorSplitting::cfl_reaction
double cfl_reaction
Time restriction due to reactions.
Definition: transport_operator_splitting.hh:254
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:83
ReactionTerm
Definition: reaction_term.hh:44
TimeGovernor::next_time
void next_time()
Proceed to the next time according to current estimated time step.
Definition: time_governor.cc:640
ConcentrationTransportBase::substances
virtual SubstanceList & substances()=0
Returns reference to the vector of substnace names.
ConcentrationTransportBase::update_after_reactions
virtual void update_after_reactions(bool solution_changed)=0
Perform changes to transport solution after reaction step.
TransportNothing::set_velocity_field
void set_velocity_field(const MH_DofHandler &dh) override
Definition: transport_operator_splitting.hh:193
TransportOperatorSplitting::~TransportOperatorSplitting
virtual ~TransportOperatorSplitting()
Destructor.
Definition: transport_operator_splitting.cc:225
MH_DofHandler
Definition: mh_dofhandler.hh:43
field.hh
TransportNothing::TransportNothing
TransportNothing(Mesh &mesh_in)
Definition: transport_operator_splitting.hh:178