Skip to content

Commit

Permalink
update 3D
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Mar 15, 2024
1 parent fd4022f commit fd1fa9e
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 63 deletions.
6 changes: 6 additions & 0 deletions agrolib/meteo/meteo.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
noMeteoVar};


enum criteria3DVariable {volumetricWaterContent, waterTotalPotential, waterMatricPotential,
availableWaterContent, degreeOfSaturation, soilTemperature,
soilSurfaceMoisture, bottomDrainage, waterDeficit, waterInflow, waterOutflow,
factorOfSafety};


const std::map<std::string, meteoVariable> MapDailyMeteoVar = {
{ "DAILY_TMIN", dailyAirTemperatureMin },
{ "DAILY_TMAX", dailyAirTemperatureMax },
Expand Down
37 changes: 36 additions & 1 deletion agrolib/outputPoints/dbOutputPointsHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "dbOutputPointsHandler.h"
#include "commonConstants.h"
#include "utilities.h"
#include "meteo.h"

#include <QtSql>

Expand Down Expand Up @@ -100,7 +101,41 @@ bool Crit3DOutputPointsDbHandler::addColumn(QString tableName, meteoVariable myV
}


bool Crit3DOutputPointsDbHandler::saveHourlyData(QString tableName, const QDateTime& myTime,
// depth [cm]
bool Crit3DOutputPointsDbHandler::addCriteria3DColumn(const QString &tableName, criteria3DVariable myVar, int depth, QString& errorStr)
{
// column name
/*
QString newField = QString::fromStdString(getMeteoVarName(myVar));
if (newField == "")
{
errorStr = "Missing variable name.";
return false;
}
// column exists already
QList<QString> fieldList = getFields(&_db, tableName);
if (fieldList.contains(newField))
{
return true;
}
// add column
QString queryString = "ALTER TABLE '" + tableName + "'";
queryString += " ADD " + newField + " REAL";
QSqlQuery myQuery = _db.exec(queryString);
if (myQuery.lastError().isValid())
{
errorStr = "Error in add column: " + newField + "\n" + myQuery.lastError().text();
return false;
}
*/
return true;
}


bool Crit3DOutputPointsDbHandler::saveHourlyMeteoData(QString tableName, const QDateTime& myTime,
const std::vector<meteoVariable>& varList,
const std::vector<float>& values,
QString& errorStr)
Expand Down
4 changes: 3 additions & 1 deletion agrolib/outputPoints/dbOutputPointsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

bool createTable(QString tableName, QString &errorStr);
bool addColumn(QString tableName, meteoVariable myVar, QString &errorString);
bool saveHourlyData(QString tableName, const QDateTime &myTime,
bool addCriteria3DColumn(const QString &tableName, criteria3DVariable myVar, int depth, QString& errorStr);

bool saveHourlyMeteoData(QString tableName, const QDateTime &myTime,
const std::vector<meteoVariable> &varList,
const std::vector<float> &values, QString& errorStr);

Expand Down
142 changes: 101 additions & 41 deletions bin/CRITERIA3D/criteria3DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,20 @@ bool Crit3DProject::writeOutputPointsTables()
if (! outputPointsDbHandler->addColumn(tableName, sensibleHeat, errorString)) return false;
if (! outputPointsDbHandler->addColumn(tableName, latentHeat, errorString)) return false;
}
if (processes.computeWater)
{
// TODO
}
if (processes.computeSlopeStability)
{
// slope stablility starts from layer 1
for (int l = 1; l < layerDepth.size(); l++)
{
int depth_cm = round(layerDepth[l] * 100);
if (! outputPointsDbHandler->addCriteria3DColumn(tableName, factorOfSafety, depth_cm, errorString))
return false;
}
}
}
}

