Diagnostic.cpp 11.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 *
 * Copyright (C) 2009-2014 INRA.
 * Copyright (C) 2009-2014 CETIOM.
 *
 *
 * TODO licence
 */

// @@tagdynamic@@
// @@tagdepends: vle.discrete-time @@endtagdepends


#include <math.h>
#include <vle/DiscreteTime.hpp>
#include <sunflo_utils.hpp>
#include <Phenologie.hpp>
#include <ParametresPlante.hpp>
#include <ParametresVariete.hpp>
20
#include <ParametresRendement.hpp>
21
22
23
24
25
26
27
28
29
30

namespace sunflo {

using namespace vle::discrete_time;

class Diagnostic : public DiscreteTimeDyn
{
public :
    ParametresVariete pv;
    ParametresPlante pp;
31
    ParametresRendement pr;
32
33
34
35

    /*Sync*/ Var TT_A2;
    /*Sync*/ Var ETRETM;

36
37
38
39
40
////////////////////////////////////////////////////////////////////////
/////////////////////////////REMI ADDS//////////////////////////////////
////////////////////////////////////////////////////////////////////////

    /*Sync*/ Var PhasePhenoPlante;
RemiM's avatar
RemiM committed
41
    /*Sync*/ Var Tmoy;
RemiM's avatar
RemiM committed
42
43
44
45
    /*Sync*/ Var Pluie;
    /*Sync*/ Var Ei;
    /*Sync*/ Var FHTR;
    /*Sync*/ Var CT_RUE;
46

47
48
49
50


// Covariables to compute OC

51
52
    /// # Jours entre maturation et récolte.
    Var D_MH;
RemiM's avatar
RemiM committed
53
   /// # Jours entre semis et germination.
54
    Var D_SE;
RemiM's avatar
RemiM committed
55
56
   /// # Jours de phase juvénile et croissance active.
    Var D_EF;
57
58
59
60
61
62
63

    /// # Somme ETPET entre maturation et récolte.
    Var SET_MH;

    /// # Moyenne ETPET entre maturation et récolte.
    Var MET_MH;

RemiM's avatar
RemiM committed
64
   /// # Somme ETPET durant les jours de phase juvénile et croissance active.
65
66
    Var SET_EF;

RemiM's avatar
RemiM committed
67
    /// # Moyenne ETPET durant les jours de phase juvénile et croissance active.
68
69
70
71
    Var MET_EF;

    // Thermal stress entre germinatioan et initiation florale.
    Var NHT28_EF;
RemiM's avatar
RemiM committed
72
 
RemiM's avatar
RemiM committed
73
    // Thermal stress during whole season
74
    Var NHT28;
RemiM's avatar
RemiM committed
75

RemiM's avatar
RemiM committed
76
77
78
    // Radiations
    Var RG;
    // Sum of radiations during flowering
RemiM's avatar
RemiM committed
79
     Var SGR_FM;
80

81

RemiM's avatar
RemiM committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Covariables to compute GY

// Somme précipitations durant la phase végétative (covariables statistiques)
    Var SRR_EF;
// Somme précipitations durant la floraison  (covariables statistiques)
    Var SRR_FM;
// Somme radiations interceptées durant la phase végétative (covariables statistiques)
    Var SIR_EF;
// Somme  radiations interceptées durant la floraison  (covariables statistiques)
    Var SIR_FM;
// Effet contrainte hydrique sur la photosynthèse durant la phase végétative (covariables statistiques)
    Var SFHTR_EF;
//  Effet contrainte hydrique sur la photosynthèse durant la floraison  (covariables statistiques)
    Var SFHTR_FM;

// Facteur de réponse de la photosynthèse à la contrainte azote
    Var FNIRUE;
//  Effet contrainte azote  sur la photosynthèse après la maturation  (covariables statistiques)
    Var SFNRUE_MH;

// Somme hautes températures durant la floraison
    Var SHT_FM; 
104

105
106
107
108
109
    Diagnostic(const vle::devs::DynamicsInit& model,
            const vle::devs::InitEventList& events) :
                DiscreteTimeDyn(model, events)
    {
        pv.initialiser(events);
110
        pr.initialiser(events);
111
112
113
114
        pp.initialiser(events);

        TT_A2.init(this, "TT_A2", events);
        ETRETM.init(this, "ETRETM", events);
115

RemiM's avatar
RemiM committed
116
	
117
118
	D_MH.init(this, "D_MH" , events);
	D_SE.init(this, "D_SE", events);
RemiM's avatar
RemiM committed
119
	D_EF.init(this, "D_EF", events);
120
121
122
123

        SET_MH.init(this, "SET_MH" , events);
        MET_MH.init(this, "MET_MH" , events);

RemiM's avatar
RemiM committed
124
125
        SET_EF.init(this, "SET_EF" , events);
        MET_EF.init(this, "MET_EF" , events);
126

RemiM's avatar
RemiM committed
127
128
129
	NHT28_EF.init(this, "NHT28_EF", events);
	NHT28.init(this, "NHT28", events);
 
RemiM's avatar
RemiM committed
130
	SGR_FM.init(this, "SGR_FM", events);
RemiM's avatar
RemiM committed
131
	RG.init(this, "RG", events);
RemiM's avatar
RemiM committed
132

133
        PhasePhenoPlante.init(this, "PhasePhenoPlante", events);
RemiM's avatar
RemiM committed
134
	Tmoy.init(this, "Tmoy", events);
RemiM's avatar
RemiM committed
135
136
137
138
	Pluie.init(this, "Pluie", events);
	Ei.init(this,  "Ei", events);
	FHTR.init(this,  "FHTR", events);
	CT_RUE.init(this,  "CT_RUE", events);
139
140


RemiM's avatar
RemiM committed
141
142
143
////// Covariables GY
	SRR_EF.init(this, "SRR_EF", events);
	SRR_FM.init(this, "SRR_FM", events);
144

RemiM's avatar
RemiM committed
145
146
	SIR_EF.init(this, "SIR_EF", events);
	SIR_FM.init(this, "SIR_FM", events);
147

RemiM's avatar
RemiM committed
148
149
150
151
152
153
	SFHTR_EF.init(this, "SFHTR_EF", events);
	SFHTR_FM.init(this, "SFHTR_FM", events);
	
	FNIRUE.init(this, "FNIRUE", events);
	SFNRUE_MH.init(this, "SFNRUE_MH", events);
	SHT_FM.init(this, "SHT_FM", events);
154
155
156
157
158
159
    }

