Flow123d  last_with_con_2.0.0-4-g42e6930
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 
16 #include "system/asserts.hh"
17 #include "flow/soil_models.hh"
18 
19 
20 template <class Model>
22 {
23  model_.reset_(data);
24 }
25 
26 template <class Model>
27 double SoilModelImplBase<Model>::conductivity( const double &p_head) const
28 {
29  return model_.conductivity_(p_head);
30 }
31 
32 template <class Model>
33 auto SoilModelImplBase<Model>::conductivity(const DiffDouble &p_head)->DiffDouble const
34 {
35  return model_.conductivity_(p_head);
36 }
37 
38 template <class Model>
39 double SoilModelImplBase<Model>::water_content( const double &p_head) const
40 {
41  return model_.water_content_(p_head);
42 }
43 
44 template <class Model>
45 auto SoilModelImplBase<Model>::water_content(const DiffDouble &p_head)->DiffDouble const
46 {
47  return model_.water_content_(p_head);
48 }
49 
50 
51 
52 
53 namespace internal {
54 
56 : Bpar(0.5), Ppar(2), K_lower_limit(1.0E-20)
57 {}
58 
60 {
61  // check soil parameters
62  ASSERT_LT_DBG( soil.cut_fraction, 1.0);
63  ASSERT_GT_DBG( soil.cut_fraction, 0.0);
64  soil_param_ = soil;
65 
66  m = 1-1/soil_param_.n;
67  // soil_param_.cut_fraction = (Qs -Qr)/(Qnc - Qr)
69 
70  // conductivity internal scaling
71  FFQr = 1.0; // pow(1 - pow(Qeer,1/m),m);
72  double Qs_relative = soil_param_.cut_fraction;
73  FFQs = pow(1 - pow(Qs_relative, 1/m),m);
74 
75 
77  //std::cout << "Hs : " << Hs << " qs: " << soil_param_.Qs << " qsnc: " << Qs_nc << std::endl;
78 
79 }
80 
81 
82 template <class T>
83 T VanGenuchten::Q_rel(const T &h) const
84 {
85  return pow( 1 + pow(-soil_param_.alpha * h, soil_param_.n), -m);
86 }
87 
88 template <class T>
89 T VanGenuchten::Q_rel_inv(const T &q) const
90 {
91  return -pow( pow( q, -1/m ) -1, 1/soil_param_.n)/soil_param_.alpha;
92 }
93 
94 
95 
96 // pri generovani grafu jsem zjistil ze originalni vzorecek pro
97 // vodivost pres theta je numericky nestabilni pro tlaky blizke
98 // nule, zejmena pro velka n
99 // tento vzorec je stabilni:
100 //
101 /// k(h)=t(h)**(0.5)* (1- ((h)**n/(1+(h)**n)) **m)**2
102 
103 template <class T>
104 T VanGenuchten::conductivity_(const T& h) const
105 {
106  T Kr, Q_unscaled, Q_cut_unscaled, FFQ;
107 
108  if (h < Hs) {
109  Q_unscaled = Q_rel(h);
110  Q_cut_unscaled = Q_unscaled / soil_param_.cut_fraction;
111  FFQ = pow(1 - pow(Q_unscaled,1/m),m);
112  Kr = soil_param_.Ks * pow(Q_cut_unscaled,Bpar)*pow((FFQr - FFQ)/(FFQr - FFQs),Ppar);
113  }
114  else Kr = soil_param_.Ks;
115 
116  if (Kr < K_lower_limit) return K_lower_limit;
117  else return Kr;
118 }
119 
120 //template SoilModelBase::DiffDouble VanGenuchten::conductivity_<SoilModelBase::DiffDouble>(const SoilModelBase::DiffDouble &h) const;
121 //template double VanGenuchten::conductivity_<double>(const double &h) const;
122 
123 
124 template <class T>
125 T VanGenuchten::water_content_(const T& h) const
126 {
127  if (h < Hs) return soil_param_.Qr + (Qs_nc - soil_param_.Qr) *Q_rel(h);
128  else return soil_param_.Qs;
129 }
130 
131 //template SoilModelBase::DiffDouble VanGenuchten::water_content_<SoilModelBase::DiffDouble>(const SoilModelBase::DiffDouble &h) const;
132 //template double VanGenuchten::water_content_<double>(const double &h) const;
133 
135 : VanGenuchten()
136 {
137  Ppar=3;
138 }
139 
140 
141 template <class T>
142 T Irmay::conductivity_(const T& h) const
143 {
144  T Kr;
145 
146  if (h < Hs) {
147  T Q = this->Q_rel(h);
148  Kr = soil_param_.Ks * pow(Q, Ppar);
149  }
150  else Kr = soil_param_.Ks;
151 
152  if (Kr < K_lower_limit) return K_lower_limit;
153  else return Kr;
154 }
155 
156 //template SoilModelBase::DiffDouble Irmay::conductivity_<SoilModelBase::DiffDouble>(const SoilModelBase::DiffDouble &h) const;
157 //template double Irmay::conductivity_<double>(const double &h) const;
158 
159 } //close namespace internal
160 
161 
162 
165 
166 
T conductivity_(const T &h) const
k(h)=t(h)**(0.5)* (1- ((h)**n/(1+(h)**n)) **m)**2
Definition: soil_models.cc:104
T Q_rel(const T &h) const
Definition: soil_models.cc:83
void reset_(SoilData soil)
Definition: soil_models.cc:59
Definitions of ASSERTS.
double cut_fraction
Definition: soil_models.hh:41
#define ASSERT_GT_DBG(a, b)
Definition of comparative assert macro (Greater Than) only for debug mode.
Definition: asserts.hh:316
double alpha
Definition: soil_models.hh:38
T conductivity_(const T &h) const
Definition: soil_models.cc:142
void reset(SoilData data) override
Definition: soil_models.cc:21
double Qr
Definition: soil_models.hh:39
T water_content_(const T &h) const
Definition: soil_models.cc:125
double Qs
Definition: soil_models.hh:40
double water_content(const double &p_head) const override
Definition: soil_models.cc:39
double Ks
Definition: soil_models.hh:42
T Q_rel_inv(const T &q) const
Definition: soil_models.cc:89
double conductivity(const double &p_head) const override
Definition: soil_models.cc:27
double n
Definition: soil_models.hh:37
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:300