SNOWPACK 20240419.9b8fae6
ReSolver1d.h
Go to the documentation of this file.
1/*
2 * SNOWPACK stand-alone
3 *
4 * Copyright WSL Institute for Snow and Avalanche Research SLF, DAVOS, SWITZERLAND
5*/
6/* This file is part of Snowpack.
7 Snowpack is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Snowpack is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Snowpack. If not, see <http://www.gnu.org/licenses/>.
19*/
25#ifndef RESOLVER1D_H
26#define RESOLVER1D_H
27
30
37
38 public:
39 ReSolver1d(const SnowpackConfig& cfg, const bool& matrix_part); // Class constructor
40 void SolveRichardsEquation(SnowStation& Xdata, SurfaceFluxes& Sdata, double& ql, const mio::Date& date);
41
42 double surfacefluxrate; // Surfacefluxrate for solving RE. It is either surface of snow, in case of snowpack and solving RE for snow, or surface of soil, when no snowpack and/or solving RE only for soil.
43 double soilsurfacesourceflux; // Soilsurfacesourceflux for solving RE. This is used when we use RE for snow AND there is a snowpack AND the lowest snow element is removed.
44
45 const static double max_theta_ice; // Maximum allowed theta[ICE]. RE always need some pore space, which is defined by this value.
46 const static double REQUIRED_ACCURACY_THETA;
47
48 // Solvers
49 static int TDMASolver (size_t n, double *a, double *b, double *c, double *v, double *x); // Thomas algorithm for tridiagonal matrices
50 static int pinv(int m, int n, int lda, double *a); // Full matrix inversion
51
52 private:
53 std::string variant;
54
55 //To prevent string comparisons, we define an enumerated list:
56 enum watertransportmodels{UNDEFINED, BUCKET, NIED, RICHARDSEQUATION};
57 //K_Average types
58 enum K_AverageTypes{ARITHMETICMEAN, LOGMEAN, GEOMETRICMEAN, HARMONICMEAN, MINIMUMVALUE, UPSTREAM};
59 //K_frozen_soil types
60 enum K_frozen_soilTypes{IGNORE, OMEGA, LIQUIDPORESPACE};
61 //Solvers
62 enum SOLVERS{DGESVD, DGTSV, TDMA};
63 //Boundary conditions
64 enum BoundaryConditions{DIRICHLET, NEUMANN, LIMITEDFLUXEVAPORATION, LIMITEDFLUXINFILTRATION, LIMITEDFLUX, WATERTABLE, FREEDRAINAGE, GRAVITATIONALDRAINAGE, SEEPAGEBOUNDARY, SEAICE};
65 //Salinity mixing models
66 enum SalinityMixingModels{NONE, CAPILLARY_GRAVITY, DENSITY_DIFFERENCE, DENSITY_GRAVITY};
67
68 watertransportmodels iwatertransportmodel_snow, iwatertransportmodel_soil;
69
70 std::string watertransportmodel_snow;
71 std::string watertransportmodel_soil;
72 BoundaryConditions BottomBC; //Bottom boundary condition (recommended choice either DIRICHLET with saturation (lower boundary in water table) or FREEDRAINAGE (lower boundary not in water table))
73 K_AverageTypes K_AverageType; //Implemented choices: ARITHMETICMEAN (recommended), LOGMEAN, GEOMETRICMEAN, HARMONICMEAN, MINIMUMVALUE, UPSTREAM
74 K_frozen_soilTypes K_frozen_soilType; //Implemented choices: IGNORE (recommended), OMEGA, LIQUIDPORESPACE
75 double omega; //The value of omega to use when K_frozen_soilType == OMEGA.
76 bool enable_pref_flow; //true: dual domain approach, false: classic Richards equation.
77 double pref_flow_param_th; //Tuning parameter: saturation threshold in preferential flow
78 double pref_flow_param_N; //Tuning parameter: number of preferential flow paths for heat exchange
79 double pref_flow_param_heterogeneity_factor; //Tuning parameter: heterogeneity factor for grain size
80 bool enable_ice_reservoir; // Ice reservoir or not
81 bool runSoilInitializer; // Run the function that initializes the soil in thermal equilibrium upon first function call
82
83 double sn_dt; //SNOWPACK time step
84 bool allow_surface_ponding; //boolean to switch on/off the formation of surface ponds in case prescribed infiltration flux exceeds matrix capacity
85 bool matrix; //boolean to define if water transport is calculated for matrixflow or preferential flow
86 SalinityTransport::SalinityTransportSolvers SalinityTransportSolver; //How to solve salinity transport?
87
88 // Grid info
89 std::vector<double> dz; //Layer height (in meters)
90 std::vector<double> z; //Height above the surface (so -1 is 1m below surface)
91 std::vector<double> dz_up; //Distance to upper node (in meters)
92 std::vector<double> dz_down; //Distance to lower node (in meters)
93 std::vector<double> dz_; //Layer distance for the finite differences, see Rathfelder (2004).
94
95 // General functions
96 void InitializeGrid(const std::vector<ElementData>& EMS, const size_t& lowernode, const size_t& uppernode);
97 std::vector<double> AssembleRHS(const size_t& lowernode, const size_t& uppernode, const std::vector<double>& h_np1_m, const std::vector<double>& theta_n, const std::vector<double>& theta_np1_m, const std::vector<double>& theta_i_n, const std::vector<double>& theta_i_np1_m, const std::vector<double>& s, const double& dt, const std::vector<double>& rho, const std::vector<double>& k_np1_m_im12, const std::vector<double>& k_np1_m_ip12, const BoundaryConditions aTopBC, const double& TopFluxRate, const BoundaryConditions aBottomBC, const double& BottomFluxRate, const SnowStation& Xdata, SalinityTransport& Salinity, const SalinityMixingModels& SALINITY_MIXING);
98
99 // Solver control variables
100 const static double REQUIRED_ACCURACY_H, convergencecriterionthreshold, MAX_ALLOWED_DELTA_H;
101 const static size_t INCR_ITER, DECR_ITER, MAX_ITER, BS_MAX_ITER;
102 const static double MIN_VAL_TIMESTEP, MAX_VAL_TIMESTEP, MIN_DT_FOR_INFILTRATION;
103 const static double SF_epsilon;
104};
105#endif //End of ReSolver1d.h
This module contains the solver for the 1d Richards Equation for the 1d snowpack model.
Definition: ReSolver1d.h:36
static const double max_theta_ice
Definition: ReSolver1d.h:45
double soilsurfacesourceflux
Definition: ReSolver1d.h:43
ReSolver1d(const SnowpackConfig &cfg, const bool &matrix_part)
Definition: ReSolver1d.cc:76
void SolveRichardsEquation(SnowStation &Xdata, SurfaceFluxes &Sdata, double &ql, const mio::Date &date)
Solve Richards Equation Solve Richards Equation .
Definition: ReSolver1d.cc:653
static const double REQUIRED_ACCURACY_THETA
Definition: ReSolver1d.h:46
double surfacefluxrate
Definition: ReSolver1d.h:42
static int TDMASolver(size_t n, double *a, double *b, double *c, double *v, double *x)
Solving system of equations using Thomas Algorithm The following function solves a tridiagonal syste...
Definition: ReSolver1d.cc:232
static int pinv(int m, int n, int lda, double *a)
Solving system of equations using matrix inversion The following function solves a tridiagonal syste...
Definition: ReSolver1d.cc:392
This module contains the solver for the diffusion-advection equation for the transport of salinity.
Definition: SalinityTransport.h:34
SalinityTransportSolvers
Definition: SalinityTransport.h:43
Definition: DataClasses.h:604
Definition: SnowpackConfig.h:28
Definition: DataClasses.h:733