Public Member Functions | Private Attributes | List of all members
SurgSim::Math::OdeState Class Reference

The state \(y\) of an ode of 2nd order of the form \(M(x,v).a = F(x, v)\) with boundary conditions. More...

#include <SurgSim/Math/OdeState.h>

Public Member Functions

 OdeState ()
 Default constructor. More...
 
virtual ~OdeState ()
 Destructor. More...
 
bool operator== (const OdeState &state) const
 Comparison operator (equality test) More...
 
bool operator!= (const OdeState &state) const
 Comparison operator (difference test) More...
 
virtual void reset ()
 Resets the state. More...
 
virtual void setNumDof (size_t numDofPerNode, size_t numNodes)
 Allocates the state for a given number of degrees of freedom. More...
 
size_t getNumDof () const
 Retrieves the number of degrees of freedom. More...
 
size_t getNumNodes () const
 Retrieves the number of nodes. More...
 
SurgSim::Math::VectorgetPositions ()
 Retrieves all degrees of freedom's position (non-const version) More...
 
const SurgSim::Math::VectorgetPositions () const
 Retrieves all degrees of freedom's position (const version) More...
 
const SurgSim::Math::Vector3d getPosition (size_t nodeId) const
 Retrieves the position of a given node (const version) More...
 
SurgSim::Math::VectorgetVelocities ()
 Retrieves all degrees of freedom's velocity (non-const version) More...
 
const SurgSim::Math::VectorgetVelocities () const
 Retrieves all degrees of freedom's velocity (const version) More...
 
const SurgSim::Math::Vector3d getVelocity (size_t nodeId) const
 Retrieves the velocity of a given node (const version) More...
 
void addBoundaryCondition (size_t nodeId)
 Adds boundary conditions for a given node (fixes all the dof for this node) More...
 
void addBoundaryCondition (size_t nodeId, size_t nodeDofId)
 Adds a boundary condition on a given dof of a given node (only 1 dof is fixed) More...
 
size_t getNumBoundaryConditions () const
 Retrieves the number of boundary conditions. More...
 
const std::vector< size_t > & getBoundaryConditions () const
 Retrieves all boundary conditions. More...
 
bool isBoundaryCondition (size_t dof) const
 Queries if a specific dof is a boundary condition or not. More...
 
VectorapplyBoundaryConditionsToVector (Vector *vector) const
 Apply boundary conditions to a given vector. More...
 
void applyBoundaryConditionsToMatrix (Matrix *matrix, bool hasCompliance=true) const
 Apply boundary conditions to a given matrix. More...
 
void applyBoundaryConditionsToMatrix (SparseMatrix *matrix, bool hasCompliance=true) const
 Apply boundary conditions to a given matrix. More...
 
virtual bool isValid () const
 Check if this state is numerically valid. More...
 
OdeState interpolate (const OdeState &other, double t) const
 Returns the linear interpolated ODE state between this and other at parameter t. More...
 

Private Attributes

size_t m_numDofPerNode
 Default public copy constructor and assignment operator are being used on purpose. More...
 
size_t m_numNodes
 
SurgSim::Math::Vector m_x
 Degrees of freedom position. More...
 
SurgSim::Math::Vector m_v
 Degrees of freedom velocity (m_x 1st derivative w.r.t. time) More...
 
std::vector< size_t > m_boundaryConditionsAsDofIds
 Boundary conditions stored as a list of dof ids. More...
 
Eigen::Matrix< bool, Eigen::Dynamic, 1 > m_boundaryConditionsPerDof
 Boundary conditions stored per dof (True indicates a boundary condition, False does not) More...
 

Detailed Description

The state \(y\) of an ode of 2nd order of the form \(M(x,v).a = F(x, v)\) with boundary conditions.

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(x, v) \end{array}\right) \]

Constructor & Destructor Documentation

◆ OdeState()

SurgSim::Math::OdeState::OdeState ( )

Default constructor.

◆ ~OdeState()

SurgSim::Math::OdeState::~OdeState ( )
virtual

Destructor.

Member Function Documentation

◆ addBoundaryCondition() [1/2]

