cas1.edp 8.99 KB
Newer Older
Olivier Bonnefon's avatar
Olivier Bonnefon committed
1
2
3
4
5
6
7
8
9
10
load "iovtk"
load "resizeCSR"
load "BinaryIO";
include "myMacro.edp";
include "defGeomGen.edp"
include "defDofsGen.edp"

include "defTigerVar.edp"
include "defSimuParamsGen.edp";
include "paramsTS.edp";
11
include "buildTobs.edp";
12
13
include "defDataAssimilation.edp";

Olivier Bonnefon's avatar
Olivier Bonnefon committed
14
int numRun=0;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
15
16
17
18
19
int NnumRun=1;
string SAVEDIR="/home/olivierb/aedes/AEDESINTER_AUTOROUTES_ADAPTIV/SAVE/";
string LOADDIR="/home/olivierb/aedes/AEDESINTER_AUTOROUTES_ADAPTIV/SAVE/";
string SRCDIR="./";
/*
Olivier Bonnefon's avatar
Olivier Bonnefon committed
20
21
22
23
24
25
26
if (ARGV.n>2){
  numRun=atoi(ARGV[2]);
  NnumRun=10;
}
if (ARGV.n>3){
  NnumRun=atoi(ARGV[3]);
}
Olivier Bonnefon's avatar
Olivier Bonnefon committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
*/
/*
  u: pop adulte
  w1: oeuf diaposant en début d'hier
  w0: oeuf ayant passe l'hiver
  
  Simulation avec assimilation de 2008 a 1019
  ---------------------------------------------
  * 2008 --> 2009
     T0 = 1 fev 2008
     IC=0
     dc u=0 jusqu'au 1 septembre
     1 septembre assimilation des donnees 2008 avec thetaAssim=1
     Sauvegarde ds SAVE/u2d0_2008_rep_0
     en fin d'annee t= 31 dec : interAnnualStage.edp
     calcul de w0 a partir de w1
     sauvegarde de w1 dans SAVE/w1s2d0_0_2008
     sauvegarde de w0 dans SAVE/w0s2d0_0_2008
  * 2009 --> 2010
     T0 = 1 fev 2008
     u=0 w1=0 ou touche pas a w0
     simulation Sauvegarde ds SAVE/u2d0_2009_rep_0
     sauvegarde de w1 dans SAVE/w1s2d0_0_2009
     sauvegarde de w0 dans SAVE/w0s2d0_0_2009

   ect

   Simulation sans assimilation de FIRSTYEAR a FIRSTYEAR+k
   --------------------------------------------------------
   
   Il s'agit de simuler la periode du 1 fev FIRSTYEAR au 31 dec FIRSTYEAR+(k-1) sans assimilation de donnee.
   Principe: on simule seleument la derinere annee FIRSTYEAR+(k-1) a partir des de la simu FIRSTYEAR+((k-1)-1)

   FIRSTYEAR ds {2009,..,2019}
   k ds {1,..,2020-FIRSTYEAR} (note NBPREDYEAR=k dans le code)
   ie, couple (FIRSTYEAR,k)possible :
     * pour FIRSTYEAR=2019
        (2019,1)
     * pour FIRSTYEAR=2018
        (2018,1), (2018,2)
     *
     *
     * pour FIRSTEYEAR=2009
        (2009,1),(2009,2),...,(2009,11) 

   Sauvegarde des trajectoires des etat de pop
   
   si k=1: ie simulation de l'annee FIRSTYEAR sans assimilation
   ------------------------------------------------------------
     On utilise la simulation de 2008 a 2019 avec assimilation de donnees:
     -> Etat initial a partir des oeufs diaposant de l'annee FIRSTYEAR ayant passe l'hiver,
         c'est a dire w0s2d5_0_$(FIRSTYEAR-1) (ici 0 est le num de repete)
   
   si k>1: ie simulation de l'annee FIRSTYEAR+(k-1) sans assimilation
   ------------------------------------------------------------------
    On utilise la simulation FIRSTYEAR+(k-1):
    -> Etat initial a partir des oeufs diaposant de l'annee FIRSTYEAR+(k-1) ayant passe l'hiver,
       c'est a dire w0s2d4_0_$(k-1)_$FIRSTYEAR (ici 0 est le num de repete)

   pour tout k:
   -> sauvegarde de la population d'adulte au cours de l'annee FIRSTYEAR+(k-1) dans
        u2d5_$k_$FIRSTYEAR_rep_0 (ici 0 est le num de repete) (code: saveState.edp)
   -> sauvegarde de la population d'oeufs diaposant ayant passe l'hiver (code: saveIntraAnnuel.edp)
        de l'annee FIRSTYEAR+k dans w0s2d4_0_$(k)_$FIRSTYEAR (ici 0 est le num de repete)


dans le repertoire POSTSIMU, Puis calcul des Brier Score pour tout les couples (FIRSTYEAR,k) a partir des sauvegarde u2d5_$k_$FIRSTYEAR_rep_0
 */
