Skip to content

Commit

Permalink
Merge commit '438c5254d13b2380d6c54aa18acab8fba5ea8cc6'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Feb 10, 2025
2 parents f66bffc + 438c525 commit 96f7b10
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 275 deletions.
2 changes: 1 addition & 1 deletion agrolib/gis/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Crit3DColorScale::Crit3DColorScale()
_minimum = NODATA;
_maximum = NODATA;
_isFixedRange = false;
_isHideOutliers = false;
_isHideMinimum = false;
_isTransparent = false;

_classification = classificationMethod::EqualInterval;
Expand Down
6 changes: 3 additions & 3 deletions agrolib/gis/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
std::vector<Crit3DColor> color;
double _minimum, _maximum;
bool _isFixedRange;
bool _isHideOutliers;
bool _isHideMinimum;
bool _isTransparent;
int _classification;

Expand Down Expand Up @@ -54,8 +54,8 @@
void setFixedRange(bool fixedRange) { _isFixedRange = fixedRange; }
bool isFixedRange() { return _isFixedRange; }

void setHideOutliers(bool hideOutliers) { _isHideOutliers = hideOutliers; }
bool isHideOutliers() { return _isHideOutliers; }
void setHideMinimum(bool isHideMinimum) { _isHideMinimum = isHideMinimum; }
bool isHideMinimum() { return _isHideMinimum; }

void setTransparent(bool transparent) { _isTransparent = transparent; }
bool isTransparent() { return _isTransparent; }
Expand Down
6 changes: 3 additions & 3 deletions agrolib/graphics/mapGraphicsRasterUtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ bool RasterUtmObject::drawRaster(QPainter* painter)
if (isEqual(value, _rasterPointer->header->flag) || isEqual(value, NODATA))
continue;

// check outliers (transparent)
if (_rasterPointer->colorScale->isHideOutliers())
// check minimum (transparent)
if (_rasterPointer->colorScale->isHideMinimum())
{
if (isEqual(value, 0) || value <= _rasterPointer->colorScale->minimum() || value > _rasterPointer->colorScale->maximum())
if (isEqual(value, 0) || value <= _rasterPointer->colorScale->minimum())
continue;
}

Expand Down
232 changes: 172 additions & 60 deletions agrolib/hydrall/hydrall.cpp

Large diffs are not rendered by default.

66 changes: 52 additions & 14 deletions agrolib/hydrall/hydrall.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@

};

struct TenvironmentalVariable {

double CO2;
double sineSolarElevation;
};

struct Tplant {

double myChlorophyllContent;
double height;
double myLeafWidth;
bool isAmphystomatic;

};

struct ThydrallSoil {

int soilLayersNr;
double soilTotalDepth;
double* rootDensity;
};

struct TbigLeaf
{
double absorbedPAR ;
Expand All @@ -77,11 +99,24 @@

};

struct TparameterWangLeuningFix
struct TparameterWangLeuning
{
double optimalTemperatureForPhotosynthesis;
double stomatalConductanceMin;
double sensitivityToVapourPressureDeficit;
double alpha;
double psiLeaf; // kPa
double waterStressThreshold;
double maxCarboxRate; // Vcmo at optimal temperature


};

struct TlightExtinctionCoefficient
{
double global;
double par;
double nir;

};

Expand All @@ -90,6 +125,8 @@
private:

public:
gis::Crit3DRasterGrid* aboveGroundBiomassMap;
gis::Crit3DRasterGrid* rootBiomassMap;
gis::Crit3DRasterGrid* mapLAI;
gis::Crit3DRasterGrid* mapLast30DaysTavg;

Expand All @@ -109,28 +146,27 @@

TbigLeaf sunlit,shaded;
TweatherVariable weatherVariable;
TparameterWangLeuningFix parameterWangLeuningFix;
TenvironmentalVariable environmentalVariable;
TparameterWangLeuning parameterWangLeuning;
Tplant plant;
ThydrallSoil soil;
TlightExtinctionCoefficient directLightExtinctionCoefficient;
TlightExtinctionCoefficient diffuseLightExtinctionCoefficient;



double myChlorophyllContent;
double sineSolarElevation;
double elevation;
int simulationStepInSeconds;
double leafAreaIndex;
double plantHeight;
double myLeafWidth;
bool isAmphystomatic;

