Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the code to count for groundwater (SSM v.0.3.2) #234

Merged
merged 90 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
27208b0
add groundwater table
MostafaGomaa93 Jun 12, 2024
2a27ca7
modify to count for groundwater
MostafaGomaa93 Jun 12, 2024
5bb5dee
modify to count for groundwater
MostafaGomaa93 Jun 13, 2024
1df36f2
modify to count for groundwater
MostafaGomaa93 Jun 14, 2024
d838eb5
Update STEMMUS_SCOPE.m
MostafaGomaa93 Jun 17, 2024
f3383e6
Update src/+conductivity/calculateVaporVariables.m
MostafaGomaa93 Jun 19, 2024
936f7ba
Update src/+dryair/assembleCoefficientMatrices.m
MostafaGomaa93 Jun 19, 2024
793e731
Update assembleCoefficientMatrices.m
MostafaGomaa93 Jun 19, 2024
0e95e18
Update assembleCoefficientMatrices.m
MostafaGomaa93 Jun 19, 2024
55016fd
Update src/+dryair/calculateDryAirParameters.m
MostafaGomaa93 Jun 19, 2024
6d092ac
Update calculateDryAirParameters.m
MostafaGomaa93 Jun 19, 2024
3950950
Update assembleCoefficientMatrices.m
MostafaGomaa93 Jun 19, 2024
3edd6d7
Update calculateBoundaryConditions.m
MostafaGomaa93 Jun 19, 2024
770a709
Update calculateBoundaryConditions.m
MostafaGomaa93 Jun 19, 2024
2465f90
Update calculateMatricCoefficients.m
MostafaGomaa93 Jun 19, 2024
f695bb2
Update solveTridiagonalMatrixEquations.m
MostafaGomaa93 Jun 19, 2024
97cdca7
Update src/+energy/assembleCoefficientMatrices.m
MostafaGomaa93 Jun 19, 2024
856bab6
Update assembleCoefficientMatrices.m
MostafaGomaa93 Jun 19, 2024
9937d58
Update calculateBoundaryConditions.m
MostafaGomaa93 Jun 19, 2024
30e82da
Update calculateEnergyParameters.m
MostafaGomaa93 Jun 19, 2024
d69d4b5
Update src/+energy/calculateEnergyParameters.m
MostafaGomaa93 Jun 19, 2024
b6f95cc
Update src/+energy/solveEnergyBalanceEquations.m
MostafaGomaa93 Jun 19, 2024
c80f711
Update src/+energy/solveEnergyBalanceEquations.m
MostafaGomaa93 Jun 19, 2024
8d6ee51
Update solveEnergyBalanceEquations.m
MostafaGomaa93 Jun 19, 2024
e9c4076
Update calculateMatricCoefficients.m
MostafaGomaa93 Jun 19, 2024
66077b4
Update calculateEnergyFluxes.m
MostafaGomaa93 Jun 19, 2024
4524e01
Update src/+energy/solveTridiagonalMatrixEquations.m
MostafaGomaa93 Jun 19, 2024
f0c2580
Update solveTridiagonalMatrixEquations.m
MostafaGomaa93 Jun 19, 2024
a8d027f
Update src/+groundwater/calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 19, 2024
4a439c5
Update src/+groundwater/calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 19, 2024
5a58765
Update src/+groundwater/calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 19, 2024
48c244f
Update src/+groundwater/calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 19, 2024
562902a
Update src/+groundwater/calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 19, 2024
9d4b252
Update src/+groundwater/calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 19, 2024
5f27b27
Update src/+groundwater/calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 19, 2024
2cb7915
Update calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 19, 2024
02a9c14
Update assembleCoefficientMatrices.m
MostafaGomaa93 Jun 19, 2024
5a60547
Update calculateMatricCoefficients.m
MostafaGomaa93 Jun 19, 2024
8139416
Update calculateTimeDerivatives.m
MostafaGomaa93 Jun 19, 2024
12a5bc8
Update calculatesSoilWaterFluxes.m
MostafaGomaa93 Jun 19, 2024
f7919de
Update solveSoilMoistureBalance.m
MostafaGomaa93 Jun 19, 2024
deec78a
Update solveTridiagonalMatrixEquations.m
MostafaGomaa93 Jun 19, 2024
51d91a2
Update calculateEvapotranspiration.m
MostafaGomaa93 Jun 19, 2024
e2cef1e
Update src/+groundwater/findPhreaticSurface.m
MostafaGomaa93 Jun 19, 2024
e02417b
Update src/+groundwater/findPhreaticSurface.m
MostafaGomaa93 Jun 19, 2024
9c13f83
Update src/+groundwater/findPhreaticSurface.m
MostafaGomaa93 Jun 19, 2024
795ba07
Update src/+groundwater/findPhreaticSurface.m
MostafaGomaa93 Jun 19, 2024
b311b60
Update src/+groundwater/findPhreaticSurface.m
MostafaGomaa93 Jun 19, 2024
ef6645d
Update src/+groundwater/findPhreaticSurface.m
MostafaGomaa93 Jun 19, 2024
7dc5590
Update findPhreaticSurface.m
MostafaGomaa93 Jun 19, 2024
b54c23b
Update findPhreaticSurface.m
MostafaGomaa93 Jun 19, 2024
0722e69
Update readGroundwaterSettings.m
MostafaGomaa93 Jun 19, 2024
bcbb9c9
Update calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 19, 2024
a88f409
Update readGroundwaterSettings.m
MostafaGomaa93 Jun 19, 2024
ed9ef63
Update src/+io/loadForcingData.m
MostafaGomaa93 Jun 19, 2024
b52de78
Update src/+io/loadForcingData.m
MostafaGomaa93 Jun 19, 2024
1e0ce70
Update src/+io/loadForcingData.m
MostafaGomaa93 Jun 19, 2024
64a7034
Update src/+io/loadForcingData.m
MostafaGomaa93 Jun 19, 2024
54550a6
Update src/+io/loadForcingData.m
MostafaGomaa93 Jun 19, 2024
8aadaf7
Update src/+io/loadForcingData.m
MostafaGomaa93 Jun 19, 2024
1093800
Update src/+io/loadForcingData.m
MostafaGomaa93 Jun 19, 2024
2e03ece
Update src/+io/loadForcingData.m
MostafaGomaa93 Jun 19, 2024
8136430
Update loadForcingData.m
MostafaGomaa93 Jun 19, 2024
b25b72a
Update loadForcingData.m
MostafaGomaa93 Jun 19, 2024
b6cafb8
Update loadForcingData.m
MostafaGomaa93 Jun 19, 2024
dc4c66e
Update calc_rsoil.m
MostafaGomaa93 Jun 19, 2024
a269115
Update calc_rsoil.m
MostafaGomaa93 Jun 19, 2024
971df7e
Update calc_rsoil.m
MostafaGomaa93 Jun 19, 2024
ce4128a
Update calc_rsoil.m
MostafaGomaa93 Jun 19, 2024
bc2d222
Update calc_rsoil.m
MostafaGomaa93 Jun 19, 2024
309c3b4
Update src/+soilmoisture/calculateBoundaryConditions.m
MostafaGomaa93 Jun 19, 2024
c4d4915
Update src/+soilmoisture/calculateBoundaryConditions.m
MostafaGomaa93 Jun 19, 2024
07a54d1
Update src/+soilmoisture/calculateBoundaryConditions.m
MostafaGomaa93 Jun 19, 2024
7bd1260
Update src/+soilmoisture/calculateBoundaryConditions.m
MostafaGomaa93 Jun 19, 2024
9ba26bf
Update calculateBoundaryConditions.m
MostafaGomaa93 Jun 19, 2024
a582473
Update src/STEMMUS_SCOPE.m
MostafaGomaa93 Jun 19, 2024
1b3e337
modify to count for groundwater
MostafaGomaa93 Jun 19, 2024
ac9180e
Update calculateGroundwaterRecharge.m
MostafaGomaa93 Jun 20, 2024
fe18914
Update readGroundwaterSettings.m
MostafaGomaa93 Jun 20, 2024
7614318
Update readGroundwaterSettings.m
MostafaGomaa93 Jun 20, 2024
2ce2a5e
Update src/STEMMUS_SCOPE_exe.m
MostafaGomaa93 Jun 21, 2024
b2971c1
Update src/STEMMUS_SCOPE.m
MostafaGomaa93 Jun 21, 2024
fbaec06
Update STEMMUS_SCOPE.m
MostafaGomaa93 Jun 21, 2024
dcdb1bb
Update readGroundwaterSettings.m
MostafaGomaa93 Jun 21, 2024
fc9b954
Update STEMMUS_SCOPE.m
MostafaGomaa93 Jun 21, 2024
9d2d964
Update readGroundwaterSettings.m
MostafaGomaa93 Jun 21, 2024
0bee5c4
Update STEMMUS_SCOPE.m
MostafaGomaa93 Jun 21, 2024
cd83ce6
add changes to changelog file
SarahAlidoost Jun 21, 2024
accde11
add initial values for bmi variables
SarahAlidoost Jun 21, 2024
698f5e4
regenerate exe file
SarahAlidoost Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@
**Changed:**

