1 #ifndef __CS_LAGR_PARTICLE_H__
2 #define __CS_LAGR_PARTICLE_H__
3 
4 /*============================================================================
5  * Lagrangian module particle model
6  *============================================================================*/
7 
8 /*
9   This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11   Copyright (C) 1998-2021 EDF S.A.
12 
13   This program is free software; you can redistribute it and/or modify it under
14   the terms of the GNU General Public License as published by the Free Software
15   Foundation; either version 2 of the License, or (at your option) any later
16   version.
17 
18   This program is distributed in the hope that it will be useful, but WITHOUT
19   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21   details.
22 
23   You should have received a copy of the GNU General Public License along with
24   this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25   Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 #include "cs_defs.h"
31 
32 #include "assert.h"
33 
34 /*----------------------------------------------------------------------------*/
35 
36 BEGIN_C_DECLS
37 
38 /*=============================================================================
39  * Macro definitions
40  *============================================================================*/
41 
42 /*=============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
46 /*!
47  * Flags specifying general event attributes
48  */
49 
50 /*! particle will be deleted */
51 #define CS_LAGR_PART_TO_DELETE         (1 << 0)
52 
53 /*! particle is fixed, no resuspension possible */
54 #define CS_LAGR_PART_FIXED             (1 << 1)
55 
56 /*! particle is deposited */
57 #define CS_LAGR_PART_DEPOSITED         (1 << 2)
58 
59 /*! particle is rolling */
60 #define CS_LAGR_PART_ROLLING           (1 << 3)
61 
62 /*! particle motion is prescribed */
63 #define CS_LAGR_PART_IMPOSED_MOTION    (1 << 4)
64 
65 /*! Flag sets (useful for cancelling nay flag of a set) */
66 
67 /*! particle is in flow */
68 #define CS_LAGR_PART_DEPOSITION_FLAGS \
69   (  CS_LAGR_PART_TO_DELETE | CS_LAGR_PART_FIXED | CS_LAGR_PART_DEPOSITED \
70    | CS_LAGR_PART_ROLLING | CS_LAGR_PART_IMPOSED_MOTION)
71 
72 /*============================================================================
73  * Type definitions
74  *============================================================================*/
75 
76 /*! Prefedined particle attributes */
77 /* ------------------------------- */
78 
79 typedef enum {
80 
81   CS_LAGR_P_FLAG,             /*!< local metadata flag */
82 
83   CS_LAGR_CELL_ID,             /*!< local cell id (0 to n-1) */
84   CS_LAGR_RANK_ID,             /*!< local parallel rank id */
85 
86   CS_LAGR_REBOUND_ID,          /*!< number of time steps since rebound, or -1 */
87 
88   CS_LAGR_RANDOM_VALUE,        /*!< associated random value (for sampling) */
89 
90   CS_LAGR_STAT_WEIGHT,         /*!< statistical weight */
91   CS_LAGR_RESIDENCE_TIME,      /*!< time since particle injection */
92   CS_LAGR_MASS,
93   CS_LAGR_DIAMETER,
94   CS_LAGR_TAUP_AUX,
95   CS_LAGR_COORDS,
96   CS_LAGR_VELOCITY,
97   CS_LAGR_VELOCITY_SEEN,
98 
99   CS_LAGR_TR_TRUNCATE,         /*!< portion of trajectory truncated */
100   CS_LAGR_TR_REPOSITION,       /*!< number of times the particle is repositioned
101                                     at the cell center, or -1 when lost (to be
102                                     discarded at the next displacement step) */
103 
104   /* Arrays for 2nd order scheme */
105 
106   CS_LAGR_TURB_STATE_1,        /* turbulence characteristics of first pass */
107   CS_LAGR_PRED_VELOCITY,       /* 1st step prediction for particle velocity */
108   CS_LAGR_PRED_VELOCITY_SEEN,  /* 1st step prediction for relative velocity */
109   CS_LAGR_V_GAUSS,             /* 1st step Gaussian variable */
110   CS_LAGR_BR_GAUSS,            /* 1st step Brownian motion Gaussian variable */
111 
112   /* Non-spherical particles submodel additoinal parameters */
113 
114   CS_LAGR_SHAPE,               /*!< Shape of spheroids */
115   CS_LAGR_ORIENTATION,         /*!< Orientation of spheroids */
116   CS_LAGR_QUATERNION,          /*!< Quaternion for spheroids */
117   CS_LAGR_RADII,               /*!< Radii a, b, c for ellispoids */
118   CS_LAGR_ANGULAR_VEL,         /*!< Angular velocity */
119   CS_LAGR_EULER,               /*!< Euler four parameters */
120   CS_LAGR_SHAPE_PARAM,         /*!< Shape parameters computed from a b c */
121 
122   /* Deposition submodel additional parameters */
123 
124   CS_LAGR_YPLUS,
125   CS_LAGR_INTERF,
126   CS_LAGR_NEIGHBOR_FACE_ID,
127   CS_LAGR_MARKO_VALUE,
128   CS_LAGR_FOULING_INDEX,
129 
130   /* Resuspension model additional parameters */
131 
132   CS_LAGR_N_LARGE_ASPERITIES,
133   CS_LAGR_N_SMALL_ASPERITIES,
134   CS_LAGR_ADHESION_FORCE,
135   CS_LAGR_ADHESION_TORQUE,
136   CS_LAGR_DISPLACEMENT_NORM,
137 
138   /* Clogging model additional parameters */
139 
140   CS_LAGR_HEIGHT,
141   CS_LAGR_CLUSTER_NB_PART,
142   CS_LAGR_DEPO_TIME,
143   CS_LAGR_CONSOL_HEIGHT,
144 
145   /* Thermal model additional parameters */
146 
147   CS_LAGR_TEMPERATURE,
148   CS_LAGR_FLUID_TEMPERATURE,
149   CS_LAGR_CP,
150 
151   /* Coal combustion additional parameters */
152 
153   CS_LAGR_WATER_MASS,
154   CS_LAGR_COAL_MASS,
155   CS_LAGR_COKE_MASS,
156 
157   CS_LAGR_SHRINKING_DIAMETER,
158   CS_LAGR_INITIAL_DIAMETER,
159 
160   CS_LAGR_COAL_ID,
161   CS_LAGR_COAL_DENSITY,
162 
163   /* Radiative model additional parameters */
164 
165   CS_LAGR_EMISSIVITY,
166 
167   /* Statistical class */
168 
169   CS_LAGR_STAT_CLASS,
170 
171   /* Agglomeration/fragmentation model parameters */
172   CS_LAGR_AGGLO_CLASS_ID,
173   CS_LAGR_AGGLO_FRACTAL_DIM,
174 
175   /* User attributes */
176 
177   CS_LAGR_USER,
178 
179   /* End of attributes */
180 
181   CS_LAGR_N_ATTRIBUTES
182 
183 } cs_lagr_attribute_t;
184 
185 /*! Particle attribute structure mapping */
186 /* ------------------------------------- */
187 
188 typedef struct {
189 
190   size_t          extents;                         /* size (in bytes) of particle
191                                                       structure */
192   size_t          lb;                              /* size (in bytes) of lower
193                                                       bounds of particle data
194                                                       (work area before) */
195 
196   int             n_time_vals;                     /* number of time values
197                                                       handled */
198 
199   size_t          size[CS_LAGR_N_ATTRIBUTES];      /* size (in bytes) of
200                                                       attributes in particle
201                                                       structure for a given
202                                                       time value */
203   cs_datatype_t   datatype[CS_LAGR_N_ATTRIBUTES];  /* datatype of associated
204                                                       attributes */
205   int            (*count)[CS_LAGR_N_ATTRIBUTES];   /* number of values for each
206                                                       attribute, per associated
207                                                       time_id */
208   ptrdiff_t      (*displ)[CS_LAGR_N_ATTRIBUTES];   /* displacement (in bytes) of
209                                                       attributes in particle data,
210                                                       per associated time_id*/
211 
212   ptrdiff_t      *source_term_displ;               /* displacement (in bytes) of
213                                                       source term values
214                                                       for second-order scheme,
215                                                       or NULL */
216 
217 } cs_lagr_attribute_map_t;
218 
219 /* Particle set */
220 /* ------------ */
221 
222 typedef struct {
223 
224   cs_lnum_t  n_particles;                     /* number of particle in domain */
225   cs_lnum_t  n_part_new;
226   cs_lnum_t  n_part_out;
227   cs_lnum_t  n_part_merged;                   /* number of merged particles */
228   cs_lnum_t  n_part_dep;
229   cs_lnum_t  n_part_fou;
230   cs_lnum_t  n_part_resusp;
231   cs_lnum_t  n_failed_part;
232 
233   cs_real_t  weight;
234   cs_real_t  weight_new;
235   cs_real_t  weight_out;
236   cs_real_t  weight_merged;
237   cs_real_t  weight_dep;
238   cs_real_t  weight_fou;
239   cs_real_t  weight_resusp;
240   cs_real_t  weight_failed;
241 
242   cs_lnum_t  n_particles_max;
243 
244   const cs_lagr_attribute_map_t  *p_am;       /*!< particle attributes maps
245                                                    (p_am + i for time n-i) */
246   unsigned char                  *p_buffer;   /*!< Particles data buffer */
247 
248 } cs_lagr_particle_set_t;
249 
250 /*=============================================================================
251  * Global variables
252  *============================================================================*/
253 
254 /*! Names of particle attributes */
255 
256 extern const char *cs_lagr_attribute_name[];
257 
258 /*! Pointer to the main particle set */
259 
260 extern cs_lagr_particle_set_t  *cs_glob_lagr_particle_set;
261 
262 /*============================================================================
263  * Public function prototypes for Fortran API
264  *============================================================================*/
265 
266 /*============================================================================
267  * Public function prototypes
268  *============================================================================*/
269 
270 /*----------------------------------------------------------------------------*/
271 /*!
272  * \brief Define particle map based on defined options.
273  */
274 /*----------------------------------------------------------------------------*/
275 
276 void
277 cs_lagr_particle_attr_initialize(void);
278 
279 /*----------------------------------------------------------------------------*/
280 /*!
281  * \brief  Return const pointer to the main particle attribute map structure.
282  *
283  * \return pointer to current particle attribute map, or NULL
284  */
285 /*----------------------------------------------------------------------------*/
286 
287 const cs_lagr_attribute_map_t *
288 cs_lagr_particle_get_attr_map(void);
289 
290 /*----------------------------------------------------------------------------*/
291 /*!
292  * Allocate main cs_lagr_particle_set_t structure.
293  */
294 /*----------------------------------------------------------------------------*/
295 
296 void
297 cs_lagr_particle_set_create(void);
298 
299 /*----------------------------------------------------------------------------*/
300 /*!
301  * \brief Destroy main particle set and map if they exist.
302  */
303 /*----------------------------------------------------------------------------*/
304 
305 void
306 cs_lagr_particle_finalize(void);
307 
308 /*----------------------------------------------------------------------------*/
309 /*!
310  * \brief Copy attributes from one particle to another
311  *
312  * The random value associated with the particle is modified.
313  *
314  * \param  dest  id (0-based) of destination particle
315  * \param  src   id (0-based) of source particle
316  */
317 /*----------------------------------------------------------------------------*/
318 
319 void
320 cs_lagr_part_copy(cs_lnum_t  dest,
321                   cs_lnum_t  src);
322 
323 /*----------------------------------------------------------------------------*/
324 /*!
325  * \brief Get data extents for a given particle attribute.
326  *
327  * For attributes not currently present, the displacement and data
328  * size should be -1 and 0 respectively.
329  *
330  * \param[in]   particles  associated particle set
331  * \param[in]   time_id    associated time id (0: current, 1: previous)
332  * \param[in]   attr       particle attribute
333  * \param[out]  extents    size (in bytes) of particle structure, or NULL
334  * \param[out]  size       size (in bytes) of attribute in particle structure,
335  *                         or NULL
336  * \param[out]  displ      displacement (in bytes) in particle structure,
337  *                         or NULL
338  * \param[out]  datatype   datatype of associated attribute, or NULL
339  * \param[out]  count      number of type values associated with attribute,
340  *                         or NULL
341  */
342 /*----------------------------------------------------------------------------*/
343 
344 void
345 cs_lagr_get_attr_info(const cs_lagr_particle_set_t  *particles,
346                       int                            time_id,
347                       cs_lagr_attribute_t            attr,
348                       size_t                        *extents,
349                       size_t                        *size,
350                       ptrdiff_t                     *displ,
351                       cs_datatype_t                 *datatype,
352                       int                           *count);
353 
354 /*----------------------------------------------------------------------------*/
355 /*!
356  * \brief Check that query for a given particle attribute is valid.
357  *
358  * \param[in]   particles             associated particle set
359  * \param[in]   attr                  attribute whose values are required
360  * \param[in]   datatype              associated value type
361  * \param[in]   stride                number of values per particle
362  * \param[in]   component_id          if -1 : extract the whole attribute
363  *                                    if >0 : id of the component to extract
364  *
365  * \return 0 in case of success, 1 in case of error
366  */
367 /*----------------------------------------------------------------------------*/
368 
369 int
370 cs_lagr_check_attr_query(const cs_lagr_particle_set_t  *particles,
371                          cs_lagr_attribute_t            attr,
372                          cs_datatype_t                  datatype,
373                          int                            stride,
374                          int                            component_id);
375 
376 /*----------------------------------------------------------------------------*/
377 /*!
378  * \brief Check if a particle attribute is in a valid range.
379  *
380  * If this is not the case, a fatal error is provoked.
381 
382  * \param[in]   attr       particle attribute
383  */
384 /*----------------------------------------------------------------------------*/
385 
386 void
387 cs_lagr_particle_attr_in_range(int  attr);
388 
389 /*----------------------------------------------------------------------------
390  * Return pointer to the main cs_lagr_particle_set_t structure.
391  *
392  * returns:
393  *   pointer to current particle set, or NULL
394  *----------------------------------------------------------------------------*/
395 
396 cs_lagr_particle_set_t  *
397 cs_lagr_get_particle_set(void);
398 
399 /*----------------------------------------------------------------------------*/
400 /*!
401  * \brief Get pointer to a current attribute of a given particle in a set.
402  *
403  * \param[in]  particle_set  pointer to particle set
404  * \param[in]  particle_id   particle id
405  * \param[in]  attr          requested attribute id
406  *
407  * \return    pointer to current attribute data
408  */
409 /*----------------------------------------------------------------------------*/
410 
411 inline static void *
cs_lagr_particles_attr(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr)412 cs_lagr_particles_attr(cs_lagr_particle_set_t  *particle_set,
413                        cs_lnum_t                particle_id,
414                        cs_lagr_attribute_t      attr)
415 {
416   assert(particle_set->p_am->count[0][attr] > 0);
417 
418   return   (unsigned char *)particle_set->p_buffer
419          + particle_set->p_am->extents*particle_id
420          + particle_set->p_am->displ[0][attr];
421 }
422 
423 /*----------------------------------------------------------------------------*/
424 /*!
425  * \brief Get const pointer to current attribute data
426  *        of a given particle in a set.
427  *
428  * \param[in]  particle_set  pointer to particle set
429  * \param[in]  particle_id   particle id
430  * \param[in]  attr          requested attribute id
431  *
432  * \return    pointer to current attribute data
433  */
434 /*----------------------------------------------------------------------------*/
435 
436 inline static const void *
cs_lagr_particles_attr_const(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr)437 cs_lagr_particles_attr_const(const cs_lagr_particle_set_t  *particle_set,
438                              cs_lnum_t                      particle_id,
439                              cs_lagr_attribute_t            attr)
440 {
441   assert(particle_set->p_am->count[0][attr] > 0);
442 
443   return   particle_set->p_buffer
444          + particle_set->p_am->extents*particle_id
445          + particle_set->p_am->displ[0][attr];
446 }
447 
448 /*----------------------------------------------------------------------------*/
449 /*!
450  * \brief Get pointer to attribute data of a given particle in a set
451  *        at a given time.
452  *
453  * \param[in]  particle_set  pointer to particle set
454  * \param[in]  particle_id   particle id
455  * \param[in]  time_id       0 for current, 1 for previous
456  * \param[in]  attr          requested attribute id
457  *
458  * \return    pointer to attribute data at given time
459  */
460 /*----------------------------------------------------------------------------*/
461 
462 inline static void *
cs_lagr_particles_attr_n(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int time_id,cs_lagr_attribute_t attr)463 cs_lagr_particles_attr_n(cs_lagr_particle_set_t  *particle_set,
464                          cs_lnum_t                particle_id,
465                          int                      time_id,
466                          cs_lagr_attribute_t      attr)
467 {
468   assert(particle_set->p_am->count[time_id][attr] > 0);
469 
470   return   particle_set->p_buffer
471          + particle_set->p_am->extents*particle_id
472          + particle_set->p_am->displ[time_id][attr];
473 }
474 
475 /*----------------------------------------------------------------------------*/
476 /*!
477  * \brief Get const pointer to attribute data of a given particle in a set
478  *        at a given time.
479  *
480  * \param[in]  particle_set  pointer to particle set
481  * \param[in]  particle_id   particle id
482  * \param[in]  time_id       0 for current, 1 for previous
483  * \param[in]  attr          requested attribute id
484  *
485  * \return    pointer to attribute data at given time
486  */
487 /*----------------------------------------------------------------------------*/
488 
489 inline static const void *
cs_lagr_particles_attr_n_const(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int time_id,cs_lagr_attribute_t attr)490 cs_lagr_particles_attr_n_const(const cs_lagr_particle_set_t  *particle_set,
491                                cs_lnum_t                      particle_id,
492                                int                            time_id,
493                                cs_lagr_attribute_t            attr)
494 {
495   assert(particle_set->p_am->count[time_id][attr] > 0);
496 
497   return   particle_set->p_buffer
498          + particle_set->p_am->extents*particle_id
499          + particle_set->p_am->displ[time_id][attr];
500 }
501 
502 /*----------------------------------------------------------------------------*/
503 /*!
504  * \brief Get flag value with a selected mask for a given particle in a set.
505  *
506  * \param[in]  particle_set  pointer to particle set
507  * \param[in]  particle_id   particle id
508  * \param[in]  mask          requested attribute flag value
509  *
510  * \return  attribute value
511  */
512 /*----------------------------------------------------------------------------*/
513 
514 inline static int
cs_lagr_particles_get_flag(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int mask)515 cs_lagr_particles_get_flag(const cs_lagr_particle_set_t  *particle_set,
516                            cs_lnum_t                      particle_id,
517                            int                            mask)
518 {
519   int flag
520     = *((const cs_lnum_t *)(  particle_set->p_buffer
521                             + particle_set->p_am->extents*particle_id
522                             + particle_set->p_am->displ[0][CS_LAGR_P_FLAG]));
523 
524   return (flag & mask);
525 }
526 
527 /*----------------------------------------------------------------------------*/
528 /*!
529  * \brief Set flag value with a selected mask for a given particle in a set.
530  *
531  * \param[in]  particle_set  pointer to particle set
532  * \param[in]  particle_id   particle id
533  * \param[in]  mask          attribute flag value to set
534  */
535 /*----------------------------------------------------------------------------*/
536 
537 inline static void
cs_lagr_particles_set_flag(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int mask)538 cs_lagr_particles_set_flag(const cs_lagr_particle_set_t  *particle_set,
539                            cs_lnum_t                      particle_id,
540                            int                            mask)
541 {
542   int flag
543     = *((const cs_lnum_t *)(  particle_set->p_buffer
544                             + particle_set->p_am->extents*particle_id
545                             + particle_set->p_am->displ[0][CS_LAGR_P_FLAG]));
546 
547   flag = flag | mask;
548 
549   *((cs_lnum_t *)(  particle_set->p_buffer
550                   + particle_set->p_am->extents*particle_id
551                   + particle_set->p_am->displ[0][CS_LAGR_P_FLAG])) = flag;
552 }
553 
554 /*----------------------------------------------------------------------------*/
555 /*!
556  * \brief Unset flag value with a selected mask for a given particle in a set.
557  *
558  * \param[in]  particle_set  pointer to particle set
559  * \param[in]  particle_id   particle id
560  * \param[in]  mask          attribute flag value to set
561  */
562 /*----------------------------------------------------------------------------*/
563 
564 inline static void
cs_lagr_particles_unset_flag(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int mask)565 cs_lagr_particles_unset_flag(const cs_lagr_particle_set_t  *particle_set,
566                              cs_lnum_t                      particle_id,
567                              int                            mask)
568 {
569   int flag
570     = *((const cs_lnum_t *)(  particle_set->p_buffer
571                             + particle_set->p_am->extents*particle_id
572                             + particle_set->p_am->displ[0][CS_LAGR_P_FLAG]));
573 
574   flag = (flag | mask) - mask;
575 
576   *((cs_lnum_t *)(  particle_set->p_buffer
577                   + particle_set->p_am->extents*particle_id
578                   + particle_set->p_am->displ[0][CS_LAGR_P_FLAG])) = flag;
579 }
580 
581 /*----------------------------------------------------------------------------*/
582 /*!
583  * \brief Get attribute value of type cs_lnum_t of a given particle in a set.
584  *
585  * \param[in]  particle_set  pointer to particle set
586  * \param[in]  particle_id   particle id
587  * \param[in]  attr          requested attribute id
588  *
589  * \return  attribute value
590  */
591 /*----------------------------------------------------------------------------*/
592 
593 inline static cs_lnum_t
cs_lagr_particles_get_lnum(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr)594 cs_lagr_particles_get_lnum(const cs_lagr_particle_set_t  *particle_set,
595                            cs_lnum_t                      particle_id,
596                            cs_lagr_attribute_t            attr)
597 {
598   assert(particle_set->p_am->count[0][attr] > 0);
599 
600   return *((const cs_lnum_t *)(  particle_set->p_buffer
601                                + particle_set->p_am->extents*particle_id
602                                + particle_set->p_am->displ[0][attr]));
603 }
604 
605 /*----------------------------------------------------------------------------*/
606 /*!
607  * \brief Get attribute value of type cs_lnum_t of a given particle in a set
608  *        at a given time.
609  *
610  * \param[in]  particle_set  pointer to particle set
611  * \param[in]  particle_id   particle id
612  * \param[in]  time_id       0 for current, 1 for previous
613  * \param[in]  attr          requested attribute id
614  *
615  * \return  attribute value
616  */
617 /*----------------------------------------------------------------------------*/
618 
619 inline static cs_lnum_t
cs_lagr_particles_get_lnum_n(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int time_id,cs_lagr_attribute_t attr)620 cs_lagr_particles_get_lnum_n(const cs_lagr_particle_set_t  *particle_set,
621                              cs_lnum_t                      particle_id,
622                              int                            time_id,
623                              cs_lagr_attribute_t            attr)
624 {
625   assert(particle_set->p_am->count[time_id][attr] > 0);
626 
627   return *((const cs_lnum_t *)(  particle_set->p_buffer
628                                + particle_set->p_am->extents*particle_id
629                                + particle_set->p_am->displ[time_id][attr]));
630 }
631 
632 /*----------------------------------------------------------------------------*/
633 /*!
634  * \brief Set attribute value of type cs_lnum_t of a given particle in a set.
635  *
636  * \param[in, out]   particle_set  pointer to particle set
637  * \param[in]        particle_id   particle id
638  * \param[in]        attr          requested attribute id
639  * \param[in]        value         value to assign
640  */
641 /*----------------------------------------------------------------------------*/
642 
643 inline static void
cs_lagr_particles_set_lnum(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr,cs_lnum_t value)644 cs_lagr_particles_set_lnum(cs_lagr_particle_set_t  *particle_set,
645                            cs_lnum_t                particle_id,
646                            cs_lagr_attribute_t      attr,
647                            cs_lnum_t                value)
648 {
649   assert(particle_set->p_am->count[0][attr] > 0);
650 
651   *((cs_lnum_t *)(  particle_set->p_buffer
652                   + particle_set->p_am->extents*particle_id
653                   + particle_set->p_am->displ[0][attr])) = value;
654 }
655 
656 /*----------------------------------------------------------------------------*/
657 /*!
658  * \brief Set attribute value of type cs_lnum_t of a given particle in a set
659  *        at a given time.
660  *
661  * \param[in, out]   particle_set  pointer to particle set
662  * \param[in]        particle_id   particle id
663  * \param[in]        time_id       0 for current, 1 for previous
664  * \param[in]        attr          requested attribute id
665  * \param[in]        value         value to assign
666  */
667 /*----------------------------------------------------------------------------*/
668 
669 inline static void
cs_lagr_particles_set_lnum_n(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int time_id,cs_lagr_attribute_t attr,cs_lnum_t value)670 cs_lagr_particles_set_lnum_n(cs_lagr_particle_set_t  *particle_set,
671                              cs_lnum_t                particle_id,
672                              int                      time_id,
673                              cs_lagr_attribute_t      attr,
674                              cs_lnum_t                value)
675 {
676   assert(particle_set->p_am->count[time_id][attr] > 0);
677 
678   *((cs_lnum_t *)(  particle_set->p_buffer
679                   + particle_set->p_am->extents*particle_id
680                   + particle_set->p_am->displ[time_id][attr])) = value;
681 }
682 
683 /*----------------------------------------------------------------------------*/
684 /*!
685  * \brief Get attribute value of type cs_gnum_t of a given particle in a set.
686  *
687  * \param[in]  particle_set  pointer to particle set
688  * \param[in]  particle_id   particle id
689  * \param[in]  attr          requested attribute id
690  *
691  * \return  attribute value
692  */
693 /*----------------------------------------------------------------------------*/
694 
695 inline static cs_gnum_t
cs_lagr_particles_get_gnum(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr)696 cs_lagr_particles_get_gnum(const cs_lagr_particle_set_t  *particle_set,
697                            cs_lnum_t                      particle_id,
698                            cs_lagr_attribute_t            attr)
699 {
700   assert(particle_set->p_am->count[0][attr] > 0);
701 
702   return *((const cs_gnum_t *)(  particle_set->p_buffer
703                                + particle_set->p_am->extents*particle_id
704                                + particle_set->p_am->displ[0][attr]));
705 }
706 
707 /*----------------------------------------------------------------------------*/
708 /*!
709  * \brief Get attribute value of type cs_gnum_t of a given particle in a set
710  *        at a given time.
711  *
712  * \param[in]  particle_set  pointer to particle set
713  * \param[in]  particle_id   particle id
714  * \param[in]  time_id       0 for current, 1 for previous
715  * \param[in]  attr          requested attribute id
716  *
717  * \return  attribute value
718  */
719 /*----------------------------------------------------------------------------*/
720 
721 inline static cs_gnum_t
cs_lagr_particles_get_gnum_n(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int time_id,cs_lagr_attribute_t attr)722 cs_lagr_particles_get_gnum_n(const cs_lagr_particle_set_t  *particle_set,
723                              cs_lnum_t                      particle_id,
724                              int                            time_id,
725                              cs_lagr_attribute_t            attr)
726 {
727   assert(particle_set->p_am->count[time_id][attr] > 0);
728 
729   return *((const cs_gnum_t *)(  particle_set->p_buffer
730                                + particle_set->p_am->extents*particle_id
731                                + particle_set->p_am->displ[time_id][attr]));
732 }
733 
734 /*----------------------------------------------------------------------------*/
735 /*!
736  * \brief Set attribute value of type cs_gnum_t of a given particle in a set.
737  *
738  * \param[in, out]   particle_set  pointer to particle set
739  * \param[in]        particle_id   particle id
740  * \param[in]        attr          requested attribute id
741  * \param[in]        value         value to assign
742  */
743 /*----------------------------------------------------------------------------*/
744 
745 inline static void
cs_lagr_particles_set_gnum(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr,cs_gnum_t value)746 cs_lagr_particles_set_gnum(cs_lagr_particle_set_t  *particle_set,
747                            cs_lnum_t                particle_id,
748                            cs_lagr_attribute_t      attr,
749                            cs_gnum_t                value)
750 {
751   assert(particle_set->p_am->count[0][attr] > 0);
752 
753   *((cs_gnum_t *)(  particle_set->p_buffer
754                   + particle_set->p_am->extents*particle_id
755                   + particle_set->p_am->displ[0][attr])) = value;
756 }
757 
758 /*----------------------------------------------------------------------------*/
759 /*!
760  * \brief Set attribute value of type cs_gnum_t of a given particle in a set
761  *        at a given time.
762  *
763  * \param[in, out]   particle_set  pointer to particle set
764  * \param[in]        particle_id   particle id
765  * \param[in]        time_id       0 for current, 1 for previous
766  * \param[in]        attr          requested attribute id
767  * \param[in]        value         value to assign
768  */
769 /*----------------------------------------------------------------------------*/
770 
771 inline static void
cs_lagr_particles_set_gnum_n(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int time_id,cs_lagr_attribute_t attr,cs_gnum_t value)772 cs_lagr_particles_set_gnum_n(cs_lagr_particle_set_t  *particle_set,
773                              cs_lnum_t                particle_id,
774                              int                      time_id,
775                              cs_lagr_attribute_t      attr,
776                              cs_gnum_t                value)
777 {
778   assert(particle_set->p_am->count[time_id][attr] > 0);
779 
780   *((cs_gnum_t *)(  particle_set->p_buffer
781                   + particle_set->p_am->extents*particle_id
782                   + particle_set->p_am->displ[time_id][attr])) = value;
783 }
784 
785 /*----------------------------------------------------------------------------*/
786 /*!
787  * \brief Get attribute value of type cs_real_t of a given particle in a set.
788  *
789  * \param[in]  particle_set  pointer to particle set
790  * \param[in]  particle_id   particle id
791  * \param[in]  attr          requested attribute id
792  *
793  * \return  attribute value
794  */
795 /*----------------------------------------------------------------------------*/
796 
797 inline static cs_real_t
cs_lagr_particles_get_real(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr)798 cs_lagr_particles_get_real(const cs_lagr_particle_set_t  *particle_set,
799                            cs_lnum_t                      particle_id,
800                            cs_lagr_attribute_t            attr)
801 {
802   assert(particle_set->p_am->count[0][attr] > 0);
803 
804   return *((const cs_real_t *)(  particle_set->p_buffer
805                                + particle_set->p_am->extents*particle_id
806                                + particle_set->p_am->displ[0][attr]));
807 }
808 
809 /*----------------------------------------------------------------------------*/
810 /*!
811  * \brief Get attribute value of type cs_real_t of a given particle in a set
812  *        at a given time.
813  *
814  * \param[in]  particle_set  pointer to particle set
815  * \param[in]  particle_id   particle id
816  * \param[in]  time_id       0 for current, 1 for previous
817  * \param[in]  attr          requested attribute id
818  *
819  * \return  attribute value
820  */
821 /*----------------------------------------------------------------------------*/
822 
823 inline static cs_real_t
cs_lagr_particles_get_real_n(const cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int time_id,cs_lagr_attribute_t attr)824 cs_lagr_particles_get_real_n(const cs_lagr_particle_set_t  *particle_set,
825                              cs_lnum_t                      particle_id,
826                              int                            time_id,
827                              cs_lagr_attribute_t            attr)
828 {
829   assert(particle_set->p_am->count[time_id][attr] > 0);
830 
831   return *((const cs_real_t *)(  particle_set->p_buffer
832                                + particle_set->p_am->extents*particle_id
833                                + particle_set->p_am->displ[time_id][attr]));
834 }
835 
836 /*----------------------------------------------------------------------------*/
837 /*!
838  * \brief Set attribute value of type cs_real_t of a given particle in a set.
839  *
840  * \param[in, out]   particle_set  pointer to particle set
841  * \param[in]        particle_id   particle id
842  * \param[in]        attr          requested attribute id
843  * \param[in]        value         value to assign
844  */
845 /*----------------------------------------------------------------------------*/
846 
847 inline static void
cs_lagr_particles_set_real(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr,cs_real_t value)848 cs_lagr_particles_set_real(cs_lagr_particle_set_t  *particle_set,
849                            cs_lnum_t                particle_id,
850                            cs_lagr_attribute_t      attr,
851                            cs_real_t                value)
852 {
853   assert(particle_set->p_am->count[0][attr] > 0);
854 
855   *((cs_real_t *)(  particle_set->p_buffer
856                   + particle_set->p_am->extents*particle_id
857                   + particle_set->p_am->displ[0][attr])) = value;
858 }
859 
860 /*----------------------------------------------------------------------------*/
861 /*!
862  * \brief Set attribute value of type cs_real_t of a given particle in a set
863  *        at a given time.
864  *
865  * \param[in, out]   particle_set  pointer to particle set
866  * \param[in]        particle_id   particle id
867  * \param[in]        time_id       0 for current, 1 for previous
868  * \param[in]        attr          requested attribute id
869  * \param[in]        value         value to assign
870  */
871 /*----------------------------------------------------------------------------*/
872 
873 inline static void
cs_lagr_particles_set_real_n(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,int time_id,cs_lagr_attribute_t attr,cs_real_t value)874 cs_lagr_particles_set_real_n(cs_lagr_particle_set_t  *particle_set,
875                              cs_lnum_t                particle_id,
876                              int                      time_id,
877                              cs_lagr_attribute_t      attr,
878                              cs_real_t                value)
879 {
880   assert(particle_set->p_am->count[time_id][attr] > 0);
881 
882   *((cs_real_t *)(  particle_set->p_buffer
883                   + particle_set->p_am->extents*particle_id
884                   + particle_set->p_am->displ[time_id][attr])) = value;
885 }
886 
887 /*----------------------------------------------------------------------------*/
888 /*!
889  * \brief Get pointer to 2nd order scheme source terms for an attribute
890  *        of a given particle in a set.
891  *
892  * \param[in]  particle_set  pointer to particle set
893  * \param[in]  particle_id   particle id
894  * \param[in]  attr          requested attribute id
895  *
896  * \return    pointer to current attribute data
897  */
898 /*----------------------------------------------------------------------------*/
899 
900 inline static cs_real_t *
cs_lagr_particles_source_terms(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr)901 cs_lagr_particles_source_terms(cs_lagr_particle_set_t  *particle_set,
902                                cs_lnum_t                particle_id,
903                                cs_lagr_attribute_t      attr)
904 {
905   assert(particle_set->p_am->source_term_displ != NULL);
906   assert(particle_set->p_am->source_term_displ[attr] >= 0);
907 
908   return (cs_real_t *)(  (unsigned char *)particle_set->p_buffer
909                        + particle_set->p_am->extents*particle_id
910                        + particle_set->p_am->source_term_displ[attr]);
911 }
912 
913 /*----------------------------------------------------------------------------*/
914 /*!
915  * \brief Get const pointer to 2nd order scheme source terms an attribute
916  *        of a given particle in a set.
917  *
918  * \param[in]  particle_set  pointer to particle set
919  * \param[in]  particle_id   particle id
920  * \param[in]  attr          requested attribute id
921  *
922  * \return    pointer to current attribute data
923  */
924 /*----------------------------------------------------------------------------*/
925 
926 inline static const cs_real_t *
cs_lagr_particles_source_terms_const(cs_lagr_particle_set_t * particle_set,cs_lnum_t particle_id,cs_lagr_attribute_t attr)927 cs_lagr_particles_source_terms_const(cs_lagr_particle_set_t  *particle_set,
928                                      cs_lnum_t                particle_id,
929                                      cs_lagr_attribute_t      attr)
930 {
931   assert(particle_set->p_am->source_term_displ != NULL);
932   assert(particle_set->p_am->source_term_displ[attr] >= 0);
933 
934   return (const cs_real_t *)(  (unsigned char *)particle_set->p_buffer
935                              + particle_set->p_am->extents*particle_id
936                              + particle_set->p_am->source_term_displ[attr]);
937 }
938 
939 /*----------------------------------------------------------------------------*/
940 /*!
941  * \brief Get pointer to current attribute data of a particle.
942  *
943  * \param[in]  particle  pointer to particle data
944  * \param[in]  attr_map  pointer to attribute map
945  * \param[in]  attr      requested attribute id
946  *
947  * \return  pointer to attribute data
948  */
949 /*----------------------------------------------------------------------------*/
950 
951 inline static void *
cs_lagr_particle_attr(void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr)952 cs_lagr_particle_attr(void                           *particle,
953                       const cs_lagr_attribute_map_t  *attr_map,
954                       cs_lagr_attribute_t             attr)
955 {
956   assert(attr_map->count[0][attr] > 0);
957 
958   return  (unsigned char *)particle + attr_map->displ[0][attr];
959 }
960 
961 /*----------------------------------------------------------------------------*/
962 /*!
963  * \brief Get const pointer to current attribute data of a particle.
964  *
965  * \param[in]  particle  pointer to particle data
966  * \param[in]  attr_map  pointer to attribute map
967  * \param[in]  attr      requested attribute id
968  *
969  * \return  const pointer to attribute
970  */
971 /*----------------------------------------------------------------------------*/
972 
973 inline static const void *
cs_lagr_particle_attr_const(const void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr)974 cs_lagr_particle_attr_const(const void                     *particle,
975                             const cs_lagr_attribute_map_t  *attr_map,
976                             cs_lagr_attribute_t             attr)
977 {
978   assert(attr_map->count[0][attr] > 0);
979 
980   return  (const unsigned char *)particle + attr_map->displ[0][attr];
981 }
982 
983 /*----------------------------------------------------------------------------*/
984 /*!
985  * \brief Get pointer to attribute data of a particle at a given time.
986  *
987  * \param[in]  particle  pointer to particle data
988  * \param[in]  attr_map  pointer to attribute map
989  * \param[in]  time_id   0 for current, 1 for previous
990  * \param[in]  attr      requested attribute id
991  *
992  * \return  pointer to attribute data
993  */
994 /*----------------------------------------------------------------------------*/
995 
996 inline static void *
cs_lagr_particle_attr_n(void * particle,const cs_lagr_attribute_map_t * attr_map,int time_id,cs_lagr_attribute_t attr)997 cs_lagr_particle_attr_n(void                           *particle,
998                         const cs_lagr_attribute_map_t  *attr_map,
999                         int                             time_id,
1000                         cs_lagr_attribute_t             attr)
1001 {
1002   assert(attr_map->count[time_id][attr] > 0);
1003 
1004   return  (unsigned char *)particle + attr_map->displ[time_id][attr];
1005 }
1006 
1007 /*----------------------------------------------------------------------------*/
1008 /*!
1009  * \brief Get const pointer to attribute data of a particle at a given time.
1010  *
1011  * \param[in]  particle  pointer to particle data
1012  * \param[in]  attr_map  pointer to attribute map
1013  * \param[in]  time_id   0 for current, 1 for previous
1014  * \param[in]  attr      requested attribute id
1015  *
1016  * \return  pointer to attribute data
1017  */
1018 /*----------------------------------------------------------------------------*/
1019 
1020 inline static const void *
cs_lagr_particle_attr_n_const(const void * particle,const cs_lagr_attribute_map_t * attr_map,int time_id,cs_lagr_attribute_t attr)1021 cs_lagr_particle_attr_n_const(const void                     *particle,
1022                               const cs_lagr_attribute_map_t  *attr_map,
1023                               int                             time_id,
1024                               cs_lagr_attribute_t             attr)
1025 {
1026   assert(attr_map->count[time_id][attr] > 0);
1027 
1028   return    (const unsigned char *)particle
1029           + attr_map->displ[time_id][attr];
1030 }
1031 
1032 /*----------------------------------------------------------------------------*/
1033 /*!
1034  * \brief Get attribute value of type cs_lnum_t of a given particle in a set
1035  *
1036  * \param[in]  particle  pointer to particle data
1037  * \param[in]  attr_map  pointer to attribute map
1038  * \param[in]  attr     requested attribute id
1039  *
1040  * \return attribute value
1041  */
1042 /*----------------------------------------------------------------------------*/
1043 
1044 inline static cs_lnum_t
cs_lagr_particle_get_lnum(const void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr)1045 cs_lagr_particle_get_lnum(const void                     *particle,
1046                           const cs_lagr_attribute_map_t  *attr_map,
1047                           cs_lagr_attribute_t             attr)
1048 {
1049   assert(attr_map->count[0][attr] > 0);
1050 
1051   return  *((const cs_lnum_t *)(  (const unsigned char *)particle
1052                                 + attr_map->displ[0][attr]));
1053 }
1054 
1055 /*----------------------------------------------------------------------------*/
1056 /*!
1057  * \brief Get attribute value of type cs_lnum_t of a given particle
1058  *        at a given time.
1059  *
1060  * \param[in]  particle  pointer to particle data
1061  * \param[in]  attr_map  pointer to attribute map
1062  * \param[in]  time_id   0 for current, 1 for previous
1063  * \param[in]  attr      requested attribute id
1064  *
1065  * \return attribute value
1066  */
1067 /*----------------------------------------------------------------------------*/
1068 
1069 inline static cs_lnum_t
cs_lagr_particle_get_lnum_n(const void * particle,const cs_lagr_attribute_map_t * attr_map,int time_id,cs_lagr_attribute_t attr)1070 cs_lagr_particle_get_lnum_n(const void                     *particle,
1071                             const cs_lagr_attribute_map_t  *attr_map,
1072                             int                             time_id,
1073                             cs_lagr_attribute_t             attr)
1074 {
1075   assert(attr_map->count[time_id][attr] > 0);
1076 
1077   return  *((const cs_lnum_t *)(  (const unsigned char *)particle
1078                                 + attr_map->displ[time_id][attr]));
1079 }
1080 
1081 /*----------------------------------------------------------------------------*/
1082 /*!
1083  * \brief Set attribute value of type cs_lnum_t of a given particle.
1084  *
1085  * \param[in, out]  particle  pointer to particle data
1086  * \param[in]       attr_map  pointer to attribute map
1087  * \param[in]       attr      requested attribute id
1088  * \param[in]       value     value to assign
1089  */
1090  /*----------------------------------------------------------------------------*/
1091 
1092 inline static void
cs_lagr_particle_set_lnum(void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr,cs_lnum_t value)1093 cs_lagr_particle_set_lnum(void                           *particle,
1094                           const cs_lagr_attribute_map_t  *attr_map,
1095                           cs_lagr_attribute_t             attr,
1096                           cs_lnum_t                       value)
1097 {
1098   assert(attr_map->count[0][attr] > 0);
1099 
1100   *((cs_lnum_t *)((unsigned char *)particle + attr_map->displ[0][attr]))
1101     = value;
1102 }
1103 
1104 /*----------------------------------------------------------------------------*/
1105 /*!
1106  * \brief Set attribute value of type cs_lnum_t of a given particle
1107  *        at a given time.
1108  *
1109  * \param[in, out]  particle  pointer to particle data
1110  * \param[in]       attr_map  pointer to attribute map
1111  * \param[in]       time_id   0 for current, 1 for previous
1112  * \param[in]       attr      requested attribute id
1113  * \param[in]       value     value to assign
1114  */
1115  /*----------------------------------------------------------------------------*/
1116 
1117 inline static void
cs_lagr_particle_set_lnum_n(void * particle,const cs_lagr_attribute_map_t * attr_map,int time_id,cs_lagr_attribute_t attr,cs_lnum_t value)1118 cs_lagr_particle_set_lnum_n(void                           *particle,
1119                             const cs_lagr_attribute_map_t  *attr_map,
1120                             int                             time_id,
1121                             cs_lagr_attribute_t             attr,
1122                             cs_lnum_t                       value)
1123 {
1124   assert(attr_map->count[time_id][attr] > 0);
1125 
1126   *((cs_lnum_t *)(  (unsigned char *)particle
1127                   + attr_map->displ[time_id][attr])) = value;
1128 }
1129 
1130 /*----------------------------------------------------------------------------*/
1131 /*!
1132  * \brief Get attribute value of type cs_gnum_t of a given particle in a set
1133  *
1134  * \param[in]  particle  pointer to particle data
1135  * \param[in]  attr_map  pointer to attribute map
1136  * \param[in]  attr     requested attribute id
1137  *
1138  * \return attribute value
1139  */
1140 /*----------------------------------------------------------------------------*/
1141 
1142 inline static cs_gnum_t
cs_lagr_particle_get_gnum(const void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr)1143 cs_lagr_particle_get_gnum(const void                     *particle,
1144                           const cs_lagr_attribute_map_t  *attr_map,
1145                           cs_lagr_attribute_t             attr)
1146 {
1147   assert(attr_map->count[0][attr] > 0);
1148 
1149   return  *((const cs_gnum_t *)(  (const unsigned char *)particle
1150                                 + attr_map->displ[0][attr]));
1151 }
1152 
1153 /*----------------------------------------------------------------------------*/
1154 /*!
1155  * \brief Get attribute value of type cs_gnum_t of a given particle
1156  *        at a given time.
1157  *
1158  * \param[in]  particle  pointer to particle data
1159  * \param[in]  attr_map  pointer to attribute map
1160  * \param[in]  time_id   0 for current, 1 for previous
1161  * \param[in]  attr      requested attribute id
1162  *
1163  * \return attribute value
1164  */
1165 /*----------------------------------------------------------------------------*/
1166 
1167 inline static cs_gnum_t
cs_lagr_particle_get_gnum_n(const void * particle,const cs_lagr_attribute_map_t * attr_map,int time_id,cs_lagr_attribute_t attr)1168 cs_lagr_particle_get_gnum_n(const void                     *particle,
1169                             const cs_lagr_attribute_map_t  *attr_map,
1170                             int                             time_id,
1171                             cs_lagr_attribute_t             attr)
1172 {
1173   assert(attr_map->count[time_id][attr] > 0);
1174 
1175   return  *((const cs_gnum_t *)(  (const unsigned char *)particle
1176                                 + attr_map->displ[time_id][attr]));
1177 }
1178 
1179 /*----------------------------------------------------------------------------*/
1180 /*!
1181  * \brief Set attribute value of type cs_gnum_t of a given particle.
1182  *
1183  * \param[in, out]  particle  pointer to particle data
1184  * \param[in]       attr_map  pointer to attribute map
1185  * \param[in]       attr      requested attribute id
1186  * \param[in]       value     value to assign
1187  */
1188  /*----------------------------------------------------------------------------*/
1189 
1190 inline static void
cs_lagr_particle_set_gnum(void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr,cs_gnum_t value)1191 cs_lagr_particle_set_gnum(void                           *particle,
1192                           const cs_lagr_attribute_map_t  *attr_map,
1193                           cs_lagr_attribute_t             attr,
1194                           cs_gnum_t                       value)
1195 {
1196   assert(attr_map->count[0][attr] > 0);
1197 
1198   *((cs_gnum_t *)((unsigned char *)particle + attr_map->displ[0][attr]))
1199     = value;
1200 }
1201 
1202 /*----------------------------------------------------------------------------*/
1203 /*!
1204  * \brief Set attribute value of type cs_gnum_t of a given particle
1205  *        at a given time.
1206  *
1207  * \param[in, out]  particle  pointer to particle data
1208  * \param[in]       attr_map  pointer to attribute map
1209  * \param[in]       time_id   0 for current, 1 for previous
1210  * \param[in]       attr      requested attribute id
1211  * \param[in]       value     value to assign
1212  */
1213  /*----------------------------------------------------------------------------*/
1214 
1215 inline static void
cs_lagr_particle_set_gnum_n(void * particle,const cs_lagr_attribute_map_t * attr_map,int time_id,cs_lagr_attribute_t attr,cs_gnum_t value)1216 cs_lagr_particle_set_gnum_n(void                           *particle,
1217                             const cs_lagr_attribute_map_t  *attr_map,
1218                             int                             time_id,
1219                             cs_lagr_attribute_t             attr,
1220                             cs_gnum_t                       value)
1221 {
1222   assert(attr_map->count[time_id][attr] > 0);
1223 
1224   *((cs_gnum_t *)(  (unsigned char *)particle
1225                   + attr_map->displ[time_id][attr])) = value;
1226 }
1227 
1228 /*----------------------------------------------------------------------------*/
1229 /*!
1230  * \brief Get attribute value of type cs_real_t of a given particle in a set
1231  *
1232  * \param[in]  particle  pointer to particle data
1233  * \param[in]  attr_map  pointer to attribute map
1234  * \param[in]  attr     requested attribute id
1235  *
1236  * \return attribute value
1237  */
1238 /*----------------------------------------------------------------------------*/
1239 
1240 inline static cs_real_t
cs_lagr_particle_get_real(const void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr)1241 cs_lagr_particle_get_real(const void                     *particle,
1242                           const cs_lagr_attribute_map_t  *attr_map,
1243                           cs_lagr_attribute_t             attr)
1244 {
1245   assert(attr_map->count[0][attr] > 0);
1246 
1247   return  *((const cs_real_t *)(  (const unsigned char *)particle
1248                                 + attr_map->displ[0][attr]));
1249 }
1250 
1251 /*----------------------------------------------------------------------------*/
1252 /*!
1253  * \brief Get attribute value of type cs_real_t of a given particle
1254  *        at a given time.
1255  *
1256  * \param[in]  particle  pointer to particle data
1257  * \param[in]  attr_map  pointer to attribute map
1258  * \param[in]  time_id   0 for current, 1 for previous
1259  * \param[in]  attr      requested attribute id
1260  *
1261  * \return attribute value
1262  */
1263 /*----------------------------------------------------------------------------*/
1264 
1265 inline static cs_real_t
cs_lagr_particle_get_real_n(const void * particle,const cs_lagr_attribute_map_t * attr_map,int time_id,cs_lagr_attribute_t attr)1266 cs_lagr_particle_get_real_n(const void                     *particle,
1267                             const cs_lagr_attribute_map_t  *attr_map,
1268                             int                             time_id,
1269                             cs_lagr_attribute_t             attr)
1270 {
1271   assert(attr_map->count[time_id][attr] > 0);
1272 
1273   return  *((const cs_real_t *)(  (const unsigned char *)particle
1274                                 + attr_map->displ[time_id][attr]));
1275 }
1276 
1277 /*----------------------------------------------------------------------------*/
1278 /*!
1279  * \brief Set attribute value of type cs_real_t of a given particle.
1280  *
1281  * \param[in, out]  particle  pointer to particle data
1282  * \param[in]       attr_map  pointer to attribute map
1283  * \param[in]       attr      requested attribute id
1284  * \param[in]       value     value to assign
1285  */
1286  /*----------------------------------------------------------------------------*/
1287 
1288 inline static void
cs_lagr_particle_set_real(void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr,cs_real_t value)1289 cs_lagr_particle_set_real(void                           *particle,
1290                           const cs_lagr_attribute_map_t  *attr_map,
1291                           cs_lagr_attribute_t             attr,
1292                           cs_real_t                       value)
1293 {
1294   assert(attr_map->count[0][attr] > 0);
1295 
1296   *((cs_real_t *)((unsigned char *)particle + attr_map->displ[0][attr]))
1297     = value;
1298 }
1299 
1300 /*----------------------------------------------------------------------------*/
1301 /*!
1302  * \brief Set attribute value of type cs_real_t of a given particle
1303  *        at a given time.
1304  *
1305  * \param[in, out]  particle  pointer to particle data
1306  * \param[in]       attr_map  pointer to attribute map
1307  * \param[in]       time_id   0 for current, 1 for previous
1308  * \param[in]       attr      requested attribute id
1309  * \param[in]       value     value to assign
1310  */
1311  /*----------------------------------------------------------------------------*/
1312 
1313 inline static void
cs_lagr_particle_set_real_n(void * particle,const cs_lagr_attribute_map_t * attr_map,int time_id,cs_lagr_attribute_t attr,cs_real_t value)1314 cs_lagr_particle_set_real_n(void                           *particle,
1315                             const cs_lagr_attribute_map_t  *attr_map,
1316                             int                             time_id,
1317                             cs_lagr_attribute_t             attr,
1318                             cs_real_t                       value)
1319 {
1320   assert(attr_map->count[time_id][attr] > 0);
1321 
1322   *((cs_real_t *)(  (unsigned char *)particle
1323                   + attr_map->displ[time_id][attr])) = value;
1324 }
1325 
1326 /*----------------------------------------------------------------------------*/
1327 /*!
1328  * \brief Get pointer to 2nd order scheme attribute source terms of a particle.
1329  *
1330  * \param[in]  particle  pointer to particle data
1331  * \param[in]  attr_map  pointer to attribute map
1332  * \param[in]  attr      requested attribute id
1333  *
1334  * \return  pointer to attribute source terms
1335  */
1336 /*----------------------------------------------------------------------------*/
1337 
1338 inline static cs_real_t *
cs_lagr_particle_source_term(void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr)1339 cs_lagr_particle_source_term(void                           *particle,
1340                              const cs_lagr_attribute_map_t  *attr_map,
1341                              cs_lagr_attribute_t             attr)
1342 {
1343   assert(attr_map->source_term_displ != NULL);
1344   assert(attr_map->source_term_displ[attr] >= 0);
1345 
1346   return  (cs_real_t *)(  (unsigned char *)particle
1347                         + attr_map->source_term_displ[attr]);
1348 }
1349 
1350 /*----------------------------------------------------------------------------*/
1351 /*!
1352  * \brief Get pointer to 2nd order scheme attribute source terms of a particle.
1353  *
1354  * \param[in]  particle  pointer to particle data
1355  * \param[in]  attr_map  pointer to attribute map
1356  * \param[in]  attr      requested attribute id
1357  *
1358  * \return  pointer to attribute source terms
1359  */
1360 /*----------------------------------------------------------------------------*/
1361 
1362 inline static const cs_real_t *
cs_lagr_particle_source_term_const(void * particle,const cs_lagr_attribute_map_t * attr_map,cs_lagr_attribute_t attr)1363 cs_lagr_particle_source_term_const(void                           *particle,
1364                                    const cs_lagr_attribute_map_t  *attr_map,
1365                                    cs_lagr_attribute_t             attr)
1366 {
1367   assert(attr_map->source_term_displ != NULL);
1368   assert(attr_map->source_term_displ[attr] >= 0);
1369 
1370   return  (const cs_real_t *)(  (unsigned char *)particle
1371                               + attr_map->source_term_displ[attr]);
1372 }
1373 
1374 /*----------------------------------------------------------------------------
1375  * Resize particle set buffers if needed.
1376  *
1377  * parameters:
1378  *   n_particles <-- minumum number of particles required
1379  *
1380  *
1381  * returns:
1382  *   1 if resizing was required, 0 otherwise
1383  *----------------------------------------------------------------------------*/
1384 
1385 int
1386 cs_lagr_particle_set_resize(cs_lnum_t  n_min_particles);
1387 
1388 /*----------------------------------------------------------------------------
1389  * Set reallocation factor for particle sets.
1390  *
1391  * This factor determines the multiplier used for reallocations when
1392  * the particle set's buffers are too small to handle the new number of
1393  * particles.
1394  *
1395  * parameters:
1396  *  f <-- reallocation size multiplier
1397  *----------------------------------------------------------------------------*/
1398 
1399 void
1400 cs_lagr_set_reallocation_factor(double f);
1401 
1402 /*----------------------------------------------------------------------------*/
1403 /*!
1404  * \brief Get global maximum number of particles.
1405  *
1406  * By default, the number is limited only by local \ref cs_lnum_t and global
1407  * \ref cs_gnum_t data representation limits.
1408  *
1409  * \return  global maximum number of particles
1410  */
1411 /*----------------------------------------------------------------------------*/
1412 
1413 unsigned long long
1414 cs_lagr_get_n_g_particles_max(void);
1415 
1416 /*----------------------------------------------------------------------------*/
1417 /*!
1418  * \brief Set global maximum number of particles.
1419  *
1420  * By default, the number is limited only by local \ref cs_lnum_t and global
1421  * \ref cs_gnum_t data representation limits.
1422  *
1423  * \param[in]  n_g_particles_max  global maximum number of particles
1424  */
1425 /*----------------------------------------------------------------------------*/
1426 
1427 void
1428 cs_lagr_set_n_g_particles_max(unsigned long long  n_g_particles_max);
1429 
1430 /*----------------------------------------------------------------------------*/
1431 /*!
1432  * \brief Copy current attributes to previous attributes.
1433  *
1434  * \param[in, out]  particles     associated particle set
1435  * \param[in]       particle_id  id of particle
1436  */
1437 /*----------------------------------------------------------------------------*/
1438 
1439 void
1440 cs_lagr_particles_current_to_previous(cs_lagr_particle_set_t  *particles,
1441                                       cs_lnum_t                particle_id);
1442 
1443 /*----------------------------------------------------------------------------*/
1444 /*!
1445  * \brief Dump a cs_lagr_particle_set_t structure
1446  *
1447  * \param[in]  particles  cs_lagr_particle_t structure to dump
1448  */
1449 /*----------------------------------------------------------------------------*/
1450 
1451 void
1452 cs_lagr_particle_set_dump(const cs_lagr_particle_set_t  *particles);
1453 
1454 /*----------------------------------------------------------------------------*/
1455 /*!
1456  * \brief Set number of user particle variables.
1457  *
1458  * \param[in]  n_user_variables  number of user variables
1459  */
1460 /*----------------------------------------------------------------------------*/
1461 
1462 void
1463 cs_lagr_set_n_user_variables(int  n_user_variables);
1464 
1465 /*----------------------------------------------------------------------------*/
1466 
1467 END_C_DECLS
1468 
1469 #endif /* __CS_LAGR_PARTICLE_H__ */
1470