Diagnostic.cpp 11 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
36
    bool first_compute;

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

37
38
39
40
41
////////////////////////////////////////////////////////////////////////
/////////////////////////////REMI ADDS//////////////////////////////////
////////////////////////////////////////////////////////////////////////

    /*Sync*/ Var PhasePhenoPlante;
RemiM's avatar
RemiM committed
42
    /*Sync*/ Var Tx;
43
////////////////////////////////////////////////////////////////////////
44
////////////////////////////////////////////////////////////////////////
45
46
47
48
49
50
51
52
53
54
55
56
57

    /// # Jours de stress jusqu'a la floraison (estimationTTentreSemisEtLevee_casPhaseSemisLeveeSimulee - F1)
    /// # (pas utilisé dans le modèle, sortie de Diagnostic)
    Var ISH1;

    /// # Jours de stress Autour de la floraison (F1 + 350°Cd)
    /// # (pas utilisé dans le modèle, sortie de Diagnostic)
    Var ISH2;

    /// # Jours de stress après la floraison (F1+350 °Cd – M3)
    /// # (pas utilisé dans le modèle, sortie de Diagnostic)
    Var ISH3;

58
59
60
61
62

////////////////////////////////////////////////////////////////////////
/////////////////////////////REMI ADDS//////////////////////////////////
////////////////////////////////////////////////////////////////////////

RemiM's avatar
RemiM committed
63
64
65
    /// # Variable test.
    Var Foo;

66
67
    /// # Jours entre maturation et récolte.
    Var D_MH;
RemiM's avatar
RemiM committed
68
   /// # Jours entre semis et germination.
69
    Var D_SE;
RemiM's avatar
RemiM committed
70
71
   /// # Jours de phase juvénile et croissance active.
    Var D_EF;
72
73
74
75
76
77
78

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

RemiM's avatar
RemiM committed
82
    /// # Moyenne ETPET durant les jours de phase juvénile et croissance active.
83
84
85
86
    Var MET_EF;

    // Thermal stress entre germinatioan et initiation florale.
    Var NHT28_EF;
RemiM's avatar
RemiM committed
87
 
RemiM's avatar
RemiM committed
88
    // Thermal stress during whole season
89
    Var NHT28;
RemiM's avatar
RemiM committed
90
/* 
RemiM's avatar
RemiM committed
91
92
93
    // Radiations
    Var RG;
    // Sum of radiations during flowering
RemiM's avatar
RemiM committed
94
    Var SGR_FM;*/
95
96
97
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

98
99
100
101
102
    Diagnostic(const vle::devs::DynamicsInit& model,
            const vle::devs::InitEventList& events) :
                DiscreteTimeDyn(model, events)
    {
        pv.initialiser(events);
103
        pr.initialiser(events);
104
105
106
107
108
109
110
        pp.initialiser(events);

        TT_A2.init(this, "TT_A2", events);
        ETRETM.init(this, "ETRETM", events);
        ISH1.init(this, "ISH1" , events);
        ISH2.init(this, "ISH2" , events);
        ISH3.init(this, "ISH3" , events);
111

112
113
////////////////////////////////////////////////////////////////////////	
/////////////////////////////REMI ADDS//////////////////////////////////
RemiM's avatar
RemiM committed
114
115
	
	Foo.init(this, "Foo", events);
116
117
	D_MH.init(this, "D_MH" , events);
	D_SE.init(this, "D_SE", events);
RemiM's avatar
RemiM committed
118
	D_EF.init(this, "D_EF", events);
119
120
121
122

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

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

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

132
        PhasePhenoPlante.init(this, "PhasePhenoPlante", events);
RemiM's avatar
RemiM committed
133
	Tx.init(this, "Tx", events);
134
135
136
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

137
        first_compute = true;
138
139
140
141
142
143
144
145
146
147
148
    }

    virtual ~Diagnostic() { }

    virtual void compute(const vle::devs::Time& /*time*/ )
    {
        if (first_compute) {
            first_compute = false;
            ISH1 = 0.0; //codeMMpourMemo Initial Value = 0.0
            ISH2 = 0.0; //codeMMpourMemo Initial Value = 0.0
            ISH3 = 0.0; //codeMMpourMemo Initial Value = 0.0
149
150

/////////////////////////////REMI ADDS//////////////////////////////////
RemiM's avatar
RemiM committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
	  {
                double ddt = 0.0;
                if ( ( PhasePhenoPlante() != PHASEPHENOPLANTE_MATURATION )
                        // traduit condition TT_A2 < date_TT_M0
                       // || ( PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE )
                       // || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE )
		   ){
                    ddt = 0.0;
                } else {
                    ddt = 1;
                }
                D_MH = D_MH(-1) + ddt;
            }

            {
                double ddt = 0.0;
                if ( PhasePhenoPlante() == PHASEPHENOPLANTE_GERMINATION ){
                    // traduit condition TT_A2 = 0
                    ddt = 0.0;
                } else {
                    ddt = 1;
                }
                D_SE = D_SE(-1) + ddt;
            }

            {
                double ddt = 0.0;
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
                    ddt = 0.0;
                } else {
                    ddt = 1;
                }
                D_EF = D_EF(-1) + ddt;
            }

187
188
189
190
	    SET_MH = 0.0;
	    MET_MH = 0.0;
	    SET_EF = 0.0;
	    MET_EF = 0.0;
RemiM's avatar
RemiM committed
191
192
193
194
195
	    NHT28 = 0.0;
            NHT28_EF = 0.0;
/* 	    SGR_FM = 0.0;*/
	    Foo = 5.0;

196
////////////////////////////////////////////////////////////////////////
197
198
199
        } else {
            {
                double ddt = 0.0;
200
                if ( ETRETM() > pr.SeuilETRETM ){
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
                    ddt = 0.0;
                } else if ( TT_A2() > pv.date_TT_F1 ){
                    ddt = 0.0;
                } else if ( TT_A2() <= 0.0 ){
                    // traduit condition TT_A2 <= 0
                    ddt = 0.0;
                } else {
                    ddt = 1.0;
                }
                ISH1 = ISH1(-1) + ddt;
            }

            {
                double ddt = 0.0;

216
                if ( ETRETM() > pr.SeuilETRETM ){
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
                    ddt = 0.0;
                } else if ( TT_A2() > (pv.date_TT_F1 + pp.date_TT_F1M0) ){
                    ddt = 0.0;
                } else if ( TT_A2() < pv.date_TT_F1 ){
                    ddt = 0.0;
                } else {
                    ddt = 1.0;
                }
                ISH2 = ISH2(-1) + ddt;
            }


            {
                double ddt = 0.0;

232
                if ( ETRETM() > pr.SeuilETRETM ){
233
234
235
236
237
238
239
240
241
242
                    ddt = 0.0;
                } else if ( TT_A2() > pv.date_TT_M3 ){
                    ddt = 0.0;
                } else if ( TT_A2() < (pv.date_TT_F1 + pp.date_TT_F1M0) ){
                    ddt = 0.0;
                } else {
                    ddt = 1.0;
                }
                ISH3 = ISH3(-1) + ddt;
            }
243
244
245
246

////////////////////////////////////////////////////////////////////////
/////////////////////////////REMI ADDS//////////////////////////////////
////////////////////////////////////////////////////////////////////////
RemiM's avatar
RemiM committed
247
248
249
250
251
		
            {
                Foo = 5.0;
            }
		
252
253
            {
                double ddt = 0.0;
RemiM's avatar
RemiM committed
254
                if ( ( PhasePhenoPlante() != PHASEPHENOPLANTE_MATURATION )
255
                        // traduit condition TT_A2 < date_TT_M0
RemiM's avatar
RemiM committed
256
257
258
                       // || ( PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE )
                       // || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE )
		   ){
259
260
261
262
263
264
265
266
267
                    // traduit condition TT_A2 = 0
                } else {
                    ddt = 1;
                }
                D_MH = D_MH(-1) + ddt;
            }

            {
                double ddt = 0.0;
RemiM's avatar
RemiM committed
268
269
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
270
271
272
                    ddt = 0.0;
                } else {
                    ddt = 1;
RemiM's avatar
RemiM committed
273
std::cout << "Dans EF \n";
274
275
276
277
278
279
                }
                D_EF = D_EF(-1) + ddt;
            }

            {
                double ddt = 0.0;
RemiM's avatar
RemiM committed
280
                if ( PhasePhenoPlante() != PHASEPHENOPLANTE_GERMINATION ){
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
                    // traduit condition TT_A2 = 0
                    ddt = 0.0;
                } else {
                    ddt = 1;
                }
                D_SE = D_SE(-1) + ddt;
            }

            {
                double ddt = 0.0;
                if ( ( PhasePhenoPlante() < PHASEPHENOPLANTE_MATURATION )
                        // traduit condition TT_A2 < date_TT_M0
                        || ( PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE )
                        || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE ) ){
                    // traduit condition TT_A2 = 0
                    ddt = 0.0;
                } else {
                    ddt = ETRETM();
                }
                SET_MH = SET_MH(-1) + ddt;
            }

            // calcul de MET_MH
            MET_MH = SET_MH() / D_MH();

            {
                double ddt = 0.0;
RemiM's avatar
RemiM committed
308
309
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
310
311
312
313
314
315
316
317
318
319
320
321
322
                    // traduit condition TT_A2 = 0
                    ddt = 0.0;
                } else {
                    ddt = ETRETM();
                }
                SET_EF = SET_EF(-1) + ddt;
            }

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


            // calcul de NHT28_EF
RemiM's avatar
RemiM committed
323
            {	
324
                double ddt = 0.0;
RemiM's avatar
RemiM committed
325
                if ( Tx() < 0 ){
326
                    ddt = 0.0;
RemiM's avatar
RemiM committed
327
328
329
330
		std::cout << "Temperature faible \n";
                } else if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
		std::cout << "Pas dans EF \n";
331
332
333
334
335
                    ddt = 0.0;
                } else {
                    ddt = 1.0;
                }

RemiM's avatar
RemiM committed
336
                NHT28_EF = NHT28_EF(-1) + ddt; 
337
338
339
340
341
            }

            // calcul de NHT28
            {
                double ddt = 0.0;
RemiM's avatar
RemiM committed
342
                if ( Tx() < 5.0 ){
343
344
345
346
347
348
349
                    ddt = 0.0;
                } else {
                    ddt = 1.0;
                }

                NHT28 = NHT28(-1) + ddt;
            }
RemiM's avatar
RemiM committed
350
/*
RemiM's avatar
RemiM committed
351
352
353
354
355
356
357
358
359
360
361
362
            // calcul de SGR_FM
            {
                double ddt = 0.0;
                if ( PhasePhenoPlante() != PHASEPHENOPLANTE_FLORAISON){
                    ddt = 0.0;
                } else {
                    ddt = RG();
                }

                SGR_FM = SGR_FM(-1) + ddt;
            }

RemiM's avatar
RemiM committed
363
*/
RemiM's avatar
RemiM committed
364

365
366
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
367
368
369
370
371
372
373
374
        }
    }
};

} // namespace sunflo

DECLARE_DYNAMICS(sunflo::Diagnostic);