|
Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
|
A vector-valued root solver using Newton's method. More...
#include <VectorRootSolver.h>
Public Types | |
| using | InitialGuessSetter = std::function< void(const InputT &)> |
| using | StopCondition = std::function< bool()> |
| using | ResultExtractor = std::function< OutputT()> |
Public Member Functions | |
| VectorRootSolver (InitialGuessSetter initialGuessSetter, StopCondition stopCondition, ResultExtractor extractResult, const OutputT &target, double tolerance=1e-3, int maxIterations=30, double jacobianStep=0.01, double damping=1.0) | |
| Construct a new VectorRootSolver object. | |
| bool | stepFrame () override |
| Performs one iteration of the vector root-finding solver. | |
Public Member Functions inherited from ISolver | |
| virtual | ~ISolver ()=default |
| Virtual destructor for proper cleanup of derived classes. | |
A vector-valued root solver using Newton's method.
This class attempts to find the input vector current such that the output of a function (extracted via ResultExtractor) matches a given target vector. It works in n-dimensional space (TODO: currently specialized for 3D vectors), using finite-difference approximations for the Jacobian.
The solver is designed to work asynchronously with a simulation loop:
stepFrame() repeatedly after the simulation has advanced. Definition at line 21 of file VectorRootSolver.h.
| using VectorRootSolver< InputT, OutputT >::InitialGuessSetter = std::function<void(const InputT&)> |
Definition at line 23 of file VectorRootSolver.h.
| using VectorRootSolver< InputT, OutputT >::ResultExtractor = std::function<OutputT()> |
Definition at line 25 of file VectorRootSolver.h.
| using VectorRootSolver< InputT, OutputT >::StopCondition = std::function<bool()> |
Definition at line 24 of file VectorRootSolver.h.
| VectorRootSolver< InputT, OutputT >::VectorRootSolver | ( | InitialGuessSetter | initialGuessSetter, |
| StopCondition | stopCondition, | ||
| ResultExtractor | extractResult, | ||
| const OutputT & | target, | ||
| double | tolerance = 1e-3, |
||
| int | maxIterations = 30, |
||
| double | jacobianStep = 0.01, |
||
| double | damping = 1.0 |
||
| ) |
Construct a new VectorRootSolver object.
| initialGuessSetter | Function to apply a new guess for the unknown input |
| stopCondition | Function to check if the simulation has reached the evaluation point |
| extractResult | Function to extract the output vector at the current guess |
| target | The target output vector the solver tries to reach |
| tolerance | Convergence tolerance for the error ||F(x) - target|| |
| maxIterations | Maximum number of Newton iterations before giving up |
| jacobianStep | Step size for finite-difference Jacobian approximation |
| damping | Damping factor (alpha) for Newton step |
Definition at line 10 of file VectorRootSolver.cpp.
|
overridevirtual |
Performs one iteration of the vector root-finding solver.
This function attempts to improve the current guess for the unknown input by performing one step of Newton's method in N dimensions. It uses the current output (from extract()) and the target value to compute the error vector, approximates the Jacobian, and computes the next guess for the input using:
x_{n+1} = x_n - J(x_n)^{-1} * F(x_n)
where x_n is the current guess and F(x_n) = extract() - target.
The guess is applied via the setGuess() function.
Implements ISolver.
Definition at line 18 of file VectorRootSolver.cpp.