1 #ifndef __CS_DOMAIN_H__
2 #define __CS_DOMAIN_H__
3 
4 /*============================================================================
5  * Manage a computational domain
6  *  - equations, settings, fields, connectivities and geometrical quantities
7  *============================================================================*/
8 
9 /*
10   This file is part of Code_Saturne, a general-purpose CFD tool.
11 
12   Copyright (C) 1998-2021 EDF S.A.
13 
14   This program is free software; you can redistribute it and/or modify it under
15   the terms of the GNU General Public License as published by the Free Software
16   Foundation; either version 2 of the License, or (at your option) any later
17   version.
18 
19   This program is distributed in the hope that it will be useful, but WITHOUT
20   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
22   details.
23 
24   You should have received a copy of the GNU General Public License along with
25   this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
26   Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 */
28 
29 /*----------------------------------------------------------------------------
30  *  Standard C library headers
31  *----------------------------------------------------------------------------*/
32 
33 #include <stdbool.h>
34 
35 /*----------------------------------------------------------------------------
36  *  Local headers
37  *----------------------------------------------------------------------------*/
38 
39 #include "cs_boundary.h"
40 #include "cs_cdo_connect.h"
41 #include "cs_cdo_quantities.h"
42 #include "cs_mesh.h"
43 #include "cs_mesh_quantities.h"
44 #include "cs_time_step.h"
45 #include "cs_timer.h"
46 #include "cs_xdef.h"
47 
48 /*----------------------------------------------------------------------------*/
49 
50 BEGIN_C_DECLS
51 
52 /*============================================================================
53  * Macro definitions
54  *============================================================================*/
55 
56 /* Flag related to the activation (or not) of the CDO schemes */
57 
58 #define CS_DOMAIN_CDO_MODE_OFF     -1  /* CDO schemes are not used */
59 #define CS_DOMAIN_CDO_MODE_WITH_FV  1  /* CDO and legacy FV schemes are used */
60 #define CS_DOMAIN_CDO_MODE_ONLY     2  /* CDO schemes are exclusively used */
61 
62 /*============================================================================
63  * Type definitions
64  *============================================================================*/
65 
66 /*! \enum cs_domain_stage_t
67 
68  *  \brief Indicator describing at which stage is the computation.
69  *
70  * This indicator is useful to know at which stage the computation is when a
71  * user-defined function is called (for instance \ref
72  * cs_user_physical_properties). Up to now, this information is only used in
73  * the CDO module.
74  *
75  * \var CS_DOMAIN_STAGE_BEFORE_STEADY_COMPUTATION
76  * The computation run is at a stage before computing the steady-state equations
77  *
78  * \var CS_DOMAIN_STAGE_BEFORE_TIME_LOOP
79  * The computation run is at a stage before starting the time loop and after
80  * solving all steady-state equations
81  *
82  * \var CS_DOMAIN_STAGE_TIME_STEP_BEGIN
83  * The computation run is inside the time loop and at the beginning of a
84  * time step
85  *
86  * \var CS_DOMAIN_STAGE_TIME_STEP_SUB_ITERATION
87  * The computation run is inside the time loop and inside a sub-iteration
88  * process
89  *
90  * \var CS_DOMAIN_STAGE_TIME_STEP_END
91  * The computation run is inside the time loop and at the end of an iteration
92  * but before the computation of user-defined equation (not triggered by a
93  * user)
94  *
95  * \var CS_DOMAIN_STAGE_AFTER_TIME_LOOP
96  * The computation run is at a stage after the time loop (finalize stage).
97  * This stage is useful to free memory allocated during the computation.
98  */
99 
100 typedef enum {
101 
102   CS_DOMAIN_STAGE_BEFORE_STEADY_COMPUTATION,
103   CS_DOMAIN_STAGE_BEFORE_TIME_LOOP,
104   CS_DOMAIN_STAGE_TIME_STEP_BEGIN,
105   CS_DOMAIN_STAGE_TIME_STEP_SUB_ITERATION,
106   CS_DOMAIN_STAGE_TIME_STEP_END,
107   CS_DOMAIN_STAGE_AFTER_TIME_LOOP,
108 
109   CS_DOMAIN_N_STAGES
110 
111 } cs_domain_stage_t;
112 
113 
114 /*! \struct cs_domain_cdo_context_t
115  *  \brief  High-level metadata for handling CDO/HHO schemes
116  */
117 
118 typedef struct {
119 
120   /* Mode for CDO: activated, switched off... */
121 
122   int                       mode;
123 
124   /* Flag to know if scalar or vector equations are requested and which kind
125      of numerical schemes is requested to solve these equations */
126 
127   cs_flag_t                 eb_scheme_flag;
128   cs_flag_t                 fb_scheme_flag;
129   cs_flag_t                 vb_scheme_flag;
130   cs_flag_t                 vcb_scheme_flag;
131   cs_flag_t                 hho_scheme_flag;
132 
133 } cs_domain_cdo_context_t;
134 
135 /*! \struct cs_domain_t
136  *  \brief  Structure storing the main features of the computational domain
137  *  and pointers to the main geometrical structures
138  */
139 
140 typedef struct {
141 
142   /* Code_Saturne mesh and mesh quantities structures already computed */
143 
144   cs_mesh_t                *mesh;
145   cs_mesh_quantities_t     *mesh_quantities;
146 
147   /* CDO structures:
148    * - cs_cdo_connect_t contains additional information about connectivity
149    * - cs_cdo_quantities_t contains additional information on mesh quantities
150    */
151 
152   cs_cdo_connect_t         *connect;
153   cs_cdo_quantities_t      *cdo_quantities;
154 
155   /* Boundary of the computational domain */
156 
157   cs_boundary_t            *boundaries;
158   cs_boundary_t            *ale_boundaries;
159 
160   /* Time step management */
161 
162   bool                      only_steady;
163   bool                      is_last_iter;     /* true or false */
164 
165   cs_time_step_t           *time_step;        /* time step descriptor */
166   cs_time_step_options_t    time_options;     /* time step options */
167 
168   cs_domain_stage_t         stage;   /* store the stage of the computation */
169 
170   /* Output options */
171 
172   int                       output_nt;   /* Logging done every nt iterations */
173   int                       restart_nt;  /* Restart done every nt iterations */
174   int                       verbosity;   /* Level of details given in log */
175 
176   /* Specific context structure related to the numerical schemes */
177 
178   cs_domain_cdo_context_t   *cdo_context;
179 
180   /* Monitoring */
181 
182   cs_timer_counter_t    tcp; /* Cumulated elapsed time for extra-operations
183                                 and post-processing */
184   cs_timer_counter_t    tcs; /* Cumulated elapsed time for setup operations */
185 
186 } cs_domain_t;
187 
188 /*============================================================================
189  * Static global variables
190  *============================================================================*/
191 
192 extern cs_domain_t  *cs_glob_domain; /* Pointer to main computational domain */
193 
194 /*============================================================================
195  * Static inline public function prototypes
196  *============================================================================*/
197 
198 /*----------------------------------------------------------------------------*/
199 /*!
200  * \brief  Update the time step after one temporal iteration
201  *
202  * \param[in, out]  domain     pointer to a cs_domain_t structure
203  */
204 /*----------------------------------------------------------------------------*/
205 
206 static inline void
cs_domain_increment_time_step(cs_domain_t * domain)207 cs_domain_increment_time_step(cs_domain_t  *domain)
208 {
209   cs_time_step_t  *ts = domain->time_step;
210 
211   /* Increment time iteration */
212   ts->nt_cur++;
213 }
214 
215 /*============================================================================
216  * Public function prototypes
217  *============================================================================*/
218 
219 /*----------------------------------------------------------------------------*/
220 /*!
221  * \brief  Create and initialize by default a cs_domain_t structure
222  *
223  * \return a pointer to a cs_domain_t structure
224  */
225 /*----------------------------------------------------------------------------*/
226 
227 cs_domain_t *
228 cs_domain_create(void);
229 
230 /*----------------------------------------------------------------------------*/
231 /*!
232  * \brief  Free a cs_domain_t structure
233  *
234  * \param[in, out]   p_domain    pointer of pointer to a cs_domain_t structure
235  */
236 /*----------------------------------------------------------------------------*/
237 
238 void
239 cs_domain_free(cs_domain_t   **p_domain);
240 
241 /*----------------------------------------------------------------------------*/
242 /*!
243  * \brief   Set the global variable storing the mode of activation to apply
244  *          to CDO/HHO schemes
245  *
246  * \param[in, out]   domain    pointer to a cs_domain_t structure
247  * \param[in]        mode      type of activation for the CDO/HHO module
248  */
249 /*----------------------------------------------------------------------------*/
250 
251 void
252 cs_domain_set_cdo_mode(cs_domain_t    *domain,
253                        int             mode);
254 
255 /*----------------------------------------------------------------------------*/
256 /*!
257  * \brief   Get the mode of activation for the CDO/HHO schemes
258  *
259  * \param[in]   domain       pointer to a cs_domain_t structure
260  *
261  * \return the mode of activation for the CDO/HHO module
262  */
263 /*----------------------------------------------------------------------------*/
264 
265 int
266 cs_domain_get_cdo_mode(const cs_domain_t   *domain);
267 
268 /*----------------------------------------------------------------------------*/
269 /*!
270  * \brief  Set the computation stage in the domain structure
271  *
272  * \param[in, out] domain    pointer to a cs_domain_t structure
273  * \param[in]      stage     stage in the computation run
274  */
275 /*----------------------------------------------------------------------------*/
276 
277 void
278 cs_domain_set_stage(cs_domain_t         *domain,
279                     cs_domain_stage_t    stage);
280 
281 /*----------------------------------------------------------------------------*/
282 /*!
283  * \brief  Retrieve the computation stage from the domain structure
284  *
285  * \param[in] domain    pointer to a cs_domain_t structure
286  *
287  * \return the current stage in the computation run
288  */
289 /*----------------------------------------------------------------------------*/
290 
291 cs_domain_stage_t
292 cs_domain_get_stage(const cs_domain_t    *domain);
293 
294 /*----------------------------------------------------------------------------*/
295 /*!
296  * \brief  Check if one needs to continue iterations in time
297  *
298  * \param[in, out]  domain     pointer to a cs_domain_t structure
299  *
300  * \return  true or false
301  */
302 /*----------------------------------------------------------------------------*/
303 
304 bool
305 cs_domain_needs_iteration(cs_domain_t  *domain);
306 
307 /*----------------------------------------------------------------------------*/
308 /*!
309  * \brief  Check if an output is requested according to the domain setting
310  *
311  * \param[in]   domain    pointer to a cs_domain_t structure
312  * \param[in]   oneplus   add or not plus one to the current time step
313  *
314  * \return true or false
315  */
316 /*----------------------------------------------------------------------------*/
317 
318 bool
319 cs_domain_needs_log(const cs_domain_t      *domain,
320                     bool                    oneplus);
321 
322 /*----------------------------------------------------------------------------*/
323 /*!
324  * \brief  Update time step after one temporal iteration
325  *
326  * \param[in, out]  domain     pointer to a cs_domain_t structure
327  */
328 /*----------------------------------------------------------------------------*/
329 
330 void
331 cs_domain_increment_time(cs_domain_t  *domain);
332 
333 /*----------------------------------------------------------------------------*/
334 /*!
335  * \brief   Print a welcome message indicating which mode of CDO is activated
336  *
337  * \param[in]  domain    pointer to a cs_domain_t structure
338  */
339 /*----------------------------------------------------------------------------*/
340 
341 void
342 cs_domain_cdo_log(const cs_domain_t   *domain);
343 
344 /*----------------------------------------------------------------------------*/
345 
346 END_C_DECLS
347 
348 #endif /* __CS_DOMAIN_H__ */
349