Skip to content

Commit 4c1bba3

Browse files
committed
Merge commit '83a9273a8b5d95e36d673bb5645471510100390c'
2 parents 6bc8abb + 83a9273 commit 4c1bba3

10 files changed

+78
-15
lines changed

agrolib/criteriaModel/criteria1DCase.cpp

+34-6
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ bool Crit1DCase::computeNumericalFluxes(const Crit3DDate &myDate, std::string &e
361361
}
362362

363363

364-
void Crit1DCase::saveWaterContent()
364+
void Crit1DCase::storeWaterContent()
365365
{
366366
prevWaterContent.clear();
367367
prevWaterContent.resize(soilLayers.size());
@@ -537,7 +537,7 @@ bool Crit1DCase::computeDailyModel(Crit3DDate &myDate, std::string &error)
537537

538538
output.dailyIrrigation = 0;
539539
// Water fluxes (first computation)
540-
saveWaterContent();
540+
storeWaterContent();
541541
if (! computeWaterFluxes(myDate, error)) return false;
542542
// Irrigation
543543
double irrigation = checkIrrigationDemand(doy, prec, precTomorrow, output.dailyMaxTranspiration);
@@ -653,11 +653,11 @@ double Crit1DCase::getTotalWaterContent()
653653

654654

655655
/*!
656-
* \brief getWaterContent
656+
* \brief getVolumetricWaterContent
657657
* \param computationDepth = computation soil depth [cm]
658-
* \return volumetric water content at specific depth [-]
658+
* \return volumetric water content (soil moisture) at specific depth [m3 m-3]
659659
*/
660-
double Crit1DCase::getWaterContent(double computationDepth)
660+
double Crit1DCase::getVolumetricWaterContent(double computationDepth)
661661
{
662662
computationDepth /= 100; // [cm] --> [m]
663663

@@ -679,6 +679,34 @@ double Crit1DCase::getWaterContent(double computationDepth)
679679
}
680680

681681

682+
/*!
683+
* \brief getDegreeOfSaturation
684+
* \param computationDepth = computation soil depth [cm]
685+
* \return degree of saturation at specific depth [-]
686+
*/
687+
double Crit1DCase::getDegreeOfSaturation(double computationDepth)
688+
{
689+
computationDepth /= 100; // [cm] --> [m]
690+
if (computationDepth <= 0 || computationDepth > mySoil.totalDepth)
691+
{
692+
return NODATA;
693+
}
694+
695+
double upperDepth, lowerDepth;
696+
for (unsigned int i = 1; i < soilLayers.size(); i++)
697+
{
698+
upperDepth = soilLayers[i].depth - soilLayers[i].thickness * 0.5;
699+
lowerDepth = soilLayers[i].depth + soilLayers[i].thickness * 0.5;
700+
if (computationDepth >= upperDepth && computationDepth <= lowerDepth)
701+
{
702+
return soilLayers[i].waterContent / soilLayers[i].SAT;
703+
}
704+
}
705+
706+
return NODATA;
707+
}
708+
709+
682710
/*!
683711
* \brief getWaterPotential
684712
* \param computationDepth = computation soil depth [cm]
@@ -778,7 +806,7 @@ double Crit1DCase::getWaterDeficitSum(double computationDepth)
778806

779807
/*!
780808
* \brief getWaterCapacity
781-
* \param computationDepth = computation soil depth [cm]
809+
* \param computationDepth = computation soil depth [cm]
782810
* \return sum of available water capacity (FC-WP) from zero to computationDepth (mm)
783811
*/
784812
double Crit1DCase::getWaterCapacitySum(double computationDepth)

agrolib/criteriaModel/criteria1DCase.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
bool initializeWaterContent(Crit3DDate myDate);
7979
bool computeDailyModel(Crit3DDate &myDate, std::string &error);
8080

81-
double getWaterContent(double computationDepth);
81+
double getVolumetricWaterContent(double computationDepth);
82+
double getDegreeOfSaturation(double computationDepth);
8283
double getWaterPotential(double computationDepth);
8384
double getFractionAW(double computationDepth);
8485
double getSlopeStability(double computationDepth);
@@ -99,7 +100,7 @@
99100
bool computeNumericalFluxes(const Crit3DDate &myDate, std::string &error);
100101
bool computeWaterFluxes(const Crit3DDate &myDate, std::string &error);
101102
double checkIrrigationDemand(int doy, double currentPrec, double nextPrec, double maxTranspiration);
102-
void saveWaterContent();
103+
void storeWaterContent();
103104
void restoreWaterContent();
104105
double getTotalWaterContent();
105106

agrolib/criteriaModel/criteria1DProject.cpp

+25-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ void Crit1DProject::initialize()
6363
lastSimulationDate = QDate(1800,1,1);
6464

6565
outputString = "";
66+
6667
// specific outputs
6768
waterDeficitDepth.clear();
6869
waterContentDepth.clear();
70+
degreeOfSaturationDepth.clear();
6971
waterPotentialDepth.clear();
7072
availableWaterDepth.clear();
7173
fractionAvailableWaterDepth.clear();
@@ -257,6 +259,12 @@ bool Crit1DProject::readSettings()
257259
projectError = "Wrong water content depth in " + configFileName;
258260
return false;
259261
}
262+
depthList = projectSettings->value("degreeOfSaturation").toStringList();
263+
if (! setVariableDepth(depthList, degreeOfSaturationDepth))
264+
{
265+
projectError = "Wrong degree of saturation depth in " + configFileName;
266+
return false;
267+
}
260268
depthList = projectSettings->value("waterPotential").toStringList();
261269
if (! setVariableDepth(depthList, waterPotentialDepth))
262270
{
@@ -1544,7 +1552,12 @@ bool Crit1DProject::createOutputTable(QString &myError)
15441552
// specific depth variables
15451553
for (unsigned int i = 0; i < waterContentDepth.size(); i++)
15461554
{
1547-
QString fieldName = "SWC_" + QString::number(waterContentDepth[i]);
1555+
QString fieldName = "VWC_" + QString::number(waterContentDepth[i]);
1556+
queryString += ", " + fieldName + " REAL";
1557+
}
1558+
for (unsigned int i = 0; i < degreeOfSaturationDepth.size(); i++)
1559+
{
1560+
QString fieldName = "DEGSAT_" + QString::number(degreeOfSaturationDepth[i]);
15481561
queryString += ", " + fieldName + " REAL";
15491562
}
15501563
for (unsigned int i = 0; i < waterPotentialDepth.size(); i++)
@@ -1604,7 +1617,12 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst)
16041617
// specific depth variables
16051618
for (unsigned int i = 0; i < waterContentDepth.size(); i++)
16061619
{
1607-
QString fieldName = "SWC_" + QString::number(waterContentDepth[i]);
1620+
QString fieldName = "VWC_" + QString::number(waterContentDepth[i]);
1621+
outputString += ", " + fieldName;
1622+
}
1623+
for (unsigned int i = 0; i < degreeOfSaturationDepth.size(); i++)
1624+
{
1625+
QString fieldName = "DEGSAT_" + QString::number(degreeOfSaturationDepth[i]);
16081626
outputString += ", " + fieldName;
16091627
}
16101628
for (unsigned int i = 0; i < waterPotentialDepth.size(); i++)
@@ -1669,7 +1687,11 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst)
16691687
// specific depth variables
16701688
for (unsigned int i = 0; i < waterContentDepth.size(); i++)
16711689
{
1672-
outputString += "," + QString::number(myCase.getWaterContent(waterContentDepth[i]), 'g', 4);
1690+
outputString += "," + QString::number(myCase.getVolumetricWaterContent(waterContentDepth[i]), 'g', 4);
1691+
}
1692+
for (unsigned int i = 0; i < degreeOfSaturationDepth.size(); i++)
1693+
{
1694+
outputString += "," + QString::number(myCase.getDegreeOfSaturation(degreeOfSaturationDepth[i]), 'g', 4);
16731695
}
16741696
for (unsigned int i = 0; i < waterPotentialDepth.size(); i++)
16751697
{

agrolib/criteriaModel/criteria1DProject.h

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191

9292
// specific output
9393
std::vector<int> waterContentDepth;
94+
std::vector<int> degreeOfSaturationDepth;
9495
std::vector<int> waterPotentialDepth;
9596
std::vector<int> waterDeficitDepth;
9697
std::vector<int> awcDepth;

agrolib/crop/root.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ namespace root
591591
}
592592
}
593593

