Flow123d  JS_before_hm-2198-g122e1f2e2
richards_lmh.cc
Go to the documentation of this file.
1 /*
2  * richards_lmh.cc
3  *
4  * Created on: Sep 16, 2015
5  * Author: jb
6  */
7 
8 
9 #include "system/global_defs.h"
10 #include "system/sys_profiler.hh"
11 #include "system/asserts.hh"
12 
13 #include "coupling/balance.hh"
14 
15 #include "input/input_type.hh"
16 #include "input/factory.hh"
17 #include "flow/richards_lmh.hh"
18 #include "flow/soil_models.hh"
19 //#include "flow/assembly_richards_old_.hh"
22 #include "tools/time_governor.hh"
23 
24 #include "petscmat.h"
25 #include "petscviewer.h"
26 #include "petscerror.h"
27 #include <armadillo>
28 
29 #include "la/schur.hh"
30 #include "la/vector_mpi.hh"
31 
32 
33 #include "tools/include_fadbad.hh" // for "fadbad.h", "badiff.h", "fadiff.h"
34 
35 
36 FLOW123D_FORCE_LINK_IN_CHILD(richards_lmh)
37 
38 
39 
41 {
42  *this += water_content.name("water_content")
43  .units(UnitSI::dimensionless())
45  .description(R"(Water content.
46  It is a fraction of water volume to the whole volume.)");
47  *this += conductivity_richards.name("conductivity_richards")
48  .units( UnitSI().m().s(-1) )
50  .description("Computed isotropic scalar conductivity by the soil model.");
51 
52  *this += water_content_saturated.name("water_content_saturated")
53  .description(R"(Saturated water content (($ \theta_s $)).
54  Relative volume of water in a reference volume of a saturated porous media.)")
55  .input_default("0.0")
56  .units( UnitSI::dimensionless() );
57 
58  *this += water_content_residual.name("water_content_residual")
59  .description(R"(Residual water content (($ \theta_r $)).
60  Relative volume of water in a reference volume of an ideally dry porous media.)")
61  .input_default("0.0")
62  .units( UnitSI::dimensionless() );
63 
64  *this += genuchten_p_head_scale.name("genuchten_p_head_scale")
65  .description(R"(The van Genuchten pressure head scaling parameter (($ \alpha $)).
66  It is related to the inverse of the air entry pressure, i.e. the pressure
67  where the relative water content starts to decrease below 1.)")
68  .input_default("0.0")
69  .units( UnitSI().m(-1) );
70 
71  *this += genuchten_n_exponent.name("genuchten_n_exponent")
72  .description("The van Genuchten exponent parameter (($ n $)).")
73  .input_default("2.0")
74  .units( UnitSI::dimensionless() );
75 }
76 
77 
79 : DarcyLMH::EqData::EqData() {}
80 
81 
83  namespace it=Input::Type;
84 
85  it::Record field_descriptor = it::Record("RichardsLMH_Data",FieldCommon::field_descriptor_record_description("RichardsLMH_Data"))
87  .copy_keys( RichardsLMH::EqFields().make_field_descriptor_type("RichardsLMH_Data_aux") )
88  .close();
89 
90  auto model_selection = it::Selection("Soil_Model_Type", "")
91  .add_value(SoilModelBase::van_genuchten, "van_genuchten", "Van Genuchten soil model with cutting near zero.")
92  .add_value(SoilModelBase::irmay, "irmay", "Irmay model for conductivity, Van Genuchten model for the water content. Suitable for bentonite.")
93  .close();
94 
95  auto soil_rec = it::Record("SoilModel", "Soil model settings.")
96  .allow_auto_conversion("model_type")
97  .declare_key("model_type", model_selection, it::Default("\"van_genuchten\""),
98  "Selection of the globally applied soil model. In future we replace this key by a field for selection of the model."
99  "That will allow usage of different soil model in a single simulation.")
100  .declare_key("cut_fraction", it::Double(0.0,1.0), it::Default("0.999"),
101  "Fraction of the water content where we cut and rescale the curve.")
102  .close();
103 
105 
106  return it::Record("Flow_Richards_LMH", "Lumped Mixed-Hybrid solver for unsteady unsaturated Darcy flow.")
109  .declare_key("input_fields", it::Array( field_descriptor ), it::Default::obligatory(),
110  "Input data for Darcy flow model.")
111  .declare_key("output", DarcyFlowMHOutput::get_input_type(eq_fields, "Flow_Richards_LMH"),
112  IT::Default("{ \"fields\": [ \"pressure_p0\", \"velocity_p0\" ] }"),
113  "Specification of output fields and output times.")
114  .declare_key("soil_model", soil_rec, it::Default("\"van_genuchten\""),
115  "Soil model settings.")
116  .close();
117 }
118 
119 
120 const int RichardsLMH::registrar =
121  Input::register_class< RichardsLMH, Mesh &, const Input::Record >("Flow_Richards_LMH") +
123 
124 
125 
127  : DarcyLMH(mesh_in, in_rec, tm),
129 {
130  eq_fields_ = make_shared<EqFields>();
131  eq_data_ = make_shared<EqData>();
134  this->eq_fieldset_ = eq_fields_.get();
135  //eq_data_->edge_new_local_4_mesh_idx_ = &(this->edge_new_local_4_mesh_idx_);
136 
137  eq_fields_->set_mesh(*mesh_);
138 }
139 
140 
142 
143  auto model_rec = input_record_.val<Input::Record>("soil_model");
144  auto model_type = model_rec.val<SoilModelBase::SoilModelType>("model_type");
145  double fraction= model_rec.val<double>("cut_fraction");
146  if (model_type == SoilModelBase::van_genuchten)
147  eq_data_->soil_model_ = std::make_shared<SoilModel_VanGenuchten>(fraction);
148  else if (model_type == SoilModelBase::irmay)
149  eq_data_->soil_model_ = std::make_shared<SoilModel_Irmay>(fraction);
150  else
151  ASSERT(false);
152 
153  // create edge vectors
154  eq_data_->water_content_previous_time = eq_data_->dh_cr_disc_->create_vector();
155  eq_data_->capacity = eq_data_->dh_cr_disc_->create_vector();
156 
157  ASSERT_PTR(mesh_);
158  eq_data_->mesh = mesh_;
159 
160  eq_fields_->water_content_ptr = create_field_fe< 3, FieldValue<3>::Scalar >(eq_data_->dh_cr_disc_);
161  eq_fields_->water_content.set(eq_fields_->water_content_ptr, 0.0);
162 
163  eq_fields_->conductivity_ptr = create_field_fe< 3, FieldValue<3>::Scalar >(eq_data_->dh_p_);
164  eq_fields_->conductivity_richards.set(eq_fields_->conductivity_ptr, 0.0);
165 
166 
167  //eq_data_->multidim_assembler = AssemblyFlowBase::create< AssemblyRichards >(eq_fields_, eq_data_);
168 }
169 
170 
171 //void RichardsLMH::initial_condition_postprocess()
172 //{
173 // // modify side fluxes in parallel
174 // // for every local edge take time term on diagonal and add it to the corresponding flux
175 //
176 // for ( DHCellAccessor dh_cell : eq_data_->dh_->own_range() ) {
177 // eq_data_->multidim_assembler[dh_cell.elm().dim()-1]->update_water_content(dh_cell);
178 // }
179 //}
180 
181 
183 {
184  eq_data_->p_edge_solution_previous_time.copy_from(eq_data_->p_edge_solution);
185  VectorMPI water_content_vec = eq_fields_->water_content_ptr->vec();
186  eq_data_->water_content_previous_time.copy_from(water_content_vec);
187 
188  eq_data_->p_edge_solution_previous_time.local_to_ghost_begin();
189  eq_data_->p_edge_solution_previous_time.local_to_ghost_end();
190 }
191 
192 bool RichardsLMH::zero_time_term(bool time_global) {
193  if (time_global) {
194  return (eq_fields_->storativity.input_list_size() == 0)
195  && (eq_fields_->water_content_saturated.input_list_size() == 0);
196 
197  } else {
198  return (eq_fields_->storativity.field_result(mesh_->region_db().get_region_set("BULK"))
199  == result_zeros)
200  && (eq_fields_->water_content_saturated.field_result(mesh_->region_db().get_region_set("BULK"))
201  == result_zeros);
202  }
203 }
204 
205 
207 {
208  START_TIMER("RicharsLMH::assembly_linear_system");
209 
210  eq_data_->p_edge_solution.local_to_ghost_begin();
211  eq_data_->p_edge_solution.local_to_ghost_end();
212 
213  eq_data_->is_linear = eq_fields_->genuchten_p_head_scale.field_result(mesh_->region_db().get_region_set("BULK")) == result_zeros;
214 
215  //DebugOut() << "Assembly linear system\n";
216  START_TIMER("full assembly");
217 // if (typeid(*schur0) != typeid(LinSys_BDDC)) {
218 // schur0->start_add_assembly(); // finish allocation and create matrix
219 // schur_compl->start_add_assembly();
220 // }
221 
223 
224  eq_data_->time_step_ = time_->dt();
225 
228 
229 // assembly_mh_matrix( eq_data_->multidim_assembler ); // fill matrix
230  START_TIMER("RichardsLMH::assembly_steady_mh_matrix");
231  this->mh_matrix_assembly_->assemble(eq_data_->dh_); // fill matrix
232  END_TIMER("RichardsLMH::assembly_steady_mh_matrix");
233 
236 }
237 
238 
242  this->mh_matrix_assembly_ = new GenericAssembly< MHMatrixAssemblyRichards >(this->eq_fields_.get(), this->eq_data_.get());
244 }
245 
246 
250 }
251 
252 
254  if (init_cond_postprocess_assembly_!=nullptr) {
257  }
258 }
EquationBase::mesh_
Mesh * mesh_
Definition: equation.hh:220
RichardsLMH::accept_time_step
void accept_time_step() override
postprocess velocity field (add sources)
Definition: richards_lmh.cc:182
result_zeros
@ result_zeros
Definition: field_algo_base.hh:74
RichardsLMH::read_init_cond_asm
void read_init_cond_asm() override
Call assemble of read_init_cond_assembly_ and init_cond_postprocess_assembly_.
Definition: richards_lmh.cc:247
TimeGovernor::dt
double dt() const
Definition: time_governor.hh:565
UnitSI::dimensionless
static UnitSI & dimensionless()
Returns dimensionless unit.
Definition: unit_si.cc:55
factory.hh
vector_mpi.hh
time_governor.hh
Basic time management class.
MeshBase::region_db
const RegionDB & region_db() const
Definition: mesh.h:171
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:347
EquationBase::time_
TimeGovernor * time_
Definition: equation.hh:221
include_fadbad.hh
RichardsLMH::EqData::EqData
EqData()
Constructor.
Definition: richards_lmh.cc:78
Input::Record::val
const Ret val(const string &key) const
Definition: accessors_impl.hh:31
asserts.hh
Definitions of ASSERTS.
richards_lmh.hh
Input::Type::Selection::close
const Selection & close() const
Close the Selection, no more values can be added.
Definition: type_selection.cc:65
RichardsLMH::eq_data_
std::shared_ptr< EqData > eq_data_
Definition: richards_lmh.hh:129
Input::Type::Double
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
LinSys::rhs_zero_entries
virtual PetscErrorCode rhs_zero_entries()
Definition: linsys.hh:273
FLOW123D_FORCE_LINK_IN_CHILD
#define FLOW123D_FORCE_LINK_IN_CHILD(x)
Definition: global_defs.h:157
RichardsLMH::zero_time_term
bool zero_time_term(bool time_global=false) override
Definition: richards_lmh.cc:192
LinSys::mat_zero_entries
virtual PetscErrorCode mat_zero_entries()
Definition: linsys.hh:264
DarcyLMH::get_input_type
static const Input::Type::Record & get_input_type()
Definition: darcy_flow_lmh.cc:104
DarcyLMH::mh_matrix_assembly_
GenericAssemblyBase * mh_matrix_assembly_
Definition: darcy_flow_lmh.hh:354
GenericAssemblyBase::assemble
virtual void assemble(std::shared_ptr< DOFHandlerMultiDim > dh)=0
GenericAssembly::assemble
void assemble(std::shared_ptr< DOFHandlerMultiDim > dh) override
General assemble methods.
Definition: generic_assembly.hh:204
LinSys::set_matrix_changed
void set_matrix_changed()
Definition: linsys.hh:212
RichardsLMH::EqData
Definition: richards_lmh.hh:89
DarcyLMH::type_field_descriptor
static const Input::Type::Record & type_field_descriptor()
Definition: darcy_flow_lmh.cc:89
RichardsLMH::eq_fields_
std::shared_ptr< EqFields > eq_fields_
Definition: richards_lmh.hh:128
DarcyFlowMHOutput::get_input_type
static const Input::Type::Instance & get_input_type(FieldSet &eq_data, const std::string &equation_name)
Definition: darcy_flow_mh_output.cc:62
Input::Type::Record::size
unsigned int size() const
Returns number of keys in the Record.
Definition: type_record.hh:602
Input::Type::Default
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
RichardsLMH::initialize_asm
void initialize_asm() override
Create and initialize assembly objects.
Definition: richards_lmh.cc:239
Input::Type::Record::derive_from
virtual Record & derive_from(Abstract &parent)
Method to derive new Record from an AbstractRecord parent.
Definition: type_record.cc:196
DarcyLMH::eq_fields
EqFields & eq_fields()
Definition: darcy_flow_lmh.hh:235
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
FieldFlag::equation_result
static constexpr Mask equation_result
Match result fields. These are never given by input or copy of input.
Definition: field_flag.hh:55
sys_profiler.hh
darcy_flow_mh_output.hh
Output class for darcy_flow_mh model.
RichardsLMH::get_input_type
static const Input::Type::Record & get_input_type()
Definition: richards_lmh.cc:82
Input::Type::Record::allow_auto_conversion
virtual Record & allow_auto_conversion(const string &from_key)
Allows shorter input of the Record providing only value of the from_key given as the parameter.
Definition: type_record.cc:133
schur.hh
Assembly explicit Schur complement for the given linear system. Provides method for resolution of the...
TimeGovernor
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Definition: time_governor.hh:317
Input::Type::Default::obligatory
static Default obligatory()
The factory function to make an empty default value which is obligatory.
Definition: type_record.hh:110
UnitSI
Class for representation SI units of Fields.
Definition: unit_si.hh:40
EquationBase::input_record_
Input::Record input_record_
Definition: equation.hh:222
RegionDB::get_region_set
RegionSet get_region_set(const std::string &set_name) const
Definition: region.cc:328
FieldCommon::field_descriptor_record_description
static const std::string field_descriptor_record_description(const string &record_name)
Definition: field_common.cc:73
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
SoilModelBase::van_genuchten
@ van_genuchten
Definition: soil_models.hh:56
soil_models.hh
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
DarcyFlowInterface::get_input_type
static Input::Type::Abstract & get_input_type()
Definition: darcy_flow_interface.hh:23
LinSys::start_add_assembly
virtual void start_add_assembly()
Definition: linsys.hh:341
DarcyLMH::eq_data_
std::shared_ptr< EqData > eq_data_
Definition: darcy_flow_lmh.hh:345
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
RichardsLMH::EqFields
Definition: richards_lmh.hh:71
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
RichardsLMH::~RichardsLMH
virtual ~RichardsLMH() override
Definition: richards_lmh.cc:253
DarcyLMH::lin_sys_schur
LinSys & lin_sys_schur()
Getter for the linear system of the 2. Schur complement.
Definition: darcy_flow_lmh.hh:322
input_type.hh
Mesh
Definition: mesh.h:355
Input::Type::Record::copy_keys
Record & copy_keys(const Record &other)
Copy keys from other record.
Definition: type_record.cc:216
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
LinSys::finish_assembly
virtual void finish_assembly()=0
global_defs.h
Global macros to enhance readability and debugging, general constants.
RichardsLMH::registrar
static const int registrar
Registrar of class to factory.
Definition: richards_lmh.hh:111
DarcyLMH
Mixed-hybrid model of linear Darcy flow, possibly unsteady.
Definition: darcy_flow_lmh.hh:132
SoilModelBase::SoilModelType
SoilModelType
Definition: soil_models.hh:55
DarcyLMH::reconstruct_schur_assembly_
GenericAssemblyBase * reconstruct_schur_assembly_
Definition: darcy_flow_lmh.hh:355
RichardsLMH::init_cond_postprocess_assembly_
GenericAssembly< InitCondPostprocessAssembly > * init_cond_postprocess_assembly_
general assembly object, hold assembly objects of appropriate dimension
Definition: richards_lmh.hh:132
RichardsLMH
Edge lumped mixed-hybrid solution of unsteady Darcy flow.
Definition: richards_lmh.hh:65
RichardsLMH::RichardsLMH
RichardsLMH(Mesh &mesh, const Input::Record in_rec, TimeGovernor *tm=nullptr)
Definition: richards_lmh.cc:126
EquationBase::eq_fieldset_
FieldSet * eq_fieldset_
Definition: equation.hh:229
DarcyLMH::read_init_cond_assembly_
GenericAssembly< ReadInitCondAssemblyLMH > * read_init_cond_assembly_
general assembly objects, hold assembly objects of appropriate dimension
Definition: darcy_flow_lmh.hh:353
balance.hh
VectorMPI
Definition: vector_mpi.hh:43
RichardsLMH::assembly_linear_system
void assembly_linear_system() override
Definition: richards_lmh.cc:206
Input::Type::Selection::add_value
Selection & add_value(const int value, const std::string &key, const std::string &description="", TypeBase::attribute_map attributes=TypeBase::attribute_map())
Adds one new value with name given by key to the Selection.
Definition: type_selection.cc:50
ASSERT_PTR
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
Definition: asserts.hh:336
DarcyLMH::eq_fields_
std::shared_ptr< EqFields > eq_fields_
Definition: darcy_flow_lmh.hh:344
START_TIMER
#define START_TIMER(tag)
Starts a timer with specified tag.
Definition: sys_profiler.hh:115
GenericAssembly< ReadInitCondAssemblyLMH >
SoilModelBase::irmay
@ irmay
Definition: soil_models.hh:57
END_TIMER
#define END_TIMER(tag)
Ends a timer with specified tag.
Definition: sys_profiler.hh:149
RichardsLMH::initialize_specific
void initialize_specific() override
Definition: richards_lmh.cc:141
assembly_richards_old.hh