Richards
Solving The Richards equation with temporally periodic surface boundary conditions
richards.h
Go to the documentation of this file.
1 #ifndef RICHARDS_H_
2 #define RICHARDS_H_
3 
5 
39 #include <cmath>
40 #include <cstdio>
41 #include <string>
42 #include <vector>
43 #include <iostream>
44 
45 #include "io.h"
46 #include "grid.h"
47 #include "util.h"
48 #include "settings.h"
49 
50 //header file for ODE integrator class
51 #include "ode_ssp_3.h"
52 
54 class Richards : public OdeSsp3 {
55 
56 public:
57 
59 
63  Richards (Grid grid, Settings stgin);
64 
67 
68  //--------------
69  //grid variables
70 
72  const long n;
74  const double dep;
76  const std::vector<double> ze;
78  const std::vector<double> zc;
80  const std::vector<double> delz;
82  const std::vector<double> delze;
84  const std::vector<double> vefac;
86  const std::vector<double> gefac;
88  std::vector<double> dtcons;
89 
90  //------------------
91  //physical variables
92 
93  //static depth-varying quantities
94 
96  std::vector<double> poroc;
98  std::vector<double> poroe;
100  std::vector<double> Ksat;
102  std::vector<double> psisat;
103 
104  //dynamic, depth-varying quantities
105 
107  std::vector<double> we;
109  std::vector<double> dpsidw;
111  std::vector<double> dwdz;
113  std::vector<double> K;
115  std::vector<double> D;
117  std::vector<double> q;
118 
119  //--------
120  //trackers
121 
123  std::vector<float> t;
125  std::vector<float> tsnap;
127  std::vector<float> qtop;
129  std::vector<float> qmid;
131  unsigned long mididx;
133  std::vector<float> qbot;
135  std::vector< std::vector<float> > qall;
137  std::vector< std::vector<float> > wall;
139  std::vector<float> infil;
140 
141  //------------------
142  //physical functions
143 
145  double f_poro (double depth, double poro);
146 
148  double f_ksat (double depth, double perm);
149 
151  double f_Ksat (double depth, double g, double mu, double rho);
152 
154  double f_K (double w, double Ksat, double wsat, double b);
155 
157  double f_psisat (double depth);
158 
160  double f_dpsidw (double w, double psisat, double wsat, double b);
161 
163  bool f_infil (double t);
164 
166  double f_w_bot (double poro);
167 
168  //--------------------
169  //ODE solver functions
170 
172  void infil_times (double t, double *ta, double *tb);
173 
175  double f_q (double K, double dpsidw, double dwdz, double satl, double satr);
176 
178  double f_dwdt (double qt, double qb, double delz);
179 
181  void update_q (double *w, double t);
182 
184  void ode_fun (double *solin, double *fout);
185 
187  double dt_adapt ();
188 
190  void steady (double atol=1e-9, unsigned long ntol=1000000);
191 
193  void spinup (double rtol=1e-12, bool quiet=true);
194 
195  //-----------------
196  //extras
197 
199  void before_solve ();
201  void after_snap (std::string dirout, long isnap, double t);
203  void q_updated (double t, bool *qup);
205  void after_step (double tin);
207  void after_solve ();
208 
209 };
210 
211 #endif
Richards::f_w_bot
double f_w_bot(double poro)
bottom boundary condition
Definition: richards.cc:124
Richards::qall
std::vector< std::vector< float > > qall
whether to track ALL fluxes
Definition: richards.h:135
Richards::f_dwdt
double f_dwdt(double qt, double qb, double delz)
computes the time derivative of a cell, given fluxes on its sides
Definition: richards.cc:155
Richards::dwdz
std::vector< double > dwdz
derivative of moisture w/r/t z
Definition: richards.h:111
Richards::qtop
std::vector< float > qtop
top boundary flux
Definition: richards.h:127
Richards::t
std::vector< float > t
time tracker
Definition: richards.h:123
settings.h
Richards::f_Ksat
double f_Ksat(double depth, double g, double mu, double rho)
computes saturated hydraulic conductivity (m/s)
Definition: richards.cc:88
Settings
container struct for all the settings variables needed for a BousThermModel run
Definition: settings.h:13
Richards::spinup
void spinup(double rtol=1e-12, bool quiet=true)
integrates over infiltration periods until nearly periodic behavior is established
Definition: richards.cc:276
Richards::f_ksat
double f_ksat(double depth, double perm)
computes saturated permeability (m^2)
Definition: richards.cc:81
Richards::f_poro
double f_poro(double depth, double poro)
computes porosity as a function of depth (-)
Definition: richards.cc:74
Grid
class for constructing and containing grid information
Definition: grid.h:17
Richards::qbot
std::vector< float > qbot
bottom boundary flux
Definition: richards.h:133
grid.h
Richards::f_q
double f_q(double K, double dpsidw, double dwdz, double satl, double satr)
computes the flux between two cells
Definition: richards.cc:140
Richards::before_solve
void before_solve()
does extra stuff before starting a solve
Definition: richards.cc:313
Richards::K
std::vector< double > K
hydraulic conductivity (unsaturated)
Definition: richards.h:113
Richards::dt_adapt
double dt_adapt()
computes the next time step, based on the maximum diffusivity
Definition: richards.cc:219
Richards::q_updated
void q_updated(double t, bool *qup)
updates fluxes and sets a flag, if needed
Definition: richards.cc:347
Richards::after_step
void after_step(double tin)
does extra stuff after every step
Definition: richards.cc:355
Richards::Richards
Richards(Grid grid, Settings stgin)
constructs
Definition: richards.cc:5
Richards::n
const long n
number of cells
Definition: richards.h:72
Richards::infil
std::vector< float > infil
infiltration flag
Definition: richards.h:139
Richards::infil_times
void infil_times(double t, double *ta, double *tb)
computes beginning and end of next or current infiltration event
Definition: richards.cc:133
Richards::zc
const std::vector< double > zc
cell center coordinates (m)
Definition: richards.h:78
Richards::ze
const std::vector< double > ze
cell edge coordinates (m)
Definition: richards.h:76
Richards::psisat
std::vector< double > psisat
saturated matric head (m)
Definition: richards.h:102
Richards::dtcons
std::vector< double > dtcons
constants for finding maximum stable time step
Definition: richards.h:88
Richards::delz
const std::vector< double > delz
cell width (m)
Definition: richards.h:80
Richards::f_dpsidw
double f_dpsidw(double w, double psisat, double wsat, double b)
computes derivative of Brooks-Corey matric head w/r/t water fraction (-)
Definition: richards.cc:105
Richards::mididx
unsigned long mididx
index of approximate middle edge
Definition: richards.h:131
Richards::delze
const std::vector< double > delze
cell widths used for stability calculations (m)
Definition: richards.h:82
Richards::Ksat
std::vector< double > Ksat
saturated hydraulic conductivity over depth (m/s)
Definition: richards.h:100
Richards::f_K
double f_K(double w, double Ksat, double wsat, double b)
computes Brooks-Corey hydraulic conductivity (m/s)
Definition: richards.cc:92
Richards::tsnap
std::vector< float > tsnap
snapshot times
Definition: richards.h:125
Richards::wall
std::vector< std::vector< float > > wall
whether to track ALL water fractions
Definition: richards.h:137
Richards::f_infil
bool f_infil(double t)
infiltration flag
Definition: richards.cc:111
Richards::q
std::vector< double > q
fluxes
Definition: richards.h:117
Richards::ode_fun
void ode_fun(double *solin, double *fout)
ode function for the integrator
Definition: richards.cc:208
Richards::dep
const double dep
length/depth of domain (m)
Definition: richards.h:74
Richards
the main model class
Definition: richards.h:54
Richards::D
std::vector< double > D
diffusivity (K*d psi /dt)
Definition: richards.h:115
Richards::poroe
std::vector< double > poroe
porosity at cell edges
Definition: richards.h:98
io.h
Richards::steady
void steady(double atol=1e-9, unsigned long ntol=1000000)
integrates to steady state using current state boundary conditions
Definition: richards.cc:250
Richards::we
std::vector< double > we
water fractions at cell edges
Definition: richards.h:107
Richards::update_q
void update_q(double *w, double t)
updates fluxes
Definition: richards.cc:161
Richards::f_psisat
double f_psisat(double depth)
computes the saturation matric head (m)
Definition: richards.cc:98
Richards::poroc
std::vector< double > poroc
porosity at cell centers (maximum saturation fraction)
Definition: richards.h:96
Richards::vefac
const std::vector< double > vefac
factors for cell edge values
Definition: richards.h:84
util.h
Richards::qmid
std::vector< float > qmid
middle boundary flux
Definition: richards.h:129
Richards::gefac
const std::vector< double > gefac
factors for cell edge gradients
Definition: richards.h:86
Richards::after_snap
void after_snap(std::string dirout, long isnap, double t)
does extra stuff after every snap
Definition: richards.cc:326
Richards::after_solve
void after_solve()
does extra stuff after integrating
Definition: richards.cc:384
Richards::stg
Settings stg
settings container
Definition: richards.h:66
Richards::dpsidw
std::vector< double > dpsidw
derivative of psi w/r/t moisture
Definition: richards.h:109