double directLightK;
double diffuseLightKPAR;
double diffuseLightKNIR;
double directLightKPAR;
double directLightKNIR;
double* transpirationInstantLayer; //molH2O m^-2 s^-1




void radiationAbsorption(double mySunElevation);
void setHourlyVariables(double temp, double irradiance , double prec , double relativeHumidity , double windSpeed, double directIrradiance, double diffuseIrradiance, double cloudIndex);
bool setWeatherVariables(double temp, double irradiance , double prec , double relativeHumidity , double windSpeed, double directIrradiance, double diffuseIrradiance, double cloudIndex);
void setHourlyVariables(double temp, double irradiance , double prec , double relativeHumidity , double windSpeed, double directIrradiance, double diffuseIrradiance, double cloudIndex, double atmosphericPressure, double CO2, double sunElevation);
bool setWeatherVariables(double temp, double irradiance , double prec , double relativeHumidity , double windSpeed, double directIrradiance, double diffuseIrradiance, double cloudIndex, double atmosphericPressure);
void setDerivedWeatherVariables(double directIrradiance, double diffuseIrradiance, double cloudIndex);
void setPlantVariables(double chlorophyllContent);
bool computeHydrallPoint(Crit3DDate myDate, double myTemperature, double myElevation, int secondPerStep, double &AGBiomass, double &rootBiomass);
Expand All @@ -144,6 +180,8 @@
double leafWidth();
void upscale();
double acclimationFunction(double Ha , double Hd, double leafTemp, double entropicTerm,double optimumTemp);
void photosynthesisKernel(double COMP,double GAC,double GHR,double GSCD,double J,double KC,double KO
,double RD,double RNI,double STOMWL,double VCmax,double *ASS,double *GSC,double *TR);

};

Expand Down
5 changes: 5 additions & 0 deletions agrolib/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,11 @@ float shepardSearchNeighbour(vector <Crit3DInterpolationDataPoint> &inputPoints,
}

float radius;

if (shepardNeighbourPoints.size() < SHEPARD_MIN_NRPOINTS)
{
int nrPoints = sortPointsByDistance(SHEPARD_MIN_NRPOINTS, inputPoints, outputPoints);
if (outputPoints.empty()) return NODATA;
radius = outputPoints[nrPoints-1].distance + float(EPSILON);
}
else if (shepardNeighbourPoints.size() > SHEPARD_MAX_NRPOINTS)
Expand Down Expand Up @@ -990,6 +992,9 @@ float modifiedShepardIdw(vector <Crit3DInterpolationDataPoint> &myPoints,
else
validPoints = myPoints;

if (myPoints.empty())
return NODATA;

weight.resize(validPoints.size());
t.resize(validPoints.size());
S.resize(validPoints.size());
Expand Down
2 changes: 1 addition & 1 deletion agrolib/mathFunctions/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ double pressureFromAltitude(double height)

double pressureFromAltitude(double temperature, double height)
{
return P0 * exp((- GRAVITY * M_AIR * height) / (R_GAS * temperature));
return P0 * exp((- GRAVITY * M_AIR * height) / (R_GAS * (temperature + 273.15)));
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion agrolib/meteo/meteo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ bool setColorScale(meteoVariable variable, Crit3DColorScale *colorScale)
if (variable == precipitation || variable == snowFall || variable == snowWaterEquivalent
|| variable == snowLiquidWaterContent || variable == snowMelt)
{
colorScale->setHideOutliers(true);
colorScale->setHideMinimum(true);
colorScale->setTransparent(true);
}
break;
Expand Down
9 changes: 8 additions & 1 deletion agrolib/project/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3052,6 +3052,8 @@ bool Project::interpolationDemGlocalDetrending(meteoVariable myVar, const Crit3D
else
myRaster->value[row][col] += interpolatedValue*areaCells[cellIndex+1];
}
else
return false;
}
}
}
Expand Down Expand Up @@ -3459,8 +3461,13 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime)
proxyIndex++;
}
}
interpolatedValue = interpolate(subsetInterpolationPoints, &interpolationSettings, meteoSettings, myVar, myX, myY, myZ, proxyValues, true)

