OGS
ProcessLib::TimeLoop Class Reference

Detailed Description

Time loop capable of time-integrating several processes at once.

Definition at line 32 of file TimeLoop.h.

#include <TimeLoop.h>

Collaboration diagram for ProcessLib::TimeLoop:
[legend]

Public Member Functions

 TimeLoop (std::vector< Output > &&outputs, std::vector< std::unique_ptr< ProcessData > > &&per_process_data, std::unique_ptr< NumLib::StaggeredCoupling > &&staggered_coupling, const NumLib::Time &start_time, const NumLib::Time &end_time)
void initialize ()
 initialize output, convergence criterion, etc.
void outputLastTimeStep () const
 ~TimeLoop ()
bool executeTimeStep ()
bool calculateNextTimeStep ()
NumLib::Time endTime () const
NumLib::Time currentTime () const

Public Attributes

bool successful_time_step = true

Private Types

using TimeStepConstraintCallback

Private Member Functions

bool preTsNonlinearSolvePostTs (NumLib::Time const &t, double const dt, std::size_t const timesteps)
NumLib::NonlinearSolverStatus solveUncoupledEquationSystems (const NumLib::Time &t, const double dt, const std::size_t timestep_id)
 Member to solver non coupled systems of equations, which can be a single system of equations, or several systems of equations without any dependency among the different systems.
NumLib::NonlinearSolverStatus solveCoupledEquationSystemsByStaggeredScheme (const NumLib::Time &t, const double dt, const std::size_t timestep_id)
 Member to solver coupled systems of equations by the staggered scheme.
std::pair< NumLib::TimeIncrement, bool > computeTimeStepping (const double prev_dt, NumLib::Time &t, std::size_t &accepted_steps, std::size_t &rejected_steps, std::vector< TimeStepConstraintCallback > const &time_step_constraints)
template<typename OutputClassMember>
void outputSolutions (unsigned timestep, const double t, OutputClassMember output_class_member) const
std::vector< TimeStepConstraintCallbackgenerateOutputTimeStepConstraints (std::vector< double > &&fixed_times) const
void preOutputInitialConditions (NumLib::Time const &t, const double dt) const

Private Attributes

std::vector< GlobalVector * > _process_solutions
std::vector< GlobalVector * > _process_solutions_prev
std::vector< Output_outputs
std::vector< std::unique_ptr< ProcessData > > _per_process_data
const NumLib::Time _start_time
const NumLib::Time _end_time
NumLib::Time _current_time = _start_time
std::size_t _accepted_steps = 0
std::size_t _rejected_steps = 0
NumLib::TimeIncrement _dt {0.}
int _repeating_times_of_rejected_step = 0
bool _previous_step_rejected = false
int _global_coupling_number_iterations = 0
std::unique_ptr< NumLib::StaggeredCoupling_staggered_coupling

Member Typedef Documentation

◆ TimeStepConstraintCallback

Initial value:
std::function<double(NumLib::Time const&, double)>

Definition at line 91 of file TimeLoop.h.

Constructor & Destructor Documentation

◆ TimeLoop()

ProcessLib::TimeLoop::TimeLoop ( std::vector< Output > && outputs,
std::vector< std::unique_ptr< ProcessData > > && per_process_data,
std::unique_ptr< NumLib::StaggeredCoupling > && staggered_coupling,
const NumLib::Time & start_time,
const NumLib::Time & end_time )

Definition at line 263 of file TimeLoop.cpp.

268 : _outputs{std::move(outputs)},
269 _per_process_data(std::move(per_process_data)),
270 _start_time(start_time),
271 _end_time(end_time),
272 _staggered_coupling(std::move(staggered_coupling))
273{
274}
std::vector< std::unique_ptr< ProcessData > > _per_process_data
Definition TimeLoop.h:126
std::vector< Output > _outputs
Definition TimeLoop.h:125
std::unique_ptr< NumLib::StaggeredCoupling > _staggered_coupling
Definition TimeLoop.h:141
const NumLib::Time _end_time
Definition TimeLoop.h:129
const NumLib::Time _start_time
Definition TimeLoop.h:128

References _end_time, _outputs, _per_process_data, _staggered_coupling, and _start_time.

