Richards
Solving The Richards equation with temporally periodic surface boundary conditions
main_periodic.cc
Go to the documentation of this file.
1 
3 #include <string>
4 #include <vector>
5 #include <iostream>
6 
7 #include "io.h"
8 #include "grid.h"
9 #include "settings.h"
10 #include "richards.h"
11 
13 int main (int argc, char **argv) {
14 
15  if ( argc != 3 )
16  print_exit("richards must be given two command line arguments\n 1. path to settings file\n 2. path to output directory");
17 
18  printf(" starting periodic richards integration\n");
19 
20  //output directory
21  std::string dirout = argv[2];
22 
23  //read settings
24  Settings stg = parse_settings(read_values(argv[1]));
25 
26  //create grid
27  Grid grid(stg.depth, stg.delz0, stg.delzfrac, stg.delzmax);
28  long n = grid.get_n();
29  printf(" %g meter grid created with %li cells\n", grid.get_dep(), grid.get_n());
30  printf(" surface cell depth: %g cm\n", grid.get_delze()[n-1]*100);
31  printf(" bottom cell depth: %g cm\n", grid.get_delze()[0]*100);
32  if ( stg.save_grid )
33  grid.save(dirout);
34 
35  //create system
36  Richards rich(grid, stg);
37 
38  //integrate
39  printf(" spinning up...\n");
40  rich.spinup(1e-6, false);
41  printf(" spinup finished @ t = %g, doing short integration\n", rich.get_t());
42  long unsigned nstep = rich.get_nstep();
43  rich.solve_adaptive(2*stg.infper, stg.infper/1e12, stg.nsnap, dirout.c_str());
44  printf(" %lu short integration steps\n", rich.get_nstep() - nstep);
45  printf(" %lu total steps\n", rich.get_nstep());
46  printf(" done\n");
47 
48  return(0);
49 }
read_values
std::vector< std::vector< std::string > > read_values(const char *fn)
reads a settings file into a vector of vectors of strings
Definition: io.cc:72
print_exit
void print_exit(const char *msg)
prints a message before quitting the program
Definition: io.cc:5
settings.h
Grid::get_delze
const std::vector< double > get_delze() const
gets arrayvector of cell widths used for stability calculations (m)
Definition: grid.h:40
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
Grid::get_dep
double get_dep()
gets length/depth of the domain (m)
Definition: grid.h:32
Grid
class for constructing and containing grid information
Definition: grid.h:17
Grid::save
void save(std::string dirout)
writes grid arrays into a directory as binary files
Definition: grid.cc:41
grid.h
Settings::delz0
double delz0
surface cell width (m)
Definition: settings.h:21
Grid::get_n
long get_n()
gets number of cells
Definition: grid.h:30
Settings::infper
double infper
infiltration period (s)
Definition: settings.h:69
Richards
the main model class
Definition: richards.h:54
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
io.h
main
int main(int argc, char **argv)
driver function compiled into richards_periodic.exe
Definition: main_periodic.cc:13
richards.h
Settings::depth
double depth
domain depth (m)
Definition: settings.h:19
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