1 #ifndef __CS_VOLUME_ZONE_H__
2 #define __CS_VOLUME_ZONE_H__
3 
4 /*============================================================================
5  * Volume zones handling.
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  * Standard C library headers
32  *----------------------------------------------------------------------------*/
33 
34 /*----------------------------------------------------------------------------
35  * Local headers
36  *----------------------------------------------------------------------------*/
37 
38 #include "cs_base.h"
39 #include "cs_mesh_location.h"
40 #include "cs_zone.h"
41 
42 /*----------------------------------------------------------------------------*/
43 
44 BEGIN_C_DECLS
45 
46 /*============================================================================
47  * Macro definitions
48  *============================================================================*/
49 
50 /*!
51  * @defgroup volume_zone_flags Flags specifying general volume zone type
52  *
53  * @{
54  */
55 
56 /*
57  * Zone type
58  */
59 
60 /*! initialization zone */
61 #define CS_VOLUME_ZONE_INITIALIZATION       (1 << 0)
62 
63 /*! porosity zone */
64 #define CS_VOLUME_ZONE_POROSITY             (1 << 1)
65 
66 /*! head loss zone */
67 #define CS_VOLUME_ZONE_HEAD_LOSS            (1 << 2)
68 
69 /*! source term (general) */
70 #define CS_VOLUME_ZONE_SOURCE_TERM          (1 << 3)
71 
72 /*! source term (mass) */
73 #define CS_VOLUME_ZONE_MASS_SOURCE_TERM     (1 << 4)
74 
75 /*! soil used in the groundwater flow module */
76 #define CS_VOLUME_ZONE_GWF_SOIL             (1 << 5)
77 
78 /*! zone defined as solid during the simulation */
79 #define CS_VOLUME_ZONE_SOLID                (1 << 6)
80 
81 /*! zone defined for physical propertiescomputation */
82 #define CS_VOLUME_ZONE_PHYSICAL_PROPERTIES  (1 << 7)
83 
84 /*! @} */
85 
86 /*============================================================================
87  * Type definitions
88  *============================================================================*/
89 
90 /*=============================================================================
91  * Global variables
92  *============================================================================*/
93 
94 /*============================================================================
95  * Public function prototypes
96  *============================================================================*/
97 
98 /*----------------------------------------------------------------------------*/
99 /*!
100  * \brief Initialize volume zone structures.
101  *
102  * This defines a default volume zone. This is the first function of
103  * the volume zone handling functions which should be called, and it should
104  * only be called after \ref cs_mesh_location_initialize.
105  */
106 /*----------------------------------------------------------------------------*/
107 
108 void
109 cs_volume_zone_initialize(void);
110 
111 /*----------------------------------------------------------------------------*/
112 /*!
113  * \brief Free all volume zone structures.
114  */
115 /*----------------------------------------------------------------------------*/
116 
117 void
118 cs_volume_zone_finalize(void);
119 
120 /*----------------------------------------------------------------------------*/
121 /*!
122  * \brief Return number of volume zones defined.
123  */
124 /*----------------------------------------------------------------------------*/
125 
126 int
127 cs_volume_zone_n_zones(void);
128 
129 /*----------------------------------------------------------------------------*/
130 /*!
131  * \brief Return number of volume zones which may vary in time.
132  *
133  * \return  number of zones which may vary in time
134  */
135 /*----------------------------------------------------------------------------*/
136 
137 int
138 cs_volume_zone_n_zones_time_varying(void);
139 
140 /*----------------------------------------------------------------------------*/
141 /*!
142  * \brief Update association of volume zones with a mesh.
143  *
144  * For time-varying zones, the associated mesh location is updated.
145  *
146  * \param[in]  mesh_modified  indicate if mesh has been modified
147  */
148 /*----------------------------------------------------------------------------*/
149 
150 void
151 cs_volume_zone_build_all(bool  mesh_modified);
152 
153 /*----------------------------------------------------------------------------*/
154 /*!
155  * \brief Define a new volume zone using a selection criteria string.
156  *
157  * \param[in]  name       name of location to define
158  * \param[in]  criteria   selection criteria for associated elements
159  * \param[in]  type_flag  mask of zone category values
160  *
161  * \return  id of newly defined volume zone
162  */
163 /*----------------------------------------------------------------------------*/
164 
165 int
166 cs_volume_zone_define(const char  *name,
167                       const char  *criteria,
168                       int          type_flag);
169 
170 /*----------------------------------------------------------------------------*/
171 /*!
172  * \brief Define a new mesh location with an associated selection function.
173  *
174  * So as to define a subset of mesh entities of a given type, a pointer
175  * to a selection function may be given.
176  *
177  * This requires more programming but allows finer control than selection
178  * criteria, as the function has access to the complete mesh structure.
179  *
180  * \param[in]  name        name of location to define
181  * \param[in]  func        pointer to selection function for associated elements
182  * \param[in, out]  input  pointer to optional (untyped) value
183  *                         or structure.
184  * \param[in]  type_flag   mask of zone category values
185  *
186  * \return  id of newly defined created mesh location
187  */
188 /*----------------------------------------------------------------------------*/
189 
190 int
191 cs_volume_zone_define_by_func(const char                 *name,
192                               cs_mesh_location_select_t  *func,
193                               void                       *input,
194                               int                         type_flag);
195 
196 /*----------------------------------------------------------------------------*/
197 /*!
198  * \brief Return a pointer to a volume zone based on its id.
199  *
200  * This function requires that a volume zone of the given id is defined.
201  *
202  * \param[in]  id   zone id
203  *
204  * \return  pointer to the volume zone structure
205  */
206 /*----------------------------------------------------------------------------*/
207 
208 const cs_zone_t  *
209 cs_volume_zone_by_id(int  id);
210 
211 /*----------------------------------------------------------------------------*/
212 /*!
213  * \brief Return a pointer to a volume zone based on its name if present.
214  *
215  * This function requires that a volume zone of the given name is defined.
216  *
217  * \param[in]  name  volume zone name
218  *
219  * \return  pointer to (read-only) zone structure
220  */
221 /*----------------------------------------------------------------------------*/
222 
223 const cs_zone_t  *
224 cs_volume_zone_by_name(const char  *name);
225 
226 /*----------------------------------------------------------------------------*/
227 /*!
228  * \brief Return a pointer to a volume zone based on its name if present.
229  *
230  * If no volume zone of the given name is defined, NULL is returned.
231  *
232  * \param[in]  name  volume zone name
233  *
234  * \return  pointer to (read only) zone structure, or NULL
235  */
236 /*----------------------------------------------------------------------------*/
237 
238 const cs_zone_t  *
239 cs_volume_zone_by_name_try(const char  *name);
240 
241 /*----------------------------------------------------------------------------*/
242 /*!
243  * \brief Set type flag for a given volume zone.
244  *
245  * \param[in]  id         volume zone id
246  * \param[in]  type_flag  volume zone type flag
247  */
248 /*----------------------------------------------------------------------------*/
249 
250 void
251 cs_volume_zone_set_type(int   id,
252                         int   type_flag);
253 
254 /*----------------------------------------------------------------------------*/
255 /*!
256  * \brief Set time varying behavior for a given volume zone.
257  *
258  * \param[in]  id            volume zone id
259  * \param[in]  time_varying  true if the zone's definition varies in time
260  */
261 /*----------------------------------------------------------------------------*/
262 
263 void
264 cs_volume_zone_set_time_varying(int   id,
265                                 bool  time_varying);
266 
267 /*----------------------------------------------------------------------------*/
268 /*!
269  * \brief Set overlay behavior for a given volume zone.
270  *
271  * \param[in]  id             volume zone id
272  * \param[in]  allow_overlay  true if the zone may be overlayed by another
273  */
274 /*----------------------------------------------------------------------------*/
275 
276 void
277 cs_volume_zone_set_overlay(int   id,
278                            bool  allow_overlay)
279 ;
280 /*----------------------------------------------------------------------------*/
281 /*!
282  * \brief Return pointer to zone id associated with each cell.
283  *
284  * In case of overlayed zones, the highest zone id associated with
285  * a given cell is given.
286  */
287 /*----------------------------------------------------------------------------*/
288 
289 const int *
290 cs_volume_zone_cell_zone_id(void);
291 
292 /*----------------------------------------------------------------------------*/
293 /*!
294  * \brief Print info relative to a given volume zone to log file.
295  *
296  * \param[in]  z   pointer to volume zone structure
297  */
298 /*----------------------------------------------------------------------------*/
299 
300 void
301 cs_volume_zone_log_info(const cs_zone_t  *z);
302 
303 /*----------------------------------------------------------------------------*/
304 /*!
305  * \brief Log setup information relative to defined volume zones.
306  */
307 /*----------------------------------------------------------------------------*/
308 
309 void
310 cs_volume_zone_log_setup(void);
311 
312 /*----------------------------------------------------------------------------*/
313 /*!
314  * \brief Return number of volume zones associated with a
315  *        given zone flag.
316  *
317  * \param[in]  type_flag  flag to compare to zone type
318  *
319  * \return  number of zones matching the given type flag
320  */
321 /*----------------------------------------------------------------------------*/
322 
323 int
324 cs_volume_zone_n_type_zones(int  type_flag);
325 
326 /*----------------------------------------------------------------------------*/
327 /*!
328  * \brief Return number of volume zone cells associated with a
329  *        given zone flag.
330  *
331  * Note that in the case of overlapping zones, a cell may be accounted
332  * for multiple times.
333  *
334  * \param[in]  type_flag  flag to compare to zone type
335  *
336  * \return  number of cells in zones matching the given type flag
337  */
338 /*----------------------------------------------------------------------------*/
339 
340 cs_lnum_t
341 cs_volume_zone_n_type_cells(int  type_flag);
342 
343 /*----------------------------------------------------------------------------*/
344 /*!
345  * \brief Select cells associated with volume zones of a given type.
346  *
347  * Note that in the case of overlapping zones, a cell may be accounted
348  * for multiple times.
349  *
350  * \param[in]   type_flag  flag to compare to zone type
351  * \param[out]  cell_ids   ids of selected cells (size: given by
352  *                         \ref cs_volume_zone_n_type_cells)
353  */
354 /*----------------------------------------------------------------------------*/
355 
356 void
357 cs_volume_zone_select_type_cells(int        type_flag,
358                                  cs_lnum_t  cell_ids[]);
359 
360 /*----------------------------------------------------------------------------*/
361 /*!
362  * \brief Tag cells of a given zone type
363  *
364  * The tag array should be initialized. The given tag_value is associted
365  * to cells of the given zone type using a logical "or", so multiple flag
366  * bits can be handled using the same array if necessary.
367  *
368  * \param[in]       zone_type_flag  zone types to tag
369  * \param[in]       tag_value  tag value to add to cells of matching zones
370  * \param[in, out]  tag        tag value for each cell
371  */
372 /*----------------------------------------------------------------------------*/
373 
374 void
375 cs_volume_zone_tag_cell_type(int  zone_type_flag,
376                              int  tag_value,
377                              int  tag[]);
378 
379 /*----------------------------------------------------------------------------*/
380 /*!
381  * \brief Print volume zones information to listing file
382  */
383 /*----------------------------------------------------------------------------*/
384 
385 void
386 cs_volume_zone_print_info(void);
387 
388 /*----------------------------------------------------------------------------*/
389 
390 END_C_DECLS
391 
392 #endif /* __CS_VOLUME_ZONE_H__ */
393