Flow123d  JS_before_hm-1878-g864746365
transport.h
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.h
15  * @brief
16  * @todo
17  * - remove transport_sources
18  * - in create_transport_matric_mpi, there there is condition edge_flow > ZERO
19  * this makes matrix sparser, but can lead to elements without outflow and other problems
20  * when there are big differences in fluxes, more over it doesn't work if overall flow is very small
21  */
22 
23 #ifndef TRANSPORT_H_
24 #define TRANSPORT_H_
25 
26 
27 #include <memory> // for shared_ptr
28 #include <vector> // for vector
29 #include <petscmat.h>
30 #include "fem/fe_values.hh" // for FEValues
31 #include "fields/field.hh" // for Field
32 #include "fields/bc_multi_field.hh"
33 #include "fields/field_values.hh"
34 #include "fields/multi_field.hh"
35 #include "la/vector_mpi.hh"
37 #include "input/type_base.hh" // for Array
38 #include "input/type_generic.hh" // for Instance
39 #include "input/accessors.hh"
40 #include "system/index_types.hh"
41 #include "mesh/region.hh" // for RegionSet
42 #include "petscvec.h" // for Vec, _p_Vec
43 #include "tools/time_marks.hh" // for TimeMark, TimeM...
44 #include "transport/substance.hh" // for SubstanceList
47 #include "la/vector_mpi.hh"
48 
49 class OutputTime;
50 class Mesh;
51 class Distribution;
52 class Balance;
53 namespace Input {
54  namespace Type {
55  class Record;
56  class Selection;
57  }
58 }
59 
60 
61 //=============================================================================
62 // TRANSPORT
63 //=============================================================================
64 
65 /**
66  * TODO:
67  * - doxy documentation
68  * - make separate method for changing time step (rescaling only), reassembly matrix only when data are changed
69  *
70  * - needs support from EqData to determine next change of the data for 1) transport matrix 2) source vector
71  * this allows us precisely choose interval where to fix timestep
72  * : field->next_change_time() - returns time jump or actual time in case of time dep. field
73  */
74 
75 
76 
77 /**
78  * Auxiliary container class for Finite element and related objects of all dimensions.
79  * Its purpose is to provide templated access to these objects, applicable in
80  * the assembling methods.
81  */
83 public:
84 
87 
88  template<unsigned int dim>
89  inline FiniteElement<dim> *fe();
90 
91  inline Quadrature &q(unsigned int dim);
92 
93  inline FEValues<3> &fe_values(unsigned int dim)
94  {
95  ASSERT_DBG( dim >= 1 && dim <= 3 );
96  return fe_values_[dim-1];
97  }
98 
99 private:
100 
101  /// Finite elements for the solution of the advection-diffusion equation.
106 
107  /// Quadratures used in assembling methods.
109 
110  /// FESideValues objects for side flux calculating.
112 };
113 
114 
115 /**
116  * Class that implements explicit finite volumes scheme with upwind. The timestep is given by CFL condition.
117  *
118  */
120 public:
121  class EqData : public TransportEqFields {
122  public:
123 
124  EqData();
125  virtual ~EqData() {};
126 
127  /// Override generic method in order to allow specification of the boundary conditions through the old bcd files.
129 
130  /**
131  * Boundary conditions (Dirichlet) for concentrations.
132  * They are applied only on water inflow part of the boundary.
133  */
135 
136  /// Initial concentrations.
138 
141 
142  MultiField<3, FieldValue<3>::Scalar> conc_mobile; ///< Calculated concentrations in the mobile zone.
143  FieldFEScalarVec conc_mobile_fe; ///< Underlaying FieldFE for each substance of conc_mobile.
144 
145  /// Fields indended for output, i.e. all input fields plus those representing solution.
147  };
148 
149 
151 
152  static const Input::Type::Record & get_input_type();
153 
154  static const IT::Selection & get_output_selection();
155 
156  /**
157  * Constructor.
158  */
159  ConvectionTransport(Mesh &init_mesh, const Input::Record in_rec);
160  /**
161  * TODO: destructor
162  */
163  virtual ~ConvectionTransport();
164 
165  void initialize() override;
166 
167  /**
168  * Initialize solution at zero time.
169  */
170  void zero_time_step() override;
171  /**
172  * Evaluates CFL condition.
173  * Assembles the transport matrix and vector (including sources, bc terms).
174  * @param time_constraint is the value CFL constraint (return parameter)
175  * @return true if CFL is changed since previous step, false otherwise
176  */
177  bool evaluate_time_constraint(double &time_constraint) override;
178  /**
179  * Calculates one time step of explicit transport.
180  */
181  void update_solution() override;
182 
183  /** Compute P0 interpolation of the solution (used reaction term).
184  * Empty - solution is already P0 interpolation.
185  */
186  void compute_p0_interpolation() override {};
187 
188  /// Not used in this class.
189  void update_after_reactions(bool) override {};
190 
191  /**
192  * Set time interval which is considered as one time step by TransportOperatorSplitting.
193  * In particular the velocity field doesn't change over this interval.
194  *
195  * Dependencies:
196  *
197  * velocity, porosity -> matrix, source_vector
198  * matrix -> time_step
199  *
200  * data_read_times -> time_step (not necessary if we won't stick to jump times)
201  * data -> source_vector
202  * time_step -> scaling
203  *
204  *
205  *
206  */
207  void set_target_time(double target_time) override;
208 
209  /**
210  * Use Balance object from upstream equation (e.g. in various couplings) instead of own instance.
211  */
212  void set_balance_object(std::shared_ptr<Balance> balance) override;
213 
215  { return subst_idx; }
216 
217  /**
218  * @brief Write computed fields.
219  */
220  virtual void output_data() override;
221 
222  void set_output_stream(std::shared_ptr<OutputTime> stream) override
223  { output_stream_ = stream; }
224 
225 
226  /**
227  * Getters.
228  */
229 
230  /// Getter for P0 interpolation by FieldFE.
232 
233  Vec get_component_vec(unsigned int sbi) override;
234 
235  void get_par_info(LongIdx * &el_4_loc, Distribution * &el_ds) override;
236 
237  LongIdx *get_row_4_el() override;
238 
239  /// Returns number of transported substances.
240  inline unsigned int n_substances() override
241  { return substances_.size(); }
242 
243  /// Returns reference to the vector of substance names.
244  inline SubstanceList &substances() override
245  { return substances_; }
246 
247 private:
248 
249  /**
250  * Assembly convection term part of the matrix and boundary matrix for application of boundary conditions.
251  *
252  * Discretization of the convection term use explicit time scheme and finite volumes with full upwinding.
253  * We count on with exchange between dimensions and mixing on edges where more then two elements connect (can happen for 2D and 1D elements in
254  * 3D embedding space)
255  *
256  * In order to get multiplication matrix for explicit transport one have to scale the convection part by the acctual time step and
257  * add time term, i. e. unit matrix (see. transport_matrix_step_mpi)
258  *
259  * Updates CFL time step constrain.
260  */
262  void create_mass_matrix();
263 
264  void make_transport_partitioning(); //
265  void set_initial_condition();
267 
268  /** @brief Assembles concentration sources for each substance and set boundary conditions.
269  * note: the source of concentration is multiplied by time interval (gives the mass, not the flow like before)
270  */
272 
273  /**
274  * Finish explicit transport matrix (time step scaling)
275  */
276  void transport_matrix_step_mpi(double time_step); //
277 
280 
281  /**
282  * @brief Wrapper of following method, call side_flux with correct template parameter.
283  */
284  double side_flux(const DHCellSide &cell_side);
285 
286  /**
287  * @brief Calculate flux on side of given element specified by dimension.
288  */
289  template<unsigned int dim>
290  double calculate_side_flux(const DHCellSide &cell);
291 
292 
293 
294  /// Registrar of class to factory
295  static const int registrar;
296 
297  /**
298  * Parameters of the equation, some are shared with other implementations since EqData is derived from TransportBase::TransportEqFields
299  */
301 
302  //@{
303  /**
304  * Flag indicates the state of object (transport matrix or source or boundary term).
305  * If false, the object is freshly assembled and not rescaled.
306  * If true, the object is scaled (not necessarily with the current time step).
307  */
309 
310  /// Flag indicates that porosity or cross_section changed during last time.
312  //@}
313 
315 
316 
317  TimeMark::Type target_mark_type; ///< TimeMark type for time marks denoting end of every time interval where transport matrix remains constant.
318  double cfl_max_step; ///< Time step constraint coming from CFL condition.
319 
320  Vec vcfl_flow_, ///< Parallel vector for flow contribution to CFL condition.
321  vcfl_source_; ///< Parallel vector for source term contribution to CFL condition.
323 
324 
325  VecScatter vconc_out_scatter;
326  Mat tm; // PETSc transport matrix
327  Vec mass_diag; // diagonal entries in pass matrix (cross_section * porosity)
328  Vec vpmass_diag; // diagonal entries in mass matrix from last time (cross_section * porosity)
329  Vec *v_tm_diag; // additions to PETSC transport matrix on the diagonal - from sources (for each substance)
330  double **tm_diag;
331 
332  /// Time when the transport matrix was created.
333  /// TODO: when we have our own classes for LA objects, we can use lazy dependence to check
334  /// necessity for matrix update
336  double transport_bc_time; ///< Time of the last update of the boundary condition terms.
337 
338  ///
339  Vec *vpconc; // previous concentration vector
340  Vec *bcvcorr; // boundary condition correction vector
342  double **cumulative_corr;
343 
344  /// Record with input specification.
346 
347  std::shared_ptr<OutputTime> output_stream_;
348 
349 
353 
354  /// Transported substances.
356 
357  /**
358  * Temporary solution how to pass velocity field form the flow model.
359  * TODO: introduce FieldDiscrete -containing true DOFHandler and data vector and pass such object together with other
360  * data. Possibly make more general set_data method, allowing setting data given by name. needs support from EqDataBase.
361  */
362  std::shared_ptr<DOFHandlerMultiDim> dh_;
363 
364  /// List of indices used to call balance methods for a set of quantities.
366 
367  /// Finite element objects
369 
371 };
372 #endif /* TRANSPORT_H_ */
FETransportObjects::fe_values_
FEValues< 3 > fe_values_[3]
FESideValues objects for side flux calculating.
Definition: transport.h:111
FETransportObjects::fe1_
FiniteElement< 1 > * fe1_
Definition: transport.h:103
ConvectionTransport::set_balance_object
void set_balance_object(std::shared_ptr< Balance > balance) override
Definition: transport.cc:857
ConvectionTransport::EqData::conc_mobile
MultiField< 3, FieldValue< 3 >::Scalar > conc_mobile
Calculated concentrations in the mobile zone.
Definition: transport.h:142
ConvectionTransport::is_bc_term_scaled
bool is_bc_term_scaled
Definition: transport.h:308
ConvectionTransport::vcfl_flow_
Vec vcfl_flow_
Parallel vector for flow contribution to CFL condition.
Definition: transport.h:320
ConvectionTransport::mass_diag
Vec mass_diag
Definition: transport.h:327
ConvectionTransport::FactoryBaseType
ConcentrationTransportBase FactoryBaseType
Definition: transport.h:150
ConvectionTransport::create_mass_matrix
void create_mass_matrix()
Definition: transport.cc:706
ConvectionTransport::EqData::init_conc
MultiField< 3, FieldValue< 3 >::Scalar > init_conc
Initial concentrations.
Definition: transport.h:137
ConvectionTransport::row_4_el
LongIdx * row_4_el
Definition: transport.h:350
vector_mpi.hh
ConvectionTransport::EqData::read_boundary_list_item
RegionSet read_boundary_list_item(Input::Record rec)
Override generic method in order to allow specification of the boundary conditions through the old bc...
ConvectionTransport::get_input_type
static const Input::Type::Record & get_input_type()
Definition: transport.cc:73
ConvectionTransport::substances
SubstanceList & substances() override
Returns reference to the vector of substance names.
Definition: transport.h:244
ConvectionTransport::feo_
FETransportObjects feo_
Finite element objects.
Definition: transport.h:368
Input
Abstract linear system class.
Definition: balance.hh:40
SubstanceList::size
unsigned int size() const
Definition: substance.hh:87
SubstanceList
Definition: substance.hh:70
ConvectionTransport::transport_matrix_time
double transport_matrix_time
Definition: transport.h:335
Balance
Definition: balance.hh:119
ConvectionTransport::update_after_reactions
void update_after_reactions(bool) override
Not used in this class.
Definition: transport.h:189
FETransportObjects::fe0_
FiniteElement< 0 > * fe0_
Finite elements for the solution of the advection-diffusion equation.
Definition: transport.h:102
FETransportObjects::FETransportObjects
FETransportObjects()
Definition: transport.cc:120
ConvectionTransport::side_flux
double side_flux(const DHCellSide &cell_side)
Wrapper of following method, call side_flux with correct template parameter.
Definition: transport.cc:863
fe_values.hh
Class FEValues calculates finite element data on the actual cells such as shape function values,...
ConvectionTransport::el_ds
Distribution * el_ds
Definition: transport.h:352
ConvectionTransport::calculate_side_flux
double calculate_side_flux(const DHCellSide &cell)
Calculate flux on side of given element specified by dimension.
Definition: transport.cc:871
ASSERT_DBG
#define ASSERT_DBG(expr)
Definition: include_fadbad.hh:28
substance.hh
Classes for storing substance data.
ConvectionTransport::~ConvectionTransport
virtual ~ConvectionTransport()
Definition: transport.cc:256
std::vector< Region >
ConvectionTransport::EqData::conc_mobile_fe
FieldFEScalarVec conc_mobile_fe
Underlaying FieldFE for each substance of conc_mobile.
Definition: transport.h:143
ConvectionTransport::get_row_4_el
LongIdx * get_row_4_el() override
Return global array of order of elements within parallel vector.
Definition: transport.cc:839
ConvectionTransport::n_substances
unsigned int n_substances() override
Returns number of transported substances.
Definition: transport.h:240
FETransportObjects::fe_values
FEValues< 3 > & fe_values(unsigned int dim)
Definition: transport.h:93
ConvectionTransport::vcumulative_corr
Vec * vcumulative_corr
Definition: transport.h:341
ConvectionTransport::output_stream_
std::shared_ptr< OutputTime > output_stream_
Definition: transport.h:347
type_base.hh
ConvectionTransport::transport_bc_time
double transport_bc_time
Time of the last update of the boundary condition terms.
Definition: transport.h:336
index_types.hh
ConvectionTransport::is_mass_diag_changed
bool is_mass_diag_changed
Flag indicates that porosity or cross_section changed during last time.
Definition: transport.h:311
FEValues< 3 >
ConvectionTransport::cumulative_corr
double ** cumulative_corr
Definition: transport.h:342
ConvectionTransport::read_concentration_sources
void read_concentration_sources()
DHCellSide
Side accessor allows to iterate over sides of DOF handler cell.
Definition: dh_cell_accessor.hh:176
equation_output.hh
ConvectionTransport::conc_sources_bdr_conditions
void conc_sources_bdr_conditions()
Assembles concentration sources for each substance and set boundary conditions. note: the source of c...
Definition: transport.cc:389
Distribution
Definition: distribution.hh:50
EquationBase::balance
std::shared_ptr< Balance > balance() const
Definition: equation.hh:185
ConvectionTransport::EqData
Definition: transport.h:121
ConvectionTransport::alloc_transport_structs_mpi
void alloc_transport_structs_mpi()
Definition: transport.cc:340
ConvectionTransport::EqData::EqData
EqData()
Definition: transport.cc:89
ConvectionTransport::bcvcorr
Vec * bcvcorr
Definition: transport.h:340
ConvectionTransport::is_convection_matrix_scaled
bool is_convection_matrix_scaled
Definition: transport.h:308
ConvectionTransport::cfl_source_
double * cfl_source_
Definition: transport.h:322
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
FETransportObjects::~FETransportObjects
~FETransportObjects()
Definition: transport.cc:138
ConvectionTransport::data_
EqData data_
Definition: transport.h:300
ConvectionTransport::input_rec
const Input::Record input_rec
Record with input specification.
Definition: transport.h:345
ConvectionTransport::evaluate_time_constraint
bool evaluate_time_constraint(double &time_constraint) override
Definition: transport.cc:517
ConvectionTransport::registrar
static const int registrar
Registrar of class to factory.
Definition: transport.h:295
ConvectionTransport::zero_time_step
void zero_time_step() override
Definition: transport.cc:493
quadrature_lib.hh
Definitions of particular quadrature rules on simplices.
type_generic.hh
ConvectionTransport::v_tm_diag
Vec * v_tm_diag
Definition: transport.h:329
ConvectionTransport::set_initial_condition
void set_initial_condition()
Definition: transport.cc:298
accessors.hh
EquationOutput
Definition: equation_output.hh:40
ConvectionTransport::vpmass_diag
Vec vpmass_diag
Definition: transport.h:328
FETransportObjects::q
Quadrature & q(unsigned int dim)
Definition: transport.cc:151
ConvectionTransport::vcfl_source_
Vec vcfl_source_
Parallel vector for source term contribution to CFL condition.
Definition: transport.h:321
ConvectionTransport::output_data
virtual void output_data() override
Write computed fields.
Definition: transport.cc:845
ConvectionTransport::dh_
std::shared_ptr< DOFHandlerMultiDim > dh_
Definition: transport.h:362
bc_multi_field.hh
ConvectionTransport::EqData::output_fields
EquationOutput output_fields
Fields indended for output, i.e. all input fields plus those representing solution.
Definition: transport.h:146
field_values.hh
TimeMark::Type
Definition: time_marks.hh:60
ConvectionTransport::subst_idx
vector< unsigned int > subst_idx
List of indices used to call balance methods for a set of quantities.
Definition: transport.h:365
ConvectionTransport::EqData::bc_conc
BCMultiField< 3, FieldValue< 3 >::Scalar > bc_conc
Definition: transport.h:134
OutputTime
The class for outputting data during time.
Definition: output_time.hh:51
QGauss::array
std::array< QGauss, 4 > array
Definition: quadrature_lib.hh:36
ConvectionTransport
Definition: transport.h:119
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
FETransportObjects
Definition: transport.h:82
FETransportObjects::fe3_
FiniteElement< 3 > * fe3_
Definition: transport.h:105
ConvectionTransport::substances_
SubstanceList substances_
Transported substances.
Definition: transport.h:355
FiniteElement
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Definition: discrete_space.hh:26
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
ConvectionTransport::tm
Mat tm
Definition: transport.h:326
ConvectionTransport::EqData::subdomain
Field< 3, FieldValue< 3 >::Scalar > subdomain
Definition: transport.h:140
ConvectionTransport::get_component_vec
Vec get_component_vec(unsigned int sbi) override
Return PETSc vector with solution for sbi-th substance.
Definition: transport.cc:220
ConvectionTransport::get_p0_interpolation
FieldFEScalarVec & get_p0_interpolation() override
Getter for P0 interpolation by FieldFE.
Definition: transport.cc:825
LongIdx
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: index_types.hh:24
BCMultiField
Definition: bc_multi_field.hh:29
ConcentrationTransportBase
Definition: transport_operator_splitting.hh:61
ConvectionTransport::is_src_term_scaled
bool is_src_term_scaled
Definition: transport.h:308
Mesh
Definition: mesh.h:98
ConvectionTransport::make_transport_partitioning
void make_transport_partitioning()
Definition: transport.cc:229
TransportOperatorSplitting
Coupling of a transport model with a reaction model by operator splitting.
Definition: transport_operator_splitting.hh:211
multi_field.hh
ConvectionTransport::target_mark_type
TimeMark::Type target_mark_type
TimeMark type for time marks denoting end of every time interval where transport matrix remains const...
Definition: transport.h:317
ConvectionTransport::el_4_loc
LongIdx * el_4_loc
Definition: transport.h:351
MultiField
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:87
ConvectionTransport::update_solution
void update_solution() override
Definition: transport.cc:580
region.hh
FETransportObjects::fe2_
FiniteElement< 2 > * fe2_
Definition: transport.h:104
ConvectionTransport::get_subst_idx
const vector< unsigned int > & get_subst_idx() override
Return substance indices used in balance.
Definition: transport.h:214
ConvectionTransport::ConvectionTransport
ConvectionTransport(Mesh &init_mesh, const Input::Record in_rec)
Definition: transport.cc:158
ConvectionTransport::get_par_info
void get_par_info(LongIdx *&el_4_loc, Distribution *&el_ds) override
Return array of indices of local elements and parallel distribution of elements.
Definition: transport.cc:829
ConvectionTransport::set_target_time
void set_target_time(double target_time) override
Definition: transport.cc:683
ConvectionTransport::get_output_selection
static const IT::Selection & get_output_selection()
ConvectionTransport::set_output_stream
void set_output_stream(std::shared_ptr< OutputTime > stream) override
Setter for output stream.
Definition: transport.h:222
time_marks.hh
ConvectionTransport::alloc_transport_vectors
void alloc_transport_vectors()
Definition: transport.cc:319
ConvectionTransport::EqData::~EqData
virtual ~EqData()
Definition: transport.h:125
ConvectionTransport::vconc_out_scatter
VecScatter vconc_out_scatter
Definition: transport.h:325
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:95
ConvectionTransport::tm_diag
double ** tm_diag
Definition: transport.h:330
TransportEqFields
Definition: transport_operator_splitting.hh:143
Quadrature
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
ConvectionTransport::vpconc
Vec * vpconc
Definition: transport.h:339
ConvectionTransport::cfl_max_step
double cfl_max_step
Time step constraint coming from CFL condition.
Definition: transport.h:318
ConvectionTransport::initialize
void initialize() override
Definition: transport.cc:181
FETransportObjects::q_
QGauss::array q_
Quadratures used in assembling methods.
Definition: transport.h:108
transport_operator_splitting.hh
ConvectionTransport::corr_vec
vector< VectorMPI > corr_vec
Definition: transport.h:314
ConvectionTransport::cfl_flow_
double * cfl_flow_
Definition: transport.h:322
field.hh
FETransportObjects::fe
FiniteElement< dim > * fe()
ConvectionTransport::EqData::region_id
Field< 3, FieldValue< 3 >::Scalar > region_id
Definition: transport.h:139
ConvectionTransport::transport_matrix_step_mpi
void transport_matrix_step_mpi(double time_step)
ConcentrationTransportBase::FieldFEScalarVec
std::vector< std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > > FieldFEScalarVec
Definition: transport_operator_splitting.hh:64
ConvectionTransport::compute_p0_interpolation
void compute_p0_interpolation() override
Definition: transport.h:186
ConvectionTransport::create_transport_matrix_mpi
void create_transport_matrix_mpi()
Definition: transport.cc:742