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