All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OdeSolver.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_MATH_ODESOLVER_H
17 #define SURGSIM_MATH_ODESOLVER_H
18 
19 #include <functional>
20 #include <unordered_map>
21 
22 #include <boost/assign/list_of.hpp> // for 'map_list_of()'
23 
25 #include "SurgSim/Math/Matrix.h"
27 
28 namespace SurgSim
29 {
30 
31 namespace Math
32 {
33 
47 };
48 
49 const std::unordered_map<IntegrationScheme, std::string, std::hash<int>> IntegrationSchemeNames =
50  boost::assign::map_list_of
51  (INTEGRATIONSCHEME_STATIC, "INTEGRATIONSCHEME_STATIC")
52  (INTEGRATIONSCHEME_LINEAR_STATIC, "INTEGRATIONSCHEME_LINEAR_STATIC")
53  (INTEGRATIONSCHEME_EXPLICIT_EULER, "INTEGRATIONSCHEME_EXPLICIT_EULER")
54  (INTEGRATIONSCHEME_LINEAR_EXPLICIT_EULER, "INTEGRATIONSCHEME_LINEAR_EXPLICIT_EULER")
55  (INTEGRATIONSCHEME_MODIFIED_EXPLICIT_EULER, "INTEGRATIONSCHEME_MODIFIED_EXPLICIT_EULER")
56  (INTEGRATIONSCHEME_LINEAR_MODIFIED_EXPLICIT_EULER, "INTEGRATIONSCHEME_LINEAR_MODIFIED_EXPLICIT_EULER")
57  (INTEGRATIONSCHEME_IMPLICIT_EULER, "INTEGRATIONSCHEME_IMPLICIT_EULER")
58  (INTEGRATIONSCHEME_LINEAR_IMPLICIT_EULER, "INTEGRATIONSCHEME_LINEAR_IMPLICIT_EULER")
59  (INTEGRATIONSCHEME_RUNGE_KUTTA_4, "INTEGRATIONSCHEME_RUNGE_KUTTA_4")
60  (INTEGRATIONSCHEME_LINEAR_RUNGE_KUTTA_4, "INTEGRATIONSCHEME_LINEAR_RUNGE_KUTTA_4");
61 
73 class OdeSolver
74 {
75 public:
78  explicit OdeSolver(OdeEquation* equation);
79 
81  virtual ~OdeSolver()
82  {}
83 
86  const std::string getName() const;
87 
90  void setLinearSolver(std::shared_ptr<LinearSolveAndInverse> linearSolver);
91 
94  std::shared_ptr<LinearSolveAndInverse> getLinearSolver() const;
95 
100  virtual void solve(double dt, const OdeState& currentState, OdeState* newState) = 0;
101 
104  const Matrix& getSystemMatrix() const;
105 
108  const Matrix& getCompliance() const;
109 
110 protected:
113  void allocate(size_t size);
114 
117  std::string m_name;
118 
121 
123  std::shared_ptr<LinearSolveAndInverse> m_linearSolver;
124 
130 
133 };
134 
135 }; // namespace Math
136 
137 }; // namespace SurgSim
138 
139 #endif // SURGSIM_MATH_ODESOLVER_H
std::string m_name
Name for this solver.
Definition: OdeSolver.h:117
const std::unordered_map< IntegrationScheme, std::string, std::hash< int > > IntegrationSchemeNames
Definition: OdeSolver.h:49
void setLinearSolver(std::shared_ptr< LinearSolveAndInverse > linearSolver)
Sets the specialized linear solver to use with this Ode solver.
Definition: OdeSolver.cpp:38
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
const Matrix & getSystemMatrix() const
Queries the current system matrix.
Definition: OdeSolver.cpp:48
Matrix m_compliance
Compliance matrix which is the inverse of the system matrix.
Definition: OdeSolver.h:132
Ode equation of 2nd order of the form M(x,v).a = F(x, v) with (x0, v0) for initial conditions and a s...
Definition: OdeEquation.h:40
OdeState defines the state y of an ode of 2nd order of the form M(x,v).a = F(x, v) with boundary cond...
Definition: OdeState.h:34
void allocate(size_t size)
Allocates the system and compliance matrices.
Definition: OdeSolver.cpp:58
IntegrationScheme
The diverse numerical integration scheme supported Each Ode Solver should have its own entry in this ...
Definition: OdeSolver.h:36
OdeSolver(OdeEquation *equation)
Constructor.
Definition: OdeSolver.cpp:25
virtual ~OdeSolver()
Virtual destructor.
Definition: OdeSolver.h:81
Definitions of small fixed-size square matrix types.
virtual void solve(double dt, const OdeState &currentState, OdeState *newState)=0
Solves the equation.
const std::string getName() const
Gets the solver's name.
Definition: OdeSolver.cpp:33
OdeEquation & m_equation
The ode equation (API providing the necessary evaluation methods and the initial state) ...
Definition: OdeSolver.h:120
Base class for all solvers of ode equation of order 2 of the form M(x(t), v(t)).a(t) = f(t...
Definition: OdeSolver.h:73
std::shared_ptr< LinearSolveAndInverse > m_linearSolver
The specialized linear solver to use when solving the ode equation.
Definition: OdeSolver.h:123
Matrix m_systemMatrix
System matrix (can be M, K, combination of MDK depending on the solver) A static solver will have K f...
Definition: OdeSolver.h:129
std::shared_ptr< LinearSolveAndInverse > getLinearSolver() const
Gets the specialized linear solver used with this Ode solver.
Definition: OdeSolver.cpp:43
const Matrix & getCompliance() const
Queries the current compliance matrix.
Definition: OdeSolver.cpp:53
Definition: OdeSolver.h:37