Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
VectorRootSolver< InputT, OutputT > Class Template Reference

A vector-valued root solver using Newton's method. More...

#include <VectorRootSolver.h>

Inheritance diagram for VectorRootSolver< InputT, OutputT >:
[legend]
Collaboration diagram for VectorRootSolver< InputT, OutputT >:
[legend]

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.
 

Detailed Description

template<typename InputT, typename OutputT>
class VectorRootSolver< InputT, OutputT >

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:

  • It does not advance the simulation internally.
  • External code calls stepFrame() repeatedly after the simulation has advanced.

Definition at line 21 of file VectorRootSolver.h.

Member Typedef Documentation

◆ InitialGuessSetter

template<typename InputT , typename OutputT >
using VectorRootSolver< InputT, OutputT >::InitialGuessSetter = std::function<void(const InputT&)>

Definition at line 23 of file VectorRootSolver.h.

◆ ResultExtractor

template<typename InputT , typename OutputT >
using VectorRootSolver< InputT, OutputT >::ResultExtractor = std::function<OutputT()>

Definition at line 25 of file VectorRootSolver.h.

◆ StopCondition

template<typename InputT , typename OutputT >
using VectorRootSolver< InputT, OutputT >::StopCondition = std::function<bool()>

Definition at line 24 of file VectorRootSolver.h.

Constructor & Destructor Documentation

◆ VectorRootSolver()

template<typename InputT , typename OutputT >
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.

Parameters
initialGuessSetterFunction to apply a new guess for the unknown input
stopConditionFunction to check if the simulation has reached the evaluation point
extractResultFunction to extract the output vector at the current guess
targetThe target output vector the solver tries to reach
toleranceConvergence tolerance for the error ||F(x) - target||
maxIterationsMaximum number of Newton iterations before giving up
jacobianStepStep size for finite-difference Jacobian approximation
dampingDamping factor (alpha) for Newton step

Definition at line 10 of file VectorRootSolver.cpp.

Member Function Documentation

◆ stepFrame()

template<typename InputT , typename OutputT >
bool VectorRootSolver< InputT, OutputT >::stepFrame ( )
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.

Note
The actual simulation should be run externally. This function only updates the solver state and the next guess based on the most recent output.
Returns
true if the error norm ||F(x_n)|| is less than the solver's tolerance, indicating convergence to a root; false otherwise.

Implements ISolver.

Definition at line 18 of file VectorRootSolver.cpp.


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