opensurgsim
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SurgSim::Math::OdeSolver Class Referenceabstract

Base class for all solvers of ode equation of order 2 of the form \(M(x(t), v(t)).a(t) = f(t, x(t), v(t))\). More...

#include <OdeSolver.h>

Inheritance diagram for SurgSim::Math::OdeSolver:
SurgSim::Math::MockOdeSolver SurgSim::Math::OdeSolverEulerExplicit SurgSim::Math::OdeSolverEulerExplicitModified SurgSim::Math::OdeSolverEulerImplicit SurgSim::Math::OdeSolverRungeKutta4 SurgSim::Math::OdeSolverStatic SurgSim::Math::OdeSolverLinearEulerExplicit SurgSim::Math::OdeSolverLinearEulerExplicitModified SurgSim::Math::OdeSolverLinearEulerImplicit SurgSim::Math::OdeSolverLinearRungeKutta4 SurgSim::Math::OdeSolverLinearStatic

Public Member Functions

 OdeSolver (OdeEquation *equation)
 Constructor. More...
 
virtual ~OdeSolver ()
 Virtual destructor.
 
const std::string getName () const
 Gets the solver's name. More...
 
void setLinearSolver (std::shared_ptr< LinearSparseSolveAndInverse > linearSolver)
 Sets the specialized linear solver to use with this Ode solver. More...
 
std::shared_ptr< LinearSparseSolveAndInversegetLinearSolver () const
 Gets the specialized linear solver used with this Ode solver. More...
 
virtual void solve (double dt, const OdeState &currentState, OdeState *newState, bool computeCompliance=true)=0
 Solves the equation. More...
 
void computeMatrices (double dt, const OdeState &state, bool computeCompliance=true)
 Computes the system and compliance matrices for a given state. More...
 
const SparseMatrixgetSystemMatrix () const
 Queries the current system matrix. More...
 
const MatrixgetComplianceMatrix () const
 

Protected Member Functions

virtual void assembleLinearSystem (double dt, const OdeState &state, const OdeState &newState, bool computeRHS=true)=0
 Assemble the linear system (A.x=b) to be solved for the state and new states (useful for certain ode solver). More...
 
void computeComplianceMatrixFromSystemMatrix (const OdeState &state)
 Helper method computing the compliance matrix from the system matrix and setting the boundary conditions. More...
 

Protected Attributes

std::string m_name
 Name for this solver. More...
 
OdeEquationm_equation
 The ode equation (API providing the necessary evaluation methods and the initial state)
 
std::shared_ptr< LinearSparseSolveAndInversem_linearSolver
 The specialized linear solver to use when solving the ode equation.
 
SparseMatrix m_systemMatrix
 Linear system matrix (can be M, K, combination of MDK depending on the solver), including boundary conditions. More...
 
Vector m_solution
 Linear system solution and rhs vectors (including boundary conditions)
 
Vector m_rhs
 
Matrix m_complianceMatrix
 Compliance matrix which is the inverse of the system matrix, including boundary conditions.
 

Detailed Description

Base class for all solvers of ode equation of order 2 of the form \(M(x(t), v(t)).a(t) = f(t, x(t), v(t))\).


This ode equation is solved as an ode of order 1 by defining the state vector \(y = \left(\begin{array}{c}x\\v\end{array}\right)\):

