Skip to content

Commit

Permalink
aggiunta mappa temperature medie del mese precedente per hydrall
Browse files Browse the repository at this point in the history
  • Loading branch information
voltAntonio committed Jan 21, 2025
1 parent 8bebfc2 commit bd7e868
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
2 changes: 1 addition & 1 deletion agrolib/grapevine/grapevine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool Vine3D_Grapevine::compute(bool computeDaily, int secondsPerStep, Crit3DMode
{
simulationStepInSeconds = double(secondsPerStep);
isAmphystomatic = true;
myLeafWidth = 0.2; // [m]
myLeafWidth = 0.2; // [cm]
// Stomatal conductance Adjust stom conductance-photosynth ratio for soil water (Pa)
alphaLeuning = modelCase->cultivar->parameterWangLeuning.alpha;
getFixSimulationParameters();
Expand Down
39 changes: 35 additions & 4 deletions agrolib/hydrall/hydrall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,45 @@
*/


#include <stdio.h>
//#include <stdio.h>
#include <math.h>
#include "crit3dDate.h"
#include "commonConstants.h"
#include "hydrall.h"


bool computeHydrall(Crit3DDate myDate, double myTemperature, double myElevation)
bool computeHydrall(Crit3DDate myDate, double myTemperature, double myElevation, int secondPerStep)
{
getCO2(myDate, myTemperature, myElevation);
double actualLAI = getLAI();
/* necessaria per ogni specie:
* il contenuto di clorofilla (g cm-2) il default è 500
* lo spessore della foglia 0.2 cm default
* un booleano che indichi se la specie è anfistomatica oppure no
* parametro alpha del modello di Leuning
*
*/
// la temperatura del mese precedente arriva da fuori



return true;
}

double getCO2(Crit3DDate myDate, double myTemperature, double myElevation)
{
double atmCO2 ; // fitting from data of Mauna Loa,Hawaii
double atmCO2 ; //https://www.eea.europa.eu/data-and-maps/daviz/atmospheric-concentration-of-carbon-dioxide-5/download.table
double year[24] = {1750,1800,1850,1900,1910,1920,1930,1940,1950,1960,1970,1980,1990,2000,2010,2020,2030,2040,2050,2060,2070,2080,2090,2100};
double valueCO2[24] = {278,283,285,296,300,303,307,310,311,317,325,339,354,369,389,413,443,473,503,530,550,565,570,575};

// exponential fitting Mauna Loa
if (myDate.year < 1990)
{
atmCO2= 280 * exp(0.0014876*(myDate.year -1840));//exponential change in CO2 concentration (ppm)
}
else
{
atmCO2= 350 * exp(0.00630*(myDate.year - 1990));
atmCO2= 353 * exp(0.00630*(myDate.year - 1990));
}
atmCO2 += 3*cos(2*PI*getDoyFromDate(myDate)/365.0); // to consider the seasonal effects
return atmCO2*getPressureFromElevation(myTemperature, myElevation)/1000000 ; // [Pa] in +- ppm/10
Expand All @@ -38,3 +54,18 @@ double getPressureFromElevation(double myTemperature, double myElevation)
{
return SEA_LEVEL_PRESSURE * exp((- GRAVITY * M_AIR * myElevation) / (R_GAS * myTemperature));
}

double getLAI()
{
// TODO
return 4;
}
/*
double meanLastMonthTemperature(double previousLastMonthTemp, double simulationStepInSeconds, double myInstantTemp)
{
double newTemperature;
double monthFraction;
monthFraction = simulationStepInSeconds/(2592000.0); // seconds of 30 days
newTemperature = previousLastMonthTemp * (1 - monthFraction) + myInstantTemp * monthFraction ;
return newTemperature;
}*/
4 changes: 3 additions & 1 deletion agrolib/hydrall/hydrall.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

#define NOT_INITIALIZED_VINE -1

bool computeHydrall(Crit3DDate myDate, double myTemperature, double myElevation, int secondPerStep);
double getCO2(Crit3DDate myDate, double myTemperature, double myElevation);
double getPressureFromElevation(double myTemperature, double myElevation);

double getLAI();
double meanLastMonthTemperature(double previousLastMonthTemp, double simulationStepInSeconds, double myInstantTemp);

#endif // HYDRALL_H
17 changes: 17 additions & 0 deletions bin/CRITERIA3D/criteria3DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void Crit3DProject::clearCropMaps()
degreeDaysMap.clear();
dailyTminMap.clear();
dailyTmaxMap.clear();
lastMonthTavgMap.clear();

isCropInitialized = false;
}
Expand All @@ -110,6 +111,7 @@ bool Crit3DProject::initializeCropMaps()

dailyTminMap.initializeGrid(*(DEM.header));
dailyTmaxMap.initializeGrid(*(DEM.header));
lastMonthTavgMap.initializeGrid(*(DEM.header));

return true;
}
Expand Down Expand Up @@ -189,6 +191,7 @@ bool Crit3DProject::initializeCropWithClimateData()
laiMap.value[row][col] = cropList[index].computeSimpleLAI(degreeDays, gisSettings.startLocation.latitude, currentDate.dayOfYear());
}
}
lastMonthTavgMap.value[row][col]= 15; // initialize to 15°C
}
}

Expand Down Expand Up @@ -1189,6 +1192,20 @@ bool Crit3DProject::computeSnowModel()
return true;
}

bool Crit3DProject::updateLast30DaysTavg()
{
if (! dailyTminMap.isLoaded || ! dailyTmaxMap.isLoaded || ! hourlyMeteoMaps->mapHourlyTair->isLoaded)
return false;

for (long row = 0; row < dailyTminMap.header->nrRows; row++)
{
for (long col = 0; col < dailyTminMap.header->nrCols; col++)
{
lastMonthTavgMap.value[row][col] = (29./30.)*lastMonthTavgMap.value[row][col] + (dailyTmaxMap.value[row][col] + dailyTminMap.value[row][col])/30;
}
}
return true;
}

bool Crit3DProject::updateDailyTemperatures()
{
Expand Down
2 changes: 2 additions & 0 deletions bin/CRITERIA3D/criteria3DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
void clear3DProject();
bool check3DProject();
bool updateDailyTemperatures();
bool updateLast30DaysTavg();

bool saveSnowModelState(const QString &currentStatePath);
bool saveSoilWaterState(const QString &currentStatePath);
Expand All @@ -47,6 +48,7 @@
gis::Crit3DRasterGrid degreeDaysMap;
gis::Crit3DRasterGrid dailyTminMap;
gis::Crit3DRasterGrid dailyTmaxMap;
gis::Crit3DRasterGrid lastMonthTavgMap;

Crit3DSnow snowModel;

Expand Down

0 comments on commit bd7e868

Please sign in to comment.