Expand All @@ -1342,78 +1356,124 @@ bool Crit3DProject::writeOutputPointsTables()
bool Crit3DProject::writeOutputPointsData()
{
QString tableName;
std::vector<meteoVariable> varList;
std::vector<float> valuesList;
std::vector<meteoVariable> meteoVarList;
std::vector<criteria3DVariable> criteria3dVarList;
std::vector<float> meteoValuesList;
std::vector<float> criteria3dValuesList;

if (processes.computeMeteo)
{
varList.push_back(airTemperature);
varList.push_back(precipitation);
varList.push_back(airRelHumidity);
varList.push_back(windScalarIntensity);
meteoVarList.push_back(airTemperature);
meteoVarList.push_back(precipitation);
meteoVarList.push_back(airRelHumidity);
meteoVarList.push_back(windScalarIntensity);
}
if (processes.computeRadiation)
{
varList.push_back(atmTransmissivity);
varList.push_back(globalIrradiance);
varList.push_back(directIrradiance);
varList.push_back(diffuseIrradiance);
varList.push_back(reflectedIrradiance);
meteoVarList.push_back(atmTransmissivity);
meteoVarList.push_back(globalIrradiance);
meteoVarList.push_back(directIrradiance);
meteoVarList.push_back(diffuseIrradiance);
meteoVarList.push_back(reflectedIrradiance);
}
if (processes.computeSnow)
{
varList.push_back(snowWaterEquivalent);
varList.push_back(snowFall);
varList.push_back(snowMelt);
varList.push_back(snowSurfaceTemperature);
varList.push_back(snowSurfaceEnergy);
varList.push_back(snowInternalEnergy);
varList.push_back(sensibleHeat);
varList.push_back(latentHeat);
meteoVarList.push_back(snowWaterEquivalent);
meteoVarList.push_back(snowFall);
meteoVarList.push_back(snowMelt);
meteoVarList.push_back(snowSurfaceTemperature);
meteoVarList.push_back(snowSurfaceEnergy);
meteoVarList.push_back(snowInternalEnergy);
meteoVarList.push_back(sensibleHeat);
meteoVarList.push_back(latentHeat);
}
if (processes.computeWater)
{
criteria3dVarList.push_back(volumetricWaterContent);
criteria3dVarList.push_back(waterMatricPotential);
}
if (processes.computeSlopeStability)
{
criteria3dVarList.push_back(factorOfSafety);
}

for (unsigned int i = 0; i < outputPoints.size(); i++)
{
if (outputPoints[i].active)
{
float x = float(outputPoints[i].utm.x);
float y = float(outputPoints[i].utm.y);
double x = outputPoints[i].utm.x;
double y = outputPoints[i].utm.y;
tableName = QString::fromStdString(outputPoints[i].id);

if (processes.computeMeteo)
{
valuesList.push_back(hourlyMeteoMaps->mapHourlyTair->getValueFromXY(x, y));
valuesList.push_back(hourlyMeteoMaps->mapHourlyPrec->getValueFromXY(x, y));
valuesList.push_back(hourlyMeteoMaps->mapHourlyRelHum->getValueFromXY(x, y));
valuesList.push_back(hourlyMeteoMaps->mapHourlyWindScalarInt->getValueFromXY(x, y));
meteoValuesList.push_back(hourlyMeteoMaps->mapHourlyTair->getValueFromXY(x, y));
meteoValuesList.push_back(hourlyMeteoMaps->mapHourlyPrec->getValueFromXY(x, y));
meteoValuesList.push_back(hourlyMeteoMaps->mapHourlyRelHum->getValueFromXY(x, y));
meteoValuesList.push_back(hourlyMeteoMaps->mapHourlyWindScalarInt->getValueFromXY(x, y));
}
if (processes.computeRadiation)
{
valuesList.push_back(radiationMaps->transmissivityMap->getValueFromXY(x, y));
valuesList.push_back(radiationMaps->globalRadiationMap->getValueFromXY(x, y));
valuesList.push_back(radiationMaps->beamRadiationMap->getValueFromXY(x, y));
valuesList.push_back(radiationMaps->diffuseRadiationMap->getValueFromXY(x, y));
valuesList.push_back(radiationMaps->reflectedRadiationMap->getValueFromXY(x, y));
meteoValuesList.push_back(radiationMaps->transmissivityMap->getValueFromXY(x, y));
meteoValuesList.push_back(radiationMaps->globalRadiationMap->getValueFromXY(x, y));
meteoValuesList.push_back(radiationMaps->beamRadiationMap->getValueFromXY(x, y));
meteoValuesList.push_back(radiationMaps->diffuseRadiationMap->getValueFromXY(x, y));
meteoValuesList.push_back(radiationMaps->reflectedRadiationMap->getValueFromXY(x, y));
}
if (processes.computeSnow)
{
valuesList.push_back(snowMaps.getSnowWaterEquivalentMap()->getValueFromXY(x, y));
valuesList.push_back(snowMaps.getSnowFallMap()->getValueFromXY(x, y));
valuesList.push_back(snowMaps.getSnowMeltMap()->getValueFromXY(x, y));
valuesList.push_back(snowMaps.getSnowSurfaceTempMap()->getValueFromXY(x, y));
valuesList.push_back(snowMaps.getSurfaceEnergyMap()->getValueFromXY(x, y));
valuesList.push_back(snowMaps.getInternalEnergyMap()->getValueFromXY(x, y));
valuesList.push_back(snowMaps.getSensibleHeatMap()->getValueFromXY(x, y));
valuesList.push_back(snowMaps.getLatentHeatMap()->getValueFromXY(x, y));
meteoValuesList.push_back(snowMaps.getSnowWaterEquivalentMap()->getValueFromXY(x, y));
meteoValuesList.push_back(snowMaps.getSnowFallMap()->getValueFromXY(x, y));
meteoValuesList.push_back(snowMaps.getSnowMeltMap()->getValueFromXY(x, y));
meteoValuesList.push_back(snowMaps.getSnowSurfaceTempMap()->getValueFromXY(x, y));
meteoValuesList.push_back(snowMaps.getSurfaceEnergyMap()->getValueFromXY(x, y));
meteoValuesList.push_back(snowMaps.getInternalEnergyMap()->getValueFromXY(x, y));
meteoValuesList.push_back(snowMaps.getSensibleHeatMap()->getValueFromXY(x, y));
meteoValuesList.push_back(snowMaps.getLatentHeatMap()->getValueFromXY(x, y));
}
if (processes.computeWater)
{
// TODO
}
if (processes.computeSlopeStability)
{
int row, col;
float value;
gis::getRowColFromXY((*DEM.header), x, y, &row, &col);

for (unsigned int layerIndex = 1; layerIndex < nrLayers; layerIndex++)
{
long nodeIndex = indexMap.at(layerIndex).value[row][col];
if (nodeIndex == indexMap.at(layerIndex).header->flag)
{
value = NODATA;
}
else
{
value = computeFactorOfSafety(row, col, layerIndex, nodeIndex);
}

if (! outputPointsDbHandler->saveHourlyData(tableName, getCurrentTime(), varList, valuesList, errorString))
criteria3dValuesList.push_back(value);
}
}

if (! outputPointsDbHandler->saveHourlyMeteoData(tableName, getCurrentTime(), meteoVarList, meteoValuesList, errorString))
{
return false;
}
valuesList.clear();
/*
if (! outputPointsDbHandler->saveHourlyCriteria3DData(tableName, getCurrentTime(), criteria3dVarList, criteria3dValuesList, layerDepth, errorString))
{
return false;
}*/

meteoValuesList.clear();
criteria3dValuesList.clear();
}
}
varList.clear();

meteoVarList.clear();
criteria3dVarList.clear();

return true;
}
Expand Down
10 changes: 5 additions & 5 deletions bin/CRITERIA3D/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ MainWindow::MainWindow(QWidget *parent) :
ui->flagView_not_active_outputPoints->setChecked(this->viewNotActiveOutputPoints);
this->currentPointsVisualization = notShown;