\[ y' = \left(\begin{array}{c} x' \\ v' \end{array}\right) = \left(\begin{array}{c} v \\ M(x, v)^{-1}.f(t, x, v) \end{array}\right) \]

Note
To allow the use of explicit and implicit solver, we need to be able to evaluate:
\(M(x(t), v(t))\)
\(f(t, x(t), v(t))\) but also
\(K = -\frac{\partial f}{\partial x}(x(t), v(t))\)
\(D = -\frac{\partial f}{\partial v}(x(t), v(t))\)
Models wanting the use of implicit solvers will need to compute these Jacobian matrices.
Matrices all have dense storage, but a specialized linear solver can be set per solver.

Constructor & Destructor Documentation

§ OdeSolver()

SurgSim::Math::OdeSolver::OdeSolver ( OdeEquation equation)
explicit

Constructor.

Parameters
equationThe ode equation to be solved

Member Function Documentation

§ assembleLinearSystem()

virtual void SurgSim::Math::OdeSolver::assembleLinearSystem ( double  dt,
const OdeState state,
const OdeState newState,
bool  computeRHS = true 
)
protectedpure virtual

Assemble the linear system (A.x=b) to be solved for the state and new states (useful for certain ode solver).

Parameters
dtThe time step used in the system
state,newStateThe state and newState to be used to evaluate the system
computeRHSTrue to compute the RHS vector, False otherwise
Note
The method should fill up the LHS matrix in m_systemMatrix and the RHS vector in m_b (if requested)
The method should take care of the boundary conditions properly on both the matrix and the vector.
The method should prepare the linear solver m_linearSolver to be used with the m_systemMatrix

Implemented in SurgSim::Math::OdeSolverEulerExplicit, SurgSim::Math::OdeSolverRungeKutta4, SurgSim::Math::OdeSolverEulerExplicitModified, SurgSim::Math::MockOdeSolver, SurgSim::Math::OdeSolverEulerImplicit, and SurgSim::Math::OdeSolverStatic.

§ computeComplianceMatrixFromSystemMatrix()

void SurgSim::Math::OdeSolver::computeComplianceMatrixFromSystemMatrix ( const OdeState state)
protected

Helper method computing the compliance matrix from the system matrix and setting the boundary conditions.

Parameters
stateThe state describing the boundary conditions
Note
The full system is not re-evaluated from the state, the current m_systemMatrix is directly used.
This method supposes that the linear solver has been updated with the current m_systemMatrix.

§ computeMatrices()

void SurgSim::Math::OdeSolver::computeMatrices ( double  dt,
const OdeState state,
bool  computeCompliance = true 
)

Computes the system and compliance matrices for a given state.

Parameters
dtThe time step
stateThe state to compute the system and compliance matrices for
computeComplianceTrue to explicitly compute the compliance matrix, False otherwise

Compute the system matrix (and discard the RHS calculation)

Compute the compliance matrix

§ getComplianceMatrix()

const Matrix & SurgSim::Math::OdeSolver::getComplianceMatrix ( ) const
Returns
The latest compliance matrix computed (either by calling solve or computeMatrices)

§ getLinearSolver()

std::shared_ptr< LinearSparseSolveAndInverse > SurgSim::Math::OdeSolver::getLinearSolver ( ) const

Gets the specialized linear solver used with this Ode solver.

Returns
The linear solver used when solving the ode equation

§ getName()

const std::string SurgSim::Math::OdeSolver::getName ( ) const

Gets the solver's name.

Returns
The solver name

§ getSystemMatrix()

const SparseMatrix & SurgSim::Math::OdeSolver::getSystemMatrix ( ) const

Queries the current system matrix.

Returns
The latest system matrix calculated

§ setLinearSolver()

void SurgSim::Math::OdeSolver::setLinearSolver ( std::shared_ptr< LinearSparseSolveAndInverse linearSolver)

Sets the specialized linear solver to use with this Ode solver.

Parameters
linearSolverthe linear solver to use when solving the ode equation

§ solve()

virtual void SurgSim::Math::OdeSolver::solve ( double  dt,
const OdeState currentState,
OdeState newState,
bool  computeCompliance = true 
)
pure virtual

Member Data Documentation

§ m_name

std::string SurgSim::Math::OdeSolver::m_name
protected

Name for this solver.

Note
MUST be set by the derived classes

§ m_systemMatrix

SparseMatrix SurgSim::Math::OdeSolver::m_systemMatrix
protected

Linear system matrix (can be M, K, combination of MDK depending on the solver), including boundary conditions.

Note
A static solver will have K for system matrix
A dynamic explicit solver will have M for system matrix
A dynamic implicit solver will have a combination of M, D and K for system matrix

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