void SurgSim::Math::OdeState::addBoundaryCondition ( size_t  nodeId)

Adds boundary conditions for a given node (fixes all the dof for this node)

Parameters
nodeIdThe node to set the boundary conditions on

◆ addBoundaryCondition() [2/2]

void SurgSim::Math::OdeState::addBoundaryCondition ( size_t  nodeId,
size_t  nodeDofId 
)

Adds a boundary condition on a given dof of a given node (only 1 dof is fixed)

Parameters
nodeIdThe node on which the boundary condition needs to be set
nodeDofIdThe dof of the node to set as boundary condition

◆ applyBoundaryConditionsToMatrix() [1/2]

void SurgSim::Math::OdeState::applyBoundaryConditionsToMatrix ( Matrix matrix,
bool  hasCompliance = true 
) const

Apply boundary conditions to a given matrix.

Parameters
matrixThe dense matrix to apply the boundary conditions on
hasComplianceTrue if the fixed dofs should have a compliance of 1 with themselves in the matrix or not.
Note
hasCompliance is practical to remove all compliance, which is helpful when the compliance matrix is used
in an architecture of type LCP. It ensures that a separate constraint resolution will never violates the
boundary conditions.

◆ applyBoundaryConditionsToMatrix() [2/2]

void SurgSim::Math::OdeState::applyBoundaryConditionsToMatrix ( SparseMatrix matrix,
bool  hasCompliance = true 
) const

Apply boundary conditions to a given matrix.

Parameters
matrixThe sparse matrix to apply the boundary conditions on
hasComplianceTrue if the fixed dofs should have a compliance of 1 with themselves in the matrix or not.
Note
hasCompliance is practical to remove all compliance, which is helpful when the compliance matrix is used
in an architecture of type LCP. It ensures that a separate constraint resolution will never violates the
boundary conditions.

◆ applyBoundaryConditionsToVector()

Vector * SurgSim::Math::OdeState::applyBoundaryConditionsToVector ( Vector vector) const

Apply boundary conditions to a given vector.

Parameters
vectorThe vector to apply the boundary conditions on
Returns
The parameter vector. This enables chained use like \(U = K^1 * \text{applyBoundaryConditionsToVector}(x)\)

◆ getBoundaryConditions()

const std::vector< size_t > & SurgSim::Math::OdeState::getBoundaryConditions ( ) const

Retrieves all boundary conditions.

Returns
All boundary conditions as a vector of dof ids

◆ getNumBoundaryConditions()

size_t SurgSim::Math::OdeState::getNumBoundaryConditions ( ) const

Retrieves the number of boundary conditions.

Returns
The number of boundary conditions

◆ getNumDof()

size_t SurgSim::Math::OdeState::getNumDof ( ) const

Retrieves the number of degrees of freedom.

Returns
The number of DOF for this representation

◆ getNumNodes()

size_t SurgSim::Math::OdeState::getNumNodes ( ) const

Retrieves the number of nodes.

Returns
The number of nodes for this representation

◆ getPosition()

const SurgSim::Math::Vector3d SurgSim::Math::OdeState::getPosition ( size_t  nodeId) const

Retrieves the position of a given node (const version)

Parameters
nodeIdThe desired node id for which the position is requested (must be a valid id)
Returns
The position of the node nodeId
Note
Behavior undefined if the nodeId is not in the correct range [0 getNumNodes()-1]

◆ getPositions() [1/2]

SurgSim::Math::Vector & SurgSim::Math::OdeState::getPositions ( )

Retrieves all degrees of freedom's position (non-const version)

Returns
Vector of collected DOF's position

◆ getPositions() [2/2]

const SurgSim::Math::Vector & SurgSim::Math::OdeState::getPositions ( ) const

Retrieves all degrees of freedom's position (const version)

Returns
Vector of collected DOF's position

◆ getVelocities() [1/2]

SurgSim::Math::Vector & SurgSim::Math::OdeState::getVelocities ( )

Retrieves all degrees of freedom's velocity (non-const version)

Returns
Vector of collected DOF's velocity

