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