Diagnostic.cpp 6.66 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
44
45

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

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

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

    // Thermal stress entre germinatioan et initiation florale.
    Var NHT28_EF;
RemiM's avatar
RemiM committed
65
 
RemiM's avatar
RemiM committed
66
    // Thermal stress during whole season
67
    Var NHT28;
RemiM's avatar
RemiM committed
68

RemiM's avatar
RemiM committed
69
70
71
    // Radiations
    Var RG;
    // Sum of radiations during flowering
RemiM's avatar
RemiM committed
72
     Var SGR_FM;
73

74
75
76
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

77
78
79
80
81
    Diagnostic(const vle::devs::DynamicsInit& model,
            const vle::devs::InitEventList& events) :
                DiscreteTimeDyn(model, events)
    {
        pv.initialiser(events);
82
        pr.initialiser(events);
83
84
85
86
        pp.initialiser(events);

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

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

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

RemiM's avatar
RemiM committed
98
99
        SET_EF.init(this, "SET_EF" , events);
        MET_EF.init(this, "MET_EF" , events);
100

RemiM's avatar
RemiM committed
101
102
103
104
105
	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
106

107
        PhasePhenoPlante.init(this, "PhasePhenoPlante", events);
RemiM's avatar
RemiM committed
108
	Tmoy.init(this, "Tmoy", events);
109
110
111
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

112
        first_compute = true;
113
114
115
116
117
118
    }

    virtual ~Diagnostic() { }

    virtual void compute(const vle::devs::Time& /*time*/ )
    {
119
120
121
122

////////////////////////////////////////////////////////////////////////
/////////////////////////////REMI ADDS//////////////////////////////////
////////////////////////////////////////////////////////////////////////
RemiM's avatar
RemiM committed
123

RemiM's avatar
RemiM committed
124
		
125
            {
RemiM's avatar
RemiM committed
126
                if ( ( PhasePhenoPlante() != PHASEPHENOPLANTE_MATURATION )
127
                        // traduit condition TT_A2 < date_TT_M0
RemiM's avatar
RemiM committed
128
129
130
                       // || ( PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE )
                       // || ( PhasePhenoPlante() >= PHASEPHENOPLANTE_RECOLTEE )
		   ){
131
132
133
134
135
136
137
138
                    D_MH = D_MH(-1);
                } else {
                    D_MH = D_MH(-1) + 1;
                }
            }

            {
                if ( PhasePhenoPlante() == PHASEPHENOPLANTE_GERMINATION ){
139
                    // traduit condition TT_A2 = 0
140
                    D_SE = D_SE(-1) + 1;
141
142
                } else {
                    D_SE = D_SE(-1);
143
144
145
146
                }
            }

            {
RemiM's avatar
RemiM committed
147
148
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
149
                    D_EF = D_EF(-1);
150
                } else {
151
                    D_EF = D_EF(-1) + 1;
152
153
154
155
156
                }
            }

            {
                double ddt = 0.0;
RemiM's avatar
RemiM committed
157
                if ( PhasePhenoPlante() != PHASEPHENOPLANTE_GERMINATION ){
158
159
160
161
162
163
164
165
166
167
168
169
170
                    // 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
171
                    SET_MH = SET_MH(-1);
172
                } else {
173
                    SET_MH = SET_MH(-1) + ETRETM();
174
175
176
177
                }
            }

            // calcul de MET_MH
178
179
            //MET_MH = SET_MH() / D_MH();
		MET_MH = 1.0;
180
            {
RemiM's avatar
RemiM committed
181
182
                if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
183
                    SET_EF = SET_EF(-1);
184
                } else {
185
                    SET_EF = SET_EF(-1) + ETRETM();
186
187
188
189
190
191
192
193
                }
            }

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


            // calcul de NHT28_EF
RemiM's avatar
RemiM committed
194
            {	
RemiM's avatar
RemiM committed
195
                if ( Tmoy() < 28.0 ){
196
                    NHT28_EF = NHT28_EF(-1);
RemiM's avatar
RemiM committed
197
198
                } else if ( (PhasePhenoPlante() < PHASEPHENOPLANTE_JUVENILE) 
			|| (PhasePhenoPlante() > PHASEPHENOPLANTE_CROISSANCEACTIVE) ){
199
                    NHT28_EF = NHT28_EF(-1);
200
                } else {
201
                    NHT28_EF = NHT28_EF(-1) + 1;
202
203
204
205
206
207
                }

            }

            // calcul de NHT28
            {
RemiM's avatar
RemiM committed
208
                if ( Tmoy() < 28.0 ){
209
                    NHT28 = NHT28(-1);
210
                } else {
211
                    NHT28 = NHT28(-1) + 1;
RemiM's avatar
RemiM committed
212
		    //std::cout << "temp haute NHT28 \n";
213
214
215
                }

            }
RemiM's avatar
RemiM committed
216

RemiM's avatar
RemiM committed
217
218
219
            // calcul de SGR_FM
            {
                if ( PhasePhenoPlante() != PHASEPHENOPLANTE_FLORAISON){
220
                    SGR_FM = SGR_FM(-1);
RemiM's avatar
RemiM committed
221
                } else {
222
                    SGR_FM = SGR_FM(-1) + RG();
RemiM's avatar
RemiM committed
223
224
225
226
                }

            }

RemiM's avatar
RemiM committed
227

RemiM's avatar
RemiM committed
228

229
230
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
231
        
232
233
234
235
236
237
238
    }
};

} // namespace sunflo

DECLARE_DYNAMICS(sunflo::Diagnostic);