Skip to content

Commit

Permalink
Merge commit 'd57d86ba25e4d56cb21879d35281ffbbb79d0348'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Dec 2, 2023
2 parents 1b7d590 + d57d86b commit 37ece91
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 152 deletions.
15 changes: 7 additions & 8 deletions agrolib/criteria1DWidget/tabLAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ void TabLAI::computeLAI(Crit3DCrop* myCrop, Crit3DMeteoPoint *meteoPoint, int fi

int prevYear = firstYear - 1;

double waterTableDepth = NODATA;
std::string error;

Crit3DDate firstDate = Crit3DDate(1, 1, prevYear);
Crit3DDate lastDate;
if (lastYear != lastDBMeteoDate.year())
Expand All @@ -124,11 +121,12 @@ void TabLAI::computeLAI(Crit3DCrop* myCrop, Crit3DMeteoPoint *meteoPoint, int fi
{
lastDate = Crit3DDate(lastDBMeteoDate.day(), lastDBMeteoDate.month(), lastYear);
}
double tmin;
double tmax;

double tmin, tmax, waterTableDepth;
QDateTime x;
double dailyEt0;
int doy;
std::string errorStr;

chart->removeSeries(seriesLAI);
chart->removeSeries(seriesPotentialEvap);
Expand All @@ -147,10 +145,11 @@ void TabLAI::computeLAI(Crit3DCrop* myCrop, Crit3DMeteoPoint *meteoPoint, int fi
{
tmin = meteoPoint->getMeteoPointValueD(myDate, dailyAirTemperatureMin);
tmax = meteoPoint->getMeteoPointValueD(myDate, dailyAirTemperatureMax);
waterTableDepth = meteoPoint->getMeteoPointValueD(myDate, dailyWaterTableDepth);

if (!myCrop->dailyUpdate(myDate, meteoPoint->latitude, soilLayers, tmin, tmax, waterTableDepth, error))
if (!myCrop->dailyUpdate(myDate, meteoPoint->latitude, soilLayers, tmin, tmax, waterTableDepth, errorStr))
{
QMessageBox::critical(nullptr, "Error!", QString::fromStdString(error));
QMessageBox::critical(nullptr, "Error!", QString::fromStdString(errorStr));
return;
}

Expand Down Expand Up @@ -189,9 +188,9 @@ void TabLAI::computeLAI(Crit3DCrop* myCrop, Crit3DMeteoPoint *meteoPoint, int fi
{
QObject::connect(marker, &QLegendMarker::clicked, this, &TabLAI::handleMarkerClicked);
}

}


void TabLAI::tooltipLAI(QPointF point, bool state)
{
if (state)
Expand Down
7 changes: 4 additions & 3 deletions agrolib/criteria1DWidget/tabRootDensity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,15 @@ void TabRootDensity::updateRootDensity()
int prevYear = year - 1;
Crit3DDate firstDate = Crit3DDate(1, 1, prevYear);
Crit3DDate lastDate = Crit3DDate(currentDate->date().day(), currentDate->date().month(), year);
double waterTableDepth = NODATA;
double tmin;
double tmax;

double tmin, tmax, waterTableDepth;
double maxRootDensity = 0;

for (Crit3DDate myDate = firstDate; myDate <= lastDate; ++myDate)
{
tmin = mp.getMeteoPointValueD(myDate, dailyAirTemperatureMin);
tmax = mp.getMeteoPointValueD(myDate, dailyAirTemperatureMax);
waterTableDepth = mp.getMeteoPointValueD(myDate, dailyWaterTableDepth);

if (!myCrop.dailyUpdate(myDate, mp.latitude, layers, tmin, tmax, waterTableDepth, error))
{
Expand Down
5 changes: 2 additions & 3 deletions agrolib/criteria1DWidget/tabRootDepth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void TabRootDepth::computeRootDepth(Crit3DCrop* myCrop, Crit3DMeteoPoint *meteoP
if (nrLayers > 0) totalSoilDepth = soilLayers[nrLayers-1].depth + soilLayers[nrLayers-1].thickness / 2;

int prevYear = firstYear - 1;
double waterTableDepth = NODATA;
std::string error;

Crit3DDate firstDate = Crit3DDate(1, 1, prevYear);
Expand All @@ -84,8 +83,7 @@ void TabRootDepth::computeRootDepth(Crit3DCrop* myCrop, Crit3DMeteoPoint *meteoP
{
lastDate = Crit3DDate(lastDBMeteoDate.day(), lastDBMeteoDate.month(), lastYear);
}
double tmin;
double tmax;
double tmin, tmax, waterTableDepth;
QDateTime x;

chart->removeSeries(seriesRootDepth);
Expand All @@ -100,6 +98,7 @@ void TabRootDepth::computeRootDepth(Crit3DCrop* myCrop, Crit3DMeteoPoint *meteoP
{
tmin = meteoPoint->getMeteoPointValueD(myDate, dailyAirTemperatureMin);
tmax = meteoPoint->getMeteoPointValueD(myDate, dailyAirTemperatureMax);
waterTableDepth = meteoPoint->getMeteoPointValueD(myDate, dailyWaterTableDepth);

if (!myCrop->dailyUpdate(myDate, meteoPoint->latitude, soilLayers, tmin, tmax, waterTableDepth, error))
{
Expand Down
1 change: 0 additions & 1 deletion agrolib/criteriaModel/carbonNitrogenModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,6 @@ void Crit1DCarbonNitrogenProfile::N_harvest(Crit1DCase &myCase) // public functi

for (int l = myCase.crop.roots.firstRootLayer; l <= myCase.crop.roots.lastRootLayer; l++) // verificare i cicli for per cambio indici
{
//Select Case TipoColtura
// annual crop
if (myCase.crop.type == HERBACEOUS_ANNUAL || myCase.crop.type == HORTICULTURAL || myCase.crop.type == FALLOW_ANNUAL)
N_toLitter = myCase.crop.roots.rootDensity[l] * nitrogenTotalProfile.roots; // !! prendere il dato da dove?
Expand Down
86 changes: 83 additions & 3 deletions agrolib/crop/crop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ void Crit3DCrop::resetCrop(unsigned int nrLayers)
currentSowingDoy = NODATA;

// roots
roots.actualRootLength = 0.0;
roots.currentRootLength = 0.0;
roots.rootDepth = NODATA;
}

Expand Down Expand Up @@ -468,7 +468,7 @@ bool Crit3DCrop::dailyUpdate(const Crit3DDate &myDate, double latitude, const st
}

// update roots
root::computeRootDepth(this, degreeDays, waterTableDepth);
updateRootDepth(degreeDays, waterTableDepth);
root::computeRootDensity(this, soilLayers);
}

Expand Down Expand Up @@ -501,14 +501,94 @@ bool Crit3DCrop::restore(const Crit3DDate &myDate, double latitude, const std::v
}

// update roots
root::computeRootDepth(this, degreeDays, currentWaterTable);
updateRootDepth(degreeDays, currentWaterTable);
root::computeRootDensity(this, soilLayers);
}

return true;
}


// update current root depth [m]
void Crit3DCrop::updateRootDepth(double currentDD, double waterTableDepth)
{
if (! isLiving)
{
roots.currentRootLength = 0.0;
roots.rootDepth = NODATA;
}
else
{
roots.currentRootLength = computeRootLength(currentDD, waterTableDepth);
roots.rootDepth = roots.rootDepthMin + roots.currentRootLength;
}
}


// return current root lenght [m]
double Crit3DCrop::computeRootLength(double currentDD, double waterTableDepth)
{
double newRootLength = NODATA;

if (isRootStatic())
{
newRootLength = roots.actualRootDepthMax - roots.rootDepthMin;
}
else
{
if (currentDD <= 0)
{
newRootLength = 0.0;
}
else
{
if (currentDD > roots.degreeDaysRootGrowth)
{
newRootLength = roots.actualRootDepthMax - roots.rootDepthMin;
}
else
{
// in order to avoid numerical divergences when calculating density through cardioid and gamma function
currentDD = MAXVALUE(currentDD, 1.0);
newRootLength = root::getRootLengthDD(roots, currentDD, degreeDaysEmergence);
}
}
}

// WATERTABLE
// Nel saturo le radici vanno in asfissia
// per cui si mantengono a distanza dalla falda nella fase di crescita
// le radici possono crescere se:
// la falda è più bassa o si abbassa (max 2 cm al giorno)
// restano invariate se:
// 1) non sono più in fase di crescita
// 2) se sono già dentro la falda
const double MAX_DAILY_GROWTH = 0.02; // [m]
const double MIN_WATERTABLE_DISTANCE = 0.1; // [m]

if (! isWaterSurplusResistant()
&& ! isEqual(waterTableDepth, NODATA)
&& ! isEqual(roots.currentRootLength, NODATA)
&& newRootLength > roots.currentRootLength)
{
// la fase di crescita è finita
if (currentDD > roots.degreeDaysRootGrowth)
newRootLength = roots.currentRootLength;
else
newRootLength = MINVALUE(newRootLength, roots.currentRootLength + MAX_DAILY_GROWTH);

// maximum root lenght
double maxRootLenght = waterTableDepth - MIN_WATERTABLE_DISTANCE - roots.rootDepthMin;
if (newRootLength > maxRootLenght)
{
newRootLength = MAXVALUE(roots.currentRootLength, maxRootLenght);
}
}

return newRootLength;
}


/*! \brief getCoveredSurfaceFraction
* \ref Liangxia Zhang, Zhongmin Hu, Jiangwen Fan, Decheng Zhou & Fengpei Tang, 2014
* A meta-analysis of the canopy light extinction coefficient in terrestrial ecosystems
Expand Down
3 changes: 3 additions & 0 deletions agrolib/crop/crop.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@
void initialize(double latitude, unsigned int nrLayers, double totalSoilDepth, int currentDoy);
bool needReset(Crit3DDate myDate, double latitude, double waterTableDepth);
void resetCrop(unsigned int nrLayers);

bool updateLAI(double latitude, unsigned int nrLayers, int currentDoy);
void updateRootDepth(double currentDD, double waterTableDepth);
double computeRootLength(double currentDD, double waterTableDepth);

double computeSimpleLAI(double myDegreeDays, double latitude, int currentDoy);

Expand Down
10 changes: 5 additions & 5 deletions agrolib/crop/cropDbQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

bool getCropIdList(const QSqlDatabase &dbCrop, QList<QString>& cropIdList, QString& errorStr)
{
QString queryString = "SELECT id_crop FROM crop";
QSqlQuery query = dbCrop.exec(queryString);
QSqlQuery query(dbCrop);
query.prepare( "SELECT id_crop FROM crop");

query.first();
if (! query.isValid())
if(! query.exec())
{
errorStr = query.lastError().text();
return false;
}

query.first();
do
{
QString cropId;
Expand All @@ -26,7 +26,7 @@ bool getCropIdList(const QSqlDatabase &dbCrop, QList<QString>& cropIdList, QStri
cropIdList.append(cropId);
}
}
while(query.next());
while( query.next() );

return true;
}
Expand Down
19 changes: 10 additions & 9 deletions agrolib/crop/landUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ bool loadLandUnitList(const QSqlDatabase &dbCrop, std::vector<Crit3DLandUnit> &l
{
landUnitList.clear();

QString queryString = "SELECT * FROM land_units";
QSqlQuery query = dbCrop.exec(queryString);
query.last();
QSqlQuery query(dbCrop);
query.prepare("SELECT * FROM land_units");
if (! query.exec())
{
errorStr = query.lastError().text();
return false;
}

query.last();
if (! query.isValid())
{
if (query.lastError().isValid())
errorStr = query.lastError().text();
else
errorStr = "the table is empty";

errorStr = "the table land_units is empty";
return false;
}

Expand All @@ -54,7 +55,7 @@ bool loadLandUnitList(const QSqlDatabase &dbCrop, std::vector<Crit3DLandUnit> &l

i++;
}
while(query.next());
while( query.next() );

return true;
}
Expand Down
2 changes: 0 additions & 2 deletions agrolib/crop/rainfallInterception.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <stdio.h>
#include <math.h>

#include "rainfallInterception.h"
#include "commonConstants.h"


namespace canopy {
Expand Down
Loading

0 comments on commit 37ece91

Please sign in to comment.