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