My Project
programmer's 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-2019 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 
87 typedef enum {
88 
96  /* End of event attributes */
97 
99 
101 
103 /* ------------------------------------- */
104 
105 typedef 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 
130 typedef 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 /*----------------------------------------------------------------------------*/
155 /*----------------------------------------------------------------------------*/
156 
157 void
159 
160 /*----------------------------------------------------------------------------*/
164 /*----------------------------------------------------------------------------*/
165 
166 void
168 
169 /*----------------------------------------------------------------------------*/
175 /*----------------------------------------------------------------------------*/
176 
179 
180 /*----------------------------------------------------------------------------*/
186 /*----------------------------------------------------------------------------*/
187 
188 const char *
190 
191 /*----------------------------------------------------------------------------*/
197 /*----------------------------------------------------------------------------*/
198 
201 
202 /*----------------------------------------------------------------------------*/
208 /*----------------------------------------------------------------------------*/
209 
210 void
212 
213 /*----------------------------------------------------------------------------*/
231 /*----------------------------------------------------------------------------*/
232 
233 void
236  size_t *extents,
237  size_t *size,
238  ptrdiff_t *displ,
239  cs_datatype_t *datatype,
240  int *count);
241 
242 /*----------------------------------------------------------------------------*/
250 /*----------------------------------------------------------------------------*/
251 
252 void
254 
255 /*----------------------------------------------------------------------------*/
265 /*----------------------------------------------------------------------------*/
266 
267 inline static void *
269  cs_lnum_t event_id,
271 {
272  assert(event_set->e_am->count[attr] > 0);
273 
274  return (unsigned char *)event_set->e_buffer
275  + event_set->e_am->extents*event_id
276  + event_set->e_am->displ[attr];
277 }
278 
279 /*----------------------------------------------------------------------------*/
290 /*----------------------------------------------------------------------------*/
291 
292 inline static const void *
294  cs_lnum_t event_id,
296 {
297  assert(event_set->e_am->count[attr] > 0);
298 
299  return event_set->e_buffer
300  + event_set->e_am->extents*event_id
301  + event_set->e_am->displ[attr];
302 }
303 
304 /*----------------------------------------------------------------------------*/
314 /*----------------------------------------------------------------------------*/
315 
316 inline static cs_lnum_t
318  cs_lnum_t event_id,
320 {
321  assert(event_set->e_am->count[attr] > 0);
322 
323  return *((const cs_lnum_t *)( event_set->e_buffer
324  + event_set->e_am->extents*event_id
325  + event_set->e_am->displ[attr]));
326 }
327 
328 /*----------------------------------------------------------------------------*/
337 /*----------------------------------------------------------------------------*/
338 
339 inline static void
341  cs_lnum_t event_id,
343  cs_lnum_t value)
344 {
345  assert(event_set->e_am->count[attr] > 0);
346 
347  *((cs_lnum_t *)( event_set->e_buffer
348  + event_set->e_am->extents*event_id
349  + event_set->e_am->displ[attr])) = value;
350 }
351 
352 /*----------------------------------------------------------------------------*/
362 /*----------------------------------------------------------------------------*/
363 
364 inline static cs_real_t
366  cs_lnum_t event_id,
368 {
369  assert(event_set->e_am->count[attr] > 0);
370 
371  return *((const cs_real_t *)( event_set->e_buffer
372  + event_set->e_am->extents*event_id
373  + event_set->e_am->displ[attr]));
374 }
375 
376 /*----------------------------------------------------------------------------*/
385 /*----------------------------------------------------------------------------*/
386 
387 inline static void
389  cs_lnum_t event_id,
391  cs_real_t value)
392 {
393  assert(event_set->e_am->count[attr] > 0);
394 
395  *((cs_real_t *)( event_set->e_buffer
396  + event_set->e_am->extents*event_id
397  + event_set->e_am->displ[attr])) = value;
398 }
399 
400 /*----------------------------------------------------------------------------
401  * Resize event set buffers if needed.
402  *
403  * \param[in, out] event_set pointer to event set
404  * \param[in] mini mum required
405  *----------------------------------------------------------------------------*/
406 
407 void
409  cs_lnum_t min_size);
410 
411 /*----------------------------------------------------------------------------*/
417 /*----------------------------------------------------------------------------*/
418 
419 void
421 
422 /*----------------------------------------------------------------------------
423  * Resize event set buffers if needed.
424  *
425  * \param[in, out] events pointer to event set
426  * \param[in, out] particles pointer to particle set
427  * \param[in] event_id event id
428  * \param[in] particle_id particle id
429  *----------------------------------------------------------------------------*/
430 
431 void
433  cs_lagr_particle_set_t *particles,
434  cs_lnum_t event_id,
435  cs_lnum_t particle_id);
436 
437 /*----------------------------------------------------------------------------*/
448 /*----------------------------------------------------------------------------*/
449 
452 
453 /*----------------------------------------------------------------------------*/
454 
456 
457 #endif /* __CS_LAGR_EVENT_H__ */
cs_lagr_event_get_attr_map
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.c:527
cs_defs.h
cs_lagr_events_attr
static void * cs_lagr_events_attr(cs_lagr_event_set_t *event_set, cs_lnum_t event_id, cs_lagr_event_attribute_t attr)
Get pointer to a current attribute of a given event in a set.
Definition: cs_lagr_event.h:268
cs_lagr_event_set_t::n_events_max
cs_lnum_t n_events_max
Definition: cs_lagr_event.h:133
cs_lagr_events_get_lnum
static cs_lnum_t cs_lagr_events_get_lnum(const cs_lagr_event_set_t *event_set, cs_lnum_t event_id, cs_lagr_event_attribute_t attr)
Get attribute value of type cs_lnum_t of a given event in a set.
Definition: cs_lagr_event.h:317
cs_lagr_event_set_destroy
void cs_lagr_event_set_destroy(cs_lagr_event_set_t **events)
Definition: cs_lagr_event.c:589
CS_LAGR_N_E_ATTRIBUTES
Definition: cs_lagr_event.h:98
cs_lagr_event_finalize
void cs_lagr_event_finalize(void)
Destroy event set map if it exists.
Definition: cs_lagr_event.c:506
CS_LAGR_E_CELL_ID
Definition: cs_lagr_event.h:90
CS_LAGR_E_FLAG
Definition: cs_lagr_event.h:89
cs_lagr_event_set_boundary_interaction
cs_lagr_event_set_t * cs_lagr_event_set_boundary_interaction(void)
Definition: cs_lagr_event.c:769
CS_LAGR_E_FACE_ID
Definition: cs_lagr_event.h:91
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
cs_lagr_event_get_attr_name
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.c:542
cs_lagr_particle_set_t
Definition: cs_lagr_particle.h:210
cs_lagr_event_set_t::e_am
const cs_lagr_event_attribute_map_t * e_am
Definition: cs_lagr_event.h:135
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
cs_lagr_event_attribute_map_t::count
int count[CS_LAGR_N_E_ATTRIBUTES]
Definition: cs_lagr_event.h:119
cs_lagr_event_set_create
cs_lagr_event_set_t * cs_lagr_event_set_create(void)
Definition: cs_lagr_event.c:568
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_datatype_t
cs_datatype_t
Definition: cs_defs.h:260
cs_lagr_event_set_t::e_buffer
unsigned char * e_buffer
Definition: cs_lagr_event.h:136
cs_lagr_particle.h
cs_lagr_event_set_t::n_events
cs_lnum_t n_events
Definition: cs_lagr_event.h:132
cs_lagr_event_get_attr_info
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.c:621
cs_lagr_event_set_dump
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.c:692
CS_LAGR_N_ATTRIBUTES
Definition: cs_lagr_particle.h:169
cs_lagr_event_attribute_map_t
Definition: cs_lagr_event.h:105
cs_lagr_events_set_lnum
static void cs_lagr_events_set_lnum(cs_lagr_event_set_t *event_set, cs_lnum_t event_id, cs_lagr_event_attribute_t 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:340
cs_lagr_event_attribute_t
cs_lagr_event_attribute_t
Definition: cs_lagr_event.h:87
cs_lagr_event_initialize
void cs_lagr_event_initialize(void)
Define event map based on defined options.
Definition: cs_lagr_event.c:390
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_lagr_event_attr_in_range
void cs_lagr_event_attr_in_range(int attr)
Check if an event attribute is in a valid range.
Definition: cs_lagr_event.c:652
cs_lagr_event_set_resize
void cs_lagr_event_set_resize(cs_lagr_event_set_t *event_set, cs_lnum_t min_size)
Definition: cs_lagr_event.c:668
cs_lagr_event_set_t
Definition: cs_lagr_event.h:130
cs_lagr_event_attribute_map_t::displ
ptrdiff_t displ[CS_LAGR_N_E_ATTRIBUTES]
Definition: cs_lagr_event.h:121
CS_LAGR_E_VELOCITY
Definition: cs_lagr_event.h:94
cs_lagr_event_init_from_particle
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.c:721
cs_lagr_event_attribute_map_t::lb
size_t lb
Definition: cs_lagr_event.h:109
cs_lagr_events_attr_const
static const void * cs_lagr_events_attr_const(const cs_lagr_event_set_t *event_set, cs_lnum_t event_id, cs_lagr_event_attribute_t attr)
Get const pointer to current attribute data of a given event in a set.
Definition: cs_lagr_event.h:293
cs_lagr_event_attribute_map_t::extents
size_t extents
Definition: cs_lagr_event.h:107
cs_lagr_events_set_real
static void cs_lagr_events_set_real(cs_lagr_event_set_t *event_set, cs_lnum_t event_id, cs_lagr_event_attribute_t 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:388
cs_lagr_events_get_real
static cs_real_t cs_lagr_events_get_real(const cs_lagr_event_set_t *event_set, cs_lnum_t event_id, cs_lagr_event_attribute_t attr)
Get attribute value of type cs_real_t of a given event in a set.
Definition: cs_lagr_event.h:365