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

src: update decision essentially

- to use vle.recursive
- update reading of parameters (robust to R)
- and update vpz
parent 977d02d3
This diff is collapsed.
// @@tagdynamic@@
// @@tagdepends: vle.discrete-time @@endtagdepends
#include <vle/DiscreteTime.hpp>
#include "SunfloUtils.hpp"
namespace vd = vle::devs;
namespace vv = vle::value;
namespace sunflo {
using namespace vle::discrete_time;
class Decision : public DiscreteTimeDyn
{
public:
std::vector<std::pair<long, double> > fertilization;
std::vector<std::pair<long, double> > irrigation;
Decision(
const vd::DynamicsInit& atom,
const vd::InitEventList& events)
: DiscreteTimeDyn(atom, events), fertilization(), irrigation()
{
ActionSemis.init(this, "ActionSemis", events);
densite.init(this, "densite", events);
zSemis.init(this, "zSemis", events);
ActionFerti.init(this, "ActionFerti", events);
DoseFerti.init(this, "DoseFerti", events);
ActionIrrig.init(this, "ActionIrrig", events);
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");
//initialise fertilizations
bool finish = false;
unsigned int i=0;
while (!finish) {
i++;
std::stringstream ss;
ss << "fertilization_" << i;
finish = !events.exist(ss.str());
if (! finish) {
double date =0;
double dose =0;
Utils::extractApport(events, ss.str(), date, dose);
if (dose > 0) {
fertilization.push_back(std::make_pair(date, dose));
}
}
}
//initialise irrigations
finish = false;
i=0;
while (!finish) {
i++;
std::stringstream ss;
ss << "irrigation_" << i;
finish = !events.exist(ss.str());
if (! finish) {
double date =0;
double dose =0;
Utils::extractApport(events, ss.str(), date, dose);
if (dose > 0) {
irrigation.push_back(std::make_pair(date, dose));
}
}
}
}
virtual ~Decision()
{}
virtual void compute(const vd::Time& j)
{
//sowing
if (jsemis == begin_date + (long)j){
ActionSemis = 1;
densite = densite_p;
zSemis = zSemis_p;
ActionFerti = 0;
DoseFerti = 0;
ActionIrrig = 0 ;
DoseIrrig = 0;
ActionRecolte = 0;
return;
}
//harvesting
if (jrecolte == begin_date + (long)j){
ActionSemis = 0;
densite = 0;
zSemis = 0;
ActionFerti = 0;
DoseFerti = 0;
ActionIrrig = 0 ;
DoseIrrig = 0;
ActionRecolte = 1;
return;
}
//fertilizations
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);
if (found) {
ActionFerti = 1;
DoseFerti = f.second;
}
}
if (not found) {
ActionFerti = 0;
DoseFerti = 0;
}
//irrigations
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);
if (found) {
ActionIrrig = 1;
DoseIrrig = f.second;
}
}
if (not found) {
ActionIrrig = 0;
DoseIrrig = 0;
}
//default sowing and harvesting
ActionSemis = 0;
densite = 0;
zSemis = 0;
ActionRecolte = 0;
}
Var ActionSemis;
Var densite;
Var zSemis;
Var ActionFerti;
Var DoseFerti;
Var ActionIrrig;
Var DoseIrrig;
Var ActionRecolte;
long begin_date;
long jsemis;
double densite_p;
double zSemis_p;
long jrecolte;
};
} // namespace
DECLARE_DYNAMICS(sunflo::Decision);
......@@ -11,6 +11,7 @@
#define SUNFLO_PARAMETRESPLANTE_HPP_
#include <vle/devs/InitEventList.hpp>
#include "SunfloUtils.hpp"
//#define VALEURPARDEFAUT_date_TT_germination 86.2 ///< valeur par defaut
//#define VALEURPARDEFAUT_dHE 1.19 ///< valeur par defaut
......@@ -178,178 +179,42 @@ struct ParametresPlante {
/// Seuil TDM relatif a TNpmax
double TDMm_seuil;
void initialiser(const vle::devs::InitEventList& events)
void initialiser(const vle::devs::InitEventList& evts)
{
if ( events.exist("date_TT_germination") ){
date_TT_germination = events.getDouble("date_TT_germination");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'date_TT_germination'");
}
if ( events.exist("dHE") ){
dHE = events.getDouble("dHE");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'dHE'");
}
if ( events.exist("Eb_0") ){
Eb_0 = events.getDouble("Eb_0");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Eb_0'");
}
if ( events.exist("Eb_c") ){
Eb_c = events.getDouble("Eb_c");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Eb_c'");
}
if ( events.exist("Eb_fin") ){
Eb_fin = events.getDouble("Eb_fin");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Eb_fin'");
}
if ( events.exist("Eb_max") ){
Eb_max = events.getDouble("Eb_max");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Eb_max'");
}
if ( events.exist("LAI_a") ){
LAI_a = events.getDouble("LAI_a");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'LAI_a'");
}
if ( events.exist("LAI_b") ){
LAI_b = events.getDouble("LAI_b");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'LAI_b'");
}
if ( events.exist("LAI_c") ){
LAI_c = events.getDouble("LAI_c");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'LAI_c'");
}
if ( events.exist("LAI_d") ){
LAI_d = events.getDouble("LAI_d");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'LAI_d'");
}
if ( events.exist("LAI_e") ){
LAI_e = events.getDouble("LAI_e");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'LAI_e'");
}
if ( events.exist("LAI_f") ){
LAI_f = events.getDouble("LAI_f");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'LAI_f'");
}
if ( events.exist("LAI_Kei") ){
LAI_Kei = events.getDouble("LAI_Kei");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'LAI_Kei'");
}
if ( events.exist("Phy1") ){
Phy1 = events.getDouble("Phy1");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Phy1'");
}
if ( events.exist("Phy2") ){
Phy2 = events.getDouble("Phy2");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Phy2'");
}
if ( events.exist("Tbase") ){
Tbase = events.getDouble("Tbase");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Tbase'");
}
if ( events.exist("Tmax_PHS") ){
Tmax_PHS = events.getDouble("Tmax_PHS");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Tmax_PHS'");
}
if ( events.exist("Topt1_PHS") ){
Topt1_PHS = events.getDouble("Topt1_PHS");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Topt1_PHS'");
}
if ( events.exist("Topt2_PHS") ){
Topt2_PHS = events.getDouble("Topt2_PHS");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Topt2_PHS'");
}
if ( events.exist("a_Pho") ){
a_Pho = events.getDouble("a_Pho");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'a_Pho'");
}
if ( events.exist("AA_a") ){
AA_a = events.getDouble("AA_a");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'AA_a'");
}
if ( events.exist("zRac_max") ){
zRac_max = events.getDouble("zRac_max");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'zRac_max'");
}
if ( events.exist("FNLEm") ){
FNLEm = events.getDouble("FNLEm");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'FNLEm'");
}
if ( events.exist("INNseuil") ){
INNseuil = events.getDouble("INNseuil");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'INNseuil'");
}
if ( events.exist("AP_a") ){
AP_a = events.getDouble("AP_a");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'AP_a'");
}
if ( events.exist("date_TT_F1M0") ){
date_TT_F1M0 = events.getDouble("date_TT_F1M0");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'date_TT_F1M0'");
}
if ( events.exist("VitCroiRac") ){
VitCroiRac = events.getDouble("VitCroiRac");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'VitCroiRac'");
}
if ( events.exist("Kc") ){
Kc = events.getDouble("Kc");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'Kc'");
}
if ( events.exist("PNCc_a") ){
PNCc_a = events.getDouble("PNCc_a");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'PNCc_a'");
}
if ( events.exist("PNCc_b") ){
PNCc_b = events.getDouble("PNCc_b");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'PNCc_b'");
}
if ( events.exist("TDMc_seuil") ){
TDMc_seuil = events.getDouble("TDMc_seuil");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'TDMc_seuil'");
}
if ( events.exist("PNCm_a") ){
PNCm_a = events.getDouble("PNCm_a");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'PNCm_a'");
}
if ( events.exist("PNCm_b") ){
PNCm_b = events.getDouble("PNCm_b");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'PNCm_b'");
}
if ( events.exist("TDMm_seuil") ){
TDMm_seuil = events.getDouble("TDMm_seuil");
} else {
throw vle::utils::ModellingError("[ParametersPlante] missing 'TDMm_seuil'");
}
date_TT_germination = Utils::extractDouble(evts, "date_TT_germination");
dHE = Utils::extractDouble(evts, "dHE");
Eb_0 = Utils::extractDouble(evts, "Eb_0");
Eb_c = Utils::extractDouble(evts, "Eb_c");
Eb_fin = Utils::extractDouble(evts, "Eb_fin");
Eb_max = Utils::extractDouble(evts, "Eb_max");
LAI_a = Utils::extractDouble(evts, "LAI_a");
LAI_b = Utils::extractDouble(evts, "LAI_b");
LAI_c = Utils::extractDouble(evts, "LAI_c");
LAI_d = Utils::extractDouble(evts, "LAI_d");
LAI_e = Utils::extractDouble(evts, "LAI_e");
LAI_f = Utils::extractDouble(evts, "LAI_f");
LAI_Kei = Utils::extractDouble(evts, "LAI_Kei");
Phy1 = Utils::extractDouble(evts, "Phy1");
Phy2 = Utils::extractDouble(evts, "Phy2");
Tbase = Utils::extractDouble(evts, "Tbase");
Tmax_PHS = Utils::extractDouble(evts, "Tmax_PHS");
Topt1_PHS = Utils::extractDouble(evts, "Topt1_PHS");
Topt2_PHS = Utils::extractDouble(evts, "Topt2_PHS");
a_Pho = Utils::extractDouble(evts, "a_Pho");
AA_a = Utils::extractDouble(evts, "AA_a");
zRac_max = Utils::extractDouble(evts, "zRac_max");
FNLEm = Utils::extractDouble(evts, "FNLEm");
INNseuil = Utils::extractDouble(evts, "INNseuil");
AP_a = Utils::extractDouble(evts, "AP_a");
date_TT_F1M0 = Utils::extractDouble(evts, "date_TT_F1M0");
VitCroiRac = Utils::extractDouble(evts, "VitCroiRac");
Kc = Utils::extractDouble(evts, "Kc");
PNCc_a = Utils::extractDouble(evts, "PNCc_a");
PNCc_b = Utils::extractDouble(evts, "PNCc_b");
TDMc_seuil = Utils::extractDouble(evts, "TDMc_seuil");
PNCm_a = Utils::extractDouble(evts, "PNCm_a");
PNCm_b = Utils::extractDouble(evts, "PNCm_b");
TDMm_seuil = Utils::extractDouble(evts, "TDMm_seuil");
}
};
} //namespace
......
......@@ -11,6 +11,8 @@
#ifndef SUNFLO_PARAMETRESSOL_HPP
#define SUNFLO_PARAMETRESSOL_HPP
#include "SunfloUtils.hpp"
namespace sunflo {
//#define VALEURPARDEFAUT_da_C1 1.5 ///< valeur par defaut
......@@ -86,81 +88,60 @@ struct ParametresSol
void initialiser( const vle::devs::InitEventList& events ){
if ( events.exist("profondeur") ){
if (events.get("profondeur")->isDouble()) {
profondeur = events.getDouble("profondeur");
} else if (events.get("profondeur")->isInteger()){
profondeur = (double) events.getInt("profondeur");
} else {
throw vle::utils::ModellingError("[ParametersSol] wrong 'profondeur'");
}
} else {
throw vle::utils::ModellingError("[ParametersSol] missing 'profondeur'");
}
profondeur = Utils::extractDouble(events, "profondeur");
if (events.exist("da_C1") and events.exist("da_C2")) {
da_C1 = events.getDouble("da_C1");
da_C2 = events.getDouble("da_C2");
da_C1 = Utils::extractDouble(events, "da_C1");
da_C2 = Utils::extractDouble(events, "da_C2");
} else if (events.exist("da")){
da_C1 = events.getDouble("da");
da_C2 = events.getDouble("da");
da_C1 = Utils::extractDouble(events, "da");
da_C2 = da_C1;
} else {
throw vle::utils::ModellingError("[ParametersSol] missing 'da_*'");
}
if (events.exist("Hcc_C1") and events.exist("Hcc_C2")) {
Hcc_C1 = events.getDouble("Hcc_C1");
Hcc_C2 = events.getDouble("Hcc_C2");
Hcc_C1 = Utils::extractDouble(events, "Hcc_C1");
Hcc_C2 = Utils::extractDouble(events, "Hcc_C2");
} else if (events.exist("Hcc")){
Hcc_C1 = events.getDouble("Hcc");
Hcc_C2 = events.getDouble("Hcc");
Hcc_C1 = Utils::extractDouble(events, "Hcc");
Hcc_C2 = Hcc_C1;
} else {
throw vle::utils::ModellingError("[ParametersSol] missing 'Hcc_*'");
}
if (events.exist("Hpf_C1") and events.exist("Hpf_C2")) {
Hpf_C1 = events.getDouble("Hpf_C1");
Hpf_C2 = events.getDouble("Hpf_C2");
Hpf_C1 = Utils::extractDouble(events, "Hpf_C1");
Hpf_C2 = Utils::extractDouble(events, "Hpf_C2");
} else if (events.exist("Hpf")){
Hpf_C1 = events.getDouble("Hpf");
Hpf_C2 = events.getDouble("Hpf");
Hpf_C1 = Utils::extractDouble(events, "Hpf");
Hpf_C2 = Hpf_C1;
} else {
throw vle::utils::ModellingError("[ParametersSol] missing 'Hpf_*'");
}
if (events.exist("Hini_C1") and events.exist("Hini_C2")) {
Hini_C1 = events.getDouble("Hini_C1");
Hini_C2 = events.getDouble("Hini_C2");
Hini_C1 = Utils::extractDouble(events, "Hini_C1");
Hini_C2 = Utils::extractDouble(events, "Hini_C2");
} else if (events.exist("Hini")){
Hini_C1 = events.getDouble("Hini");
Hini_C2 = events.getDouble("Hini");
Hini_C1 = Utils::extractDouble(events, "Hini");
Hini_C2 = Hini_C1;
} else {
throw vle::utils::ModellingError("[ParametersSol] missing 'Hini_*'");
}
if ( events.exist("Fpf") ){
Fpf = events.getDouble("Fpf");
} else {
throw vle::utils::ModellingError("[ParametersSol] missing 'Fpf'");
}
if ( events.exist("Vp") ){
Vp = events.getDouble("Vp");
} else {
throw vle::utils::ModellingError("[ParametersSol] missing 'Vp'");
}
Fpf = Utils::extractDouble(events, "Fpf");
if ( events.exist("TC") ){
TC = events.getDouble("TC");
} else {
throw vle::utils::ModellingError("[ParametersSol] missing 'TC'");
}
if ( events.exist("zC1") ){
zC1 = events.getDouble("zC1");
} else {
throw vle::utils::ModellingError("[ParametersSol] missing 'zC1'");
}
if (events.exist("RUmmC1") and (events.getDouble("RUmmC1") != -1)) {
RUmmC1 = events.getDouble("RUmmC1");
Vp = Utils::extractDouble(events, "Vp");
TC = Utils::extractDouble(events, "TC");
zC1 = Utils::extractDouble(events, "zC1");
if (events.exist("RUmmC1") and
(Utils::extractDouble(events, "RUmmC1") != -1)) {
RUmmC1 = Utils::extractDouble(events, "RUmmC1");
} else {
RUmmC1 = (Hcc_C1 - Hpf_C1 ) / 100.0 * da_C1 * ( 1.0 - TC );
}
if (events.exist("RUmmC2") and (events.getDouble("RUmmC2") != -1)) {
RUmmC2 = events.getDouble("RUmmC2");
if (events.exist("RUmmC2") and
(Utils::extractDouble(events, "RUmmC2") != -1)) {
RUmmC2 = Utils::extractDouble(events, "RUmmC2");
} else {
RUmmC2 = (Hcc_C2 - Hpf_C2 ) / 100.0 * da_C2 * ( 1.0 - TC );
}
......
......@@ -11,6 +11,7 @@
#ifndef SUNFLO_PARAMETRESVARIETE_HPP
#define SUNFLO_PARAMETRESVARIETE_HPP
#include "SunfloUtils.hpp"
namespace sunflo {
......@@ -94,48 +95,50 @@ struct ParametresVariete
//codeMMpourMemo Linear interpolation
double thp;
void initialiser( const vle::devs::InitEventList& events ){
void initialiser( const vle::devs::InitEventList& evts ){
if ( events.exist("date_TT_E1") ){
date_TT_E1 = events.getDouble("date_TT_E1");
} else {
throw vle::utils::ModellingError("[ParametersVariete] missing 'date_TT_E1'");
}
date_TT_E1 = Utils::extractDouble(evts, "date_TT_E1");
//date_TT_F1
if ( events.exist("date_TT_F1") ){
if (events.exist("reldate_TT_F1")) {
throw vle::utils::ModellingError("[ParametersVariete] either 'date_TT_F1' or 'reldate_TT_F1'");
if ( evts.exist("date_TT_F1") ){
if (evts.exist("reldate_TT_F1")) {
throw vle::utils::ModellingError(
"[ParametersVariete] either 'date_TT_F1' or 'reldate_TT_F1'");
}
date_TT_F1 = events.getDouble("date_TT_F1");
} else if (events.exist("reldate_TT_F1")) {
date_TT_F1 = date_TT_E1 + events.getDouble("reldate_TT_F1");
date_TT_F1 = Utils::extractDouble(evts, "date_TT_F1");
} else if (evts.exist("reldate_TT_F1")) {
date_TT_F1 = date_TT_E1+Utils::extractDouble(evts, "reldate_TT_F1");
} else {
throw vle::utils::ModellingError("[ParametersVariete] missing 'date_TT_F1' and 'reldate_TT_F1' ");
throw vle::utils::ModellingError(
"[ParametersVariete] missing 'date_TT_F1' and 'reldate_TT_F1'");
}
//date_TT_M0
if ( events.exist("date_TT_M0") ){
if (events.exist("reldate_TT_M0")) {
throw vle::utils::ModellingError("[ParametersVariete] either 'date_TT_M0' or 'reldate_TT_M0'");
if ( evts.exist("date_TT_M0") ){
if (evts.exist("reldate_TT_M0")) {
throw vle::utils::ModellingError(
"[ParametersVariete] either 'date_TT_M0' or 'reldate_TT_M0'");
}
date_TT_M0 = events.getDouble("date_TT_M0");
} else if (events.exist("reldate_TT_M0")) {
date_TT_M0 = date_TT_F1 + events.getDouble("reldate_TT_M0");
date_TT_M0 = Utils::extractDouble(evts, "date_TT_M0");
} else if (evts.exist("reldate_TT_M0")) {
date_TT_M0 = date_TT_F1+Utils::extractDouble(evts, "reldate_TT_M0");
} else {
throw vle::utils::ModellingError("[ParametersVariete] missing 'date_TT_M0' and 'reldate_TT_M0'");
throw vle::utils::ModellingError(
"[ParametersVariete] missing 'date_TT_M0' and 'reldate_TT_M0'");
}
//date_TT_M3
if ( events.exist("date_TT_M3") ){
if (events.exist("reldate_TT_M3")) {
throw vle::utils::ModellingError("[ParametersVariete] either 'date_TT_M3' or 'reldate_TT_M3'");
//date_TT_M3
if ( evts.exist("date_TT_M3") ){
if (evts.exist("reldate_TT_M3")) {
throw vle::utils::ModellingError(
"[ParametersVariete] either 'date_TT_M3' or 'reldate_TT_M3'");
}
date_TT_M3 = events.getDouble("date_TT_M3");
} else if (events.exist("reldate_TT_M3")) {