OGS
ProcessLib::TimeLoop Class Reference

Detailed Description

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

Definition at line 37 of file TimeLoop.h.

#include <TimeLoop.h>

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 double start_time, const double end_time)
 
void initialize ()
 initialize output, convergence criterion, etc.
 
void outputLastTimeStep () const
 
 ~TimeLoop ()
 
bool executeTimeStep ()
 
bool calculateNextTimeStep ()
 
double endTime () const
 
double currentTime () const
 

Public Attributes

bool successful_time_step = false
 

Private Member Functions

bool preTsNonlinearSolvePostTs (double const t, double const dt, std::size_t const timesteps)
 
NumLib::NonlinearSolverStatus solveUncoupledEquationSystems (const double 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 double t, const double dt, const std::size_t timestep_id)
 Member to solver coupled systems of equations by the staggered scheme.
 
std::pair< double, bool > computeTimeStepping (const double prev_dt, double &t, std::size_t &accepted_steps, std::size_t &rejected_steps, std::vector< std::function< double(double, double)> > const &time_step_constraints)
 
template<typename OutputClassMember >
void outputSolutions (unsigned timestep, const double t, OutputClassMember output_class_member) const
 
std::vector< std::function< double(double, double)> > generateOutputTimeStepConstraints (std::vector< double > &&fixed_times) const
 
void preOutputInitialConditions (const double t) 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 double _start_time
 
const double _end_time
 
double _current_time = _start_time
 
std::size_t _accepted_steps = 0
 
std::size_t _rejected_steps = 0
 
double _dt = 0
 
int _repeating_times_of_rejected_step = 0
 
bool _last_step_rejected = false
 
std::unique_ptr< NumLib::StaggeredCoupling_staggered_coupling
 

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 double start_time,
const double end_time )

Definition at line 266 of file TimeLoop.cpp.

271 : _outputs{std::move(outputs)},
272 _per_process_data(std::move(per_process_data)),
273 _start_time(start_time),
274 _end_time(end_time),
275 _staggered_coupling(std::move(staggered_coupling))
276{
277}
const double _start_time
Definition TimeLoop.h:131
std::vector< std::unique_ptr< ProcessData > > _per_process_data
Definition TimeLoop.h:129
const double _end_time
Definition TimeLoop.h:132
std::vector< Output > _outputs
Definition TimeLoop.h:128
std::unique_ptr< NumLib::StaggeredCoupling > _staggered_coupling
Definition TimeLoop.h:140

◆ ~TimeLoop()

ProcessLib::TimeLoop::~TimeLoop ( )

Definition at line 743 of file TimeLoop.cpp.

744{
745 for (auto* x : _process_solutions)
746 {
748 }
749 for (auto* x : _process_solutions_prev)
750 {
752 }
753}
virtual void releaseVector(GlobalVector const &x)=0
std::vector< GlobalVector * > _process_solutions
Definition TimeLoop.h:126
std::vector< GlobalVector * > _process_solutions_prev
Definition TimeLoop.h:127
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 538 of file TimeLoop.cpp.