current3DlayerIndex = waterContent;
current3DlayerIndex = 0;
view3DVariable = false;

Expand Down Expand Up @@ -2205,6 +2204,7 @@ void MainWindow::on_actionCriteria3D_Initialize_triggered()
myProject.processes.computeWater = true;
myProject.processes.computeEvaporation = true;
myProject.processes.computeCrop = true;
myProject.processes.computeSlopeStability = true;

if (myProject.initializeCriteria3DModel())
{
Expand Down Expand Up @@ -2291,7 +2291,7 @@ void MainWindow::showCriteria3DVariable(criteria3DVariable var, int layerIndex,
current3DVariable = var;
current3DlayerIndex = layerIndex;

if (current3DVariable == waterContent)
if (current3DVariable == volumetricWaterContent)
{
if (layerIndex == 0)
{
Expand Down Expand Up @@ -3113,7 +3113,7 @@ void MainWindow::on_actionHide_Geomap_triggered()

void MainWindow::on_actionView_surfaceWaterContent_automatic_range_triggered()
{
showCriteria3DVariable(waterContent, 0, false, NODATA, NODATA);
showCriteria3DVariable(volumetricWaterContent, 0, false, NODATA, NODATA);
}


Expand All @@ -3131,14 +3131,14 @@ void MainWindow::on_actionView_surfaceWaterContent_fixed_range_triggered()
if (valueStr == "") return;
maximum = valueStr.toFloat();

showCriteria3DVariable(waterContent, 0, true, minimum, maximum);
showCriteria3DVariable(volumetricWaterContent, 0, true, minimum, maximum);
}


void MainWindow::on_actionView_SoilMoisture_triggered()
{
int layerIndex = std::max(1, ui->layerNrEdit->value());
showCriteria3DVariable(waterContent, layerIndex, false, NODATA, NODATA);
showCriteria3DVariable(volumetricWaterContent, layerIndex, false, NODATA, NODATA);
}


Expand Down
Loading

0 comments on commit fd1fa9e

Please sign in to comment.