14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/CheckedConvert.h"
17#include "arcane/utils/ITraceMng.h"
19#include "arcane/ISubDomain.h"
20#include "arcane/ICaseFunction.h"
21#include "arcane/CommonVariables.h"
23#include "arcane/OutputChecker.h"
34OutputChecker(ISubDomain* sd,
const String& name)
37, m_out_type(OutTypeNone)
39, m_next_global_time(0)
42, m_step_global_time(0)
47assignGlobalTime(VariableScalarReal* variable,
const CaseOptionReal* option)
49 m_next_global_time = variable;
50 m_step_global_time = option;
54assignCPUTime(VariableScalarInteger* variable,
const CaseOptionInteger* option)
56 m_next_cpu_time = variable;
57 m_step_cpu_time = option;
61assignIteration(VariableScalarInteger* variable,
const CaseOptionInteger* option)
63 m_next_iteration = variable;
64 m_step_iteration = option;
86check(Real old_time,Real current_time,
87 Integer current_iteration,Integer cpu_time_used,
88 const String& from_function)
90 String function_id =
"OutputChecker::check >>> ";
92 if (m_out_type==OutTypeNone)
95 ITraceMng* trace = m_sub_domain->traceMng();
98 bool do_output =
false;
100 case OutTypeGlobalTime:
102 Real next_time = (*m_next_global_time)();
103 trace->
debug()<<from_function<<function_id <<
"Next out: " << next_time <<
" Saved Time: " << old_time
104 <<
" Current time: " << current_time <<
" step=" << m_step_global_time;
106 if (math::isEqual(next_time,current_time))
111 else if (next_time>old_time && next_time<current_time){
115 if (do_output || next_time<old_time){
120 Real to_add = m_step_global_time->valueAtParameter(current_time);
121 if (!math::isZero(to_add)){
123 Real diff = (current_time-next_time) / to_add;
125 *m_next_global_time = next_time+to_add;
127 double i_diff = math::floor(diff);
128 *m_next_global_time = next_time+(to_add*(i_diff+1));
130 trace->
debug()<<from_function<<function_id
131 <<
"Next output at time " << next_time
132 <<
" (" << to_add <<
' ' << old_time
133 <<
' ' << current_iteration <<
")";
138 case OutTypeIteration:
140 Integer next_iteration = (*m_next_iteration)();
141 Integer to_add = m_step_iteration->valueAtParameter(current_time);
143 if (next_iteration>current_iteration+to_add){
146 next_iteration = current_iteration;
149 if (next_iteration==current_iteration) do_output =
true;
152 if (next_iteration<=current_iteration){
154 Integer diff = (current_iteration-next_iteration) / to_add;
155 (*m_next_iteration) = next_iteration + ((diff+1)*to_add);
156 trace->
debug()<<from_function<<function_id
157 <<
"Next output at iteration " << (*m_next_iteration)()
158 <<
" (" << to_add <<
' ' << old_time
159 <<
' ' << current_iteration <<
" diff=" << diff <<
")";
166 Integer next_cpu_time = (*m_next_cpu_time)();
167 Integer cpu_time = cpu_time_used;
170 Integer current_cpu_time = cpu_time / 60;
172 if (next_cpu_time<=current_cpu_time)
176 if (next_cpu_time<=current_cpu_time){
177 Integer to_add = m_step_cpu_time->valueAtParameter(current_time);
179 Integer diff = (current_cpu_time-next_cpu_time) / to_add;
180 (*m_next_cpu_time) = next_cpu_time + ((diff+1)*to_add);
181 trace->
debug()<<from_function<<function_id
182 <<
"Next output at cpu time " << (*m_next_cpu_time)()
183 <<
" (" << to_add <<
' ' << current_cpu_time <<
" diff=" << diff <<
")";
188 if (current_cpu_time==0)
213_recomputeTypeGlobalTime()
215 Real current_time = m_sub_domain->commonVariables().globalTime();
216 Real step = m_step_global_time->valueAtParameter(current_time);
218 Real old_next = (*m_next_global_time)();
219 Real next = old_next;
220 Real current_value = current_time;
221 if (!math::isZero(step)){
222 Real index = ::floor(current_value/step);
223 next = step*(index+1.0);
224 *m_next_global_time = next;
227 ITraceMng* tm = m_sub_domain->traceMng();
228 tm->info(4) <<
"Recompute OutputChecker for Global Time: old=" << old_next
236_recomputeTypeCPUTime()
238 Real current_time = m_sub_domain->commonVariables().globalTime();
239 Integer step = m_step_cpu_time->valueAtParameter(current_time);
241 Integer old_next = (*m_next_cpu_time)();
243 double current_value = math::floor(m_sub_domain->commonVariables().globalCPUTime());
246 current_value /= 60.0;
249 Integer index = CheckedConvert::toInteger(current_value / step);
250 next = step*(index+1);
251 *m_next_cpu_time = next;
254 ITraceMng* tm = m_sub_domain->traceMng();
255 tm->info(4) <<
"Recompute OutputChecker for CPU Time: old=" << old_next <<
" new=" << next;
262_recomputeTypeIteration()
264 Real current_time = m_sub_domain->commonVariables().globalTime();
265 Integer step = m_step_iteration->valueAtParameter(current_time);
267 Integer old_next = (*m_next_iteration)();
269 Integer current_value = m_sub_domain->commonVariables().globalIteration();
271 if (old_next<=current_value){
272 *m_next_iteration = current_value;
275 Integer index = current_value / step;
276 next = step*(index+1);
277 *m_next_iteration = next;
281 ITraceMng* tm = m_sub_domain->traceMng();
282 tm->info(4) <<
"Recompute OutputChecker for CPU Time: old=" << old_next <<
" new=" << next;
298initialize(
bool recompute_next_value)
300 ITraceMng* trace = m_sub_domain->traceMng();
301 m_out_type = OutTypeNone;
303 ICaseFunction* func = 0;
306 if (m_step_global_time && m_next_global_time && m_step_global_time->isPresent()){
307 m_out_type = OutTypeGlobalTime;
308 func = m_step_global_time->function();
310 trace->info() <<
"Output in real time controlled by function '" << func->name() <<
"'.";
312 trace->info() <<
"Output in real time every " << (*m_step_global_time)() <<
" seconds.";
313 if (recompute_next_value)
314 _recomputeTypeGlobalTime();
316 else if (m_step_iteration && m_next_iteration && m_step_iteration->value()!=0){
317 m_out_type = OutTypeIteration;
318 func = m_step_iteration->function();
320 trace->info() <<
"Output in iterations controlled by function '" << func->name() <<
"'.";
322 trace->info() <<
"Output every " << (*m_step_iteration)() <<
" iterations.";
323 if (recompute_next_value)
324 _recomputeTypeIteration();
326 else if (m_step_cpu_time && m_next_cpu_time && m_step_cpu_time->isPresent()){
327 m_out_type = OutTypeCPUTime;
328 func = m_step_cpu_time->function();
330 trace->info() <<
"Output in CPU time controlled by function '" << func->name() <<
"'.";
332 trace->info() <<
"Output in CPU time every " << (*m_step_cpu_time)() <<
" minutes.";
333 if (recompute_next_value)
334 _recomputeTypeCPUTime();
337 trace->info() <<
"No output required.";
344nextGlobalTime()
const
347 if (m_next_global_time)
348 v = (*m_next_global_time)();
359 if (m_next_iteration)
360 v = (*m_next_iteration)();
372 v= (*m_next_cpu_time)();
Interface du gestionnaire de traces.
virtual TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium)=0
Flot pour un message de debug.
Chaîne de caractères unicode.
double Real
Type représentant un réel.
Int32 Integer
Type représentant un entier.