594+
// normalize root density
594595
if (rootDensitySumSubset != rootDensitySum)
595596
{
596597
double ratio = rootDensitySum / rootDensitySumSubset;
@@ -600,6 +601,7 @@ namespace root
600601
}
601602
}
602603

604+
// find first and last root layers
603605
myCrop->roots.firstRootLayer = 0;
604606
unsigned int layer = 0;
605607
while (layer < nrLayers && myCrop->roots.rootDensity[layer] == 0.0)

agrolib/gis/gis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ namespace gis
459459
}
460460

461461

462-
void convertNodataRasterGrid(Crit3DRasterGrid& myGrid)
462+
void convertFlagToNodata(Crit3DRasterGrid& myGrid)
463463
{
464464
if (myGrid.header->flag == NODATA)
465465
return;

agrolib/gis/gis.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
float computeDistance(float x1, float y1, float x2, float y2);
198198
double computeDistancePoint(Crit3DUtmPoint *p0, Crit3DUtmPoint *p1);
199199
bool updateMinMaxRasterGrid(Crit3DRasterGrid *rasterGrid);
200-
void convertNodataRasterGrid(Crit3DRasterGrid& myGrid);
200+
void convertFlagToNodata(Crit3DRasterGrid& myGrid);
201201
bool updateColorScale(Crit3DRasterGrid* rasterGrid, int row0, int col0, int row1, int col1);
202202

203203
void getRowColFromXY(const Crit3DRasterHeader& myHeader, double myX, double myY, int *row, int *col);

agrolib/project/project.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ bool Project::loadDEM(QString myFileName)
996996
QString infoStr = "WARNING: " + QString::number(DEM.header->flag) + " is not a valid NODATA value for DEM!";
997997
infoStr += " It will be converted in: " + QString::number(NODATA);
998998
logInfo(infoStr);
999-
gis::convertNodataRasterGrid(DEM);
999+
gis::convertFlagToNodata(DEM);
10001000
}
10011001

10021002
setColorScale(noMeteoTerrain, DEM.colorScale);

agrolib/soil/soil.h

+3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
Crit3DDriessen Driessen;
153153

154154
Crit3DHorizon();
155+
156+
double getSoilFraction()
157+
{ return (1.0 - coarseFragments); }
155158
};
156159

157160

agrolib/soil/soilDbTools.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@
1010
#include <QSqlError>
1111
#include <QUuid>
1212
#include <QVariant>
13+
#include <QFile>
1314

1415

1516
bool openDbSoil(const QString &dbSoilName, QSqlDatabase &dbSoil, QString &errorStr)
1617
{
18+
if (! QFile(dbSoilName).exists())
19+
{
20+
errorStr = "Soil database doesn't exist:\n" + dbSoilName;
21+
return false;
22+
}
1723

1824
dbSoil = QSqlDatabase::addDatabase("QSQLITE", QUuid::createUuid().toString());
1925
dbSoil.setDatabaseName(dbSoilName);
2026

21-
if (!dbSoil.open())
27+
if (! dbSoil.open())
2228
{
2329
errorStr = "Connection with database fail";
2430
return false;

0 commit comments

Comments
 (0)