22 #include "smith/numerics/nonlinear_convergence.hpp"
34 class BoundaryConditionManager;
35 class FiniteElementState;
36 class FiniteElementDual;
38 struct NonlinearSolverOptions;
39 struct LinearSolverOptions;
51 using MatrixPtr = std::unique_ptr<mfem::HypreParMatrix>;
59 virtual std::vector<FieldPtr>
solve(
60 const std::vector<FieldPtr>& u_guesses,
61 std::function<std::vector<mfem::Vector>(
const std::vector<FieldPtr>&)> residuals,
62 std::function<std::vector<std::vector<MatrixPtr>>(
const std::vector<FieldPtr>&)> jacobians)
const = 0;
68 virtual std::vector<FieldPtr>
solveAdjoint(
const std::vector<DualPtr>& u_bars,
69 std::vector<std::vector<MatrixPtr>>& jacobian_transposed)
const = 0;
86 bool checkConvergence(
double tolerance_multiplier,
const std::vector<mfem::Vector>& residuals)
const
115 NonlinearBlockSolver(std::unique_ptr<EquationSolver> s, MPI_Comm comm,
double abs_tol = 1e-12,
double rel_tol = 1e-8,
116 std::optional<NonlinearSolverOptions> retained_nonlinear_options = std::nullopt,
117 std::optional<LinearSolverOptions> retained_linear_options = std::nullopt);
128 std::vector<FieldPtr>
solve(
129 const std::vector<FieldPtr>& u_guesses,
130 std::function<std::vector<mfem::Vector>(
const std::vector<FieldPtr>&)> residuals,
131 std::function<std::vector<std::vector<MatrixPtr>>(
const std::vector<FieldPtr>&)> jacobians)
const override;
134 std::vector<FieldPtr>
solveAdjoint(
const std::vector<DualPtr>& u_bars,
135 std::vector<std::vector<MatrixPtr>>& jacobian_transposed)
const override;
144 std::shared_ptr<NonlinearBlockSolver>
cloneFresh()
const;
146 mutable std::unique_ptr<mfem::BlockOperator>
148 mutable std::vector<std::vector<MatrixPtr>>
152 mutable std::unique_ptr<EquationSolver>
Class for encapsulating the dual vector space of a finite element space (i.e. the space of linear for...
Class for encapsulating the critical MFEM components of a primal finite element field.
Helper class for constructing a mesh consistent with Smith.
Abstract interface for nonlinear block solvers that provide both forward and adjoint solves.
bool checkConvergence(double tolerance_multiplier, const std::vector< mfem::Vector > &residuals) const
Check whether the current residuals satisfy the convergence criterion.
virtual ~NonlinearBlockSolverBase()
destructor
bool is_setup_
Records if this block solver has its preconditioner initialized.
ConvergenceStatus convergenceStatus(double tolerance_multiplier, const std::vector< mfem::Vector > &residuals) const
Evaluate convergence for this solver's configured tolerance using solver-owned convergence state.
virtual void primeConvergenceContext(const std::vector< mfem::Vector > &residuals, NonlinearConvergenceContext &context) const =0
Initialize a convergence context from a residual snapshot without relying on a fake convergence test.
virtual std::vector< FieldPtr > solveAdjoint(const std::vector< DualPtr > &u_bars, std::vector< std::vector< MatrixPtr >> &jacobian_transposed) const =0
Solve the (linear) adjoint set of equations with a vector of FiniteElementState as unknown.
std::shared_ptr< FieldD > DualPtr
using
virtual ConvergenceStatus convergenceStatus(double tolerance_multiplier, const std::vector< mfem::Vector > &residuals, NonlinearConvergenceContext &context) const =0
Evaluate convergence with externally owned convergence state.
std::shared_ptr< FieldT > FieldPtr
using
std::unique_ptr< mfem::HypreParMatrix > MatrixPtr
using
virtual void resetConvergenceState() const
Reset internal convergence tracking state (e.g. the stored initial residual norm used for relative to...
NonlinearConvergenceContext convergence_context_
Solver-owned convergence state for one solve.
virtual void clearMemory() const
Interface option to clear memory between solves to avoid high-water mark memory usage.
virtual std::vector< FieldPtr > solve(const std::vector< FieldPtr > &u_guesses, std::function< std::vector< mfem::Vector >(const std::vector< FieldPtr > &)> residuals, std::function< std::vector< std::vector< MatrixPtr >>(const std::vector< FieldPtr > &)> jacobians) const =0
Solve a set of equations with a vector of FiniteElementState as unknown.
virtual void setInnerToleranceMultiplier(double multiplier)=0
Set an inner-solve tolerance multiplier, e.g. for staggered solves.
Nonlinear block solver backed by an EquationSolver forward solve and linear adjoint solves.
double abs_tol_
absolute residual tolerance for convergence check
ConvergenceStatus convergenceStatus(double tolerance_multiplier, const std::vector< mfem::Vector > &residuals) const
Evaluate convergence for this solver's configured tolerance using solver-owned convergence state.
std::vector< FieldPtr > solveAdjoint(const std::vector< DualPtr > &u_bars, std::vector< std::vector< MatrixPtr >> &jacobian_transposed) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::unique_ptr< EquationSolver > nonlinear_solver_
the nonlinear equation solver used for the forward pass
std::vector< FieldPtr > solve(const std::vector< FieldPtr > &u_guesses, std::function< std::vector< mfem::Vector >(const std::vector< FieldPtr > &)> residuals, std::function< std::vector< std::vector< MatrixPtr >>(const std::vector< FieldPtr > &)> jacobians) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::optional< LinearSolverOptions > retained_linear_options_
retained linear config
void primeConvergenceContext(const std::vector< mfem::Vector > &residuals, NonlinearConvergenceContext &context) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::unique_ptr< mfem::BlockOperator > block_jac_
Need to hold an instance of a block operator to work with the mfem solver interface.
MPI_Comm comm_
MPI communicator for parallel norm computation.
NonlinearBlockSolver(std::unique_ptr< EquationSolver > s, MPI_Comm comm, double abs_tol=1e-12, double rel_tol=1e-8, std::optional< NonlinearSolverOptions > retained_nonlinear_options=std::nullopt, std::optional< LinearSolverOptions > retained_linear_options=std::nullopt)
Construct from a nonlinear equation solver.
void setInnerToleranceMultiplier(double multiplier) override
Set the inner tolerance multiplier.
std::optional< NonlinearSolverOptions > retained_nonlinear_options_
retained nonlinear config
void completeSetup(const std::vector< FieldPtr > &us) const
Initialize the preconditioner in case of vector problems.
double inner_tol_multiplier_
multiplier for tolerances during inner solves
double rel_tol_
relative residual tolerance for convergence check
std::shared_ptr< NonlinearBlockSolver > cloneFresh() const
Build a fresh solver instance from retained config.
std::vector< std::vector< MatrixPtr > > matrix_of_jacs_
Accelerator functionality.
std::shared_ptr< NonlinearBlockSolver > buildNonlinearBlockSolver(NonlinearSolverOptions nonlinear_opts, LinearSolverOptions linear_opts, const smith::Mesh &mesh)
Create an equation-backed nonlinear block solver.
This file contains enumerations and record types for physics solver configuration.
Detailed status from evaluating nonlinear residual convergence.
bool converged
True when the scalar global residual criterion passes.
Parameters for an iterative linear solution scheme.
Stores initial residual norms used for relative nonlinear convergence checks.
void reset()
Clear all stored initial norms for a new solve. The next convergence evaluation seeds a fresh relativ...
Nonlinear solution scheme parameters.