Diagnostic.cpp 6.77 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 Tmoy;
43

RemiM's avatar
RemiM committed
44
45
46
    /// # Variable test.
    Var Foo;

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
    Diagnostic(const vle::devs::DynamicsInit& model,
            const vle::devs::InitEventList& events) :
                DiscreteTimeDyn(model, events)
    {
        pv.initialiser(events);
84
        pr.initialiser(events);
85
86
87
88
        pp.initialiser(events);

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

90
91
////////////////////////////////////////////////////////////////////////	
/////////////////////////////REMI ADDS//////////////////////////////////
RemiM's avatar
RemiM committed
92
93
	
	Foo.init(this, "Foo", events);
94
95
	D_MH.init(this, "D_MH" , events);
	D_SE.init(this, "D_SE", events);
RemiM's avatar
RemiM committed
96
	D_EF.init(this, "D_EF", events);
97
98
99
100

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

RemiM's avatar
RemiM committed
101
102
        SET_EF.init(this, "SET_EF" , events);
        MET_EF.init(this, "MET_EF" , events);
103

RemiM's avatar
RemiM committed
104
105
106
107
108
	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
109

110
        PhasePhenoPlante.init(this, "PhasePhenoPlante", events);
RemiM's avatar
RemiM committed
111
	Tmoy.init(this, "Tmoy", events);
112
113
114
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

115
        first_compute = true;
116
117
118
119
120
121
    }

    virtual ~Diagnostic() { }

    virtual void compute(const vle::devs::Time& /*time*/ )
    {
122
123
124
125

////////////////////////////////////////////////////////////////////////
/////////////////////////////REMI ADDS//////////////////////////////////
////////////////////////////////////////////////////////////////////////
RemiM's avatar
RemiM committed
126
127
128
129
130
		
            {
                Foo = 5.0;
            }
		
131
            {
RemiM's avatar
RemiM committed
132
                if ( ( PhasePhenoPlante() != PHASEPHENOPLANTE_MATURATION )
133
                        // traduit condition TT_A2 < date_TT_M0
RemiM's avatar
RemiM committed
134
135
136
                       // || ( PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE )
                       // || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE )
		   ){
137
138
139
140
141
142
143
144
                    D_MH = D_MH(-1);
                } else {
                    D_MH = D_MH(-1) + 1;
                }
            }

            {
                if ( PhasePhenoPlante() == PHASEPHENOPLANTE_GERMINATION ){
145
                    // traduit condition TT_A2 = 0
146
                    D_SE = D_SE(-1) + 1;
147
148
                } else {
                    D_SE = D_SE(-1);
149
150
151
152
                }
            }

            {
RemiM's avatar
RemiM committed
153
154
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
155
                    D_EF = D_EF(-1);
156
                } else {
157
                    D_EF = D_EF(-1) + 1;
158
159
160
161
162
                }
            }

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

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

            {
RemiM's avatar
RemiM committed
187
188
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
189
                    SET_EF = SET_EF(-1);
190
                } else {
191
                    SET_EF = SET_EF(-1) + ETRETM();
192
193
194
195
196
197
198
199
                }
            }

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


            // calcul de NHT28_EF
RemiM's avatar
RemiM committed
200
            {	
RemiM's avatar
RemiM committed
201
                if ( Tmoy() < 28.0 ){
202
                    NHT28_EF = NHT28_EF(-1);
RemiM's avatar
RemiM committed
203
204
                } else if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
205
                    NHT28_EF = NHT28_EF(-1);
206
                } else {
207
                    NHT28_EF = NHT28_EF(-1) + 1;
208
209
210
211
212
213
                }

            }

            // calcul de NHT28
            {
RemiM's avatar
RemiM committed
214
                if ( Tmoy() < 28.0 ){
215
                    NHT28 = NHT28(-1);
216
                } else {
217
                    NHT28 = NHT28(-1) + 1;
RemiM's avatar
RemiM committed
218
		    //std::cout << "temp haute NHT28 \n";
219
220
221
                }

            }
RemiM's avatar
RemiM committed
222

RemiM's avatar
RemiM committed
223
224
225
            // calcul de SGR_FM
            {
                if ( PhasePhenoPlante() != PHASEPHENOPLANTE_FLORAISON){
226
                    SGR_FM = SGR_FM(-1);
RemiM's avatar
RemiM committed
227
                } else {
228
                    SGR_FM = SGR_FM(-1) + RG();
RemiM's avatar
RemiM committed
229
230
231
232
                }

            }

RemiM's avatar
RemiM committed
233

RemiM's avatar
RemiM committed
234

235
236
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
237
        
238
239
240
241
242
243
244
    }
};

} // namespace sunflo

DECLARE_DYNAMICS(sunflo::Diagnostic);