Commit c2b5b0c4 authored by jouke's avatar jouke
Browse files

Updated for leaf area code

Removed time caching
Removed some warnings which were not particularly needed.
parent 252aaf14
Loading
Loading
Loading
Loading
+21 −33
Original line number Diff line number Diff line
@@ -297,15 +297,11 @@ DerivativeBase * newInstantiationLeafAreaIndex(SimulaDynamic* const pSD){
   return new LeafAreaIndex(pSD);
}

SunlitLeafAreaIndex::SunlitLeafAreaIndex(SimulaDynamic* pSD):DerivativeBase(pSD), cachedTime(-10){
SunlitLeafAreaIndex::SunlitLeafAreaIndex(SimulaDynamic* pSD):DerivativeBase(pSD){
	leafAreaIndex = pSD->getSibling("leafAreaIndex");
	solarElevationAngle = ORIGIN->getPath("/environment/atmosphere/sineSolarElevationAngle");
}
void SunlitLeafAreaIndex::calculate(const Time &t, double &sunLAI){
	if (std::abs(t - cachedTime) < TIMEERROR){
		sunLAI = cachedSunlitLAI;
		return;
	}
	double sinEl;
	solarElevationAngle->get(t, sinEl);
	if (sinEl <= 0){
@@ -314,12 +310,10 @@ void SunlitLeafAreaIndex::calculate(const Time &t, double &sunLAI){
	}
	double LAI;
	leafAreaIndex->get(t, LAI);
	double extinctionCoefficient = 0.5/sinEl;
	const double extinctionCoefficient = 0.5/sinEl;
	sunLAI = (1 - exp(-extinctionCoefficient*LAI))/extinctionCoefficient;
	if (sunLAI > LAI) sunLAI = LAI;
	if (sunLAI > 1) sunLAI = 1;
	cachedTime = t;
	cachedSunlitLAI = sunLAI;
}
std::string SunlitLeafAreaIndex::getName()const{
	return "sunlitLeafAreaIndex";
@@ -329,21 +323,17 @@ DerivativeBase * newInstantiationSunlitLeafAreaIndex(SimulaDynamic* const pSD){
   return new SunlitLeafAreaIndex(pSD);
}

ShadedLeafAreaIndex::ShadedLeafAreaIndex(SimulaDynamic* pSD):DerivativeBase(pSD), cachedTime(-10){
ShadedLeafAreaIndex::ShadedLeafAreaIndex(SimulaDynamic* pSD):DerivativeBase(pSD){
	leafAreaIndex = pSD->getSibling("leafAreaIndex");
	sunlitLeafAreaIndex = pSD->getSibling("sunlitLeafAreaIndex");
}
void ShadedLeafAreaIndex::calculate(const Time &t, double &shadedLAI){
	if (std::abs(t - cachedTime) < TIMEERROR){
		shadedLAI = cachedShadedLAI;
		return;
	}

	double LAI, sunLAI;
	leafAreaIndex->get(t, LAI);
	sunlitLeafAreaIndex->get(t, sunLAI);
	shadedLAI = LAI - sunLAI;
	cachedTime = t;
	cachedShadedLAI = shadedLAI;

}
std::string ShadedLeafAreaIndex::getName()const{
	return "shadedLeafAreaIndex";
@@ -353,7 +343,7 @@ DerivativeBase * newInstantiationShadedLeafAreaIndex(SimulaDynamic* const pSD){
   return new ShadedLeafAreaIndex(pSD);
}

MeanLeafAreaIndex::MeanLeafAreaIndex(SimulaDynamic* pSD):DerivativeBase(pSD), plantsPlantedAtDifferentTimes(false), splitBySunStatus(false)
MeanLeafAreaIndex::MeanLeafAreaIndex(SimulaDynamic* pSD):DerivativeBase(pSD), splitBySunStatus(false)
{
	std::string name = pSD->getName().substr(4, 6); // name = sunlit or shaded
	if (name == "Sunlit" || name == "Shaded"){
@@ -370,20 +360,20 @@ MeanLeafAreaIndex::MeanLeafAreaIndex(SimulaDynamic* pSD):DerivativeBase(pSD), pl
		senescedLeafArea=pSD->existingSibling("senescedLeafArea","cm2");
	}
	plantArea=pSD->getSibling("plantArea","cm2");
	plantArea->get(0,pa);
	msg::warning("MeanLeafAreaIndex: Assuming all plants are planted at t = 0. If this is not the case, add 'plantsPlantedAtDifferentTimes' under 'environment'.");
	//plantArea->get(0,pa);
	//msg::warning("MeanLeafAreaIndex: Assuming all plants are planted at t = 0. If this is not the case, add 'plantsPlantedAtDifferentTimes' under 'environment'.");
	//area
	Coordinate minCorner, maxCorner;
	SimulaBase * params(ORIGIN->getChild("environment")->getChild("dimensions"));
	params->getChild("minCorner")->get(minCorner);
	params->getChild("maxCorner")->get(maxCorner);
	double x=fabs(maxCorner.x-minCorner.x);
	double z=fabs(maxCorner.z-minCorner.z);
	area=x*z;
	if(area<0.1) msg::error("MeanLeafAreaIndex: very small area calculated, check values for min and max corners");
	if(fabs(pa-area)>1.) msg::warning("MeanLeafAreaIndex: plant area and area of the box are not the same. Using plant Area");
	SimulaBase *probe = params->existingChild("plantsPlantedAtDifferentTimes");
	if (probe) probe->get(plantsPlantedAtDifferentTimes);
	//Coordinate minCorner, maxCorner;
	//SimulaBase * params(ORIGIN->getChild("environment")->getChild("dimensions"));
	//params->getChild("minCorner")->get(minCorner);
	//params->getChild("maxCorner")->get(maxCorner);
	//double x=fabs(maxCorner.x-minCorner.x);
	//double z=fabs(maxCorner.z-minCorner.z);
	//area=x*z;
	//if(area<0.1) msg::error("MeanLeafAreaIndex: very small area calculated, check values for min and max corners");
	//if(fabs(pa-area)>1.) msg::warning("MeanLeafAreaIndex: plant area and area of the box are not the same. Using plant Area");
	//SimulaBase *probe = params->existingChild("plantsPlantedAtDifferentTimes");
	//if (probe) probe->get(plantsPlantedAtDifferentTimes);
}
void MeanLeafAreaIndex::calculate(const Time &t, double &LAI){
	//calculate LAI
@@ -393,10 +383,8 @@ void MeanLeafAreaIndex::calculate(const Time &t, double &LAI){
		senescedLeafArea->get(t,sLA);
		LAI-=sLA;
	}
	if (plantsPlantedAtDifferentTimes){
	double pa;
	plantArea->get(t,pa);
		if(fabs(pa-area)>1.) msg::warning("MeanLeafAreaIndex: plant area and area of the box are not the same. Using plant Area");
	}
	LAI/=pa;//cm2/cm2
}
std::string MeanLeafAreaIndex::getName()const{
+1 −4
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ public:
protected:
	void calculate(const Time &t, double &LAI);
	SimulaBase *leafAreaIndex, *solarElevationAngle;
	double cachedTime, cachedSunlitLAI;
};
class ShadedLeafAreaIndex:public DerivativeBase {
public:
@@ -86,7 +85,6 @@ public:
protected:
	void calculate(const Time &t, double &LAI);
	SimulaBase *leafAreaIndex, *sunlitLeafAreaIndex;
	double cachedTime, cachedShadedLAI;
};
class MeanLeafAreaIndex:public DerivativeBase {
public:
@@ -94,9 +92,8 @@ public:
	std::string getName()const;
protected:
	void calculate(const Time &t, double &LAI);
	double area, pa;
	SimulaBase* leafArea, *senescedLeafArea, *plantArea;
	bool plantsPlantedAtDifferentTimes, splitBySunStatus;
	bool splitBySunStatus;
};
/// Simulates the ratio between actual and potential leaf area
class LeafAreaReductionCoefficient:public DerivativeBase {