Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ITimeLoopMng.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ITimeLoopMng.h (C) 2000-2025 */
9/* */
10/* Time loop manager interface. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITIMELOOPMNG_H
13#define ARCANE_CORE_ITIMELOOPMNG_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24class IBackwardMng;
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29enum class eTimeLoopEventType
30{
31 BeginEntryPoint,
32 EndEntryPoint,
33 BeginIteration,
34 EndIteration
35};
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40/*!
41 * \brief Reason for stopping the code.
42 */
44{
45 //! Indicates that the code is not yet in stop mode.
46 NoStop = 0,
47 //! No specific reason
49 //! Stop due to an error
50 Error = 2,
51 //! Stop because final time was reached
53 //! Stop because maximum number of iterations specified was reached.
55};
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
60/*!
61 * \brief Interface for the time loop manager.
62 *
63 The time loop consists of three parts, executed in the following order:
64 \arg initialization (Init)
65 \arg compute loop (ComputeLoop)
66 \arg termination (Exit)
67
68 Initialization and termination are called only once.
69 However, the compute loop is executed as long as no one requests
70 an explicit stop via the stopComputeLoop() method.
71 */
73{
74 public:
75
76 virtual ~ITimeLoopMng() {} //!< Frees resources.
77
78 public:
79
80 virtual void build() = 0;
81
82 //virtual void initialize() =0;
83
84 public:
85
86 //!< Returns the sub-domain manager
87 virtual ISubDomain* subDomain() const = 0;
88
89 //! Executes the exit entry points
90 virtual void execExitEntryPoints() = 0;
91
92 //! Executes the build entry points
93 virtual void execBuildEntryPoints() = 0;
94
95 /*! \brief Executes the initialization entry points.
96 * \param is_continue is true if resuming */
97 virtual void execInitEntryPoints(bool is_continue) = 0;
98
99 //! Executes the entry points after load balancing
100 //virtual void execLoadBalanceEntryPoints() =0;
101
102 //! Executes the entry points after load balancing
104
105 //! Executes the entry points after refinement
107
108 /*!
109 * \brief Indicates that the compute loop must stop.
110 *
111 * If \a is_final_time is true, it indicates that the final time has been reached.
112 * If \a has_error is true, it indicates that the calculation stopped due to an
113 * error. In this case, the application return code will be different from 0.
114 */
115 virtual void stopComputeLoop(bool is_final_time, bool has_error = false) = 0;
116
117 //! Returns \a true if the final time has been reached.
118 virtual bool finalTimeReached() const = 0;
119
120 //! Returns the CPU time used in seconds.
121 virtual Real cpuTimeUsed() const = 0;
122
123 //! Returns the list of 'ComputeLoop' type entry points in the time loop.
125
126 //! List of all entry points for the current time loop.
128
129 /*!
130 * Executes the next entry point.
131 *
132 * Returns in \a is_last \e true if the entry point that was just
133 * executed is the last one of the iteration.
134 */
135 virtual void doExecNextEntryPoint(bool& is_last) = 0;
136
137 //! Returns the next entry point to execute or 0 if there is none
139
140 //! Returns the entry point currently being executed or 0 if there is none
142
143 /*!
144 * \brief Starts the execution of a compute loop iteration.
145 *
146 * \retval 0 if the code should continue.
147 * \retval >0 if the calculation stops normally.
148 * \retval <0 if the calculation stops due to an error.
149 */
150 virtual int doOneIteration() = 0;
151
152 /*!
153 * \brief Executes the compute loop.
154 *
155 * The compute loop is executed until the stopComputeLoop() method is called
156 * or the number of loops performed equals \a max_loop if \a max_loop is not 0.
157 * \retval 1 if the code stops normally due to final time reached
158 * \retval 2 if the code stops normally due to \a max_loop reached
159 * \retval <0 if the calculation stops due to an error.
160 */
161 virtual int doComputeLoop(Integer max_loop = 0) = 0;
162
163 //@{
164 //! Registration and selection of the time loop.
165 /*!
166 * \brief Registers a time loop.
167 * Registers the time loop \a time_loop.
168 *
169 * If a time loop with the same name as \a time_loop is already referenced,
170 * the new one replaces the old one.
171 */
172 virtual void registerTimeLoop(ITimeLoop* time_loop) = 0;
173
174 /*! \brief Positions the time loop to be executed.
175 * Selects the time loop named \a name as the one to be
176 * executed. This method performs the following operations:
177 * <ul>
178 * <li>Starting from the name \a name, it searches for the time loop to use.
179 * This time loop must have been referenced by the call to
180 * registerTimeLoop()</li>
181 * <li>For each entry point name of the time loop,
182 * it searches for the corresponding entry point (IEntryPoint) registered in
183 * the architecture</li>
184 * <li>It constructs the list of entry points to be called during
185 * initialization, in the compute loop, and during termination,
186 * taking into account the entry points that are automatically loaded.</li>
187 * <li>It determines the list of modules used by considering that a module
188 * is used if and only if one of its entry points is used</li>
189 * </ul>
190 *
191 * The operation fails and causes a fatal error in one of the following cases:
192 * \arg this method has already been called,
193 * \arg no time loop named \a name is registered,
194 * \arg one of the entry point names in the list does not correspond to
195 * any referenced entry point.
196 *
197 * If \a name is null, the time loop used is the default loop which contains no explicit entry points. It only contains
198 * the automatically registered entry points.
199 *
200 * \retval true in case of error,
201 * \retval false otherwise.
202 */
203 virtual void setUsedTimeLoop(const String& name) = 0;
204 //@}
205
206 //! Returns the time loop used
207 virtual ITimeLoop* usedTimeLoop() const = 0;
208
209 virtual void setBackwardMng(IBackwardMng* backward_mng) = 0;
210
211 virtual IBackwardMng* getBackwardMng() const = 0;
212
213 /*!
214 * \brief Performs a backward step.
215 *
216 * This method just positions a marker. The backward step actually
217 * takes place when the currently executing entry point finishes.
218 *
219 * After backward step, the backward entry points are called.
220 *
221 * \warning During parallel execution, this method must be
222 * called by all sub-domains.
223 */
224 virtual void goBackward() = 0;
225
226 /*! \brief True if currently in a backward step.
227 *
228 * A backward step is active as long as the physical time is less than
229 * the physical time reached before the backward step trigger.
230 */
231 virtual bool isDoingBackward() = 0;
232
233 /*!
234 * \brief Schedules a mesh partitioning using the partition tool
235 * \a mesh_partitioner.
236 *
237 * This method just positions a marker. The partitioning actually
238 * takes place when the last entry point of the compute loop is finished (end of an iteration).
239 *
240 * After partitioning, the mesh change entry points are called.
241 *
242 * \warning During parallel execution, this method must be
243 * called by all sub-domains.
244 */
245 virtual void registerActionMeshPartition(IMeshPartitionerBase* mesh_partitioner) = 0;
246
247 /*!
248 * \brief Positions the period between two saves for backward step.
249 * If this value is null, backward step is disabled.
250 */
251 virtual void setBackwardSavePeriod(Integer n) = 0;
252
253 /*!
254 * \brief Positions the state of the verification mode
255 */
256 virtual void setVerificationActive(bool is_active) = 0;
257
258 /*!
259 * \brief Performs a verification.
260 *
261 * This operation is collective.
262 *
263 * This operation allows manually performing a verification operation,
264 * whose name is \a name. This name \a name must be unique for
265 * given iteration.
266 */
267 virtual void doVerification(const String& name) = 0;
268
269 /*!
270 * \brief Returns in \a names the list of time loop names.
271 */
272 virtual void timeLoopsName(StringCollection& names) const = 0;
273
274 //! Returns in \a time_loops the list of time loops.
275 virtual void timeLoops(TimeLoopCollection& time_loops) const = 0;
276
277 //! Creates a time loop named \a name.
278 virtual ITimeLoop* createTimeLoop(const String& name) = 0;
279
280 //! Number of compute loops performed.
281 virtual Integer nbLoop() const = 0;
282
283 /*!
284 * \brief Observable on the instance.
285 *
286 * The type of the observable is given by \a type
287 */
288 virtual IObservable* observable(eTimeLoopEventType type) = 0;
289
290 //! Positions the reason for stopping the code
291 virtual void setStopReason(eTimeLoopStopReason reason) = 0;
292
293 /*!
294 * \brief Reason for stopping the code.
295 *
296 * If the value is eTimeLoopStopReason::NoStop, then the code
297 * is not stopping.
298 */
299 virtual eTimeLoopStopReason stopReason() const = 0;
300};
301
302/*---------------------------------------------------------------------------*/
303/*---------------------------------------------------------------------------*/
304
305} // namespace Arcane
306
307/*---------------------------------------------------------------------------*/
308/*---------------------------------------------------------------------------*/
309
310#endif
Declarations of Arcane's general types.
Interface of a module entry point.
Definition IEntryPoint.h:35
Interface of a mesh partitioner.
Interface of the subdomain manager.
Definition ISubDomain.h:75
Interface for the time loop manager.
virtual EntryPointCollection loopEntryPoints()=0
Returns the list of 'ComputeLoop' type entry points in the time loop.
virtual Integer nbLoop() const =0
Number of compute loops performed.
virtual void timeLoopsName(StringCollection &names) const =0
Returns in names the list of time loop names.
virtual void timeLoops(TimeLoopCollection &time_loops) const =0
Returns in time_loops the list of time loops.
virtual ITimeLoop * createTimeLoop(const String &name)=0
Creates a time loop named name.
virtual int doComputeLoop(Integer max_loop=0)=0
Executes the compute loop.
virtual void execBuildEntryPoints()=0
Executes the build entry points.
virtual IEntryPoint * currentEntryPoint()=0
Returns the entry point currently being executed or 0 if there is none.
virtual EntryPointCollection usedTimeLoopEntryPoints()=0
List of all entry points for the current time loop.
virtual void goBackward()=0
Performs a backward step.
virtual eTimeLoopStopReason stopReason() const =0
Reason for stopping the code.
virtual void setVerificationActive(bool is_active)=0
Positions the state of the verification mode.
virtual void doVerification(const String &name)=0
Performs a verification.
virtual ITimeLoop * usedTimeLoop() const =0
Returns the time loop used.
virtual IEntryPoint * nextEntryPoint()=0
Returns the next entry point to execute or 0 if there is none.
virtual void execOnMeshRefinementEntryPoints()=0
Executes the entry points after refinement.
virtual bool isDoingBackward()=0
True if currently in a backward step.
virtual void execInitEntryPoints(bool is_continue)=0
Executes the initialization entry points.
virtual void stopComputeLoop(bool is_final_time, bool has_error=false)=0
Indicates that the compute loop must stop.
virtual void setStopReason(eTimeLoopStopReason reason)=0
Positions the reason for stopping the code.
virtual void registerTimeLoop(ITimeLoop *time_loop)=0
Registration and selection of the time loop.
virtual void setBackwardSavePeriod(Integer n)=0
Positions the period between two saves for backward step. If this value is null, backward step is dis...
virtual Real cpuTimeUsed() const =0
Returns the CPU time used in seconds.
virtual IObservable * observable(eTimeLoopEventType type)=0
Observable on the instance.
virtual void setUsedTimeLoop(const String &name)=0
Positions the time loop to be executed. Selects the time loop named name as the one to be executed....
virtual ~ITimeLoopMng()
Frees resources.
virtual void registerActionMeshPartition(IMeshPartitionerBase *mesh_partitioner)=0
Schedules a mesh partitioning using the partition tool mesh_partitioner.
virtual int doOneIteration()=0
Starts the execution of a compute loop iteration.
virtual void doExecNextEntryPoint(bool &is_last)=0
virtual void execOnMeshChangedEntryPoints()=0
Executes the entry points after load balancing.
virtual bool finalTimeReached() const =0
Returns true if the final time has been reached.
virtual void execExitEntryPoints()=0
Executes the exit entry points.
virtual ISubDomain * subDomain() const =0
< Returns the sub-domain manager
Interface of a time loop.
Definition ITimeLoop.h:33
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
eTimeLoopStopReason
Reason for stopping the code.
@ MaxIterationReached
Stop because maximum number of iterations specified was reached.
@ NoStop
Indicates that the code is not yet in stop mode.
@ FinalTimeReached
Stop because final time was reached.
@ NoReason
No specific reason.
@ Error
Stop due to an error.
Int32 Integer
Type representing an integer.
Collection< String > StringCollection
Collection of strings.
Definition UtilsTypes.h:506
Collection< ITimeLoop * > TimeLoopCollection
Collection of time loops.
double Real
Type representing a real number.
Collection< IEntryPoint * > EntryPointCollection
Collection of entry points.