OdeSolver.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_MATH_ODESOLVER_H
#define SURGSIM_MATH_ODESOLVER_H
#include <functional>
#include <unordered_map>
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
#include "SurgSim/Math/LinearSparseSolveAndInverse.h"
#include "SurgSim/Math/Matrix.h"
#include "SurgSim/Math/OdeEquation.h"
namespace SurgSim
{
namespace Math
{
enum IntegrationScheme
{
INTEGRATIONSCHEME_STATIC = 0,
INTEGRATIONSCHEME_LINEAR_STATIC,
INTEGRATIONSCHEME_EULER_EXPLICIT,
INTEGRATIONSCHEME_LINEAR_EULER_EXPLICIT,
INTEGRATIONSCHEME_EULER_EXPLICIT_MODIFIED,
INTEGRATIONSCHEME_LINEAR_EULER_EXPLICIT_MODIFIED,
INTEGRATIONSCHEME_EULER_IMPLICIT,
INTEGRATIONSCHEME_LINEAR_EULER_IMPLICIT,
INTEGRATIONSCHEME_RUNGE_KUTTA_4,
INTEGRATIONSCHEME_LINEAR_RUNGE_KUTTA_4,
MAX_INTEGRATIONSCHEMES
};
const std::unordered_map<IntegrationScheme, std::string, std::hash<int>> IntegrationSchemeNames =
boost::assign::map_list_of
(INTEGRATIONSCHEME_STATIC, "INTEGRATIONSCHEME_STATIC")
(INTEGRATIONSCHEME_LINEAR_STATIC, "INTEGRATIONSCHEME_LINEAR_STATIC")
(INTEGRATIONSCHEME_EULER_EXPLICIT, "INTEGRATIONSCHEME_EULER_EXPLICIT")
(INTEGRATIONSCHEME_LINEAR_EULER_EXPLICIT, "INTEGRATIONSCHEME_LINEAR_EULER_EXPLICIT")
(INTEGRATIONSCHEME_EULER_EXPLICIT_MODIFIED, "INTEGRATIONSCHEME_EULER_EXPLICIT_MODIFIED")
(INTEGRATIONSCHEME_LINEAR_EULER_EXPLICIT_MODIFIED, "INTEGRATIONSCHEME_LINEAR_EULER_EXPLICIT_MODIFIED")
(INTEGRATIONSCHEME_EULER_IMPLICIT, "INTEGRATIONSCHEME_EULER_IMPLICIT")
(INTEGRATIONSCHEME_LINEAR_EULER_IMPLICIT, "INTEGRATIONSCHEME_LINEAR_EULER_IMPLICIT")
(INTEGRATIONSCHEME_RUNGE_KUTTA_4, "INTEGRATIONSCHEME_RUNGE_KUTTA_4")
(INTEGRATIONSCHEME_LINEAR_RUNGE_KUTTA_4, "INTEGRATIONSCHEME_LINEAR_RUNGE_KUTTA_4");
class OdeSolver
{
public:
explicit OdeSolver(OdeEquation* equation);
virtual ~OdeSolver()
{}
const std::string getName() const;
void setLinearSolver(std::shared_ptr<LinearSparseSolveAndInverse> linearSolver);
std::shared_ptr<LinearSparseSolveAndInverse> getLinearSolver() const;
virtual void solve(double dt, const OdeState& currentState, OdeState* newState, bool computeCompliance = true) = 0;
void computeMatrices(double dt, const OdeState& state, bool computeCompliance = true);
const SparseMatrix& getSystemMatrix() const;
const Matrix& getComplianceMatrix() const;
protected:
virtual void assembleLinearSystem(double dt, const OdeState& state, const OdeState& newState,
bool computeRHS = true) = 0;
void computeComplianceMatrixFromSystemMatrix(const OdeState& state);
std::string m_name;
OdeEquation& m_equation;
std::shared_ptr<LinearSparseSolveAndInverse> m_linearSolver;
SparseMatrix m_systemMatrix;
Vector m_solution, m_rhs;
Matrix m_complianceMatrix;
};
}; // namespace Math
}; // namespace SurgSim
#endif // SURGSIM_MATH_ODESOLVER_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Math::OdeSolver::m_name
std::string m_name
Name for this solver.
Definition: OdeSolver.h:140
SurgSim::Math::IntegrationSchemeNames
const std::unordered_map< IntegrationScheme, std::string, std::hash< int > > IntegrationSchemeNames
Definition: OdeSolver.h:51
SurgSim::Math::INTEGRATIONSCHEME_LINEAR_RUNGE_KUTTA_4
Definition: OdeSolver.h:47
SurgSim::Math::OdeSolver::solve
virtual void solve(double dt, const OdeState &currentState, OdeState *newState, bool computeCompliance=true)=0
Solves the equation.
SurgSim::Math::OdeSolver::computeComplianceMatrixFromSystemMatrix
void computeComplianceMatrixFromSystemMatrix(const OdeState &state)
Helper method computing the compliance matrix from the system matrix and setting the boundary conditi...
Definition: OdeSolver.cpp:69
SurgSim::Math::Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
SurgSim::Math::INTEGRATIONSCHEME_EULER_EXPLICIT
Definition: OdeSolver.h:40
SurgSim::Math::MAX_INTEGRATIONSCHEMES
Definition: OdeSolver.h:48
SurgSim::Math::INTEGRATIONSCHEME_EULER_EXPLICIT_MODIFIED
Definition: OdeSolver.h:42
SurgSim::Math::OdeEquation
Ode equation of 2nd order of the form with for initial conditions and a set of boundary conditions...
Definition: OdeEquation.h:54
SurgSim::Math::OdeState
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
SurgSim::Math::OdeSolver::m_solution
Vector m_solution
Linear system solution and rhs vectors (including boundary conditions)
Definition: OdeSolver.h:155
SurgSim::Math::INTEGRATIONSCHEME_RUNGE_KUTTA_4
Definition: OdeSolver.h:46
SurgSim::Math::OdeSolver::assembleLinearSystem
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 ...
SurgSim::Math::OdeSolver::getName
const std::string getName() const
Gets the solver&#39;s name.
Definition: OdeSolver.cpp:31
SurgSim::Math::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
SurgSim::Math::SparseMatrix
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
SurgSim::Math::IntegrationScheme
IntegrationScheme
The diverse numerical integration scheme supported Each Ode Solver should have its own entry in this ...
Definition: OdeSolver.h:36
SurgSim::Math::INTEGRATIONSCHEME_LINEAR_EULER_EXPLICIT
Definition: OdeSolver.h:41
SurgSim::Math::OdeSolver::OdeSolver
OdeSolver(OdeEquation *equation)
Constructor.
Definition: OdeSolver.cpp:25
SurgSim::Math::OdeSolver::~OdeSolver
virtual ~OdeSolver()
Virtual destructor.
Definition: OdeSolver.h:86
SurgSim::Math::OdeSolver::m_rhs
Vector m_rhs
Definition: OdeSolver.h:155
Matrix.h
Definitions of small fixed-size square matrix types.
SurgSim::Math::INTEGRATIONSCHEME_EULER_IMPLICIT
Definition: OdeSolver.h:44
SurgSim::Math::OdeSolver::m_equation
OdeEquation & m_equation
The ode equation (API providing the necessary evaluation methods and the initial state) ...
Definition: OdeSolver.h:143
SurgSim::Math::OdeSolver::getComplianceMatrix
const Matrix & getComplianceMatrix() const
Definition: OdeSolver.cpp:51
SurgSim::Math::OdeSolver
Base class for all solvers of ode equation of order 2 of the form .
Definition: OdeSolver.h:78
SurgSim::Math::OdeSolver::getSystemMatrix
const SparseMatrix & getSystemMatrix() const
Queries the current system matrix.
Definition: OdeSolver.cpp:46
SurgSim::Math::INTEGRATIONSCHEME_LINEAR_EULER_IMPLICIT
Definition: OdeSolver.h:45
SurgSim::Math::INTEGRATIONSCHEME_LINEAR_STATIC
Definition: OdeSolver.h:39
SurgSim::Math::OdeSolver::m_systemMatrix
SparseMatrix m_systemMatrix
Linear system matrix (can be M, K, combination of MDK depending on the solver), including boundary co...
Definition: OdeSolver.h:152
SurgSim::Math::INTEGRATIONSCHEME_LINEAR_EULER_EXPLICIT_MODIFIED
Definition: OdeSolver.h:43
LinearSparseSolveAndInverse.h
SurgSim::Math::OdeSolver::m_complianceMatrix
Matrix m_complianceMatrix
Compliance matrix which is the inverse of the system matrix, including boundary conditions.
Definition: OdeSolver.h:158
SurgSim::Math::OdeSolver::getLinearSolver
std::shared_ptr< LinearSparseSolveAndInverse > getLinearSolver() const
Gets the specialized linear solver used with this Ode solver.
Definition: OdeSolver.cpp:41
SurgSim::Math::OdeSolver::computeMatrices
void computeMatrices(double dt, const OdeState &state, bool computeCompliance=true)
Computes the system and compliance matrices for a given state.
Definition: OdeSolver.cpp:57
SurgSim::Math::OdeSolver::m_linearSolver
std::shared_ptr< LinearSparseSolveAndInverse > m_linearSolver
The specialized linear solver to use when solving the ode equation.
Definition: OdeSolver.h:146
SurgSim::Math::OdeSolver::setLinearSolver
void setLinearSolver(std::shared_ptr< LinearSparseSolveAndInverse > linearSolver)
Sets the specialized linear solver to use with this Ode solver.
Definition: OdeSolver.cpp:36
OdeEquation.h
SurgSim::Math::INTEGRATIONSCHEME_STATIC
Definition: OdeSolver.h:38