File: cs_lagr_coupling.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 (505 lines) | stat: -rw-r--r-- 20,478 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
/*============================================================================
 * Methods for particle coupling
 *============================================================================*/

/*
  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 lagrangian coupling
 *============================================================================*/

#include "cs_defs.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 "cs_base.h"
#include "cs_math.h"
#include "cs_prototypes.h"

#include "bft_mem.h"
#include "bft_error.h"

#include "cs_physical_constants.h"

#include "cs_lagr.h"
#include "cs_lagr_particle.h"

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

#include "cs_lagr_coupling.h"

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

BEGIN_C_DECLS

/*! \cond DOXYGEN_SHOULD_SKIP_THIS */

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

/* Constants */

static const cs_real_t  _c_stephan = 5.6703e-8;

/*! (DOXYGEN_SHOULD_SKIP_THIS) \endcond */

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

/* --------------------------------------------------------------------
 *     CALCUL DES TERMES SOURCES DU COUPLAGE RETOUR
 *     Remarque : les termes sources sont calcules pour
 *                la cellule de depart de la particule
 *                lors de l'iteration courante. Attention, meme
 *                si la particule est sortante du domaine de
 *                calcul (peu importe la maniere) on doit calculer
 *                un terme source qui correspond a ce qu'echange le
 *                fluide porteur et la particule au debut du pas de
 *                temps. Si NORDRE = 2 et que la particule est en
 *                interaction avec la frontiere, alors les termes
 *                source sont calcules comme si NORDRE=1
 *                (on oublie le pre-remplissage de TSFEXT dans
 * ONFC                 LAGES2).
 * --------------------------------------------------------------------
 * Arguments
 *
 *   ntersl            <--  nbr termes sources de couplage retour
 *
 *   taup(nbpart)      <--  temps caracteristique dynamique
 *   tsfext(nbpart)    <--  forces externes
 *   tempct            <--  temps caracteristique thermique
 *    (nbpart,2)
 *   cpgd1,cpgd2,      <--  termes de devolatilisation 1 et 2 et
 *    cpght(nbpart)           de combusion heterogene (charbon
 *                            avec couplage retour thermique)
 *   volp(ncelet)      ---  fraction volumique des particules
 *   volm(ncelet)      ---  fraction massique des particules
 * --------------------------------------------------------------------   */

