9.1
general documentation
cs_time_step.h
Go to the documentation of this file.
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-2025 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 "base/cs_defs.h"
35
36/*----------------------------------------------------------------------------*/
37
39
40/*=============================================================================
41 * Macro definitions
42 *============================================================================*/
43
44/*============================================================================
45 * Type definitions
46 *============================================================================*/
47
48/*----------------------------------------------------------------------------
49 * Time stepping algorithme
50 *----------------------------------------------------------------------------*/
51
52typedef enum {
53
58
60
61/* time step descriptor */
62/*----------------------*/
63
64typedef 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#if defined(__cplusplus)
88
89 /* Helper function to check if code needs to do at least one more iteration.
90 ------------------------------------------------------------------------ */
91
92 bool needs_iteration() const;
93
94#endif
95
97
98/* Time step options descriptor */
99/*------------------------------*/
100
101typedef struct {
102
103 int iptlro; /* Clip the time step with respect to the buoyant effects
104 - 0: false
105 - 1: true. */
106
107 cs_time_step_type_t idtvar; /* time step type (constant, adaptive, steady) */
108
109 double coumax; /* Maximum Courant number (when idtvar is
110 different from 0). */
111
112 double cflmmx; /* Maximum Courant number for the continuity equation
113 in compressible model. */
114
115 double foumax; /* Maximum Fourier number
116 (when idtvar is different from CS_TIME_STEP_CONSTANT). */
117
118 double varrdt; /* Relative allowed variation of dt
119 (when idtvar is different from CS_TIME_STEP_CONSTANT). */
120
121 double dtmin; /* Minimum value of dt
122 (when idtvar is different from CS_TIME_STEP_CONSTANT).
123 Take
124 dtmin = min(ld/ud, sqrt(lt/(gdelta rho/rho)), ...). */
125
126 double dtmax; /* Maximum value of dt
127 (when idtvar is different from CS_TIME_STEP_CONSTANT).
128 Take
129 dtmax = max(ld/ud, sqrt(lt/(gdelta rho/rho)), ...). */
130
131 double relxst; /* Relaxation coefficient for the steady algorithm. */
132
134
135/*============================================================================
136 * Static global variables
137 *============================================================================*/
138
139/* Pointer to main time step structure */
140
142
144
145/*=============================================================================
146 * Public function prototypes
147 *============================================================================*/
148
149/*----------------------------------------------------------------------------
150 * Provide read/write access to cs_glob_time_step
151 *
152 * returns:
153 * pointer to global time step structure
154 *----------------------------------------------------------------------------*/
155
158
159/*----------------------------------------------------------------------------
160 * Provide read/write access to cs_glob_time_step_options
161 *
162 * returns:
163 * pointer to global time step options structure
164 *----------------------------------------------------------------------------*/
165
168
169/*----------------------------------------------------------------------------
170 * Define whether time step is variable or not
171 *
172 * parameters:
173 * is_variable <-- 0 if time step is variable in time, 1 if it is fixed
174 *----------------------------------------------------------------------------*/
175
176void
177cs_time_step_define_variable(int is_variable);
178
179/*----------------------------------------------------------------------------
180 * Define whether time step is local in space or not
181 *
182 * parameters:
183 * is_local <-- 0 if time step is uniform in space, 1 if it is local
184 *----------------------------------------------------------------------------*/
185
186void
187cs_time_step_define_local(int is_local);
188
189/*----------------------------------------------------------------------------
190 * Define maximum time step number
191 *
192 * parameters:
193 * nt_max <-- maximum time step number (unlimited if negative)
194 *----------------------------------------------------------------------------*/
195
196void
198
199/*----------------------------------------------------------------------------
200 * Define maximum time value
201 *
202 * parameters:
203 * t_max <-- maximum time value (unlimited if negative)
204 *----------------------------------------------------------------------------*/
205
206void
207cs_time_step_define_t_max(double t_max);
208
209/*----------------------------------------------------------------------------
210 * Set time values from previous (usually restarted) calculations
211 *
212 * parameters:
213 * nt_prev <-- previous time step number
214 * t_prev <-- previous physical time
215 *----------------------------------------------------------------------------*/
216
217void
218cs_time_step_define_prev(int nt_prev,
219 double t_prev);
220
221/*----------------------------------------------------------------------------
222 * Increment the global time step.
223 *
224 * parameters:
225 * dt <-- time step value to increment
226 *----------------------------------------------------------------------------*/
227
228void
230
231/*----------------------------------------------------------------------------*/
240/*----------------------------------------------------------------------------*/
241
242void
244
245/*----------------------------------------------------------------------------
246 * Redefine the current time values.
247 *
248 * Remark: Using cs_time_step_increment() is preferred, but this function
249 * may be required for reverting to a previous time step.
250 *
251 * parameters:
252 * nt_cur <-- current time step number
253 * t_cur <-- current physical time
254 *----------------------------------------------------------------------------*/
255
256void
258 double t_cur);
259
260/*----------------------------------------------------------------------------*
261 * Print the time stepping options to setup.log.
262 *----------------------------------------------------------------------------*/
263
264void
266
267/*----------------------------------------------------------------------------*/
268
270
271#endif /* __CS_TIME_STEP_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
#define END_C_DECLS
Definition: cs_defs.h:555
@ dt
Definition: cs_field_pointer.h:65
const cs_time_step_t * cs_glob_time_step
cs_time_step_t * cs_get_glob_time_step(void)
Provide read/write access to cs_glob_time_step.
Definition: cs_time_step.cpp:381
cs_time_step_options_t * cs_get_glob_time_step_options(void)
Provide read/write access to cs_glob_time_step_options.
Definition: cs_time_step.cpp:395
void cs_time_step_redefine_cur(int nt_cur, double t_cur)
Redefine the current time values.
Definition: cs_time_step.cpp:562
const cs_time_step_options_t * cs_glob_time_step_options
void cs_time_step_define_nt_max(int nt_max)
Define maximum time step number.
Definition: cs_time_step.cpp:443
cs_time_step_type_t
Definition: cs_time_step.h:52
@ CS_TIME_STEP_LOCAL
Definition: cs_time_step.h:57
@ CS_TIME_STEP_STEADY
Definition: cs_time_step.h:54
@ CS_TIME_STEP_CONSTANT
Definition: cs_time_step.h:55
@ CS_TIME_STEP_ADAPTIVE
Definition: cs_time_step.h:56
void cs_time_step_define_prev(int nt_prev, double t_prev)
Set time values from previous (usually restarted) calculations.
Definition: cs_time_step.cpp:474
void cs_time_step_increment(double dt)
Increment the global time step.
Definition: cs_time_step.cpp:492
void cs_time_step_define_local(int is_local)
Define whether time step is local in space or not.
Definition: cs_time_step.cpp:426
void cs_time_step_define_variable(int is_variable)
Define whether time step is variable or not.
Definition: cs_time_step.cpp:409
void cs_time_step_define_t_max(double t_max)
Define maximum time value.
Definition: cs_time_step.cpp:458
void cs_time_step_update_dt(double dt)
Update global time step value for a time step in progress.
Definition: cs_time_step.cpp:533
void cs_time_step_log_setup(void)
Print the time stepping options to setup.log.
Definition: cs_time_step.cpp:576
time step options descriptor
Definition: cs_time_step.h:101
double foumax
Definition: cs_time_step.h:115
double cflmmx
Definition: cs_time_step.h:112
double relxst
Definition: cs_time_step.h:131
int iptlro
Definition: cs_time_step.h:103
double dtmin
Definition: cs_time_step.h:121
double coumax
Definition: cs_time_step.h:109
double dtmax
Definition: cs_time_step.h:126
cs_time_step_type_t idtvar
Definition: cs_time_step.h:107
double varrdt
Definition: cs_time_step.h:118
time step descriptor
Definition: cs_time_step.h:64
int nt_prev
Definition: cs_time_step.h:72
int is_variable
Definition: cs_time_step.h:66
int nt_ini
Definition: cs_time_step.h:76
double t_max
Definition: cs_time_step.h:81
double t_prev
Definition: cs_time_step.h:78
double dt_next
Definition: cs_time_step.h:85
int nt_cur
Definition: cs_time_step.h:74
int nt_max
Definition: cs_time_step.h:75
double t_cur
Definition: cs_time_step.h:80
int is_local
Definition: cs_time_step.h:68
double dt_ref
Definition: cs_time_step.h:84