OdeState.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2016, 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_ODESTATE_H
#define SURGSIM_MATH_ODESTATE_H
#include <memory>
#include "SurgSim/Math/Matrix.h"
#include "SurgSim/Math/SparseMatrix.h"
#include "SurgSim/Math/Vector.h"
namespace SurgSim
{
namespace Math
{
class OdeState
{
public:
OdeState();
virtual ~OdeState();
bool operator ==(const OdeState& state) const;
bool operator !=(const OdeState& state) const;
virtual void reset();
virtual void setNumDof(size_t numDofPerNode, size_t numNodes);
size_t getNumDof() const;
size_t getNumNodes() const;
SurgSim::Math::Vector& getPositions();
const SurgSim::Math::Vector& getPositions() const;
const SurgSim::Math::Vector3d getPosition(size_t nodeId) const;
SurgSim::Math::Vector& getVelocities();
const SurgSim::Math::Vector& getVelocities() const;
const SurgSim::Math::Vector3d getVelocity(size_t nodeId) const;
void addBoundaryCondition(size_t nodeId);
void addBoundaryCondition(size_t nodeId, size_t nodeDofId);
size_t getNumBoundaryConditions() const;
const std::vector<size_t>& getBoundaryConditions() const;
bool isBoundaryCondition(size_t dof) const;
Vector* applyBoundaryConditionsToVector(Vector* vector) const;
void applyBoundaryConditionsToMatrix(Matrix* matrix, bool hasCompliance = true) const;
void applyBoundaryConditionsToMatrix(SparseMatrix* matrix, bool hasCompliance = true) const;
virtual bool isValid() const;
OdeState interpolate(const OdeState& other, double t) const;
private:
size_t m_numDofPerNode, m_numNodes;
SurgSim::Math::Vector m_x;
SurgSim::Math::Vector m_v;
std::vector<size_t> m_boundaryConditionsAsDofIds;
Eigen::Matrix<bool, Eigen::Dynamic, 1> m_boundaryConditionsPerDof;
};
}; // namespace Math
}; // namespace SurgSim
#endif // SURGSIM_MATH_ODESTATE_H
SurgSim::Math::OdeState::m_numDofPerNode
size_t m_numDofPerNode
Default public copy constructor and assignment operator are being used on purpose.
Definition: OdeState.h:164
SurgSim::Math::OdeState::m_numNodes
size_t m_numNodes
Definition: OdeState.h:164
SurgSim::Math::OdeState::m_boundaryConditionsAsDofIds
std::vector< size_t > m_boundaryConditionsAsDofIds
Boundary conditions stored as a list of dof ids.
Definition: OdeState.h:173
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Math::OdeState::reset
virtual void reset()
Resets the state.
Definition: OdeState.cpp:45
SurgSim::Math::OdeState::applyBoundaryConditionsToMatrix
void applyBoundaryConditionsToMatrix(Matrix *matrix, bool hasCompliance=true) const
Apply boundary conditions to a given matrix.
Definition: OdeState.cpp:172
SurgSim::Math::OdeState::m_v
SurgSim::Math::Vector m_v
Degrees of freedom velocity (m_x 1st derivative w.r.t. time)
Definition: OdeState.h:170
SurgSim::Math::OdeState::getVelocities
SurgSim::Math::Vector & getVelocities()
Retrieves all degrees of freedom&#39;s velocity (non-const version)
Definition: OdeState.cpp:98
SurgSim::Math::OdeState::m_boundaryConditionsPerDof
Eigen::Matrix< bool, Eigen::Dynamic, 1 > m_boundaryConditionsPerDof
Boundary conditions stored per dof (True indicates a boundary condition, False does not) ...
Definition: OdeState.h:176
SurgSim::Math::OdeState::operator!=
bool operator!=(const OdeState &state) const
Comparison operator (difference test)
Definition: OdeState.cpp:40
SurgSim::Math::OdeState::getNumNodes
size_t getNumNodes() const
Retrieves the number of nodes.
Definition: OdeState.cpp:78
SurgSim::Math::OdeState::m_x
SurgSim::Math::Vector m_x
Degrees of freedom position.
Definition: OdeState.h:167
SurgSim::Math::Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
SurgSim::Math::OdeState::~OdeState
virtual ~OdeState()
Destructor.
Definition: OdeState.cpp:31
SurgSim::Math::OdeState
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
SurgSim::Math::OdeState::isValid
virtual bool isValid() const
Check if this state is numerically valid.
Definition: OdeState.cpp:219
SparseMatrix.h
Definitions of useful sparse matrix functions.
SurgSim::Math::OdeState::operator==
bool operator==(const OdeState &state) const
Comparison operator (equality test)
Definition: OdeState.cpp:35
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::OdeState::getNumDof
size_t getNumDof() const
Retrieves the number of degrees of freedom.
Definition: OdeState.cpp:68
SurgSim::Math::OdeState::getNumBoundaryConditions
size_t getNumBoundaryConditions() const
Retrieves the number of boundary conditions.
Definition: OdeState.cpp:142
Matrix.h
Definitions of small fixed-size square matrix types.
SurgSim::Math::OdeState::interpolate
OdeState interpolate(const OdeState &other, double t) const
Returns the linear interpolated ODE state between this and other at parameter t.
Definition: OdeState.cpp:231
Vector.h
Definitions of small fixed-size vector types.
SurgSim::Math::OdeState::getVelocity
const SurgSim::Math::Vector3d getVelocity(size_t nodeId) const
Retrieves the velocity of a given node (const version)
Definition: OdeState.cpp:108
SurgSim::Math::OdeState::applyBoundaryConditionsToVector
Vector * applyBoundaryConditionsToVector(Vector *vector) const
Apply boundary conditions to a given vector.
Definition: OdeState.cpp:157
SurgSim::Math::OdeState::getBoundaryConditions
const std::vector< size_t > & getBoundaryConditions() const
Retrieves all boundary conditions.
Definition: OdeState.cpp:147
SurgSim::Math::OdeState::addBoundaryCondition
void addBoundaryCondition(size_t nodeId)
Adds boundary conditions for a given node (fixes all the dof for this node)
Definition: OdeState.cpp:113
SurgSim::Math::OdeState::setNumDof
virtual void setNumDof(size_t numDofPerNode, size_t numNodes)
Allocates the state for a given number of degrees of freedom.
Definition: OdeState.cpp:53
SurgSim::Math::OdeState::OdeState
OdeState()
Default constructor.
Definition: OdeState.cpp:27
SurgSim::Math::OdeState::getPositions
SurgSim::Math::Vector & getPositions()
Retrieves all degrees of freedom&#39;s position (non-const version)
Definition: OdeState.cpp:83
SurgSim::Math::OdeState::getPosition
const SurgSim::Math::Vector3d getPosition(size_t nodeId) const
Retrieves the position of a given node (const version)
Definition: OdeState.cpp:93
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim::Math::OdeState::isBoundaryCondition
bool isBoundaryCondition(size_t dof) const
Queries if a specific dof is a boundary condition or not.
Definition: OdeState.cpp:152