Skip to content

Commit 1028ee9

Browse files
committed
Merge commit '2e7771d7f5bd471462f17290654a4867871abd44'
2 parents 5a871d3 + 2e7771d commit 1028ee9

File tree

4 files changed

+144
-9
lines changed

4 files changed

+144
-9
lines changed

agrolib/crop/crop.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,16 @@ bool Crit3DCrop::updateLAI(double latitude, unsigned int nrLayers, int currentDo
254254
else
255255
{
256256
if (type == GRASS)
257+
{
257258
// grass cut
258259
if (degreeDays >= degreeDaysIncrease)
260+
{
261+
int oldDaysSinceIrr = daysSinceIrrigation;
259262
resetCrop(nrLayers);
263+
// grass cut does not reset the irrigation
264+
daysSinceIrrigation = oldDaysSinceIrr;
265+
}
266+
}
260267

261268
if (degreeDays > 0)
262269
myLai = leafDevelopment::getLAICriteria(this, degreeDays);
@@ -434,13 +441,13 @@ void Crit3DCrop::resetCrop(unsigned int nrLayers)
434441
roots.rootDensity[i] = 0;
435442
}
436443

437-
isEmerged = false;
444+
if (isSowingCrop())
445+
isEmerged = false;
438446

439447
if (isLiving)
440448
{
441449
degreeDays = 0;
442450

443-
// LAI
444451
LAI = LAImin;
445452
LAIpreviousDay = LAImin;
446453
if (type == TREE)
@@ -458,8 +465,8 @@ void Crit3DCrop::resetCrop(unsigned int nrLayers)
458465
roots.rootDepth = NODATA;
459466
}
460467

461-
LAIstartSenescence = NODATA;
462468
daysSinceIrrigation = NODATA;
469+
LAIstartSenescence = NODATA;
463470
}
464471

465472

