Commit ae31ea5e authored by jouke's avatar jouke
Browse files

minor code improvements, removed caching

parent c926e151
Loading
Loading
Loading
Loading
+33 −35
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ NOTE: The GPL.v3 license requires that all derivative work is distributed under
#include "../../engine/Origin.hpp"
/*******************PenmanMonteith*************************/
PenmanMonteith::PenmanMonteith(SimulaDynamic* const pSV) :
		ETbaseclass(pSV), cachedTime(-10) {
		ETbaseclass(pSV){
	std::string name = pSD->getName().substr(0, 6); // name = sunlit or shaded
	if (name == "sunlit" || name == "shaded") splitBySunStatus = true;
	//check if unit given in input file agrees with this function
@@ -57,44 +57,41 @@ DerivativeBase * newInstantiationPenmanMonteith(
	this->checkMode(t);
	//--------------------------------------------------------------------
	const double conversion_day = 86400.; // conversion from second to 1 day
	if (std::abs(t - cachedTime) < TIMEERROR){
		ETSOIL = cachedSoilET;
	} else{

	double temperature;
	dailyTemperature_->get(t, temperature);
	/// --- latent heat of vaporization ---
		lambda = this->calculateLatentHeat(temperature);
	double lambda = this->calculateLatentHeat(temperature);
	///  --- pressure of water vapor in the air ---
		double e_a, e_s; // actual and saturated vapor pressure
	double e_a, e_s, delta; // actual and saturated vapor pressure
	// --- gradient of saturation vapor pressure, derivative of e_s ---
	actualVaporPressure_->get(t, e_a); //hPa
	saturatedVaporPressure_->get(t, e_s); //hPa
	slopeVaporPressure_->get(t, delta);  //hPa/degreeC
	/// vapor pressure deficit of air (in mb.=hPa)
		VPD = e_s - e_a;
	const double VPD = e_s - e_a;
	double airDensity;
	airDensity_->get(t, airDensity);
		double P;
	double P, airHeatCapacity;
	airPressure_->get(t, P);
	specificHeatCapacityOfAir_->get(t, airHeatCapacity);
	/// psychrometer constant
	const double MWratio = 0.622; ///< ratio molecular weight of water vapor/dry air
		gamma = (airHeatCapacity * P * 0.01) / (lambda * MWratio); // psychrometric constant
		double H_soil;
	const double gamma = (airHeatCapacity * P * 0.01) / (lambda * MWratio); // psychrometric constant
	double H_soil, H_crop, r_a;
	this->calculateRadiation(t, H_soil, H_crop);
	aerodynamicResistance_->get(t, r_a);
	// Using equation 8 on page 208 of
	/// Monteith, J.L., Evaporation and Environment, Proc. Symp. Soc. Exp. Biol. 19 (1965), 205-234
	// Monteith, J.L., Evaporation and Environment, Proc. Symp. Soc. Exp. Biol. 19 (1965), 205-234
	ETSOIL = (delta * H_soil + conversion_day * airDensity * airHeatCapacity * VPD / r_a) / (lambda * (delta + gamma)); // kg/m2/d
	ETSOIL = ETSOIL * 0.1; // convert from kg/m2/d to cm3/cm2/d
	}

	double r_s;
	stomatalResistance_->get(t, r_s);
	// We use equation 13 on page 210 of
    /// Monteith, J.L., Evaporation and Environment, Proc. Symp. Soc. Exp. Biol. 19 (1965), 205-234
	ETCROP = (delta*H_crop + conversion_day*airDensity*airHeatCapacity*VPD/r_a)/(lambda*(delta + gamma*(1 + r_s/r_a))); // kg/m2/d
	ETCROP = ETCROP*0.1; // convert from kg/m2/d to cm3/cm2/d
	cachedTime = t;
	cachedSoilET = ETSOIL;
}


@@ -480,7 +477,7 @@ void Grass_reference_evapotranspiration::calculateET(const Time &t,double& ETCRO
 	//--------------------------------------------------------------------
 	double P;
    airPressure_->get(t,P);
 	double c = 1013.;///< J/kg/C  , this is proposed by FAO, constant pressure and 20C
 	double c = 1013.;///< J/kg/C  , this is proposed by FAO, constant pressure and 20 deg. C
 	specificHeatCapacityOfAir_->get(t,c);
 	/// psychrometer constant
 	const double MWratio = 0.622; ///< ratio molecular weight of water vapor/dry air
@@ -656,6 +653,7 @@ void Grass_reference_evapotranspiration::calculateET(const Time &t,double& ETCRO
 		BaseClassesMap::getDerivativeBaseClasses()["penmanEQ"] 	= newInstantiationPenman;
 		BaseClassesMap::getDerivativeBaseClasses()["useET0fromTable"] 	= newInstantiationUseET0fromTable;
 		BaseClassesMap::getDerivativeBaseClasses()["monteithEQ"] = newInstantiationPenmanMonteith;
 		BaseClassesMap::getDerivativeBaseClasses()["penmanmonteithEQ"] = newInstantiationPenmanMonteith;
 	}
 };

+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ public:
protected:
	void calculateET(const Time &t, double& ETCROP, double& ETSOIL);
	SimulaBase *aerodynamicResistance_,*airDensity_ ;
	double cachedTime, lambda, VPD, delta, gamma, airDensity, airHeatCapacity, H_crop, r_a, cachedSoilET;

};