if (ARGV.n>2){
  FIRSTYEAR=atoi(ARGV[2]);
}
if (ARGV.n>3){
  NBPREDYEAR=atoi(ARGV[3]);
  if (NBPREDYEAR<=0){
    cout<<"usage, Freefem++ cas1.edp FIRSTYEAR>=2008 NBPREDYEAR>=0\n";
    exit(0);
  }
  LASTYEAR=FIRSTYEAR+NBPREDYEAR-1;
}
Olivier Bonnefon's avatar
Olivier Bonnefon committed
106
107
108
int scenarioLow=0;
int scenarioMedian=1;
int scenarioHight=2;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
109
int scenario=scenarioMedian;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
110
int seed = 1234+numRun;
111
int callSolver=1;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
randinit ( seed );
//include "defPluginVaraibleGen.edp"
//real nu=0.0;//1.0;//2D to 1D
//real mu=0.0;//0.5;//1D to 2D /ok
//real alpha1D=0.0;
int freqAff=1000;
real B0=0;
real betamodel=0;
real alphaw0,alphaw1;
//exp(-2*h0/365)=0.8;
//h0=-365*ln(0.8)/2=40.7;
alphaw0=40.7;
alphaw1=1;
//h0 tel que exp(-(2 jour)*h0) = 0.8
//exp(-2*h0/364)=0.8
//h0/364~0.1
//h0=36.4
//real lifeexpectancy=1.0/12.0;

real h0=36.4;
//deathrate=1/lifeexpected
real deathrate=12;
real mupowm1=0;
int freqVtk=100000;
real Tw=1.0;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
137
//real Rstar=0.14*365.0;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
138
139
140
real timeScal=365;
string GDDTHRESHOLD="GDD_269/";
if (scenario==scenarioLow){
Olivier Bonnefon's avatar
Olivier Bonnefon committed
141
  //Rstar=0.12*365;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
142
143
  Tw=2;
  GDDTHRESHOLD="GDD_294/";
Olivier Bonnefon's avatar
Olivier Bonnefon committed
144
145
146
147
148
}
if (scenario==scenarioMedian){
  //Rstar=0.12*365;
  Tw=1;
  GDDTHRESHOLD="GDD_269/";
Olivier Bonnefon's avatar
Olivier Bonnefon committed
149
150
}
if (scenario==scenarioHight){
Olivier Bonnefon's avatar
Olivier Bonnefon committed
151
  //Rstar=0.15*365;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  Tw=0;
  GDDTHRESHOLD="GDD_246/";
}

real K=1.0;
//real Ru2=(Rstar-deathrate)/K;
real maxGt=0.11*365.0;
real Ru2=maxGt + deathrate;
include "defOutputGen.edp";
real[int] u6(6);
//real[int] grad6(6);
include "inputParam.edp";
cout<<"u6="<<u6<<endl;
real dirichlet0=1;
include "defParamsGen.edp";
include "mat1D2Duseful.edp";
include "postTraitementLoad.edp";
//system("export OUTPUTDIR="+OUTPUTDIR+";./outputScript.sh");

