Richards
Solving The Richards equation with temporally periodic surface boundary conditions
settings.cc
Go to the documentation of this file.
1 
3 #include "settings.h"
4 
5 bool eval_txt_bool (const char *s) {
6  if ( (strcmp(s, "true") == 0) || (strcmp(s, "True") == 0) ) return(true);
7  return(false);
8 }
9 
10 bool cmp (const char *s1, const char *s2) {
11  if ( strcmp(s1, s2) == 0 ) return(true);
12  return(false);
13 }
14 
15 long to_long(const char *val) {
16  //convert a string to a long int, handling scientific notation
17  return( long(std::atof(val)) );
18 }
19 
20 Settings parse_settings ( std::vector< std::vector< std::string > > sv ) {
21 
22  Settings s;
23  const char *set, *val;
24 
25  for (int i=0; i < int(sv.size()); i++) {
26 
27  //get the setting and value pair
28  set = sv[i][0].c_str();
29  val = sv[i][1].c_str();
30 
31  //get the setting
32 
33  if ( cmp(set, "depth") ) s.depth = std::atof(val);
34  else if ( cmp(set, "delz0") ) s.delz0 = std::atof(val);
35  else if ( cmp(set, "delzfrac") ) s.delzfrac = std::atof(val);
36  else if ( cmp(set, "delzmax") ) s.delzmax = std::atof(val);
37  else if ( cmp(set, "save_grid") ) s.save_grid = eval_txt_bool(val);
38 
39  else if ( cmp(set, "tint") ) s.tint = std::atof(val);
40  else if ( cmp(set, "tunit") ) s.tunit = std::atof(val);
41  else if ( cmp(set, "nsnap") ) s.nsnap = to_long(val);
42  else if ( cmp(set, "nmaxout") ) s.nmaxout = to_long(val);
43  else if ( cmp(set, "dtfac") ) s.dtfac = std::atof(val);
44 
45  else if ( cmp(set, "poro") ) s.poro = std::atof(val);
46  else if ( cmp(set, "perm") ) s.perm = std::atof(val);
47  else if ( cmp(set, "g") ) s.g = std::atof(val);
48  else if ( cmp(set, "mu") ) s.mu = std::atof(val);
49  else if ( cmp(set, "rho") ) s.rho = std::atof(val);
50  else if ( cmp(set, "b") ) s.b = std::atof(val);
51  else if ( cmp(set, "wilt") ) s.wilt = std::atof(val);
52 
53  else if ( cmp(set, "tauevap") ) s.tauevap = std::atof(val);
54  else if ( cmp(set, "Levap") ) s.Levap = std::atof(val);
55  else if ( cmp(set, "infper") ) s.infper = std::atof(val);
56  else if ( cmp(set, "infdur") ) s.infdur = std::atof(val);
57 
58  else if ( cmp(set, "poroc") ) s.poroc = eval_txt_bool(val);
59  else if ( cmp(set, "poroe") ) s.poroe = eval_txt_bool(val);
60  else if ( cmp(set, "Ksat") ) s.Ksat = eval_txt_bool(val);
61  else if ( cmp(set, "psisat") ) s.psisat = eval_txt_bool(val);
62  else if ( cmp(set, "dpsidw") ) s.dpsidw = eval_txt_bool(val);
63  else if ( cmp(set, "dwdz") ) s.dwdz = eval_txt_bool(val);
64  else if ( cmp(set, "K") ) s.K = eval_txt_bool(val);
65  else if ( cmp(set, "D") ) s.D = eval_txt_bool(val);
66  else if ( cmp(set, "w") ) s.w = eval_txt_bool(val);
67  else if ( cmp(set, "we") ) s.we = eval_txt_bool(val);
68  else if ( cmp(set, "wall") ) s.wall = eval_txt_bool(val);
69  else if ( cmp(set, "q") ) s.q = eval_txt_bool(val);
70  else if ( cmp(set, "qtop") ) s.qtop = eval_txt_bool(val);
71  else if ( cmp(set, "qmid") ) s.qmid = eval_txt_bool(val);
72  else if ( cmp(set, "qbot") ) s.qbot = eval_txt_bool(val);
73  else if ( cmp(set, "qall") ) s.qall = eval_txt_bool(val);
74  else if ( cmp(set, "infil") ) s.infil = eval_txt_bool(val);
75  else if ( cmp(set, "t") ) s.t = eval_txt_bool(val);
76  else if ( cmp(set, "tsnap") ) s.tsnap = eval_txt_bool(val);
77 
78  else {
79  std::cout << "FAILURE: unknown setting in settings file: " << set << std::endl;
80  exit(EXIT_FAILURE);
81  }
82  }
83 
84  return(s);
85 }
86 
88  //blank struct
89  Settings a;
90  //grid
91  a.depth = b.depth;
92  a.delz0 = b.delz0;
93  a.delzfrac = b.delzfrac;
94  a.delzmax = b.delzmax;
95  a.save_grid = b.save_grid;
96  //model
97  a.tint = b.tint;
98  a.tunit = b.tunit;
99  a.nsnap = b.nsnap;
100  a.nmaxout = b.nmaxout;
101  a.dtfac = b.dtfac;
102  //physical
103  a.poro = b.poro;
104  a.perm = b.perm;
105  a.g = b.g;
106  a.mu = b.mu;
107  a.rho = b.rho;
108  a.b = b.b;
109  a.wilt = b.wilt;
110  //forcing
111  a.tauevap = b.tauevap;
112  a.Levap = b.Levap;
113  a.infper = b.infper;
114  a.infdur = b.infdur;
115  //trackers and output
116  a.poroc = b.poroc;
117  a.poroe = b.poroe;
118  a.Ksat = b.Ksat;
119  a.psisat = b.psisat;
120  a.dpsidw = b.dpsidw;
121  a.dwdz = b.dwdz;
122  a.K = b.K;
123  a.D = b.D;
124  a.w = b.w;
125  a.we = b.we;
126  a.wall = b.wall;
127  a.q = b.q;
128  a.qtop = b.qtop;
129  a.qmid = b.qmid;
130  a.qbot = b.qbot;
131  a.qall = b.qall;
132  a.infil = b.infil;
133  a.t = b.t;
134  a.tsnap = b.tsnap;
135 
136  return(a);
137 }
Settings::qall
bool qall
whether to track all fluxes
Definition: settings.h:107
Settings::perm
double perm
permeability (m^2)
Definition: settings.h:49
Settings::qbot
bool qbot
whether to track bottom flux
Definition: settings.h:105
Settings::K
bool K
whether to write hydraulic conductivity when snapping
Definition: settings.h:89
Settings::b
double b
Brooks-Corey parameter.
Definition: settings.h:57
settings.h
Settings::infil
bool infil
whether to track infiltration flag
Definition: settings.h:109
Settings::dtfac
double dtfac
safety factor for stable time step
Definition: settings.h:41
Settings
container struct for all the settings variables needed for a BousThermModel run
Definition: settings.h:13
Settings::tauevap
double tauevap
evaporation timescale
Definition: settings.h:65
Settings::w
bool w
whether to water fraction profile when snapping
Definition: settings.h:93
eval_txt_bool
bool eval_txt_bool(const char *s)
converts a string into a bool if it's supposed to be "true" or "false"
Definition: settings.cc:5
Settings::tsnap
bool tsnap
whether to track snap times
Definition: settings.h:113
Settings::t
bool t
whether to track step times
Definition: settings.h:111
Settings::tint
double tint
duration of solve
Definition: settings.h:33
Settings::wilt
double wilt
wilting saturation as fraction of porosity
Definition: settings.h:59
Settings::Levap
double Levap
evaporation depth
Definition: settings.h:67
Settings::mu
double mu
water viscosity (Pa*s)
Definition: settings.h:53
Settings::nmaxout
long nmaxout
maximum length of output vectors (subsampled to accomodate)
Definition: settings.h:39
Settings::delz0
double delz0
surface cell width (m)
Definition: settings.h:21
cmp
bool cmp(const char *s1, const char *s2)
abbreviates strcmp
Definition: settings.cc:10
Settings::poroc
bool poroc
whether to write porosity at cell centers
Definition: settings.h:77
Settings::poro
double poro
porosity
Definition: settings.h:47
Settings::infdur
double infdur
infiltration duration (s)
Definition: settings.h:71
Settings::qtop
bool qtop
whether to track top flux
Definition: settings.h:101
copy_settings
Settings copy_settings(Settings &b)
constructs a copy of another Settings object
Definition: settings.cc:87
Settings::Ksat
bool Ksat
whether to write saturated hydraulic conductivity
Definition: settings.h:81
Settings::poroe
bool poroe
whether to write porosity at cell edges
Definition: settings.h:79
to_long
long to_long(const char *val)
converts a character to an integet
Definition: settings.cc:15
Settings::we
bool we
whether to write water fraction at cell edges when snapping
Definition: settings.h:95
Settings::psisat
bool psisat
whether to write saturated matric head
Definition: settings.h:83
Settings::infper
double infper
infiltration period (s)
Definition: settings.h:69
Settings::tunit
double tunit
time unit to use (number of seconds)
Definition: settings.h:35
Settings::g
double g
gravity (m/s^2)
Definition: settings.h:51
Settings::rho
double rho
water density (kg/m^3)
Definition: settings.h:55
Settings::dwdz
bool dwdz
whether to write moisture fraction derivative when snapping
Definition: settings.h:87
Settings::delzmax
double delzmax
maximum cell width (m)
Definition: settings.h:25
parse_settings
Settings parse_settings(std::vector< std::vector< std::string > > sv)
parses a settings file and returns it in a Settings structure
Definition: settings.cc:20
Settings::dpsidw
bool dpsidw
whether to write dpsidw when snapping
Definition: settings.h:85
Settings::q
bool q
whether to write water flux when snapping
Definition: settings.h:99
Settings::D
bool D
whether to write diffusivity when snapping
Definition: settings.h:91
Settings::wall
bool wall
whether to track all water fractions
Definition: settings.h:97
Settings::depth
double depth
domain depth (m)
Definition: settings.h:19
Settings::qmid
bool qmid
whether to track middle flux
Definition: settings.h:103
Settings::nsnap
long nsnap
number of snaps to take
Definition: settings.h:37
Settings::save_grid
bool save_grid
whether to write grid files
Definition: settings.h:27
Settings::delzfrac
double delzfrac
fraction increase for deeper neighbor cell
Definition: settings.h:23