1 #ifndef __CS_TIME_STEP_H__
2 #define __CS_TIME_STEP_H__
3 
4 /*============================================================================
5  * Base time step data.
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 /*----------------------------------------------------------------------------*/
37 
38 BEGIN_C_DECLS
39 
40 /*=============================================================================
41  * Macro definitions
42  *============================================================================*/
43 
44 /*============================================================================
45  * Type definitions
46  *============================================================================*/
47 
48 /*----------------------------------------------------------------------------
49  * Time stepping algorithme
50  *----------------------------------------------------------------------------*/
51 
52 typedef enum {
53 
54   CS_TIME_STEP_STEADY = -1,
55   CS_TIME_STEP_CONSTANT = 0,
56   CS_TIME_STEP_ADAPTIVE = 1,
57   CS_TIME_STEP_LOCAL = 2
58 
59 } cs_time_step_type_t;
60 
61 /* time step descriptor */
62 /*----------------------*/
63 
64 typedef struct {
65 
66   int           is_variable;  /* 0 if time step is fixed in time,
67                                  1 if the time step is variable. */
68   int           is_local;     /* 0 if time step is uniform in space,
69                                  1 if it is local in space (in which case
70                                  the time value is only a reference. */
71 
72   int           nt_prev;      /* absolute time step number reached by previous
73                                  computation */
74   int           nt_cur;       /* current absolute time step number */
75   int           nt_max;       /* maximum absolute time step number */
76   int           nt_ini;       /* Number of time steps for initialization */
77 
78   double        t_prev;       /* physical time reached by previous
79                                  computation */
80   double        t_cur;        /* current absolute time */
81   double        t_max;        /* maximum absolute time */
82 
83   double        dt[3];        /* n, n-1, and n-2 time steps */
84   double        dt_ref;       /* reference time step. */
85   double        dt_next;      /* next (predicted) time step. */
86 
87 } cs_time_step_t;
88 
89 /* Time step options descriptor */
90 /*------------------------------*/
91 
92 typedef struct {
93 
94   int       iptlro; /* Clip the time step with respect to the buoyant effects
95                        - 0: false
96                        - 1: true. */
97 
98   cs_time_step_type_t   idtvar; /* time step type (constant, adaptive, steady) */
99 
100   double    coumax; /* Maximum Courant number (when idtvar is
101                        different from 0). */
102 
103   double    cflmmx; /* Maximum Courant number for the continuity equation
104                        in compressible model. */
105 
106   double    foumax; /* Maximum Fourier number
107                        (when idtvar is different from CS_TIME_STEP_CONSTANT). */
108 
109   double    varrdt; /* Relative allowed variation of dt
110                        (when idtvar is different from CS_TIME_STEP_CONSTANT). */
111 
112   double    dtmin;  /* Minimum value of dt
113                        (when idtvar is different from CS_TIME_STEP_CONSTANT).
114                        Take
115                        dtmin = min(ld/ud, sqrt(lt/(gdelta rho/rho)), ...). */
116 
117   double    dtmax;  /* Maximum value of dt
118                        (when idtvar is different from CS_TIME_STEP_CONSTANT).
119                        Take
120                        dtmax = max(ld/ud, sqrt(lt/(gdelta rho/rho)), ...). */
121 
122   double    relxst; /* Relaxation coefficient for the steady algorithm. */
123 
124 } cs_time_step_options_t;
125 
126 /*============================================================================
127  * Static global variables
128  *============================================================================*/
129 
130 /* Pointer to main time step structure */
131 
132 extern const cs_time_step_t  *cs_glob_time_step;
133 
134 extern const cs_time_step_options_t  *cs_glob_time_step_options;
135 
136 /*=============================================================================
137  * Public function prototypes
138  *============================================================================*/
139 
140 /*----------------------------------------------------------------------------
141  * Provide read/write access to cs_glob_time_step
142  *
143  * returns:
144  *   pointer to global time step structure
145  *----------------------------------------------------------------------------*/
146 
147 cs_time_step_t *
148 cs_get_glob_time_step(void);
149 
150 /*----------------------------------------------------------------------------
151  * Provide read/write access to cs_glob_time_step_options
152  *
153  * returns:
154  *  pointer to global time step options structure
155  *----------------------------------------------------------------------------*/
156 
157 cs_time_step_options_t *
158 cs_get_glob_time_step_options(void);
159 
160 /*----------------------------------------------------------------------------
161  * Define whether time step is variable or not
162  *
163  * parameters:
164  *   is_variable <-- 0 if time step is variable in time, 1 if it is fixed
165  *----------------------------------------------------------------------------*/
166 
167 void
168 cs_time_step_define_variable(int  is_variable);
169 
170 /*----------------------------------------------------------------------------
171  * Define whether time step is local in space or not
172  *
173  * parameters:
174  *   is_local <-- 0 if time step is uniform in space, 1 if it is local
175  *----------------------------------------------------------------------------*/
176 
177 void
178 cs_time_step_define_local(int  is_local);
179 
180 /*----------------------------------------------------------------------------
181  * Define maximum time step number
182  *
183  * parameters:
184  *   nt_max <-- maximum time step number (unlimited if negative)
185  *----------------------------------------------------------------------------*/
186 
187 void
188 cs_time_step_define_nt_max(int  nt_max);
189 
190 /*----------------------------------------------------------------------------
191  * Define maximum time value
192  *
193  * parameters:
194  *   t_max <-- maximum time value (unlimited if negative)
195  *----------------------------------------------------------------------------*/
196 
197 void
198 cs_time_step_define_t_max(double  t_max);
199 
200 /*----------------------------------------------------------------------------
201  * Set time values from previous (usually restarted) calculations
202  *
203  * parameters:
204  *   nt_prev <-- previous time step number
205  *   t_prev  <-- previous physical time
206  *----------------------------------------------------------------------------*/
207 
208 void
209 cs_time_step_define_prev(int     nt_prev,
210                          double  t_prev);
211 
212 /*----------------------------------------------------------------------------
213  * Increment the global time step.
214  *
215  * parameters:
216  *   dt <-- time step value to increment
217  *----------------------------------------------------------------------------*/
218 
219 void
220 cs_time_step_increment(double  dt);
221 
222 /*----------------------------------------------------------------------------
223  * Redefine the current time values.
224  *
225  * Remark: Using cs_time_step_increment() is preferred, but this function
226  *         may be required for reverting to a previous time step.
227  *
228  * parameters:
229  *   nt_cur <-- current time step number
230  *   t_cur  <-- current physical time
231  *----------------------------------------------------------------------------*/
232 
233 void
234 cs_time_step_redefine_cur(int     nt_cur,
235                           double  t_cur);
236 
237 /*----------------------------------------------------------------------------*
238  * Print the time stepping options to setup.log.
239  *----------------------------------------------------------------------------*/
240 
241 void
242 cs_time_step_log_setup(void);
243 
244 /*----------------------------------------------------------------------------*/
245 
246 END_C_DECLS
247 
248 #endif /* __CS_TIME_STEP_H__ */
249