Skip to content

Commit

Permalink
fix wrong soil
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Nov 16, 2023
1 parent 2a10259 commit ee133e6
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 49 deletions.
11 changes: 2 additions & 9 deletions agrolib/criteria1DWidget/criteria1DWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,15 +1553,8 @@ void Criteria1DWidget::on_actionChooseSoil(QString soilCode)
if (! loadSoil(myProject.dbSoil, soilCode, myProject.myCase.mySoil, myProject.texturalClassList,
myProject.geotechnicsClassList, myProject.myCase.fittingOptions, errorStr))
{
if (errorStr.contains("Empty"))
{
QMessageBox::information(nullptr, "Warning", errorStr);
}
else
{
QMessageBox::critical(nullptr, "Error!", errorStr);
return;
}
QMessageBox::critical(nullptr, "Error!", errorStr);
return;
}

// warning: some soil data are wrong
Expand Down
5 changes: 4 additions & 1 deletion agrolib/criteria1DWidget/tabCarbonNitrogen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ void TabCarbonNitrogen::computeCarbonNitrogen(Crit1DProject &myProject, carbonNi
}

myProject.myCase.crop.initialize(myProject.myCase.meteoPoint.latitude, nrLayers, totalSoilDepth, currentDoy);
myProject.myCase.initializeWaterContent(firstDate);
if (! myProject.myCase.initializeWaterContent(firstDate))
{
return;
}

myProject.myCarbonNitrogenProfile.N_InitializeVariables(myProject.myCase);

Expand Down
5 changes: 4 additions & 1 deletion agrolib/criteria1DWidget/tabIrrigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ void TabIrrigation::computeIrrigation(Crit1DCase &myCase, int firstYear, int las

int currentDoy = 1;
myCase.crop.initialize(myCase.meteoPoint.latitude, nrLayers, totalSoilDepth, currentDoy);
myCase.initializeWaterContent(firstDate);
if (! myCase.initializeWaterContent(firstDate))
{
return;
}

std::string errorString;
int step = formInfo.start("Compute model...", (lastYear-firstYear+2)*365);
Expand Down
18 changes: 13 additions & 5 deletions agrolib/criteria1DWidget/tabWaterContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,30 @@ void TabWaterContent::computeWaterContent(Crit1DCase &myCase, int firstYear, int
lastDate = Crit3DDate(lastDBMeteoDate.day(), lastDBMeteoDate.month(), lastYear);
}

// update axes and colorMap size
// update axes
QDateTime first(QDate(firstYear, 1, 1), QTime(0, 0, 0));
QDateTime last(QDate(lastDate.year, lastDate.month, lastDate.day), QTime(23, 0, 0));
double firstDouble = first.toSecsSinceEpoch();
double lastDouble = last.toSecsSinceEpoch();
graphic->xAxis->setRange(firstDouble, lastDouble);

// initialize crop and water
myCase.crop.initialize(myCase.meteoPoint.latitude, nrLayers, totalSoilDepth, currentDoy);
if (! myCase.initializeWaterContent(firstDate))
{
return;
}

// update colorMap
if (nrLayers == 0)
{
return;
}
nx = first.date().daysTo(last.date())+1;
ny = (nrLayers-1);

colorMap->data()->setSize(nx, ny);
colorMap->data()->setRange(QCPRange(0, nx), QCPRange(totalSoilDepth,0));

myCase.crop.initialize(myCase.meteoPoint.latitude, nrLayers, totalSoilDepth, currentDoy);
myCase.initializeWaterContent(firstDate);

std::string errorString;
double waterContent = 0.0;
double maxWaterContent = 0.0;
Expand Down
22 changes: 15 additions & 7 deletions agrolib/criteriaModel/criteria1DCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,24 @@ bool Crit1DCase::initializeSoil(std::string &error)
}


