Flow123d  release_3.0.0-1150-g11be08a
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", Elasticity::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 
61 {
62 }
63 
64 
65 
67 : DarcyFlowInterface(mesh, in_record)
68 {
69  START_TIMER("HM constructor");
70  using namespace Input;
71 
72  // setup flow equation
73  Record flow_rec = in_record.val<Record>("flow_equation");
74  // Need explicit template types here, since reference is used (automatically passing by value)
75  flow_ = std::make_shared<RichardsLMH>(*mesh_, flow_rec);
76  flow_->initialize();
77  std::stringstream ss; // print warning message with table of uninitialized fields
78  if ( FieldCommon::print_message_table(ss, "flow") ) {
79  WarningOut() << ss.str();
80  }
81 
82  // setup mechanics
83  Record mech_rec = in_record.val<Record>("mechanics_equation");
84  mechanics_ = std::make_shared<Elasticity>(*mesh_, mech_rec);
85  mechanics_->data()["cross_section"].copy_from(flow_->data()["cross_section"]);
86  mechanics_->initialize();
87 
88  // read parameters controlling the iteration
89  beta_ = in_record.val<double>("iteration_parameter");
90  min_it_ = in_record.val<unsigned int>("min_it");
91  max_it_ = in_record.val<unsigned int>("max_it");
92  a_tol_ = in_record.val<double>("a_tol");
93  r_tol_ = in_record.val<double>("r_tol");
94 
95  this->eq_data_ = &data_;
96 
97  this->time_ = &flow_->time();
98 
99  // synchronize time marks of flow and mechanics
100  for (auto mark = TimeGovernor::marks().begin(flow_->mark_type()); mark != TimeGovernor::marks().end(flow_->mark_type()); ++mark )
101  TimeGovernor::marks().add( TimeMark(mark->time(), mechanics_->time().equation_fixed_mark_type()) );
102  for (auto mark = TimeGovernor::marks().begin(mechanics_->mark_type()); mark != TimeGovernor::marks().end(mechanics_->mark_type()); ++mark )
103  TimeGovernor::marks().add( TimeMark(mark->time(), flow_->time().equation_fixed_mark_type()) );
104 }
105 
106 
108 {
109 }
110 
111 
113 {
114  flow_->zero_time_step();
115  mechanics_->zero_time_step();
116 }
117 
118 
120 {
121  unsigned it = 0;
122  double difference = 0;
123  double init_difference = 1;
124 
125  while (it < min_it_ ||
126  (it < max_it_ && difference > a_tol_ && difference/init_difference > r_tol_)
127  )
128  {
129  it++;
130 
131  flow_->update_solution();
132  // TODO: pass pressure to mechanics
133  mechanics_->update_solution();
134  // TODO: pass displacement (divergence) to flow
135  // TODO: compute difference of iterates
136  }
137 }
138 
139 
141 {
142  return flow_->get_mh_dofhandler();
143 }
144 
145 
147  flow_.reset();
148  mechanics_.reset();
149 }
150 
151 
152 
FieldSet * eq_data_
Definition: equation.hh:232
unsigned int max_it_
Maximal number of iterations.
Definition: hm_iterative.hh:86
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:80
double r_tol_
Relative tolerance for difference between two succeeding iterations.
Definition: hm_iterative.hh:92
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:69
Abstract linear system class.
Definition: balance.hh:37
static const Input::Type::Record & get_input_type()
Declare input record type for the equation TransportDG.
Definition: elasticity.cc:44
TimeMarks::iterator begin(TimeMark::Type mask) const
Iterator for the begin mimics container-like of TimeMarks.
Definition: time_marks.cc:192
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
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:89
static const Input::Type::Record & get_input_type()
Define input record.
Definition: hm_iterative.cc:32
static TimeMarks & marks()
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
virtual Record & derive_from(Abstract &parent)
Method to derive new Record from an AbstractRecord parent.
Definition: type_record.cc:196
void update_solution() override
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
std::shared_ptr< Elasticity > mechanics_
solute transport with chemistry through operator splitting
Definition: hm_iterative.hh:75
#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:503
static Input::Type::Abstract & get_input_type()
void initialize() override
TimeMark add(const TimeMark &mark)
Definition: time_marks.cc:81
unsigned int min_it_
Minimal number of iterations to perform.
Definition: hm_iterative.hh:83
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:66
TimeMarks::iterator end(TimeMark::Type mask) const
Iterator for the end mimics container-like of TimeMarks.
Definition: time_marks.cc:206
#define WarningOut()
Macro defining &#39;warning&#39; record of log.
Definition: logger.hh:246
Class used for marking specified times at which some events occur.
Definition: time_marks.hh:45
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:72
static bool print_message_table(ostream &stream, std::string equation_name)
Definition: field_common.cc:96
TimeGovernor * time_
Definition: equation.hh:224