Skip to content

Commit

Permalink
Merge commit 'ceb5d9dccf968b2f09078ba1f56fab4d2abbd33d'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Nov 22, 2023
2 parents 5f61e1b + ceb5d9d commit 2de7988
Show file tree
Hide file tree
Showing 31 changed files with 344 additions and 222 deletions.
50 changes: 26 additions & 24 deletions agrolib/criteria1DWidget/criteria1DWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Criteria1DWidget::Criteria1DWidget()
waterContentGroup = new QGroupBox(tr(""));
carbonNitrogenGroup = new QGroupBox(tr(""));

float widthRatio = 0.25;
float widthRatio = 0.30f;
infoCaseGroup->setFixedWidth(this->width() * widthRatio);
infoCropGroup->setFixedWidth(this->width() * widthRatio);
infoMeteoGroup->setFixedWidth(this->width() * widthRatio);
Expand Down Expand Up @@ -342,24 +342,24 @@ Criteria1DWidget::Criteria1DWidget()
parametersRootDepthLayout->addWidget(rootDegreeDaysGrowth, 4, 0);
parametersRootDepthLayout->addWidget(rootDegreeDaysGrowthValue, 4, 1);

QLabel *irrigationVolume = new QLabel(tr("irrigation quantity [mm]: "));
QLabel *irrigationVolume = new QLabel(tr("irrigation quantity [mm]:"));
irrigationVolumeValue = new QLineEdit();
irrigationVolumeValue->setText(QLocale().toString(0));
irrigationVolumeValue->setMaximumWidth(irrigationParametersGroup->width()/5);
irrigationVolumeValue->setValidator(positiveValidator);
QLabel *irrigationShift = new QLabel(tr("irrigation shift [days]: "));
QLabel *irrigationShift = new QLabel(tr("irrigation shift [days]:"));
irrigationShiftValue = new QSpinBox();
irrigationShiftValue->setMaximumWidth(irrigationParametersGroup->width()/5);
irrigationShiftValue->setMinimum(0);
irrigationShiftValue->setMaximum(365);
irrigationShiftValue->setEnabled(false);

