Flow123d  JS_before_hm-927-g0a4a2b5
transport_dg.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_dg.hh
15  * @brief Discontinuous Galerkin method for equation of transport with dispersion.
16  * @author Jan Stebel
17  */
18 
19 #ifndef TRANSPORT_DG_HH_
20 #define TRANSPORT_DG_HH_
21 
22 #include <math.h> // for fabs
23 #include <string.h> // for memcpy
24 #include <algorithm> // for max
25 #include <boost/exception/info.hpp> // for operator<<, error_info...
26 #include <string> // for operator<<
27 #include <vector> // for vector
28 #include <armadillo>
29 #include "fem/update_flags.hh" // for operator|
30 #include "fields/field_values.hh" // for FieldValue<>::Scalar
31 #include "fields/field.hh"
32 #include "fields/multi_field.hh"
33 #include "la/vector_mpi.hh"
35 #include "la/linsys.hh"
36 #include "input/accessors.hh" // for ExcAccessorForNullStorage
37 #include "input/accessors_impl.hh" // for Record::val
38 #include "input/storage.hh" // for ExcStorageTypeMismatch
39 #include "input/type_base.hh" // for Array
40 #include "input/type_generic.hh" // for Instance
41 #include "input/type_record.hh" // for Record::ExcRecordKeyNo...
42 #include "system/index_types.hh" // for LongIdx
43 #include "mesh/accessors.hh" // for ElementAccessor, SIdeIter
44 #include "mesh/elements.h" // for Element::dim, Element:...
45 #include "mesh/neighbours.h" // for Neighbour::element
46 #include "mpi.h" // for MPI_Comm_rank
47 #include "petscmat.h" // for Mat, MatDestroy
48 #include "petscvec.h" // for Vec, VecDestroy, VecSc...
49 #include "transport/concentration_model.hh" // for ConcentrationTransport...
50 #include "transport/heat_model.hh" // for HeatTransferModel, Hea...
51 #include "tools/mixed.hh"
52 class DiscreteSpace;
53 class Distribution;
54 class OutputTime;
55 class DOFHandlerMultiDim;
56 template<unsigned int dim, class Model> class AssemblyDG;
57 template<unsigned int dim, class Model> class MassAssemblyDG;
58 template<unsigned int dim, class Model> class StiffnessAssemblyDG;
59 template<unsigned int dim, class Model> class SourcesAssemblyDG;
60 template<unsigned int dim, class Model> class BdrConditionAssemblyDG;
61 template<unsigned int dim, class Model> class InitConditionAssemblyDG;
62 template< template<IntDim...> class DimAssembly> class GenericAssembly;
63 template<unsigned int dim, unsigned int spacedim> class FEValuesBase;
64 template<unsigned int dim> class FiniteElement;
65 template<unsigned int dim, unsigned int spacedim> class Mapping;
66 class Quadrature;
67 namespace Input { namespace Type { class Selection; } }
68 class ElementCacheMap;
69 
70 /*class FEObjects {
71 public:
72 
73  inline FEObjects(Mesh *mesh_, unsigned int fe_order)
74  {
75  fe = MixedPtr<FE_P_disc>(fe_order);
76  fe_rt = MixedPtr<FE_RT0>();
77  q = MixedPtr<QGauss>(2*fe_order);
78 
79  auto ds = std::make_shared<EqualOrderDiscreteSpace>(mesh_, fe);
80  dh = std::make_shared<DOFHandlerMultiDim>(*mesh_);
81  dh->distribute_dofs(ds_);
82  }
83 
84  ~FEObjects();
85 
86  MixedPtr<FiniteElement> fe;
87  MixedPtr<FiniteElement> fe_rt;
88  MixedPtr<Quadrature> q;
89 
90  /// Object for distribution of dofs.
91  std::shared_ptr<DOFHandlerMultiDim> dh;
92 };*/
93 
94 
95 
96 /**
97  * @brief Transport with dispersion implemented using discontinuous Galerkin method.
98  *
99  * TransportDG implements the discontinuous Galerkin method for the transport and diffusion of substances.
100  * The concentration @f$ c_i ~[kg/m^3]@f$ of the i-th substance is governed by the advection-diffusion equation
101  * @f[
102  * \partial_t c_i + \mathbf v\cdot\nabla c_i - \mathrm{div}(D\nabla c_i) = F \mbox{ in }\Omega^d,
103  * @f]
104  * where @f$\mathbf v@f$ is the fluid velocity and @f$\Omega^d@f$ the @f$d@f$-dimensional domain, respectively.
105  * The hydrodynamic dispersivity tensor @f$\mathbf D ~[m^2/s]@f$ is given by:
106  * @f[
107  * \mathbf D = D_m\mathbf I + |\mathbf v|\left(\alpha_T\mathbf I + (\alpha_L-\alpha_T)\frac{\mathbf v\otimes\mathbf v}{|\mathbf v|^2}\right).
108  * @f]
109  * The molecular dispersivity @f$D_m~[m^2/s]@f$, as well as the longitudal and transversal dispersivity @f$\alpha_L,~\alpha_T~[m]@f$ are input parameters of the model.
110  *
111  * For lower dimensions @f$d=1,2@f$ the advection-diffusion equation is multiplied by the fracture cross-cut @f$\delta^d~[m^{3-d}]@f$.
112  *
113  * The boundary @f$\partial\Omega^d@f$ is divided into three disjoint parts @f$\Gamma^d_D\cup\Gamma^d_N\cup\Gamma^d_F@f$.
114  * We prescribe the following boundary conditions:
115  * @f{eqnarray*}{
116  * c_i^d &= c_{iD}^d &\mbox{ on }\Gamma^d_D \mbox{ (Dirichlet)},\\
117  * \mathbf D^d\nabla c_i^d\cdot\mathbf n &= 0 &\mbox{ on }\Gamma^d_N \mbox{ (Neumann)},
118  * @f}
119  * The transfer of mass through fractures is described by the transmission conditions on @f$\Gamma^d_F@f$:
120  * @f[
121  * -\mathbf D^d\nabla c_i^d\cdot\mathbf n = \sigma(c_i^d-c_i^{d-1}) + \left\{\begin{array}{cl}0 &\mbox{ if }\mathbf v^d\cdot\mathbf n\ge 0\\\mathbf v^d\cdot\mathbf n(c_i^{d-1}-c_i^d) & \mbox{ if }\mathbf v^d\cdot\mathbf n<0\end{array}\right.,\qquad
122  * F^{d-1} = (\sigma + |\mathbf v^d\cdot\mathbf n|)(c_i^d-c_i^{d-1}).
123  * @f]
124  * Here @f$\mathbf n@f$ stands for the unit outward normal vector to @f$\partial\Omega^d@f$.
125  * The coefficient @f$\sigma@f$ determines the transfer of mass through fractures due to diffusion.
126  *
127  * @ingroup transport_mod
128  *
129  */
130 template<class Model>
131 class TransportDG : public Model
132 {
133 public:
134 
135  template<unsigned int dim> using MassAssemblyDim = MassAssemblyDG<dim, Model>;
136  template<unsigned int dim> using StiffnessAssemblyDim = StiffnessAssemblyDG<dim, Model>;
137  template<unsigned int dim> using SourcesAssemblyDim = SourcesAssemblyDG<dim, Model>;
140 
141  class EqData : public Model::ModelEqData {
142  public:
143 
144  EqData();
145 
146  /**
147  * @brief Sets up parameters of the DG method on a given boundary edge.
148  *
149  * Assumption is that the edge consists of only 1 side.
150  * @param side The boundary side.
151  * @param K_size Size of vector of tensors K.
152  * @param K Dispersivity tensor.
153  * @param ad_vector Advection vector.
154  * @param normal_vector Normal vector (assumed constant along the edge).
155  * @param alpha Penalty parameter that influences the continuity
156  * of the solution (large value=more continuity).
157  * @param gamma Computed penalty parameters.
158  */
159  void set_DG_parameters_boundary(Side side,
160  const int K_size,
161  const std::vector<arma::mat33> &K,
162  const double flux,
163  const arma::vec3 &normal_vector,
164  const double alpha,
165  double &gamma);
166 
167 
168  /// Compute and return anisotropy of given element
169  double elem_anisotropy(ElementAccessor<3> e) const;
170 
171 
172 
173  MultiField<3, FieldValue<3>::Scalar> fracture_sigma; ///< Transition parameter for diffusive transfer on fractures (for each substance).
174  MultiField<3, FieldValue<3>::Scalar> dg_penalty; ///< Penalty enforcing inter-element continuity of solution (for each substance).
177 
179 
180 
181  /// @name Parameters of the numerical method
182  // @{
183 
184  /// Penalty parameters.
186 
187  /// DG variant ((non-)symmetric/incomplete
189 
190  /// Polynomial order of finite elements.
191  unsigned int dg_order;
192 
193  // @}
194 
195 
196  /// Auxiliary vectors for calculation of sources in balance due to retardation (e.g. sorption).
198 
199  /// Linear algebra system for the transport equation.
201 
202  /// Linear algebra system for the time derivative (actually it is used only for handling the matrix structures).
204 
205  /// @name Auxiliary fields used during assembly
206  // @{
207 
208  /// Advection coefficients.
210  /// Diffusion coefficients.
212  /// Advection coefficients on edges.
214  /// Diffusion coefficients on edges.
216 
217  // @}
218 
219  /// Object for distribution of dofs.
220  std::shared_ptr<DOFHandlerMultiDim> dh_;
221 
222  /// general assembly objects, hold assembly objects of appropriate dimension
228  };
229 
230 
231 
232  enum DGVariant {
233  // Non-symmetric weighted interior penalty DG
234  non_symmetric = -1,
235 
236  // Incomplete weighted interior penalty DG
237  incomplete = 0,
238 
239  // Symmetric weighted interior penalty DG
240  symmetric = 1
241  };
242 
243  /**
244  * @brief Constructor.
245  * @param init_mesh computational mesh
246  * @param in_rec input record
247  */
248  TransportDG(Mesh &init_mesh, const Input::Record in_rec);
249  /**
250 
251  * @brief Declare input record type for the equation TransportDG.
252  */
253  static const Input::Type::Record & get_input_type();
254 
255  /**
256  * @brief Input type for the DG variant selection.
257  */
258  static const Input::Type::Selection & get_dg_variant_selection_input_type();
259 
260  /**
261  * @brief Initialize solution in the zero time.
262  */
263  void zero_time_step() override;
264 
266  { return false; }
267 
268  /**
269  * @brief Computes the solution in one time instant.
270  */
271  void update_solution() override;
272 
273  /**
274  * @brief Postprocesses the solution and writes to output file.
275  */
276  void output_data();
277 
278  /**
279  * @brief Destructor.
280  */
281  ~TransportDG() override;
282 
283  void initialize() override;
284 
285  void calculate_cumulative_balance();
286 
287  const Vec &get_solution(unsigned int sbi)
288  { return data_->ls[sbi]->get_solution(); }
289 
291  { return solution_elem_; }
292 
293  void calculate_concentration_matrix();
294 
295  void update_after_reactions(bool solution_changed);
296 
297  void get_par_info(LongIdx * &el_4_loc, Distribution * &el_ds);
298 
299  LongIdx *get_row_4_el();
300 
301  /// Access to balance object of Model
302  inline std::shared_ptr<Balance> balance() const {
303  return Model::balance_;
304  }
305 
306  /// Return vector of substances indices
307  inline const vector<unsigned int> subst_idx() const {
308  return Model::subst_idx;
309  }
310 
311 
312 
313 
314 private:
315  /// Registrar of class to factory
316  static const int registrar;
317 
318  inline typename Model::ModelEqData &data() { return *data_; }
319 
320  void preallocate();
321 
322  /**
323  * @brief Calculates the dispersivity (diffusivity) tensor from the velocity field.
324  *
325  * @param K The computed dispersivity tensor.
326  * @param velocity The velocity field (at quadrature points).
327  * @param Dm Molecular diffusivities.
328  * @param alphaL Longitudal dispersivities.
329  * @param alphaT Transversal dispersivities.
330  * @param porosity Porosities.
331  * @param cross_cut Cross-cuts of higher dimension.
332  */
333 // void calculate_dispersivity_tensor(arma::mat33 &K, const arma::vec3 &velocity,
334 // double Dm, double alphaL, double alphaT, double porosity,
335 // double cross_cut);
336 
337  /**
338  * @brief Sets the initial condition.
339  *
340  * This method just calls AssemblyDG::prepare_initial_condition() for each elements.
341  */
342  void set_initial_condition();
343 
344 
345 
346  void output_region_statistics();
347 
348 
349 
350  /// @name Physical parameters
351  // @{
352 
353  /// Field data for model parameters.
354  std::shared_ptr<EqData> data_;
355 
356  // @}
357 
358 
359 
360  /// @name Solution of algebraic system
361  // @{
362 
363  /// Vector of right hand side.
365 
366  /// The stiffness matrix.
368 
369  /// The mass matrix.
371 
372  /// Mass from previous time instant (necessary when coefficients of mass matrix change in time).
374 
375  /// Element averages of solution (the array is passed to reactions in operator splitting).
376  double **solution_elem_;
377 
378  // @}
379 
380 
381  /// @name Output to file
382  // @{
383 
384  /// Array for storing the output solution data.
385  //vector<double*> output_solution;
386 
387  /// Vector of solution data.
389 
390  /// Record with input specification.
392 
393  ofstream reg_stat_stream;
394 
395 
396  // @}
397 
398 
399  /// @name Auxiliary fields used during assembly
400  // @{
401 
402  /// Temporary values of increments due to retardation (e.g. sorption)
404 
405  // @}
406 
407 
408 
409 
410  /// @name Other
411  // @{
412 
413  /// Indicates whether matrices have been preallocated.
415 
416  // @}
417 
418 };
419 
420 
421 
422 
423 
424 
425 #endif /* TRANSPORT_DG_HH_ */
GenericAssembly< MassAssemblyDim > * mass_assembly_
general assembly objects, hold assembly objects of appropriate dimension
Input::Record input_rec
Record with input specification.
vector< vector< arma::vec3 > > ad_coef
Advection coefficients.
std::vector< std::vector< double > > gamma
Penalty parameters.
Transport with dispersion implemented using discontinuous Galerkin method.
unsigned int dg_order
Polynomial order of finite elements.
const vector< unsigned int > subst_idx() const
Return vector of substances indices.
Abstract linear system class.
Definition: balance.hh:40
Wrappers for linear systems based on MPIAIJ and MATIS format.
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:92
vector< VectorMPI > output_vec
Array for storing the output solution data.
Directing class of FieldValueCache.
Definition: mesh.h:78
int dg_variant
DG variant ((non-)symmetric/incomplete.
Discontinuous Galerkin method for equation of transport with dispersion.
const Vec & get_solution(unsigned int sbi)
vector< double > ret_sources_prev
MultiField< 3, FieldValue< 3 >::Scalar > dg_penalty
Penalty enforcing inter-element continuity of solution (for each substance).
Enum type UpdateFlags indicates which quantities are to be recomputed on each finite element cell...
EquationOutput output_fields
std::vector< Mat > mass_matrix
The mass matrix.
vector< vector< vector< arma::mat33 > > > dif_coef_edg
Diffusion coefficients on edges.
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
bool evaluate_time_constraint(double &)
GenericAssembly< SourcesAssemblyDim > * sources_assembly_
vector< vector< arma::mat33 > > dif_coef
Diffusion coefficients.
double ** get_concentration_matrix()
MultiField< 3, FieldValue< 3 >::Scalar > fracture_sigma
Transition parameter for diffusive transfer on fractures (for each substance).
GenericAssembly< BdrConditionAssemblyDim > * bdr_cond_assembly_
static const int registrar
Registrar of class to factory.
std::vector< Vec > ret_vec
Auxiliary vectors for calculation of sources in balance due to retardation (e.g. sorption).
LinSys ** ls
Linear algebra system for the transport equation.
Field< 3, FieldValue< 3 >::Scalar > subdomain
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
ofstream reg_stat_stream
Provides the numbering of the finite element degrees of freedom on the computational mesh...
Definition: dofhandler.hh:151
std::vector< Vec > rhs
Vector of right hand side.
Field< 3, FieldValue< 3 >::Scalar > region_id
The class for outputting data during time.
Definition: output_time.hh:50
unsigned int IntDim
A dimension index type.
Definition: mixed.hh:19
double ** solution_elem_
Element averages of solution (the array is passed to reactions in operator splitting).
vector< vector< vector< arma::vec3 > > > ad_coef_edg
Advection coefficients on edges.
Model::ModelEqData & data()
std::vector< Mat > stiffness_matrix
The stiffness matrix.
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: index_types.hh:24
bool allocation_done
Indicates whether matrices have been preallocated.
GenericAssembly< StiffnessAssemblyDim > * stiffness_assembly_
Generic class of assemblation.
Definition: assembly_dg.hh:64
std::shared_ptr< DOFHandlerMultiDim > dh_
Object for distribution of dofs.
std::shared_ptr< Balance > balance() const
Access to balance object of Model.
Discontinuous Galerkin method for equation of transport with dispersion.
std::vector< Vec > mass_vec
Mass from previous time instant (necessary when coefficients of mass matrix change in time)...
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
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
GenericAssembly< InitConditionAssemblyDim > * init_cond_assembly_
LinSys ** ls_dt
Linear algebra system for the time derivative (actually it is used only for handling the matrix struc...
Template for classes storing finite set of named values.
std::shared_ptr< EqData > data_
Field data for model parameters.