Solvers#
Newton solver#
- class skhippr.solvers.newton.NewtonSolver(tolerance: float = 1e-08, max_iterations: int = 20, verbose: bool = False)#
Implements Newton’s method for solving nonlinear equations and equation systems given by
EquationSystemorAbstractEquationobjects.Attributes:#
- num_iterint
Number of iterations performed.
- convergedbool or None
Indicates whether the solution procedure has converged.
- max_iterationsint
Maximum number of allowed iterations.
- verbosebool
If True, prints progress information.
- tolerancefloat
Convergence tolerance for the residual norm.
- reset() None#
Reset the state of the solver.
- solve_equation(equation: AbstractEquation, unknown: str) EquationSystem#
Solve a single equation with a single unknown. The method creates an
EquationSystemfrom the given equation and unknown, solves it usingsolve(), and checks for convergence.While the solved
EquationSystemis returned, theequationitself is also updated, storing the resulting system is optional.
- solve(equation_system: EquationSystem) None#
Applies Newton’s method to solve the system of nonlinear equations given by a
EquationSystem.Performs iterative correction steps starting from the current vector of unknowns until the residual norm is sufficiently small or the maximum number of iterations is reached. In every step the unknown attributes of
equation_systemare updated. After convergence, performs a stability check if applicable.Prints progress and convergence information if
verboseisTrue.
Pseudo-arclength continuation#
The :py:module:`skhippr.solvers.continuation` module offers the functionality to perform pseudo-arclength continuation on equation systems encoded by EquationSystem objects.
It provides the generator function pseudo_arclength_continuator() for continuation. This generator returns in each iteration a BranchPoint object, which is a subclass of EquationSystem and includes all equations of the initial system, along with an additional ContinuationAnchor equation that ensures all updates are orthogonal to the tangent.
- skhippr.solvers.continuation.pseudo_arclength_continuator(initial_system: EquationSystem, solver: NewtonSolver, stepsize: float = None, stepsize_range: Iterable[float] = (0.0001, 0.1), initial_direction=1, continuation_parameter=None, verbose=False, num_steps: int = 1000) Iterator[BranchPoint]#
Perform pseudo-arclength continuation of the solution branch emerging from a nonlinear
EquationSystem.This generator yields a sequence of
BranchPointobjects, each representing an individual solution of the problem, by following the solution branch using the pseudo-arclength continuation method.- Parameters:
initial_problem (
EquationSystem) –The initial
EquationSystemto start continuation from. It need not be solved already. All branch points will duplicte the equations of this system,Explicit case: If the
EquationSystemiswell_posed, an explicitcontinuation_parameter, which must be an attribute of at least one equation, is required.Implicit case: Otherwise, the problem must have exactly one equation more than unknowns.
stepsize (float, optional) – Initial step size for continuation. If None, uses the lower bound of
stepsize_range.stepsize_range (Iterable of float, optional) – Tuple specifying the minimum and maximum allowed step sizes. Default is (1e-4, 1e-1).
initial_direction (int, optional) – Direction (+1 or -1) to start continuation along the branch. If positive, the continuation parameter (explicit case) or the last entry of the unknowns (implicit case) increases initially.
key_param (str, optional) – Name of the parameter to track during continuation.
value_param (Any, optional) – Value of the parameter at the initial point. Defaults to
initial_problem.<key_param>.verbose (bool, optional) – If
True, prints progress and diagnostic information. Default isFalse.num_steps (int, optional) – Maximum number of continuation steps to perform. Default is 1000.
- Yields:
BranchPoint– The next converged solution point along the continuation branch.- Raises:
RuntimeError – If the initial problem does not converge.
Notes
If the minimal stepsize does not converge, the continuation stops.
The continuator does not check whether the branch point lies within any value bounds. Such checks should be made within the
forloop over which the continuator is iterated.
- class skhippr.solvers.continuation.BranchPoint(underlying_system: EquationSystem, continuation_parameter: str = None, initial_direction=1)#
A
BranchPointrepresents a point on an implicit or explicit continuation branch.An object of this class contains all equations of the underlying
EquationSystem, and additionally oneContinuationAnchoras the last equation. If a continuation parameter is passed, the unknowns are extended by this continuation parameter.- determine_tangent()#
Compute, normalize and store the tangent vector at the branch point.
This method checks if the
BranchPointequation system is solved. If not, it raises aRuntimeError. It then constructs the tangent vector by solving a linear system. with the same Jacobian matrix as for the Newton updates. The resulting normalized tangent vector forms an acute angle with the previous tangent vector. It is stored in theself.tangentattribute.- Raises:
RuntimeError – If the solution has not converged and the tangent would thus be meaningless.
- predict(stepsize: float) BranchPoint#
Predict the next branch point in the continuation process.
- Parameters:
stepsize (float) – The step size to advance along the tangent direction.
- Returns:
A new
BranchPointinstance (not converged) representing the predicted next point along the continuation path. all equations are shallow-copied to prevent that updates in the next point affect the current point.- Return type:
- class skhippr.solvers.continuation.ContinuationAnchor(equation_system, continuation_parameter=None, previous_tangent=None, initial_direction=1)#
A scalar
AbstractEquationsubclass that ensures orthogonality to the tangent direction in the continuation process. While the residual function is always zero, the closed-form derivative is the tangent vector at the previous branch point, ensuring that all Newton updates of the branch point are orthogonal to the tangent.During instantiation, either a previous tangent vector or an initial direction must be provided.
- residual_function()#
Always returns zero.
- closed_form_derivative(variable)#
Returns the segment of the tangent vector at the previous branch point corresponding to the unknown
variable.