◆ ~TimeLoop()

ProcessLib::TimeLoop::~TimeLoop ( )

Definition at line 754 of file TimeLoop.cpp.

755{
756 for (auto* x : _process_solutions)
757 {
759 }
760 for (auto* x : _process_solutions_prev)
761 {
763 }
764}
virtual void releaseVector(GlobalVector const &x)=0
std::vector< GlobalVector * > _process_solutions
Definition TimeLoop.h:123
std::vector< GlobalVector * > _process_solutions_prev
Definition TimeLoop.h:124
static NUMLIB_EXPORT VectorProvider & provider

References _process_solutions, _process_solutions_prev, and NumLib::GlobalVectorProvider::provider.

Member Function Documentation

◆ calculateNextTimeStep()

bool ProcessLib::TimeLoop::calculateNextTimeStep ( )

Computes and sets the next timestep.

Attention
The timestepper might reject the current timestep and repeat it (with a reduced timestep size).
Returns
true if the simulation (time) has not finished, yet, false otherwise.

Definition at line 541 of file TimeLoop.cpp.

542{
543 const double prev_dt = _dt();
544 // keep a copy of _current_time to check if a new point in time is computed
545 auto const current_time = _current_time;
546
547 const std::size_t timesteps = _accepted_steps + 1;
548
549 auto const time_step_constraints = generateOutputTimeStepConstraints(
551
552 // _previous_step_rejected is also checked in computeTimeStepping.
553 std::tie(_dt, _previous_step_rejected) =
555 _rejected_steps, time_step_constraints);
556
558 {
559 outputSolutions(timesteps, current_time(), &Output::doOutput);
560 }
561
562 // check if the newly computed time point (=_current_time + _dt()) differs
563 // from the previously computed time point (current_time) saved at the
564 // beginning of the method
565 if (current_time == (_current_time + _dt()))
566 {
567 DBUG("current time == previous time + dt : {:a} == {:a} + {:a} = {:a}",
568 current_time(), _current_time(), _dt(), _current_time() + _dt());
569 ERR("The time increment {} results in exactly the same time {} as the "
570 "previous rejected time step.\n"
571 "Time stepping stops at time step {:d} and time {}.",
572 _dt, current_time, timesteps, _current_time);
573 return false;
574 }
575
577 {
578 return false;
579 }
580
581 return true;
582}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
void doOutput(Process const &process, const int process_id, int const timestep, const NumLib::Time &t, int const iteration, bool const converged, std::vector< GlobalVector * > const &xs) const
NumLib::TimeIncrement _dt
Definition TimeLoop.h:133
NumLib::Time _current_time
Definition TimeLoop.h:130
std::pair< NumLib::TimeIncrement, bool > computeTimeStepping(const double prev_dt, NumLib::Time &t, std::size_t &accepted_steps, std::size_t &rejected_steps, std::vector< TimeStepConstraintCallback > const &time_step_constraints)
Definition TimeLoop.cpp:289
void outputSolutions(unsigned timestep, const double t, OutputClassMember output_class_member) const
Definition TimeLoop.cpp:728
std::size_t _accepted_steps
Definition TimeLoop.h:131
std::size_t _rejected_steps
Definition TimeLoop.h:132
std::vector< TimeStepConstraintCallback > generateOutputTimeStepConstraints(std::vector< double > &&fixed_times) const
Definition TimeLoop.cpp:453
std::vector< double > calculateUniqueFixedTimesForAllOutputs(std::vector< Output > const &outputs)

References _accepted_steps, _current_time, _dt, _end_time, _outputs, _previous_step_rejected, _rejected_steps, ProcessLib::calculateUniqueFixedTimesForAllOutputs(), computeTimeStepping(), DBUG(), ProcessLib::Output::doOutput(), ERR(), generateOutputTimeStepConstraints(), and outputSolutions().

◆ computeTimeStepping()

std::pair< NumLib::TimeIncrement, bool > ProcessLib::TimeLoop::computeTimeStepping ( const double prev_dt,
NumLib::Time & t,
std::size_t & accepted_steps,
std::size_t & rejected_steps,
std::vector< TimeStepConstraintCallback > const & time_step_constraints )
private

