Diagnostic.cpp 9.44 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;
42

43
44
45
46


// Covariables to compute OC

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

    /// # 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
60
   /// # Somme ETPET durant les jours de phase juvénile et croissance active.
61
62
    Var SET_EF;

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

    // Thermal stress entre germinatioan et initiation florale.
    Var NHT28_EF;
RemiM's avatar
RemiM committed
68
 
RemiM's avatar
RemiM committed
69
    // Thermal stress during whole season
70
    Var NHT28;
RemiM's avatar
RemiM committed
71

RemiM's avatar
RemiM committed
72
73
74
    // Radiations
    Var RG;
    // Sum of radiations during flowering
RemiM's avatar
RemiM committed
75
     Var SGR_FM;
76

77
78
79
80
81
82
83
84
// Covariables to compute HI

// Jours de stress végétatifs (E1 - F1) (covariables statistiques)
    Var NET_EF;
// Jours de stress végétatifs (F1 - M0) (covariables statistiques)
    Var NET_FM;
// Jours de stress végétatifs (M0 - M3) (covariables statistiques)
    Var NET_MH;
85
86
// Somme temps thermique après floraison (M0 - M3) (covariables statistiques)
    Var TT_MH;
87
88


89
90
91
92
93
    Diagnostic(const vle::devs::DynamicsInit& model,
            const vle::devs::InitEventList& events) :
                DiscreteTimeDyn(model, events)
    {
        pv.initialiser(events);
94
        pr.initialiser(events);
95
96
97
98
        pp.initialiser(events);

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

RemiM's avatar
RemiM committed
100
	
101
102
	D_MH.init(this, "D_MH" , events);
	D_SE.init(this, "D_SE", events);
RemiM's avatar
RemiM committed
103
	D_EF.init(this, "D_EF", events);
104
105
106
107

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

RemiM's avatar
RemiM committed
108
109
        SET_EF.init(this, "SET_EF" , events);
        MET_EF.init(this, "MET_EF" , events);
110

RemiM's avatar
RemiM committed
111
112
113
114
115
	NHT28_EF.init(this, "NHT28_EF", events);
	NHT28.init(this, "NHT28", events);
 
	 SGR_FM.init(this, "SGR_FM", events);
	RG.init(this, "RG", events);
RemiM's avatar
RemiM committed
116

117
        PhasePhenoPlante.init(this, "PhasePhenoPlante", events);
RemiM's avatar
RemiM committed
118
	Tmoy.init(this, "Tmoy", events);
119
120
121
122
123

////// Covariables HI
        NET_EF.init(this, "NET_EF" , events);
        NET_FM.init(this, "NET_FM" , events);
        NET_MH.init(this, "NET_MH" , events);
124
        TT_MH.init(this, "TT_MH" , events);
125
126


127

128
129
130
131
132
133
    }

    virtual ~Diagnostic() { }

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

RemiM's avatar
RemiM committed
135

RemiM's avatar
RemiM committed
136
		
137
            {
RemiM's avatar
RemiM committed
138
                if ( ( PhasePhenoPlante() != PHASEPHENOPLANTE_MATURATION )
139
                        // traduit condition TT_A2 < date_TT_M0
RemiM's avatar
RemiM committed
140
141
142
                       // || ( PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE )
                       // || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE )
		   ){
143
144
145
146
147
148
149
150
                    D_MH = D_MH(-1);
                } else {
                    D_MH = D_MH(-1) + 1;
                }
            }

            {
                if ( PhasePhenoPlante() == PHASEPHENOPLANTE_GERMINATION ){
151
                    // traduit condition TT_A2 = 0
152
                    D_SE = D_SE(-1) + 1;
153
154
                } else {
                    D_SE = D_SE(-1);
155
156
157
158
                }
            }

            {
RemiM's avatar
RemiM committed
159
160
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
161
                    D_EF = D_EF(-1);
162
                } else {
163
                    D_EF = D_EF(-1) + 1;
164
165
166
167
168
                }
            }

            {
                double ddt = 0.0;
RemiM's avatar
RemiM committed
169
                if ( PhasePhenoPlante() != PHASEPHENOPLANTE_GERMINATION ){
170
171
172
173
174
175
176
177
178
179
180
181
182
                    // 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
183
                    SET_MH = SET_MH(-1);
184
                } else {
185
                    SET_MH = SET_MH(-1) + ETRETM();
186
187
188
189
                }
            }

            // calcul de MET_MH