    virtual ~Diagnostic() { }

    virtual void compute(const vle::devs::Time& /*time*/ )
    {
160

RemiM's avatar
RemiM committed
161

RemiM's avatar
RemiM committed
162
		
163
            {
RemiM's avatar
RemiM committed
164
                if ( ( PhasePhenoPlante() != PHASEPHENOPLANTE_MATURATION )
165
                        // traduit condition TT_A2 < date_TT_M0
RemiM's avatar
RemiM committed
166
167
168
                       // || ( PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE )
                       // || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE )
		   ){
169
170
171
172
173
174
175
176
                    D_MH = D_MH(-1);
                } else {
                    D_MH = D_MH(-1) + 1;
                }
            }

            {
                if ( PhasePhenoPlante() == PHASEPHENOPLANTE_GERMINATION ){
177
                    // traduit condition TT_A2 = 0
178
                    D_SE = D_SE(-1) + 1;
179
180
                } else {
                    D_SE = D_SE(-1);
181
182
183
184
                }
            }

            {
RemiM's avatar
RemiM committed
185
186
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
187
                    D_EF = D_EF(-1);
188
                } else {
189
                    D_EF = D_EF(-1) + 1;
190
191
192
193
194
                }
            }

            {
                double ddt = 0.0;
RemiM's avatar
RemiM committed
195
                if ( PhasePhenoPlante() != PHASEPHENOPLANTE_GERMINATION ){
196
197
198
199
200
201
202
203
204
205
206
207
208
                    // traduit condition TT_A2 = 0
                    ddt = 0.0;
                } else {
                    ddt = 1;
                }
                D_SE = D_SE(-1) + ddt;
            }

            {
                if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_MATURATION )
                        || ( PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE )
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE ) ){
                    // traduit condition TT_A2 = 0
209
                    SET_MH = SET_MH(-1);
210
                } else {
211
                    SET_MH = SET_MH(-1) + ETRETM();
212
213
214
215
                }
            }

            // calcul de MET_MH
216
217
            MET_MH = SET_MH() / D_MH();
		//MET_MH = 1.0;
218
            {
RemiM's avatar
RemiM committed
219
220
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
221
                    SET_EF = SET_EF(-1);
222
                } else {
223
                    SET_EF = SET_EF(-1) + ETRETM();
224
225
226
227
228
229
230
231
                }
            }

            // calcul de MET_EF
            MET_EF = SET_EF() / D_EF();


            // calcul de NHT28_EF
