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