double temp = interpolate(subsetInterpolationPoints, &interpolationSettings, meteoSettings, myVar, myX, myY, myZ, proxyValues, true);
if (! isEqual(temp, NODATA))
interpolatedValue = interpolate(subsetInterpolationPoints, &interpolationSettings, meteoSettings, myVar, myX, myY, myZ, proxyValues, true)
* areaCells[cellIndex + 1];
else
return false;
}
if (freq == hourly)
{
Expand Down
3 changes: 2 additions & 1 deletion agrolib/proxyWidget/proxyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Crit3DProxyWidget::Crit3DProxyWidget(Crit3DInterpolationSettings* interpolationS
selectionOptionBoxLayout->addWidget(&modelLR);
selectionOptionBoxLayout->addWidget(&climatologicalLR);

if (macroAreaNumber != NODATA) modelLR.setEnabled(false);

selectionOptionEditLayout->addWidget(r2Label);
selectionOptionEditLayout->addWidget(&r2);
selectionOptionEditLayout->addStretch(150);
Expand Down Expand Up @@ -585,7 +587,6 @@ void Crit3DProxyWidget::addMacroAreaLR()
point_vector.append(point);
}

macroAreaNumber = NODATA;
chartView->drawModelLapseRate(point_vector);
}
return;
Expand Down
29 changes: 14 additions & 15 deletions agrolib/soilFluxes3D/balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@


Tbalance balanceCurrentTimeStep, balancePreviousTimeStep, balanceCurrentPeriod, balanceWholePeriod;
double Courant = 0.0;
double CourantWater = 0.0;

static double bestMBRerror;
static bool isHalfTimeStepForced = false;
Expand Down Expand Up @@ -252,42 +252,41 @@ bool waterBalance(double deltaT, int approxNr)

isHalfTimeStepForced = false;

/*! error better than previuosly */
if ((approxNr == 0) || (MBRerror < bestMBRerror))
// error is better than previuosly
if (approxNr == 0 || MBRerror < bestMBRerror)
{
saveBestStep();
bestMBRerror = MBRerror;
}

/*! best case */
// best case
if (MBRerror < myParameters.MBRThreshold)
{
acceptStep(deltaT);
if ((approxNr <= 2) && (Courant < 0.5) && (MBRerror < (myParameters.MBRThreshold * 0.5)))
if (approxNr <= 2 && CourantWater < 0.5 && MBRerror < (myParameters.MBRThreshold * 0.5))
{
/*! system is stable: double time step */
doubleTimeStep();
}
return true;
}

/*! worst case: error high or last approximation */
if ((MBRerror > (bestMBRerror * 2.0))
||(approxNr == (myParameters.maxApproximationsNumber-1)))
{
// worst case: error is high or last approximation
if ( MBRerror > (bestMBRerror * 2.0) || approxNr == (myParameters.maxApproximationsNumber-1) )
{
if (deltaT > myParameters.delta_t_min)
{
{
halveTimeStep();
isHalfTimeStepForced = true;
return (false);
}
return false;
}
else
{
{
restoreBestStep(deltaT);
acceptStep(deltaT);
return (true);
}
return true;
}
}

// default
return false;
Expand Down
4 changes: 1 addition & 3 deletions agrolib/soilFluxes3D/header/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

double arithmeticMean(double v1, double v2);

bool solver(int myApproximation, double myResidualTolerance, int myProcess);

void initializeThreads();
bool solveLinearSystem(int approximation, double residualTolerance, int computationType);

#endif // SOLVER_H

2 changes: 1 addition & 1 deletion agrolib/soilFluxes3D/header/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
extern Tculvert myCulvert;
extern double *b, *C, *X, *X1;
extern double *invariantFlux; // array accessorio per flussi avvettivi e latenti
extern double Courant;
extern double CourantWater;

extern Tbalance balanceCurrentTimeStep, balancePreviousTimeStep, balanceCurrentPeriod, balanceWholePeriod;

Expand Down
3 changes: 2 additions & 1 deletion agrolib/soilFluxes3D/heat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,8 @@ bool HeatComputation(double timeStep, double timeStepWater)
return (false);
}

solver(0, myParameters.ResidualTolerance, PROCESS_HEAT);
int approximation = 0;
solveLinearSystem(approximation, myParameters.ResidualTolerance, PROCESS_HEAT);

for (i = 1; i < myStructure.nrNodes; i++)
nodeList[i].extra->Heat->T = X[i];
Expand Down
Loading

0 comments on commit 96f7b10

Please sign in to comment.