539{
540 const double prev_dt = _dt;
541 double const current_time = _current_time;
542
543 const std::size_t timesteps = _accepted_steps + 1;
544
545 auto const time_step_constraints = generateOutputTimeStepConstraints(
547
548 // _last_step_rejected is also checked in computeTimeStepping.
549 std::tie(_dt, _last_step_rejected) =
551 _rejected_steps, time_step_constraints);
552
554 {
555 outputSolutions(timesteps, current_time, &Output::doOutput);
556 }
557
558 if (std::abs(_current_time - _end_time) <
559 std::numeric_limits<double>::epsilon() ||
561 {
562 return false;
563 }
564
565 if (_dt < std::numeric_limits<double>::epsilon())
566 {
567 WARN(
568 "Time step size of {:g} is too small.\n"
569 "Time stepping stops at step {:d} and at time of {:g}.",
570 _dt, timesteps, _current_time);
571 return false;
572 }
573
574 return true;
575}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
void doOutput(Process const &process, const int process_id, int const timestep, const double t, int const iteration, std::vector< GlobalVector * > const &xs) const
Definition Output.cpp:335
std::vector< std::function< double(double, double)> > generateOutputTimeStepConstraints(std::vector< double > &&fixed_times) const
Definition TimeLoop.cpp:445
std::pair< double, bool > computeTimeStepping(const double prev_dt, double &t, std::size_t &accepted_steps, std::size_t &rejected_steps, std::vector< std::function< double(double, double)> > const &time_step_constraints)
Definition TimeLoop.cpp:291
void outputSolutions(unsigned timestep, const double t, OutputClassMember output_class_member) const
Definition TimeLoop.cpp:718
std::size_t _accepted_steps
Definition TimeLoop.h:134
std::size_t _rejected_steps
Definition TimeLoop.h:135
std::vector< double > calculateUniqueFixedTimesForAllOutputs(std::vector< Output > const &outputs)
Definition Output.cpp:432

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

◆ computeTimeStepping()

std::pair< double, bool > ProcessLib::TimeLoop::computeTimeStepping ( const double prev_dt,
double & t,
std::size_t & accepted_steps,
std::size_t & rejected_steps,
std::vector< std::function< double(double, double)> > 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 291 of file TimeLoop.cpp.

296{
297 bool all_process_steps_accepted = true;
298 // Get minimum time step size among step sizes of all processes.
299 double dt = std::numeric_limits<double>::max();
300 constexpr double eps = std::numeric_limits<double>::epsilon();
301
302 bool const is_initial_step =
303 std::any_of(_per_process_data.begin(), _per_process_data.end(),
304 [](auto const& ppd) -> bool
305 { return ppd->timestep_current.timeStepNumber() == 0; });
306
307 for (std::size_t i = 0; i < _per_process_data.size(); i++)
308 {
309 auto& ppd = *_per_process_data[i];
310 auto& timestep_algorithm = *ppd.timestep_algorithm.get();
311
312 auto const& x = *_process_solutions[i];
313 auto const& x_prev = *_process_solutions_prev[i];
314
315 const double solution_error =
316 computationOfChangeNeeded(timestep_algorithm, t)
318 x, x_prev,
319 ppd.conv_crit.get() ? ppd.conv_crit->getVectorNormType()
321 : 0.0;
322
323 ppd.timestep_current.setAccepted(
324 ppd.nonlinear_solver_status.error_norms_met);
325
326 auto [previous_step_accepted, timestepper_dt] = timestep_algorithm.next(
327 solution_error, ppd.nonlinear_solver_status.number_iterations,
328 ppd.timestep_previous, ppd.timestep_current);
329
330 if (!previous_step_accepted &&
331 // In case of FixedTimeStepping, which makes
332 // timestep_algorithm.next(...) return false when the ending time
333 // is reached.
334 t + eps < timestep_algorithm.end())
335 {
336 // Not all processes have accepted steps.
337 all_process_steps_accepted = false;
338 }
339
340 if (!ppd.nonlinear_solver_status.error_norms_met)
341 {
342 WARN(
343 "Time step will be rejected due to nonlinear solver "
344 "divergence.");
345 all_process_steps_accepted = false;
346 }
347
348 if (timestepper_dt > eps ||
349 std::abs(t - timestep_algorithm.end()) < eps)
350 {
351 dt = 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 || std::abs(t - _end_time) < eps)
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_constain : time_step_constraints)
385 {
386 dt = std::min(dt, time_step_constain(t, dt));
387 }
388
389 // Check whether the time stepping is stabilized
390 if (std::abs(dt - prev_dt) < eps)
391 {
392 if (last_step_rejected)
393 {
394 OGS_FATAL(
395 "The new step size of {:g} is the same as that of the previous "
396 "rejected time step. \nPlease re-run ogs with a proper "
397 "adjustment in the numerical settings, \ne.g those for time "
398 "stepper, local or global non-linear solver.",
399 dt);
400 }
401 else
402 {
403 DBUG("The time stepping is stabilized with the step size of {:g}.",
404 dt);
405 }
406 }
407
408 // Reset the time step with the minimum step size, dt
409 // Update the solution of the previous time step.
410 for (std::size_t i = 0; i < _per_process_data.size(); i++)
411 {
412 if (all_process_steps_accepted)
413 {
414 auto& ppd = *_per_process_data[i];
415 NumLib::updateTimeSteps(dt, ppd.timestep_previous,
416 ppd.timestep_current);
417 auto& timestep_algorithm = ppd.timestep_algorithm;
418 timestep_algorithm->resetCurrentTimeStep(dt, ppd.timestep_previous,
419 ppd.timestep_current);
420 }
421
422 auto& x = *_process_solutions[i];
423 auto& x_prev = *_process_solutions_prev[i];
424 if (all_process_steps_accepted)
425 {
426 MathLib::LinAlg::copy(x, x_prev); // pushState
427 }
428 else
429 {
430 if (t < _end_time || std::abs(t - _end_time) < eps)
431 {
432 WARN(
433 "Time step {:d} was rejected {:d} times and it will be "
434 "repeated with a reduced step size.",
435 accepted_steps + 1, _repeating_times_of_rejected_step);
436 MathLib::LinAlg::copy(x_prev, x); // popState
437 }
438 }
439 }
440
441 return {dt, last_step_rejected};
442}
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
int _repeating_times_of_rejected_step
Definition TimeLoop.h:137
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:286
VecNormType
Norm type. Not declared as class type in order to use the members as integers.
Definition LinAlgEnums.h:22
void updateTimeSteps(double const dt, TimeStep &previous_timestep, TimeStep &current_timestep)
Definition TimeStep.h:112
bool computationOfChangeNeeded(NumLib::TimeStepAlgorithm const &timestep_algorithm, double const time)
Definition TimeLoop.cpp:279

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()

double ProcessLib::TimeLoop::currentTime ( ) const
inline

Definition at line 62 of file TimeLoop.h.

62{ return _current_time; }

References _current_time.

◆ endTime()

double ProcessLib::TimeLoop::endTime ( ) const
inline

Definition at line 61 of file TimeLoop.h.

61{ return _end_time; }

References _end_time.

◆ executeTimeStep()

bool ProcessLib::TimeLoop::executeTimeStep ( )

Definition at line 515 of file TimeLoop.cpp.

516{
517 BaseLib::RunTime time_timestep;
518 time_timestep.start();
519
521
522 const std::size_t timesteps = _accepted_steps + 1;
523 // TODO(wenqing): , input option for time unit.
524 INFO(
525 "=== Time stepping at step #{:d} and time {:.15g} with step size "
526 "{:.15g}",
527 timesteps, _current_time, _dt);
528
530
533 INFO("[time] Time step #{:d} took {:g} s.", timesteps,
534 time_timestep.elapsed());
536}
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(double const t, double const dt, std::size_t const timesteps)
Definition TimeLoop.cpp:592
void updateDeactivatedSubdomains(std::vector< std::unique_ptr< ProcessLib::ProcessData > > const &per_process_data, double const t)
Definition TimeLoop.cpp:27

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

◆ generateOutputTimeStepConstraints()

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

Definition at line 445 of file TimeLoop.cpp.

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

467{
468 for (auto const& process_data : _per_process_data)
469 {
470 auto& pcs = process_data->process;
471 for (auto& output : _outputs)
472 {
473 output.addProcess(pcs);
474 }
475
476 setTimeDiscretizedODESystem(*process_data);
477
478 if (auto* conv_crit =
480 process_data->conv_crit.get()))
481 {
482 int const process_id = process_data->process_id;
483 conv_crit->setDOFTable(pcs.getDOFTable(process_id), pcs.getMesh());
484 }
485 }
486
487 // initial solution storage
490
492 {
493 _staggered_coupling->initializeCoupledSolutions(_process_solutions);
494 }
495
497
498 // Output initial conditions
499 {
502 }
503
504 auto const time_step_constraints = generateOutputTimeStepConstraints(
506
507 std::tie(_dt, _last_step_rejected) =
509 _rejected_steps, time_step_constraints);
510
513}
void preOutputInitialConditions(const double t) const
Definition TimeLoop.cpp:755
void setTimeDiscretizedODESystem(ProcessData &process_data, NumLib::ODESystem< ODETag, NumLib::NonlinearSolverTag::Picard > &ode_sys)
Definition TimeLoop.cpp:111
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:205
std::pair< std::vector< GlobalVector * >, std::vector< GlobalVector * > > setInitialConditions(double const t0, std::vector< std::unique_ptr< ProcessData > > const &per_process_data)
Definition TimeLoop.cpp:170

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

578{
579 INFO(
580 "The whole computation of the time stepping took {:d} steps, in which\n"
581 "\t the accepted steps are {:d}, and the rejected steps are {:d}.\n",
583
584 // output last time step
586 {
589 }
590}
void doOutputLastTimestep(Process const &process, const int process_id, int const timestep, const double t, int const iteration, std::vector< GlobalVector * > const &xs) const
Definition Output.cpp:354

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

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

References _outputs, _per_process_data, and _process_solutions.

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

◆ preOutputInitialConditions()

void ProcessLib::TimeLoop::preOutputInitialConditions ( const double t) const
private

Definition at line 755 of file TimeLoop.cpp.

756{
757 for (auto const& process_data : _per_process_data)
758 {
759 // If nonlinear solver diverged, the solution has already been
760 // saved.
761 if (!process_data->nonlinear_solver_status.error_norms_met)
762 {
763 continue;
764 }
765
766 auto const process_id = process_data->process_id;
767 auto& pcs = process_data->process;
768
769 // dummy value to handle the time derivative terms more or less
770 // correctly, i.e. to ignore them.
771 double const dt = 1;
772 process_data->time_disc->nextTimestep(t, dt);
773
774 pcs.preTimestep(_process_solutions, _start_time, dt, process_id);
775
776 pcs.preOutput(_start_time, dt, _process_solutions,
777 _process_solutions_prev, process_id);
778
779 // Update secondary variables, which might be uninitialized, before
780 // output.
781 pcs.computeSecondaryVariable(_start_time, dt, _process_solutions,
782 *_process_solutions_prev[process_id],
783 process_id);
784 }
785}

References _per_process_data, _process_solutions, _process_solutions_prev, and _start_time.

Referenced by initialize().

◆ preTsNonlinearSolvePostTs()

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

Definition at line 592 of file TimeLoop.cpp.

594{
596
597 NumLib::NonlinearSolverStatus nonlinear_solver_status;
598
600 {
601 nonlinear_solver_status =
603 }
604 else
605 {
606 nonlinear_solver_status =
607 solveUncoupledEquationSystems(t, dt, timesteps);
608 }
609
610 // Run post time step only if the last iteration was successful.
611 // Otherwise it runs the risks to get the same errors as in the last
612 // iteration, an exception thrown in assembly, for example.
613 if (nonlinear_solver_status.error_norms_met)
614 {
615 // Later on, the timestep_algorithm might reject the timestep. We assume
616 // that this is a rare case, so still, we call preOutput() here. We
617 // don't expect a large overhead from it.
620 _outputs);
621
625 }
626 return nonlinear_solver_status.error_norms_met;
627}
NumLib::NonlinearSolverStatus solveUncoupledEquationSystems(const double 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:650
NumLib::NonlinearSolverStatus solveCoupledEquationSystemsByStaggeredScheme(const double 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(double const t, double const dt, std::vector< std::unique_ptr< ProcessData > > const &per_process_data, std::vector< GlobalVector * > const &_process_solutions)
Definition TimeLoop.cpp:78
void postTimestepForAllProcesses(double 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:91
void preOutputForAllProcesses(int const timestep, double const t, double const dt, const double 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:52
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 double 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 {
703 for (auto const& process_data : _per_process_data)
704 {
705 auto& pcs = process_data->process;
706 int const process_id = process_data->process_id;
707 auto& ode_sys = *process_data->tdisc_ode_sys;
708 pcs.solveReactionEquation(_process_solutions,
709 _process_solutions_prev, t, dt, ode_sys,
710 process_id);
711 }
712 }
713
714 return nonlinear_solver_status;
715}
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:221

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

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

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

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

◆ _current_time

double ProcessLib::TimeLoop::_current_time = _start_time
private

◆ _dt

double ProcessLib::TimeLoop::_dt = 0
private

Definition at line 136 of file TimeLoop.h.

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

◆ _end_time

const double 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 135 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 137 of file TimeLoop.h.

Referenced by computeTimeStepping().

◆ _staggered_coupling

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

◆ _start_time

const double ProcessLib::TimeLoop::_start_time
private

Definition at line 131 of file TimeLoop.h.

Referenced by initialize(), and preOutputInitialConditions().

◆ successful_time_step

bool ProcessLib::TimeLoop::successful_time_step = false

Definition at line 63 of file TimeLoop.h.

Referenced by executeTimeStep(), and outputLastTimeStep().


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