9 #ifndef RICHARDS__VAN_GENUCHTEN_H_
10 #define RICHARDS__VAN_GENUCHTEN_H_
19 #include <autodiff/forward/dual.hpp>
29 #include <nlohmann/json.hpp>
43 if (!std::isfinite(
number.val) || std::isnan(
number.val))
45 std::cerr <<
"WARNING: Invalid value:" <<
number.val << std::endl;
49 if (!std::isfinite(
number.grad) || std::isnan(
number.grad))
51 std::cerr <<
"WARNING: Invalid value:" <<
number.grad << std::endl;
76 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
VanGenuchtenParameters, alpha, n, m, thetaS, thetaR, Ksat);
82 void CreateJSONMap(
const JSONType &array, std::map<std::string, JSONType> &map);
120 template <
typename TDerived>
126 const TDerived*
me()
const
127 {
return static_cast<const TDerived*
>(
this); }
130 {
return static_cast<TDerived*
>(
this); }
132 template <
typename TFunc>
137 auto [F0, Df0] = derivatives(F, wrt(h), at(h));
145 auto sat = [
this](
dual h){
return me()->Saturation_(h);};
151 for (
size_t i=0; i<n; ++i)
158 auto perm = [
this](
dual h){
return me()->RelativePermeability_(h);};
164 for (
size_t i=0; i<n; ++i)
171 auto cond = [
this](
dual h){
return me()->Conductivity_(h);};
178 for (
size_t i=0; i<n; ++i)
189 auto func = [
this](
dual h){
return me()->Saturation_(h);};
195 auto func = [
this](
dual h){
return me()->Saturation_(h);};
196 return derivative(func, wrt(h), at(h));
203 auto func = [
this](
dual h){
return me()->Conductivity_(h);};
210 auto func = [
this](
dual h){
return me()->Conductivity_(h);};
211 return derivative(func, wrt(h), at(h));
222 dual val = pow(pb/pc, lambda);
230 template <
typename TParameter>
298 return exp(-
p.alpha * (pc/
p.pentry));
307 if (pc.val <= 0)
return p.thetaS;
310 return p.thetaR + (
p.thetaS-
p.thetaR)*Seff;
320 if (pc.val<= 0)
return 1.0;
321 const dual kval = exp(-
p.beta * (pc/
p.pentry));
347 dual apn = alpha*psi_;
353 dual val = pow(1.0/(1.0+apn), m);
398 if (psi_ <= 0)
return p.thetaS;
403 return p.thetaR + (
p.thetaS-
p.thetaR)*Seff;
413 if (psi_<= 0)
return 1.0;
416 if (fabs(Seff.val-1.0)<1e-15)
return 1.0;
420 dual brackS = 1.0-pow(Seff,1.0/m);
423 dual auxS = pow(brackS,m);
426 return sqrt(Seff)*(1.0-auxS)*(1.0-auxS);
492 nlohmann::json j = nlohmann::json::parse(json);
511 if (psi_ <= 0.0)
return p.thetaS;
514 return p.thetaR + (
p.thetaS-
p.thetaR)*Seff;
522 if (psi_<= 0.0)
return 1.0;
576 {
return exp(-
p.alpha*psi_); }
581 if (psi_ <= 0)
return p.thetaS;
585 return p.thetaR + (
p.thetaS-
p.thetaR)*Seff;
602 template <
typename TModel,
typename TParameter =
typename TModel::parameter_type>
608 nlohmann::json j = nlohmann::json::parse(jstring);
609 TParameter
p = j.get<TParameter>();
614 UG_THROW (
"Construction failed: " << jstring);
626 struct RichardsModelFactory {
641 template <>
struct is_json_constructible<typename Richards::ExponentialModelParameters> {
const static bool value =
true;};
652 struct adl_serializer<
ug::Richards::VanGenuchtenModel>
parameterString p
Definition: Biogas.lua:1
Implement a simple exponential model.
Definition: van_genuchten.h:278
ExponentialModelParameters parameter_type
Definition: van_genuchten.h:281
dual Conductivity_(dual pc) const
Definition: van_genuchten.h:329
dual RelativePermeability_(dual pc) const
Relative permeability: $0 \le k_r \le 1$.
Definition: van_genuchten.h:315
dual Saturation_(dual pc) const
Rescaled Saturation: $$ S:=\theta_r+ (\theta_s - \theta_r) * \hat S$$.
Definition: van_genuchten.h:302
friend parameterized_model_type
Definition: van_genuchten.h:285
IParameterizedModel< ExponentialModelParameters > parameterized_model_type
Definition: van_genuchten.h:282
ExponentialModel(const parameter_type &p)
Definition: van_genuchten.h:287
dual EffSaturation_(dual pc) const
Effective saturation: $0 \le \hat S \le 1$.
Definition: van_genuchten.h:295
friend base_type
Definition: van_genuchten.h:284
IRichardsModel< ExponentialModel > base_type
Definition: van_genuchten.h:280
Implements a van Genuchten model.
Definition: van_genuchten.h:541
GardnerModel(const VanGenuchtenParameters &p)
Definition: van_genuchten.h:547
IRichardsModel< GardnerModel > base_type
Definition: van_genuchten.h:543
std::string config_string() const
VanGenuchtenParameters parameter_type
Definition: van_genuchten.h:545
IParameterizedModel< HaverkampParameters > parameterized_model_type
Definition: van_genuchten.h:544
void get_conductivity(double H, double &K, double &dKdH) const
Conductivity K.
Definition: van_genuchten.h:557
static dual Conductivity_(dual psi_, const VanGenuchtenParameters &p)
Definition: van_genuchten.h:590
VanGenuchtenParameters m_param
Definition: van_genuchten.h:567
static dual Saturation_(dual psi_, const VanGenuchtenParameters &p)
Rescaled Saturation.
Definition: van_genuchten.h:579
void get_saturation(double H, double &S, double &dSdH) const
Saturation.
Definition: van_genuchten.h:550
static dual EffSaturation_(dual psi_, const VanGenuchtenParameters &p)
Normalisierter Wassergehalt (reduzierte Sättigung):
Definition: van_genuchten.h:575
static double one
Definition: van_genuchten.h:566
Implements a Haverkamp model.
Definition: van_genuchten.h:476
friend base_type
Definition: van_genuchten.h:482
IRichardsModel< HaverkampModel > base_type
Definition: van_genuchten.h:478
HaverkampParameters parameter_type
Definition: van_genuchten.h:480
dual Saturation_(dual psi_) const
Rescaled Saturation $$ S:=\theta_r+ (\theta_s - \theta_r) * \hat S $$.
Definition: van_genuchten.h:508
IParameterizedModel< HaverkampParameters > parameterized_model_type
Definition: van_genuchten.h:479
HaverkampModel(const parameter_type &p)
Definition: van_genuchten.h:485
friend parameterized_model_type
Definition: van_genuchten.h:483
dual Conductivity_(dual psi_) const
Definition: van_genuchten.h:528
dual RelativePermeability_(dual psi_) const
Relative permeability $0 \le k_r \le 1$.
Definition: van_genuchten.h:519
This is the interface for a Richards-type model. All derived classes use CRTP for evaluation.
Definition: van_genuchten.h:122
double Conductivity(double H)
Conductivity K = Ks*kr.
Definition: van_genuchten.h:200
void get_relative_permeability(double H, double &Kr, double &dKrdH) const
Calls RelativePermeability_.
Definition: van_genuchten.h:156
void get_value_and_deriv(TFunc F, double H, double &f, double &df) const
Definition: van_genuchten.h:133
void get_saturations(const double *H, double *S, double *dSdH, size_t n) const
Definition: van_genuchten.h:149
double Saturation(double H) const
Definition: van_genuchten.h:186
void get_conductivities(const double *H, double *K, double *dKdH, size_t n) const
Definition: van_genuchten.h:176
double dConductivity_dH(double H)
Definition: van_genuchten.h:207
const TDerived * me() const
Definition: van_genuchten.h:126
void get_conductivity(double H, double &K, double &dKdH) const
Calls Conductivity_.
Definition: van_genuchten.h:169
TDerived * me()
Definition: van_genuchten.h:129
double dSaturation_dH(double H) const
Definition: van_genuchten.h:192
void get_relative_permeabilities(const double *H, double *K, double *dKdH, size_t n) const
Definition: van_genuchten.h:162
void get_saturation(double H, double &S, double &dSdH) const
Calls Saturation_.
Definition: van_genuchten.h:143
Implements a van Genuchten-Mualem model.
Definition: van_genuchten.h:368
dual RelativePermeability_(dual psi_) const
Relative permeability: $0 \le k_r \le 1$.
Definition: van_genuchten.h:408
VanGenuchtenModel(const parameter_type &p)
Definition: van_genuchten.h:377
VanGenuchtenParameters parameter_type
Definition: van_genuchten.h:372
friend parameterized_model_type
Definition: van_genuchten.h:375
dual Conductivity_(dual psi_) const
Definition: van_genuchten.h:430
dual Saturation_(dual psi_) const
Rescaled Saturation: $$ S:=\theta_r+ (\theta_s - \theta_r) * \hat S$$.
Definition: van_genuchten.h:393
dual EffSaturation_(dual psi_) const
Effective saturation: $0 \le \hat S \le 1$.
Definition: van_genuchten.h:386
IParameterizedModel< VanGenuchtenParameters > parameterized_model_type
Definition: van_genuchten.h:371
friend base_type
Definition: van_genuchten.h:374
IRichardsModel< VanGenuchtenModel > base_type
Definition: van_genuchten.h:370
const NullSmartPtr SPNULL
#define UG_ASSERT(expr, msg)
void to_json(nlohmann::json &j, const BiotSubsetParameters &p)
Definition: biot_tools.cpp:57
void from_json(const nlohmann::json &j, BiotSubsetParameters &p)
Definition: biot_tools.cpp:69
void UGCheckValues(const dual &number)
Definition: van_genuchten.h:41
autodiff::dual dual
Definition: van_genuchten.h:37
SmartPtr< T, FreePolicy > make_sp(T *inst)
Definition: van_genuchten.h:219
static dual ComputeEffectiveSaturation(dual pc, double lambda, double pb)
Definition: van_genuchten.h:220
Definition: van_genuchten.h:258
double thetaR
Definition: van_genuchten.h:263
double alpha
Definition: van_genuchten.h:260
double thetaS
Definition: van_genuchten.h:264
double Ksat
Definition: van_genuchten.h:266
double beta
Definition: van_genuchten.h:261
double pentry
Definition: van_genuchten.h:259
Definition: van_genuchten.h:447
double Ksat
Definition: van_genuchten.h:457
double m
Definition: van_genuchten.h:452
double thetaS
Definition: van_genuchten.h:455
double thetaR
Definition: van_genuchten.h:454
double beta
Definition: van_genuchten.h:451
double alpha
Definition: van_genuchten.h:448
double n
Definition: van_genuchten.h:449
Base class for a parameterized model. Provides serialization.
Definition: van_genuchten.h:232
void set_parameters(const TParameter &p)
Definition: van_genuchten.h:237
std::string config_string() const
Definition: van_genuchten.h:243
const TParameter & get_parameters() const
Definition: van_genuchten.h:240
IParameterizedModel(const TParameter &p)
Definition: van_genuchten.h:235
TParameter m_param
Definition: van_genuchten.h:249
IParameterizedModel()
Definition: van_genuchten.h:233
Definition: van_genuchten.h:341
static dual ComputeEffectiveSaturation(dual psi_, double alpha, double n, double m)
Effective (reduced) saturation $0 \le \hat S \le 1$.
Definition: van_genuchten.h:344
static dual ComputeEffectiveSaturation(dual psi_, double alpha, double n)
Two argument version.
Definition: van_genuchten.h:359
Definition: van_genuchten.h:62
double n
Definition: van_genuchten.h:65
double alpha
Definition: van_genuchten.h:63
double thetaR
Definition: van_genuchten.h:68
double thetaS
Definition: van_genuchten.h:69
double Ksat
Definition: van_genuchten.h:71
double m
Definition: van_genuchten.h:66