Statistiques
| Révision:

root / UCalcSimulP.pas

Historique | Voir | Annoter | Télécharger (26,807 ko)

1
unit UCalcSimulP;
2

    
3
interface
4

    
5
uses
6
  UVariables;
7

    
8
 // Simul = N? de la simulation (-1 pour profil)
9
 // Profil, SeqAli, Ration = N? d'enregistrement pour comparaison
10
 // Variable = N? de la variable ? moduler
11
 // Variation = Coefficient de variation
12
 // Restrict = Coefficient de restriction
13
 // PResSimulP = Tableau de r?sultats
14
procedure CalcSimulP(Simul, Profil, SeqAli, Ration, Variable: integer;
15
  Variation: double; PResSimulP: PTabResSimulP; AALimit: Boolean = True);
16

    
17
implementation
18

    
19
uses
20
  Math, UFindRec, UCalcul;
21

    
22
procedure CalcSimulP(Simul, Profil, SeqAli, Ration, Variable: integer;
23
  Variation: double; PResSimulP: PTabResSimulP; AALimit: Boolean = True);
24
const
25
  Standing = 4;
26
  PVmr1 = 19.999;
27
  mrPV1 = 8.4 * GEProtJaap;
28
  mrPV2 = 0;
29
var
30
  i, j: integer;
31
  FinSimul, ErrSimul, ok: boolean;
32
  NumRuleSeqAli, NumRuleRation, RuleSeqAliInit, RuleRationInit, Unite: integer;
33
  Age, Ecart, AgeInit, AgeFin, ModeFinSim, Duree: integer;
34
  PDMoy, BGompertz, Entretien, PVmr2, ProtInit, ProtFin, PVFin: double;
35
  PV, p, PD, EnergyPD, l, LD, EnergyLD, PVVafter, PVafter, GMQ, PVV: double;
36
  PctAli1, PctAli2, Cumul, Init, QuantiteAL, Quantite: double;
37
  IngereAL, Ingere, IngereSec, IngSec1, IngSec2, Gaspillage: double;
38
  DEcrois, MEcrois, NEcrois: double;
39
  PDFirstLimit, FHP60, NEmAL, NEm, NEintakeAL: double;
40
  PDAL, px1AL, py1AL, mr, F, a, b, PDmaxE, NEintake, px1, py1, PfreeNE: double;
41
  ExcessProt, ObligUrinELoss, UrinEnergy, MEexcessProt, NEexcessProt: double;
42
  PDfreeNEintake, NEintakeSim, MEintake, PDfreeNEPD, PDfreeNEreq: double;
43
  TabAAdig, TabAAm, TabAAfG, TabPDAA: array[0..12] of double;
44
  TabDEIntake, TabProtFreeNE, TabProtFreeME: array[1..6] of double;
45
  RecCC1, RecCC2: CompositionChimique;
46
  TabAAtotal1, TabAAtotal2, TabCUDAA1, TabCUDAA2: array[0..12] of double;
47
  Gompertz, Pmat: Extended;
48
begin
49
  FinSimul := False;
50
  ErrSimul := False;
51
  // Initialisation du tableau de r?sultat
52
  for i := 1 to NB_COL_PORC do
53
    for j := 1 to MAX_LIG_PORC do
54
      PResSimulP.TabResult[i, j] := 0;
55
  // Initialisation de la simulation
56
  PResSimulP.NbJSim := 0;
57
  NumRuleSeqAli  := 1;
58
  RuleSeqAliInit := 1;
59
  NumRuleRation  := 1;
60
  RuleRationInit := 1;
61
  if Simul = -1 then // Profil
62
  begin
63
    // Initialisation du profil animal
64
    PProfilP := ListProfilP[FindIdxProfilP(FindNomProfilP(Profil))];
65
    // Initialisation de la s?quence alimentaire
66
    //    PSeqAliP := ListSeqAliP[FindIdxSeqAliP(FindNomSeqAliP(PProfilP.SeqAli))];
67
    PSeqAliP := ListSeqAliP[FindIdxSeqAliP(FindNomSeqAliP(SeqAli))];
68
    // Initialisation du plan de rationnement
69
    //    if PProfilP.Ration <> -1
70
    //    then
71
    //      PRationP := ListRationP[FindIdxRationP(FindNomRationP(PProfilP.Ration))];
72
    if Ration <> -1 then // plan de rationnement de la simulation
73
      PRationP := ListRationP[FindIdxRationP(FindNomRationP(Ration))];
74
    // D?but et fin de simulation
75
    Age := PProfilP.AgeInit;
76
    PV := PProfilP.PVInit;
77
    p  := PProfilP.ProtInit;
78
    l  := PProfilP.LipInit;
79
    ModeFinSim := PProfilP.ModeFin;
80
    Duree := PProfilP.Duree;
81
    PVFin := PProfilP.PVFin;
82
  end
83
  else // Simulation
84
  begin
85
    // Initialisation des param?tres de simulation
86
    PSimulP := ListSimulP[FindIdxSimulP(FindNomSimulP(Simul))];
87
    // Initialisation du profil animal
88
    if Profil = -1 then // Profil de la simulation
89
      PProfilP := ListProfilP[FindIdxProfilP(FindNomProfilP(PSimulP.Profil))]
90
    else
91
      PProfilP := ListProfilP[FindIdxProfilP(FindNomProfilP(Profil))];
92
    // Initialisation de la s?quence alimentaire
93
    if SeqAli = -1 then // S?quence alimentaire de la simulation
94
      PSeqAliP := ListSeqAliP[FindIdxSeqAliP(FindNomSeqAliP(PSimulP.SeqAli))]
95
    else
96
      PSeqAliP := ListSeqAliP[FindIdxSeqAliP(FindNomSeqAliP(SeqAli))];
97
    // Initialisation du plan de rationnement
98
    if Ration = -1 then // plan de rationnement de la simulation
99
      PRationP := ListRationP[FindIdxRationP(FindNomRationP(PSimulP.Ration))]
100
    else
101
      PRationP := ListRationP[FindIdxRationP(FindNomRationP(Ration))];
102
    // D?but et fin de simulation
103
    if PSimulP.AgeInitProfil then // Profil
104
      Age := PProfilP.AgeInit
105
    else // Simulation
106
      Age := PSimulP.AgeInit;
107
    if PSimulP.PVInitProfil then // Profil
108
      PV := PProfilP.PVInit
109
    else // Simulation
110
      PV := PSimulP.PVInit;
111
    if PSimulP.ProtLipInitProfil then // Profil
112
      if PSimulP.PVInitProfil then // Valeurs stock?es
113
      begin
114
        p := PProfilP.ProtInit;
115
        l := PProfilP.LipInit;
116
      end
117
      else // Valeurs calcul?es
118
      begin
119
        p := CalcProt(PV);
120
        l := CalcLipProt(PV, p);
121
      end
122
    else // Simulation
123
    begin
124
      p := PSimulP.ProtInit;
125
      l := PSimulP.LipInit;
126
    end;
127
    if PSimulP.FinProfil then // Profil
128
    begin
129
      ModeFinSim := PProfilP.ModeFin;
130
      Duree := PProfilP.Duree;
131
      PVFin := PProfilP.PVFin;
132
    end
133
    else // Simulation
134
    begin
135
      ModeFinSim := PSimulP.ModeFin;
136
      Duree := PSimulP.Duree;
137
      PVFin := PSimulP.PVFin;
138
    end;
139
  end;
140
  AgeInit := Age;
141
  ProtInit := p;
142
  PDMoy := PProfilP.PDMoy;
143
  BGompertz := PProfilP.BGompertz;
144
  Entretien := PProfilP.Entretien;
145
  PVmr2 := PProfilP.PVmr2;
146
  // Sensibilit? (animal)
147
  case Variable of
148
    0: // PD moyen
149
      PDMoy := PDMoy * Variation;
150
    1: // Pr?cocit?
151
      BGompertz := BGompertz * Variation;
152
    2: // Entretien
153
      Entretien := Entretien * Variation;
154
    3: // PV PDMax
155
      PVmr2 := PVmr2 * Variation;
156
    4: // Etat final
157
    begin
158
      Duree := Round(Duree * Variation);
159
      PVFin := PVFin * Variation;
160
    end;
161
  end;
162
  // Poids de prot?ines ? la maturit?
163
  if PProfilP.ModeFin = 0 then // Dur?e
164
  begin
165
    AgeFin  := PProfilP.AgeInit + PProfilP.Duree;
166
    ProtFin := PProfilP.Duree * (PDMoy / 1000) + PProfilP.ProtInit;
167
  end
168
  else // Poids
169
  begin
170
    AgeFin  := Round((CalcProt(PProfilP.PVFin) - PProfilP.ProtInit) / (PDMoy / 1000)) + PProfilP.AgeInit;
171
    ProtFin := (AgeFin - PProfilP.AgeInit) * (PDMoy / 1000) + PProfilP.ProtInit;
172
  end;
173
  Gompertz := Exp(-BGompertz * (AgeFin - PProfilP.AgeInit));
174
  Pmat := ProtFin * Power(ProtFin / PProfilP.ProtInit, Gompertz / (1 - Gompertz));
175
  repeat
176
    Inc(PResSimulP.NbJSim);
177
    PVV := CalcPVV(PV);
178
    PResSimulP.TabResult[1, PResSimulP.NbJSim] := Age;
179
    PResSimulP.TabResult[2, PResSimulP.NbJSim] := PV;
180
    PResSimulP.TabResult[48, PResSimulP.NbJSim] := PVV;
181
    PResSimulP.TabResult[49, PResSimulP.NbJSim] := p;
182
    PResSimulP.TabResult[50, PResSimulP.NbJSim] := l;
183
    PResSimulP.TabResult[70, PResSimulP.NbJSim] := Standing * Entretien;
184

    
185
    PResSimulP.TabResult[85, PResSimulP.NbJSim] := Pmat;
186
    PResSimulP.TabResult[107, PResSimulP.NbJSim] := AgeFin;
187
    PResSimulP.TabResult[108, PResSimulP.NbJSim] := ProtFin;
188
    // Muscle
189
    //    PResSimulP.TabResult[107, PResSimulP.NbJSim] := CalcMuscle(PVV, l);
190
    // TVM
191
    //    PResSimulP.TabResult[108, PResSimulP.NbJSim] := CalcTVM(PVV, l);
192
    /////////////////////////
193
    // Apports journaliers //
194
    /////////////////////////
195
    // Aliment(s) distribu?(s)
196
    repeat
197
      ok := True;
198
      with PSeqAliP.Rule[NumRuleSeqAli] do
199
        case ModeFin of
200
          0: // Dur?e
201
            if PResSimulP.NbJSim - RuleSeqAliInit >= ValFin then
202
              ok := False;
203
          1: // Age
204
            if Age > ValFin then
205
              ok := False;
206
          2: // Poids vif
207
            if PV >= ValFin then
208
              ok := False;
209
          3: // Cumul aliment
210
          begin
211
            Cumul := 0;
212
            for i := RuleSeqAliInit to PResSimulP.NbJSim do
213
              Cumul := Cumul + PResSimulP.TabResult[113, i];
214
            if Cumul >= ValFin then
215
              ok := False;
216
          end;
217
        end;
218
      if not ok then // Changement de r?gle
219
      begin
220
        Inc(NumRuleSeqAli);
221
        RuleSeqAliInit := PResSimulP.NbJSim;
222
      end;
223
    until ok;
224
    with PSeqAliP.Rule[NumRuleSeqAli] do
225
    begin
226
      PResSimulP.TabResult[3, PResSimulP.NbJSim] := NumRuleSeqAli;
227
      PResSimulP.TabResult[4, PResSimulP.NbJSim] := ModeFin;
228
      PResSimulP.TabResult[7, PResSimulP.NbJSim] := NumAli1;
229
      PResSimulP.TabResult[8, PResSimulP.NbJSim] := NumAli2;
230
      // Composition aliment 1
231
      if NumAli1 = -1 then
232
      begin
233
        RecCC1 := CCVide;
234
        for i := 0 to 12 do
235
          TabAAtotal1[i] := 0;
236
        for i := 0 to 12 do
237
          TabCUDAA1[i] := 0;
238
      end
239
      else
240
      begin
241
        PAliment := ListAliment[FindIdxAliment(FindNomAliment(NumAli1))];
242
        RecCC1 := PAliment.CC;
243
        for i := 0 to 12 do
244
          TabAAtotal1[i] := PAliment.AAtotal[i];
245
        for i := 0 to 12 do
246
          TabCUDAA1[i] := PAliment.CUDAA[i];
247
      end;
248
      // Composition aliment 2
249
      if NumAli2 = -1 then
250
      begin
251
        RecCC2 := CCVide;
252
        for i := 0 to 12 do
253
          TabAAtotal2[i] := 0;
254
        for i := 0 to 12 do
255
          TabCUDAA2[i] := 0;
256
      end
257
      else
258
      begin
259
        PAliment := ListAliment[FindIdxAliment(FindNomAliment(NumAli2))];
260
        RecCC2 := PAliment.CC;
261
        for i := 0 to 12 do
262
          TabAAtotal2[i] := PAliment.AAtotal[i];
263
        for i := 0 to 12 do
264
          TabCUDAA2[i] := PAliment.CUDAA[i];
265
      end;
266
      // Calcul des % aliments
267
      if PctAli1Init = PctAli1Fin then
268
        PctAli1 := PctAli1Init
269
      else // Transition
270
      begin
271
        Ecart := PctAli1Fin - PctAli1Init;
272
        case ModeFin of
273
          -1: // Fin de simulation
274
            case ModeFinSim of
275
              0: // Dur?e
276
                PctAli1 := PctAli1Init + (PResSimulP.NbJSim - RuleSeqAliInit) * Ecart / (Duree - 1);
277
              1: // Poids vif
278
              begin
279
                Init := PResSimulP.TabResult[2, RuleSeqAliInit];
280
                PctAli1 := PctAli1Init + (PV - Init) * Ecart / (PVFin - Init);
281
              end;
282
              else
283
                PctAli1 := PctAli1Init;
284
            end;
285
          0: // Dur?e
286
            PctAli1 := PctAli1Init + (PResSimulP.NbJSim - RuleSeqAliInit) * Ecart / (ValFin - 1);
287
          1: // Age
288
          begin
289
            Init := PResSimulP.TabResult[1, RuleSeqAliInit];
290
            PctAli1 := PctAli1Init + (Age - Init) * Ecart / (ValFin - Init);
291
          end;
292
          2: // Poids vif
293
          begin
294
            Init := PResSimulP.TabResult[2, RuleSeqAliInit];
295
            PctAli1 := PctAli1Init + (PV - Init) * Ecart / (ValFin - Init);
296
          end;
297
          else
298
            PctAli1 := PctAli1Init;
299
        end;
300
        if (PctAli1 > 100) then
301
          PctAli1 := 100;
302
        if (PctAli1 < 0) then
303
          PctAli1 := 0;
304
      end;
305
    end;
306
    PResSimulP.TabResult[9, PResSimulP.NbJSim] := PctAli1;
307
    PctAli2 := 100 - PctAli1;
308
    PResSimulP.TabResult[10, PResSimulP.NbJSim] := PctAli2;
309
    // Ing?r? AdLib
310
    with PProfilP^ do
311
    begin
312
      // Calcul des quantit?s
313
      {
314
      case Equation of
315
        0 : // a+b*PV
316
          QuantiteAL := a + b * PV ;
317
        1 : // a*PV^b
318
          QuantiteAL := a * Power (PV, b) ;
319
        2 : // a*(1-exp(-b*PV))
320
          QuantiteAL := a * (1 - Exp (-b * PV)) ;
321
        else
322
          QuantiteAL := 0 ;
323
      end ;
324
      }
325
      QuantiteAL := CalcIngere(Equation, Unite, a, b, PV);
326
      // Convertion de ED, EM, EN en quantit? si besoin
327
      case Unite of
328
        1: // ED (MJ/j)
329
          IngereAL := QuantiteAL / (PctAli1 / 100 *
330
            RecCC1.ED_C * RecCC1.MS / 1000 + PctAli2 / 100 *
331
            RecCC2.ED_C * RecCC2.MS / 1000);
332
        2: // EM (MJ/j)
333
          IngereAL := QuantiteAL / (PctAli1 / 100 *
334
            RecCC1.EM_C * RecCC1.MS / 1000 + PctAli2 / 100 *
335
            RecCC2.EM_C * RecCC2.MS / 1000);
336
        3: // EN (MJ/j)
337
          IngereAL := QuantiteAL / (PctAli1 / 100 *
338
            RecCC1.EN_C * RecCC1.MS / 1000 + PctAli2 / 100 *
339
            RecCC2.EN_C * RecCC2.MS / 1000);
340
        4: // MS (kg/j)
341
          IngereAL := QuantiteAL / (PctAli1 / 100 *
342
            RecCC1.MS / 1000 + PctAli2 / 100 * RecCC2.MS / 1000);
343
        else // Quantit? (kg/j)
344
          IngereAL := QuantiteAL;
345
      end;
346
    end;
347
    PResSimulP.TabResult[78, PResSimulP.NbJSim] := IngereAL;
348
    // Quantit?(s) distribu?e(s)
349
    if (Simul = -1) and (Ration = -1) then // Consommation AdLib
350
      Ingere := IngereAL
351
    else // Plan de rationnement
352
    begin
353
      repeat
354
        ok := True;
355
        with PRationP.Rule[NumRuleRation] do
356
          case ModeFin of
357
            0: // Dur?e
358
              if PResSimulP.NbJSim - RuleRationInit >= ValFin then
359
                ok := False;
360
            1: // Age
361
              if Age > ValFin then
362
                ok := False;
363
            2: // Poids vif
364
              if PV >= ValFin then
365
                ok := False;
366
            3: // Cumul aliment
367
            begin
368
              Cumul := 0;
369
              for i := RuleRationInit to PResSimulP.NbJSim do
370
                Cumul := Cumul + PResSimulP.TabResult[113, i];
371
              if Cumul >= ValFin then
372
                ok := False;
373
            end;
374
            4..8: // Consommation
375
              if PResSimulP.NbJSim > 1 then
376
              begin
377
                i := PResSimulP.NbJSim - 1;
378
                case ModeFin of
379
                  4: // Consommation (aliment)
380
                    if PResSimulP.TabResult[113, i] >= ValFin then
381
                      ok := False;
382
                  5: // Consommation (MS)
383
                    if PResSimulP.TabResult[106, i] * PResSimulP.TabResult[113, i] >=
384
                      ValFin then
385
                      ok := False;
386
                  6: // Consommation (ED)
387
                    if PResSimulP.TabResult[109, i] * PResSimulP.TabResult[113, i] >=
388
                      ValFin then
389
                      ok := False;
390
                  7: // Consommation (EM)
391
                    if PResSimulP.TabResult[89, i] * PResSimulP.TabResult[113, i] >=
392
                      ValFin then
393
                      ok := False;
394
                  8: // Consommation (EN)
395
                    if PResSimulP.TabResult[90, i] * PResSimulP.TabResult[113, i] >=
396
                      ValFin then
397
                      ok := False;
398
                end;
399
              end;
400
          end;
401
        if not ok then // Changement de r?gle
402
        begin
403
          Inc(NumRuleRation);
404
          RuleRationInit := PResSimulP.NbJSim;
405
        end;
406
      until ok;
407
      with PRationP.Rule[NumRuleRation] do
408
      begin
409
        PResSimulP.TabResult[5, PResSimulP.NbJSim] := NumRuleRation;
410
        PResSimulP.TabResult[6, PResSimulP.NbJSim] := ModeFin;
411
        // Calcul des quantit?s
412
        case RuleType of
413
          0: // % Ad libitum
414
            Quantite := QuantiteAL * Percent;
415
          1: // Constant
416
            Quantite := Quantity;
417
          2: // f(dur?e)
418
            case EqDuree of
419
              0: // a+b*jour
420
              begin
421
                Init := PResSimulP.TabResult[1, RuleRationInit];
422
                Quantite := aDuree + bDuree * (Age - Init);
423
              end;
424
              1: // a+b*semaine
425
              begin
426
                Init := PResSimulP.TabResult[1, RuleRationInit];
427
                Quantite := aDuree + bDuree * Trunc((Age - Init) / 7);
428
              end;
429
              else
430
                Quantite := 0;
431
            end;
432
          3: // f(poids vif)
433
            {
434
            case EqPV of
435
              0: // a+b*PV
436
                Quantite := aPV + bPV * PV;
437
              1: // a*PV^b
438
                Quantite := aPV * Power(PV, bPV);
439
              2: // a*(1-exp(-b*PV))
440
                Quantite := aPV * (1 - Exp(-bPV * PV));
441
              else
442
                Quantite := 0;
443
            end;
444
            }
445
            Quantite := CalcIngere(EqPV, Unite, aPV, bPV, PV);
446
          else
447
            Quantite := 0;
448
        end;
449
      end;
450
      // Convertion de ED, EM, EN en quantit? si besoin
451
      if PRationP.Rule[NumRuleRation].RuleType = 0 then
452
        // % AdLib : Unite est d?finie au niveau du profil
453
        Unite := PProfilP.Unite
454
      else
455
        Unite := PRationP.Rule[NumRuleRation].Unite;
456
      case Unite of
457
        1: // ED (MJ/j)
458
          Ingere := Quantite / (PctAli1 / 100 * RecCC1.ED_C *
459
            RecCC1.MS / 1000 + PctAli2 / 100 * RecCC2.ED_C * RecCC2.MS / 1000);
460
        2: // EM (MJ/j)
461
          Ingere := Quantite / (PctAli1 / 100 * RecCC1.EM_C *
462
            RecCC1.MS / 1000 + PctAli2 / 100 * RecCC2.EM_C * RecCC2.MS / 1000);
463
        3: // EN (MJ/j)
464
          Ingere := Quantite / (PctAli1 / 100 * RecCC1.EN_C *
465
            RecCC1.MS / 1000 + PctAli2 / 100 * RecCC2.EN_C * RecCC2.MS / 1000);
466
        4: // MS (kg/j)
467
          Ingere := Quantite / (PctAli1 / 100 * RecCC1.MS /
468
            1000 + PctAli2 / 100 * RecCC2.MS / 1000);
469
        else // Quantit? (kg/j)
470
          Ingere := Quantite;
471
      end;
472
    end;
473
    // Gaspillage
474
    if (Simul = -1) and (Ration = -1) then // Ad libitum : pas de gaspillage
475
      Gaspillage := 0
476
    else
477
      Gaspillage := PRationP.Rule[NumRuleRation].Gaspillage;
478
    // Sensibilit? (aliment)
479
    case Variable of
480
      5: // Quantit? d'aliment
481
        Ingere := Ingere * Variation;
482
      6: // Gaspillage
483
        Gaspillage := Max(Gaspillage + Variation, 0);
484
      7..18: // Acides amin?s
485
      begin
486
        TabAAtotal1[Variable - 6] := TabAAtotal1[Variable - 6] * Variation;
487
        TabAAtotal2[Variable - 6] := TabAAtotal2[Variable - 6] * Variation;
488
        if (Variable = 9) or (Variable = 13) then // met+cys ou phe+tyr
489
        begin
490
          TabAAtotal1[Variable - 7] := TabAAtotal1[Variable - 7] * Variation;
491
          TabAAtotal2[Variable - 7] := TabAAtotal2[Variable - 7] * Variation;
492
        end;
493
      end;
494
    end;
495
    PResSimulP.TabResult[11, PResSimulP.NbJSim] := Ingere;
496
    PResSimulP.TabResult[112, PResSimulP.NbJSim] := Gaspillage;
497
    PResSimulP.TabResult[113, PResSimulP.NbJSim] := Ingere / (1 - Gaspillage);
498
    // Calcul des apports journaliers
499
    IngSec1 := Ingere * PctAli1 / 100 * RecCC1.MS / 1000;
500
    IngSec2 := Ingere * PctAli2 / 100 * RecCC2.MS / 1000;
501
    IngereSec := IngSec1 + IngSec2;
502
    if Ingere <> 0 then
503
      PResSimulP.TabResult[106, PResSimulP.NbJSim] := IngereSec / Ingere;
504
    // Energie brute ing?r?e
505
    PResSimulP.TabResult[12, PResSimulP.NbJSim] :=
506
      IngSec1 * RecCC1.EB + IngSec2 * RecCC2.EB;
507
    // Composants digestibles ing?r?s
508
    TabDEIntake[1] := IngSec1 * RecCC1.MAT * RecCC1.dMAT_C / 100 +
509
      IngSec2 * RecCC2.MAT * RecCC2.dMAT_C / 100;
510
    TabDEIntake[2] := IngSec1 * RecCC1.Lip * RecCC1.dLip_C / 100 +
511
      IngSec2 * RecCC2.Lip * RecCC2.dLip_C / 100;
512
    TabDEIntake[3] := IngSec1 * RecCC1.Amidon + IngSec2 * RecCC2.Amidon;
513
    TabDEIntake[4] := IngSec1 * RecCC1.Sucres + IngSec2 * RecCC2.Sucres;
514
    TabDEIntake[5] := IngSec1 * RecCC1.CB * RecCC1.dCB_C / 100 +
515
      IngSec2 * RecCC2.CB * RecCC2.dCB_C / 100;
516
    TabDEIntake[6] := IngSec1 * RecCC1.Residu * RecCC1.dResidu_C /
517
      100 + IngSec2 * RecCC2.Residu * RecCC2.dResidu_C / 100;
518
    for i := 1 to 6 do
519
      PResSimulP.TabResult[12 + i, PResSimulP.NbJSim] := TabDEIntake[i];
520
    // Acides amin?s totaux ing?r?s
521
    for i := 0 to 12 do
522
      PResSimulP.TabResult[93 + i, PResSimulP.NbJSim] :=
523
        IngSec1 * TabAAtotal1[i] + IngSec2 * TabAAtotal2[i];
524
    // Acides amin?s digestibles ing?r?s
525
    for i := 0 to 12 do
526
      TabAAdig[i] := IngSec1 * TabAAtotal1[i] * TabCUDAA1[i] / 100 +
527
        IngSec2 * TabAAtotal2[i] * TabCUDAA2[i] / 100;
528
    for i := 0 to 12 do
529
      PResSimulP.TabResult[19 + i, PResSimulP.NbJSim] := TabAAdig[i];
530
    ////////////////
531
    // Simulation //
532
    ////////////////
533
    // Calcul de l'ED croissance
534
    if Ingere = 0 then
535
      DEcrois := 0
536
    else
537
      DEcrois := (IngSec1 * RecCC1.ED_C + IngSec2 * RecCC2.ED_C) / Ingere;
538
    PResSimulP.TabResult[109, PResSimulP.NbJSim] := DEcrois;
539
    // Calcul de l'EM croissance
540
    if Ingere = 0 then
541
      MEcrois := 0
542
    else
543
      MEcrois := (IngSec1 * RecCC1.EM_C + IngSec2 * RecCC2.EM_C) / Ingere;
544
    PResSimulP.TabResult[89, PResSimulP.NbJSim] := MEcrois;
545
    // Calcul de l'EN croissance
546
    if Ingere = 0 then
547
      NEcrois := 0
548
    else
549
      NEcrois := (IngSec1 * RecCC1.EN_C + IngSec2 * RecCC2.EN_C) / Ingere;
550
    PResSimulP.TabResult[90, PResSimulP.NbJSim] := NEcrois;
551
    // D?pot de prot?ines et d'acides amin?s
552
    for i := 0 to 12 do
553
    begin
554
      TabAAm[i]  := AAm75[i] * Power(PV, 0.75) + IngereSec * AAendogene[i];
555
      TabAAfG[i] := (TabAAdig[i] - TabAAm[i]) * kAA[i];
556
      TabPDAA[i] := TabAAfG[i] / AAbody[i];
557
      PResSimulP.TabResult[32 + i, PResSimulP.NbJSim] := TabPDAA[i];
558
    end;
559
    // met+cys
560
    PResSimulP.TabResult[45, PResSimulP.NbJSim] :=
561
      (TabAAfG[2] + TabAAfG[3]) / (AAbody[2] + AAbody[3]);
562
    // phe+tyr
563
    PResSimulP.TabResult[46, PResSimulP.NbJSim] :=
564
      (TabAAfG[6] + TabAAfG[7]) / (AAbody[6] + AAbody[7]);
565
    // Premier facteur limitant le d?pot de prot?ines
566
    PDFirstLimit := PResSimulP.TabResult[32, PResSimulP.NbJSim];
567
    for i := 33 to 46 do
568
      if (i <> 35) and (i <> 39) // Ignorer 'cys' et 'tyr'
569
      then
570
        if PResSimulP.TabResult[i, PResSimulP.NbJSim] < PDFirstLimit then
571
          PDFirstLimit := PResSimulP.TabResult[i, PResSimulP.NbJSim];
572
    PResSimulP.TabResult[47, PResSimulP.NbJSim] := PDFirstLimit;
573
    // Besoins en ?nergie nette
574
    // 1) NEmAL
575
    FHP60 := FHPint + FHPpente * IngereAL * 1000 * NEcrois / Power(PV, 0.6);
576
    NEmAL := Entretien * (Standing * NEact60h + kBR * FHP60) * Power(PV, 0.6);
577
    PResSimulP.TabResult[71, PResSimulP.NbJSim] := NEmAL;
578
    // 2) NEm
579
    FHP60 := FHPint + FHPpente * Ingere * 1000 * NEcrois / Power(PV, 0.6);
580
    PResSimulP.TabResult[91, PResSimulP.NbJSim] := FHP60;
581
    NEm := Entretien * (Standing * NEact60h + kBR * FHP60) * Power(PV, 0.6);
582
    PResSimulP.TabResult[72, PResSimulP.NbJSim] := NEm;
583
    // R?partition de l'?nergie
584
    NEintakeAL := 1000 * IngereAL * NEcrois;
585
    PDAL := 1000 * BGompertz * p * Ln(Pmat / p);
586
    px1AL := (NEintakeAL - NEmAL) / NEmAL + 1;
587
    py1AL := PDAL * GEProtJaap;
588
    PResSimulP.TabResult[110, PResSimulP.NbJSim] := px1AL;
589
    PResSimulP.TabResult[111, PResSimulP.NbJSim] := py1AL;
590
    mr := (mrPV1 * PVmr2 - mrPV2 * PVmr1 - PV * mrPV1 + PV * mrPV2) /
591
      (-PVmr1 + PVmr2) * (NEmAL / 1000);
592
    PResSimulP.TabResult[51, PResSimulP.NbJSim] := mr;
593
    F  := 1 / 2 * (mr * power(px1AL, 2) - 2 * px1AL * py1AL - mr) /
594
      (-py1AL + px1AL * mr - mr);
595
    if (F <= 1) or (py1AL / (px1AL - 1) <= mr) then // Minimum (courbure convexe)
596
    begin
597
      F := INFINI;
598
      a := py1AL / (px1AL - 1);
599
      b := 0;
600
    end
601
    else
602
    if mr >= 0 then
603
    begin
604
      a := -(px1AL * mr - mr - 2 * py1AL) / (px1AL - 1);
605
      b := (-py1AL + px1AL * mr - mr) / (power(px1AL, 2) - 2 * px1AL + 1);
606
    end
607
    else
608
    begin
609
      a := 2 * py1AL / (F - 1);
610
      b := -py1AL / power((F - 1), 2);
611
    end;
612
    PResSimulP.TabResult[52, PResSimulP.NbJSim] := F;
613
    PResSimulP.TabResult[74, PResSimulP.NbJSim] := a;
614
    PResSimulP.TabResult[75, PResSimulP.NbJSim] := b;
615
    if px1AL < F then
616
      PDmaxE := a * (F - 1) + b * Power((F - 1), 2)
617
    else
618
      PDmaxE := py1AL;
619
    PResSimulP.TabResult[69, PResSimulP.NbJSim] := PDmaxE;
620
    NEintake := 1000 * Ingere * NEcrois;
621
    px1 := (NEintake - NEm) / NEmAL + 1;
622
    PResSimulP.TabResult[76, PResSimulP.NbJSim] := px1;
623
    if px1 < F then
624
      py1 := a * (px1 - 1) + b * Power(px1 - 1, 2)
625
    else
626
      py1 := PDmaxE;
627
    PResSimulP.TabResult[77, PResSimulP.NbJSim] := py1;
628
    // D?p?t de prot?ines
629
    if AALimit
630
    then
631
      PD := Min(py1 / GEProtJaap, PDFirstLimit)
632
    else
633
      PD := py1 / GEProtJaap;
634
    PResSimulP.TabResult[79, PResSimulP.NbJSim] := PD;
635
    EnergyPD := PD * GEProtJaap;
636
    PResSimulP.TabResult[66, PResSimulP.NbJSim] := EnergyPD;
637
    // Apport en ?nergie
638
    PfreeNE := 0;
639
    for i := 1 to 6 do
640
    begin
