Flow123d  JS_before_hm-2154-g185f171e0
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.
142  Field<3, FieldValue<3>::Scalar> ref_pressure_potential; ///< Potential of reference (prescribed) pressure from flow b.c. TODO: Swith to BCField when possible.
144 
145  /// FieldFE for pressure_potential field.
146  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > potential_ptr_;
147  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > ref_potential_ptr_;
148  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > beta_ptr_;
149  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > flow_source_ptr_;
150  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > old_pressure_ptr_;
151  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > old_iter_pressure_ptr_;
152  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > div_u_ptr_;
153  std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar> > old_div_u_ptr_;
154  };
155 
156  /// Define input record.
157  static const Input::Type::Record & get_input_type();
158 
159  HM_Iterative(Mesh &mesh, Input::Record in_record);
160  void initialize() override;
161  void zero_time_step() override;
162  void update_solution() override;
163  ~HM_Iterative();
164 
165 private:
166 
167  void update_potential();
168 
169  void update_flow_fields();
170 
171  void solve_iteration() override;
172 
173  void update_after_iteration() override;
174 
175  void update_after_converged() override;
176 
177  void compute_iteration_error(double &abs_error, double &rel_error) override;
178 
179  static const int registrar;
180 
181  /// steady or unsteady water flow simulator based on MH scheme
182  std::shared_ptr<RichardsLMH> flow_;
183 
184  /// solute transport with chemistry through operator splitting
185  std::shared_ptr<Elasticity> mechanics_;
186 
188 
189  /// Tuning parameter for iterative splitting.
190  double beta_;
191 
192 };
193 
194 #endif /* HC_EXPLICIT_SEQUENTIAL_HH_ */
HM_Iterative::get_input_type
static const Input::Type::Record & get_input_type()
Define input record.
Definition: hm_iterative.cc:32
HM_Iterative::EqData::old_iter_pressure_ptr_
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > old_iter_pressure_ptr_
Definition: hm_iterative.hh:151
FieldSet::mesh
const Mesh * mesh() const
Returns pointer to mesh.
Definition: field_set.hh:382
IterativeCoupling::solve_step
void solve_step()
Definition: hm_iterative.hh:64
HM_Iterative::EqData::beta_ptr_
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > beta_ptr_
Definition: hm_iterative.hh:148
HM_Iterative::EqData::old_div_u_ptr_
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > old_div_u_ptr_
Definition: hm_iterative.hh:153
HM_Iterative
Class for solution of fully coupled flow and mechanics using fixed-stress iterative splitting.
Definition: hm_iterative.hh:125
IterativeCoupling::iteration
unsigned int iteration()
Definition: hm_iterative.hh:80
HM_Iterative::flow_
std::shared_ptr< RichardsLMH > flow_
steady or unsteady water flow simulator based on MH scheme
Definition: hm_iterative.hh:182
IterativeCoupling::update_after_iteration
virtual void update_after_iteration()=0
Save data (e.g. solution fields) for the next iteration.
Input::Type::Integer
Class for declaration of the integral input data.
Definition: type_base.hh:483
IterativeCoupling
Definition: hm_iterative.hh:38
Input::Record::val
const Ret val(const string &key) const
Definition: accessors_impl.hh:31
HM_Iterative::registrar
static const int registrar
Definition: hm_iterative.hh:179
Input::Type::Double
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
HM_Iterative::zero_time_step
void zero_time_step() override
Definition: hm_iterative.cc:191
HM_Iterative::EqData::ref_pressure_potential
Field< 3, FieldValue< 3 >::Scalar > ref_pressure_potential
Potential of reference (prescribed) pressure from flow b.c. TODO: Swith to BCField when possible.
Definition: hm_iterative.hh:142
HM_Iterative::EqData
Definition: hm_iterative.hh:128
HM_Iterative::mechanics_
std::shared_ptr< Elasticity > mechanics_
solute transport with chemistry through operator splitting
Definition: hm_iterative.hh:185
input_type_forward.hh
HM_Iterative::EqData::pressure_potential
Field< 3, FieldValue< 3 >::Scalar > pressure_potential
Potential -alpha*pressure whose gradient is passed to mechanics as additional load.
Definition: hm_iterative.hh:141
IterativeCoupling::solve_iteration
virtual void solve_iteration()=0
Solve equations and update data (fields).
HM_Iterative::EqData::flow_source_ptr_
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > flow_source_ptr_
Definition: hm_iterative.hh:149
HM_Iterative::EqData::initialize
void initialize(Mesh &mesh)
Definition: hm_iterative.cc:109
HM_Iterative::update_after_converged
void update_after_converged() override
Save data after iterations have finished.
Definition: hm_iterative.cc:239
HM_Iterative::EqData::div_u_ptr_
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > div_u_ptr_
Definition: hm_iterative.hh:152
IterativeCoupling::a_tol_
double a_tol_
Absolute tolerance for difference between two succeeding iterations.
Definition: hm_iterative.hh:105
IterativeCoupling::min_it_
unsigned int min_it_
Minimal number of iterations to perform.
Definition: hm_iterative.hh:99
EquationBase::mesh
Mesh & mesh()
Definition: equation.hh:179
Input::Type::Default
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
HM_Iterative::HM_Iterative
HM_Iterative(Mesh &mesh, Input::Record in_record)
Definition: hm_iterative.cc:134
HM_Iterative::EqData::old_pressure_ptr_
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > old_pressure_ptr_
Definition: hm_iterative.hh:150
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
IterativeCoupling::record_template
static const Input::Type::Record & record_template()
Definition: hm_iterative.hh:41
elasticity.hh
FEM for linear elasticity.
HM_Iterative::EqData::potential_ptr_
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > potential_ptr_
FieldFE for pressure_potential field.
Definition: hm_iterative.hh:146
HM_Iterative::update_potential
void update_potential()
Definition: hm_iterative.cc:250
HM_Iterative::compute_iteration_error
void compute_iteration_error(double &abs_error, double &rel_error) override
Compute absolute and relative error in the solution.
Definition: hm_iterative.cc:334
FieldCommon
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:76
HM_Iterative::EqData::ref_potential_ptr_
std::shared_ptr< FieldFE< 3, FieldValue< 3 >::Scalar > > ref_potential_ptr_
Definition: hm_iterative.hh:147
Input::Type::Record::declare_key
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
FieldSet
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
equation.hh
Abstract base class for equation clasess.
HM_Iterative::update_flow_fields
void update_flow_fields()
Definition: hm_iterative.cc:297
HM_Iterative::update_solution
void update_solution() override
Definition: hm_iterative.cc:209
Input::Type::Record::close
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
Input::Type
Definition: balance.hh:41
HM_Iterative::beta_
double beta_
Tuning parameter for iterative splitting.
Definition: hm_iterative.hh:190
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
HM_Iterative::initialize
void initialize() override
Definition: hm_iterative.cc:172
Mesh
Definition: mesh.h:355
HM_Iterative::~HM_Iterative
~HM_Iterative()
Definition: hm_iterative.cc:365
HM_Iterative::EqData::alpha
Field< 3, FieldValue< 3 >::Scalar > alpha
Biot coefficient.
Definition: hm_iterative.hh:135
IterativeCoupling::r_tol_
double r_tol_
Relative tolerance for difference between two succeeding iterations.
Definition: hm_iterative.hh:108
HM_Iterative::EqData::gravity
Field< 3, FieldValue< 3 >::Scalar > gravity
Standard gravity.
Definition: hm_iterative.hh:137
accessors_forward.hh
HM_Iterative::EqData::flow_source
Field< 3, FieldValue< 3 >::Scalar > flow_source
Definition: hm_iterative.hh:143
HM_Iterative::EqData::beta
Field< 3, FieldValue< 3 >::Scalar > beta
Definition: hm_iterative.hh:138
IterativeCoupling::update_after_converged
virtual void update_after_converged()=0
Save data after iterations have finished.
HM_Iterative::data_
EqData data_
Definition: hm_iterative.hh:187
RichardsLMH
Edge lumped mixed-hybrid solution of unsteady Darcy flow.
Definition: richards_lmh.hh:62
HM_Iterative::update_after_iteration
void update_after_iteration() override
Save data (e.g. solution fields) for the next iteration.
Definition: hm_iterative.cc:231
IterativeCoupling::IterativeCoupling
IterativeCoupling(Input::Record in_record)
Definition: hm_iterative.hh:55
IterativeCoupling::compute_iteration_error
virtual void compute_iteration_error(double &abs_error, double &rel_error)=0
Compute absolute and relative error in the solution.
HM_Iterative::EqData::EqData
EqData()
Definition: hm_iterative.cc:67
HM_Iterative::solve_iteration
void solve_iteration() override
Solve equations and update data (fields).
Definition: hm_iterative.cc:218
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:93
HM_Iterative::EqData::density
Field< 3, FieldValue< 3 >::Scalar > density
Density of fluid.
Definition: hm_iterative.hh:136
IterativeCoupling::max_it_
unsigned int max_it_
Maximal number of iterations.
Definition: hm_iterative.hh:102
darcy_flow_interface.hh
DarcyFlowInterface
Definition: darcy_flow_interface.hh:15
IterativeCoupling::it
unsigned int it
Iteration index.
Definition: hm_iterative.hh:113