File: cs_lagr_deposition_model.c

package info (click to toggle)
code-saturne 4.3.3%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 77,992 kB
  • sloc: ansic: 281,257; f90: 122,305; python: 56,490; makefile: 3,915; xml: 3,285; cpp: 3,183; sh: 1,139; lex: 176; yacc: 101; sed: 16
file content (1224 lines) | stat: -rw-r--r-- 41,310 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
106
107
108
109
110
111
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
/*============================================================================
 * Methods for particle deposition
 *============================================================================*/

/*
  This file is part of Code_Saturne, a general-purpose CFD tool.

  Copyright (C) 1998-2016 EDF S.A.

  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later
  version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
  Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/*----------------------------------------------------------------------------*/

/*============================================================================
 * Functions dealing with particle deposition
 *============================================================================*/

#include "cs_defs.h"
#include "cs_math.h"

/*----------------------------------------------------------------------------
 * Standard C library headers
 *----------------------------------------------------------------------------*/

#include <limits.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <float.h>
#include <assert.h>

/*----------------------------------------------------------------------------
 *  Local headers
 *----------------------------------------------------------------------------*/

#include "bft_printf.h"

#include "cs_physical_constants.h"
#include "cs_prototypes.h"

/*----------------------------------------------------------------------------
 *  Header for the current file
 *----------------------------------------------------------------------------*/

#include "cs_lagr_deposition_model.h"

/*============================================================================
 * Static global variables
 *============================================================================*/

/* Boltzmann constant */
static const double _k_boltz = 1.38e-23;

/*=============================================================================
 * Prototypes for private functions used in a cross-recursive manner (ugly)
 *============================================================================*/

/*-----------------------------------------------------------------------------
 * Management of the diffusion in the internal zone (y^+ < dintrf)
 *
 * parameters:
 *   dx        -->    wall-normal displacement
 *   vvue      <->    wall-normal velocity of the flow seen
 *   vpart     <->    particle wall-normal velocity
 *   marko     <->    state of the jump process
 *   tempf     <--    temperature of the fluid
 *   dtl       -->    Lagrangian time step
 *   tstruc    <->    coherent structure mean duration
 *   tdiffu    <->    diffusion phase mean duration
 *   ttotal    <->    tdiffu + tstruc
 *   vstruc    <--    coherent structure velocity
 *   romp      -->    particle density
 *   taup      <->    particle relaxation time
 *   kdif      <->    diffusion phase diffusion coefficient
 *   tlag2     <->    diffusion relaxation timescale
 *   lvisq     <--    wall-unit lengthscale
 *   yplus     <--    wall-normal velocity of the flow seen
 *   unif1     <->    random number (uniform law)
 *   unif2     <->    random number (uniform law)
 *   dintrf    <--    extern-intern interface location
 *   rpart     <--    particle radius
 *   kdifcl    <->    internal zone diffusion coefficient
 *   indint    <->    interface indicator
 *   gnorm     <--    wall-normal gravity component
 *   vnorm     <--    wall-normal fluid (Eulerian) velocity
 *   grpn      <--    wall-normal pressure gradient
 *   piiln     <--    SDE integration auxiliary term
 *----------------------------------------------------------------------------*/

/*=============================================================================
 * Private function definitions
 *============================================================================*/

/*-----------------------------------------------------------------------------
 * Management of the ejection coherent structure (marko = 3)
 *
 * parameters:
 *   marko     -->    state of the jump process
 *   depint    <--    interface location near-wall/core-flow
 *   rpart     <--    particle radius
 *   kdifcl    <--    internal zone diffusion coefficient
 *   dtp       <--    Lagrangian timestep
 *   tstruc    <--    coherent structure mean duration
 *   vstruc    <--    coherent structure velocity
 *   lvisq     <--    wall-unit lengthscale
 *   dx        <->    wall-normal displacement
 *   vpart     <->    particle wall-normal velocity
 *   vvue      <->    wall-normal velocity of the flow seen
 *   taup      <--    particle relaxation time
 *   yplus     <--    particle wall-normal normalized distance
 *   unif1     <--    random number (uniform law)
 *   unif2     <--    random number (uniform law)
 *   dintrf    <--    extern-intern interface location
 *   gnorm     <--    wall-normal gravity component
 *   vnorm     <--    wall-normal fluid (Eulerian) velocity
 *----------------------------------------------------------------------------*/

void
_dep_ejection(cs_lnum_t *marko,
              cs_real_t *depint,
              cs_real_t  dtp,
              cs_real_t *tstruc,
              cs_real_t *vstruc,
              cs_real_t *lvisq,
              cs_real_t *dx,
              cs_real_t *vvue,
              cs_real_t *vpart,
              cs_real_t *taup,
              cs_real_t *yplus,
              cs_real_t *unif1,
              cs_real_t *dintrf,
              cs_real_t *gnorm,
              cs_real_t *vnorm)
{
  cs_real_t  vpart0, vvue0, ypaux;

  vvue0  = *vvue;
  vpart0 = *vpart;

  /* Gravity and ormal fluid velocity added   */

  *vvue  =  -*vstruc + *gnorm * *taup + *vnorm;
  *vpart = vpart0 * exp ( -dtp / *taup) + (1 - exp ( -dtp / *taup)) * vvue0;
  *dx    =   vvue0 * dtp
           + vvue0 * *taup * (exp ( -dtp / *taup) - 1)
           + vpart0 * *taup * (1 - exp ( -dtp / *taup));
  ypaux  = *yplus - *dx / *lvisq;

  /* --------------------------------------------------------
   *    Dissociation of cases by the arrival position
   * --------------------------------------------------------*/

  if (ypaux > *depint)
    *marko    =  -2;
  else if (ypaux < *dintrf)
    *marko    = 0;
  else {

    if (*unif1 < (dtp / *tstruc))
      *marko  = 12;
    else
      *marko  = 3;

  }
}

