Flow123d  release_3.0.0-968-gc87a28e79
soil_models.cc
Go to the documentation of this file.
1 /*
2  * soil_models.cc
3  *
4  * Created on: Aug 11, 2016
5  * Author: jb
6  */
7 
8 
9 #include <algorithm>
10 #include <cmath>
11 
12 #include "fadbad.h"
13 #include "badiff.h"
14 #include "fadiff.h"
15 #include "system/logger.hh"
16 
17 #include "system/asserts.hh"
18 #include "flow/soil_models.hh"
19 
20 
21 template <class Model>
23 : cut_fraction_(cut_fraction)
24 {}
25 
26 
27 template <class Model>
29 {
30  data.cut_fraction = cut_fraction_;
31  model_.reset_(data);
32  /*
33  // Check table of hydraulic functions
34  static int checked=0;
35  if (! checked) {
36  checked=1;
37 
38  double factor=pow(10, 0.1);
39  for(double h=0.1; h < 1e4; h*=factor) {
40  LogOut().fmt("h: {:g} sat: {:g} cond: {:g}", -h, water_content(-h), conductivity(-h));
41  }
42  }
43  */
44 }
45 
46 template <class Model>
47 double SoilModelImplBase<Model>::conductivity( const double &p_head) const
48 {
49  return model_.conductivity_(p_head);
50 }
51 
52 template <class Model>
53 auto SoilModelImplBase<Model>::conductivity_diff(const DiffDouble &p_head)->DiffDouble const
54 {
55  return model_.conductivity_(p_head);
56 }
57 
58 template <class Model>
59 double SoilModelImplBase<Model>::water_content( const double &p_head) const
60 {
61  return model_.water_content_(p_head);
62 }
63 
64 template <class Model>
65 auto SoilModelImplBase<Model>::water_content_diff(const DiffDouble &p_head)->DiffDouble const
66 {
67  return model_.water_content_(p_head);
68 }
69 
70 
71 
72 
73 namespace internal {
74 
76 : Bpar(0.5), Ppar(2), K_lower_limit(1.0E-20)
77 {}
78 
80 {
81  // check soil parameters
82  ASSERT_LT_DBG( soil.cut_fraction, 1.0);
83  ASSERT_GT_DBG( soil.cut_fraction, 0.0);
84  soil_param_ = soil;
85 
86  m = 1-1/soil_param_.n;
87  // soil_param_.cut_fraction = (Qs -Qr)/(Qnc - Qr)
89 
90  // conductivity internal scaling
91  FFQr = 1.0; // pow(1 - pow(Qeer,1/m),m);
92  double Qs_relative = soil_param_.cut_fraction;
93  FFQs = pow(1 - pow(Qs_relative, 1/m),m);
94 
95 
97  /*
98  std::cout << "Hs : " << Hs
99  << " qs: " << soil_param_.Qs
100  << " qsnc: " << Qs_nc
101  << " Q: " << Q_rel(Hs) << std::endl;
102  */
103 }
104 
105 
106 template <class T>
107 T VanGenuchten::Q_rel(const T &h) const
108 {
109  return pow( 1 + pow(-soil_param_.alpha * h, soil_param_.n), -m);
110 }
111 
112 template <class T>
113 T VanGenuchten::Q_rel_inv(const T &q) const
114 {
115  return -pow( pow( q, -1/m ) -1, 1/soil_param_.n)/soil_param_.alpha;
116 }
117 
118 
119 
120 // pri generovani grafu jsem zjistil ze originalni vzorecek pro
121 // vodivost pres theta je numericky nestabilni pro tlaky blizke
122 // nule, zejmena pro velka n
123 // tento vzorec je stabilni:
124 //
125 /// k(h)=t(h)**(0.5)* (1- ((h)**n/(1+(h)**n)) **m)**2
126 
127 template <class T>
128 T VanGenuchten::conductivity_(const T& h) const
129 {
130  T Kr, Q_unscaled, Q_cut_unscaled, FFQ;
131 
132  if (h < Hs) {
133  Q_unscaled = Q_rel(h);
134  Q_cut_unscaled = Q_unscaled / soil_param_.cut_fraction;
135  FFQ = pow(1 - pow(Q_unscaled,1/m),m);
136  Kr = soil_param_.Ks * pow(Q_cut_unscaled,Bpar)*pow((FFQr - FFQ)/(FFQr - FFQs),Ppar);
137  }
138  else Kr = soil_param_.Ks;
139 
140  if (Kr < K_lower_limit) return K_lower_limit;
141  else return Kr;
142 }
143 
144 //template SoilModelBase::DiffDouble VanGenuchten::conductivity_<SoilModelBase::DiffDouble>(const SoilModelBase::DiffDouble &h) const;
145 //template double VanGenuchten::conductivity_<double>(const double &h) const;
146 
147 
148 template <class T>
149 T VanGenuchten::water_content_(const T& h) const
150 {
151  if (h < Hs) return soil_param_.Qr + (Qs_nc - soil_param_.Qr) *Q_rel(h);
152  else return soil_param_.Qs;
153 }
154 
155 //template SoilModelBase::DiffDouble VanGenuchten::water_content_<SoilModelBase::DiffDouble>(const SoilModelBase::DiffDouble &h) const;
156 //template double VanGenuchten::water_content_<double>(const double &h) const;
157 
159 : VanGenuchten()
160 {
161  Ppar=3;
162 }
163 
164 
165 template <class T>
166 T Irmay::conductivity_(const T& h) const
167 {
168  T Kr;
169 
170  if (h < Hs) {
171  T Q = this->Q_rel(h);
172  Kr = soil_param_.Ks * pow(Q, Ppar);
173  }
174  else Kr = soil_param_.Ks;
175 
176  if (Kr < K_lower_limit) return K_lower_limit;
177  else return Kr;
178 }
179 
180 //template SoilModelBase::DiffDouble Irmay::conductivity_<SoilModelBase::DiffDouble>(const SoilModelBase::DiffDouble &h) const;
181 //template double Irmay::conductivity_<double>(const double &h) const;
182 
183 } //close namespace internal
184 
185 
186 
189 
190 
SoilData::cut_fraction
double cut_fraction
Definition: soil_models.hh:43
ASSERT_GT_DBG
#define ASSERT_GT_DBG(a, b)
Definition of comparative assert macro (Greater Than) only for debug mode.
Definition: asserts.hh:315
internal::VanGenuchten::conductivity_
T conductivity_(const T &h) const
k(h)=t(h)**(0.5)* (1- ((h)**n/(1+(h)**n)) **m)**2
Definition: soil_models.cc:128
internal::VanGenuchten::Bpar
double Bpar
Definition: soil_models.hh:127
SoilData::n
double n
Definition: soil_models.hh:39
asserts.hh
Definitions of ASSERTS.
internal::VanGenuchten::VanGenuchten
VanGenuchten()
Definition: soil_models.cc:75
SoilData::Qr
double Qr
Definition: soil_models.hh:41
internal::VanGenuchten::Qs_nc
double Qs_nc
Definition: soil_models.hh:133
SoilModelImplBase::reset
void reset(SoilData data) override
Definition: soil_models.cc:28
internal::VanGenuchten::reset_
void reset_(SoilData soil)
Definition: soil_models.cc:79
internal::VanGenuchten::Q_rel_inv
T Q_rel_inv(const T &q) const
Definition: soil_models.cc:113
SoilModelImplBase::water_content
double water_content(const double &p_head) const override
Definition: soil_models.cc:59
internal::VanGenuchten::K_lower_limit
double K_lower_limit
Definition: soil_models.hh:129
logger.hh
SoilModelImplBase::conductivity_diff
auto conductivity_diff(const DiffDouble &p_head) -> DiffDouble const override
Definition: soil_models.cc:53
soil_models.hh
internal::VanGenuchten
Definition: soil_models.hh:106
internal::VanGenuchten::water_content_
T water_content_(const T &h) const
Definition: soil_models.cc:149
internal::VanGenuchten::soil_param_
SoilData soil_param_
Definition: soil_models.hh:124
SoilModelImplBase::conductivity
double conductivity(const double &p_head) const override
Definition: soil_models.cc:47
internal::Irmay::Irmay
Irmay()
Definition: soil_models.cc:158
internal::VanGenuchten::m
double m
Definition: soil_models.hh:132
internal::VanGenuchten::FFQr
double FFQr
Definition: soil_models.hh:136
internal::Irmay::conductivity_
T conductivity_(const T &h) const
Definition: soil_models.cc:166
SoilData::alpha
double alpha
Definition: soil_models.hh:40
SoilData::Ks
double Ks
Definition: soil_models.hh:44
ASSERT_LT_DBG
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:299
SoilData
Definition: soil_models.hh:38
internal::VanGenuchten::Ppar
double Ppar
Definition: soil_models.hh:128
internal
Definition: field_values.cc:20
internal::VanGenuchten::FFQs
double FFQs
Definition: soil_models.hh:136
SoilModelBase::DiffDouble
fadbad::B< double > DiffDouble
Definition: soil_models.hh:59
internal::VanGenuchten::Q_rel
T Q_rel(const T &h) const
Definition: soil_models.cc:107
SoilModelImplBase::water_content_diff
auto water_content_diff(const DiffDouble &p_head) -> DiffDouble const override
Definition: soil_models.cc:65
SoilModelImplBase
Definition: soil_models.hh:74
internal::VanGenuchten::Hs
double Hs
Definition: soil_models.hh:137
SoilData::Qs
double Qs
Definition: soil_models.hh:42
SoilModelImplBase::SoilModelImplBase
SoilModelImplBase(double cut_fraction=0.999)
Definition: soil_models.cc:22