9.2
general documentation
cs_time_control.h
Go to the documentation of this file.
1#ifndef CS_TIME_CONTROL_H
2#define CS_TIME_CONTROL_H
3
4/*============================================================================
5 * Time dependency control for variables or properties.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 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#include <stdarg.h>
35
36/*----------------------------------------------------------------------------
37 * Local headers
38 *----------------------------------------------------------------------------*/
39
40#include "base/cs_defs.h"
41
42#include "base/cs_time_step.h"
43
44/*=============================================================================
45 * Macro definitions
46 *============================================================================*/
47
48/*============================================================================
49 * Type definitions
50 *============================================================================*/
51
52/*----------------------------------------------------------------------------*/
69/*----------------------------------------------------------------------------*/
70
71typedef bool
73 void *input);
74
75/* Time control types */
76/*--------------------*/
77
78/* Datatype enumeration */
79
80typedef enum {
81
87
88/*----------------------------------------------------------------------------
89 * Time control structure
90 *----------------------------------------------------------------------------*/
91
93
94public:
95
96 /* Constructors */
97
99
101 (
102 int nt_start,
103 int nt_end,
104 int nt_interval,
105 bool at_start_ = true,
106 bool at_end_ = true,
107 bool at_first_ = false
108 );
109
111 (
112 double t_start,
113 double t_end,
114 double t_interval,
115 bool at_start_ = true,
116 bool at_end_ = true,
117 bool at_first_ = false
118 );
119
121 (
122 cs_time_control_func_t *control_func_,
123 void *input_,
124 bool at_start_ = true,
125 bool at_end_ = true,
126 bool at_first_ = false
127 );
128
129 /* Public functions */
130
131 bool
132 is_active(const cs_time_step_t *ts);
133
134 void
136 (
137 char *desc,
138 size_t desc_size
139 ) const;
140
141 /* Type and control parameters */
142
143 cs_time_control_type_t type; /* control type */
144
145 bool at_start; /* always active at start? */
146 bool at_first; /* always active at first it? */
147 bool at_end; /* always active at end? */
148
149 union {
150 int start_nt; /* update start time step */
151 double start_t; /* update start physical time */
152 };
153
154 union {
155 int end_nt; /* update end time step */
156 double end_t; /* update end physical time */
157 };
158
159 union {
160 int interval_nt; /* interval, in time steps */
161 double interval_t; /* interval, in physical time units */
162 };
163
164 cs_time_control_func_t *control_func; /* function for advanced control */
165 void *control_input; /* input associated function */
166
167 /* Current state */
168
169 bool current_state; /* query return value of current time step */
170 int current_time_step; /* last time step queried */
171
172 int last_nt; /* last active time step */
173 double last_t; /* last active physical time */
174
175};
176
177/*============================================================================
178 * Global variables
179 *============================================================================*/
180
181/*=============================================================================
182 * Public function prototypes
183 *============================================================================*/
184
185/*----------------------------------------------------------------------------
186 *!
187 * \brief Indicate if a time control is active or not at the given time.
188 *
189 * If the time control or time step argument is NULL, true is returned.
190 *
191 * \param[in] tc time control structure
192 * \param[in] ts time step structure
193 *
194 * \return true if active, false if inactive
195 */
196/*----------------------------------------------------------------------------*/
197
198bool
200 const cs_time_step_t *ts);
201
202/*----------------------------------------------------------------------------
203 *!
204 * \brief Simple time control initialization based on time step options.
205 *
206 * \param[in] tc pointer to time control structure.
207 * \param[in] nt_start start time step (or < 0 for unlimited)
208 * \param[in] nt_end end time step (or < 0 for unlimited)
209 * \param[in] nt_interval time step interval (< 0 if no periodic output)
210 * \param[in] at_start always active at start ?
211 * \param[in] at_start always active at end ?
212 */
213/*----------------------------------------------------------------------------*/
214
215[[deprecated("Use cs_time_control_t constructor instead")]] void
217 int nt_start,
218 int nt_end,
219 int nt_interval,
220 bool at_start,
221 bool at_end);
222
223/*----------------------------------------------------------------------------
224 *!
225 * \brief Get text description of time control configuration.
226 *
227 * If the time control or time step argument is NULL, true is returned.
228 *
229 * \param[in] tc time control structure
230 * \param[out] desc description string
231 * \param[in] desc_size description string maximum size
232 *
233 * \return true if active, false if inactive
234 */
235/*----------------------------------------------------------------------------*/
236
237void
239 char *desc,
240 size_t desc_size);
241
242/*----------------------------------------------------------------------------*/
243/* Copy data from one cs_time_control_t instance to another */
244/*----------------------------------------------------------------------------*/
245
246void
248 cs_time_control_t *dst);
249
250/*----------------------------------------------------------------------------*/
251/* Copy data from the default cs_time_control_t instance to another one */
252/*----------------------------------------------------------------------------*/
253
254void
256
257/*----------------------------------------------------------------------------*/
258
259#endif /* CS_TIME_CONTROL_H */
Definition: cs_time_control.h:92
bool current_state
Definition: cs_time_control.h:169
double interval_t
Definition: cs_time_control.h:161
int interval_nt
Definition: cs_time_control.h:160
bool at_first
Definition: cs_time_control.h:146
bool is_active(const cs_time_step_t *ts)
Definition: cs_time_control.cpp:249
int end_nt
Definition: cs_time_control.h:155
bool at_end
Definition: cs_time_control.h:147
cs_time_control_type_t type
Definition: cs_time_control.h:143
void get_description(char *desc, size_t desc_size) const
Definition: cs_time_control.cpp:338
int current_time_step
Definition: cs_time_control.h:170
double last_t
Definition: cs_time_control.h:173
cs_time_control_func_t * control_func
Definition: cs_time_control.h:164
double start_t
Definition: cs_time_control.h:151
void * control_input
Definition: cs_time_control.h:165
cs_time_control_t()
Definition: cs_time_control.cpp:102
int last_nt
Definition: cs_time_control.h:172
bool at_start
Definition: cs_time_control.h:145
int start_nt
Definition: cs_time_control.h:150
double end_t
Definition: cs_time_control.h:156
time step descriptor
Definition: cs_time_step.h:60
cs_time_control_type_t
Definition: cs_time_control.h:80
@ CS_TIME_CONTROL_FUNCTION
Definition: cs_time_control.h:84
@ CS_TIME_CONTROL_TIME
Definition: cs_time_control.h:83
@ CS_TIME_CONTROL_TIME_STEP
Definition: cs_time_control.h:82
bool cs_time_control_is_active(cs_time_control_t *tc, const cs_time_step_t *ts)
Definition: cs_time_control.cpp:403
void cs_time_control_copy_from_default(cs_time_control_t *tc)
Copy contents of the default cs_time_control to another instance.
Definition: cs_time_control.cpp:514
bool() cs_time_control_func_t(const cs_time_step_t *ts, void *input)
Function pointer to a time control function.
Definition: cs_time_control.h:72
void cs_time_control_get_description(const cs_time_control_t *tc, char *desc, size_t desc_size)
Definition: cs_time_control.cpp:456
void cs_time_control_copy(const cs_time_control_t *src, cs_time_control_t *dst)
Copy contents of a cs_time_control to another instance.
Definition: cs_time_control.cpp:477
void cs_time_control_init_by_time_step(cs_time_control_t *tc, int nt_start, int nt_end, int nt_interval, bool at_start, bool at_end)
Definition: cs_time_control.cpp:430