OGS
ProcessLib::TimeLoop Class Reference

Detailed Description

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

Definition at line 39 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 _last_step_rejected = false
 
std::unique_ptr< NumLib::StaggeredCoupling_staggered_coupling
 

Member Typedef Documentation

◆ TimeStepConstraintCallback

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

Definition at line 98 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 271 of file TimeLoop.cpp.

276 : _outputs{std::move(outputs)},
277 _per_process_data(std::move(per_process_data)),
278 _start_time(start_time),
279 _end_time(end_time),
280 _staggered_coupling(std::move(staggered_coupling))
281{
282}
std::vector< std::unique_ptr< ProcessData > > _per_process_data
Definition TimeLoop.h:133
std::vector< Output > _outputs
Definition TimeLoop.h:132
std::unique_ptr< NumLib::StaggeredCoupling > _staggered_coupling
Definition TimeLoop.h:144
const NumLib::Time _end_time
Definition TimeLoop.h:136
const NumLib::Time _start_time
Definition TimeLoop.h:135

◆ ~TimeLoop()

ProcessLib::TimeLoop::~TimeLoop ( )

Definition at line 741 of file TimeLoop.cpp.

742{
743 for (auto* x : _process_solutions)
744 {
746 }
747 for (auto* x : _process_solutions_prev)
748 {
750 }
751}
virtual void releaseVector(GlobalVector const &x)=0
std::vector< GlobalVector * > _process_solutions
Definition TimeLoop.h:130
std::vector< GlobalVector * > _process_solutions_prev
Definition TimeLoop.h:131
static NUMLIB_EXPORT VectorProvider & provider

References _process_solutions, _process_solutions_prev, NumLib::GlobalVectorProvider::provider, and NumLib::VectorProvider::releaseVector().

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 531 of file TimeLoop.cpp.

532{
533 const double prev_dt = _dt();
534 // keep a copy of _current_time to check if a new point in time is computed
535 auto const current_time = _current_time;
536
537 const std::size_t timesteps = _accepted_steps + 1;
538
539 auto const time_step_constraints = generateOutputTimeStepConstraints(
541
542 // _last_step_rejected is also checked in computeTimeStepping.
543 std::tie(_dt, _last_step_rejected) =
545 _rejected_steps, time_step_constraints);
546
548 {
549 outputSolutions(timesteps, current_time(), &Output::doOutput);
550 }
551
552 // check if the newly computed time point (=_current_time + _dt()) differs
553 // from the previously computed time point (current_time) saved at the
554 // beginning of the method
555 if (current_time == (_current_time + _dt()))
556 {
557 DBUG("current time == previous time + dt : {:a} == {:a} + {:a} = {:a}",
558 current_time(), _current_time(), _dt(), _current_time() + _dt());
559 ERR("The time increment {} results in exactly the same time {} as the "
560 "last rejected time step.\n"
561 "Time stepping stops at time step {:d} and time {}.",
562 _dt, current_time, timesteps, _current_time);
563 return false;
564 }
565
567 {
568 return false;
569 }
570
571 return true;
572}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
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
Definition Output.cpp:338
NumLib::TimeIncrement _dt
Definition TimeLoop.h:140
NumLib::Time _current_time
Definition TimeLoop.h:137
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:297
void outputSolutions(unsigned timestep, const double t, OutputClassMember output_class_member) const
Definition TimeLoop.cpp:715
std::size_t _accepted_steps
Definition TimeLoop.h:138
std::size_t _rejected_steps
Definition TimeLoop.h:139
std::vector< TimeStepConstraintCallback > generateOutputTimeStepConstraints(std::vector< double > &&fixed_times) const
Definition TimeLoop.cpp:443
std::vector< double > calculateUniqueFixedTimesForAllOutputs(std::vector< Output > const &outputs)
Definition Output.cpp:441

References _accepted_steps, _current_time, _dt, _end_time, _last_step_rejected, _outputs, _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 last time step was rejected

Definition at line 297 of file TimeLoop.cpp.

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

References _end_time, _per_process_data, _process_solutions, _process_solutions_prev, _repeating_times_of_rejected_step, 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 64 of file TimeLoop.h.

64{ return _current_time; }

References _current_time.

◆ endTime()

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

Definition at line 63 of file TimeLoop.h.

63{ return _end_time; }

References _end_time.

◆ executeTimeStep()

