Flow123d  JS_before_hm-913-g695b665
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 #include <boost/exception/info.hpp> // for operator<<, error_inf...
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 "system/index_types.hh"
37 
38 /// external types:
39 class Mesh;
40 class ReactionTerm;
41 class Balance;
42 class Distribution;
43 class OutputTime;
44 class SubstanceList;
45 namespace Input {
46  namespace Type {
47  class Abstract;
48  class Record;
49  }
50 }
51 
52 
53 
54 
55 
56 
57 /**
58  * Abstract interface class for implementations of transport equation within TransportOperatorSplitting.
59  */
61 public:
62 
63  /**
64  * Constructor.
65  */
66  ConcentrationTransportBase(Mesh &init_mesh, const Input::Record in_rec)
67  : EquationBase(init_mesh, in_rec) {};
68 
69 
70  /// Common specification of the input record for secondary equations.
71  static Input::Type::Abstract & get_input_type();
72 
73 
74  /**
75  * Set time interval which is considered as one time step by TransportOperatorSplitting.
76  * In particular the velocity field dosn't change over this interval.
77  *
78  * Dependencies:
79  *
80  * velocity, porosity -> matrix, source_vector
81  * matrix -> time_step
82  *
83  * data_read_times -> time_step (not necessary if we won't stick to jump times)
84  * data -> source_vector
85  * time_step -> scaling
86  *
87  *
88  *
89  */
90  virtual void set_target_time(double target_time) = 0;
91 
92  /**
93  * Use Balance object from upstream equation (e.g. in various couplings) instead of own instance.
94  */
95  virtual void set_balance_object(std::shared_ptr<Balance> balance) = 0;
96 
97  /// Computes a constraint for time step.
98  virtual bool evaluate_time_constraint(double &time_constraint) = 0;
99 
100  /// Return substance indices used in balance.
101  virtual const vector<unsigned int> &get_subst_idx() = 0;
102 
103  /// Calculate the array of concentrations per element (for reactions).
104  virtual void calculate_concentration_matrix() = 0;
105 
106  /// Perform changes to transport solution after reaction step.
107  virtual void update_after_reactions(bool solution_changed) = 0;
108 
109  /// Setter for output stream.
110  virtual void set_output_stream(std::shared_ptr<OutputTime> stream) = 0;
111 
112  /// Getter for output stream.
113  virtual std::shared_ptr<OutputTime> output_stream() = 0;
114 
115  /// Getter for array of concentrations per element.
116  virtual double **get_concentration_matrix() = 0;
117 
118  /// Return PETSc vector with solution for sbi-th substance.
119  virtual const Vec &get_solution(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  /// Pass velocity from flow to transport.
128  virtual void set_velocity_field(std::shared_ptr<FieldFE<3, FieldValue<3>::VectorFixed>> flux_field) = 0;
129 
130  /// Returns number of trnasported substances.
131  virtual unsigned int n_substances() = 0;
132 
133  /// Returns reference to the vector of substnace names.
134  virtual SubstanceList &substances() = 0;
135 
136 
137 };
138 
139 
140 
141 
142 
143 /**
144  * Class with fields that are common to all transport models.
145  */
146 class TransportEqData : public FieldSet {
147 public:
148 
149  TransportEqData();
150  inline virtual ~TransportEqData() {};
151 
152  /// Mobile porosity - usually saturated water content in the case of unsaturated flow model
154 
155  /// Water content - result of unsaturated water flow model or porosity
157 
158  /// Pointer to DarcyFlow field cross_section
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 void set_velocity_field(FMT_UNUSED std::shared_ptr<FieldFE<3, FieldValue<3>::VectorFixed>> flux_field) 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(std::shared_ptr<FieldFE<3, FieldValue<3>::VectorFixed>> flux_field) override;
232 
233  void initialize() override;
234  void zero_time_step() override;
235  void update_solution() override;
236 
237  void compute_until_save_time();
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_
Abstract base class for equation clasess.
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:74
ConcentrationTransportBase(Mesh &init_mesh, const Input::Record in_rec)
Abstract linear system class.
Definition: balance.hh:40
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:92
MultiField< 3, FieldValue< 3 >::Scalar > sources_density
Concentration sources - density of substance source, only positive part is used.
Coupling of a transport model with a reaction model by operator splitting.
Definition: mesh.h:78
MultiField< 3, FieldValue< 3 >::Scalar > sources_conc
Basic time management functionality for unsteady (and steady) solvers (class Equation).
static TimeMarks & marks()
Basic time management class.
#define FMT_UNUSED
Definition: posix.h:75
std::shared_ptr< ReactionTerm > reaction
MultiField< 3, FieldValue< 3 >::Scalar > sources_sigma
Concentration sources - Robin type, in_flux = sources_sigma * (sources_conc - mobile_conc) ...
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
TimeMark::Type new_mark_type()
Definition: time_marks.cc:68
double cfl_convection
Time restriction due to transport.
virtual void output_data() override
Write computed fields.
The class for outputting data during time.
Definition: output_time.hh:50
Class for declaration of polymorphic Record.
Field< 3, FieldValue< 3 >::Scalar > water_content
Water content - result of unsaturated water flow model or porosity.
Empty transport class.
void set_velocity_field(FMT_UNUSED std::shared_ptr< FieldFE< 3, FieldValue< 3 >::VectorFixed >> flux_field) override
std::shared_ptr< ConcentrationTransportBase > convection
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: index_types.hh:24
double cfl_reaction
Time restriction due to reactions.
Record type proxy class.
Definition: type_record.hh:182
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:89
Field< 3, FieldValue< 3 >::Scalar > cross_section
Pointer to DarcyFlow field cross_section.
static const double inf_time
Infinity time used for steady case.
Definition: field.hh:60
static const int registrar
Registrar of class to factory.