Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ARPA-SIMC/CRITERIA3D
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jul 30, 2024
2 parents 684ede7 + ad0d822 commit 5892f9a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 7 deletions.
11 changes: 7 additions & 4 deletions agrolib/outputPoints/dbOutputPointsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,26 @@ bool Crit3DOutputPointsDbHandler::addCriteria3DColumn(const QString &tableName,
}

// column name
if (depth != NODATA)
{
QString newField = variableString + "_" + QString::number(depth);
}

// column exists already
QList<QString> fieldList = getFields(&_db, tableName);
if ( fieldList.contains(newField) )
if ( fieldList.contains(variableString) )
{
return true;
}

// add column
QString queryString = "ALTER TABLE '" + tableName + "'";
queryString += " ADD " + newField + " REAL";
queryString += " ADD " + variableString + " REAL";

QSqlQuery myQuery = _db.exec(queryString);
if (myQuery.lastError().isValid())
{
errorStr = "Error in add column: " + newField + "\n" + myQuery.lastError().text();
errorStr = "Error in add column: " + variableString + "\n" + myQuery.lastError().text();
return false;
}

Expand Down Expand Up @@ -193,7 +196,7 @@ bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(const QString &table
}

int nrValues = int(varList.size()) * nrSoilLayers;
if (nrValues != values.size())
if (nrValues != int(values.size()))
{
errorStr = "Error saving values: number of values is not as expected.";
return false;
Expand Down
56 changes: 53 additions & 3 deletions bin/CRITERIA3D/shared/project3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ void Project3D::initializeProject3D()
totalEvaporation = 0;
totalTranspiration = 0;

// specific outputs
isClimateOutput = false;
//waterDeficitDepth.clear();
waterContentDepth.clear();
//degreeOfSaturationDepth.clear();
waterPotentialDepth.clear();
//availableWaterDepth.clear();
//fractionAvailableWaterDepth.clear();
factorOfSafetyDepth.clear();
//awcDepth.clear();


setCurrentFrequency(hourly);
}

Expand Down Expand Up @@ -253,6 +265,28 @@ bool Project3D::loadProject3DSettings()

projectSettings->endGroup();

// OUTPUT variables (optional)
QList<QString> depthList;
projectSettings->beginGroup("output");

depthList = projectSettings->value("waterContent").toStringList();
if (! setVariableDepth(depthList, waterContentDepth))
{
errorString = "Wrong water content depth in " + projectSettings->fileName();
}

depthList = projectSettings->value("waterPotential").toStringList();
if (! setVariableDepth(depthList, waterPotentialDepth))
{
errorString = "Wrong water potential depth in " + projectSettings->fileName();
}

depthList = projectSettings->value("factorOfSafety").toStringList();
if (! setVariableDepth(depthList, factorOfSafetyDepth))
{
errorString = "Wrong factor of safety depth in " + projectSettings->fileName();
}

return true;
}

Expand Down Expand Up @@ -2024,15 +2058,15 @@ float Project3D::computeFactorOfSafety(int row, int col, unsigned int layerIndex
double weightSum = 0; // [kPa]
for (unsigned int layer = 1; layer <= layerIndex; layer++)
{
long cuurentNode = indexMap.at(layer).value[row][col];
if (cuurentNode != indexMap.at(layer).header->flag)
long currentNode = indexMap.at(layer).value[row][col];
if (currentNode != indexMap.at(layer).header->flag)
{
int currentHorizon = soil::getHorizonIndex(soilList[unsigned(soilIndex)], layerDepth[layer]);
if (currentHorizon != NODATA)
{
// [g cm-3] --> [Mg m-3]
double bulkDensity = soilList[unsigned(soilIndex)].horizon[currentHorizon].bulkDensity;
double waterContent = soilFluxes3D::getWaterContent(cuurentNode);
double waterContent = soilFluxes3D::getWaterContent(currentNode);
// [kN m-3]
double unitWeight = (bulkDensity + waterContent) * GRAVITY;
// [kPa]
Expand Down Expand Up @@ -2222,3 +2256,19 @@ QString getDailyPrefixFromVar(QDate myDate, criteria3DVariable myVar)
return fileName;
}

bool setVariableDepth(const QList<QString>& depthList, std::vector<int>& variableDepth)
{
int nrDepth = depthList.size();
if (nrDepth > 0)
{
variableDepth.resize(unsigned(nrDepth));
for (int i = 0; i < nrDepth; i++)
{
variableDepth[unsigned(i)] = depthList[i].toInt();
if (variableDepth[unsigned(i)] <= 0)
return false;
}
}

return true;
}
12 changes: 12 additions & 0 deletions bin/CRITERIA3D/shared/project3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@
double totalEvaporation; // [m3 h-1]
double totalTranspiration; // [m3 h-1]

// specific outputs
bool isClimateOutput;
std::vector<int> waterContentDepth;
//std::vector<int> degreeOfSaturationDepth;
std::vector<int> waterPotentialDepth;
//std::vector<int> waterDeficitDepth;
//std::vector<int> awcDepth;
//std::vector<int> availableWaterDepth;
//std::vector<int> fractionAvailableWaterDepth;
std::vector<int> factorOfSafetyDepth;

Project3D();

void initializeProject3D();
Expand Down Expand Up @@ -210,5 +221,6 @@
float readDataHourly(meteoVariable myVar, QString hourlyPath, QDateTime myTime, QString myArea, int row, int col);
bool readHourlyMap(meteoVariable myVar, QString hourlyPath, QDateTime myTime, QString myArea, gis::Crit3DRasterGrid* myGrid);

bool setVariableDepth(const QList<QString> &depthList, std::vector<int> &variableDepth);

#endif // PROJECT3D_H

0 comments on commit 5892f9a

Please sign in to comment.