bool ProcessLib::TimeLoop::executeTimeStep ( )

Definition at line 510 of file TimeLoop.cpp.

511{
512 BaseLib::RunTime time_timestep;
513 time_timestep.start();
514
515 _current_time += _dt();
516
517 const std::size_t timesteps = _accepted_steps + 1;
518 // TODO(wenqing): , input option for time unit.
519 INFO("Time step #{:d} started. Time: {}. Step size: {}.", timesteps,
521
523
526 INFO("[time] Time step #{:d} took {:g} s.", timesteps,
527 time_timestep.elapsed());
529}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Count the running time.
Definition RunTime.h:29
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:42
void start()
Start the timer.
Definition RunTime.h:32
bool preTsNonlinearSolvePostTs(NumLib::Time const &t, double const dt, std::size_t const timesteps)
Definition TimeLoop.cpp:589
void updateDeactivatedSubdomains(std::vector< std::unique_ptr< ProcessLib::ProcessData > > const &per_process_data, double const t)
Definition TimeLoop.cpp:28

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 443 of file TimeLoop.cpp.

445{
446 std::vector<TimeStepConstraintCallback> const time_step_constraints{
447 [fixed_times = std::move(fixed_times)](NumLib::Time const& t, double dt)
448 { return NumLib::possiblyClampDtToNextFixedTime(t, dt, fixed_times); },
449 [this](NumLib::Time const& t, double dt) -> double
450 {
451 if (t < _end_time && _end_time < t + dt)
452 {
453 return _end_time() - t();
454 }
455 return dt;
456 }};
457 return time_step_constraints;
458}
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 461 of file TimeLoop.cpp.

462{
463 for (auto const& process_data : _per_process_data)
464 {
465 auto& pcs = process_data->process;
466 for (auto& output : _outputs)
467 {
468 output.addProcess(pcs);
469 }
470
471 setTimeDiscretizedODESystem(*process_data);
472
473 if (auto* conv_crit =
475 process_data->conv_crit.get()))
476 {
477 int const process_id = process_data->process_id;
478 conv_crit->setDOFTable(pcs.getDOFTable(process_id), pcs.getMesh());
479 }
480 }
481
482 // initial solution storage
485
487 {
488 _staggered_coupling->initializeCoupledSolutions(_process_solutions);
489 }
490
492
493 auto const time_step_constraints = generateOutputTimeStepConstraints(
495
496 std::tie(_dt, _last_step_rejected) =
498 _rejected_steps, time_step_constraints);
499
500 // Output initial conditions
501 {
504 }
505
508}
void preOutputInitialConditions(NumLib::Time const &t, const double dt) const
Definition TimeLoop.cpp:753
void setTimeDiscretizedODESystem(ProcessData &process_data, NumLib::ODESystem< ODETag, NumLib::NonlinearSolverTag::Picard > &ode_sys)
Definition TimeLoop.cpp:114
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:208
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:173

References _accepted_steps, _current_time, _dt, _last_step_rejected, _outputs, _per_process_data, _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 574 of file TimeLoop.cpp.