/*-----------------------------------------------------------------------------
 * Management of the sweep coherent structure (marko = 1)
 *
 * parameters:
 *   dx        <->    wall-normal displacement
 *   vvue      <->    wall-normal velocity of the flow seen
 *   vpart     <->    particle wall-normal velocity
 *   marko     -->    state of the jump process
 *   tempf     <--    temperature of the fluid
 *   dtp       <--    Lagrangian time step
 *   tstruc    <--    coherent structure mean duration
 *   tdiffu    <--    diffusion phase mean duration
 *   ttotal    <--    tdiffu + tstruc
 *   vstruc    <--    coherent structure velocity
 *   romp      <--    particle density
 *   taup      <--    particle relaxation time
 *   kdif      <--    diffusion phase diffusion coefficient
 *   tlag2     <--    diffusion relaxation timescale
 *   lvisq     <--    wall-unit lengthscale
 *   yplus     <--    wall-normal velocity of the flow seen
 *   unif1     <--    random number (uniform law)
 *   unif2     <--    random number (uniform law)
 *   dintrf    <--    extern-intern interface location
 *   rpart     <--    particle radius
 *   kdifcl    <--    internal zone diffusion coefficient
 *   gnorm     <--    wall-normal gravity component
 *   vnorm     <--    wall-normal fluid (Eulerian) velocity
 *   grpn      <--    wall-normal pressure gradient
 *   depint    <--    interface location near-wall/core-flow
 *   piiln     <--    SDE integration auxiliary term
 *----------------------------------------------------------------------------*/

void
_dep_sweep(cs_real_t *dx,
           cs_real_t *vvue,
           cs_real_t *vpart,
           cs_lnum_t *marko,
           cs_real_t *tempf,
           cs_real_t *depint,
           cs_real_t  dtp,
           cs_real_t *tstruc,
           cs_real_t *tdiffu,
           cs_real_t *ttotal,
           cs_real_t *vstruc,
           cs_real_t *romp,
           cs_real_t *taup,
           cs_real_t *kdif,
           cs_real_t *tlag2,
           cs_real_t *lvisq,
           cs_real_t *yplus,
           cs_real_t *unif1,
           cs_real_t *unif2,
           cs_real_t *dintrf,
           cs_real_t *rpart,
           cs_real_t *kdifcl,
           cs_real_t *gnorm,
           cs_real_t *vnorm,
           cs_real_t *grpn,
           cs_real_t *piiln)
{
  /* -------------------------------------------------------
   *  Computation phase
   * ------------------------------------------------------- */

  cs_real_t vvue0  = *vvue;
  cs_real_t vpart0 = *vpart;
  *vvue  = *vstruc + *gnorm * *taup + *vnorm;

  /*  Deposition submodel */

  *vpart = vpart0 * exp ( -dtp / *taup) + (1 - exp ( -dtp / *taup)) * vvue0;
  *dx    =   vvue0 * dtp + vvue0 * *taup * (exp ( -dtp / *taup) - 1)
           + vpart0 * *taup * (1 - exp ( -dtp / *taup));
  cs_real_t yplusa = *yplus - *dx / *lvisq;

  /* --------------------------------------------------------
   *    Dissociation of cases by the arrival position
   * --------------------------------------------------------*/

  if (yplusa > *depint)
    *marko    =  -2;

  else if (yplusa < *dintrf) {

    cs_real_t dtp1 = (*dintrf - yplusa) * *lvisq / CS_ABS(*vpart);
    *dx *= (*dintrf - *yplus) / (yplusa - *yplus);
    cs_real_t dxaux     = *dx;
    cs_real_t ypluss    = *yplus;
    *yplus    = *dintrf;
    *vvue     =  -*vstruc + *gnorm * *taup + *vnorm;
    *marko    = 0;
    cs_lnum_t indint    = 1;

    _dep_inner_zone_diffusion(dx,
                              vvue,
                              vpart,
                              marko,
                              tempf,
                              depint,
                              dtp1,
                              tstruc,
                              tdiffu,
                              ttotal,
                              vstruc,
                              romp,
                              taup,
                              kdif,
                              tlag2,
                              yplus,
                              lvisq,
                              unif1,
                              unif2,
                              dintrf,
                              rpart,
                              kdifcl,
                              &indint,
                              gnorm,
                              vnorm,
                              grpn,
                              piiln);

    indint  = 0;
    *dx    += dxaux;
    yplusa  = ypluss - *dx / *lvisq;

    if (yplusa > *dintrf) {

      *marko  = 3;
      *vvue   =  -*vstruc + *gnorm * *taup + *vnorm;
      _dep_ejection(marko,
                    depint,
                    dtp1,
                    tstruc,
                    vstruc,
                    lvisq,
                    dx,
                    vvue,
                    vpart,
                    taup,
                    yplus,
                    unif1,
                    dintrf,
                    gnorm,
                    vnorm);

      *dx     = *dx + dxaux;

    }

  }
  else {

    if (*unif1 < (dtp / *tstruc))
      *marko  = 12;
    else
      *marko  = 1;

  }
}