real gamma0min=100000;
real gamma0max=-100000;
real gamma1min=100000;
real gamma1max=-100000;
real w0min=100000;
real w0max=-100000;
real w1min=100000;
real w1max=-100000;

real RRmin=100000;
real RRmax=-100000;

macro  printInfoYear(XX){
        XX<<"simulation year "<<CURYEAR<<" ended"<<endl;
        XX<<"uminDensity="<<uminDensity<<endl;
        XX<<"umaxDensity="<<umaxDensity<<endl;
        XX<<"w0min="<<w0min<<endl;
        XX<<"w0max="<<w0max<<endl;
        XX<<"w1min="<<w1min<<endl;
        XX<<"w1max="<<w1max<<endl;
        XX<<"gamma0min="<<h0*gamma0min<<endl;
        XX<<"gamma0max="<<h0*gamma0max<<endl;
        XX<<"gamma1min="<<gamma1min<<endl;
        XX<<"gamma1max="<<gamma1max<<endl;
        XX<<"RRmin="<<RRmin<<endl;
        XX<<"RRmax="<<RRmax<<endl;
}//




int nbCallSave;
int numDay=0;
int lastRRPlot=0;
func real J(real[int] & u)
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
{
  real coefLength=969000/12;
  //real coefExpo=2*log(coefLength)/log(10.0);
  D2DXu0=pow(10,u[0])*coefLength*coefLength;
  D2DYu0=D2DXu0;
  D1Du1=pow(10,u[1])*coefLength*coefLength;
  D1Du0=D1Du1;
  real R=pow(10,u[2]);
  muu1=u[3]*u[3];
  nuu1=coefLength*u[4]*u[4];
  dirichlet0=0.1*u[5]*u[5]/coefLength;
  betamodel=coefLength*coefLength;
  RR0=R;RR1=R;RR2=R;RR3=R;RR4=R;RR5=R;RR6=R;RR7=R;RR8=R;RR9=R;RR10=R;RR11=R;RR12=R;RR13=R;RR14=R;
  cout<<"PostTrait u("<<u[0]<<","<<u[1]<<","<<u[2]<<","<<u[3]<<","<<u[4]<<","<<u[5]<<")"<<endl;
  cout<<"PostTrait J("<<D2DXu0<<","<<D2DYu0<<","<<D1Du1<<","<<R<<","<<muu1<<","<<nuu1<<","<<dirichlet0<<")"<<endl;
  include "defVarfGen.edp";
  include "defIC.edp";
  include "defIC1dNull.edp";
  include "defMatGen.edp";
Olivier Bonnefon's avatar
Olivier Bonnefon committed
225

226
  //include "buildMatGenW01.edp";
Olivier Bonnefon's avatar
Olivier Bonnefon committed
227
      
228
  cout<<"end ic\n";
Olivier Bonnefon's avatar
Olivier Bonnefon committed
229
//  ofstream infoFileNull("infosimu.txt");
230
  //nbCallSave=0;
231
  cout<<"begin loop\n";
Olivier Bonnefon's avatar
Olivier Bonnefon committed
232
233
234
235
236
237
  if (NBPREDYEAR>0)
    CURYEAR=FIRSTYEAR+NBPREDYEAR-1;
  else
    CURYEAR=FIRSTYEAR;
  
  for (CURYEAR=CURYEAR; CURYEAR<=LASTYEAR; CURYEAR++){
238
    nbCallSave=0;
239
240
241
242
    if (CURYEAR>2019){
      real p;
      p=randreal1();
      int rg=p/0.2+1;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
243
      CURYEARRAND=2008+rg;
244
245
      if (CURYEARRAND>2019)
        CURYEARRAND=2019;
246
247
      cout<<"CURYEAR "<<CURYEAR<<" use data "<<CURYEARRAND<<endl;
    }
Olivier Bonnefon's avatar
Olivier Bonnefon committed
248
249
//    ofstream infoFile("infosimu.txt",append);
    if (CURYEAR==2008){
250
251
252
253
254
255
256
      //nbSteps=nbSteps2011;
      T0=1-122.0/365.0;
    }else{
      //nbSteps=nbStepsByYear;
      T0=59.0/365.0;
    }
    curT=T0;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
257
        
258
259
260
261
262
263
264
265
266
267
    gamma0min=100000;
    gamma0max=-100000;
    gamma1min=100000;
    gamma1max=-100000;
    w0min=100000;
    w0max=-100000;
    w1min=100000;
    w1max=-100000;
    RRmin=100000;
    RRmax=-100000;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
268
//    if (CURYEAR!=FIRSTYEAR){
269
      include "zeroAdultAndW1.edp";
Olivier Bonnefon's avatar
Olivier Bonnefon committed
270
271
272
273
//    }
   plot(w0s2d0,w0s2d1,w0s2d2,w0s2d3,w0s2d4,w0s2d5,w0s2d6,w0s2d7,w0s2d8,w0s2d9,w0s2d10,w0s2d11,w0s2d12,w0s2d13,w0s2d14,cmm=string(CURYEAR),value=true,fill=true,wait=true);
   if (CURYEAR>=2010)
   plot(u2d0,u2d1,u2d2,u2d3,u2d4,u2d5,u2d6,u2d7,u2d8,u2d9,u2d10,u2d11,u2d12,u2d13,uk2d14,cmm="uk k="+"curT="+string(curT),value=true,fill=true,wait=true);
274
275
    cout<<"doing adaptiv timestepping "<<endl;//with nbSteps="<<nbSteps<<endl;
    include "timeSteppingGenAdaptiv.edp";
Olivier Bonnefon's avatar
Olivier Bonnefon committed
276
//    printInfoYear(infoFile);
277
    printInfoYear(cout);
Olivier Bonnefon's avatar
Olivier Bonnefon committed
278
        
279
280
281
282
283
    /*
      visuScal("2D",Th0,u2d0,10);
      {
      ofstream fileU("fileU");
      //fileU<<pu1d0s1;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
284
      }
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
      {
      ofstream pyFile("vtktopngGen.py");
      int aux=nbSteps/freqVtk;
      pyFile<<"#this file is generated during FF simulation\n"<<endl;
      pyFile<<"nbStep="<<aux<<";\n";
      pyFile<<"step="<<freqVtk<<";\n";
      pyFile<<"firstStep=1;\n";
      pyFile<<"nbOmega="<<Nwires<<";\n";
      pyFile<<"OUTPUTDIR=\""<<OUTPUTDIR<<"\";\n";
      umaxDensity=1.6e-10;
      include "vtktopngGen.edp";
      }*/
    //include "saveStatew1.edp"
    if (CURYEAR!=2019){
      include "interAnnualStage.edp";
Olivier Bonnefon's avatar
Olivier Bonnefon committed
300
    }
301
302
303
304
305
  }
//  include "saveStateSetSize.edp"
    numRun=numRun+1;
  return Tllh;
}
Olivier Bonnefon's avatar
Olivier Bonnefon committed
306
307
308
309
310
311
312
313
314
315

// func real[int] DJ(real[int] &u)
//     { 
//       for (int i=0;i<u.n;i++)
// 	u[i]=(i+1)*u[i]-b[i];
//       return u;  // return of global variable ok 
//     };


real resTllh;
Olivier Bonnefon's avatar
Olivier Bonnefon committed
316
//for (int ii=0; ii<NnumRun;ii++)
Olivier Bonnefon's avatar
Olivier Bonnefon committed
317
318
319
320
       resTllh=J(u6);
//grad6=DJ(u6);
//cout<<"PostTrait "<<grad6(0)<<" "<<grad6(1)<<" "<<grad6(2)<<" "<<grad6(3)<<" "<<grad6(4)<<endl;;
//BFGS(J,DJ,u6,eps=1.e-6,nbiter=500,nbiterline=5);