◆ getVelocities() [2/2]

const SurgSim::Math::Vector & SurgSim::Math::OdeState::getVelocities ( ) const

Retrieves all degrees of freedom's velocity (const version)

Returns
Vector of collected DOF's velocity

◆ getVelocity()

const SurgSim::Math::Vector3d SurgSim::Math::OdeState::getVelocity ( size_t  nodeId) const

Retrieves the velocity of a given node (const version)

Parameters
nodeIdThe desired node id for which the velocity is requested (must be a valid id)
Returns
The velocity of the node nodeId
Note
Behavior undefined if the nodeId is not in the correct range [0 getNumNodes()-1]

◆ interpolate()

OdeState SurgSim::Math::OdeState::interpolate ( const OdeState other,
double  t 
) const

Returns the linear interpolated ODE state between this and other at parameter t.

Parameters
otherthe end point for the linear interpolation
tthe interpolation time
Returns
the interpolated state = this + (other - this) * t;
Note
All dof are independently linearly interpolated (This will not work correctly on rotation vectors where a slerp will be required.)

◆ isBoundaryCondition()

bool SurgSim::Math::OdeState::isBoundaryCondition ( size_t  dof) const

Queries if a specific dof is a boundary condition or not.

Parameters
dofThe requested dof
Returns
True if dof is a boundary condition, False otherwise
Note
The behavior is undefined when dof is out of range [0 getNumBoundaryConditions()-1]

◆ isValid()

bool SurgSim::Math::OdeState::isValid ( ) const
virtual

Check if this state is numerically valid.

Returns
True if all positions and velocities are valid numerical values, False otherwise

http://steve.hollasch.net/cgindex/coding/ieeefloat.html We use the IEEE754 standard stipulating that any arithmetic operation with a NaN operand will produce NaN and any sum of +-INF with a finite number or +-INF will produce +-INF. Therefore, testing if a vector contains only finite numbers can be achieve easily by summing all the values and testing if the result is a finite number or not.

◆ operator!=()

bool SurgSim::Math::OdeState::operator!= ( const OdeState state) const

Comparison operator (difference test)

Parameters
stateThe state to compare it to
Returns
False if the 2 states are equal, True otherwise

◆ operator==()

bool SurgSim::Math::OdeState::operator== ( const OdeState state) const

Comparison operator (equality test)

Parameters
stateThe state to compare it to
Returns
True if the 2 states are equal, False otherwise

◆ reset()

void SurgSim::Math::OdeState::reset ( )
virtual

Resets the state.

Note
Simply set all positions/velocities to 0 and remove all boundary conditions

◆ setNumDof()

void SurgSim::Math::OdeState::setNumDof ( size_t  numDofPerNode,
size_t  numNodes 
)
virtual

Allocates the state for a given number of degrees of freedom.

Parameters
numDofPerNodeThe number of degrees of freedom per node to account for
numNodesThe number of nodes to account for
Note
This method clears all the data structures and remove all existing boundary conditions

Member Data Documentation

◆ m_boundaryConditionsAsDofIds

std::vector<size_t> SurgSim::Math::OdeState::m_boundaryConditionsAsDofIds
private

Boundary conditions stored as a list of dof ids.

◆ m_boundaryConditionsPerDof

Eigen::Matrix<bool, Eigen::Dynamic, 1> SurgSim::Math::OdeState::m_boundaryConditionsPerDof
private

Boundary conditions stored per dof (True indicates a boundary condition, False does not)

◆ m_numDofPerNode

size_t SurgSim::Math::OdeState::m_numDofPerNode
private

Default public copy constructor and assignment operator are being used on purpose.

Keep track of the number of degrees of freedom per node and the number of nodes

◆ m_numNodes

size_t SurgSim::Math::OdeState::m_numNodes
private

◆ m_v

SurgSim::Math::Vector SurgSim::Math::OdeState::m_v
private

Degrees of freedom velocity (m_x 1st derivative w.r.t. time)

◆ m_x

SurgSim::Math::Vector SurgSim::Math::OdeState::m_x
private

Degrees of freedom position.


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