SpECTRE  v2024.06.18
Convergence::HasConverged Struct Reference

Signals convergence or termination of the algorithm. More...

#include <HasConverged.hpp>

Public Member Functions

 HasConverged (const Criteria &criteria, size_t iteration_id, double residual_magnitude, double initial_residual_magnitude)
 Determine whether the criteria are met by means of Convergence::criteria_match.
 HasConverged (size_t num_iterations, size_t iteration_id)
 Construct at a state where iteration_id iterations of a total of num_iterations have completed. Use when the algorithm is intended to run for a fixed number of iterations. The convergence reason() will be Convergence::Reason::NumIterations.
 HasConverged (Reason reason, std::optional< std::string > error_message, size_t iteration_id)
 Construct a state manually. More...
 operator bool () const
Reason reason () const
 The reason the algorithm has converged. More...
const std::stringerror_message () const
 Error message if reason is Reason::Error More...
size_t num_iterations () const
 The number of iterations the algorithm has completed.
double residual_magnitude () const
 The residual magnitude after the last iteration. NaN if no iteration has completed yet.
double initial_residual_magnitude () const
 The residual magnitude before the first iteration. NaN if this information is not available yet.
void check_for_error () const
 Throw an exception if the reason() is Reason::Error.
void pup (PUP::er &p)


bool operator== (const HasConverged &lhs, const HasConverged &rhs)
bool operator!= (const HasConverged &lhs, const HasConverged &rhs)
std::ostreamoperator<< (std::ostream &os, const HasConverged &has_converged)

Detailed Description

Signals convergence or termination of the algorithm.


Evaluates to true if the algorithm has converged or terminated and no further iterations should be performed. In this case, the reason() member function provides more information. If false, calling reason() is an error.

The stream operator provides a human-readable description of the convergence status.

This type default-constructs to a state that signals the algorithm has not yet converged.

Constructor & Destructor Documentation

◆ HasConverged()

Convergence::HasConverged::HasConverged ( Reason  reason,
std::optional< std::string error_message,
size_t  iteration_id 

Construct a state manually.

Currently only allows to construct a state with Reason::Error. Use the other constructors for the other Reasons.

Member Function Documentation

◆ error_message()

const std::string & Convergence::HasConverged::error_message ( ) const

Error message if reason is Reason::Error

You may only call this function if the reason() is Reason::Error.

◆ reason()

Reason Convergence::HasConverged::reason ( ) const

The reason the algorithm has converged.

Calling this function is an error if the algorithm has not yet converged.

The documentation for this struct was generated from the following file: