Flow123d  JS_before_hm-1601-gc6ac32d
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 
31 class Mesh;
32 class FieldCommon;
33 class RichardsLMH;
34 
35 namespace it = Input::Type;
36 
37 
39 public:
40 
42  return it::Record("Coupling_Iterative_AUX",
43  "Record with data for iterative coupling.\n")
44  .declare_key( "max_it", it::Integer(0), it::Default("100"),
45  "Maximal count of HM iterations." )
46  .declare_key( "min_it", it::Integer(0), it::Default("1"),
47  "Minimal count of HM iterations." )
48  .declare_key( "a_tol", it::Double(0), it::Default("0"),
49  "Absolute tolerance for difference in HM iteration." )
50  .declare_key( "r_tol", it::Double(0), it::Default("1e-7"),
51  "Relative tolerance for difference in HM iteration." )
52  .close();
53  }
54 
56  : it(0)
57  {
58  min_it_ = in_record.val<unsigned int>("min_it");
59  max_it_ = in_record.val<unsigned int>("max_it");
60  a_tol_ = in_record.val<double>("a_tol");
61  r_tol_ = in_record.val<double>("r_tol");
62  }
63 
64  void solve_step()
65  {
66  it = 0;
67  double abs_error = std::numeric_limits<double>::max();
68  double rel_error = std::numeric_limits<double>::max();
69 
70  while ( it < min_it_ || (abs_error > a_tol_ && rel_error > r_tol_ && it < max_it_) )
71  {
72  it++;
74  compute_iteration_error(abs_error, rel_error);
76  }
78  }
79 
80  unsigned int iteration()
81  { return it; }
82 
83 protected:
84 
85  /// Solve equations and update data (fields).
86  virtual void solve_iteration() = 0;
87 
88  /// Compute absolute and relative error in the solution.
89  virtual void compute_iteration_error(double &abs_error, double &rel_error) = 0;
90 
91  /// Save data (e.g. solution fields) for the next iteration.
92  virtual void update_after_iteration() = 0;
93 
94  /// Save data after iterations have finished.
95  virtual void update_after_converged() = 0;
96 
97 
98  /// Minimal number of iterations to perform.
99  unsigned int min_it_;
100 
101  /// Maximal number of iterations.
102  unsigned int max_it_;
103 
104  /// Absolute tolerance for difference between two succeeding iterations.
105  double a_tol_;
106 
107  /// Relative tolerance for difference between two succeeding iterations.
108  double r_tol_;
109 
110 private:
111 
112  /// Iteration index.
113  unsigned int it;
114 
115 };
116 
117 
118 /**
119  * @brief Class for solution of fully coupled flow and mechanics using fixed-stress iterative splitting.
120  *
121  * Flow and mechanics are solved separately and within each iteration the coupling terms are updated.
122  * Here we use the fixed-stress splitting [see Mikelic&Wheeler, Comput. Geosci. 17(3), 2013] which uses
123  * a tuning parameter "beta" to speed up the convergence.
124  */
126 public:
127 
128  class EqData : public FieldSet
129  {
130  public:
131  EqData();
132 
133  void initialize(Mesh &mesh);
134 
135  Field<3, FieldValue<3>::Scalar> alpha; ///< Biot coefficient.
136  Field<3, FieldValue<3>::Scalar> density; ///< Density of fluid.
137  Field<3, FieldValue<3>::Scalar> gravity; ///< Standard gravity.
139 
140  /// Potential -alpha*pressure whose gradient is passed to mechanics as additional load.
143 
144  /// FieldFE for pressure_potential field.
145  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > potential_ptr_;
146  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > beta_ptr_;
147  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > flow_source_ptr_;
148  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > old_pressure_ptr_;
149  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > old_iter_pressure_ptr_;
150  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > div_u_ptr_;
151  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > old_div_u_ptr_;
152  };
153 
154  /// Define input record.
155  static const Input::Type::Record & get_input_type();
156 
157  HM_Iterative(Mesh &mesh, Input::Record in_record);
158  void initialize() override;
159  void zero_time_step() override;
160  void update_solution() override;
161  ~HM_Iterative();
162 
163 private:
164 
165  void update_potential();
166 
167  void update_flow_fields();
168 
169  void solve_iteration() override;
170 
171  void update_after_iteration() override;
172 
173  void update_after_converged() override;
174 
175  void compute_iteration_error(double &abs_error, double &rel_error) override;
176 
177  static const int registrar;
178 
179  /// steady or unsteady water flow simulator based on MH scheme
180  std::shared_ptr<RichardsLMH> flow_;
181 
182  /// solute transport with chemistry through operator splitting
183  std::shared_ptr<Elasticity> mechanics_;
184 
186 
187  /// Tuning parameter for iterative splitting.
188  double beta_;
189 
190 };
191 
192 #endif /* HC_EXPLICIT_SEQUENTIAL_HH_ */
Abstract base class for equation clasess.
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:74
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > old_div_u_ptr_
virtual void compute_iteration_error(double &abs_error, double &rel_error)=0
Compute absolute and relative error in the solution.
Class for solution of fully coupled flow and mechanics using fixed-stress iterative splitting...
double beta_
Tuning parameter for iterative splitting.
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
static const int registrar
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:94
unsigned int iteration()
Definition: hm_iterative.hh:80
double a_tol_
Absolute tolerance for difference between two succeeding iterations.
unsigned int it
Iteration index.
Definition: mesh.h:77
static const Input::Type::Record & record_template()
Definition: hm_iterative.hh:41
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > potential_ptr_
FieldFE for pressure_potential field.
Class for declaration of the integral input data.
Definition: type_base.hh:483
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > old_pressure_ptr_
FEM for linear elasticity.
virtual void update_after_iteration()=0
Save data (e.g. solution fields) for the next iteration.
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > div_u_ptr_
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
virtual void solve_iteration()=0
Solve equations and update data (fields).
Field< 3, FieldValue< 3 >::Scalar > pressure_potential
Potential -alpha*pressure whose gradient is passed to mechanics as additional load.
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > flow_source_ptr_
Edge lumped mixed-hybrid solution of unsteady Darcy flow.
Definition: richards_lmh.hh:62
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Field< 3, FieldValue< 3 >::Scalar > alpha
Biot coefficient.
const Ret val(const string &key) const
std::shared_ptr< Elasticity > mechanics_
solute transport with chemistry through operator splitting
Field< 3, FieldValue< 3 >::Scalar > gravity
Standard gravity.
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
Field< 3, FieldValue< 3 >::Scalar > flow_source
Field< 3, FieldValue< 3 >::Scalar > beta
unsigned int min_it_
Minimal number of iterations to perform.
Definition: hm_iterative.hh:99
IterativeCoupling(Input::Record in_record)
Definition: hm_iterative.hh:55
unsigned int max_it_
Maximal number of iterations.
double r_tol_
Relative tolerance for difference between two succeeding iterations.
Record type proxy class.
Definition: type_record.hh:182
std::shared_ptr< RichardsLMH > flow_
steady or unsteady water flow simulator based on MH scheme
virtual void update_after_converged()=0
Save data after iterations have finished.
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > old_iter_pressure_ptr_
Field< 3, FieldValue< 3 >::Scalar > density
Density of fluid.
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > beta_ptr_