// meteoPoint has to be loaded
void Crit1DCase::initializeWaterContent(Crit3DDate myDate)
bool Crit1DCase::initializeWaterContent(Crit3DDate myDate)
{
initializeWater(soilLayers);
if (soilLayers.size() > 0)
{
initializeWater(soilLayers);

// water table
if (unit.useWaterTableData)
// water table
if (unit.useWaterTableData)
{
float waterTable = meteoPoint.getMeteoPointValueD(myDate, dailyWaterTableDepth);
computeCapillaryRise(soilLayers, double(waterTable));
}

return true;
}
else
{
double waterTable = double(meteoPoint.getMeteoPointValueD(myDate, dailyWaterTableDepth));
computeCapillaryRise(soilLayers, waterTable);
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion agrolib/criteriaModel/criteria1DCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
Crit1DCase();

bool initializeSoil(std::string &error);
void initializeWaterContent(Crit3DDate myDate);
bool initializeWaterContent(Crit3DDate myDate);
bool computeDailyModel(Crit3DDate &myDate, std::string &error);

double getWaterContent(double computationDepth);
Expand Down
3 changes: 2 additions & 1 deletion agrolib/criteriaModel/criteria1DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@ bool Crit1DProject::computeCase(unsigned int memberNr)
myCase.mySoil.totalDepth, getDoyFromDate(firstDate));

// initialize water content
myCase.initializeWaterContent(firstDate);
if (! myCase.initializeWaterContent(firstDate))
return false;

// restart
bool isFirstDay = true;
Expand Down
2 changes: 1 addition & 1 deletion agrolib/criteriaModel/water1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ double computeCapillaryRise(std::vector<soil::Crit3DLayer> &soilLayers, double w
unsigned int lastLayer = nrLayers-1;
if (nrLayers == 0) return 0;

// NO WaterTable, wrong data or watertable too depth (6 meters)
// No WaterTable, wrong data or watertable too depth (6 meters)
if ( isEqual(waterTableDepth, NODATA) || waterTableDepth <= 0
|| waterTableDepth > (soilLayers[lastLayer].depth + 6) )
{
Expand Down
18 changes: 10 additions & 8 deletions agrolib/soil/soilDbTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ bool loadSoilData(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Cri
}
else
{
// soil has no horizons
// missing data
mySoil.initialize(soilCode.toStdString(), 0);
return true;
errorStr = "soil_code:" + soilCode + " has no horizons.";
return false;
}
}

Expand Down Expand Up @@ -344,11 +345,11 @@ bool loadSoil(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DS
const std::vector<soil::Crit3DGeotechnicsClass> &geotechnicsClassList,
const soil::Crit3DFittingOptions &fittingOptions, QString& errorStr)
{
if (!loadSoilData(dbSoil, soilCode, mySoil, errorStr))
if (!loadSoilInfo(dbSoil, soilCode, mySoil, errorStr))
{
return false;
}
if (!loadSoilInfo(dbSoil, soilCode, mySoil, errorStr))
if (!loadSoilData(dbSoil, soilCode, mySoil, errorStr))
{
return false;
}
Expand All @@ -358,8 +359,8 @@ bool loadSoil(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DS
int firstWrongIndex = NODATA;
for (unsigned int i = 0; i < mySoil.nrHorizons; i++)
{
std::string currentError;
if (! soil::setHorizon(mySoil.horizon[i], textureClassList, geotechnicsClassList, fittingOptions, currentError))
std::string horizonError;
if (! soil::setHorizon(mySoil.horizon[i], textureClassList, geotechnicsClassList, fittingOptions, horizonError))
{
if (isFirstError)
{
Expand All @@ -371,9 +372,9 @@ bool loadSoil(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DS
errorStr += "\n";
}

errorStr += "SOIL " + QString::fromStdString(mySoil.code)
errorStr += "soil_code: " + soilCode
+ " horizon nr." + QString::number(mySoil.horizon[i].dbData.horizonNr)
+ " " + QString::fromStdString(currentError);
+ " " + QString::fromStdString(horizonError);
}
}

Expand All @@ -395,6 +396,7 @@ bool loadSoil(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DS
else
{
mySoil.totalDepth = 0;
errorStr = "soil_code: " + soilCode + " has no horizons.";
}

return true;
Expand Down
5 changes: 4 additions & 1 deletion agrolib/soilWidget/barHorizon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ BarHorizonList::BarHorizonList()
mainLayout->addLayout(depthLayout);
mainLayout->addLayout(barLayout);
groupBox->setLayout(mainLayout);

}


void BarHorizonList::draw(soil::Crit3DSoil *soil)
{
// check
if (soil->nrHorizons == 0)
return;

int totHeight = int(groupBox->height() * 0.9);
double soilDepth = soil->horizon[soil->nrHorizons - 1].dbData.lowerDepth;

Expand Down
15 changes: 6 additions & 9 deletions agrolib/soilWidget/soilWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,12 @@ void Crit3DSoilWidget::on_actionChooseSoil(QString soilCode)

if (! loadSoil(dbSoil, soilCode, mySoil, textureClassList, geotechnicsClassList, fittingOptions, errorStr))
{
if (errorStr.contains("Empty", Qt::CaseInsensitive))
{
QMessageBox::information(nullptr, "Warning", errorStr);
}
else
{
QMessageBox::critical(nullptr, "Error!", errorStr);
return;
}
QMessageBox::critical(nullptr, "Error!", errorStr);
return;
}
if (! errorStr.isEmpty())
{
QMessageBox::information(nullptr, "Warning", errorStr);
}

savedSoil = mySoil;
Expand Down
7 changes: 3 additions & 4 deletions agrolib/soilWidget/tabWaterRetentionData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ void TabWaterRetentionData::insertData(soil::Crit3DSoil *soil, std::vector<soil:
std::vector<soil::Crit3DGeotechnicsClass> *geotechnicsClassList,
soil::Crit3DFittingOptions* fittingOptions)
{
if (soil == nullptr)
{
resetAll();

if (soil == nullptr || soil->nrHorizons == 0)
return;
}

resetAll();
fillData = true;

barHorizons.draw(soil);
Expand Down
2 changes: 1 addition & 1 deletion bin/CRITERIA1D/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "utilities.h"

// uncomment to execute test
#define TEST
//#define TEST
//#define TEST_GEO
//#define TEST_FIRSTRUN
//#define TEST_RESTART
Expand Down

0 comments on commit ee133e6

Please sign in to comment.