Flow123d  JS_before_hm-2074-g7860a8b45
darcy_flow_lmh.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 darcy_flow_lmh.hh
15  * @brief Lumped mixed-hybrid model of linear Darcy flow, possibly unsteady.
16  * @author Jan Brezina
17  *
18  * Main object for mixed-hybrid discretization of the linear elliptic PDE (Laplace)
19  * on a multidimensional domain. Discretization of saturated Darcy flow using
20  * RT0 approximation for the velocity
21  */
22 
23 /*
24  * list of files dependent on this one:
25  *
26  * posprocess.cc
27  * problem.cc
28  * main.hh
29  * transport.cc
30  */
31 
32 
33 #ifndef DARCY_FLOW_LMH_HH
34 #define DARCY_FLOW_LMH_HH
35 
36 #include <petscmat.h> // for Mat
37 #include <string.h> // for memcpy
38 #include <algorithm> // for swap
39 
40 #include <memory> // for shared_ptr, allocator...
41 #include <new> // for operator new[]
42 #include <string> // for string, operator<<
43 #include <vector> // for vector, vector<>::con...
44 #include <armadillo>
45 #include "fields/bc_field.hh" // for BCField
46 #include "fields/field.hh" // for Field
47 #include "fields/field_set.hh" // for FieldSet
48 #include "fields/field_values.hh" // for FieldValue<>::Scalar
49 #include "flow/darcy_flow_interface.hh" // for DarcyFlowInterface
50 #include "input/input_exception.hh" // for DECLARE_INPUT_EXCEPTION
51 #include "input/type_base.hh" // for Array
52 #include "input/type_generic.hh" // for Instance
53 #include "mesh/mesh.h" // for Mesh
54 #include "petscvec.h" // for Vec, _p_Vec, VecScatter
55 #include "system/exceptions.hh" // for ExcStream, operator<<
56 #include "tools/time_governor.hh" // for TimeGovernor
57 #include "la/vector_mpi.hh" // for VectorMPI
58 
59 #include "flow/darcy_flow_mh.hh" // for DarcyMH::EqData
60 
61 class Balance;
62 class DarcyFlowMHOutput;
63 class Element;
64 class Intersection;
65 class LinSys;
66 // class LinSys_BDDC;
67 class LocalSystem;
68 namespace Input {
69  class AbstractRecord;
70  class Record;
71  namespace Type {
72  class Record;
73  class Selection;
74  }
75 }
76 
77 template<int spacedim, class Value> class FieldAddPotential;
78 
79 /**
80  * @brief Mixed-hybrid model of linear Darcy flow, possibly unsteady.
81  *
82  * Abstract class for various implementations of Darcy flow. In future there should be
83  * one further level of abstraction for general time dependent problem.
84  *
85  * maybe TODO:
86  * split compute_one_step to :
87  * 1) prepare_next_timestep
88  * 2) actualize_solution - this is for iterative nonlinear solvers
89  *
90  */
91 
92 
93 /**
94  * @brief Mixed-hybrid of steady Darcy flow with sources and variable density.
95  *
96  * solve equations:
97  * @f[
98  * q= -{\mathbf{K}} \nabla h -{\mathbf{K}} R \nabla z
99  * @f]
100  * @f[
101  * \mathrm{div} q = f
102  * @f]
103  *
104  * where
105  * - @f$ q @f$ is flux @f$[ms^{-1}]@f$ for 3d, @f$[m^2s^{-1}]@f$ for 2d and @f$[m^3s^{-1}]@f$ for 1d.
106  * - @f$ \mathbf{K} @f$ is hydraulic tensor ( its orientation for 2d, 1d case is questionable )
107  * - @f$ h = \frac{\pi}{\rho_0 g}+z @f$ is pressure head, @f$ \pi, \rho_0, g @f$ are the pressure, water density, and acceleration of gravity , respectively.
108  * Assumes gravity force acts counter to the direction of the @f$ z @f$ axis.
109  * - @f$ R @f$ is destity or gravity variability coefficient. For density driven flow it should be
110  * @f[
111  * R = \frac{\rho}{\rho_0} -1 = \rho_0^{-1}\sum_{i=1}^s c_i
112  * @f]
113  * where @f$ c_i @f$ is concentration in @f$ kg m^{-3} @f$.
114  *
115  * The time key is optional, when not specified the equation is forced to steady regime. Using Steady TimeGovernor which have no dt constraints.
116  *
117  *
118  * TODO:
119  * Make solution regular field (need FeSeystem and parallel DofHandler for edge pressures), then remove get_solution_vector from
120  * Equation interface.
121  */
122 /**
123  * Model for transition coefficients due to Martin, Jaffre, Roberts (see manual for full reference)
124  *
125  * TODO:
126  * - how we can reuse field values computed during assembly
127  *
128  */
129 
131 {
132 public:
133  TYPEDEF_ERR_INFO( EI_Reason, string);
134  DECLARE_EXCEPTION(ExcSolverDiverge,
135  << "Diverged nonlinear solver. Reason: " << EI_Reason::val
136  );
137  DECLARE_INPUT_EXCEPTION(ExcMissingTimeGovernor,
138  << "Missing the key 'time', obligatory for the transient problems.");
139 
140  /** Class with all fields used in the equation DarcyFlow.
141  * This is common to all implementations since this provides interface
142  * to this equation for possible coupling.
143  *
144  * This class is derived from DarcyMH::EqData especially due to the common output class DarcyFlowMHOutput.
145  * This is the only dependence between DarcyMH and DarcyLMH classes.
146  * It is also base class of RichardsLMH::EqData.
147  * */
148  class EqData : public DarcyMH::EqData {
149  public:
150 
151  EqData();
152 
153  std::shared_ptr<SubDOFHandlerMultiDim> dh_p_; ///< DOF handler represents DOFs of element pressure
154 
155  // Propagate test for the time term to the assembly.
156  // This flag is necessary for switching BC to avoid setting zero neumann on the whole boundary in the steady case.
158 
159  // for time term assembly
160  double time_step_;
161 
162  std::shared_ptr<LinSys> lin_sys_schur; //< Linear system of the 2. Schur complement.
163  VectorMPI p_edge_solution; //< 2. Schur complement solution
164  VectorMPI p_edge_solution_previous; //< 2. Schur complement previous solution (iterative)
165  VectorMPI p_edge_solution_previous_time; //< 2. Schur complement previous solution (time)
166 
168  };
169 
170  /// Selection for enum MortarMethod.
172 
173 
174 
175 
176 
177  DarcyLMH(Mesh &mesh, const Input::Record in_rec, TimeGovernor *tm = nullptr);
178 
180  static const Input::Type::Record & get_input_type();
181 
182  void init_eq_data();
183  void initialize() override;
184  virtual void initialize_specific();
185  void zero_time_step() override;
186  void update_solution() override;
187 
188  /// Solve the problem without moving to next time and without output.
189  void solve_time_step(bool output = true);
190 
191  /// postprocess velocity field (add sources)
192  virtual void accept_time_step();
193  virtual void postprocess();
194  virtual void output_data() override;
195 
196 
197  EqData &data() { return *data_; }
198 
199  /// Sets external storarivity field (coupling with other equation).
201  { data_->extra_storativity = extra_stor; }
202 
203  /// Sets external source field (coupling with other equation).
204  void set_extra_source(const Field<3, FieldValue<3>::Scalar> &extra_src)
205  { data_->extra_source = extra_src; }
206 
207  virtual ~DarcyLMH() override;
208 
209 
210 protected:
211  /**
212  * Returns true is the fields involved in the time term have values that makes the time term zero.
213  * For time_global==true, it returns true if there are no field descriptors in the input list, so the
214  * fields )of the time ter) have their default values for whole simulation.
215  * If time_global==false (default), only the actual values are considered.
216  */
217  virtual bool zero_time_term(bool time_global=false);
218 
219  /// Solve method common to zero_time_step and update solution.
220  void solve_nonlinear();
221 
222  /**
223  * Create and preallocate MH linear system (including matrix, rhs and solution vectors)
224  */
226 
227  /**
228  * Read initial condition into solution vector.
229  * Must be called after create_linear_system.
230  *
231  * For the LMH scheme we have to be able to save edge pressures in order to
232  * restart simulation or use results of one simulation as initial condition for other one.
233  */
234  void read_initial_condition();
235 
236  /**
237  * In some circumstances, the intial condition must be processed.
238  * It is called at the end of @p read_initial_condition().
239  * This is used in Richards equation due the update of water content.
240  */
241  virtual void initial_condition_postprocess();
242 
243  /**
244  * Allocates linear system matrix for MH.
245  * TODO:
246  * - use general preallocation methods in DofHandler
247  */
248  void allocate_mh_matrix();
249 
250  /**
251  * Assembles linear system matrix for MH.
252  * Element by element assembly is done using dim-template assembly class.
253  * Assembles only steady part of the equation.
254  * TODO:
255  * - include time term - DONE
256  * - add support for Robin type sources
257  * - support for nonlinear solvers - assembly either residual vector, matrix, or both (using FADBAD++)
258  */
259  void assembly_mh_matrix(MultidimAssembly& assembler);
260 
262 
263  /**
264  * Assembly or update whole linear system.
265  */
266  virtual void assembly_linear_system();
267 
268 // void set_mesh_data_for_bddc(LinSys_BDDC * bddc_ls);
269  /**
270  * Return a norm of residual vector.
271  * TODO: Introduce Equation::compute_residual() updating
272  * residual field, standard part of EqData.
273  */
274  virtual double solution_precision() const;
275 
276  /// Print darcy flow matrix in matlab format into a file.
277  void print_matlab_matrix(string matlab_file);
278 
279  /// Get vector of all DOF indices of given component (0..side, 1..element, 2..edge)
280  std::vector<int> get_component_indices_vec(unsigned int component) const;
281 
282  /// Getter for the linear system of the 2. Schur complement.
284  { return *(data_->lin_sys_schur); }
285 
286  std::shared_ptr<Balance> balance_;
287 
289 
290  int size; // global size of MH matrix
291 
293 
294  // Setting of the nonlinear solver. TODO: Move to the solver class later on.
295  double tolerance_;
296  unsigned int min_n_it_;
297  unsigned int max_n_it_;
298  unsigned int nonlinear_iteration_; //< Actual number of completed nonlinear iterations, need to pass this information into assembly.
299 
300  std::shared_ptr<EqData> data_;
301 
302  friend class DarcyFlowMHOutput;
303  //friend class P0_CouplingAssembler;
304  //friend class P1_CouplingAssembler;
305 
306 private:
307  /// Registrar of class to factory
308  static const int registrar;
309 };
310 
311 #endif //DARCY_FLOW_LMH_HH
312 //-----------------------------------------------------------------------------
313 // vim: set cindent:
314 
bc_field.hh
DarcyLMH::print_matlab_matrix
void print_matlab_matrix(string matlab_file)
Print darcy flow matrix in matlab format into a file.
Definition: darcy_flow_lmh.cc:1069
DarcyLMH::zero_time_term
virtual bool zero_time_term(bool time_global=false)
Definition: darcy_flow_lmh.cc:554
DarcyLMH::reconstruct_solution_from_schur
void reconstruct_solution_from_schur(MultidimAssembly &assembler)
Definition: darcy_flow_lmh.cc:1007
LinSys
Definition: la_linsys_new.hh:169
vector_mpi.hh
DarcyLMH::output_object
DarcyFlowMHOutput * output_object
Definition: darcy_flow_lmh.hh:288
time_governor.hh
Basic time management class.
LocalSystem
Definition: local_system.hh:45
DarcyLMH::EqData
Definition: darcy_flow_lmh.hh:148
DarcyLMH::EqData::p_edge_solution
VectorMPI p_edge_solution
Definition: darcy_flow_lmh.hh:163
Input
Abstract linear system class.
Definition: balance.hh:40
DarcyLMH::accept_time_step
virtual void accept_time_step()
postprocess velocity field (add sources)
Definition: darcy_flow_lmh.cc:654
string.h
Balance
Definition: balance.hh:119
DarcyLMH::create_linear_system
void create_linear_system(Input::AbstractRecord rec)
Definition: darcy_flow_lmh.cc:892
DarcyLMH::EqData::seepage_bc_systems
std::map< LongIdx, LocalSystem > seepage_bc_systems
Definition: darcy_flow_lmh.hh:167
DarcyLMH::TYPEDEF_ERR_INFO
TYPEDEF_ERR_INFO(EI_Reason, string)
DarcyLMH::init_eq_data
void init_eq_data()
Definition: darcy_flow_lmh.cc:225
field_set.hh
DarcyLMH::max_n_it_
unsigned int max_n_it_
Definition: darcy_flow_lmh.hh:297
DarcyLMH::nonlinear_iteration_
unsigned int nonlinear_iteration_
Definition: darcy_flow_lmh.hh:298
std::vector< std::shared_ptr< AssemblyBase > >
DarcyLMH::data_changed_
bool data_changed_
Definition: darcy_flow_lmh.hh:292
DarcyLMH::EqData::lin_sys_schur
std::shared_ptr< LinSys > lin_sys_schur
Definition: darcy_flow_lmh.hh:162
DarcyLMH::solve_time_step
void solve_time_step(bool output=true)
Solve the problem without moving to next time and without output.
Definition: darcy_flow_lmh.cc:504
DarcyLMH::update_solution
void update_solution() override
Definition: darcy_flow_lmh.cc:490
FieldAddPotential
Definition: field_add_potential.hh:38
DarcyLMH::get_input_type
static const Input::Type::Record & get_input_type()
Definition: darcy_flow_lmh.cc:103
type_base.hh
DarcyLMH::postprocess
virtual void postprocess()
Definition: darcy_flow_lmh.cc:1004
DarcyLMH::DECLARE_EXCEPTION
DECLARE_EXCEPTION(ExcSolverDiverge,<< "Diverged nonlinear solver. Reason: "<< EI_Reason::val)
DarcyLMH::assembly_linear_system
virtual void assembly_linear_system()
Definition: darcy_flow_lmh.cc:1032
DarcyLMH::set_extra_source
void set_extra_source(const Field< 3, FieldValue< 3 >::Scalar > &extra_src)
Sets external source field (coupling with other equation).
Definition: darcy_flow_lmh.hh:204
DarcyLMH::min_n_it_
unsigned int min_n_it_
Definition: darcy_flow_lmh.hh:296
exceptions.hh
Element
Definition: elements.h:40
DarcyLMH::type_field_descriptor
static const Input::Type::Record & type_field_descriptor()
Definition: darcy_flow_lmh.cc:88
DarcyMH::EqData
Definition: darcy_flow_mh.hh:145
DarcyLMH::zero_time_step
void zero_time_step() override
Definition: darcy_flow_lmh.cc:443
EquationBase::mesh
Mesh & mesh()
Definition: equation.hh:177
DarcyLMH::assembly_mh_matrix
void assembly_mh_matrix(MultidimAssembly &assembler)
Definition: darcy_flow_lmh.cc:690
Intersection
Definition: intersectionquadrature.hh:146
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
type_generic.hh
DarcyLMH::EqData::dh_p_
std::shared_ptr< SubDOFHandlerMultiDim > dh_p_
DOF handler represents DOFs of element pressure.
Definition: darcy_flow_lmh.hh:153
DarcyLMH::solve_nonlinear
void solve_nonlinear()
Solve method common to zero_time_step and update solution.
Definition: darcy_flow_lmh.cc:563
DarcyLMH::data
EqData & data()
Definition: darcy_flow_lmh.hh:197
DarcyLMH::balance_
std::shared_ptr< Balance > balance_
Definition: darcy_flow_lmh.hh:286
DarcyLMH::registrar
static const int registrar
Registrar of class to factory.
Definition: darcy_flow_lmh.hh:308
DarcyLMH::set_extra_storativity
void set_extra_storativity(const Field< 3, FieldValue< 3 >::Scalar > &extra_stor)
Sets external storarivity field (coupling with other equation).
Definition: darcy_flow_lmh.hh:200
TimeGovernor
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Definition: time_governor.hh:310
DarcyLMH::EqData::EqData
EqData()
Definition: darcy_flow_lmh.cc:156
field_values.hh
Input::AbstractRecord
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:458
input_exception.hh
mesh.h
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
std::map< LongIdx, LocalSystem >
DarcyLMH::initialize_specific
virtual void initialize_specific()
Definition: darcy_flow_lmh.cc:373
DarcyLMH::solution_precision
virtual double solution_precision() const
Definition: darcy_flow_lmh.cc:678
DarcyLMH::~DarcyLMH
virtual ~DarcyLMH() override
Definition: darcy_flow_lmh.cc:1310
DarcyLMH::initialize
void initialize() override
Definition: darcy_flow_lmh.cc:268
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
DarcyLMH::get_component_indices_vec
std::vector< int > get_component_indices_vec(unsigned int component) const
Get vector of all DOF indices of given component (0..side, 1..element, 2..edge)
Definition: darcy_flow_lmh.cc:1319
DarcyLMH::EqData::time_step_
double time_step_
Definition: darcy_flow_lmh.hh:160
DarcyLMH::lin_sys_schur
LinSys & lin_sys_schur()
Getter for the linear system of the 2. Schur complement.
Definition: darcy_flow_lmh.hh:283
DarcyLMH::EqData::use_steady_assembly_
bool use_steady_assembly_
Definition: darcy_flow_lmh.hh:157
Mesh
Definition: mesh.h:355
DarcyLMH::tolerance_
double tolerance_
Definition: darcy_flow_lmh.hh:295
DarcyLMH::get_mh_mortar_selection
static const Input::Type::Selection & get_mh_mortar_selection()
Selection for enum MortarMethod.
Definition: darcy_flow_lmh.cc:80
DarcyLMH::allocate_mh_matrix
void allocate_mh_matrix()
Definition: darcy_flow_lmh.cc:717
DarcyLMH
Mixed-hybrid model of linear Darcy flow, possibly unsteady.
Definition: darcy_flow_lmh.hh:130
darcy_flow_mh.hh
mixed-hybrid model of linear Darcy flow, possibly unsteady.
DarcyLMH::initial_condition_postprocess
virtual void initial_condition_postprocess()
Definition: darcy_flow_lmh.cc:440
DarcyLMH::size
int size
Definition: darcy_flow_lmh.hh:290
DarcyLMH::EqData::p_edge_solution_previous
VectorMPI p_edge_solution_previous
Definition: darcy_flow_lmh.hh:164
DarcyLMH::DECLARE_INPUT_EXCEPTION
DECLARE_INPUT_EXCEPTION(ExcMissingTimeGovernor,<< "Missing the key 'time', obligatory for the transient problems.")
VectorMPI
Definition: vector_mpi.hh:43
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:93
DarcyFlowMHOutput
Definition: darcy_flow_mh_output.hh:74
DarcyLMH::output_data
virtual void output_data() override
Write computed fields.
Definition: darcy_flow_lmh.cc:662
DarcyLMH::DarcyLMH
DarcyLMH(Mesh &mesh, const Input::Record in_rec, TimeGovernor *tm=nullptr)
CREATE AND FILL GLOBAL MH MATRIX OF THE WATER MODEL.
Definition: darcy_flow_lmh.cc:178
darcy_flow_interface.hh
DarcyLMH::data_
std::shared_ptr< EqData > data_
Definition: darcy_flow_lmh.hh:300
field.hh
DarcyFlowInterface
Definition: darcy_flow_interface.hh:15
DarcyLMH::read_initial_condition
void read_initial_condition()
Definition: darcy_flow_lmh.cc:405
FieldValue
Definition: field_values.hh:645
DarcyLMH::EqData::p_edge_solution_previous_time
VectorMPI p_edge_solution_previous_time
Definition: darcy_flow_lmh.hh:165