575{
576 INFO(
577 "The whole computation of the time stepping took {:d} steps, in which\n"
578 "\t the accepted steps are {:d}, and the rejected steps are {:d}.\n",
580
581 // output last time step
583 {
586 }
587}
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
Definition Output.cpp:359

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 715 of file TimeLoop.cpp.

717{
718 for (auto const& process_data : _per_process_data)
719 {
720 // If nonlinear solver diverged, the solution has already been
721 // saved.
722 if (!process_data->nonlinear_solver_status.error_norms_met)
723 {
724 continue;
725 }
726
727 auto const process_id = process_data->process_id;
728 auto const& pcs = process_data->process;
729
730 for (auto const& output_object : _outputs)
731 {
732 (output_object.*output_class_member)(
733 pcs, process_id, timestep, NumLib::Time(t),
734 process_data->nonlinear_solver_status.number_iterations,
735 process_data->nonlinear_solver_status.error_norms_met,
737 }
738 }
739}

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 753 of file TimeLoop.cpp.

755{
756 for (auto const& process_data : _per_process_data)
757 {
758 // If nonlinear solver diverged, the solution has already been
759 // saved.
760 if (!process_data->nonlinear_solver_status.error_norms_met)
761 {
762 continue;
763 }
764
765 auto const process_id = process_data->process_id;
766 auto& pcs = process_data->process;
767
768 process_data->time_disc->nextTimestep(t(), dt);
769
770 pcs.preTimestep(_process_solutions, _start_time(), dt, process_id);
771
772 pcs.preOutput(_start_time(), dt, _process_solutions,
773 _process_solutions_prev, process_id);
774
775 // Update secondary variables, which might be uninitialized, before
776 // output.
777 pcs.computeSecondaryVariable(_start_time(), dt, _process_solutions,
778 *_process_solutions_prev[process_id],
779 process_id);
780 }
781}

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 589 of file TimeLoop.cpp.

591{
593
594 NumLib::NonlinearSolverStatus nonlinear_solver_status;
595
597 {
598 nonlinear_solver_status =
600 }
601 else
602 {
603 nonlinear_solver_status =
604 solveUncoupledEquationSystems(t, dt, timesteps);
605 }
606
607 // Run post time step only if the last iteration was successful.
608 // Otherwise it runs the risks to get the same errors as in the last
609 // iteration, an exception thrown in assembly, for example.
610 if (nonlinear_solver_status.error_norms_met)
611 {
612 // Later on, the timestep_algorithm might reject the timestep. We assume
613 // that this is a rare case, so still, we call preOutput() here. We
614 // don't expect a large overhead from it.
617 _outputs);
618
622 }
623 return nonlinear_solver_status.error_norms_met;
624}
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:649
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:692
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:81
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:94
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:54
Status of the non-linear solver.

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 692 of file TimeLoop.cpp.

694{
695 auto const nonlinear_solver_status =
696 _staggered_coupling->execute<ProcessData, Output>(
697 t(), dt, timestep_id, _process_solutions, _process_solutions_prev,
699
700 _last_step_rejected = nonlinear_solver_status.error_norms_met;
701
702 for (auto const& process_data : _per_process_data)
703 {
704 auto& pcs = process_data->process;
705 int const process_id = process_data->process_id;
706 auto& ode_sys = *process_data->tdisc_ode_sys;
707 pcs.solveReactionEquation(_process_solutions, _process_solutions_prev,
708 t(), dt, ode_sys, process_id);
709 }
710
711 return nonlinear_solver_status;
712}
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:224

References _last_step_rejected, _outputs, _per_process_data, _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 649 of file TimeLoop.cpp.

651{
652 NumLib::NonlinearSolverStatus nonlinear_solver_status;
653
654 for (auto const& process_data : _per_process_data)
655 {
656 auto const process_id = process_data->process_id;
657 nonlinear_solver_status = solveMonolithicProcess(
658 t, dt, timestep_id, *process_data, _process_solutions,
660
661 process_data->nonlinear_solver_status = nonlinear_solver_status;
662 if (!nonlinear_solver_status.error_norms_met)
663 {
664 ERR("The nonlinear solver failed in time step #{:d} at t = {} s "
665 "for process #{:d}.",
666 timestep_id, t, process_id);
667
668 if (!process_data->timestep_algorithm->canReduceTimestepSize(
669 process_data->timestep_current,
670 process_data->timestep_previous))
671 {
672 // save unsuccessful solution
673 for (auto const& output : _outputs)
674 {
675 output.doOutputAlways(
676 process_data->process, process_id, timestep_id, t,
677 process_data->nonlinear_solver_status.number_iterations,
678 process_data->nonlinear_solver_status.error_norms_met,
680 }
682 }
683
684 return nonlinear_solver_status;
685 }
686 }
687
688 return nonlinear_solver_status;
689}
static constexpr std::string_view timestepper_cannot_reduce_dt
Definition TimeLoop.cpp:646
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:626

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 138 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 140 of file TimeLoop.h.

140{0.};

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

◆ _end_time

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

◆ _last_step_rejected

bool ProcessLib::TimeLoop::_last_step_rejected = false
private

◆ _outputs

◆ _per_process_data

◆ _process_solutions

◆ _process_solutions_prev

◆ _rejected_steps

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

Definition at line 139 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 141 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 135 of file TimeLoop.h.

Referenced by initialize(), and preOutputInitialConditions().

◆ successful_time_step

bool ProcessLib::TimeLoop::successful_time_step = true

Definition at line 65 of file TimeLoop.h.

Referenced by executeTimeStep(), and outputLastTimeStep().


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