Flow123d  master-27b3058
hm_iterative.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 hm_iterative.hh
15  * @brief
16  * @author Jan Stebel
17  */
18 
19 #ifndef HM_ITERATIVE_HH_
20 #define HM_ITERATIVE_HH_
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
27 #include "coupling/equation.hh"
29 #include "mechanics/elasticity.hh"
30 #include "system/exceptions.hh"
31 #include "system/sys_profiler.hh"
32 
33 class Mesh;
34 class FieldCommon;
35 class DarcyLMH;
36 
37 template<unsigned int dim> class FlowPotentialAssemblyHM;
38 template<unsigned int dim> class ResidualAssemblyHM;
39 
40 namespace it = Input::Type;
41 
42 
44 public:
45  TYPEDEF_ERR_INFO( EI_Reason, string);
46  DECLARE_EXCEPTION(ExcSolverDiverge,
47  << "Nonlinear solver did not converge. Reason: " << EI_Reason::val
48  );
49 
51  return it::Record("Coupling_Iterative_AUX",
52  "Record with data for iterative coupling.\n")
53  .declare_key( "max_it", it::Integer(0), it::Default("100"),
54  "Maximal count of HM iterations." )
55  .declare_key( "min_it", it::Integer(0), it::Default("1"),
56  "Minimal count of HM iterations." )
57  .declare_key( "a_tol", it::Double(0), it::Default("0"),
58  "Absolute tolerance for difference in HM iteration." )
59  .declare_key( "r_tol", it::Double(0), it::Default("1e-7"),
60  "Relative tolerance for difference in HM iteration." )
61  .close();
62  }
63 
65  : it(0)
66  {
67  min_it_ = in_record.val<unsigned int>("min_it");
68  max_it_ = in_record.val<unsigned int>("max_it");
69  a_tol_ = in_record.val<double>("a_tol");
70  r_tol_ = in_record.val<double>("r_tol");
71  }
72 
73  void solve_step()
74  {
75  START_TIMER("HM step");
76  it = 0;
77  double abs_error = std::numeric_limits<double>::max();
78  double rel_error = std::numeric_limits<double>::max();
79 
80  while ( it < min_it_ || (abs_error > a_tol_ && rel_error > r_tol_ && it < max_it_) )
81  {
82  it++;
84  compute_iteration_error(abs_error, rel_error);
86  }
88  END_TIMER("HM step");
89  }
90 
91  unsigned int iteration()
92  { return it; }
93 
94 protected:
95 
96  /// Solve equations and update data (fields).
97  virtual void solve_iteration() = 0;
98 
99  /// Compute absolute and relative error in the solution.
100  virtual void compute_iteration_error(double &abs_error, double &rel_error) = 0;
101 
102  /// Save data (e.g. solution fields) for the next iteration.
103  virtual void update_after_iteration() = 0;
104 
105  /// Save data after iterations have finished.
106  virtual void update_after_converged() = 0;
107 
108 
109  /// Minimal number of iterations to perform.
110  unsigned int min_it_;
111 
112  /// Maximal number of iterations.
113  unsigned int max_it_;
114 
115  /// Absolute tolerance for difference between two succeeding iterations.
116  double a_tol_;
117 
118  /// Relative tolerance for difference between two succeeding iterations.
119  double r_tol_;
120 
121 private:
122 
123  /// Iteration index.
124  unsigned int it;
125 
126 };
127 
128 
129 /**
130  * @brief Class for solution of fully coupled flow and mechanics using fixed-stress iterative splitting.
131  *
132  * Flow and mechanics are solved separately and within each iteration the coupling terms are updated.
133  * Here we use the fixed-stress splitting [see Mikelic&Wheeler, Comput. Geosci. 17(3), 2013] which uses
134  * a tuning parameter "beta" to speed up the convergence.
135  */
137 public:
138 
139  class EqData
140  {
141  public:
142  /// steady or unsteady water flow simulator based on MH scheme
143  std::shared_ptr<DarcyLMH> flow_;
144 
145  /// solute transport with chemistry through operator splitting
146  std::shared_ptr<Elasticity> mechanics_;
147 
148  double p_dif2; ///< Squared norm of pressure difference in two subsequent iterations.
149  double p_norm2; ///< Squared pressure norm in the last iteration.
150  };
151 
152 
153  class EqFields : public FieldSet
154  {
155  public:
156  EqFields();
157 
158  void initialize(Mesh &mesh, HM_Iterative::EqData &eq_data, const TimeGovernor *time_, double beta_);
159 
160  Field<3, FieldValue<3>::Scalar> alpha; ///< Biot coefficient.
161  Field<3, FieldValue<3>::Scalar> density; ///< Density of fluid.
162  Field<3, FieldValue<3>::Scalar> gravity; ///< Standard gravity.
164 
165  /// Potential -alpha*pressure whose gradient is passed to mechanics as additional load.
167  Field<3, FieldValue<3>::Scalar> ref_pressure_potential; ///< Potential of reference (prescribed) pressure from flow b.c. TODO: Swith to BCField when possible.
172 
173  /// FieldFE for pressure_potential field.
174  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > ref_potential_ptr_;
175  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > old_iter_pressure_ptr_;
176  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > old_div_u_ptr_;
177  };
178 
179  /// Define input record.
180  static const Input::Type::Record & get_input_type();
181 
182  HM_Iterative(Mesh &mesh, Input::Record in_record);
183  void initialize() override;
184  void zero_time_step() override;
185  void update_solution() override;
186  ~HM_Iterative();
187 
188 private:
189 
190  void update_potential();
191 
192  void update_flow_fields();
193 
194  void solve_iteration() override;
195 
196  void update_after_iteration() override;
197 
198  void update_after_converged() override;
199 
200  void compute_iteration_error(double &abs_error, double &rel_error) override;
201 
202  static const int registrar;
203 
206 
207  std::shared_ptr<EqFields> eq_fields_;
208 
209  std::shared_ptr<EqData> eq_data_;
210 
211 };
212 
213 #endif /* HC_EXPLICIT_SEQUENTIAL_HH_ */
Mixed-hybrid model of linear Darcy flow, possibly unsteady.
Mesh & mesh()
Definition: equation.hh:181
TimeGovernor * time_
Definition: equation.hh:241
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:77
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
const Mesh * mesh() const
Returns pointer to mesh.
Definition: field_set.hh:393
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:92
double p_dif2
Squared norm of pressure difference in two subsequent iterations.
std::shared_ptr< DarcyLMH > flow_
steady or unsteady water flow simulator based on MH scheme
std::shared_ptr< Elasticity > mechanics_
solute transport with chemistry through operator splitting
double p_norm2
Squared pressure norm in the last iteration.
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > old_iter_pressure_ptr_
Field< 3, FieldValue< 3 >::Scalar > flow_source
Field< 3, FieldValue< 3 >::Scalar > density
Density of fluid.
Field< 3, FieldValue< 3 >::Scalar > old_pressure
Field< 3, FieldValue< 3 >::Scalar > old_iter_pressure
Field< 3, FieldValue< 3 >::Scalar > beta
Field< 3, FieldValue< 3 >::Scalar > ref_pressure_potential
Potential of reference (prescribed) pressure from flow b.c. TODO: Swith to BCField when possible.
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > ref_potential_ptr_
FieldFE for pressure_potential field.
Field< 3, FieldValue< 3 >::Scalar > alpha
Biot coefficient.
Field< 3, FieldValue< 3 >::Scalar > old_div_u
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > old_div_u_ptr_
void initialize(Mesh &mesh, HM_Iterative::EqData &eq_data, const TimeGovernor *time_, double beta_)
Field< 3, FieldValue< 3 >::Scalar > pressure_potential
Potential -alpha*pressure whose gradient is passed to mechanics as additional load.
Field< 3, FieldValue< 3 >::Scalar > gravity
Standard gravity.
Class for solution of fully coupled flow and mechanics using fixed-stress iterative splitting.
void solve_iteration() override
Solve equations and update data (fields).
void update_potential()
GenericAssembly< FlowPotentialAssemblyHM > * flow_potential_assembly_
GenericAssembly< ResidualAssemblyHM > * residual_assembly_
void initialize() override
static const Input::Type::Record & get_input_type()
Define input record.
Definition: hm_iterative.cc:74
static const int registrar
void update_after_iteration() override
Save data (e.g. solution fields) for the next iteration.
std::shared_ptr< EqData > eq_data_
void update_solution() override
void compute_iteration_error(double &abs_error, double &rel_error) override
Compute absolute and relative error in the solution.
void zero_time_step() override
void update_flow_fields()
HM_Iterative(Mesh &mesh, Input::Record in_record)
void update_after_converged() override
Save data after iterations have finished.
std::shared_ptr< EqFields > eq_fields_
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
const Ret val(const string &key) const
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
Class for declaration of the integral input data.
Definition: type_base.hh:483
Record type proxy class.
Definition: type_record.hh:182
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
Record & declare_key(const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
Declares a new key of the Record.
Definition: type_record.cc:503
unsigned int it
Iteration index.
double r_tol_
Relative tolerance for difference between two succeeding iterations.
virtual void solve_iteration()=0
Solve equations and update data (fields).
double a_tol_
Absolute tolerance for difference between two succeeding iterations.
DECLARE_EXCEPTION(ExcSolverDiverge,<< "Nonlinear solver did not converge. Reason: "<< EI_Reason::val)
unsigned int min_it_
Minimal number of iterations to perform.
virtual void compute_iteration_error(double &abs_error, double &rel_error)=0
Compute absolute and relative error in the solution.
unsigned int max_it_
Maximal number of iterations.
unsigned int iteration()
Definition: hm_iterative.hh:91
virtual void update_after_iteration()=0
Save data (e.g. solution fields) for the next iteration.
IterativeCoupling(Input::Record in_record)
Definition: hm_iterative.hh:64
TYPEDEF_ERR_INFO(EI_Reason, string)
static const Input::Type::Record & record_template()
Definition: hm_iterative.hh:50
virtual void update_after_converged()=0
Save data after iterations have finished.
Definition: mesh.h:362
Basic time management functionality for unsteady (and steady) solvers (class Equation).
FEM for linear elasticity.
Abstract base class for equation clasess.
#define END_TIMER(tag)
Ends a timer with specified tag.
#define START_TIMER(tag)
Starts a timer with specified tag.