void
cs_lagr_coupling(cs_real_t taup[],
                 cs_real_t tempct[],
                 cs_real_t tsfext[],
                 cs_real_t cpgd1[],
                 cs_real_t cpgd2[],
                 cs_real_t cpght[],
                 cs_real_t volp[],
                 cs_real_t volm[])
{

  /* ====================================================================   */
  /* 1. INITIALISATION    */
  /* ====================================================================   */

  cs_lagr_extra_module_t *extra = cs_glob_lagr_extra_module;
  cs_lagr_source_terms_t *lag_st = cs_glob_lagr_source_terms;

  cs_real_t grav[] = {cs_glob_physical_constants->gx,
                      cs_glob_physical_constants->gy,
                      cs_glob_physical_constants->gz};

  cs_lagr_particle_set_t  *p_set = cs_glob_lagr_particle_set;
  const cs_lagr_attribute_map_t  *p_am = p_set->p_am;

  cs_real_t tvmax = 0.8;

  cs_lnum_t ncelet = cs_glob_mesh->n_cells_with_ghosts;
  cs_lnum_t ncel = cs_glob_mesh->n_cells;
  cs_lnum_t nbpart = p_set->n_particles;

  cs_real_t dtp = cs_glob_lagr_time_step->dtp;

  cs_lnum_t ntersl = cs_glob_lagr_dim->ntersl;

  cs_real_t *tslag, *auxl1, *auxl2, *auxl3;
  BFT_MALLOC (tslag, ncelet * ntersl, cs_real_t);
  BFT_MALLOC (auxl1, nbpart, cs_real_t);
  BFT_MALLOC (auxl2, nbpart, cs_real_t);
  BFT_MALLOC (auxl3, nbpart, cs_real_t);

  /*   Nombre de passage pour les termes sources en stationnaire  */
  if (   cs_glob_lagr_time_scheme->isttio == 1
      && cs_glob_time_step->nt_cur >= cs_glob_lagr_source_terms->nstits)
    lag_st->npts += 1;

  cs_glob_lagr_source_terms->ntxerr = 0;
  cs_glob_lagr_source_terms->vmax = 0.0;
  cs_glob_lagr_source_terms->tmamax = 0.0;

  for (cs_lnum_t iel = 0; iel < ncel; iel++) {

    volp[iel]      = 0.0;
    volm[iel]      = 0.0;

  }

  for (cs_lnum_t ivar = 0; ivar < ntersl; ivar++) {

    for (cs_lnum_t iel = 0; iel < ncel; iel++)
      tslag[ncelet * ivar + iel]  = 0.0;

  }

  /* ====================================================================   */
  /* 2. CALCULS PRELIMINAIRES  */
  /* ====================================================================   */
  /* Finalisation des forces externes (Si la particule a interagit avec     */
  /* une frontiere du domaine de calcul, on degenere a l'ordre 1).     */

  for (cs_lnum_t npt = 0; npt < nbpart; npt++) {

    cs_real_t aux1 = dtp / taup[npt];
    cs_real_t p_mass = cs_lagr_particles_get_real(p_set, npt, CS_LAGR_MASS);

    if (   cs_glob_lagr_time_scheme->t_order == 1
        || cs_lagr_particles_get_lnum_n(p_set, npt, 1, CS_LAGR_SWITCH_ORDER_1) > 0)
      tsfext[npt] = (1.0 - exp(-aux1)) * p_mass * taup[npt];

    else
      tsfext[npt] +=  (1.0 - (1.0 - exp (-aux1)) / aux1) * taup[npt]
                    * p_mass;

  }

  for (cs_lnum_t npt = 0; npt < nbpart; npt++) {

    cs_real_t  p_stat_w = cs_lagr_particles_get_real(p_set, npt, CS_LAGR_STAT_WEIGHT);
    cs_real_t  p_mass   = cs_lagr_particles_get_real(p_set, npt, CS_LAGR_MASS);
    cs_real_t *p_vel    = cs_lagr_particles_attr(p_set, npt, CS_LAGR_VELOCITY);

    cs_real_t  prev_p_mass = cs_lagr_particles_get_real_n(p_set, npt, 1, CS_LAGR_MASS);
    cs_real_t *prev_p_vel  = cs_lagr_particles_attr_n(p_set, npt, 1, CS_LAGR_VELOCITY);

    auxl1[npt] = p_stat_w * (p_mass * p_vel[0] - prev_p_mass * prev_p_vel[0] - grav[0] * tsfext[npt]) / dtp;
    auxl2[npt] = p_stat_w * (p_mass * p_vel[1] - prev_p_mass * prev_p_vel[1] - grav[1] * tsfext[npt]) / dtp;
    auxl3[npt] = p_stat_w * (p_mass * p_vel[2] - prev_p_mass * prev_p_vel[2] - grav[2] * tsfext[npt]) / dtp;

  }

  /* ====================================================================   */
  /* 3. TERMES SOURCES DE QUANTITE DE MOUVEMENT    */
  /* ====================================================================   */

  if (cs_glob_lagr_source_terms->ltsdyn == 1) {

    for (cs_lnum_t npt = 0; npt < nbpart; npt++) {

      unsigned char *particle = p_set->p_buffer + p_am->extents * npt;

      cs_real_t  p_stat_w = cs_lagr_particle_get_real(particle, p_am, CS_LAGR_STAT_WEIGHT);

      cs_real_t  prev_p_diam = cs_lagr_particle_get_real_n(particle, p_am, 1, CS_LAGR_DIAMETER);
      cs_real_t  prev_p_mass = cs_lagr_particle_get_real_n(particle, p_am, 1, CS_LAGR_MASS);
      cs_real_t  p_mass = cs_lagr_particle_get_real(particle, p_am, CS_LAGR_MASS);

      cs_lnum_t iel = cs_lagr_particle_get_cell_id(particle, p_am);

      /* Volume et masse des particules dans la maille */
      volp[iel] += p_stat_w * cs_math_pi * pow(prev_p_diam, 3) / 6.0;
      volm[iel] += p_stat_w * prev_p_mass;

      /* TS de QM   */
      tslag[iel + (lag_st->itsvx-1) * ncelet] += - auxl1[npt];
      tslag[iel + (lag_st->itsvy-1) * ncelet] += - auxl2[npt];
      tslag[iel + (lag_st->itsvz-1) * ncelet] += - auxl3[npt];
      tslag[iel + (lag_st->itsli-1) * ncelet] += - 2.0 * p_stat_w * p_mass / taup[npt];

    }

    /* ====================================================================   */
    /* 4. TERMES SOURCES SUR LA TURBULENCE */
    /* ====================================================================   */

    if (extra->itytur == 2 || extra->iturb == 50 || extra->iturb == 60) {

      /* En v2f (ITURB=50) les TS lagrangiens influent uniquement sur k et eps  */
      /* (difficile d'ecrire quoi que ce soit sur v2, qui perd son sens de */
      /*  "composante de Rij")     */

      for (cs_lnum_t npt = 0; npt < nbpart; npt++) {

        unsigned char *particle = p_set->p_buffer + p_am->extents * npt;

        cs_lnum_t  iel         = cs_lagr_particle_get_cell_id(particle, p_am);
        cs_real_t *prev_f_vel  = cs_lagr_particle_attr_n(particle, p_am, 1, CS_LAGR_VELOCITY_SEEN);
        cs_real_t *f_vel       = cs_lagr_particle_attr(particle, p_am, CS_LAGR_VELOCITY_SEEN);

        cs_real_t uuf = 0.5 * (prev_f_vel[0] + f_vel[0]);
        cs_real_t vvf = 0.5 * (prev_f_vel[1] + f_vel[1]);
        cs_real_t wwf = 0.5 * (prev_f_vel[2] + f_vel[2]);

        tslag[iel + (lag_st->itske-1) * ncelet] += - uuf * auxl1[npt] - vvf * auxl2[npt] - wwf * auxl3[npt];

      }

      for (cs_lnum_t iel = 0; iel < ncel; iel++)
        tslag[iel + (lag_st->itske-1) * ncelet] += - extra->vel->val[iel * 3    ] * tslag[iel + (lag_st->itsvx-1) * ncelet]
                                                   - extra->vel->val[iel * 3 + 1] * tslag[iel + (lag_st->itsvy-1) * ncelet]
                                                   - extra->vel->val[iel * 3 + 2] * tslag[iel + (lag_st->itsvz-1) * ncelet];

    }
    else if (extra->itytur == 3) {

      for (cs_lnum_t npt = 0; npt < nbpart; npt++) {

        unsigned char *particle = p_set->p_buffer + p_am->extents * npt;

        cs_lnum_t  iel         = cs_lagr_particle_get_cell_id(particle, p_am);

        cs_real_t *prev_f_vel  = cs_lagr_particle_attr_n(particle, p_am, 1, CS_LAGR_VELOCITY_SEEN);
        cs_real_t *f_vel       = cs_lagr_particle_attr(particle, p_am, CS_LAGR_VELOCITY_SEEN);

        cs_real_t uuf = 0.5 * (prev_f_vel[0] + f_vel[0]);
        cs_real_t vvf = 0.5 * (prev_f_vel[1] + f_vel[1]);
        cs_real_t wwf = 0.5 * (prev_f_vel[2] + f_vel[2]);

        tslag[iel + (lag_st->itsr11-1) * ncelet] += - 2.0 * uuf * auxl1[npt];
        tslag[iel + (lag_st->itsr12-1) * ncelet] += - uuf * auxl2[npt] - vvf * auxl1[npt];
        tslag[iel + (lag_st->itsr13-1) * ncelet] += - uuf * auxl3[npt] - wwf * auxl1[npt];
        tslag[iel + (lag_st->itsr22-1) * ncelet] += - 2.0 * vvf * auxl2[npt];
        tslag[iel + (lag_st->itsr23-1) * ncelet] += - vvf * auxl3[npt] - wwf * auxl2[npt];
        tslag[iel + (lag_st->itsr33-1) * ncelet] += - 2.0 * wwf * auxl3[npt];

      }
      for (cs_lnum_t iel = 0; iel < ncel; iel++) {

        tslag[iel + (lag_st->itsr11-1) * ncelet] += - 2.0 * extra->vel->val[iel * 3    ] * tslag[iel + (lag_st->itsvx-1) * ncelet];

        tslag[iel + (lag_st->itsr12-1) * ncelet] += -       extra->vel->val[iel * 3    ] * tslag[iel + (lag_st->itsvy-1) * ncelet]
                                                    -       extra->vel->val[iel * 3 + 1] * tslag[iel + (lag_st->itsvx-1) * ncelet];

        tslag[iel + (lag_st->itsr13-1) * ncelet] += -       extra->vel->val[iel * 3    ] * tslag[iel + (lag_st->itsvz-1) * ncelet]
                                                    -       extra->vel->val[iel * 3 + 2] * tslag[iel + (lag_st->itsvx-1) * ncelet];

        tslag[iel + (lag_st->itsr22-1) * ncelet] += - 2.0 * extra->vel->val[iel * 3 + 1] * tslag[iel + (lag_st->itsvy-1) * ncelet];

        tslag[iel + (lag_st->itsr23-1) * ncelet] += -       extra->vel->val[iel * 3 + 1] * tslag[iel + (lag_st->itsvz-1) * ncelet]
                                                    -       extra->vel->val[iel * 3 + 2] * tslag[iel + (lag_st->itsvy-1) * ncelet];

        tslag[iel + (lag_st->itsr33-1) * ncelet] += - 2.0 * extra->vel->val[iel * 3 + 2] * tslag[iel + (lag_st->itsvz-1) * ncelet];

      }

    }

  }

  /* ====================================================================   */
  /* 5. TERME SOURCE MASSIQUES */
  /* ====================================================================   */

  if (    cs_glob_lagr_source_terms->ltsmas == 1
      && (   cs_glob_lagr_specific_physics->impvar == 1
          || cs_glob_lagr_specific_physics->idpvar == 1)) {

    for (cs_lnum_t npt = 0; npt < nbpart; npt++) {

      unsigned char *particle = p_set->p_buffer + p_am->extents * npt;

      cs_real_t  p_stat_w = cs_lagr_particle_get_real(particle, p_am, CS_LAGR_STAT_WEIGHT);
      cs_real_t  prev_p_mass = cs_lagr_particle_get_real_n(particle, p_am, 1, CS_LAGR_MASS);
      cs_real_t  p_mass = cs_lagr_particle_get_real_n(particle, p_am, 0, CS_LAGR_MASS);

      /* Dans saturne TSmasse > 0 ===> Apport de masse sur le fluide  */
      cs_lnum_t iel = cs_lagr_particle_get_cell_id(particle, p_am);

      tslag[iel + (lag_st->itsmas-1) * ncelet] += - p_stat_w * (p_mass - prev_p_mass) / dtp;

    }

  }

  /* ====================================================================   */
  /* 6. TERMES SOURCES THERMIQUE    */
  /* ====================================================================   */

  if (cs_glob_lagr_source_terms->ltsthe == 1) {

    if (   cs_glob_lagr_model->physical_model == 1
        && cs_glob_lagr_specific_physics->itpvar == 1) {

      for (cs_lnum_t npt = 0; npt < nbpart; npt++) {

        unsigned char *particle = p_set->p_buffer + p_am->extents * npt;
        cs_lnum_t iel = cs_lagr_particle_get_cell_id(particle, p_am);
        cs_real_t  p_mass = cs_lagr_particle_get_real_n(particle, p_am, 0, CS_LAGR_MASS);
        cs_real_t  prev_p_mass = cs_lagr_particle_get_real_n(particle, p_am, 1, CS_LAGR_MASS);
        cs_real_t  p_cp = cs_lagr_particle_get_real_n(particle, p_am, 0, CS_LAGR_CP);
        cs_real_t  prev_p_cp = cs_lagr_particle_get_real_n(particle, p_am, 1, CS_LAGR_CP);
        cs_real_t  p_tmp = cs_lagr_particle_get_real_n(particle, p_am, 0, CS_LAGR_TEMPERATURE);
        cs_real_t  prev_p_tmp = cs_lagr_particle_get_real_n(particle, p_am, 1, CS_LAGR_TEMPERATURE);
        cs_real_t  p_stat_w = cs_lagr_particle_get_real(particle, p_am, CS_LAGR_STAT_WEIGHT);

        tslag[iel + (lag_st->itste-1) * ncelet] += - (p_mass * p_tmp * p_cp
                                - prev_p_mass * prev_p_tmp * prev_p_cp) / dtp * p_stat_w;
        tslag[iel + (lag_st->itsti-1) * ncelet] += tempct[nbpart + npt] * p_stat_w;

      }
      if (extra->iirayo > 0) {

        for (cs_lnum_t npt = 0; npt < nbpart; npt++) {

          unsigned char *particle = p_set->p_buffer + p_am->extents * npt;
          cs_lnum_t iel = cs_lagr_particle_get_cell_id(particle, p_am);
          cs_real_t  p_diam = cs_lagr_particle_get_real_n(particle, p_am, 0, CS_LAGR_DIAMETER);
          cs_real_t  p_eps = cs_lagr_particle_get_real_n(particle, p_am, 0, CS_LAGR_EMISSIVITY);
          cs_real_t  p_tmp = cs_lagr_particle_get_real_n(particle, p_am, 0, CS_LAGR_TEMPERATURE);
          cs_real_t  p_stat_w = cs_lagr_particle_get_real(particle, p_am, CS_LAGR_STAT_WEIGHT);

          cs_real_t aux1 = cs_math_pi * p_diam * p_diam * p_eps
                          * (extra->luminance->val[iel] - 4.0 * _c_stephan * pow (p_tmp, 4));

          tslag[iel + (lag_st->itste-1) * ncelet] += aux1 * p_stat_w;

        }

      }

    }
    else if (cs_glob_lagr_model->physical_model == 2) {
      if (cs_glob_lagr_const_dim->nlayer > 1)
        bft_error(__FILE__, __LINE__, 0,
                  _("Couplage thermique non-fonctionnel en multi-layer"));

      else {

        for (cs_lnum_t npt = 0; npt < nbpart; npt++) {

          unsigned char *particle = p_set->p_buffer + p_am->extents * npt;

          cs_lnum_t iel  = cs_lagr_particle_get_cell_id(particle, p_am);
          cs_lnum_t icha = cs_lagr_particle_get_lnum(particle, p_am, CS_LAGR_COAL_NUM);

          cs_real_t  p_mass = cs_lagr_particle_get_real_n(particle, p_am, 0, CS_LAGR_MASS);
          cs_real_t  p_tmp = cs_lagr_particle_get_real(particle, p_am, CS_LAGR_TEMPERATURE);
          cs_real_t  p_cp = cs_lagr_particle_get_real_n(particle, p_am, 0, CS_LAGR_CP);

          cs_real_t  prev_p_mass = cs_lagr_particle_get_real_n(particle, p_am, 1, CS_LAGR_MASS);
          cs_real_t  prev_p_tmp  = cs_lagr_particle_get_real_n(particle, p_am, 1, CS_LAGR_TEMPERATURE);
          cs_real_t  prev_p_cp   = cs_lagr_particle_get_real_n(particle, p_am, 1, CS_LAGR_CP);

          cs_real_t  p_stat_w = cs_lagr_particle_get_real(particle, p_am, CS_LAGR_STAT_WEIGHT);

          tslag[iel + (lag_st->itste-1) * ncelet]  += - (  p_mass * p_tmp * p_cp
                                             - prev_p_mass * prev_p_tmp * prev_p_cp) / dtp * p_stat_w;
          tslag[iel + (lag_st->itsti-1) * ncelet] += tempct[nbpart + npt] * p_stat_w;
          tslag[iel + (lag_st->itsmv1[icha]-1) * ncelet] += p_stat_w * cpgd1[npt];
          tslag[iel + (lag_st->itsmv2[icha]-1) * ncelet] += p_stat_w * cpgd2[npt];
          tslag[iel + (lag_st->itsco-1) * ncelet] += p_stat_w * cpght[npt];
          tslag[iel + (lag_st->itsfp4-1) * ncelet] = 0.0;

        }

      }

    }

  }

  /* ====================================================================   */
  /* 7. Verif que le taux volumique maximal TVMAX admissible de particules  */
  /*    ne soit pas depasse dans quelques cellules.     */
  /* ====================================================================   */

  cs_real_t *st_val = cs_glob_lagr_source_terms->st_val; /* short alias */

  for (cs_lnum_t iel = 0; iel < ncel; iel++) {

    cs_real_t mf =   cs_glob_mesh_quantities->cell_vol[iel]
                   * extra->cromf->val[iel];
    cs_real_t tauv = volp[iel] / cs_glob_mesh_quantities->cell_vol[iel];
    cs_real_t taum = volm[iel] / mf;

    if (tauv > tvmax) {

      cs_glob_lagr_source_terms->ntxerr++;;

      for (int ivar = 0; ivar < ntersl; ivar++) {
        st_val[iel + ivar * ncelet] = 0.0;

      }

    }

    cs_glob_lagr_source_terms->vmax   = CS_MAX(tauv, cs_glob_lagr_source_terms->vmax);
    cs_glob_lagr_source_terms->tmamax = CS_MAX(taum, cs_glob_lagr_source_terms->tmamax);

  }

  /* ====================================================================   */
  /* 8. MOYENNE TEMPORELLE DES TERMES SOURCES */
  /* ====================================================================   */

  if (cs_glob_lagr_time_scheme->isttio == 1 && lag_st->npts > 0) {

    for (int ivar = 0; ivar < ntersl; ivar++) {

      for (cs_lnum_t iel = 0; iel < ncel; iel++)
        st_val[iel + ivar * ncelet]
          =  (  tslag[iel + ncelet * ivar]
              + (lag_st->npts - 1.0) * st_val[iel + ncelet * ivar])
            / lag_st->npts;

    }

  }
  else {

    for (int ivar = 0; ivar < ntersl; ivar++) {

      for (cs_lnum_t iel = 0; iel < ncel; iel++)
        st_val[iel + ncelet * ivar] = tslag[iel + ncelet * ivar];

    }
  }


  BFT_FREE (auxl1);
  BFT_FREE (auxl2);
  BFT_FREE (auxl3);
  BFT_FREE (tslag);
}

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

END_C_DECLS