190
191
            MET_MH = SET_MH() / D_MH();
		//MET_MH = 1.0;
192
            {
RemiM's avatar
RemiM committed
193
194
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
195
                    SET_EF = SET_EF(-1);
196
                } else {
197
                    SET_EF = SET_EF(-1) + ETRETM();
198
199
200
201
202
203
204
205
                }
            }

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


            // calcul de NHT28_EF
RemiM's avatar
RemiM committed
206
            {	
207
                if ( Tmoy() <= 28.0 ){
208
                    NHT28_EF = NHT28_EF(-1);
RemiM's avatar
RemiM committed
209
210
                } else if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
211
                    NHT28_EF = NHT28_EF(-1);
212
                } else {
213
                    NHT28_EF = NHT28_EF(-1) + 1;
214
215
216
217
218
219
                }

            }

            // calcul de NHT28
            {
220
                if ( Tmoy() <= 28.0 ){
221
                    NHT28 = NHT28(-1);
222
                } else if ((PhasePhenoPlante() >= PHASEPHENOPLANTE_DESSICATION) || (PhasePhenoPlante() <= PHASEPHENOPLANTE_GERMINATION)) {
223
224
225
		    NHT28 = NHT28(-1);
		}
		 else {
226
                    NHT28 = NHT28(-1) + 1;
RemiM's avatar
RemiM committed
227
		    //std::cout << "temp haute NHT28 \n";
228
229
230
                }

            }
RemiM's avatar
RemiM committed
231

RemiM's avatar
RemiM committed
232
233
234
            // calcul de SGR_FM
            {
                if ( PhasePhenoPlante() != PHASEPHENOPLANTE_FLORAISON){
235
                    SGR_FM = SGR_FM(-1);
RemiM's avatar
RemiM committed
236
                } else {
237
                    SGR_FM = SGR_FM(-1) + RG();
RemiM's avatar
RemiM committed
238
239
240
241
                }

            }

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
	    {

                if ( ETRETM() > pr.SeuilETRETM  ){
                    NET_EF = NET_EF(-1);
                } else if ( ( PhasePhenoPlante() >= PHASEPHENOPLANTE_FLORAISON)
                        && ( PhasePhenoPlante() < PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 > date_TT_F1
                    NET_EF = NET_EF(-1);
                } else if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_CROISSANCEACTIVE)
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 < date_TT_E1
                    NET_EF = NET_EF(-1);
                } else {
                    NET_EF = NET_EF(-1) + 1;
                }
            }
RemiM's avatar
RemiM committed
258

259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
            {
                if ( ETRETM() > pr.SeuilETRETM  ){
                    NET_FM = NET_FM(-1);

                } else if ( ( PhasePhenoPlante() >= PHASEPHENOPLANTE_MATURATION)
                        && ( PhasePhenoPlante() < PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 > date_TT_M0
                    NET_FM = NET_FM(-1);
                } else if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_FLORAISON)
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 < date_TT_F1
                    NET_FM = NET_FM(-1);
                } else {
                    NET_FM = NET_FM(-1) + 1; 
                }
            }

            {

                if ( ETRETM() > pr.SeuilETRETM ){
                    NET_MH = NET_MH(-1);

                } else if ( ( PhasePhenoPlante() >= PHASEPHENOPLANTE_DESSICATION)
                        && ( PhasePhenoPlante() < PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 > date_TT_M3
                    NET_MH = NET_MH(-1);
                } else if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_MATURATION)
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 < date_TT_M0
                    NET_MH = NET_MH(-1);
                } else {
                    NET_MH = NET_MH(-1) + 1;
                }
            }
RemiM's avatar
RemiM committed
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
            {

                if ( Tmoy() <= pp.Tbase ){
                    TT_MH = TT_MH(-1);

                } else if ( ( PhasePhenoPlante() >= PHASEPHENOPLANTE_DESSICATION)
                        && ( PhasePhenoPlante() < PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 > date_TT_M3
                    TT_MH = TT_MH(-1);
                } else if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_MATURATION)
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE) ){
                    // traduit condition TT_A2 < date_TT_M0
                    TT_MH = TT_MH(-1);
                } else {
                    TT_MH = TT_MH(-1) + (Tmoy() - pp.Tbase);
                }
            }

312
313
314
315
316
317
318
    }
};

} // namespace sunflo

DECLARE_DYNAMICS(sunflo::Diagnostic);