Commit 574ad0c1 authored by jouke's avatar jouke
Browse files

merged the two leaf dry weight classes into one supporting all

functionality.
parent 3e32c623
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ protected:
	void calculate(const Time &t, double &dw);
	SimulaBase *SLASimulator, *leafAreaSimulator;
	Time plantingTime;
	bool SLAisLAR_;
	bool SLAisLAR_, rates;
};
class StemDryWeight:public DerivativeBase {
public:
+15 −42
Original line number Diff line number Diff line
@@ -24,44 +24,9 @@ NOTE: The GPL.v3 license requires that all derivative work is distributed under
#include "../PlantType.hpp"


LeafDryWeight::LeafDryWeight(SimulaDynamic* const pSD):DerivativeBase(pSD)
{
	//check if unit given in input file agrees with this function
	pSD->checkUnit("g");
	//planting time
	pSD->getParent(2)->getSibling("plantingTime")->get(plantingTime);
	//plant type
	std::string plantType;
	PLANTTYPE(plantType,pSD)
	//SLA
	SLASimulator=ORIGIN->getChild("rootTypeParameters")->getChild(plantType)->getChild("shoot")->getChild("specificLeafArea","g/cm2");
	if(SLASimulator->getType()!="SimulaConstant<double>") msg::error("LeafDryWeight: this assumes a constant SLA use leafDryWeight.v2 with SimulaVariable when sla is not constant.");
	//leaf area
	leafAreaSimulator=pSD->getSibling("leafArea","cm2");
}
void LeafDryWeight::calculate(const Time &t, double &dw){
	//note that the original version starts with an exponential growth curve instead of using photosynthesis
	//local time
	Time localTime(t - plantingTime);
	//get specific leaf area SLA
	double SLA;
	SLASimulator->get(localTime,SLA);
	//get portion of shoot allocated carbon that is used for leafs.
	double la;
	leafAreaSimulator->get(t,la);
	//multiply and return the result
	dw=la*SLA;
}
std::string LeafDryWeight::getName()const{
	return "leafDryWeight";
}
DerivativeBase * newInstantiationLeafDryWeight(SimulaDynamic* const pSD){
   return new LeafDryWeight(pSD);
}


LeafDryWeight2::LeafDryWeight2(SimulaDynamic* const pSD):DerivativeBase(pSD),
		SLAisLAR_(true)
		SLAisLAR_(true), rates(false)
{
	//check if unit given in input file agrees with this function
	pSD->checkUnit("g");
@@ -82,17 +47,25 @@ LeafDryWeight2::LeafDryWeight2(SimulaDynamic* const pSD):DerivativeBase(pSD),

	//leaf area
	leafAreaSimulator=pSD->getSibling("leafArea","cm2");

	//rates yes or no
	if(pSD->getType()=="SimulaVariable") {
		rates=true;
	}else{
		msg::warning("LeafDryWeight is not defined as SimulaVariable. If SLA is not constant, results will be inconsistent");
	}
}
void LeafDryWeight2::calculate(const Time &t, double &dw){
	//note that the original version starts with an exponential growth curve instead of using photosynthesis
	//local time
	Time localTime(t - plantingTime);
	//get specific leaf area SLA
	double SLA;
	SLASimulator->get(localTime,SLA);
	SLASimulator->get(t - plantingTime,SLA);
	//get portion of shoot allocated carbon that is used for leafs.
	double la;
	if(rates){
		leafAreaSimulator->getRate(t,la);
	}else{
		leafAreaSimulator->get(t,la);
	}
	//multiply and return the result
	if(SLAisLAR_){
		dw=la*SLA;
@@ -214,7 +187,7 @@ DerivativeBase * newInstantiationShootDryWeight(SimulaDynamic* const pSD){
class AutoRegisterRateClassInstantiationFunctionsDryWeight {
public:
   AutoRegisterRateClassInstantiationFunctionsDryWeight() {
 	  BaseClassesMap::getDerivativeBaseClasses()["leafDryWeight"] = newInstantiationLeafDryWeight;
 	  BaseClassesMap::getDerivativeBaseClasses()["leafDryWeight"] = newInstantiationLeafDryWeight2;//original code depricated, now auto switching to correct version with or without rates.
 	  BaseClassesMap::getDerivativeBaseClasses()["leafDryWeight.v2"] = newInstantiationLeafDryWeight2;
	  BaseClassesMap::getDerivativeBaseClasses()["shootDryWeight"] = newInstantiationShootDryWeight;
	  BaseClassesMap::getDerivativeBaseClasses()["stemDryWeight"] = newInstantiationStemDryWeight;