Find the minimum time step size among the predicted step sizes of processes and step it as common time step size.

Parameters
prev_dtPrevious time step size.
tCurrent time.
accepted_stepsAccepted time steps that are counted in this function.
rejected_stepsRejected time steps that are counted in this function.
time_step_constraintsFunctions that are evaluate to influence the time step size (for instance a fixed output time)
Returns
the time step size and the information if the previous time step was rejected

Definition at line 289 of file TimeLoop.cpp.

293{
294 bool all_process_steps_accepted = true;
295 // Get minimum time step size among step sizes of all processes.
296 NumLib::TimeIncrement dt{std::numeric_limits<double>::max()};
297 constexpr double eps = std::numeric_limits<double>::epsilon();
298
299 bool const is_initial_step =
300 std::any_of(_per_process_data.begin(), _per_process_data.end(),
301 [](auto const& ppd) -> bool
302 { return ppd->timestep_current.timeStepNumber() == 0; });
303
304 // In the staggered scheme the time step size is controlled by the maximum
305 // over the number of global coupling iterations and the per-process
306 // nonlinear solver iterations of all processes.
307 int staggered_number_iterations = 0;
309 {
310 auto const ppd_max_iterations = std::ranges::max_element(
311 _per_process_data, {}, [](auto const& ppd)
312 { return ppd->nonlinear_solver_status.number_iterations; });
313 staggered_number_iterations = std::max(
315 (*ppd_max_iterations)->nonlinear_solver_status.number_iterations);
316 }
317
318 for (std::size_t i = 0; i < _per_process_data.size(); i++)
319 {
320 auto& ppd = *_per_process_data[i];
321 auto& timestep_algorithm = *ppd.timestep_algorithm.get();
322
323 auto const& x = *_process_solutions[i];
324 auto const& x_prev = *_process_solutions_prev[i];
325
326 const double solution_error =
327 computationOfChangeNeeded(timestep_algorithm, t)
329 x, x_prev,
330 ppd.conv_crit.get() ? ppd.conv_crit->getVectorNormType()
332 : 0.0;
333
334 ppd.timestep_current.setAccepted(
335 ppd.nonlinear_solver_status.error_norms_met);
336
337 int const number_iterations =
338 _staggered_coupling ? staggered_number_iterations
339 : ppd.nonlinear_solver_status.number_iterations;
340
341 auto const timestepper_dt = timestep_algorithm.next(
342 solution_error, number_iterations, ppd.timestep_previous,
343 ppd.timestep_current);
344
345 if (!ppd.timestep_current.isAccepted())
346 {
347 // Not all processes have accepted steps.
348 all_process_steps_accepted = false;
349 }
350
351 if (!ppd.nonlinear_solver_status.error_norms_met)
352 {
353 WARN(
354 "Time step will be rejected due to nonlinear solver "
355 "divergence.");
356 all_process_steps_accepted = false;
357 }
358
359 if (timestepper_dt > eps || t < timestep_algorithm.end())
360 {
361 dt = NumLib::TimeIncrement{std::min(timestepper_dt, dt())};
362 }
363 }
364
365 if (all_process_steps_accepted)
366 {
368 }
369 else
370 {
372 }
373
374 bool previous_step_rejected = false;
375 if (!is_initial_step)
376 {
377 if (all_process_steps_accepted)
378 {
379 accepted_steps++;
380 previous_step_rejected = false;
381 }
382 else
383 {
384 if (t <= _end_time)
385 {
386 t -= prev_dt;
387 rejected_steps++;
388 previous_step_rejected = true;
389 }
390 }
391 }
392
393 // adjust step size considering external communciation_point_calculators
394 for (auto const& time_step_constraint : time_step_constraints)
395 {
396 dt = NumLib::TimeIncrement{
397 std::min(dt(), time_step_constraint(t, dt()))};
398 }
399
400 // Check whether the time stepping is stabilized
401 if (std::abs(dt() - prev_dt) < eps)
402 {
403 if (previous_step_rejected)
404 {
405 OGS_FATAL(
406 "The new step size of {} is the same as that of the previous "
407 "rejected time step. \nPlease re-run ogs with a proper "
408 "adjustment in the numerical settings, \ne.g. those for time "
409 "stepper, local or global non-linear solver.",
410 dt);
411 }
412 else
413 {
414 DBUG("The time stepping is stabilized with the step size of {}.",
415 dt);
416 }
417 }
418
419 // Reset the time step with the minimum step size, dt
420 // Update the solution of the previous time step.
421 for (std::size_t i = 0; i < _per_process_data.size(); i++)
422 {
423 if (all_process_steps_accepted)
424 {
425 auto& ppd = *_per_process_data[i];
426 NumLib::updateTimeSteps(dt(), ppd.timestep_previous,
427 ppd.timestep_current);
428 }
429
430 auto& x = *_process_solutions[i];
431 auto& x_prev = *_process_solutions_prev[i];
432 if (all_process_steps_accepted)
433 {
434 MathLib::LinAlg::copy(x, x_prev); // pushState
435 }
436 else
437 {
438 if (t <= _end_time)
439 {
440 WARN(
441 "Time step {:d} was rejected {:d} times and it will be "
442 "repeated with a reduced step size.",
443 accepted_steps + 1, _repeating_times_of_rejected_step);
444 MathLib::LinAlg::copy(x_prev, x); // popState
445 }
446 }
447 }
448
449 return {dt, previous_step_rejected};
450}
#define OGS_FATAL(...)
Definition Error.h:10
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
int _global_coupling_number_iterations
Definition TimeLoop.h:139
int _repeating_times_of_rejected_step
Definition TimeLoop.h:134
void copy(PETScVector const &x, PETScVector &y)
Definition LinAlg.cpp:30
double computeRelativeNorm(VectorType const &x, VectorType const &y, MathLib::VecNormType norm_type)
Definition LinAlg.h:298
void updateTimeSteps(double const dt, TimeStep &previous_timestep, TimeStep &current_timestep)
Definition TimeStep.h:101
bool computationOfChangeNeeded(NumLib::TimeStepAlgorithm const &timestep_algorithm, NumLib::Time const &time)
Definition TimeLoop.cpp:276