/*----------------------------------------------------------------------------
 * Management of the diffusion phases (marko = 2)
 *
 * parameters:
 *   dx        -->    wall-normal displacement
 *   vvue      <->    wall-normal velocity of the flow seen
 *   vpart     <->    particle wall-normal velocity
 *   marko     <->    state of the jump process
 *   tempf     <--    temperature of the fluid
 *   depint    <--    interface location near-wall/core-flow
 *   dtl       -->    Lagrangian time step
 *   tstruc    <->    coherent structure mean duration
 *   tdiffu    <->    diffusion phase mean duration
 *   ttotal    <->    tdiffu + tstruc
 *   vstruc    <--    coherent structure velocity
 *   romp      -->    particle density
 *   taup      <->    particle relaxation time
 *   kdif      <->    diffusion phase diffusion coefficient
 *   tlag2     <->    diffusion relaxation timescale
 *   lvisq     <--    wall-unit lengthscale
 *   yplus     <--    wall-normal velocity of the flow seen
 *   unif1     <->    random number (uniform law)
 *   unif2     <->    random number (uniform law)
 *   dintrf    <--    extern-intern interface location
 *   rpart     <--    particle radius
 *   kdifcl    <->    internal zone diffusion coefficient
 *   indint    <->    interface indicator
 *   gnorm     <--    wall-normal gravity component
 *   vnorm     <--    wall-normal fluid (Eulerian) velocity
 *   grpn      <--    wall-normal pressure gradient
 *   piiln     <--    SDE integration auxiliary term
 *----------------------------------------------------------------------------*/

void
_dep_diffusion_phases(cs_real_t *dx,
                      cs_real_t *vvue,
                      cs_real_t *vpart,
                      cs_lnum_t *marko,
                      cs_real_t *tempf,
                      cs_real_t *depint,
                      cs_real_t  dtl,
                      cs_real_t *tstruc,
                      cs_real_t *tdiffu,
                      cs_real_t *ttotal,
                      cs_real_t *vstruc,
                      cs_real_t *romp,
                      cs_real_t *taup,
                      cs_real_t *kdif,
                      cs_real_t *tlag2,
                      cs_real_t *lvisq,
                      cs_real_t *yplus,
                      cs_real_t *unif1,
                      cs_real_t *unif2,
                      cs_real_t *dintrf,
                      cs_real_t *rpart,
                      cs_real_t *kdifcl,
                      cs_lnum_t *indint,
                      cs_real_t *gnorm,
                      cs_real_t *vnorm,
                      cs_real_t *grpn,
                      cs_real_t *piiln)
{
  cs_real_t  tci, force, aux1, aux2, aux3, aux4, aux5, aux6;
  cs_real_t  aux7, aux8, aux9, aux10, aux11, aa, bb, cc, dd, ee, ter1x, ter2x;
  cs_real_t  ter3x, ter4x, ter5x, ter1f, ter2f, ter3f, ter1p, ter2p, ter3p;
  cs_real_t  ter4p, ter5p, gama2, omegam, omega2, p11, p21, p22, p31, p32;
  cs_real_t  p33, grga2, gagam, gaome, yplusa, dxaux, dtp1;

  cs_real_t vagaus[4];
  cs_lnum_t quatre = 4;
  CS_PROCF(normalen,NORMALEN) (&quatre, vagaus);

  cs_real_t vpart0 = *vpart;

  cs_real_t vvue0;
  if (*marko == 12)
    vvue0 = vagaus[3] * sqrt (pow (*kdif, 2) * *tlag2 / 2.0);
  else
    vvue0 = *vvue;

  tci = *piiln * *tlag2 + *vnorm;

  force = (- *grpn / *romp + *gnorm) * *taup;

  /* --> Coefficients and deterministic terms computation
   *     ------------------------------------------------    */

  aux1 = exp ( -dtl / *taup);
  aux2 = exp ( -dtl / *tlag2);
  aux3 = *tlag2 / (*tlag2 - *taup);
  aux4 = *tlag2 / (*tlag2 + *taup);
  aux5 = *tlag2 * (1.0 - aux2);
  aux6 = pow (*kdif, 2) * *tlag2;
  aux7 = *tlag2 - *taup;
  aux8 = pow (*kdif, 2) * pow (aux3, 2);

  /* --> terms for the trajectory   */
  aa     = *taup * (1.0 - aux1);
  bb     = (aux5 - aa) * aux3;
  cc     = dtl - aa - bb;
  ter1x  = aa * vpart0;
  ter2x  = bb * vvue0;
  ter3x  = cc * tci;
  ter4x  = (dtl - aa) * force;

  /* --> vu fluid terms   */
  ter1f  = vvue0 * aux2;
  ter2f  = tci * (1.0 - aux2);

  /* --> particles velocity terms   */
  dd     = aux3 * (aux2 - aux1);
  ee     = 1.0 - aux1;
  ter1p  = vpart0 * aux1;
  ter2p  = vvue0 * dd;
  ter3p  = tci * (ee - dd);
  ter4p  = force * ee;

  /* --> Coefficients computation for the stochastic integrals:
   * --> Integral on the particles position   */
  gama2  = 0.5 * (1.0 - aux2 * aux2);
  omegam = 0.5 * aux4 * (aux5 - aux2 * aa) - 0.5 * aux2 * bb;
  omegam = omegam * sqrt (aux6);
  omega2 =   aux7 * (aux7 * dtl - 2.0 * (*tlag2 * aux5 - *taup * aa))
           + 0.5 * *tlag2 * *tlag2 * aux5 * (1.0 + aux2)
           + 0.5 * *taup * *taup * aa * (1.0 + aux1)
           - 2.0 * aux4 * *tlag2 * *taup * *taup * (1.0 - aux1 * aux2);
  omega2      = aux8 * omega2;

  if (CS_ABS(gama2) > cs_math_epzero) {

    p21  = omegam / sqrt (gama2);
    p22  = omega2 - pow (p21, 2);
    p22  = sqrt (CS_MAX(0.0, p22));

  }
  else {

    p21  = 0.0;
    p22  = 0.0;

  }

  ter5x  = p21 * vagaus[0] + p22 * vagaus[1];

  /* --> vu fluid integral     */
  p11    = sqrt (gama2 * aux6);
  ter3f  = p11 * vagaus[0];

  /* --> particles velocity Integral     */
  aux9   = 0.5 * *tlag2 * (1.0 - aux2 * aux2);
  aux10  = 0.5 * *taup * (1.0 - aux1 * aux1);
  aux11  = *taup * *tlag2 * (1.0 - aux1 * aux2) / (*taup + *tlag2);

  grga2  = (aux9 - 2.0 * aux11 + aux10) * aux8;

  gagam  = (aux9 - aux11) * (aux8 / aux3);

  gaome  = ((*tlag2 - *taup) * (aux5 - aa) - *tlag2 * aux9 - *taup * aux10 + (*tlag2 + *taup) * aux11) * aux8;

  if (p11 > cs_math_epzero)
    p31  = gagam / p11;
  else
    p31  = 0.0;

  if (p22 > cs_math_epzero)
    p32  = (gaome - p31 * p21) / p22;
  else
    p32  = 0.0;

  p33    = grga2 - pow (p31, 2) - pow (p32, 2);
  p33    = sqrt (CS_MAX(0.0, p33));
  ter5p  = p31 * vagaus[0] + p32 * vagaus[1] + p33 * vagaus[2];

  /* ====================================================================
   * 3. Writings finalization
   * ====================================================================*/

  /* --> trajectory  */
  *dx = ter1x + ter2x + ter3x + ter4x + ter5x;

  /* --> vu fluid velocity     */
  *vvue = ter1f + ter2f + ter3f;

  /* --> particles velocity    */
  *vpart = ter1p + ter2p + ter3p + ter4p + ter5p;
  yplusa = *yplus - *dx / *lvisq;

  /* --------------------------------------------------
   *  Dissociation of cases by the arrival position
   * -------------------------------------------------- */

  if (yplusa > *depint)
    *marko    =  -2;
  else if (yplusa < *dintrf) {

    *marko = 0;
    *vvue  = sqrt (pow ((*kdifcl), 2) * *tlag2 / 2.0) * sqrt (2.0 * cs_math_pi) * 0.5;
    *dx   *= (*dintrf - *yplus) / (yplusa - *yplus);
    dxaux  = *dx;
    *vpart = (*yplus - yplusa) * *lvisq / dtl;
    dtp1   = dtl * (*dintrf - yplusa) / (*yplus - yplusa);
    *yplus = *dintrf;
    _dep_inner_zone_diffusion(dx,
                              vvue,
                              vpart,
                              marko,
                              tempf,
                              depint,
                              dtp1,
                              tstruc,
                              tdiffu,
                              ttotal,
                              vstruc,
                              romp,
                              taup,
                              kdif,
                              tlag2,
                              yplus,
                              lvisq,
                              unif1,
                              unif2,
                              dintrf,
                              rpart,
                              kdifcl,
                              indint,
                              gnorm,
                              vnorm,
                              grpn,
                              piiln);

    *dx  = dxaux + *dx;

  }
  else {

    if (*unif1 < (dtl / *tdiffu)) {

      if (*unif2 < 0.5) {

        *marko = 1;
        *vvue  = *vstruc + *gnorm * *taup + *vnorm;

      }
      else {

        *marko = 3;
        *vvue  =  -*vstruc + *gnorm * *taup + *vnorm;

      }
    }
    else
      *marko = 2;

  }
}

/*----------------------------------------------------------------------------
 * Management of the diffusion in the internal zone (y^+ < dintrf)
 *
 * parameters:
 *   dx        -->    wall-normal displacement
 *   vvue      <->    wall-normal velocity of the flow seen
 *   vpart     <->    particle wall-normal velocity
 *   marko     <->    state of the jump process
 *   tempf     <--    temperature of the fluid
 *   dtl       -->    Lagrangian time step
 *   tstruc    <->    coherent structure mean duration
 *   tdiffu    <->    diffusion phase mean duration
 *   ttotal    <->    tdiffu + tstruc
 *   vstruc    <--    coherent structure velocity
 *   romp      -->    particle density
 *   taup      <->    particle relaxation time
 *   kdif      <->    diffusion phase diffusion coefficient
 *   tlag2     <->    diffusion relaxation timescale
 *   lvisq     <--    wall-unit lengthscale
 *   yplus     <--    wall-normal velocity of the flow seen
 *   unif1     <->    random number (uniform law)
 *   unif2     <->    random number (uniform law)
 *   dintrf    <--    extern-intern interface location
 *   rpart     <--    particle radius
 *   kdifcl    <->    internal zone diffusion coefficient
 *   indint    <->    interface indicator
 *   gnorm     <--    wall-normal gravity component
 *   vnorm     <--    wall-normal fluid (Eulerian) velocity
 *   grpn      <--    wall-normal pressure gradient
 *   piiln     <--    SDE integration auxiliary term
 *----------------------------------------------------------------------------*/

void
_dep_inner_zone_diffusion(cs_real_t *dx,
                          cs_real_t *vvue,
                          cs_real_t *vpart,
                          cs_lnum_t *marko,
                          cs_real_t *tempf,
                          cs_real_t *depint,
                          cs_real_t  dtl,
                          cs_real_t *tstruc,
                          cs_real_t *tdiffu,
                          cs_real_t *ttotal,
                          cs_real_t *vstruc,
                          cs_real_t *romp,
                          cs_real_t *taup,
                          cs_real_t *kdif,
                          cs_real_t *tlag2,
                          cs_real_t *yplus,
                          cs_real_t *lvisq,
                          cs_real_t *unif1,
                          cs_real_t *unif2,
                          cs_real_t *dintrf,
                          cs_real_t *rpart,
                          cs_real_t *kdifcl,
                          cs_lnum_t *indint,
                          cs_real_t *gnorm,
                          cs_real_t *vnorm,
                          cs_real_t *grpn,
                          cs_real_t *piiln)
{
  cs_real_t vagaus[3], vagausbr[2];
  cs_lnum_t n = 3;
  CS_PROCF(normalen,NORMALEN) (&n, vagaus);
  n = 2;
  CS_PROCF(normalen,NORMALEN) (&n, vagausbr);

  cs_real_t force  = *gnorm * *taup;
  cs_real_t vvue0  = *vvue;
  cs_real_t vpart0 = *vpart;

  cs_real_t  argt, kaux, tci;
  if (*yplus < 5.0) {

    argt = cs_math_pi * *yplus / 5.0;
    kaux = *kdifcl * 0.5 * (1.0 - cos (argt));
    tci  =  -pow (*tlag2, 2) * 0.5 * pow (*kdifcl, 2) * cs_math_pi * sin (argt)
           * (1.0 - cos (argt)) / (2.0 * 5.0) / *lvisq;

  }
  else {

    kaux      = *kdifcl;
    /* Interpolation of the decreasing normal fluid velocity around zero:     */
    tci  = *vnorm * *yplus / *dintrf;

  }

  /* -----------------------------------------------
   *  Brownian motion
   * -----------------------------------------------    */

  cs_real_t mpart    = 4.0 / 3.0 * cs_math_pi * pow (*rpart, 3) * *romp;
  cs_real_t kdifbr   = sqrt (2.0 * _k_boltz * *tempf / (mpart * *taup));
  cs_real_t kdifbrtp = kdifbr * *taup;

  /* -----------------------------------------------    */

  cs_real_t dtstl  = dtl / *tlag2;
  cs_real_t dtstp  = dtl / *taup;
  cs_real_t tlmtp  = *tlag2 - *taup;
  cs_real_t tlptp  = *tlag2 + *taup;
  cs_real_t tltp   = *tlag2 * *taup;
  cs_real_t tl2    = pow (*tlag2, 2);
  cs_real_t tp2    = pow (*taup, 2);
  cs_real_t thet   = *tlag2 / tlmtp;
  cs_real_t the2   = pow (thet, 2);
  cs_real_t etl    = exp ( -dtstl);
  cs_real_t etp    = exp ( -dtstp);
  cs_real_t l1l    = 1.0 - etl;
  cs_real_t l1p    = 1.0 - etp;
  cs_real_t l2l    = 1.0 - etl * etl;
  cs_real_t l2p    = 1.0 - etp * etp;
  cs_real_t l3     = 1.0 - etl * etp;
  cs_real_t kaux2  = pow (kaux, 2);
  cs_real_t k2the2 = kaux2 * the2;
  cs_real_t aa1    = *taup * l1p;
  cs_real_t bb1    = thet * (*tlag2 * l1l - aa1);
  cs_real_t cc1    = dtl - aa1 - bb1;
  cs_real_t dd1    = thet * (etl - etp);
  cs_real_t ee1    = l1p;

  /* --------------------------------------------------
   * Auxiliary terms for Brownian motion
   * -------------------------------------------------- */

  cs_real_t xiubr  = 0.5 * pow ((kdifbrtp * l1p), 2);
  cs_real_t ucarbr = kdifbrtp * kdifbr * 0.5 * l2p;
  cs_real_t xcarbr = pow (kdifbrtp, 2) * (dtl - l1p * (2.0 + l1p) * 0.5 * *taup);
  cs_real_t ubr    = sqrt (CS_MAX(ucarbr, 0.0));

  /* ---------------------------------------------------
   * Deterministic terms computation
   * ---------------------------------------------------*/

  *vvue  = vvue0 * etl + tci * l1l;
  *vpart = vpart0 * etp + dd1 * vvue0 + tci * (ee1 - dd1) + force * ee1;
  *dx    = aa1 * vpart0 + bb1 * vvue0 + cc1 * tci + (dtl - aa1) * force;

  /* ---------------------------------------------------
   * Correlation matrix
   * ---------------------------------------------------*/

  cs_real_t pgam2  = 0.5 * kaux2 * *tlag2 * l2l;
  cs_real_t ggam2  = the2 * pgam2 + k2the2 * (  l3 * ( -2 * tltp / tlptp)
                                              + l2p * (*taup * 0.5));
  cs_real_t ome2   = k2the2 * ( dtl * pow (tlmtp, 2) + l2l * (tl2 * *tlag2 * 0.5)
                               + l2p * (tp2 * *taup * 0.5)
                               + l1l * ( -2.0 * tl2 * tlmtp)
                               + l1p * (2.0 * tp2 * tlmtp)
                               + l3 * ( -2.0 * (pow (tltp, 2)) / tlptp));

  cs_real_t pgagga = thet * (pgam2 - kaux2 * tltp / tlptp * l3);
  cs_real_t pgaome = thet * *tlag2 * ( -pgam2 + kaux2 * (  l1l * tlmtp
                                                         + l3 * tp2 /  tlptp));
  cs_real_t ggaome = k2the2 * (  tlmtp * ( *tlag2 * l1l + l1p * ( -*taup))
                               + l2l * ( -tl2 * 0.5)
                               + l2p * ( -tp2 * 0.5) + l3 * tltp);

  /* -----------------------------------------------------
   *  Choleski decomposition
   * -----------------------------------------------------*/

  /*  P11 Computation     */
  cs_real_t p11 = sqrt (CS_MAX(0.0, pgam2));
  cs_real_t p21;

  /*  P21 and P22 computations */
  if (CS_ABS(p11) > cs_math_epzero)
    p21  = pgagga / p11;
  else
    p21  = 0.0;

  cs_real_t p22 = sqrt (CS_MAX (0.0, ggam2 - pow (p21, 2)));

  /*  P31, P32 and P33 computations */
  cs_real_t p31;
  if (CS_ABS(p11) > cs_math_epzero) {
    p31  = pgaome / p11;
  }
  else {
    p31  = 0.0;
  }

  cs_real_t p32;
  if (CS_ABS(p22) > cs_math_epzero)
    p32  = (ggaome - p21 * p31) / p22;
  else
    p32  = 0.0;

  cs_real_t p33 = sqrt(CS_MAX(0.0, ome2 - p31*p31 - p32*p32));

  /* ----------------------------------------------------------
   *  Brownian motion term
   * ----------------------------------------------------------*/

  cs_real_t p11br  = ubr;

  cs_real_t p21br;
  if (CS_ABS(p11br) > cs_math_epzero)
    p21br = xiubr / p11br;
  else
    p21br = 0.0;

  cs_real_t p22br  = sqrt (CS_MAX (xcarbr - pow (p21br, 2), 0.0));

  /* ----------------------------------------------------------
   *  The random terms are consequently:
   * ----------------------------------------------------------*/

  cs_real_t terf = p11 * vagaus[0];
  cs_real_t terp = p21 * vagaus[0] + p22 * vagaus[1];
  cs_real_t terx = p31 * vagaus[0] + p32 * vagaus[1] + p33 * vagaus[2];

  /* ----------------------------------------------------------
   *  Brownian motion
   * ----------------------------------------------------------*/

  cs_real_t terpbr = p11br * vagausbr[0];
  cs_real_t terxbr = p21br * vagausbr[0] + p22br * vagausbr[1];

  /* -----------------------------------------------------------
   *  Finalization (First order)
   * ----------------------------------------------------------*/

  *vvue  = *vvue + terf;
  *vpart = *vpart + terp + terpbr;
  *dx    = *dx + terx + terxbr;
  cs_real_t yplusa = *yplus - *dx / *lvisq;

  if ((yplusa * *lvisq) < *rpart) {

    *dx  = *dx + 2 * *rpart;
    return;

  }

  if ((yplusa > *dintrf) && (*indint != 1)) {

    *marko = 2;
    *vvue  =  -sqrt(pow ((*kdifcl * (*ttotal / *tdiffu)), 2) * *tlag2 / 2.0)
             * sqrt (2.0 * cs_math_pi) * 0.5;
    *dx   *= (*dintrf - *yplus) / (yplusa - *yplus);
    *vpart = (*yplus - yplusa) * *lvisq / dtl;
    cs_real_t dxaux  = *dx;
    cs_real_t dtp1   = dtl * (*dintrf - yplusa) / (*yplus - yplusa);
    *yplus = *dintrf;
    _dep_diffusion_phases(dx,
                          vvue,
                          vpart,
                          marko,
                          tempf,
                          depint,
                          dtp1,
                          tstruc,
                          tdiffu,
                          ttotal,
                          vstruc,
                          romp,
                          taup,
                          kdif,
                          tlag2,
                          lvisq,
                          yplus,
                          unif1,
                          unif2,
                          dintrf,
                          rpart,
                          kdifcl,
                          indint,
                          gnorm,
                          vnorm,
                          grpn,
                          piiln);

    *dx  = dxaux + *dx;

  }
  else {

    if (yplusa > 0.0) {

      cs_real_t tcin1;
      cs_real_t kauxn1;

      if (yplusa < 5.0) {

        cs_real_t argtn1  = cs_math_pi * yplusa / 5.0;
        kauxn1  = *kdifcl * 0.5 * (1.0 - cos (argtn1));
        tcin1   =  cs_math_sq(*tlag2) * 0.5 * cs_math_sq(*kdifcl)
                   * cs_math_pi * sin (argtn1) * (1.0 - cos (argtn1))
                   / (2.0 * 5.0) / *lvisq;
      }
      else {
        kauxn1     = *kdifcl;
        tcin1      = 0.0;
      }

      /* ---------------------------------------------------------------
       *   Auxiliary computation
       * ---------------------------------------------------------------*/

      cs_real_t pox1 = l1l / dtstl;
      cs_real_t pox2 = tlptp / dtl * l1p;
      cs_real_t aa2  = -etl + pox1;
      cs_real_t bb2  = 1.0 - pox1;
      cs_real_t c2c  = *tlag2 / tlmtp * (etl - etp);
      cs_real_t a2c  = -etp + pox2 - (1.0 + *tlag2 / dtl) * c2c;
      cs_real_t b2c  = 1.0 - pox2 + (*tlag2 / dtl) * c2c;
      cs_real_t a22  = l2l + l2l / (2 * dtstl) - 1.0;
      cs_real_t b22  = 1.0 - l2l / (2 * dtstl);

      /* ---------------------------------------------------------------
       *   Deterministic terms computation
       * ---------------------------------------------------------------*/

      *vvue   = vvue0 * etl + aa2 * tci + bb2 * tcin1;
      *vpart  = vpart0 * etp + vvue0 * c2c + a2c * tci + b2c * tcin1
                             + force * (1.0 - (etp - 1.0) / ( -dtstp));

      /* -------------------------------------------------
       *  Diffusion coefficient computation
       * --------------------------------------------------*/

      cs_real_t ketoi   = (a22 * kaux + b22 * kauxn1) / l2l;
      cs_real_t ketoi2  = pow (ketoi, 2);

      /* --------------------------------------------------
       *  Correlation matrix computation
       * --------------------------------------------------*/

      pgam2   = 0.5 * ketoi2 * *tlag2 * l2l;
      ggam2   = the2 * (pgam2 + ketoi2 * (l3 * ( -2.0 * tltp / tlptp) + l2p *
                                          *taup * 0.5));
      pgagga  = thet * (pgam2 - ketoi2 * tltp / tlptp * l3);

      /* -----------------------------------------------------
       *  Choleski decomposition
       * -----------------------------------------------------*/

      /*  P11 computation     */
      p11 = sqrt (CS_MAX (0.0, pgam2));

      /*  P21 and P22 computation  */
      if (CS_ABS(p11) > cs_math_epzero)
        p21 = pgagga / p11;
      else
        p21 = 0.0;

      p22 = sqrt (CS_MAX (0.0, ggam2 - pow (p21, 2)));

      /* ----------------------------------------------------------
       *  The random terms are:
       * ----------------------------------------------------------*/

      terf = p11 * vagaus[0];
      terp = p21 * vagaus[0] + p22 * vagaus[1];

      /* -----------------------------------------------------------
       *  Finalization (Second order)
       * -----------------------------------------------------------*/

      *vvue   = *vvue + terf;
      *vpart  = *vpart + terp + terpbr;

    }

  }
}

/*============================================================================
 * Public function prototypes for Fortran API
 *============================================================================*/

/*----------------------------------------------------------------------------
 * Deposition submodel:
 *   1/ Parameter initialization
 *   2/ Call of the different subroutines with respect to the marko indicator
 *
 * parameters:
 *   marko     <->    state of the jump process
 *   tempf     <--    temperature of the fluid
 *   lvisq     <--    wall-unit lenghtscale
 *   tvisq     <--    wall-unit timescale
 *   vpart     <--    particle wall-normal velocity
 *   vvue      <--    wall-normal velocity of the flow seen
 *   dx        <--    wall-normal displacement
 *   diamp     <--    particle diameter
 *   romp      <--    particle density
 *   taup      <--    particle relaxation time
 *   yplus     <--    particle wall-normal normalized distance
 *   dintrf    <--    extern-intern interface location
 *   enertur   <--    turbulent kinetic energy
 *   gnorm     <--    wall-normal gravity component
 *   vnorm     <--    wall-normal fluid (Eulerian) velocity
 *   grpn      <--    wall-normal pressure gradient
 *   piiln     <--    SDE integration auxiliary term
 *   depint    <--    interface location near-wall/core-flow
 *----------------------------------------------------------------------------*/

void
cs_lagr_deposition(cs_real_t  dtp,
                   cs_lnum_t *marko,
                   cs_real_t *tempf,
                   cs_real_t *lvisq,
                   cs_real_t *tvisq,
                   cs_real_t *vpart,
                   cs_real_t *vvue,
                   cs_real_t *dx,
                   cs_real_t *diamp,
                   cs_real_t *romp,
                   cs_real_t *taup,
                   cs_real_t *yplus,
                   cs_real_t *dintrf,
                   cs_real_t *enertur,
                   cs_real_t *gnorm,
                   cs_real_t *vnorm,
                   cs_real_t *grpn,
                   cs_real_t *piiln,
                   cs_real_t *depint)
{
  /* ====================================================================   */
  /* 1. Initializations   */
  /* ====================================================================   */
  /* Ratio between k and v'    */

  cs_real_t rapkvp = 0.39;

  /* The temporal parameters estimated from the DNS computations  */
  /* and written in adimensional form    */

  cs_real_t tlag2  = 3.0 * *tvisq;
  cs_real_t tstruc = 30.0 * *tvisq;
  cs_real_t tdiffu = 10.0 * *tvisq;
  cs_real_t ttotal = tstruc + tdiffu;

  /* The velocity Vstruc is estimated as the square-root of turbulent kinetic
   *  energy times rapkvp, which corresponds roughly to v' in most of the turbulent boundary
   * layer */

  cs_real_t vstruc = sqrt (*enertur * rapkvp);

  /* From Vstruc we estimate the diffusion coefficient Kdif to balance the fluxes.
     * Kdif is roughly equal to sqrt(k/(4*pi)) in the core flow (which is the
     * theoretical value of the standard Langevin model with a C0 = 2.1) such as:
     *    flux_langevin = sig / sqrt(2*pi)  = v' / sqrt(2*pi)
     * and (v') = k * C0 /( 1 + 3*C0/2 ) = approx. k/2 (see Minier & Pozorski, 1999) */

  cs_real_t kdif;

  if (ttotal > (sqrt (cs_math_pi * rapkvp) * tstruc))
    kdif = sqrt (*enertur / tlag2) * (ttotal - sqrt (cs_math_pi * rapkvp) * tstruc) / tdiffu;

  else {

    bft_printf(_("Incorrect parameter values in LAGCLI"));
    cs_exit (1);

  }

  /* Ratios computation of the flux to determine the kdifcl value */

  cs_real_t ectype = sqrt (pow (kdif, 2) * tlag2 / 2.0);
  cs_real_t paux   = sqrt (cs_math_pi / 2.0) * tstruc * vstruc / (ectype * tdiffu);
  paux   = paux / (1.0 + paux);
  cs_real_t kdifcl = kdif * (tdiffu / ttotal);

  cs_lnum_t two = 2;
  cs_real_t unif[2];
  CS_PROCF (zufall,ZUFALL) (&two, unif);

  cs_lnum_t indint = 0;

  /* ====================================================================   */
  /* 2. Treatment of the 'degenerated' cases (marko = 10, 20, 30) */
  /* ====================================================================   */

  cs_real_t unif1;
  if (*marko == 10) {

    *marko    = 0;
    *vvue     = 0.0;

  }
  else if (*marko == 20) {

    cs_lnum_t one = 1;
    CS_PROCF (zufall,ZUFALL) (&one, &unif1);

    if (unif1 < paux)
      *marko  = 1;

    else
      *marko  = 12;

  }
  else if (*marko == 30) {

    cs_lnum_t one = 1;
    CS_PROCF (zufall,ZUFALL) (&one, &unif1);

    if (unif1 < 0.5)
      *marko  = 1;

    else
      *marko  = 3;

  }

  /* ====================================================================
   * 2. Call of different subroutines given the value of marko
   *   marko = 1 --> sweep phase
   *   marko = 2 or 12 --> diffusion phase
   *   marko = 3 --> ejection phase
   *   marko = 0 --> inner-zone diffusion
   * =====================================================================  */

  cs_real_t rpart = *diamp * 0.5;

  if (*marko == 1)
    _dep_sweep(dx,
               vvue,
               vpart,
               marko,
               tempf,
               depint,
               dtp,
               &tstruc,
               &tdiffu,
               &ttotal,
               &vstruc,
               romp,
               taup,
               &kdif,
               &tlag2,
               lvisq,
               yplus,
               &(unif[0]),
               &(unif[1]),
               dintrf,
               &rpart,
               &kdifcl,
               gnorm,
               vnorm,
               grpn,
               piiln);

  else if (*marko == 2 || *marko == 12)
    _dep_diffusion_phases(dx,
                          vvue,
                          vpart,
                          marko,
                          tempf,
                          depint,
                          dtp,
                          &tstruc,
                          &tdiffu,
                          &ttotal,
                          &vstruc,
                          romp,
                          taup,
                          &kdif,
                          &tlag2,
                          lvisq,
                          yplus,
                          &(unif[0]),
                          &(unif[1]),
                          dintrf,
                          &rpart,
                          &kdifcl,
                          &indint,
                          gnorm,
                          vnorm,
                          grpn,
                          piiln);

  else if (*marko == 3)
    _dep_ejection(marko,
                  depint,
                  dtp,
                  &tstruc,
                  &vstruc,
                  lvisq,
                  dx,
                  vvue,
                  vpart,
                  taup,
                  yplus,
                  &(unif[0]),
                  dintrf,
                  gnorm,
                  vnorm);

  else if (*marko == 0)
    _dep_inner_zone_diffusion(dx,
                              vvue,
                              vpart,
                              marko,
                              tempf,
                              depint,
                              dtp,
                              &tstruc,
                              &tdiffu,
                              &ttotal,
                              &vstruc,
                              romp,
                              taup,
                              &kdif,
                              &tlag2,
                              yplus,
                              lvisq,
                              &(unif[0]),
                              &(unif[1]),
                              dintrf,
                              &rpart,
                              &kdifcl,
                              &indint,
                              gnorm,
                              vnorm,
                              grpn,
                              piiln);
}

/*----------------------------------------------------------------------------*/

END_C_DECLS