|
Richards
Solving The Richards equation with temporally periodic surface boundary conditions
|
Go to the documentation of this file.
6 OdeSsp3 (grid.get_n()+1),
12 delz (grid.get_delz()),
13 delze (grid.get_delze()),
14 vefac (grid.get_vefac()),
15 gefac (grid.get_gefac()) {
22 set_silent_snap(
true);
45 D.resize(
n+1, INFINITY);
65 for (i=0; i<
n; i++) set_sol(i, 0.999*
poroc[i]);
94 Ksat*pow(w/wsat, 2.0*b + 3.0)
107 -(b/wsat)*
psisat*pow(w/wsat, -(b + 1))
117 if ( (
t >= ta) && (
t <= tb) )
140 double Richards::f_q (
double K,
double dpsidw,
double dwdz,
double satl,
double satr) {
145 if ( (satl > 1) || (satr <
stg.
wilt) )
147 }
else if (
q > 0 ) {
148 if ( (satr > 1) || (satl <
stg.
wilt) )
175 for (i=1; i<
n; i++) {
186 for (i=0; i<
n+1; i++) {
215 for (
long i=0; i<
n; i++)
222 double dt = INFINITY;
224 for (
long i=0; i<
n+1; i++) {
226 if ( (dtmax < dt) && !std::isnan(dtmax) )
234 if ( (
t >= ta) && (
t <= tb) ) {
255 unsigned long count = 0;
257 double dt = INFINITY;
259 double *w = get_sol();
261 double *dwdt =
new double[
n+1];
262 for (i=0; i<
n; i++) dwdt[i] = INFINITY;
265 while ( (
absmax(dwdt,
n)*dt > atol) && (count < ntol) ) {
280 printf(
" max rel dif requirement is %g\n", rtol);
281 printf(
" PERIODS | MAX REL DIF \n");
282 printf(
" ------- | -------------\n");
287 std::vector<double> q_a(
n, INFINITY);
288 std::vector<double> q_b;
289 for (i=0; i<
n; i++) q_b.push_back(
q[i]);
294 long ord = floor(log10(mrd));
295 while ( (mrd > rtol) || (count <= 5) ) {
298 for (i=0; i<
n; i++) {
303 if ( (!quiet) && (floor(log10(mrd)) != ord ) ) {
304 printf(
" %-7li | %-11g\n", count, mrd);
305 ord = floor(log10(mrd));
314 std::string name = get_name();
315 std::string dirout = get_dirout();
327 std::string name = get_name();
340 write_array(dirout +
"/" + name +
"_w_" + i, get_sol(),
n);
344 tsnap.push_back( tin );
364 qtop.push_back(
q.back() );
372 qbot.push_back(
q[0] );
376 for (
long i=0; i<
n+1; i++)
qall[i].push_back(
q[i] );
379 for (
long i=0; i<
n; i++)
wall[i].push_back( get_sol(i) );
386 std::string name = get_name();
387 std::string dirout = get_dirout();
388 std::vector<float> all, temp;
401 for (
long i=0; i<
n+1; i++) {
403 for (
long unsigned j=0; j<temp.size(); j++)
404 all.push_back(temp[j]);
410 for (
long i=0; i<
n; i++) {
412 for (
long unsigned j=0; j<temp.size(); j++)
413 all.push_back(temp[j]);
double f_w_bot(double poro)
bottom boundary condition
std::vector< std::vector< float > > qall
whether to track ALL fluxes
bool qall
whether to track all fluxes
double f_dwdt(double qt, double qb, double delz)
computes the time derivative of a cell, given fluxes on its sides
double perm
permeability (m^2)
bool qbot
whether to track bottom flux
bool K
whether to write hydraulic conductivity when snapping
std::vector< double > dwdz
derivative of moisture w/r/t z
double b
Brooks-Corey parameter.
std::vector< float > qtop
top boundary flux
std::vector< float > t
time tracker
bool infil
whether to track infiltration flag
double dtfac
safety factor for stable time step
double f_Ksat(double depth, double g, double mu, double rho)
computes saturated hydraulic conductivity (m/s)
container struct for all the settings variables needed for a BousThermModel run
double tauevap
evaporation timescale
bool w
whether to water fraction profile when snapping
void spinup(double rtol=1e-12, bool quiet=true)
integrates over infiltration periods until nearly periodic behavior is established
double f_ksat(double depth, double perm)
computes saturated permeability (m^2)
double f_poro(double depth, double poro)
computes porosity as a function of depth (-)
class for constructing and containing grid information
std::vector< float > qbot
bottom boundary flux
double f_q(double K, double dpsidw, double dwdz, double satl, double satr)
computes the flux between two cells
void before_solve()
does extra stuff before starting a solve
std::vector< double > K
hydraulic conductivity (unsaturated)
bool tsnap
whether to track snap times
double dt_adapt()
computes the next time step, based on the maximum diffusivity
bool t
whether to track step times
std::string int_to_string(long i)
converts an integer into a string
double wilt
wilting saturation as fraction of porosity
void q_updated(double t, bool *qup)
updates fluxes and sets a flag, if needed
void after_step(double tin)
does extra stuff after every step
Richards(Grid grid, Settings stgin)
constructs
const long n
number of cells
std::vector< float > infil
infiltration flag
double Levap
evaporation depth
void infil_times(double t, double *ta, double *tb)
computes beginning and end of next or current infiltration event
const std::vector< double > zc
cell center coordinates (m)
void write_array(const char *fn, T *a, long size)
writes an array to a binary file
double mu
water viscosity (Pa*s)
long nmaxout
maximum length of output vectors (subsampled to accomodate)
bool poroc
whether to write porosity at cell centers
const std::vector< double > ze
cell edge coordinates (m)
std::vector< T > subsample(std::vector< T > v, unsigned long n)
subsample a vector, keeping first and last elements
std::vector< double > psisat
saturated matric head (m)
std::vector< double > dtcons
constants for finding maximum stable time step
const std::vector< double > delz
cell width (m)
double infdur
infiltration duration (s)
double f_dpsidw(double w, double psisat, double wsat, double b)
computes derivative of Brooks-Corey matric head w/r/t water fraction (-)
bool qtop
whether to track top flux
unsigned long mididx
index of approximate middle edge
double maxreldif(T a, T b, long n)
finds the maximum relative difference between two arrays/vectors
Settings copy_settings(Settings &b)
constructs a copy of another Settings object
const std::vector< double > delze
cell widths used for stability calculations (m)
std::vector< double > Ksat
saturated hydraulic conductivity over depth (m/s)
double f_K(double w, double Ksat, double wsat, double b)
computes Brooks-Corey hydraulic conductivity (m/s)
std::vector< float > tsnap
snapshot times
bool Ksat
whether to write saturated hydraulic conductivity
std::vector< std::vector< float > > wall
whether to track ALL water fractions
bool poroe
whether to write porosity at cell edges
bool f_infil(double t)
infiltration flag
std::vector< double > q
fluxes
bool we
whether to write water fraction at cell edges when snapping
long argclose(T a, double b, long n)
find index of value in array closest to a number
bool psisat
whether to write saturated matric head
double infper
infiltration period (s)
void ode_fun(double *solin, double *fout)
ode function for the integrator
const double dep
length/depth of domain (m)
double rho
water density (kg/m^3)
std::vector< double > D
diffusivity (K*d psi /dt)
bool dwdz
whether to write moisture fraction derivative when snapping
std::vector< double > poroe
porosity at cell edges
bool dpsidw
whether to write dpsidw when snapping
void steady(double atol=1e-9, unsigned long ntol=1000000)
integrates to steady state using current state boundary conditions
std::vector< double > we
water fractions at cell edges
double absmax(double *a, long n)
find max magnitude of array
void update_q(double *w, double t)
updates fluxes
bool q
whether to write water flux when snapping
bool D
whether to write diffusivity when snapping
bool wall
whether to track all water fractions
double f_psisat(double depth)
computes the saturation matric head (m)
std::vector< double > poroc
porosity at cell centers (maximum saturation fraction)
const std::vector< double > vefac
factors for cell edge values
bool qmid
whether to track middle flux
std::vector< float > qmid
middle boundary flux
const std::vector< double > gefac
factors for cell edge gradients
void after_snap(std::string dirout, long isnap, double t)
does extra stuff after every snap
void after_solve()
does extra stuff after integrating
Settings stg
settings container
std::vector< double > dpsidw
derivative of psi w/r/t moisture