Flow123d  JS_before_hm-62-ge56f9d5
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 "fem/mapping_p1.hh"
31 #include "fields/field_values.hh" // for FieldValue<>::Scalar
32 #include "fields/field.hh"
33 #include "fields/multi_field.hh"
34 #include "la/vector_mpi.hh"
36 #include "la/linsys.hh"
37 #include "input/accessors.hh" // for ExcAccessorForNullStorage
38 #include "input/accessors_impl.hh" // for Record::val
39 #include "input/storage.hh" // for ExcStorageTypeMismatch
40 #include "input/type_base.hh" // for Array
41 #include "input/type_generic.hh" // for Instance
42 #include "input/type_record.hh" // for Record::ExcRecordKeyNo...
43 #include "mesh/long_idx.hh" // for LongIdx
44 #include "mesh/accessors.hh" // for ElementAccessor, SIdeIter
45 #include "mesh/elements.h" // for Element::dim, Element:...
46 #include "mesh/neighbours.h" // for Neighbour::element
47 #include "mpi.h" // for MPI_Comm_rank
48 #include "petscmat.h" // for Mat, MatDestroy
49 #include "petscvec.h" // for Vec, VecDestroy, VecSc...
50 #include "transport/concentration_model.hh" // for ConcentrationTransport...
51 #include "transport/heat_model.hh" // for HeatTransferModel, Hea...
52 
53 class DiscreteSpace;
54 class Distribution;
55 class OutputTime;
56 class DOFHandlerMultiDim;
57 template<unsigned int dim, unsigned int spacedim> class FEValuesBase;
58 template<unsigned int dim> class FiniteElement;
59 template<unsigned int dim, unsigned int spacedim> class Mapping;
60 class Quadrature;
61 namespace Input { namespace Type { class Selection; } }
62 
63 
64 
65 /**
66  * Auxiliary container class for Finite element and related objects of all dimensions.
67  * Its purpose is to provide templated access to these objects, applicable in
68  * the assembling methods.
69  */
70 class FEObjects {
71 public:
72 
73  FEObjects(Mesh *mesh_, unsigned int fe_order);
74  ~FEObjects();
75 
76  template<unsigned int dim>
77  inline FiniteElement<dim> *fe();
78 
79  template<unsigned int dim>
80  inline FiniteElement<dim> *fe_rt();
81 
82  template<unsigned int dim>
83  inline Quadrature *q() { return q_[dim]; }
84 
85  template<unsigned int dim>
86  inline MappingP1<dim,3> *mapping();
87 
88  inline std::shared_ptr<DOFHandlerMultiDim> dh();
89 
90 private:
91 
92  /// Finite elements for the solution of the advection-diffusion equation.
97 
98  /// Finite elements for the water velocity field.
102 
103  /// Quadratures used in assembling methods.
104  Quadrature *q_[4];
105 
106  /// Auxiliary mappings of reference elements.
110 
111  std::shared_ptr<DiscreteSpace> ds_;
112 
113  /// Object for distribution of dofs.
114  std::shared_ptr<DOFHandlerMultiDim> dh_;
115 };
116 
117 
118 
119 /**
120  * @brief Transport with dispersion implemented using discontinuous Galerkin method.
121  *
122  * TransportDG implements the discontinuous Galerkin method for the transport and diffusion of substances.
123  * The concentration @f$ c_i ~[kg/m^3]@f$ of the i-th substance is governed by the advection-diffusion equation
124  * @f[
125  * \partial_t c_i + \mathbf v\cdot\nabla c_i - \mathrm{div}(D\nabla c_i) = F \mbox{ in }\Omega^d,
126  * @f]
127  * where @f$\mathbf v@f$ is the fluid velocity and @f$\Omega^d@f$ the @f$d@f$-dimensional domain, respectively.
128  * The hydrodynamic dispersivity tensor @f$\mathbf D ~[m^2/s]@f$ is given by:
129  * @f[
130  * \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).
131  * @f]
132  * 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.
133  *
134  * 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$.
135  *
136  * 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$.
137  * We prescribe the following boundary conditions:
138  * @f{eqnarray*}{
139  * c_i^d &= c_{iD}^d &\mbox{ on }\Gamma^d_D \mbox{ (Dirichlet)},\\
140  * \mathbf D^d\nabla c_i^d\cdot\mathbf n &= 0 &\mbox{ on }\Gamma^d_N \mbox{ (Neumann)},
141  * @f}
142  * The transfer of mass through fractures is described by the transmission conditions on @f$\Gamma^d_F@f$:
143  * @f[
144  * -\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
145  * F^{d-1} = (\sigma + |\mathbf v^d\cdot\mathbf n|)(c_i^d-c_i^{d-1}).
146  * @f]
147  * Here @f$\mathbf n@f$ stands for the unit outward normal vector to @f$\partial\Omega^d@f$.
148  * The coefficient @f$\sigma@f$ determines the transfer of mass through fractures due to diffusion.
149  *
150  * @ingroup transport_mod
151  *
152  */
153 template<class Model>
154 class TransportDG : public Model
155 {
156 public:
157 
158  class EqData : public Model::ModelEqData {
159  public:
160 
161  EqData();
162 
163  MultiField<3, FieldValue<3>::Scalar> fracture_sigma; ///< Transition parameter for diffusive transfer on fractures (for each substance).
164  MultiField<3, FieldValue<3>::Scalar> dg_penalty; ///< Penalty enforcing inter-element continuity of solution (for each substance).
167 
169 
170  };
171 
172 
173 
174  enum DGVariant {
175  // Non-symmetric weighted interior penalty DG
176  non_symmetric = -1,
177 
178  // Incomplete weighted interior penalty DG
179  incomplete = 0,
180 
181  // Symmetric weighted interior penalty DG
182  symmetric = 1
183  };
184 
185  /**
186  * @brief Constructor.
187  * @param init_mesh computational mesh
188  * @param in_rec input record
189  */
190  TransportDG(Mesh &init_mesh, const Input::Record in_rec);
191  /**
192 
193  * @brief Declare input record type for the equation TransportDG.
194  */
195  static const Input::Type::Record & get_input_type();
196 
197  /**
198  * @brief Input type for the DG variant selection.
199  */
200  static const Input::Type::Selection & get_dg_variant_selection_input_type();
201 
202  /**
203  * @brief Initialize solution in the zero time.
204  */
205  void zero_time_step() override;
206 
208  { return false; }
209 
210  /**
211  * @brief Computes the solution in one time instant.
212  */
213  void update_solution() override;
214 
215  /**
216  * @brief Postprocesses the solution and writes to output file.
217  */
218  void output_data();
219 
220  /**
221  * @brief Destructor.
222  */
223  ~TransportDG();
224 
225  void initialize() override;
226 
227  void calculate_cumulative_balance();
228 
229  const Vec &get_solution(unsigned int sbi)
230  { return ls[sbi]->get_solution(); }
231 
233  { return solution_elem_; }
234 
235  void calculate_concentration_matrix();
236 
237  void update_after_reactions(bool solution_changed);
238 
239  void get_par_info(LongIdx * &el_4_loc, Distribution * &el_ds);
240 
241  LongIdx *get_row_4_el();
242 
243 
244 
245 
246 private:
247  /// Registrar of class to factory
248  static const int registrar;
249 
250  inline typename Model::ModelEqData &data() { return data_; }
251 
252  void preallocate();
253 
254  /**
255  * @brief Assembles the mass matrix.
256  *
257  * The routine just calls templated method assemble_mass_matrix() for each
258  * space dimension.
259  */
260  void assemble_mass_matrix();
261 
262  /**
263  * @brief Assembles the mass matrix for the given dimension.
264  */
265  template<unsigned int dim>
266  void assemble_mass_matrix();
267 
268  /**
269  * @brief Assembles the stiffness matrix.
270  *
271  * This routine just calls assemble_volume_integrals(), assemble_fluxes_boundary(),
272  * assemble_fluxes_element_element() and assemble_fluxes_element_side() for each
273  * space dimension.
274  */
275  void assemble_stiffness_matrix();
276 
277  /**
278  * @brief Assembles the volume integrals into the stiffness matrix.
279  */
280  template<unsigned int dim>
281  void assemble_volume_integrals();
282 
283  /**
284  * @brief Assembles the right hand side due to volume sources.
285  *
286  * This method just calls set_sources() for each space dimension.
287  */
288  void set_sources();
289 
290  /**
291  * @brief Assembles the right hand side vector due to volume sources.
292  */
293  template<unsigned int dim>
294  void set_sources();
295 
296  /**
297  * @brief Assembles the fluxes on the boundary.
298  */
299  template<unsigned int dim>
300  void assemble_fluxes_boundary();
301 
302  /**
303  * @brief Assembles the fluxes between elements of the same dimension.
304  */
305  template<unsigned int dim>
306  void assemble_fluxes_element_element();
307 
308  /**
309  * @brief Assembles the fluxes between elements of different dimensions.
310  */
311  template<unsigned int dim>
312  void assemble_fluxes_element_side();
313 
314 
315  /**
316  * @brief Assembles the r.h.s. components corresponding to the Dirichlet boundary conditions.
317  *
318  * The routine just calls templated method set_boundary_condition() for each space dimension.
319  */
320  void set_boundary_conditions();
321 
322  /**
323  * @brief Assembles the r.h.s. components corresponding to the Dirichlet boundary conditions
324  * for a given space dimension.
325  */
326  template<unsigned int dim>
327  void set_boundary_conditions();
328 
329  /**
330  * @brief Calculates the velocity field on a given @p dim dimensional cell.
331  *
332  * @param cell The cell.
333  * @param velocity The computed velocity field (at quadrature points).
334  * @param fv The FEValues class providing the quadrature points
335  * and the shape functions for velocity.
336  */
337  template<unsigned int dim>
338  void calculate_velocity(const ElementAccessor<3> &cell, std::vector<arma::vec3> &velocity, FEValuesBase<dim,3> &fv);
339 
340  /**
341  * @brief Calculates the dispersivity (diffusivity) tensor from the velocity field.
342  *
343  * @param K The computed dispersivity tensor.
344  * @param velocity The velocity field (at quadrature points).
345  * @param Dm Molecular diffusivities.
346  * @param alphaL Longitudal dispersivities.
347  * @param alphaT Transversal dispersivities.
348  * @param porosity Porosities.
349  * @param cross_cut Cross-cuts of higher dimension.
350  */
351 // void calculate_dispersivity_tensor(arma::mat33 &K, const arma::vec3 &velocity,
352 // double Dm, double alphaL, double alphaT, double porosity,
353 // double cross_cut);
354 
355  /**
356  * @brief Sets up parameters of the DG method on a given boundary edge.
357  *
358  * Assumption is that the edge consists of only 1 side.
359  * @param side The boundary side.
360  * @param K_size Size of vector of tensors K.
361  * @param K Dispersivity tensor.
362  * @param ad_vector Advection vector.
363  * @param normal_vector Normal vector (assumed constant along the edge).
364  * @param alpha Penalty parameter that influences the continuity
365  * of the solution (large value=more continuity).
366  * @param gamma Computed penalty parameters.
367  */
368  void set_DG_parameters_boundary(Side side,
369  const int K_size,
370  const std::vector<arma::mat33> &K,
371  const double flux,
372  const arma::vec3 &normal_vector,
373  const double alpha,
374  double &gamma);
375 
376 
377  /**
378  * @brief Sets the initial condition.
379  */
380  void set_initial_condition();
381 
382  /**
383  * @brief Assembles the auxiliary linear system to calculate the initial solution
384  * as L^2-projection of the prescribed initial condition.
385  */
386  template<unsigned int dim>
387  void prepare_initial_condition();
388 
389 
390  void output_region_statistics();
391 
392 
393 
394  /// @name Physical parameters
395  // @{
396 
397  /// Field data for model parameters.
399 
400  // @}
401 
402 
403  /// @name Parameters of the numerical method
404  // @{
405 
406  /// Finite element objects
408 
409  /// Penalty parameters.
411 
412  /// DG variant ((non-)symmetric/incomplete
414 
415  /// Polynomial order of finite elements.
416  unsigned int dg_order;
417 
418  // @}
419 
420 
421 
422  /// @name Solution of algebraic system
423  // @{
424 
425  /// Vector of right hand side.
427 
428  /// The stiffness matrix.
430 
431  /// The mass matrix.
433 
434  /// Mass from previous time instant (necessary when coefficients of mass matrix change in time).
436 
437  /// Auxiliary vectors for calculation of sources in balance due to retardation (e.g. sorption).
439 
440  /// Linear algebra system for the transport equation.
442 
443  /// Linear algebra system for the time derivative (actually it is used only for handling the matrix structures).
445 
446  /// Element averages of solution (the array is passed to reactions in operator splitting).
447  double **solution_elem_;
448 
449  // @}
450 
451 
452  /// @name Output to file
453  // @{
454 
455  /// Array for storing the output solution data.
456  //vector<double*> output_solution;
457 
458  /// Vector of solution data.
460 
461  /// Record with input specification.
463 
464  ofstream reg_stat_stream;
465 
466 
467  // @}
468 
469 
470  /// @name Auxiliary fields used during assembly
471  // @{
472 
473  /// Mass matrix coefficients.
475  /// Retardation coefficient due to sorption.
477  /// Temporary values of increments due to retardation (e.g. sorption)
479  /// Advection coefficients.
481  /// Diffusion coefficients.
483  /// Advection coefficients on edges.
485  /// Diffusion coefficients on edges.
487 
488  // @}
489 
490 
491 
492 
493  /// @name Other
494  // @{
495 
496  /// Indicates whether matrices have been preallocated.
498 
499  // @}
500 };
501 
502 
503 
504 
505 
506 
507 #endif /* TRANSPORT_DG_HH_ */
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: long_idx.hh:22
Input::Record input_rec
Record with input specification.
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell...
FiniteElement< 2 > * fe_rt2_
vector< double > mm_coef
Mass matrix coefficients.
MappingP1< 3, 3 > * map3_
Transport with dispersion implemented using discontinuous Galerkin method.
Abstract linear system class.
Definition: balance.hh:37
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:83
vector< VectorMPI > output_vec
Array for storing the output solution data.
int dg_variant
DG variant ((non-)symmetric/incomplete.
Definition: mesh.h:76
vector< vector< arma::vec3 > > ad_coef
Advection coefficients.
vector< vector< vector< arma::mat33 > > > dif_coef_edg
Diffusion coefficients on edges.
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.
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
vector< vector< double > > ret_coef
Retardation coefficient due to sorption.
bool evaluate_time_constraint(double &)
vector< vector< vector< arma::vec3 > > > ad_coef_edg
Advection coefficients on edges.
double ** get_concentration_matrix()
FiniteElement< 0 > * fe0_
Finite elements for the solution of the advection-diffusion equation.
Definition: transport_dg.hh:93
MultiField< 3, FieldValue< 3 >::Scalar > fracture_sigma
Transition parameter for diffusive transfer on fractures (for each substance).
vector< vector< arma::mat33 > > dif_coef
Diffusion coefficients.
FEObjects * feo
Finite element objects.
static const int registrar
Registrar of class to factory.
FiniteElement< 2 > * fe2_
Definition: transport_dg.hh:95
Abstract class for the mapping between reference and actual cell.
Definition: fe_values.hh:38
Quadrature * q()
Definition: transport_dg.hh:83
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::shared_ptr< DiscreteSpace > ds_
std::vector< Vec > rhs
Vector of right hand side.
Field< 3, FieldValue< 3 >::Scalar > region_id
unsigned int dg_order
Polynomial order of finite elements.
The class for outputting data during time.
Definition: output_time.hh:50
FiniteElement< 1 > * fe_rt1_
Finite elements for the water velocity field.
Definition: transport_dg.hh:99
MappingP1< 2, 3 > * map2_
double ** solution_elem_
Element averages of solution (the array is passed to reactions in operator splitting).
Model::ModelEqData & data()
std::vector< Mat > stiffness_matrix
The stiffness matrix.
EqData data_
Field data for model parameters.
bool allocation_done
Indicates whether matrices have been preallocated.
std::vector< std::vector< double > > gamma
Penalty parameters.
FiniteElement< 1 > * fe1_
Definition: transport_dg.hh:94
std::vector< Vec > ret_vec
Auxiliary vectors for calculation of sources in balance due to retardation (e.g. sorption).
FiniteElement< 3 > * fe3_
Definition: transport_dg.hh:96
FiniteElement< 3 > * fe_rt3_
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:87
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Base class for FEValues and FESideValues.
Definition: fe_values.hh:37
MappingP1< 1, 3 > * map1_
Auxiliary mappings of reference elements.
LinSys ** ls
Linear algebra system for the transport equation.
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< DOFHandlerMultiDim > dh_
Object for distribution of dofs.