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