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-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 /*----------------------------------------------------------------------------
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
42 BEGIN_C_DECLS
43
44 /*=============================================================================
45 * Macro definitions
46 *============================================================================*/
47
48 /*!
49 * Flags specifying general event attributes
50 */
51
52 /*! inflow event */
53 #define CS_EVENT_INFLOW (1 << 0)
54
55 /*! outflow event */
56 #define CS_EVENT_OUTFLOW (1 << 1)
57
58 /*! rebound on wall */
59 #define CS_EVENT_REBOUND (1 << 2)
60
61 /*! deposistion event */
62 #define CS_EVENT_DEPOSITION (1 << 3)
63
64 /*! resuspension event */
65 #define CS_EVENT_RESUSPENSION (1 << 4)
66
67 /*! roll off */
68 #define CS_EVENT_ROLL_OFF (1 << 5)
69
70 /*! roll on */
71 #define CS_EVENT_ROLL_ON (1 << 6)
72
73 /*! fouling */
74 #define CS_EVENT_FOULING (1 << 7)
75
76 /*============================================================================
77 * Type definitions
78 *============================================================================*/
79
80 /*! Prefedined event attributes */
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
89 CS_LAGR_E_FLAG = CS_LAGR_N_ATTRIBUTES, /*!< local flag */
90 CS_LAGR_E_CELL_ID, /*!< local cell id */
91 CS_LAGR_E_FACE_ID, /*!< local face id
92 (-1 if not on boundary) */
93
94 CS_LAGR_E_VELOCITY, /*!< velocity following event */
95
96 /* End of event attributes */
97
98 CS_LAGR_N_E_ATTRIBUTES
99
100 } cs_lagr_event_attribute_t;
101
102 /*! Event attribute structure mapping */
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
125 } cs_lagr_event_attribute_map_t;
126
127 /* Event set */
128 /* ------------ */
129
130 typedef struct {
131
132 cs_lnum_t n_events; /* number of events */
133 cs_lnum_t n_events_max;
134
135 const cs_lagr_event_attribute_map_t *e_am; /*!< event attributes map */
136 unsigned char *e_buffer; /*!< Events data buffer */
137
138 } cs_lagr_event_set_t;
139
140 /*=============================================================================
141 * Global variables
142 *============================================================================*/
143
144 /*============================================================================
145 * Public function prototypes
146 *============================================================================*/
147
148 /*----------------------------------------------------------------------------*/
149 /*!
150 * \brief Define event map based on defined options.
151 *
152 * This function should only be called after
153 * \ref cs_lagr_particle_attr_initialize,
154 * as it may use elements from the main particle attributes map.
155 */
156 /*----------------------------------------------------------------------------*/
157
158 void
159 cs_lagr_event_initialize(void);
160
161 /*----------------------------------------------------------------------------*/
162 /*!
163 * \brief Destroy event set map if it exists.
164 */
165 /*----------------------------------------------------------------------------*/
166
167 void
168 cs_lagr_event_finalize(void);
169
170 /*----------------------------------------------------------------------------*/
171 /*!
172 * \brief Return const pointer to the main event attribute map structure.
173 *
174 * \return pointer to current event attribute map, or NULL
175 */
176 /*----------------------------------------------------------------------------*/
177
178 const cs_lagr_event_attribute_map_t *
179 cs_lagr_event_get_attr_map(void);
180
181 /*----------------------------------------------------------------------------*/
182 /*!
183 * \brief Return name associated with a given attribute.
184 *
185 * \param[in] attr event attribute
186 */
187 /*----------------------------------------------------------------------------*/
188
189 const char *
190 cs_lagr_event_get_attr_name(cs_lagr_event_attribute_t attr);
191
192 /*----------------------------------------------------------------------------*/
193 /*!
194 * Create a cs_lagr_event_set_t structure.
195 *
196 * \return pointer to event set
197 */
198 /*----------------------------------------------------------------------------*/
199
200 cs_lagr_event_set_t *
201 cs_lagr_event_set_create(void);
202
203 /*----------------------------------------------------------------------------*/
204 /*!
205 * Destroy a cs_lagr_event_set_t structure.
206 *
207 * \param[in, out] events pointer to pointer to event set to destroy
208 */
209 /*----------------------------------------------------------------------------*/
210
211 void
212 cs_lagr_event_set_destroy(cs_lagr_event_set_t **events);
213
214 /*----------------------------------------------------------------------------*/
215 /*!
216 * \brief Get data extents for a given event attribute.
217 *
218 * For attributes not currently present, the displacement and data
219 * size should be -1 and 0 respectively.
220 *
221 * \param[in] events associated event set
222 * \param[in] attr event attribute
223 * \param[out] extents size (in bytes) of event structure, or NULL
224 * \param[out] size size (in bytes) of attribute in event structure,
225 * or NULL
226 * \param[out] displ displacement (in bytes) in event structure,
227 * or NULL
228 * \param[out] datatype datatype of associated attribute, or NULL
229 * \param[out] count number of type values associated with attribute,
230 * or NULL
231 */
232 /*----------------------------------------------------------------------------*/
233
234 void
235 cs_lagr_event_get_attr_info(const cs_lagr_event_set_t *events,
236 cs_lagr_event_attribute_t attr,
237 size_t *extents,
238 size_t *size,
239 ptrdiff_t *displ,
240 cs_datatype_t *datatype,
241 int *count);
242
243 /*----------------------------------------------------------------------------*/
244 /*!
245 * \brief Check if an event attribute is in a valid range.
246 *
247 * If this is not the case, a fatal error is provoked.
248
249 * \param[in] attr event attribute
250 */
251 /*----------------------------------------------------------------------------*/
252
253 void
254 cs_lagr_event_attr_in_range(int attr);
255
256 /*----------------------------------------------------------------------------*/
257 /*!
258 * \brief Get pointer to a current attribute of a given event in a set.
259 *
260 * \param[in] event_set pointer to event set
261 * \param[in] event_id event id
262 * \param[in] attr requested attribute id
263 *
264 * \return pointer to current attribute data
265 */
266 /*----------------------------------------------------------------------------*/
267
268 inline static void *
cs_lagr_events_attr(cs_lagr_event_set_t * event_set,cs_lnum_t event_id,cs_lagr_event_attribute_t attr)269 cs_lagr_events_attr(cs_lagr_event_set_t *event_set,
270 cs_lnum_t event_id,
271 cs_lagr_event_attribute_t 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 /*----------------------------------------------------------------------------*/
281 /*!
282 * \brief Get const pointer to current attribute data
283 * of a given event in a set.
284 *
285 * \param[in] event_set pointer to event set
286 * \param[in] event_id event id
287 * \param[in] attr requested attribute id
288 *
289 * \return pointer to current attribute data
290 */
291 /*----------------------------------------------------------------------------*/
292
293 inline 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)294 cs_lagr_events_attr_const(const cs_lagr_event_set_t *event_set,
295 cs_lnum_t event_id,
296 cs_lagr_event_attribute_t 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 * \brief Get attribute value of type cs_lnum_t of a given event in a set.
308 *
309 * \param[in] event_set pointer to event set
310 * \param[in] event_id event id
311 * \param[in] attr requested attribute id
312 *
313 * \return attribute value
314 */
315 /*----------------------------------------------------------------------------*/
316
317 inline 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)318 cs_lagr_events_get_lnum(const cs_lagr_event_set_t *event_set,
319 cs_lnum_t event_id,
320 cs_lagr_event_attribute_t attr)
321 {
322 assert(event_set->e_am->count[attr] > 0);
323
324 return *((const cs_lnum_t *)( event_set->e_buffer
325 + event_set->e_am->extents*event_id
326 + event_set->e_am->displ[attr]));
327 }
328
329 /*----------------------------------------------------------------------------*/
330 /*!
331 * \brief Set attribute value of type cs_lnum_t of a given event in a set.
332 *
333 * \param[in, out] event_set pointer to event set
334 * \param[in] event_id event id
335 * \param[in] attr requested attribute id
336 * \param[in] value value to assign
337 */
338 /*----------------------------------------------------------------------------*/
339
340 inline 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)341 cs_lagr_events_set_lnum(cs_lagr_event_set_t *event_set,
342 cs_lnum_t event_id,
343 cs_lagr_event_attribute_t attr,
344 cs_lnum_t value)
345 {
346 assert(event_set->e_am->count[attr] > 0);
347
348 *((cs_lnum_t *)( event_set->e_buffer
349 + event_set->e_am->extents*event_id
350 + event_set->e_am->displ[attr])) = value;
351 }
352
353 /*----------------------------------------------------------------------------*/
354 /*!
355 * \brief Get attribute value of type cs_real_t of a given event in a set.
356 *
357 * \param[in] event_set pointer to event set
358 * \param[in] event_id event id
359 * \param[in] attr requested attribute id
360 *
361 * \return attribute value
362 */
363 /*----------------------------------------------------------------------------*/
364
365 inline 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)366 cs_lagr_events_get_real(const cs_lagr_event_set_t *event_set,
367 cs_lnum_t event_id,
368 cs_lagr_event_attribute_t attr)
369 {
370 assert(event_set->e_am->count[attr] > 0);
371
372 return *((const cs_real_t *)( event_set->e_buffer
373 + event_set->e_am->extents*event_id
374 + event_set->e_am->displ[attr]));
375 }
376
377 /*----------------------------------------------------------------------------*/
378 /*!
379 * \brief Set attribute value of type cs_real_t of a given event in a set.
380 *
381 * \param[in, out] event_set pointer to event set
382 * \param[in] event_id event id
383 * \param[in] attr requested attribute id
384 * \param[in] value value to assign
385 */
386 /*----------------------------------------------------------------------------*/
387
388 inline 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)389 cs_lagr_events_set_real(cs_lagr_event_set_t *event_set,
390 cs_lnum_t event_id,
391 cs_lagr_event_attribute_t attr,
392 cs_real_t value)
393 {
394 assert(event_set->e_am->count[attr] > 0);
395
396 *((cs_real_t *)( event_set->e_buffer
397 + event_set->e_am->extents*event_id
398 + event_set->e_am->displ[attr])) = value;
399 }
400
401 /*----------------------------------------------------------------------------
402 * Resize event set buffers if needed.
403 *
404 * \param[in, out] event_set pointer to event set
405 * \param[in] mini mum required
406 *----------------------------------------------------------------------------*/
407
408 void
409 cs_lagr_event_set_resize(cs_lagr_event_set_t *event_set,
410 cs_lnum_t min_size);
411
412 /*----------------------------------------------------------------------------*/
413 /*!
414 * \brief Dump a cs_lagr_event_set_t structure
415 *
416 * \param[in] events cs_lagr_event_t structure to dump
417 */
418 /*----------------------------------------------------------------------------*/
419
420 void
421 cs_lagr_event_set_dump(const cs_lagr_event_set_t *events);
422
423 /*----------------------------------------------------------------------------
424 * Resize event set buffers if needed.
425 *
426 * \param[in, out] events pointer to event set
427 * \param[in, out] particles pointer to particle set
428 * \param[in] event_id event id
429 * \param[in] particle_id particle id
430 *----------------------------------------------------------------------------*/
431
432 void
433 cs_lagr_event_init_from_particle(cs_lagr_event_set_t *events,
434 cs_lagr_particle_set_t *particles,
435 cs_lnum_t event_id,
436 cs_lnum_t particle_id);
437
438 /*----------------------------------------------------------------------------*/
439 /*!
440 * Return a cs_lagr_event_set_t structure for particle/boundary interactions.
441 *
442 * The event set is created if not present yet.
443 *
444 * This event set is automatically freed and destroyed at the end of the
445 * computation.
446 *
447 * \return pointer to event set
448 */
449 /*----------------------------------------------------------------------------*/
450
451 cs_lagr_event_set_t *
452 cs_lagr_event_set_boundary_interaction(void);
453
454 /*----------------------------------------------------------------------------*/
455
456 END_C_DECLS
457
458 #endif /* __CS_LAGR_EVENT_H__ */
459