References _end_time, _global_coupling_number_iterations, _per_process_data, _process_solutions, _process_solutions_prev, _repeating_times_of_rejected_step, _staggered_coupling, ProcessLib::computationOfChangeNeeded(), MathLib::LinAlg::computeRelativeNorm(), MathLib::LinAlg::copy(), DBUG(), MathLib::NORM2, OGS_FATAL, NumLib::updateTimeSteps(), and WARN().

Referenced by calculateNextTimeStep(), and initialize().

◆ currentTime()

NumLib::Time ProcessLib::TimeLoop::currentTime ( ) const
inline

Definition at line 57 of file TimeLoop.h.

57{ return _current_time; }

References _current_time.

◆ endTime()

NumLib::Time ProcessLib::TimeLoop::endTime ( ) const
inline

Definition at line 56 of file TimeLoop.h.

56{ return _end_time; }

References _end_time.

◆ executeTimeStep()

bool ProcessLib::TimeLoop::executeTimeStep ( )

Definition at line 520 of file TimeLoop.cpp.

521{
522 BaseLib::RunTime time_timestep;
523 time_timestep.start();
524
525 _current_time += _dt();
526
527 const std::size_t timesteps = _accepted_steps + 1;
528 // TODO(wenqing): , input option for time unit.
529 INFO("Time step #{:d} started. Time: {}. Step size: {}.", timesteps,
531
533
536 INFO("[time] Time step #{:d} took {:g} s.", timesteps,
537 time_timestep.elapsed());
539}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:31
void start()
Start the timer.
Definition RunTime.h:21
bool preTsNonlinearSolvePostTs(NumLib::Time const &t, double const dt, std::size_t const timesteps)
Definition TimeLoop.cpp:599
void updateDeactivatedSubdomains(std::vector< std::unique_ptr< ProcessLib::ProcessData > > const &per_process_data, double const t)
Definition TimeLoop.cpp:22

References _accepted_steps, _current_time, _dt, _per_process_data, BaseLib::RunTime::elapsed(), INFO(), preTsNonlinearSolvePostTs(), BaseLib::RunTime::start(), and successful_time_step.

◆ generateOutputTimeStepConstraints()

std::vector< TimeLoop::TimeStepConstraintCallback > ProcessLib::TimeLoop::generateOutputTimeStepConstraints ( std::vector< double > && fixed_times) const
private

Definition at line 453 of file TimeLoop.cpp.

455{
456 std::vector<TimeStepConstraintCallback> const time_step_constraints{
457 [fixed_times = std::move(fixed_times)](NumLib::Time const& t, double dt)
458 { return NumLib::possiblyClampDtToNextFixedTime(t, dt, fixed_times); },
459 [this](NumLib::Time const& t, double dt) -> double
460 {
461 if (t < _end_time && _end_time < t + dt)
462 {
463 return _end_time() - t();
464 }
465 return dt;
466 }};
467 return time_step_constraints;
468}
double possiblyClampDtToNextFixedTime(Time const &t, double const dt, std::vector< double > const &fixed_output_times)

References _end_time, and NumLib::possiblyClampDtToNextFixedTime().

Referenced by calculateNextTimeStep(), and initialize().

◆ initialize()

void ProcessLib::TimeLoop::initialize ( )

initialize output, convergence criterion, etc.

Definition at line 471 of file TimeLoop.cpp.

472{
473 for (auto const& process_data : _per_process_data)
474 {
475 auto& pcs = process_data->process;
476 for (auto& output : _outputs)
477 {
478 output.addProcess(pcs);
479 }
480
481 setTimeDiscretizedODESystem(*process_data);
482
483 if (auto* conv_crit =
484 dynamic_cast<NumLib::ConvergenceCriterionPerComponent*>(
485 process_data->conv_crit.get()))
486 {
487 int const process_id = process_data->process_id;
488 conv_crit->setDOFTable(pcs.getDOFTable(process_id), pcs.getMesh());
489 }
490 }
491
492 // initial solution storage
495
497 {
498 _staggered_coupling->initializeCoupledSolutions(_process_solutions);
499 }
500
502
503 auto const time_step_constraints = generateOutputTimeStepConstraints(
505
506 std::tie(_dt, _previous_step_rejected) =
508 _rejected_steps, time_step_constraints);
509
510 // Output initial conditions
511 {
514 }
515
518}
void preOutputInitialConditions(NumLib::Time const &t, const double dt) const
Definition TimeLoop.cpp:766
void setTimeDiscretizedODESystem(ProcessData &process_data, NumLib::ODESystem< ODETag, NumLib::NonlinearSolverTag::Picard > &ode_sys)
Definition TimeLoop.cpp:108
void calculateNonEquilibriumInitialResiduum(std::vector< std::unique_ptr< ProcessData > > const &per_process_data, std::vector< GlobalVector * > const &process_solutions, std::vector< GlobalVector * > const &process_solutions_prev)
Definition TimeLoop.cpp:202
std::pair< std::vector< GlobalVector * >, std::vector< GlobalVector * > > setInitialConditions(NumLib::Time const &t0, std::vector< std::unique_ptr< ProcessData > > const &per_process_data)
Definition TimeLoop.cpp:167

References _accepted_steps, _current_time, _dt, _outputs, _per_process_data, _previous_step_rejected, _process_solutions, _process_solutions_prev, _rejected_steps, _staggered_coupling, _start_time, ProcessLib::calculateNonEquilibriumInitialResiduum(), ProcessLib::calculateUniqueFixedTimesForAllOutputs(), computeTimeStepping(), ProcessLib::Output::doOutput(), generateOutputTimeStepConstraints(), outputSolutions(), preOutputInitialConditions(), ProcessLib::setInitialConditions(), and ProcessLib::setTimeDiscretizedODESystem().

◆ outputLastTimeStep()

void ProcessLib::TimeLoop::outputLastTimeStep ( ) const

Definition at line 584 of file TimeLoop.cpp.

585{
586 INFO(
587 "The whole computation of the time stepping took {:d} steps, in which\n"
588 "\t the accepted steps are {:d}, and the rejected steps are {:d}.\n",
590
591 // output last time step
593 {
596 }
597}
void doOutputLastTimestep(Process const &process, const int process_id, int const timestep, const NumLib::Time &t, int const iteration, bool const converged, std::vector< GlobalVector * > const &xs) const

References _accepted_steps, _current_time, _rejected_steps, ProcessLib::Output::doOutputLastTimestep(), INFO(), outputSolutions(), and successful_time_step.

◆ outputSolutions()

template<typename OutputClassMember>
void ProcessLib::TimeLoop::outputSolutions ( unsigned timestep,
const double t,
OutputClassMember output_class_member ) const
private

Definition at line 728 of file TimeLoop.cpp.

730{
731 for (auto const& process_data : _per_process_data)
732 {
733 // If nonlinear solver diverged, the solution has already been
734 // saved.
735 if (!process_data->nonlinear_solver_status.error_norms_met)
736 {
737 continue;
738 }
739
740 auto const process_id = process_data->process_id;
741 auto const& pcs = process_data->process;
742
743 for (auto const& output_object : _outputs)
744 {
745 (output_object.*output_class_member)(
746 pcs, process_id, timestep, NumLib::Time(t),
747 process_data->nonlinear_solver_status.number_iterations,
748 process_data->nonlinear_solver_status.error_norms_met,
750 }
751 }
752}

References _outputs, _per_process_data, and _process_solutions.

Referenced by calculateNextTimeStep(), initialize(), and outputLastTimeStep().

◆ preOutputInitialConditions()

void ProcessLib::TimeLoop::preOutputInitialConditions ( NumLib::Time const & t,
const double dt ) const
private

Definition at line 766 of file TimeLoop.cpp.

768{
769 for (auto const& process_data : _per_process_data)
770 {
771 // If nonlinear solver diverged, the solution has already been
772 // saved.
773 if (!process_data->nonlinear_solver_status.error_norms_met)
774 {
775 continue;
776 }
777
778 auto const process_id = process_data->process_id;
779 auto& pcs = process_data->process;
780
781 process_data->time_disc->nextTimestep(t(), dt);
782
783 pcs.preTimestep(_process_solutions, _start_time(), dt, process_id);
784
785 pcs.preOutput(_start_time(), dt, _process_solutions,
786 _process_solutions_prev, process_id);
787
788 // Update secondary variables, which might be uninitialized, before
789 // output.
790 pcs.computeSecondaryVariable(_start_time(), dt, _process_solutions,
791 *_process_solutions_prev[process_id],
792 process_id);
793 }
794}

References _per_process_data, _process_solutions, _process_solutions_prev, and _start_time.

Referenced by initialize().

◆ preTsNonlinearSolvePostTs()

bool ProcessLib::TimeLoop::preTsNonlinearSolvePostTs ( NumLib::Time const & t,
double const dt,
std::size_t const timesteps )
private

Definition at line 599 of file TimeLoop.cpp.

601{
603
604 NumLib::NonlinearSolverStatus nonlinear_solver_status;
605
607 {
608 nonlinear_solver_status =
610 }
611 else
612 {
613 nonlinear_solver_status =
614 solveUncoupledEquationSystems(t, dt, timesteps);
615 }
616
617 // Run post time step only if the last iteration was successful.
618 // Otherwise it runs the risks to get the same errors as in the last
619 // iteration, an exception thrown in assembly, for example.
620 if (nonlinear_solver_status.error_norms_met)
621 {
622 // Later on, the timestep_algorithm might reject the timestep. We assume
623 // that this is a rare case, so still, we call preOutput() here. We
624 // don't expect a large overhead from it.
627 _outputs);
628
632 }
633 return nonlinear_solver_status.error_norms_met;
634}
NumLib::NonlinearSolverStatus solveUncoupledEquationSystems(const NumLib::Time &t, const double dt, const std::size_t timestep_id)
Member to solver non coupled systems of equations, which can be a single system of equations,...
Definition TimeLoop.cpp:659
NumLib::NonlinearSolverStatus solveCoupledEquationSystemsByStaggeredScheme(const NumLib::Time &t, const double dt, const std::size_t timestep_id)
Member to solver coupled systems of equations by the staggered scheme.
Definition TimeLoop.cpp:702
void preTimestepForAllProcesses(NumLib::Time const &t, double const dt, std::vector< std::unique_ptr< ProcessData > > const &per_process_data, std::vector< GlobalVector * > const &_process_solutions)
Definition TimeLoop.cpp:75
void postTimestepForAllProcesses(NumLib::Time const &t, double const dt, std::vector< std::unique_ptr< ProcessData > > const &per_process_data, std::vector< GlobalVector * > const &process_solutions, std::vector< GlobalVector * > const &process_solutions_prev)
Definition TimeLoop.cpp:88
void preOutputForAllProcesses(int const timestep, NumLib::Time const &t, double const dt, const NumLib::Time &end_time, std::vector< std::unique_ptr< ProcessLib::ProcessData > > const &per_process_data, std::vector< GlobalVector * > const &process_solutions, std::vector< GlobalVector * > const &process_solutions_prev, std::vector< ProcessLib::Output > const &outputs)
Definition TimeLoop.cpp:48

References _end_time, _outputs, _per_process_data, _process_solutions, _process_solutions_prev, _staggered_coupling, NumLib::NonlinearSolverStatus::error_norms_met, ProcessLib::postTimestepForAllProcesses(), ProcessLib::preTimestepForAllProcesses(), solveCoupledEquationSystemsByStaggeredScheme(), and solveUncoupledEquationSystems().

Referenced by executeTimeStep().

◆ solveCoupledEquationSystemsByStaggeredScheme()

NumLib::NonlinearSolverStatus ProcessLib::TimeLoop::solveCoupledEquationSystemsByStaggeredScheme ( const NumLib::Time & t,
const double dt,
const std::size_t timestep_id )
private

Member to solver coupled systems of equations by the staggered scheme.

Parameters
tCurrent time
dtTime step size
timestep_idIndex of the time step
Returns
true: if all nonlinear solvers convergence. false: if any of nonlinear solvers divergences.

Definition at line 702 of file TimeLoop.cpp.

704{
705 auto const nonlinear_solver_status =
706 _staggered_coupling->execute<ProcessData, Output>(
707 t(), dt, timestep_id, _process_solutions, _process_solutions_prev,
709
711 _staggered_coupling->lastNumberOfCouplingIterations();
712
713 _previous_step_rejected = nonlinear_solver_status.error_norms_met;
714
715 for (auto const& process_data : _per_process_data)
716 {
717 auto& pcs = process_data->process;
718 int const process_id = process_data->process_id;
719 auto& ode_sys = *process_data->tdisc_ode_sys;
720 pcs.solveReactionEquation(_process_solutions, _process_solutions_prev,
721 t(), dt, ode_sys, process_id);
722 }
723
724 return nonlinear_solver_status;
725}
NumLib::NonlinearSolverStatus solveOneTimeStepOneProcess(std::vector< GlobalVector * > &x, std::vector< GlobalVector * > const &x_prev, std::size_t const timestep, double const t, double const delta_t, ProcessData const &process_data, std::vector< Output > const &outputs)
Definition TimeLoop.cpp:218

References _global_coupling_number_iterations, _outputs, _per_process_data, _previous_step_rejected, _process_solutions, _process_solutions_prev, _staggered_coupling, and ProcessLib::solveOneTimeStepOneProcess().

Referenced by preTsNonlinearSolvePostTs().

◆ solveUncoupledEquationSystems()

NumLib::NonlinearSolverStatus ProcessLib::TimeLoop::solveUncoupledEquationSystems ( const NumLib::Time & t,
const double dt,
const std::size_t timestep_id )
private

Member to solver non coupled systems of equations, which can be a single system of equations, or several systems of equations without any dependency among the different systems.

Parameters
tCurrent time
dtTime step size
timestep_idIndex of the time step
Returns
true: if all nonlinear solvers convergence. false: if any of nonlinear solvers divergences.

Definition at line 659 of file TimeLoop.cpp.

661{
662 NumLib::NonlinearSolverStatus nonlinear_solver_status;
663
664 for (auto const& process_data : _per_process_data)
665 {
666 auto const process_id = process_data->process_id;
667 nonlinear_solver_status = solveMonolithicProcess(
668 t, dt, timestep_id, *process_data, _process_solutions,
670
671 process_data->nonlinear_solver_status = nonlinear_solver_status;
672 if (!nonlinear_solver_status.error_norms_met)
673 {
674 ERR("The nonlinear solver failed in time step #{:d} at t = {} s "
675 "for process #{:d}.",
676 timestep_id, t, process_id);
677
678 if (!process_data->timestep_algorithm->canReduceTimestepSize(
679 process_data->timestep_current,
680 process_data->timestep_previous))
681 {
682 // save unsuccessful solution
683 for (auto const& output : _outputs)
684 {
685 output.doOutputAlways(
686 process_data->process, process_id, timestep_id, t,
687 process_data->nonlinear_solver_status.number_iterations,
688 process_data->nonlinear_solver_status.error_norms_met,
690 }
692 }
693
694 return nonlinear_solver_status;
695 }
696 }
697
698 return nonlinear_solver_status;
699}
static constexpr std::string_view timestepper_cannot_reduce_dt
Definition TimeLoop.cpp:656
static NumLib::NonlinearSolverStatus solveMonolithicProcess(const NumLib::Time &t, const double dt, const std::size_t timestep_id, ProcessData const &process_data, std::vector< GlobalVector * > &x, std::vector< GlobalVector * > const &x_prev, std::vector< Output > const &outputs)
Definition TimeLoop.cpp:636

References _outputs, _per_process_data, _process_solutions, _process_solutions_prev, ERR(), NumLib::NonlinearSolverStatus::error_norms_met, OGS_FATAL, ProcessLib::solveMonolithicProcess(), and ProcessLib::timestepper_cannot_reduce_dt.

Referenced by preTsNonlinearSolvePostTs().

Member Data Documentation

◆ _accepted_steps

std::size_t ProcessLib::TimeLoop::_accepted_steps = 0
private

Definition at line 131 of file TimeLoop.h.

Referenced by calculateNextTimeStep(), executeTimeStep(), initialize(), and outputLastTimeStep().

◆ _current_time

NumLib::Time ProcessLib::TimeLoop::_current_time = _start_time
private

◆ _dt

NumLib::TimeIncrement ProcessLib::TimeLoop::_dt {0.}
private

Definition at line 133 of file TimeLoop.h.

133{0.};

Referenced by calculateNextTimeStep(), executeTimeStep(), and initialize().

◆ _end_time

const NumLib::Time ProcessLib::TimeLoop::_end_time
private

◆ _global_coupling_number_iterations

int ProcessLib::TimeLoop::_global_coupling_number_iterations = 0
private

Number of global coupling iterations of the previous time step in the staggered scheme. It drives the time step size control of all processes.

Definition at line 139 of file TimeLoop.h.

Referenced by computeTimeStepping(), and solveCoupledEquationSystemsByStaggeredScheme().

◆ _outputs

◆ _per_process_data

◆ _previous_step_rejected

bool ProcessLib::TimeLoop::_previous_step_rejected = false
private

◆ _process_solutions

◆ _process_solutions_prev

◆ _rejected_steps

std::size_t ProcessLib::TimeLoop::_rejected_steps = 0
private

Definition at line 132 of file TimeLoop.h.

Referenced by calculateNextTimeStep(), initialize(), and outputLastTimeStep().

◆ _repeating_times_of_rejected_step

int ProcessLib::TimeLoop::_repeating_times_of_rejected_step = 0
private

Definition at line 134 of file TimeLoop.h.

Referenced by computeTimeStepping().

◆ _staggered_coupling

std::unique_ptr<NumLib::StaggeredCoupling> ProcessLib::TimeLoop::_staggered_coupling
private

◆ _start_time

const NumLib::Time ProcessLib::TimeLoop::_start_time
private

Definition at line 128 of file TimeLoop.h.

Referenced by TimeLoop(), initialize(), and preOutputInitialConditions().

◆ successful_time_step

bool ProcessLib::TimeLoop::successful_time_step = true

Definition at line 58 of file TimeLoop.h.

Referenced by executeTimeStep(), and outputLastTimeStep().


The documentation for this class was generated from the following files: