Skip to content

Commit

Permalink
fix evaporation
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jun 25, 2024
1 parent 84c2597 commit 1f553d7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 41 deletions.
63 changes: 31 additions & 32 deletions criteria1DWidget/tabIrrigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ TabIrrigation::TabIrrigation()
seriesLAI = new QLineSeries();
seriesMaxTransp = new QLineSeries();
seriesRealTransp = new QLineSeries();
seriesMaxEvap = new QLineSeries();
seriesRealEvap = new QLineSeries();

seriesLAI->setName("LAI [m2 m-2]");
seriesMaxTransp->setName("Transpiration max [mm]");
seriesRealTransp->setName("Transpiration real [mm]");
seriesRealTransp->setName("actual Transpiration [mm]");
seriesMaxEvap->setName("Evaporation max [mm]");
seriesRealEvap->setName("actual Evaporation [mm]");

seriesLAI->setColor(QColor(Qt::darkGreen));
seriesLAI->setColor(QColor(Qt::green));
seriesMaxTransp->setColor(QColor(0,0,1,255));
seriesRealTransp->setColor(QColor(Qt::red));
seriesMaxEvap->setColor(QColor(Qt::gray));
seriesRealEvap->setColor(QColor(Qt::yellow));

seriesPrecIrr = new QBarSeries();

Expand Down Expand Up @@ -71,16 +77,22 @@ TabIrrigation::TabIrrigation()
chart->addSeries(seriesLAI);
chart->addSeries(seriesMaxTransp);
chart->addSeries(seriesRealTransp);
chart->addSeries(seriesMaxEvap);
chart->addSeries(seriesRealEvap);
chart->addSeries(seriesPrecIrr);

seriesLAI->attachAxis(axisX);
seriesMaxTransp->attachAxis(axisX);
seriesRealTransp->attachAxis(axisX);
seriesMaxEvap->attachAxis(axisX);
seriesRealEvap->attachAxis(axisX);
seriesPrecIrr->attachAxis(axisX);

seriesLAI->attachAxis(axisY);
seriesMaxTransp->attachAxis(axisY);
seriesRealTransp->attachAxis(axisY);
seriesMaxEvap->attachAxis(axisY);
seriesRealEvap->attachAxis(axisY);
seriesPrecIrr->attachAxis(axisYdx);

chart->legend()->setVisible(true);
Expand All @@ -96,8 +108,10 @@ TabIrrigation::TabIrrigation()
m_tooltip->hide();

