8.3
general documentation
cs_lagr_event.h
Go to the documentation of this file.
1#ifndef __CS_LAGR_EVENT_H__
2#define __CS_LAGR_EVENT_H__
3
4/*============================================================================
5 * Lagrangian particle event model
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2024 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/*----------------------------------------------------------------------------
31 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "cs_defs.h"
35
36#include "cs_lagr_particle.h"
37
38#include "assert.h"
39
40/*----------------------------------------------------------------------------*/
41
43
44/*=============================================================================
45 * Macro definitions
46 *============================================================================*/
47
53#define CS_EVENT_INFLOW (1 << 0)
54
56#define CS_EVENT_OUTFLOW (1 << 1)
57
59#define CS_EVENT_REBOUND (1 << 2)
60
62#define CS_EVENT_DEPOSITION (1 << 3)
63
65#define CS_EVENT_RESUSPENSION (1 << 4)
66
68#define CS_EVENT_ROLL_OFF (1 << 5)
69
71#define CS_EVENT_ROLL_ON (1 << 6)
72
74#define CS_EVENT_FOULING (1 << 7)
75
76/*============================================================================
77 * Type definitions
78 *============================================================================*/
79
81/* ----------------------------- */
82
83/* Numbering of predefined attributes starts after particle attributes,
84 so that particle attribute can be added to mapped variables traced
85 a particle events */
86
87typedef enum {
88
96 /* End of event attributes */
97
99
101
103/* ------------------------------------- */
104
105typedef struct {
106
107 size_t extents; /* size (in bytes) of event
108 structure */
109 size_t lb; /* size (in bytes) of lower
110 bounds of event data
111 (work area before) */
112
113 size_t size[CS_LAGR_N_E_ATTRIBUTES]; /* size (in bytes) of
114 attributes in event
115 structure for a given
116 time value */
117 cs_datatype_t datatype[CS_LAGR_N_E_ATTRIBUTES]; /* datatype of associated
118 attributes */
119 int count[CS_LAGR_N_E_ATTRIBUTES]; /* number of values for each
120 attribute */
121 ptrdiff_t displ[CS_LAGR_N_E_ATTRIBUTES]; /* displacement (in bytes)
122 of attributes in event
123 data */
124
126
127/* Event set */
128/* ------------ */
129
130typedef struct {
131
132 cs_lnum_t n_events; /* number of events */
134
136 unsigned char *e_buffer;
139
140/*=============================================================================
141 * Global variables
142 *============================================================================*/
143
144/*============================================================================
145 * Public function prototypes
146 *============================================================================*/
147
148/*----------------------------------------------------------------------------*/
156/*----------------------------------------------------------------------------*/
157
158void
160
161/*----------------------------------------------------------------------------*/
165/*----------------------------------------------------------------------------*/
166
167void
169
170/*----------------------------------------------------------------------------*/
176/*----------------------------------------------------------------------------*/
177
180
181/*----------------------------------------------------------------------------*/
187/*----------------------------------------------------------------------------*/
188
189const char *
191
192/*----------------------------------------------------------------------------*/
198/*----------------------------------------------------------------------------*/
199
202
203/*----------------------------------------------------------------------------*/
209/*----------------------------------------------------------------------------*/
210
211void
213
214/*----------------------------------------------------------------------------*/
232/*----------------------------------------------------------------------------*/
233
234void
237 size_t *extents,
238 size_t *size,
239 ptrdiff_t *displ,
240 cs_datatype_t *datatype,
241 int *count);
242
243/*----------------------------------------------------------------------------*/
251/*----------------------------------------------------------------------------*/
252
253void
255
256/*----------------------------------------------------------------------------*/
266/*----------------------------------------------------------------------------*/
267
268inline static void *
270 cs_lnum_t event_id,
271 int attr)
272{
273 assert(event_set->e_am->count[attr] > 0);
274
275 return (unsigned char *)event_set->e_buffer
276 + event_set->e_am->extents*event_id
277 + event_set->e_am->displ[attr];
278}
279
280/*----------------------------------------------------------------------------*/
291/*----------------------------------------------------------------------------*/
292
293inline static const void *
295 cs_lnum_t event_id,
296 int attr)
297{
298 assert(event_set->e_am->count[attr] > 0);
299
300 return event_set->e_buffer
301 + event_set->e_am->extents*event_id
302 + event_set->e_am->displ[attr];
303}
304
305/*----------------------------------------------------------------------------*/
306/*----------------------------------------------------------------------------*/
307
309
310#if defined(__cplusplus)
311template <typename T>
312T *
313cs_lagr_events_attr_get_ptr(cs_lagr_event_set_t *event_set,
314 cs_lnum_t event_id,
315 int attr)
316{
317 assert(event_set->e_am->count[attr] > 0);
318
319 return (T *)( event_set->e_buffer
320 + event_set->e_am->extents*event_id
321 + event_set->e_am->displ[attr]);
322}
323
324template <typename T>
325const T *
326cs_lagr_events_attr_get_const_ptr(const cs_lagr_event_set_t *event_set,
327 cs_lnum_t event_id,
328 int attr)
329{
330 assert(event_set->e_am->count[attr] > 0);
331
332 return (const T *)( event_set->e_buffer
333 + event_set->e_am->extents*event_id
334 + event_set->e_am->displ[attr]);
335}
336
337template <typename T>
338T
339cs_lagr_events_attr_get_val(const cs_lagr_event_set_t *event_set,
340 cs_lnum_t event_id,
341 int attr)
342{
343 assert(event_set->e_am->count[attr] > 0);
344
345 return *((const T *)( event_set->e_buffer
346 + event_set->e_am->extents*event_id
347 + event_set->e_am->displ[attr]));
348}
349
350template <typename T>
351void
352cs_lagr_events_attr_set_val(cs_lagr_event_set_t *event_set,
353 cs_lnum_t event_id,
354 int attr,
355 T value)
356{
357 assert(event_set->e_am->count[attr] > 0);
358
359 *((T *)( event_set->e_buffer
360 + event_set->e_am->extents*event_id
361 + event_set->e_am->displ[attr])) = value;
362}
363#endif
364
366
367/*----------------------------------------------------------------------------*/
377/*----------------------------------------------------------------------------*/
378
379inline static cs_lnum_t
381 cs_lnum_t event_id,
382 int attr)
383{
384 assert(event_set->e_am->count[attr] > 0);
385
386 return *((const cs_lnum_t *)( event_set->e_buffer
387 + event_set->e_am->extents*event_id
388 + event_set->e_am->displ[attr]));
389}
390
391/*----------------------------------------------------------------------------*/
400/*----------------------------------------------------------------------------*/
401
402inline static void
404 cs_lnum_t event_id,
405 int attr,
406 cs_lnum_t value)
407{
408 assert(event_set->e_am->count[attr] > 0);
409
410 *((cs_lnum_t *)( event_set->e_buffer
411 + event_set->e_am->extents*event_id
412 + event_set->e_am->displ[attr])) = value;
413}
414
415/*----------------------------------------------------------------------------*/
425/*----------------------------------------------------------------------------*/
426
427inline static cs_real_t
429 cs_lnum_t event_id,
430 int attr)
431{
432 assert(event_set->e_am->count[attr] > 0);
433
434 return *((const cs_real_t *)( event_set->e_buffer
435 + event_set->e_am->extents*event_id
436 + event_set->e_am->displ[attr]));
437}
438
439/*----------------------------------------------------------------------------*/
448/*----------------------------------------------------------------------------*/
449
450inline static void
452 cs_lnum_t event_id,
453 int attr,
454 cs_real_t value)
455{
456 assert(event_set->e_am->count[attr] > 0);
457
458 *((cs_real_t *)( event_set->e_buffer
459 + event_set->e_am->extents*event_id
460 + event_set->e_am->displ[attr])) = value;
461}
462
463/*----------------------------------------------------------------------------
464 * Resize event set buffers if needed.
465 *
466 * \param[in, out] event_set pointer to event set
467 * \param[in] mini mum required
468 *----------------------------------------------------------------------------*/
469
470void
472 cs_lnum_t min_size);
473
474/*----------------------------------------------------------------------------*/
480/*----------------------------------------------------------------------------*/
481
482void
484
485/*----------------------------------------------------------------------------
486 * Resize event set buffers if needed.
487 *
488 * \param[in, out] events pointer to event set
489 * \param[in, out] particles pointer to particle set
490 * \param[in] event_id event id
491 * \param[in] particle_id particle id
492 *----------------------------------------------------------------------------*/
493
494void
496 cs_lagr_particle_set_t *particles,
497 cs_lnum_t event_id,
498 cs_lnum_t particle_id);
499
500/*----------------------------------------------------------------------------*/
511/*----------------------------------------------------------------------------*/
512
515
516/*----------------------------------------------------------------------------*/
517
519
520#endif /* __CS_LAGR_EVENT_H__ */
cs_datatype_t
Definition: cs_defs.h:300
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
double cs_real_t
Floating-point value.
Definition: cs_defs.h:342
#define END_C_DECLS
Definition: cs_defs.h:543
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335
void cs_lagr_event_finalize(void)
Destroy event set map if it exists.
Definition: cs_lagr_event.cpp:520
void cs_lagr_event_set_dump(const cs_lagr_event_set_t *events)
Dump a cs_lagr_event_set_t structure.
Definition: cs_lagr_event.cpp:706
static cs_real_t cs_lagr_events_get_real(const cs_lagr_event_set_t *event_set, cs_lnum_t event_id, int attr)
Get attribute value of type cs_real_t of a given event in a set.
Definition: cs_lagr_event.h:428
static const void * cs_lagr_events_attr_const(const cs_lagr_event_set_t *event_set, cs_lnum_t event_id, int attr)
Get const pointer to current attribute data of a given event in a set.
Definition: cs_lagr_event.h:294
void cs_lagr_event_attr_in_range(int attr)
Check if an event attribute is in a valid range.
Definition: cs_lagr_event.cpp:666
static void cs_lagr_events_set_real(cs_lagr_event_set_t *event_set, cs_lnum_t event_id, int attr, cs_real_t value)
Set attribute value of type cs_real_t of a given event in a set.
Definition: cs_lagr_event.h:451
cs_lagr_event_set_t * cs_lagr_event_set_create(void)
Definition: cs_lagr_event.cpp:582
const cs_lagr_event_attribute_map_t * cs_lagr_event_get_attr_map(void)
Return const pointer to the main event attribute map structure.
Definition: cs_lagr_event.cpp:541
void cs_lagr_event_get_attr_info(const cs_lagr_event_set_t *events, cs_lagr_event_attribute_t attr, size_t *extents, size_t *size, ptrdiff_t *displ, cs_datatype_t *datatype, int *count)
Get data extents for a given event attribute.
Definition: cs_lagr_event.cpp:635
void cs_lagr_event_set_resize(cs_lagr_event_set_t *event_set, cs_lnum_t min_size)
Definition: cs_lagr_event.cpp:682
cs_lagr_event_attribute_t
Definition: cs_lagr_event.h:87
@ CS_LAGR_N_E_ATTRIBUTES
Definition: cs_lagr_event.h:98
@ CS_LAGR_E_FACE_ID
Definition: cs_lagr_event.h:91
@ CS_LAGR_E_FLAG
Definition: cs_lagr_event.h:89
@ CS_LAGR_E_CELL_ID
Definition: cs_lagr_event.h:90
@ CS_LAGR_E_VELOCITY
Definition: cs_lagr_event.h:94
static cs_lnum_t cs_lagr_events_get_lnum(const cs_lagr_event_set_t *event_set, cs_lnum_t event_id, int attr)
Get attribute value of type cs_lnum_t of a given event in a set.
Definition: cs_lagr_event.h:380
cs_lagr_event_set_t * cs_lagr_event_set_boundary_interaction(void)
Definition: cs_lagr_event.cpp:783
const char * cs_lagr_event_get_attr_name(cs_lagr_event_attribute_t attr)
Return name associated with a given attribute.
Definition: cs_lagr_event.cpp:556
void cs_lagr_event_initialize(void)
Define event map based on defined options.
Definition: cs_lagr_event.cpp:397
static void * cs_lagr_events_attr(cs_lagr_event_set_t *event_set, cs_lnum_t event_id, int attr)
Get pointer to a current attribute of a given event in a set.
Definition: cs_lagr_event.h:269
static void cs_lagr_events_set_lnum(cs_lagr_event_set_t *event_set, cs_lnum_t event_id, int attr, cs_lnum_t value)
Set attribute value of type cs_lnum_t of a given event in a set.
Definition: cs_lagr_event.h:403
void cs_lagr_event_set_destroy(cs_lagr_event_set_t **events)
Definition: cs_lagr_event.cpp:603
void cs_lagr_event_init_from_particle(cs_lagr_event_set_t *events, cs_lagr_particle_set_t *particles, cs_lnum_t event_id, cs_lnum_t particle_id)
Definition: cs_lagr_event.cpp:735
@ CS_LAGR_N_ATTRIBUTES
Definition: cs_lagr_particle.h:182
Definition: cs_lagr_event.h:105
ptrdiff_t displ[CS_LAGR_N_E_ATTRIBUTES]
Definition: cs_lagr_event.h:121
size_t lb
Definition: cs_lagr_event.h:109
int count[CS_LAGR_N_E_ATTRIBUTES]
Definition: cs_lagr_event.h:119
size_t extents
Definition: cs_lagr_event.h:107
Definition: cs_lagr_event.h:130
cs_lnum_t n_events_max
Definition: cs_lagr_event.h:133
const cs_lagr_event_attribute_map_t * e_am
Definition: cs_lagr_event.h:135
unsigned char * e_buffer
Definition: cs_lagr_event.h:136
cs_lnum_t n_events
Definition: cs_lagr_event.h:132
Definition: cs_lagr_particle.h:223