- Added changes to support groundwater coupling via BMI in
[#221](https://github.com/EcoExtreML/STEMMUS_SCOPE/pull/221)
[#221](https://github.com/EcoExtreML/STEMMUS_SCOPE/pull/221) and
[#234](https://github.com/EcoExtreML/STEMMUS_SCOPE/pull/234)
- Save water stress factor and water potential into csv files.
[#229](https://github.com/EcoExtreML/STEMMUS_SCOPE/pull/229)

**Fixed:**

- Calculations of surface runoff discussed in
[#232](https://github.com/EcoExtreML/STEMMUS_SCOPE/issues/232) and fixed in
[#234](https://github.com/EcoExtreML/STEMMUS_SCOPE/pull/234)
- The bug in the QVT calculations discussed in
[#230](https://github.com/EcoExtreML/STEMMUS_SCOPE/issues/230) and fixed in
[#234](https://github.com/EcoExtreML/STEMMUS_SCOPE/pull/234)
- The bug in activating the dry air calculations discussed in
[#227](https://github.com/EcoExtreML/STEMMUS_SCOPE/issues/230) and fixed in
[#234](https://github.com/EcoExtreML/STEMMUS_SCOPE/pull/227)


<a name="1.5.0"></a>
# [1.5.0](https://github.com/EcoExtreML/STEMMUS_SCOPE/releases/tag/1.5.0) - 3 Jan 2024
Expand Down
Binary file modified run_model_on_snellius/exe/STEMMUS_SCOPE
Binary file not shown.
5 changes: 5 additions & 0 deletions src/+conductivity/calculateVaporVariables.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@

if SoilVariables.DVT_Switch == 1
Eta(i, j) = ThermalConductivityCapacity.ZETA(i, j) * EnhnLiqIsland / (f0 * Theta_g(i, j));
% When Theta_g(i, j) = 0, both EnhnLiqIsland and f0 have too low values -> leading to extreme large value of Eta and QVT, ...
% The following line (if statement) tries to solve the issue mentioned in https://github.com/EcoExtreML/STEMMUS_SCOPE/issues/230
if Theta_g(i, j) <= 1e-2 % added by Mostafa
Eta(i, j) = 0;
end
else
Eta(i, j) = 0;
end
Expand Down
37 changes: 22 additions & 15 deletions src/+dryair/assembleCoefficientMatrices.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [RHS, AirMatrices, SAVE] = assembleCoefficientMatrices(AirMatrices, SoilVariables, Delt_t, P_g)
function [RHS, AirMatrices, SAVE] = assembleCoefficientMatrices(AirMatrices, SoilVariables, Delt_t, P_g, GroundwaterSettings)
%{
Assemble the coefficient matrices of Equation 4.32 STEMMUS Technical
Notes, page 44, for dry air equation.
Expand All @@ -20,14 +20,21 @@
% Alias of SoilVariables
SV = SoilVariables;

if ~GroundwaterSettings.GroundwaterCoupling % no Groundwater coupling, added by Mostafa
indxBotm = 1; % index of bottom layer is 1, STEMMUS calculates from bottom to top
else % Groundwater Coupling is activated
% index of bottom layer after neglecting saturated layers (from bottom to top)
indxBotm = GroundwaterSettings.indxBotmLayer;
end

if ModelSettings.Thmrlefc
RHS(1) = -C7(1) + (C3(1, 1) * P_g(1) + C3(1, 2) * P_g(2)) / Delt_t ...
- (C2(1, 1) / Delt_t + C5(1, 1)) * SV.TT(1) - (C2(1, 2) / Delt_t + C5(1, 2)) * SV.TT(2) ...
- (C1(1, 1) / Delt_t + C4(1, 1)) * SV.hh(1) - (C1(1, 2) / Delt_t + C4(1, 2)) * SV.hh(2) ...
+ (C2(1, 1) / Delt_t) * SV.T(1) + (C2(1, 2) / Delt_t) * SV.T(2) ...
+ (C1(1, 1) / Delt_t) * SV.h(1) + (C1(1, 2) / Delt_t) * SV.h(2);
RHS(indxBotm) = -C7(indxBotm) + (C3(indxBotm, 1) * P_g(indxBotm) + C3(indxBotm, 2) * P_g(indxBotm + 1)) / Delt_t ...
- (C2(indxBotm, 1) / Delt_t + C5(indxBotm, 1)) * SV.TT(indxBotm) - (C2(indxBotm, 2) / Delt_t + C5(indxBotm, 2)) * SV.TT(indxBotm + 1) ...
- (C1(indxBotm, 1) / Delt_t + C4(indxBotm, 1)) * SV.hh(indxBotm) - (C1(indxBotm, 2) / Delt_t + C4(indxBotm, 2)) * SV.hh(indxBotm + 1) ...
+ (C2(indxBotm, 1) / Delt_t) * SV.T(indxBotm) + (C2(indxBotm, 2) / Delt_t) * SV.T(indxBotm + 1) ...
+ (C1(indxBotm, 1) / Delt_t) * SV.h(indxBotm) + (C1(indxBotm, 2) / Delt_t) * SV.h(indxBotm + 1);

for i = 2:ModelSettings.NL
for i = indxBotm + 1:ModelSettings.NL
ARG1 = C2(i - 1, 2) / Delt_t;
ARG2 = C2(i, 1) / Delt_t;
ARG3 = C2(i, 2) / Delt_t;
Expand All @@ -49,10 +56,10 @@
+ (C2(n - 1, 2) / Delt_t) * SV.T(n - 1) + (C2(n, 1) / Delt_t) * SV.T(n) ...
+ (C1(n - 1, 2) / Delt_t) * SV.h(n - 1) + (C1(n, 1) / Delt_t) * SV.h(n);
else
RHS(1) = -C7(1) + (C3(1, 1) * P_g(1) + C3(1, 2) * P_g(2)) / Delt_t ...
- (C1(1, 1) / Delt_t + C4(1, 1)) * SV.hh(1) - (C1(1, 2) / Delt_t + C4(1, 2)) * SV.hh(2) ...
+ (C1(1, 1) / Delt_t) * SV.h(1) + (C1(1, 2) / Delt_t) * SV.h(2);
for i = 2:ModelSettings.NL
RHS(indxBotm) = -C7(indxBotm) + (C3(indxBotm, 1) * P_g(indxBotm) + C3(indxBotm, 2) * P_g(indxBotm + 1)) / Delt_t ...
- (C1(indxBotm, 1) / Delt_t + C4(indxBotm, 1)) * SV.hh(indxBotm) - (C1(indxBotm, 2) / Delt_t + C4(indxBotm, 2)) * SV.hh(indxBotm + 1) ...
+ (C1(indxBotm, 1) / Delt_t) * SV.h(indxBotm) + (C1(indxBotm, 2) / Delt_t) * SV.h(indxBotm + 1);
for i = indxBotm + 1:ModelSettings.NL
ARG4 = C1(i - 1, 2) / Delt_t;
ARG5 = C1(i, 1) / Delt_t;
ARG6 = C1(i, 2) / Delt_t;
Expand All @@ -65,17 +72,17 @@
+ (C1(n - 1, 2) / Delt_t) * SV.h(n - 1) + (C1(n, 1) / Delt_t) * SV.h(n);
end

for i = 1:ModelSettings.NN
for i = indxBotm:ModelSettings.NN
for j = 1:ModelSettings.nD
C6(i, j) = C3(i, j) / Delt_t + C6(i, j);
end
end

AirMatrices.C6 = C6;

SAVE(1, 1, 3) = RHS(1);
SAVE(1, 2, 3) = C6(1, 1);
SAVE(1, 3, 3) = C6(1, 2);
SAVE(1, 1, 3) = RHS(indxBotm);
SAVE(1, 2, 3) = C6(indxBotm, 1);
SAVE(1, 3, 3) = C6(indxBotm, 2);
SAVE(2, 1, 3) = RHS(n);
SAVE(2, 2, 3) = C6(n - 1, 2);
SAVE(2, 3, 3) = C6(n, 1);
Expand Down
23 changes: 16 additions & 7 deletions src/+dryair/calculateBoundaryConditions.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [RHS, AirMatrices] = calculateBoundaryConditions(BoundaryCondition, AirMatrices, ForcingData, RHS, KT)
function [RHS, AirMatrices] = calculateBoundaryConditions(BoundaryCondition, AirMatrices, ForcingData, RHS, KT, P_gg, GroundwaterSettings)
%{
Determine the boundary condition for solving the dry air equation.
%}
Expand All @@ -7,15 +7,24 @@
ModelSettings = io.getModelSettings();
n = ModelSettings.NN;

if ~GroundwaterSettings.GroundwaterCoupling % no Groundwater coupling, added by Mostafa
indxBotm = 1; % index of bottom layer is 1, STEMMUS calculates from bottom to top
BtmPg = BoundaryCondition.BtmPg;
else % Groundwater Coupling is activated
% index of bottom layer after neglecting saturated layers (from bottom to top)
indxBotm = GroundwaterSettings.indxBotmLayer;
BtmPg = P_gg(indxBotm);
end

% Apply the bottom boundary condition called for by NBCPB
if BoundaryCondition.NBCPB == 1 % Bounded bottom with the water table
RHS(1) = BtmPg;
AirMatrices.C6(1, 1) = 1;
RHS(2) = RHS(2) - AirMatrices.C6(1, 2) * RHS(1);
AirMatrices.C6(1, 2) = 0;
AirMatrices.C6_a(1) = 0;
RHS(indxBotm) = BtmPg;
AirMatrices.C6(indxBotm, 1) = 1;
RHS(indxBotm + 1) = RHS(indxBotm + 1) - AirMatrices.C6(indxBotm, 2) * RHS(indxBotm);
AirMatrices.C6(indxBotm, 2) = 0;
AirMatrices.C6_a(indxBotm) = 0;
elseif BoundaryCondition.NBCPB == 2 % The soil air is allowed to escape from the bottom
RHS(1) = RHS(1) + BoundaryCondition.BCPB;
RHS(indxBotm) = RHS(indxBotm) + BoundaryCondition.BCPB;
end

% Apply the surface boundary condition called by NBCP
Expand Down
17 changes: 14 additions & 3 deletions src/+dryair/calculateDryAirParameters.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function AirVariabes = calculateDryAirParameters(SoilVariables, GasDispersivity, TransportCoefficient, InitialValues, VaporVariables, ...
P_gg, Xah, XaT, Xaa, RHODA)
P_gg, Xah, XaT, Xaa, RHODA, GroundwaterSettings)
%{
Calculate all the parameters related to dry air equation e.g., Equation
3.59-3.64, STEMMUS Technical Notes, page 27-28.
Expand All @@ -24,7 +24,14 @@
AirVariabes.DTDZ = InitialValues.DTDZ;
GasDispersivity.DPgDZ = InitialValues.DPgDZ;

for i = 1:ModelSettings.NL
if ~GroundwaterSettings.GroundwaterCoupling % no Groundwater coupling, added by Mostafa
indxBotm = 1; % index of bottom layer is 1, STEMMUS calculates from bottom to top
else % Groundwater Coupling is activated
% index of bottom layer after neglecting saturated layers (from bottom to top)
indxBotm = GroundwaterSettings.indxBotmLayer;
end

for i = indxBotm:ModelSettings.NL
KLhBAR = (SoilVariables.KfL_h(i, 1) + SoilVariables.KfL_h(i, 2)) / 2;
KLTBAR = (InitialValues.KL_T(i, 1) + InitialValues.KL_T(i, 2)) / 2;
DDhDZ = (SoilVariables.hh(i + 1) - SoilVariables.hh(i)) / ModelSettings.DeltZ(i);
Expand All @@ -50,7 +57,11 @@
AirVariabes.DDhDZ(i) = DDhDZ;
AirVariabes.DhDZ(i) = DhDZ;
AirVariabes.DTDZ(i) = DTDZ;
AirVariabes.QL(i) = QL;
AirVariabes.QL(i) = QL; % total liquid flux
% added by Mostafa
AirVariabes.QL_h(i) = QL_h(i); % liquid flux due to matric potential
AirVariabes.QL_T(i) = QL_T(i); % liquid flux due to temperature gradient
AirVariabes.QL_a(i) = QL_a(I); % liquid flux due to air pressure gradient

for j = 1:ModelSettings.nD
MN = i + j - 1;
Expand Down
11 changes: 9 additions & 2 deletions src/+dryair/calculateMatricCoefficients.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function AirMatrices = calculateMatricCoefficients(AirVariabes, InitialValues)
function AirMatrices = calculateMatricCoefficients(AirVariabes, InitialValues, GroundwaterSettings)
%{
Calculate all the parameters related to matric coefficients e.g.,
c1-c7 as in Equation 4.32 STEMMUS Technical Notes, page 44, which is
Expand All @@ -15,7 +15,14 @@
AirMatrices.C6 = InitialValues.C6;
AirMatrices.C7 = zeros(ModelSettings.NN);

for i = 1:ModelSettings.NL
if ~GroundwaterSettings.GroundwaterCoupling % no Groundwater coupling, added by Mostafa
indxBotm = 1; % index of bottom layer is 1, STEMMUS calculates from bottom to top
else % Groundwater Coupling is activated
% index of bottom layer after neglecting saturated layers (from bottom to top)
indxBotm = GroundwaterSettings.indxBotmLayer;
end

for i = indxBotm:ModelSettings.NL
AirMatrices.C1(i, 1) = AirMatrices.C1(i, 1) + AirVariabes.Cah(i, 1) * ModelSettings.DeltZ(i) / 2;
AirMatrices.C1(i + 1, 1) = AirMatrices.C1(i + 1, 1) + AirVariabes.Cah(i, 2) * ModelSettings.DeltZ(i) / 2;

Expand Down
12 changes: 6 additions & 6 deletions src/+dryair/solveDryAirEquations.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
function [AirVariabes, RHS, SAVE, P_gg] = solveDryAirEquations(SoilVariables, GasDispersivity, TransportCoefficient, InitialValues, VaporVariables, ...
BoundaryCondition, ForcingData, P_gg, P_g, Xah, XaT, Xaa, RHODA, KT, Delt_t)
BoundaryCondition, ForcingData, P_gg, P_g, Xah, XaT, Xaa, RHODA, KT, Delt_t, GroundwaterSettings)
%{
Solve the dry air equation with the Thomas algorithm to update the soil
air pressure 'P_gg', the finite difference time-stepping scheme is
exampled as for the soil moisture equation, which derived in 'STEMMUS
Technical Notes' section 4, Equation 4.32.
%}
AirVariabes = dryair.calculateDryAirParameters(SoilVariables, GasDispersivity, TransportCoefficient, InitialValues, VaporVariables, ...
P_gg, Xah, XaT, Xaa, RHODA);
P_gg, Xah, XaT, Xaa, RHODA, GroundwaterSettings);

AirMatrices = dryair.calculateMatricCoefficients(AirVariabes, InitialValues);
AirMatrices = dryair.calculateMatricCoefficients(AirVariabes, InitialValues, GroundwaterSettings);

[RHS, AirMatrices, SAVE] = dryair.assembleCoefficientMatrices(AirMatrices, SoilVariables, Delt_t, P_g);
[RHS, AirMatrices, SAVE] = dryair.assembleCoefficientMatrices(AirMatrices, SoilVariables, Delt_t, P_g, GroundwaterSettings);

[RHS, AirMatrices] = dryair.calculateBoundaryConditions(BoundaryCondition, AirMatrices, ForcingData, RHS, KT);
[RHS, AirMatrices] = dryair.calculateBoundaryConditions(BoundaryCondition, AirMatrices, ForcingData, RHS, KT, P_gg, GroundwaterSettings);

[AirMatrices, P_gg, RHS] = dryair.solveTridiagonalMatrixEquations(RHS, AirMatrices);
[AirMatrices, P_gg, RHS] = dryair.solveTridiagonalMatrixEquations(RHS, AirMatrices, GroundwaterSettings);

end
18 changes: 13 additions & 5 deletions src/+dryair/solveTridiagonalMatrixEquations.m
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
function [AirMatrices, P_gg, RHS] = solveTridiagonalMatrixEquations(RHS, AirMatrices)
function [AirMatrices, P_gg, RHS] = solveTridiagonalMatrixEquations(RHS, AirMatrices, GroundwaterSettings)
%{
Use Thomas algorithm to solve the tridiagonal matrix equations, which is
in the form of Equation 4.25 STEMMUS Technical Notes, page 41.
%}

ModelSettings = io.getModelSettings();
RHS(1) = RHS(1) / AirMatrices.C6(1, 1);

for i = 2:ModelSettings.NN
if ~GroundwaterSettings.GroundwaterCoupling % no Groundwater coupling, added by Mostafa
indxBotm = 1; % index of bottom layer is 1, STEMMUS calculates from bottom to top
else % Groundwater Coupling is activated
% index of bottom layer after neglecting saturated layers (from bottom to top)
indxBotm = GroundwaterSettings.indxBotmLayer;
end

RHS(indxBotm) = RHS(indxBotm) / AirMatrices.C6(indxBotm, 1);

for i = indxBotm + 1:ModelSettings.NN
AirMatrices.C6(i, 1) = AirMatrices.C6(i, 1) - AirMatrices.C6_a(i - 1) * AirMatrices.C6(i - 1, 2) / AirMatrices.C6(i - 1, 1);
RHS(i) = (RHS(i) - AirMatrices.C6_a(i - 1) * RHS(i - 1)) / AirMatrices.C6(i, 1);
end

for i = ModelSettings.NL:-1:1
for i = ModelSettings.NL:-1:indxBotm
RHS(i) = RHS(i) - AirMatrices.C6(i, 2) * RHS(i + 1) / AirMatrices.C6(i, 1);
end

for i = 1:ModelSettings.NN
for i = indxBotm:ModelSettings.NN
P_gg(i) = RHS(i);
end
end
43 changes: 27 additions & 16 deletions src/+energy/assembleCoefficientMatrices.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [RHS, EnergyMatrices, SAVE] = assembleCoefficientMatrices(EnergyMatrices, SoilVariables, Delt_t, P_g, P_gg)
function [RHS, EnergyMatrices, SAVE] = assembleCoefficientMatrices(EnergyMatrices, SoilVariables, Delt_t, P_g, P_gg, GroundwaterSettings)
%{
assembles the coefficient matrices of Equation 4.32, STEMMUS Technical
Notes, page 44, the example was only shown for the soil moisture
Expand All @@ -17,17 +17,28 @@
ModelSettings = io.getModelSettings();
n = ModelSettings.NN;

if ModelSettings.Soilairefc == 1 % see https://github.com/EcoExtreML/STEMMUS_SCOPE/issues/227
C6_a = EnergyMatrices.C6_a;
end

if ~GroundwaterSettings.GroundwaterCoupling % no Groundwater coupling, added by Mostafa
indxBotm = 1; % index of bottom layer is 1, STEMMUS calculates from bottom to top
else % Groundwater Coupling is activated
% index of bottom layer after neglecting saturated layers (from bottom to top)
indxBotm = GroundwaterSettings.indxBotmLayer;
end

% Alias of SoilVariables
SV = SoilVariables;

if ModelSettings.Soilairefc && ModelSettings.Thmrlefc
RHS(1) = -C7(1) + (C2(1, 1) * SV.T(1) + C2(1, 2) * SV.T(2)) / Delt_t ...
- (C1(1, 1) / Delt_t + C4(1, 1)) * SV.hh(1) - (C1(1, 2) / Delt_t + C4(1, 2)) * SV.hh(2) ...
- (C3(1, 1) / Delt_t + C6(1, 1)) * P_gg(1) - (C3(1, 2) / Delt_t + C6(1, 2)) * P_gg(2) ...
+ (C3(1, 1) / Delt_t) * P_g(1) + (C3(1, 2) / Delt_t) * P_g(2) ...
+ (C1(1, 1) / Delt_t) * SV.h(1) + (C1(1, 2) / Delt_t) * SV.h(2);
RHS(indxBotm) = -C7(indxBotm) + (C2(indxBotm, 1) * SV.T(indxBotm) + C2(indxBotm, 2) * SV.T(2)) / Delt_t ...
- (C1(indxBotm, 1) / Delt_t + C4(indxBotm, 1)) * SV.hh(indxBotm) - (C1(indxBotm, 2) / Delt_t + C4(indxBotm, 2)) * SV.hh(indxBotm + 1) ...
- (C3(indxBotm, 1) / Delt_t + C6(indxBotm, 1)) * P_gg(indxBotm) - (C3(indxBotm, 2) / Delt_t + C6(indxBotm, 2)) * P_gg(indxBotm + 1) ...
+ (C3(indxBotm, 1) / Delt_t) * P_g(indxBotm) + (C3(indxBotm, 2) / Delt_t) * P_g(indxBotm + 1) ...
+ (C1(indxBotm, 1) / Delt_t) * SV.h(indxBotm) + (C1(indxBotm, 2) / Delt_t) * SV.h(indxBotm + 1);

for i = 2:ModelSettings.NL
for i = indxBotm + 1:ModelSettings.NL
ARG1 = C3(i - 1, 2) / Delt_t;
ARG2 = C3(i, 1) / Delt_t;
ARG3 = C3(i, 2) / Delt_t;
Expand All @@ -49,9 +60,9 @@
+ (C3(n - 1, 2) / Delt_t) * P_g(n - 1) + (C3(n, 1) / Delt_t) * P_g(n) ...
+ (C1(n - 1, 2) / Delt_t) * SV.h(n - 1) + (C1(n, 1) / Delt_t) * SV.h(n);
elseif ~ModelSettings.Soilairefc && ModelSettings.Thmrlefc
RHS(1) = -C7(1) + (C2(1, 1) * SV.T(1) + C2(1, 2) * SV.T(2)) / Delt_t ...
- (C1(1, 1) / Delt_t + C4(1, 1)) * SV.hh(1) - (C1(1, 2) / Delt_t + C4(1, 2)) * SV.hh(2) ...
+ (C1(1, 1) / Delt_t) * SV.h(1) + (C1(1, 2) / Delt_t) * SV.h(2);
RHS(indxBotm) = -C7(indxBotm) + (C2(indxBotm, 1) * SV.T(indxBotm) + C2(indxBotm, 2) * SV.T(indxBotm + 1)) / Delt_t ...
- (C1(indxBotm, 1) / Delt_t + C4(indxBotm, 1)) * SV.hh(indxBotm) - (C1(indxBotm, 2) / Delt_t + C4(indxBotm, 2)) * SV.hh(indxBotm + 1) ...
+ (C1(indxBotm, 1) / Delt_t) * SV.h(indxBotm) + (C1(indxBotm, 2) / Delt_t) * SV.h(indxBotm + 1);
for i = 2:ModelSettings.NL
ARG4 = C1(i - 1, 2) / Delt_t;
ARG5 = C1(i, 1) / Delt_t;
Expand All @@ -66,24 +77,24 @@
- (C1(n - 1, 2) / Delt_t + C4(n - 1, 2)) * SV.hh(n - 1) - (C1(n, 1) / Delt_t + C4(n, 1)) * SV.hh(n) ...
+ (C1(n - 1, 2) / Delt_t) * SV.h(n - 1) + (C1(n, 1) / Delt_t) * SV.h(n);
else
RHS(1) = -C7(1) + (C2(1, 1) * SV.T(1) + C2(1, 2) * SV.T(2)) / Delt_t;
for i = 2:ModelSettings.NL
RHS(indxBotm) = -C7(indxBotm) + (C2(indxBotm, 1) * SV.T(indxBotm) + C2(1, 2) * SV.T(indxBotm + 1)) / Delt_t;
for i = indxBotm + 1:ModelSettings.NL
RHS(i) = -C7(i) + (C2(i - 1, 2) * SV.T(i - 1) + C2(i, 1) * SV.T(i) + C2(i, 2) * SV.T(i + 1)) / Delt_t;
end
RHS(n) = -C7(n) + (C2(n - 1, 2) * SV.T(n - 1) + C2(n, 1) * SV.T(n)) / Delt_t;
end

for i = 1:ModelSettings.NN
for i = indxBotm:ModelSettings.NN
for j = 1:ModelSettings.nD
C5(i, j) = C2(i, j) / Delt_t + C5(i, j);
end
end

EnergyMatrices.C5 = C5;

SAVE(1, 1, 2) = RHS(1);
SAVE(1, 2, 2) = C5(1, 1);
SAVE(1, 3, 2) = C5(1, 2);
SAVE(1, 1, 2) = RHS(indxBotm);
SAVE(1, 2, 2) = C5(indxBotm, 1);
SAVE(1, 3, 2) = C5(indxBotm, 2);
SAVE(2, 1, 2) = RHS(n);
SAVE(2, 2, 2) = C5(n - 1, 2);
SAVE(2, 3, 2) = C5(n, 1);
Expand Down
Loading
Loading