QLabel *degreeDaysStart = new QLabel(tr("degreee days start irrigation [°C]: "));
QLabel *degreeDaysStart = new QLabel(tr("deg. days start irrigation [°C]:"));
degreeDaysStartValue = new QLineEdit();
degreeDaysStartValue->setMaximumWidth(irrigationParametersGroup->width()/5);
degreeDaysStartValue->setValidator(positiveValidator);
degreeDaysStartValue->setEnabled(false);
QLabel *degreeDaysEnd = new QLabel(tr("degreee days end irrigation [°C]: "));
QLabel *degreeDaysEnd = new QLabel(tr("deg. days end irrigation [°C]:"));
degreeDaysEndValue = new QLineEdit();
degreeDaysEndValue->setMaximumWidth(irrigationParametersGroup->width()/5);
degreeDaysEndValue->setValidator(positiveValidator);
Expand Down Expand Up @@ -900,7 +900,7 @@ void Criteria1DWidget::openMeteoDB(QString dbMeteoName)
}
else
{
if (! openDbMeteo(dbMeteoName, &(myProject.dbMeteo), &errorStr))
if (! openDbMeteo(dbMeteoName, myProject.dbMeteo, errorStr))
{
QMessageBox::critical(nullptr, "Error DB meteo", errorStr);
return;
Expand Down Expand Up @@ -1244,19 +1244,22 @@ void Criteria1DWidget::on_actionChooseMeteo(QString idMeteo)
QMessageBox::critical(nullptr, "Error load properties DB Grid", errorStr);
return;
}

double lat;
if (!myProject.observedMeteoGrid->meteoGrid()->getLatFromId(idMeteo.toStdString(), &lat) )
if (! myProject.observedMeteoGrid->meteoGrid()->getLatFromId(idMeteo.toStdString(), &lat))
{
errorStr = "Missing observed meteo cell";
return;
}
myProject.myCase.meteoPoint.latitude = lat;

meteoTableName = myProject.observedMeteoGrid->tableDaily().prefix + idMeteo + myProject.observedMeteoGrid->tableDaily().postFix;
if (!myProject.observedMeteoGrid->getYearList(&errorStr, idMeteo, &yearList))
{
QMessageBox::critical(nullptr, "Error!", errorStr);
return;
}

int pos = 0;
if (myProject.observedMeteoGrid->gridStructure().isFixedFields())
{
Expand All @@ -1268,7 +1271,7 @@ void Criteria1DWidget::on_actionChooseMeteo(QString idMeteo)
for (int i = 0; i<yearList.size()-1; i++)
{

if ( !checkYearMeteoGridFixedFields(myProject.dbMeteo, meteoTableName, myProject.observedMeteoGrid->tableDaily().fieldTime, fieldTmin, fieldTmax, fieldPrec, yearList[i], &errorStr))
if (! checkYearMeteoGridFixedFields(myProject.dbMeteo, meteoTableName, myProject.observedMeteoGrid->tableDaily().fieldTime, fieldTmin, fieldTmax, fieldPrec, yearList[i], &errorStr))
{
yearList.removeAt(pos);
i = i - 1;
Expand Down Expand Up @@ -1313,12 +1316,12 @@ void Criteria1DWidget::on_actionChooseMeteo(QString idMeteo)
else
{
QString lat,lon;
if (getLatLonFromIdMeteo(&(myProject.dbMeteo), idMeteo, &lat, &lon, &errorStr))
if (getLatLonFromIdMeteo(myProject.dbMeteo, idMeteo, lat, lon, errorStr))
{
myProject.myCase.meteoPoint.latitude = lat.toDouble();
}

meteoTableName = getTableNameFromIdMeteo(&(myProject.dbMeteo), idMeteo, &errorStr);
meteoTableName = getTableNameFromIdMeteo(myProject.dbMeteo, idMeteo, errorStr);

if (!getYearList(&(myProject.dbMeteo), meteoTableName, &yearList, &errorStr))
{
Expand Down Expand Up @@ -1553,15 +1556,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 Expand Up @@ -2074,17 +2070,23 @@ bool Criteria1DWidget::checkCropIsChanged()
}

// irrigation parameters
// TODO gestire caso irrigazioni azzerate
if(irrigationShiftValue->isVisible())
{
if( isEqual(cropFromDB.irrigationVolume, QLocale().toDouble(irrigationVolumeValue->text()))
|| cropFromDB.irrigationShift != irrigationShiftValue->value()
|| cropFromDB.degreeDaysStartIrrigation != degreeDaysStartValue->text().toInt()
|| cropFromDB.degreeDaysEndIrrigation != degreeDaysEndValue->text().toInt() )
if(! isEqual(cropFromDB.irrigationVolume, QLocale().toDouble(irrigationVolumeValue->text())) )
{
isCropChanged = true;
return isCropChanged;
}
if (QLocale().toDouble(irrigationVolumeValue->text()) > 0)
{
if ( cropFromDB.irrigationShift != irrigationShiftValue->value()
|| cropFromDB.degreeDaysStartIrrigation != degreeDaysStartValue->text().toInt()
|| cropFromDB.degreeDaysEndIrrigation != degreeDaysEndValue->text().toInt() )
{
isCropChanged = true;
return isCropChanged;
}
}
}

isCropChanged = false;
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
23 changes: 15 additions & 8 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 Expand Up @@ -557,7 +565,6 @@ bool Crit1DCase::computeDailyModel(Crit3DDate &myDate, std::string &error)
rootDensityMax = std::max(rootDensityMax, crop.roots.rootDensity[l]);
}

// TODO add crop.roots.tensileStrength
for (unsigned int l = 1; l < nrLayers; l++)
{
double rootDensityNorm;
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
Loading

0 comments on commit 2de7988

Please sign in to comment.