8.1
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-2023 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 "cs_defs.h"
41 
42 #include "cs_time_step.h"
43 
44 /*----------------------------------------------------------------------------*/
45 
47 
48 /*=============================================================================
49  * Macro definitions
50  *============================================================================*/
51 
52 /*============================================================================
53  * Type definitions
54  *============================================================================*/
55 
56 /*----------------------------------------------------------------------------*/
73 /*----------------------------------------------------------------------------*/
74 
75 typedef bool
77  void *input);
78 
79 /* Time control types */
80 /*--------------------*/
81 
82 /* Datatype enumeration */
83 
84 typedef enum {
85 
91 
92 /*----------------------------------------------------------------------------
93  * Time control structure
94  *----------------------------------------------------------------------------*/
95 
96 typedef struct {
97 
98  /* Type and control parameters */
99 
100  cs_time_control_type_t type; /* control type */
101 
102  bool at_start; /* always active at start? */
103  bool at_first; /* always active at first it? */
104  bool at_end; /* always active at end? */
105 
106  union {
107  int start_nt; /* update start time step */
108  double start_t; /* update start physical time */
109  };
110 
111  union {
112  int end_nt; /* update end time step */
113  double end_t; /* update end physical time */
114  };
115 
116  union {
117  int interval_nt; /* interval, in time steps */
118  double interval_t; /* interval, in physical time units */
119  };
120 
121  cs_time_control_func_t *control_func; /* function for advanced control */
122  void *control_input; /* input associated function */
123 
124  /* Current state */
125 
126  bool current_state; /* query return value of current time step */
127  int current_time_step; /* last time step queried */
128 
129  int last_nt; /* last active time step */
130  double last_t; /* last active physical time */
131 
133 
134 /*============================================================================
135  * Global variables
136  *============================================================================*/
137 
138 /*=============================================================================
139  * Public function prototypes
140  *============================================================================*/
141 
142 /*----------------------------------------------------------------------------
143  *!
144  * \brief Indicate if a time control is active or not at the given time.
145  *
146  * If the time control or time step argument is NULL, true is returned.
147  *
148  * \param[in] tc time control structure
149  * \param[in] ts time step structure
150  *
151  * \return true if active, false if inactive
152  */
153 /*----------------------------------------------------------------------------*/
154 
155 bool
157  const cs_time_step_t *ts);
158 
159 /*----------------------------------------------------------------------------
160  *!
161  * \brief Simple time control initialization based on time step options.
162  *
163  * \param[in] tc pointer to time control structure.
164  * \param[in] nt_start start time step (or < 0 for unlimited)
165  * \param[in] nt_end end time step (or < 0 for unlimited)
166  * \param[in] nt_interval time step interval
167  * \param[in] at_start always active at start ?
168  * \param[in] at_start always active at end ?
169  */
170 /*----------------------------------------------------------------------------*/
171 
172 void
174  int nt_start,
175  int nt_end,
176  int nt_interval,
177  bool at_start,
178  bool at_end);
179 
180 /*----------------------------------------------------------------------------
181  *!
182  * \brief Simple time control initialization based on physical time options.
183  *
184  * \param[in] tc pointer to time control structure.
185  * \param[in] t_start start time (or < 0 for unlimited)
186  * \param[in] t_end end time (or < 0 for unlimited)
187  * \param[in] t_interval time interval
188  * \param[in] at_start always active at start ?
189  * \param[in] at_start always active at end ?
190  */
191 /*----------------------------------------------------------------------------*/
192 
193 void
195  double t_start,
196  double t_end,
197  double t_interval,
198  bool at_start,
199  bool at_end);
200 
201 /*----------------------------------------------------------------------------
202  *!
203  * \brief Simple time control initialization based on external function.
204  *
205  * \remark: if the input pointer is non-NULL, it must point to valid data
206  * when the control function is called, so that value or structure
207  * should not be temporary (i.e. local);
208  *
209  * \param[in] tc pointer to time control structure.
210  * \param[in] control_func pointer to time control funcction.
211  * \param[in] control_input pointer to optional (untyped) value or structure,
212  * or NULL.
213  * \param[in] at_start always active at start ?
214  * \param[in] at_start always active at end ?
215  */
216 /*----------------------------------------------------------------------------*/
217 
218 void
220  cs_time_control_func_t *control_func,
221  void *control_input,
222  bool at_start,
223  bool at_end);
224 
225 /*----------------------------------------------------------------------------
226  *!
227  * \brief Get text description of time control configuration.
228  *
229  * If the time control or time step argument is NULL, true is returned.
230  *
231  * \param[in] tc time control structure
232  * \param[out] desc description string
233  * \param[in] desc_size description string maximum size
234  *
235  * \return true if active, false if inactive
236  */
237 /*----------------------------------------------------------------------------*/
238 
239 void
241  char *desc,
242  size_t desc_size);
243 
244 /*----------------------------------------------------------------------------*/
245 
247 
248 #endif /* __CS_TIME_CONTROL_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:514
#define END_C_DECLS
Definition: cs_defs.h:515
cs_time_control_type_t
Definition: cs_time_control.h:84
@ CS_TIME_CONTROL_FUNCTION
Definition: cs_time_control.h:88
@ CS_TIME_CONTROL_TIME
Definition: cs_time_control.h:87
@ CS_TIME_CONTROL_TIME_STEP
Definition: cs_time_control.h:86
bool cs_time_control_is_active(cs_time_control_t *tc, const cs_time_step_t *ts)
Definition: cs_time_control.c:154
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:76
void cs_time_control_get_description(const cs_time_control_t *tc, char *desc, size_t desc_size)
Definition: cs_time_control.c:338
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.c:232
void cs_time_control_init_by_time(cs_time_control_t *tc, double t_start, double t_end, double t_interval, bool at_start, bool at_end)
Definition: cs_time_control.c:268
void cs_time_control_init_by_func(cs_time_control_t *tc, cs_time_control_func_t *control_func, void *control_input, bool at_start, bool at_end)
Definition: cs_time_control.c:309
Definition: cs_time_control.h:96
bool current_state
Definition: cs_time_control.h:126
double interval_t
Definition: cs_time_control.h:118
int interval_nt
Definition: cs_time_control.h:117
bool at_first
Definition: cs_time_control.h:103
int end_nt
Definition: cs_time_control.h:112
bool at_end
Definition: cs_time_control.h:104
cs_time_control_type_t type
Definition: cs_time_control.h:100
int current_time_step
Definition: cs_time_control.h:127
double last_t
Definition: cs_time_control.h:130
cs_time_control_func_t * control_func
Definition: cs_time_control.h:121
double start_t
Definition: cs_time_control.h:108
void * control_input
Definition: cs_time_control.h:122
int last_nt
Definition: cs_time_control.h:129
bool at_start
Definition: cs_time_control.h:102
int start_nt
Definition: cs_time_control.h:107
double end_t
Definition: cs_time_control.h:113
time step descriptor
Definition: cs_time_step.h:64