connect(seriesLAI, &QLineSeries::hovered, this, &TabIrrigation::tooltipLAI);
connect(seriesMaxTransp, &QLineSeries::hovered, this, &TabIrrigation::tooltipMT);
connect(seriesRealTransp, &QLineSeries::hovered, this, &TabIrrigation::tooltipRT);
connect(seriesMaxTransp, &QLineSeries::hovered, this, &TabIrrigation::tooltipEvapTransp);
connect(seriesRealTransp, &QLineSeries::hovered, this, &TabIrrigation::tooltipEvapTransp);
connect(seriesMaxEvap, &QLineSeries::hovered, this, &TabIrrigation::tooltipEvapTransp);
connect(seriesRealEvap, &QLineSeries::hovered, this, &TabIrrigation::tooltipEvapTransp);
connect(seriesPrecIrr, &QHorizontalBarSeries::hovered, this, &TabIrrigation::tooltipPrecIrr);
foreach(QLegendMarker* marker, chart->legend()->markers())
{
Expand Down Expand Up @@ -139,6 +153,8 @@ void TabIrrigation::computeIrrigation(Crit1DCase &myCase, int firstYear, int las
seriesLAI->clear();
seriesMaxTransp->clear();
seriesRealTransp->clear();
seriesMaxEvap->clear();
seriesRealEvap->clear();
categories.clear();

if (setPrec!= nullptr)
Expand Down Expand Up @@ -184,6 +200,8 @@ void TabIrrigation::computeIrrigation(Crit1DCase &myCase, int firstYear, int las
seriesLAI->append(doy, myCase.crop.LAI);
seriesMaxTransp->append(doy, myCase.output.dailyMaxTranspiration);
seriesRealTransp->append(doy, myCase.output.dailyTranspiration);
seriesMaxEvap->append(doy, myCase.output.dailyMaxEvaporation);
seriesRealEvap->append(doy, myCase.output.dailyEvaporation);
*setPrec << myCase.output.dailyPrec;
*setIrrigation << myCase.output.dailyIrrigation;
}
Expand Down Expand Up @@ -215,9 +233,9 @@ void TabIrrigation::computeIrrigation(Crit1DCase &myCase, int firstYear, int las
}
}

void TabIrrigation::tooltipLAI(QPointF point, bool state)
void TabIrrigation::tooltipLAI(QPointF point, bool isShow)
{
if (state)
if (isShow)
{
QDate xDate(firstYear, 1, 1);
int doy = int(round(point.x())); // start from 0
Expand All @@ -234,34 +252,15 @@ void TabIrrigation::tooltipLAI(QPointF point, bool state)
}
}

void TabIrrigation::tooltipMT(QPointF point, bool state)
{
if (state)
{
QDate xDate(firstYear, 1, 1);
int doy = int(round(point.x()));
xDate = xDate.addDays(doy);
m_tooltip->setText(QString("%1 \nTransp max %2 ").arg(xDate.toString("yyyy-MM-dd")).arg(point.y(), 0, 'f', 1));
m_tooltip->setAnchor(point);
m_tooltip->setZValue(11);
m_tooltip->updateGeometry();
m_tooltip->show();
}
else
{
m_tooltip->hide();
}

}

void TabIrrigation::tooltipRT(QPointF point, bool state)
void TabIrrigation::tooltipEvapTransp(QPointF point, bool isShow)
{
if (state)
if (isShow)
{
QDate xDate(firstYear, 1, 1);
int doy = int(round(point.x()));
xDate = xDate.addDays(doy);
m_tooltip->setText(QString("%1 \nTransp real %2 ").arg(xDate.toString("yyyy-MM-dd")).arg(point.y(), 0, 'f', 1));
m_tooltip->setText(xDate.toString("yyyy-MM-dd") + "\n" + "evap/transp." + QString::number(point.y(),'f', 2));
m_tooltip->setAnchor(point);
m_tooltip->setZValue(11);
m_tooltip->updateGeometry();
Expand All @@ -273,12 +272,12 @@ void TabIrrigation::tooltipRT(QPointF point, bool state)
}
}

void TabIrrigation::tooltipPrecIrr(bool state, int index, QBarSet *barset)
{

if (state && barset!=nullptr && index < barset->count())
{

void TabIrrigation::tooltipPrecIrr(bool isShow, int index, QBarSet *barset)
{
if (isShow && barset!=nullptr && index < barset->count())
{
QPoint point = QCursor::pos();
QPoint mapPoint = chartView->mapFromGlobal(point);
QPointF pointF = chart->mapToValue(mapPoint,seriesPrecIrr);
Expand Down
10 changes: 6 additions & 4 deletions criteria1DWidget/tabIrrigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
TabIrrigation();
void computeIrrigation(Crit1DCase &myCase, int firstYear, int lastYear, const QDate &lastDBMeteoDate);

void tooltipLAI(QPointF point, bool state);
void tooltipMT(QPointF point, bool state);
void tooltipRT(QPointF point, bool state);
void tooltipPrecIrr(bool state, int index, QBarSet *barset);
void tooltipLAI(QPointF point, bool isShow);
void tooltipEvapTransp(QPointF point, bool isShow);
void tooltipPrecIrr(bool isShow, int index, QBarSet *barset);

void handleMarkerClicked();

private:
Expand All @@ -33,6 +33,8 @@
QLineSeries* seriesLAI;
QLineSeries* seriesMaxTransp;
QLineSeries* seriesRealTransp;
QLineSeries* seriesMaxEvap;
QLineSeries* seriesRealEvap;
QBarSeries* seriesPrecIrr;
QBarSet *setPrec;
QBarSet *setIrrigation;
Expand Down
4 changes: 2 additions & 2 deletions criteria1DWidget/tabLAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ TabLAI::TabLAI()
connect(seriesLAI, &QLineSeries::hovered, this, &TabLAI::tooltipLAI);
connect(seriesPotentialEvap, &QLineSeries::hovered, this, &TabLAI::tooltipPE);
connect(seriesMaxEvap, &QLineSeries::hovered, this, &TabLAI::tooltipME);
connect(seriesMaxTransp, &QLineSeries::hovered, this, &TabLAI::tooltipMT);
connect(seriesMaxTransp, &QLineSeries::hovered, this, &TabLAI::tooltipMaxTranspiration);

foreach(QLegendMarker* marker, chart->legend()->markers())
{
Expand Down Expand Up @@ -239,7 +239,7 @@ void TabLAI::tooltipME(QPointF point, bool state)
}
}

void TabLAI::tooltipMT(QPointF point, bool state)
void TabLAI::tooltipMaxTranspiration(QPointF point, bool state)
{

if (state)
Expand Down
2 changes: 1 addition & 1 deletion criteria1DWidget/tabLAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
void tooltipLAI(QPointF point, bool state);
void tooltipPE(QPointF point, bool state);
void tooltipME(QPointF point, bool state);
void tooltipMT(QPointF point, bool state);
void tooltipMaxTranspiration(QPointF point, bool state);
void handleMarkerClicked();
private:
QChartView *chartView;
Expand Down
4 changes: 2 additions & 2 deletions criteriaModel/water1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,13 @@ double computeEvaporation(std::vector<soil::Crit1DLayer> &soilLayers, double max
bool isWaterSupply = true;
double sumEvap, evapLayerThreshold, evapLayer;
int nrIteration = 0;
while ((residualEvaporation > EPSILON) && (isWaterSupply == true) && nrIteration < 5)
while ((residualEvaporation > EPSILON) && (isWaterSupply == true) && nrIteration < 3)
{
sumEvap = 0.0;

for (int i=1; i <= nrEvapLayers; i++)
{
evapLayer = residualEvaporation * (coeffEvap[i-1] / sumCoeff);
evapLayer = residualEvaporation * coeffEvap[i-1];
evapLayerThreshold = soilLayers[i].HH + (soilLayers[i].FC - soilLayers[i].HH) * coeffThreshold[i-1];

if (soilLayers[i].waterContent > (evapLayerThreshold + evapLayer))
Expand Down

0 comments on commit 1f553d7

Please sign in to comment.