RemiM's avatar
RemiM committed
232
            {	
233
                if ( Tmoy() <= 28.0 ){
234
                    NHT28_EF = NHT28_EF(-1);
RemiM's avatar
RemiM committed
235
236
                } else if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
237
                    NHT28_EF = NHT28_EF(-1);
238
                } else {
239
                    NHT28_EF = NHT28_EF(-1) + 1;
240
241
242
243
244
245
                }

            }

            // calcul de NHT28
            {
246
                if ( Tmoy() <= 28.0 ){
247
                    NHT28 = NHT28(-1);
248
                } else if ((PhasePhenoPlante() >= PHASEPHENOPLANTE_DESSICATION) || (PhasePhenoPlante() <= PHASEPHENOPLANTE_GERMINATION)) {
249
250
251
		    NHT28 = NHT28(-1);
		}
		 else {
252
                    NHT28 = NHT28(-1) + 1;
RemiM's avatar
RemiM committed
253
		    //std::cout << "temp haute NHT28 \n";
254
255
256
                }

            }
RemiM's avatar
RemiM committed
257

RemiM's avatar
RemiM committed
258
259
260
            // calcul de SGR_FM
            {
                if ( PhasePhenoPlante() != PHASEPHENOPLANTE_FLORAISON){
261
                    SGR_FM = SGR_FM(-1);
RemiM's avatar
RemiM committed
262
                } else {
263
                    SGR_FM = SGR_FM(-1) + RG();
RemiM's avatar
RemiM committed
264
265
266
267
                }

            }

268

269

RemiM's avatar
RemiM committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
	    {
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
                    // traduit condition TT_A2 > date_TT_F1
                    SRR_EF = SRR_EF(-1);
                } else {
                    SRR_EF = SRR_EF(-1) + Pluie();
                }
            }

	    {
                if ( ( PhasePhenoPlante() >= PHASEPHENOPLANTE_MATURATION)
                        && ( PhasePhenoPlante() < PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 > date_TT_F1
                    SRR_FM = SRR_FM(-1);
                } else if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_FLORAISON)
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 < date_TT_E1
                    SRR_FM = SRR_FM(-1);
                } else {
                    SRR_FM = SRR_FM(-1) + Pluie();
                }
            }
	    {
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
                    // traduit condition TT_A2 < date_TT_E1
                    SIR_EF = SIR_EF(-1);
                } else {
                    SIR_EF = SIR_EF(-1) + 0.48*RG()*Ei();
                }
            }
	    {
                if ( ( PhasePhenoPlante() >= PHASEPHENOPLANTE_MATURATION)
                        && ( PhasePhenoPlante() < PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 > date_TT_F1
                    SIR_FM = SIR_FM(-1);
                } else if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_FLORAISON)
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 < date_TT_E1
                    SIR_FM = SIR_FM(-1);
                } else {
                    SIR_FM = SIR_FM(-1) + 0.48*RG()*Ei();
                }
            }
	    {
                if ( ( PhasePhenoPlante() >= PHASEPHENOPLANTE_MATURATION)
                        && ( PhasePhenoPlante() < PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 > date_TT_F1
                    SFHTR_FM = SFHTR_FM(-1);
                } else if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_FLORAISON)
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 < date_TT_E1
                    SFHTR_FM = SFHTR_FM(-1);
                } else {
                    SFHTR_FM = SFHTR_FM(-1) + (1 - FHTR());
                }
            }
	    {
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
                    // traduit condition TT_A2 < date_TT_E1
                    SFHTR_EF = SFHTR_EF(-1);
                } else {
                    SFHTR_EF = SFHTR_EF(-1) + (1 - FHTR());
                }
            }



	    {
                if ( ( PhasePhenoPlante() >= PHASEPHENOPLANTE_MATURATION)
                        && ( PhasePhenoPlante() < PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 > date_TT_F1
                    SHT_FM = SHT_FM(-1);
                } else if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_FLORAISON)
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 < date_TT_E1
                    SHT_FM = SHT_FM(-1);
                } else {
                    SHT_FM = SHT_FM(-1) + (1 - CT_RUE());
                }
            }
            {
                if ( ( PhasePhenoPlante() >= PHASEPHENOPLANTE_DESSICATION)
                        && ( PhasePhenoPlante() < PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 > date_TT_M3
                    SFNRUE_MH = SFNRUE_MH(-1);
                } else if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_MATURATION)
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 < date_TT_M0
                    SFNRUE_MH = SFNRUE_MH(-1);
                } else {
                    SFNRUE_MH = SFNRUE_MH(-1) + (1 - FNIRUE());
                }
            }
366
367
368
369
370
371
372
    }
};

} // namespace sunflo

DECLARE_DYNAMICS(sunflo::Diagnostic);