Commit f69c0b97 authored by jouke's avatar jouke
Browse files

introduced seed reserve allocation rate based on linear decline and the

set seedReserveDuration.
parent 574ad0c1
Loading
Loading
Loading
Loading
+20 −18
Original line number Diff line number Diff line
@@ -29,18 +29,16 @@ NOTE: The GPL.v3 license requires that all derivative work is distributed under


Reserves::Reserves(SimulaDynamic* const pSV):
	DerivativeBase(pSV)
	DerivativeBase(pSV),plantingTime(pSD->getStartTime()),mt(12)
{
	//check if unit given in input file agrees with this function
	pSD->checkUnit("g");
	//plantingTime
	plantingTime=pSD->getStartTime();
	//plant type
	std::string plantType;
	pSD->getSibling("plantType")->get(plantType);
	//get rate from table / constant
	SimulaBase* param(GETRESOURCEPARAMETERS(plantType));
	rrSimulator=param->getChild("reserveAllocationRate");
	rrSimulator=param->existingChild("reserveAllocationRate");
	//get seed size
	double seedsize;
	SimulaBase *p = param->existingChild("carbonInSeed", "g");
@@ -58,29 +56,33 @@ Reserves::Reserves(SimulaDynamic* const pSV):
			if (p){
				msg::error("Reserves: You are using seedSize, which is deprecated. Use carbonInSeed (if this value represents the amount of carbon in the seed) or seedMass (if this value represents the total mass of the seed, carbon weight will be calculated using the carbonToDryWeightRatio) instead.");
			} else{
				msg::error("Reserves: Seed carbon parameter not found.");
				msg::error("Reserves: Specify either carbonInSeed or seedMass in the resources section of your plant parameters.");
			}
		}
	}
	pSD->setInitialValue(seedsize);
	//time after which seed reserves have expired
	p = param->existingChild("seedReserveDuration","day");
	if(p) p->get(mt);
	mt+=plantingTime;
}

void Reserves::calculate(const Time &t, double& reserve){
	//current reserve
	pSD->get(t,reserve);
	if(reserve==0.) {
		pSD->minTimeStep()= pSD->maxTimeStep();
	}else if (reserve<0.00001) {//drop to zero
		pSD->preferedTimeStep()=pSD->maxTimeStep();
		reserve/=pSD->maxTimeStep();
	}else{ //calculate
    if (reserve<1e-9) {//drop to zero
		reserve=0;
	}else{
		if(t>=mt){
			reserve=0;
		}else if(rrSimulator){
			double rate;
		rrSimulator->get((Time)(t-plantingTime),rate);
			rrSimulator->get(t-plantingTime,rate);
			reserve*= rate*-1;
		}else{
			reserve/=(t-mt);
		}
	if(std::isnan(reserve)) {
		msg::error("Reserves: Reserves is NaN");
	}

}

std::string Reserves::getName()const{
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ public:
protected:
	void calculate(const Time &t, double&);
	SimulaBase *rrSimulator;
	Time plantingTime;
	Time plantingTime,mt;
};

/**