Flow123d  release_3.0.0-965-gb0c8897
hm_iterative.cc
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.cc
15  * @brief
16  * @author Jan Stebel
17  */
18 
19 #include "hm_iterative.hh"
20 #include "system/sys_profiler.hh"
21 #include "input/input_type.hh"
22 #include "flow/richards_lmh.hh"
23 
24 
25 FLOW123D_FORCE_LINK_IN_CHILD(coupling_iterative);
26 
27 
28 namespace it = Input::Type;
29 
30 
31 
33  return it::Record("Coupling_Iterative",
34  "Record with data for iterative coupling of flow and mechanics.\n")
36  .declare_key("flow_equation", RichardsLMH::get_input_type(),
38  "Flow equation, provides the velocity field as a result.")
39 // .declare_key("mechanics_equation", Mechanics::get_input_type(),
40 // "Mechanics, provides the displacement field.")
41  .declare_key( "iteration_parameter", it::Double(), it::Default("1"),
42  "Tuning parameter for iterative splitting. Its default value"
43  "corresponds to a theoretically optimal value with fastest convergence." )
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("1e-7"),
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 
55 
56 const int HM_Iterative::registrar = Input::register_class< HM_Iterative, Mesh &, const Input::Record >("Coupling_Iterative")
58 
59 
60 
62 : DarcyFlowInterface(mesh, in_record)
63 {
64  START_TIMER("HM constructor");
65  using namespace Input;
66 
67  // setup flow equation
68  Record prim_eq = in_record.val<Record>("flow_equation");
69  // Need explicit template types here, since reference is used (automatically passing by value)
70  flow_ = std::make_shared<RichardsLMH>(*mesh_, prim_eq);
71  flow_->initialize();
72  std::stringstream ss; // print warning message with table of uninitialized fields
73  if ( FieldCommon::print_message_table(ss, "HM iterative") ) {
74  WarningOut() << ss.str();
75  }
76 
77  // setup mechanics
78  // TODO: supply real equation
79  mechanics_ = std::make_shared<EquationBase>();
80 
81  // read parameters controlling the iteration
82  beta_ = in_record.val<double>("iteration_parameter");
83  min_it_ = in_record.val<unsigned int>("min_it");
84  max_it_ = in_record.val<unsigned int>("max_it");
85  a_tol_ = in_record.val<double>("a_tol");
86  r_tol_ = in_record.val<double>("r_tol");
87 
88  this->eq_data_ = std::make_shared<FieldSet>().get();
89  this->time_ = &flow_->time();
90 }
91 
92 
94 {
95  flow_->zero_time_step();
96 }
97 
98 
100 {
101  unsigned it = 0;
102  double difference = 0;
103  double init_difference = 1;
104 
105  while (it < min_it_ ||
106  (it < max_it_ && difference > a_tol_ && difference/init_difference > r_tol_)
107  )
108  {
109  it++;
110 
111  mechanics_->update_solution();
112  // TODO: pass displacement (divergence) to flow
113  flow_->update_solution();
114  // TODO: pass pressure to mechanics
115  // TODO: compute difference of iterates
116  }
117 }
118 
119 
121 {
122  return flow_->get_mh_dofhandler();
123 }
124 
125 
127  flow_.reset();
128  mechanics_.reset();
129 }
130 
131 
132 
FieldSet * eq_data_
Definition: equation.hh:232
unsigned int max_it_
Maximal number of iterations.
Definition: hm_iterative.hh:74
unsigned int size() const
Returns number of keys in the Record.
Definition: type_record.hh:598
double beta_
Tuning parameter for iterative splitting.
Definition: hm_iterative.hh:68
double r_tol_
Relative tolerance for difference between two succeeding iterations.
Definition: hm_iterative.hh:80
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
static const int registrar
Definition: hm_iterative.hh:59
Abstract linear system class.
Definition: balance.hh:35
std::shared_ptr< EquationBase > mechanics_
solute transport with chemistry through operator splitting
Definition: hm_iterative.hh:65
static Default obligatory()
The factory function to make an empty default value which is obligatory.
Definition: type_record.hh:110
const MH_DofHandler & get_mh_dofhandler() override
Definition: mesh.h:76
FLOW123D_FORCE_LINK_IN_CHILD(coupling_iterative)
void zero_time_step() override
Definition: hm_iterative.cc:93
Class for declaration of the integral input data.
Definition: type_base.hh:490
double a_tol_
Absolute tolerance for difference between two succeeding iterations.
Definition: hm_iterative.hh:77
static const Input::Type::Record & get_input_type()
Define input record.
Definition: hm_iterative.cc:32
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:303
virtual Record & derive_from(Abstract &parent)
Method to derive new Record from an AbstractRecord parent.
Definition: type_record.cc:195
void update_solution() override
Definition: hm_iterative.cc:99
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:541
Mesh & mesh()
Definition: equation.hh:176
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
const Ret val(const string &key) const
#define START_TIMER(tag)
Starts a timer with specified tag.
Mesh * mesh_
Definition: equation.hh:223
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:501
static Input::Type::Abstract & get_input_type()
unsigned int min_it_
Minimal number of iterations to perform.
Definition: hm_iterative.hh:71
static const Input::Type::Record & get_input_type()
Definition: richards_lmh.cc:72
HM_Iterative(Mesh &mesh, Input::Record in_record)
Definition: hm_iterative.cc:61
#define WarningOut()
Macro defining &#39;warning&#39; record of log.
Definition: logger.hh:246
Record type proxy class.
Definition: type_record.hh:182
std::shared_ptr< RichardsLMH > flow_
steady or unsteady water flow simulator based on MH scheme
Definition: hm_iterative.hh:62
static bool print_message_table(ostream &stream, std::string equation_name)
Definition: field_common.cc:96
TimeGovernor * time_
Definition: equation.hh:224