Commit f72a2194 authored by Ronan Trépos's avatar Ronan Trépos
Browse files

sunflo: improve Phenology

'date_levee' can now be forced
parent a76f808d
......@@ -84,7 +84,7 @@
<port name="ISH3"/>
</out>
</model>
<model observables="phenologie" conditions="CONFIG_Variete,CONFIG_SimuInit,CONFIG_Plante,EXPERT_Plante,phenologie" width="100" dynamics="Phenologie" height="105" x="252" y="22" name="phenologie" type="atomic">
<model observables="phenologie" conditions="CONFIG_Variete,cBegin,CONFIG_SimuInit,itk,CONFIG_Plante,EXPERT_Plante,phenologie" width="100" dynamics="Phenologie" height="105" x="252" y="22" name="phenologie" type="atomic">
<in>
<port name="ActionRecolte"/>
<port name="ActionSemis"/>
......@@ -1053,8 +1053,8 @@
<port name="NomSimuInit">
<string>indetermine</string>
</port>
<port name="dateLevee_casForcee">
<string>00/00</string>
<port name="data_levee">
<double>-1</double>
</port>
<port name="init_value_N1">
<double>10.000000000000000</double>
......
......@@ -4,6 +4,7 @@
#include <vle/DiscreteTime.hpp>
#include <ParametresSimuInit.hpp>
#include "SunfloUtils.hpp"
......@@ -25,6 +26,8 @@ public:
const vd::InitEventList& events)
: DiscreteTimeDyn(atom, events), fertilization(), irrigation()
{
psi.initialiser(events);
ActionSemis.init(this, "ActionSemis", events);
densite.init(this, "densite", events);
zSemis.init(this, "zSemis", events);
......@@ -34,9 +37,6 @@ public:
DoseIrrig.init(this, "DoseIrrig", events);
ActionRecolte.init(this, "ActionRecolte", events);
begin_date = Utils::extractDate(events, "begin_date");
jsemis = Utils::extractDate(events, "jsemis");
densite_p = Utils::extractDouble(events, "densite");
zSemis_p = Utils::extractDouble(events, "zSemis");
jrecolte = Utils::extractDate(events, "jrecolte");
......@@ -86,7 +86,7 @@ public:
virtual void compute(const vd::Time& j)
{
//sowing
if (jsemis == begin_date + (long)j){
if (psi.jsemis == psi.begin_date + (long)j){
ActionSemis = 1;
densite = densite_p;
zSemis = zSemis_p;
......@@ -98,7 +98,7 @@ public:
return;
}
//harvesting
if (jrecolte == begin_date + (long)j){
if (jrecolte == psi.begin_date + (long)j){
ActionSemis = 0;
densite = 0;
zSemis = 0;
......@@ -113,7 +113,7 @@ public:
bool found = false;
for(unsigned int i=0;i < fertilization.size() and not found; i++) {
const std::pair<long, double>& f = fertilization[i];
found = (f.first == (long) begin_date + j);
found = (f.first == (long) psi.begin_date + j);
if (found) {
ActionFerti = 1;
DoseFerti = f.second;
......@@ -128,7 +128,7 @@ public:
found = false;
for(unsigned int i=0;i < irrigation.size() and not found; i++) {
const std::pair<long, double>& f = irrigation[i];
found = (f.first == (long) begin_date + j);
found = (f.first == (long) psi.begin_date + j);
if (found) {
ActionIrrig = 1;
DoseIrrig = f.second;
......@@ -154,8 +154,8 @@ public:
Var DoseIrrig;
Var ActionRecolte;
long begin_date;
long jsemis;
ParametresSimuInit psi;
double densite_p;
double zSemis_p;
long jrecolte;
......
......@@ -10,6 +10,7 @@
#ifndef SUNFLO_PARAMETRESSIMUINIT_HPP
#define SUNFLO_PARAMETRESSIMUINIT_HPP
#include "SunfloUtils.hpp"
namespace sunflo {
......@@ -22,17 +23,26 @@ namespace sunflo {
struct ParametresSimuInit
{
/// # Jour de levee (si spécifié, on ne simule plus la phase semis-levée)
//codeMMpourMemo parameter: date_A2 0 0
// date_A2 est renomme dateLevee_casForcee
std::string dateLevee_casForcee ;
//begin day corresponding to t=0 of simulation
long begin_date;
//sowing day in julian days
long jsemis;
//forcing rising day of the crop in julian day (-1 if rising is simulated)
long date_levee ;
void initialiser( const vle::devs::InitEventList& events ){
if ( events.exist("dateLevee_casForcee") ){
dateLevee_casForcee = events.getString("dateLevee_casForcee");
} else {
throw vle::utils::ModellingError("[ParametersSimuInit] missing 'dateLevee_casForcee'");
begin_date = Utils::extractDate(events, "begin_date");
jsemis = Utils::extractDate(events, "jsemis");
date_levee = -1;
if (events.exist("date_levee")){
date_levee = Utils::extractDate(events, "date_levee");
} else if(events.exist("reldate_levee")) {
date_levee = jsemis +
(long) Utils::extractDouble(events, "reldate_levee");
}
if (date_levee <= jsemis){
date_levee = -1;
}
}
};
......
......@@ -57,7 +57,7 @@ public :
psi.initialiser(events);
if ( utils::nullite(psi.dateLevee_casForcee) ){
if ( psi.date_levee < 0 ){
simulationPhaseSemisLevee = true;
} else {
simulationPhaseSemisLevee = false;
......@@ -124,12 +124,12 @@ public :
double ddt = 0.0;
if ( ( (int)PhasePhenoPlante(-1) > PHASEPHENOPLANTE_NONSEMEE )
&& ( (int)PhasePhenoPlante(-1) < PHASEPHENOPLANTE_RECOLTEE ) ){
and ( (int)PhasePhenoPlante(-1) < PHASEPHENOPLANTE_RECOLTEE ) ){
if ( ( simulationPhaseSemisLevee )
&& ( TT_A0() < estimationTTentreSemisEtLevee_casPhaseSemisLeveeSimulee ) ){
and ( TT_A0() < estimationTTentreSemisEtLevee_casPhaseSemisLeveeSimulee ) ){
ddt = 0.0;
} else if ( ( not simulationPhaseSemisLevee )
&& ( ! utils::ordreChronologique( psi.dateLevee_casForcee, utils::dateJJMM(time) ) ) ){
} else if (( not simulationPhaseSemisLevee ) and
(psi.date_levee > psi.begin_date + (long) time)){
ddt = 0.0;
} else {
ddt = Teff() + AP(-1);
......@@ -166,14 +166,6 @@ public :
if ((int)ActionSemis() == 1 ){ // instant de semis
PhasePhenoPlante_tmp = PHASEPHENOPLANTE_GERMINATION ;
// verification de coherence (dateLevee_casForcee non anterieur a semis)
if ( simulationPhaseSemisLevee == false ){
if ( utils::ordreChronologique( psi.dateLevee_casForcee, utils::dateJJMM(time) ) ){ // date semis anormalement >= dateLevee_casForcee
throw vle::utils::ModellingError("[Phenologie] Error dateLevee_casForcee");
}
}
}
if ((int)ActionRecolte() == 1 ){
......@@ -190,7 +182,7 @@ public :
PhasePhenoPlante_tmp = PHASEPHENOPLANTE_JUVENILE ;
}
} else { // not p.simulationPhaseSemisLevee
if ( utils::ordreChronologique( psi.dateLevee_casForcee, utils::dateJJMM(time) ) ){
if (psi.date_levee == psi.begin_date + (long) time){
// date levee (dateLevee_casForcee) atteinte
PhasePhenoPlante_tmp = PHASEPHENOPLANTE_JUVENILE ;
}
......
......@@ -124,10 +124,10 @@ struct Utils
/**
* @brief Extract a date from a double or a date "1999-01-01"
* @brief Extract a date from a double, an integer, or a date "1999-01-01"
* @param evts, init event list
* @param port, name of the port in events
* @return a double
* @return a long
*/
static long
extractDate(const vle::devs::InitEventList& evts,
......@@ -144,11 +144,14 @@ struct Utils
}
if (init->isDouble()) {
return (long) init->toDouble().value();
}
if (init->isInteger()) {
return (long) init->toInteger().value();
} else {
std::string mess = " parameter "+port;
mess += " has wrong format (expect String or Double)";
throw vu::ArgError(mess);
}
}
return -1;
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment