Flow123d  jenkins-Flow123d-windows32-release-multijob-51
transport_operator_splitting.cc
Go to the documentation of this file.
1 /*
2  * transport_operator_splitting.cc
3  *
4  * Created on: May 21, 2011
5  * Author: jiri
6  */
7 
8 #include <iostream>
9 #include <iomanip>
10 
11 #include "system/system.hh"
12 #include "system/sys_profiler.hh"
13 #include "system/xio.h"
14 
16 #include <petscmat.h>
17 #include "system/sys_vector.hh"
19 #include "coupling/equation.hh"
20 #include "transport/transport.h"
21 #include "mesh/mesh.h"
22 #include "flow/old_bcd.hh"
23 
24 #include "reaction/reaction.hh"
27 #include "reaction/sorption.hh"
29 
31 
32 #include "la/distribution.hh"
33 #include "io/output.h"
34 
35 #include "input/input_type.hh"
36 #include "input/accessors.hh"
37 
38 using namespace Input::Type;
39 
41  = AbstractRecord("Transport", "Secondary equation for transport of substances.")
43  "Time governor setting for the secondary equation.")
45  "Parameters of output stream.")
46  .declare_key("mass_balance", MassBalance::input_type, Default::optional(), "Settings for computing mass balance.");
47 
48 
50  = Record("TransportOutput", "Output setting for transport equations.")
52  "Parameters of output stream.");
53 
54 
56  = Record("TransportOperatorSplitting",
57  "Explicit FVM transport (no diffusion)\n"
58  "coupled with reaction and adsorption model (ODE per element)\n"
59  " via operator splitting.")
61  .declare_key("substances", Array(String()), Default::obligatory(),
62  "Names of transported substances.")
63  // input data
65  "Reaction model involved in transport.")
66 
67  .declare_key("input_fields", Array(
68  ConvectionTransport::EqData().make_field_descriptor_type("TransportOperatorSplitting")
69  .declare_key(OldBcdInput::transport_old_bcd_file_key(), IT::FileName::input(), "File with mesh dependent boundary conditions (obsolete).")
70  ), IT::Default::obligatory(), "")
72  Default("conc"),
73  "List of fields to write to output file.");
74 
75 
77 {
78 
79  ADD_FIELD(porosity, "Mobile porosity", "1");
80  porosity.units( UnitSI::dimensionless() );
81 
82  ADD_FIELD(cross_section, "");
83  cross_section.flags( FieldFlag::input_copy );
84 
85  ADD_FIELD(sources_density, "Density of concentration sources.", "0");
86  sources_density.units( UnitSI().kg().m(-3) );
87 
88  ADD_FIELD(sources_sigma, "Concentration flux.", "0");
89  sources_sigma.units( UnitSI().s(-1) );
90 
91  ADD_FIELD(sources_conc, "Concentration sources threshold.", "0");
92  sources_conc.units( UnitSI().kg().m(-3) );
93 }
94 
95 
97 : AdvectionProcessBase(mesh, in_rec ),
98  mh_dh(nullptr),
99  mass_balance_(nullptr)
100 {
101 }
102 
104 {
105 }
106 
107 
108 
109 
110 
111 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
112 
113 
114 
116 : TransportBase(init_mesh, in_rec),
117  convection(NULL),
118  reaction(nullptr),
119  Semchem_reactions(NULL)
120 {
121  Distribution *el_distribution;
122  int *el_4_loc;
123 
124  in_rec.val<Input::Array>("substances").copy_to(subst_names_);
125  n_subst_ = subst_names_.size();
126  convection = new ConvectionTransport(*mesh_, in_rec);
127  this->eq_data_ = &(convection->data());
128 
129  time_ = new TimeGovernor(in_rec.val<Input::Record>("time"), convection->mark_type() );
130 
131 
132  convection->get_par_info(el_4_loc, el_distribution);
133  Input::Iterator<Input::AbstractRecord> reactions_it = in_rec.find<Input::AbstractRecord>("reaction_term");
134  if ( reactions_it ) {
135  if (reactions_it->type() == LinearReaction::input_type ) {
136  reaction = new LinearReaction(init_mesh, *reactions_it);
137  } else
138  if (reactions_it->type() == PadeApproximant::input_type) {
139  reaction = new PadeApproximant(init_mesh, *reactions_it);
140  } else
141  if (reactions_it->type() == SorptionSimple::input_type ) {
142  reaction = new SorptionSimple(init_mesh, *reactions_it);
143  } else
144  if (reactions_it->type() == DualPorosity::input_type ) {
145  reaction = new DualPorosity(init_mesh, *reactions_it);
146  } else
147  if (reactions_it->type() == Semchem_interface::input_type ) {
148  Semchem_reactions = new Semchem_interface(0.0, mesh_, n_subst_, false); //false instead of convection->get_dual_porosity
149  Semchem_reactions->set_el_4_loc(el_4_loc);
151 
152  } else {
153  xprintf(UsrErr, "Wrong reaction type.\n");
154  }
155  //temporary, until new mass balance considering reaction term is created
156  xprintf(Warn, "The mass balance is not computed correctly when reaction term is present. "
157  "Only the mass flux over boundaries is correct.\n");
158 
161  el_distribution, el_4_loc, convection->get_row_4_el())
162  .output_stream(*(convection->output_stream()))
164 
165  reaction->initialize();
166 
167  } else {
168  reaction = nullptr;
169  Semchem_reactions = nullptr;
170  }
171 
172  //coupling - passing fields
173  if(reaction)
174  if( typeid(*reaction) == typeid(SorptionSimple) ||
175  typeid(*reaction) == typeid(DualPorosity)
176  )
177  {
178  reaction->data().set_field("porosity", convection->data()["porosity"]);
179  }
180 }
181 
183 {
184  //delete field_output;
185  delete convection;
186  if (reaction) delete reaction;
188  delete time_;
189 }
190 
191 
192 
193 
195 
196 
197  START_TIMER("TOS-output data");
198 
199  time_->view("TOS"); //show time governor
201  if(reaction) reaction->output_data(); // do not perform write_time_frame
203 
204 }
205 
206 
208 {
209 
213 
214 }
215 
216 
217 
219 
220 
221 
222  time_->next_time();
223 
224 
227 
228  START_TIMER("TOS-one step");
229  int steps=0;
230  while ( convection->time().lt(time_->t()) )
231  {
232  steps++;
233  // one internal step
237  if (convection->mass_balance() != NULL)
239 
240  }
241  END_TIMER("TOS-one step");
242 
243 
244 
245  xprintf( MsgLog, " CONVECTION: steps: %d\n",steps);
246 }
247 
248 
249 
250 
251 
253 {
254  mh_dh = &dh;
256 };
257 
258 
259 void TransportOperatorSplitting::calc_fluxes(vector<vector<double> > &bcd_balance, vector<vector<double> > &bcd_plus_balance, vector<vector<double> > &bcd_minus_balance)
260 {}
261 
263 {}
264 
265 
266 
267 
268 
FieldSet & data()
Definition: equation.hh:188
void calculate(double time)
Definition: mass_balance.cc:89
virtual void zero_time_step()
Definition: equation.hh:97
FieldSet * eq_data_
Definition: equation.hh:227
double *** get_concentration_matrix()
Definition: transport.cc:720
Abstract base class for equation clasess.
static Input::Type::Record input_type
Header: The functions for all outputs.
void update_solution() override
Definition: transport.cc:484
Accessor to input data conforming to declared Array.
Definition: accessors.hh:521
static Input::Type::AbstractRecord input_type
Common specification of the input record for secondary equations.
void set_el_4_loc(int *el_for_loc)
virtual void output_data(void)
Output method.
Definition: reaction.hh:75
static Input::Type::Record input_type
The specification of output stream.
Definition: output_time.hh:57
virtual void initialize()
Initialize fields.
Definition: equation.hh:114
void calc_fluxes(vector< vector< double > > &bcd_balance, vector< vector< double > > &bcd_plus_balance, vector< vector< double > > &bcd_minus_balance) override
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:39
virtual void set_velocity_field(const MH_DofHandler &dh) override
void next_time()
Proceed to the next time according to current estimated time step.
static Default obligatory()
Definition: type_record.hh:87
???
void update_solution(void)
const MH_DofHandler * mh_dh
static Input::Type::Record input_type
Definition: mesh.h:108
Iterator< Ret > find(const string &key) const
Record & derive_from(AbstractRecord &parent)
Definition: type_record.cc:169
virtual void set_velocity_field(const MH_DofHandler &dh) override
double t() const
void get_par_info(int *&el_4_loc, Distribution *&el_ds)
Definition: transport.cc:724
#define ADD_FIELD(name,...)
Definition: field_set.hh:260
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
Basic time management functionality for unsteady (and steady) solvers (class Equation).
void zero_time_step() override
Definition: transport.cc:468
Definition: system.hh:72
Basic time management class.
Class for declaration of inputs sequences.
Definition: type_base.hh:230
Specification of transport model interface.
double estimate_dt() const
Estimate choice of next time step according to actual setting of constraints.
OutputTime * output_stream_
Definition: transport.h:272
void view(const char *name="") const
static Input::Type::AbstractRecord input_type
Definition: reaction.hh:24
static Default optional()
Definition: type_record.hh:100
#define MOBILE
static Input::Type::Record input_type
Definition: system.hh:72
static FileName input()
Definition: type_base.hh:443
bool lt(double other_time) const
static constexpr Mask input_copy
A field that is input of its equation and cna not read from input, thus muzt be set by copy...
Definition: field_flag.hh:29
Accessor to the data with type Type::Record.
Definition: accessors.hh:308
const Ret val(const string &key) const
#define xprintf(...)
Definition: system.hh:100
#define START_TIMER(tag)
Starts a timer with specified tag.
Class for declaration of polymorphic Record.
Definition: type_record.hh:463
Mesh * mesh_
Definition: equation.hh:218
void set_field(const std::string &dest_field_name, FieldCommon &source)
Definition: field_set.cc:94
static Input::Type::Record input_type
unsigned int n_subst_
Number of transported substances.
static Input::Type::Record input_type
AbstractRecord & declare_key(const string &key, const KeyType &type, const Default &default_value, const string &description)
Definition: type_record.cc:422
static Input::Type::Record input_type_output_record
static string transport_old_bcd_file_key()
Definition: old_bcd.hh:56
static Input::Type::AbstractRecord input_type
Class representing dual porosity model in transport.
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:423
virtual void set_time_governor(TimeGovernor &time)
Definition: equation.cc:80
std::vector< string > subst_names_
Names of transported substances.
Definition: system.hh:72
void write_time_frame()
Definition: output.cc:362
Support classes for parallel programing.
void calc_elem_sources(vector< vector< double > > &mass, vector< vector< double > > &src_balance) override
void output_data() override
Write computed fields.
virtual void update_solution()
Definition: equation.hh:105
static Input::Type::Record input_type
Definition: sorption.hh:28
static Input::Type::Selection output_selection
Definition: transport.h:89
TimeGovernor const & time()
Definition: equation.hh:143
Vector classes to support both Iterator, index and Id access and creating co-located vectors...
virtual void output_data() override
Write computed fields.
Definition: transport.cc:808
ReactionTerm & names(const std::vector< string > &names)
Sets the names of substances considered in transport.
Definition: reaction.hh:46
void set_target_time(double target_time)
Definition: transport.cc:567
OutputTime * output_stream()
Definition: transport.h:164
#define END_TIMER(tag)
Ends a timer with specified tag.
TimeMark::Type mark_type()
Definition: equation.hh:179
void set_concentration_matrix(double ***ConcentrationsMatrix, Distribution *conc_distr, int *el_4_loc)
TransportBase(Mesh &mesh, const Input::Record in_rec)
Simple sorption model without dual porosity.
Definition: sorption.hh:25
Record type proxy class.
Definition: type_record.hh:161
static Input::Type::Record input_type
Declare input record type for the equation TransportOperatorSplittiong.
Class for representation SI units of Fields.
Definition: unit_si.hh:31
static UnitSI & dimensionless()
Returns dimensionless unit.
Definition: unit_si.cc:44
ReactionTerm & concentration_matrix(double **concentration, Distribution *conc_distr, int *el_4_loc, int *row_4_el)
Definition: reaction.hh:57
TransportOperatorSplitting(Mesh &init_mesh, const Input::Record &in_rec)
Constructor.
TimeGovernor * time_
Definition: equation.hh:219
virtual ~TransportOperatorSplitting()
Destructor.
Record & declare_key(const string &key, const KeyType &type, const Default &default_value, const string &description)
Definition: type_record.cc:386