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