-
Notifications
You must be signed in to change notification settings - Fork 1
/
van_genuchten.cpp
119 lines (83 loc) · 2.96 KB
/
van_genuchten.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* unit_test.cpp
*
* Created on: 21.12.2019
* Author: anaegel
*/
//g++ unit_test.cpp -I/Users/anaegel/Software/third-party/nlohmann/json/include/ -I/Users/anaegel/Software/ug4-git/externals/BoostForUG4/ -std=c++11 -I/Users/anaegel/adolc_base/include -L /Users/anaegel/adolc_base/lib64/ -ladolc
#include <iostream>
#include <sstream>
#include "van_genuchten.h"
namespace ug {
namespace Richards {
//////////////////////////////////////////////
// VanGenuchtenParameters
//////////////////////////////////////////////
#ifdef UG_JSON
/// JSON serialize.
void to_json(JSONType& j, const HaverkampParameters& p) {
j = JSONType{{"thetaS", p.thetaS}, {"thetaR", p.thetaR}, {"alpha", p.alpha}, {"n", p.n}, {"beta", p.beta}, {"m", p.m}, {"Ksat", p.Ksat}};
}
/// JSON de-serialize.
void from_json(const JSONType& jobject, HaverkampParameters& p) {
jobject.at("alpha").get_to(p.alpha);
jobject.at("n").get_to(p.n);
jobject.at("beta").get_to(p.beta);
jobject.at("m").get_to(p.m);
// Optional parameters
{
p.Ksat = 1.0;
auto it = jobject.find("Ksat");
if (it != jobject.end()) {it->get_to(p.Ksat);}
}
{
p.thetaS = 1.0;
auto it = jobject.find("thetaS");
if (it != jobject.end()) {it->get_to(p.thetaS);}
}
{
p.thetaR = 0.0;
auto it = jobject.find("thetaR");
if (it != jobject.end()) {it->get_to(p.thetaR);}
}
}
//////////////////////////////////////////////
// VanGenuchtenModel
//////////////////////////////////////////////
//! Create a map uid -> json
void CreateJSONMap(const JSONType &array, std::map<std::string, JSONType> &map)
{
for (JSONType::const_iterator it = array.cbegin(); it!=array.cend(); ++it)
{
if (!it->is_array()) continue;
JSONType jelem = *it;
jelem.erase("uid");
map.insert( std::pair<std::string, JSONType>(it->at("uid"), *it) );
}
// Print
for (std::map<std::string, JSONType>::iterator it=map.begin(); it!=map.end(); ++it)
std::cout << it->first << " => " << it->second << '\n';
}
/*SmartPtr<VanGenuchtenModel> VanGenuchtenModelFactory::create_default()
{
// VanGenuchtenParameters SiltLoamParams = { 0.396, 0.131, 0.423, 2.06, 4.96e-2};
VanGenuchtenParameters BeitNetofaClayParams = { 0.446, 0.0, 0.152, 1.17, 8.2e-4};
SmartPtr<VanGenuchtenModel> inst = make_sp(new VanGenuchtenModel(BeitNetofaClayParams));
return inst;
};
*/
//! Factory functions.
SmartPtr<VanGenuchtenModel> CreateVanGenuchtenModel(const char *jstring)
{
UG_LOG("CreateVanGenuchtenModel has been deprecated. Please use 'RichardsModelFactory::create_van_genuchten' ")
return CreateModel<VanGenuchtenModel>(jstring);
}
SmartPtr<ExponentialModel> RichardsModelFactory::create_exponential(const char *jstring)
{ return CreateModel<ExponentialModel>(jstring); }
SmartPtr<VanGenuchtenModel> RichardsModelFactory::create_van_genuchten(const char *jstring)
{ return CreateModel<VanGenuchtenModel>(jstring); }
SmartPtr<HaverkampModel> RichardsModelFactory::create_haverkamp(const char *jstring)
{ return CreateModel<HaverkampModel>(jstring); }
#endif
}
}