641
      TabProtFreeME[i] := TabDEIntake[i] * ValEnergie[i, 4] * ValEnergie[i, 2];
642
      TabProtFreeNE[i] := TabProtFreeME[i] * ValEnergie[i, 5];
643
      PfreeNE := PfreeNE + TabProtFreeNE[i];
644
      PResSimulP.TabResult[i + 52, PResSimulP.NbJSim] := TabProtFreeNE[i];
645
    end;
646
    PResSimulP.TabResult[59, PResSimulP.NbJSim] := PfreeNE;
647
    // Exc?s de prot?ines
648
    ExcessProt  := TabDEIntake[1] - PD;
649
    PResSimulP.TabResult[60, PResSimulP.NbJSim] := ExcessProt;
650
    ObligUrinELoss := 168 * Power(PV, 0.175);
651
    PResSimulP.TabResult[61, PResSimulP.NbJSim] := ObligUrinELoss;
652
    UrinEnergy  := ((ExcessProt / 6.25) * VarUrinELoss) + ObligUrinELoss;
653
    PResSimulP.TabResult[62, PResSimulP.NbJSim] := UrinEnergy;
654
    MEexcessProt := (ExcessProt * GEProtJaap) - UrinEnergy;
655
    PResSimulP.TabResult[63, PResSimulP.NbJSim] := MEexcessProt;
656
    NEexcessProt := MEexcessProt * kProtJaap;
657
    PResSimulP.TabResult[64, PResSimulP.NbJSim] := NEexcessProt;
658
    PDfreeNEintake := PfreeNE + NEexcessProt;
659
    PResSimulP.TabResult[65, PResSimulP.NbJSim] := PDfreeNEintake;
660
    NEintakeSim := EnergyPD + PDfreeNEintake;
661
    PResSimulP.TabResult[67, PResSimulP.NbJSim] := NEintakeSim;
662
    if Ingere <> 0 then
663
      PResSimulP.TabResult[88, PResSimulP.NbJSim] := NEintakeSim / (Ingere * 1000);
664
    MEintake := TabProtFreeME[1] + TabProtFreeME[2] + TabProtFreeME[3] +
665
      TabProtFreeME[4] + TabProtFreeME[5] + TabProtFreeME[6] + MEexcessProt + EnergyPD;
666
    PResSimulP.TabResult[86, PResSimulP.NbJSim] := MEintake;
667
    if Ingere <> 0 then
668
      PResSimulP.TabResult[87, PResSimulP.NbJSim] := MEintake / (Ingere * 1000);
669
    // Besoin en ?nergie pour le d?pot de prot?ines
670
    PDfreeNEPD := PD * GEProtJaap * NEPD;
671
    PResSimulP.TabResult[68, PResSimulP.NbJSim] := PDfreeNEPD;
672
    PDfreeNEreq := PDfreeNEPD + NEm;
673
    PResSimulP.TabResult[73, PResSimulP.NbJSim] := PDfreeNEreq;
674
    PResSimulP.TabResult[92, PResSimulP.NbJSim] := NEintakeSim - NEm;
675
    // D?p?t de lipides
676
    EnergyLD := PDfreeNEintake - PDfreeNEreq;
677
    LD := EnergyLD / ValEnergie[2, 2];
678
    PResSimulP.TabResult[80, PResSimulP.NbJSim] := LD;
679
    // Performances
680
    p  := p + PD / 1000;
681
    PResSimulP.TabResult[81, PResSimulP.NbJSim] := p;
682
    l  := l + LD / 1000;
683
    PResSimulP.TabResult[82, PResSimulP.NbJSim] := l;
684
    if (p > 0) and (l > 0) then
685
      // Calcul du PVV ? partir des poids de prot?ines et lipides
686
      PVVafter := ((Pallom * Power(p * 1000, Ballom)) +
687
        (Lallom * Power(l * 1000, Ballom))) / 1000
688
    else
689
    begin
690
      PVVafter := PVV;
691
      ErrSimul := True;
692
    end;
693
    PVafter := CalcPV(PVVafter);
694
    PResSimulP.TabResult[83, PResSimulP.NbJSim] := PVafter;
695
    GMQ := PVafter - PV;
696
    PResSimulP.TabResult[84, PResSimulP.NbJSim] := GMQ;
697
    //    if GMQ <> 0
698
    //    then
699
    //      PResSimulP.TabResult[85, PResSimulP.NbJSim] := Ingere / GMQ ;
700
    // Test de fin de simulation
701
    if ModeFinSim = 0 then // Dur?e
702
      FinSimul := PResSimulP.NbJSim >= Duree
703
    else // Poids vif
704
      FinSimul := PV >= PVFin;
705
    Inc(Age);
706
    PV := PVafter;
707
  until FinSimul or ErrSimul or (PResSimulP.NbJSim = MAX_LIG_PORC);
708
end;
709

    
710
end.