@@ -775,7 +782,7 @@ double Crit3DCrop::computeTranspiration(double maxTranspiration, const std::vect
775782
{
776783
// [mm]
777784
waterSurplusThreshold = soilLayers[i].SAT - (WSS * (soilLayers[i].SAT - soilLayers[i].FC));
778-
785+
// [-]
779786
thetaWP = soil::thetaFromSignPsi(-soil::cmTokPa(psiLeaf), *(soilLayers[i].horizonPtr));
780787
// [mm]
781788
cropWP = thetaWP * soilLayers[i].thickness * soilLayers[i].soilFraction * 1000.;

agrolib/soil/soilDbTools.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ bool openDbSoil(const QString &dbSoilName, QSqlDatabase &dbSoil, QString &errorS
3737

3838
bool loadGeotechnicsParameters(const QSqlDatabase &dbSoil, std::vector<soil::Crit3DGeotechnicsClass> &geotechnicsClassList, QString &errorStr)
3939
{
40-
QString queryString = "SELECT id_class, effective_cohesion, friction_angle ";
41-
queryString += "FROM geotechnics ORDER BY id_class";
40+
QString queryString = "SELECT id_class, effective_cohesion, friction_angle FROM geotechnics ORDER BY id_class";
41+
QSqlQuery query(dbSoil);
4242

43-
QSqlQuery query = dbSoil.exec(queryString);
44-
if (query.lastError().text() != "")
43+
if (! query.exec(queryString))
4544
{
4645
errorStr = query.lastError().text();
4746
return false;

agrolib/soilFluxes3D/linealia.h

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// This file is part of https://github.com/KurtBoehm/linealia.
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
#ifndef INCLUDE_LINEALIA_LINEALIA_HPP
8+
#define INCLUDE_LINEALIA_LINEALIA_HPP
9+
10+
#include <cstddef>
11+
#include <cstdint>
12+
13+
extern "C" {
14+
15+
enum LinealiaIterativeStopReason {
16+
LINEALIA_STOP_RESIDUAL_NORM,
17+
LINEALIA_STOP_ITERATIONS,
18+
};
19+
20+
struct LinealiaIterativeResult {
21+
LinealiaIterativeStopReason reason;
22+
size_t iteration;
23+
// ||Ax−b||₂
24+
double residual_norm;
25+
// ||Ax−b||₂/||b||₂
26+
double relative_residual_norm;
27+
};
28+
29+
struct LinealiaMatrix {
30+
uint32_t num_rows = 0;
31+
uint8_t max_columns = 11;
32+
uint8_t* num_columns = nullptr;
33+
uint32_t** column_indices = nullptr;
34+
double** values = nullptr;
35+
};
36+
37+
struct LinealiaVector {
38+
uint32_t num_elements = 0;
39+
double* values = nullptr;
40+
};
41+
42+
struct LinealExecutionParams {
43+
// The number of threads to use
44+
// If the value is 0 (the default), the number of threads is determined automatically
45+
size_t num_threads = 0;
46+
};
47+
48+
struct LinealiaIterativeSolverParams {
49+
// Maximum number of iterations
50+
size_t max_iterations = 256;
51+
// Maximum relative residual norm, i.e. ||Ax−b||₂/||b||₂
52+
double max_relative_residual_norm = 1e-10;
53+
};
54+
55+
struct LinealiaRelaxedParams {
56+
// The relaxation factor, commonly called ω (1 by default, i.e. SOR→Gauß-Seidel)
57+
double relax = 1.0;
58+
};
59+
60+
LinealiaIterativeResult linealia_solve_sor(LinealiaMatrix lhs, LinealiaVector sol,
61+
LinealiaVector rhs, LinealExecutionParams eparams,
62+
LinealiaIterativeSolverParams iparams,
63+
LinealiaRelaxedParams sparams);
64+
LinealiaIterativeResult linealia_solve_ssor(LinealiaMatrix lhs, LinealiaVector sol,
65+
LinealiaVector rhs, LinealExecutionParams eparams,
66+
LinealiaIterativeSolverParams iparams,
67+
LinealiaRelaxedParams sparams);
68+
69+
LinealiaIterativeResult linealia_solve_cg(LinealiaMatrix lhs, LinealiaVector sol,
70+
LinealiaVector rhs, LinealExecutionParams eparams,
71+
LinealiaIterativeSolverParams iparams);
72+
73+
struct LinealiaRelaxedPreconditionerParams {
74+
// The relaxation factor, commonly called ω (1 by default, i.e. Gauß-Seidel)
75+
double relax = 1.0;
76+
// The number of SOR iterations to apply per CG iteration
77+
size_t iterations = 2;
78+
};
79+
80+
LinealiaIterativeResult linealia_solve_pcg_sor(LinealiaMatrix lhs, LinealiaVector sol, LinealiaVector rhs,
81+
LinealExecutionParams eparams, LinealiaIterativeSolverParams iparams,
82+
LinealiaRelaxedPreconditionerParams preconditioner_params);
83+
84+
LinealiaIterativeResult linealia_solve_pcg_ssor(LinealiaMatrix lhs, LinealiaVector sol, LinealiaVector rhs,
85+
LinealExecutionParams eparams, LinealiaIterativeSolverParams iparams,
86+
LinealiaRelaxedPreconditionerParams preconditioner_params);
87+
88+
struct AmgAggregateSizeRange {
89+
size_t min;
90+
size_t max;
91+
};
92+
93+
struct LinealiaPcgAmgParams {
94+
// The AMG relaxation factor
95+
double amg_relax = 0.6;
96+
// The aggregate size ranges
97+
// If these are null/0, uses [8, 12] on the finest level and [6, 9] on other levels
98+
AmgAggregateSizeRange* amg_aggregate_size_ranges = nullptr;
99+
size_t amg_aggregate_size_ranges_size = 0;
100+
// The maximum number of levels in the AMG hierarchy
101+
size_t amg_max_level_num = 64;
102+
// A linear system must have at least this size to continue coarsening
103+
uint32_t amg_min_coarsen_size = 1024;
104+
// The decrease in the size of the linear system must be at least this factor
105+
// to continue coarsening
106+
double amg_min_coarsen_factor = 1.2;
107+
// The minimum number of unknowns per thread
108+
// If there are fewer, the number of threads is reduced accordingly
109+
double amg_aggregation_min_per_thread = 32768;
110+
// The SOR smoother relaxation factor, commonly called ω (1 by default)
111+
double smoother_relax = 1.0;
112+
// The number of SOR smoother iterations to apply
113+
size_t smoother_iterations = 2;
114+
};
115+
116+
LinealiaIterativeResult linealia_solve_pcg_amg_sor(LinealiaMatrix lhs, LinealiaVector sol,
117+
LinealiaVector rhs,
118+
LinealExecutionParams eparams,
119+
LinealiaIterativeSolverParams iparams,
120+
LinealiaPcgAmgParams sparams);
121+
LinealiaIterativeResult linealia_solve_pcg_amg_ssor(LinealiaMatrix lhs, LinealiaVector sol,
122+
LinealiaVector rhs,
123+
LinealExecutionParams eparams,
124+
LinealiaIterativeSolverParams iparams,
125+
LinealiaPcgAmgParams sparams);
126+
}
127+
128+
#endif // INCLUDE_LINEALIA_LINEALIA_HPP

agrolib/soilFluxes3D/soilFluxes3D.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ HEADERS += \
5252
solver.h \
5353
types.h \
5454
types_cpu.h \
55-
water.h
55+
water.h \
56+
linealia.h
5657

5758
DISTFILES += \
5859
ToDoList.txt

0 commit comments

Comments
 (0)