opensurgsim
Public Member Functions | 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 <OdeState.h>

Inheritance diagram for SurgSim::Math::OdeState:
SurgSim::Math::MassPointsStateForStatic SurgSim::Math::MassPointState

Public Member Functions

 OdeState ()
 Default constructor.
 
virtual ~OdeState ()
 Destructor.
 
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...
 
void addBoundaryConditionStaticDof (size_t nodeId, double value)
 Adds a boundary condition on the static dof of a given node (we consider here that each node has a single static dof) More...
 
size_t getNumBoundaryConditionsStaticDof () const
 
const std::vector< std::pair< size_t, double > > & getBoundaryConditionsStaticDof () const
 
void setBoundaryConditionsStaticDof (const std::vector< std::pair< size_t, double >> &staticDof)
 Set all boundary conditions on static dofs. More...
 
void changeBoundaryConditionStaticDof (size_t nodeId, double value)
 Set the value of an existing boundary condition on a static dof. 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...
 

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) \]

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

§ addBoundaryConditionStaticDof()

void SurgSim::Math::OdeState::addBoundaryConditionStaticDof ( size_t  nodeId,
double  value 
)

Adds a boundary condition on the static dof of a given node (we consider here that each node has a single static dof)

Parameters
nodeIdThe node on which the boundary condition needs to be set
valueThe boundary conidtion value that the static dof needs to be set on
Note
For example, this is fixing the twist angle of a Kircchoff model using a quasi-static update of the material frame.
i.e. the twist is not part of the dynamic DOF, but is still a static dof of the model.

§ 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)\)

§ changeBoundaryConditionStaticDof()

void SurgSim::Math::OdeState::changeBoundaryConditionStaticDof ( size_t  nodeId,
double  value 
)

Set the value of an existing boundary condition on a static dof.

Parameters
nodeIdThe node for which the static dof must be set
valueThe value to set the static dof of the given node
Note
Does not do anything if the static dof boundary condition does not exists yet.

§ 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

§ getBoundaryConditionsStaticDof()

const std::vector< std::pair< size_t, double > > & SurgSim::Math::OdeState::getBoundaryConditionsStaticDof ( ) const
Returns
All boundary conditions for statically defined Dof 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

§ getNumBoundaryConditionsStaticDof()

size_t SurgSim::Math::OdeState::getNumBoundaryConditionsStaticDof ( ) const
Returns
The number of boundary conditions for statically defined Dof

§ 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

§ setBoundaryConditionsStaticDof()

void SurgSim::Math::OdeState::setBoundaryConditionsStaticDof ( const std::vector< std::pair< size_t, double >> &  staticDof)

Set all boundary conditions on static dofs.

Parameters
staticDofThe vector of static dof that must be set
Exceptions
SurgSim::Framework::AssertionFailureif a an item in staticDof does not have a valid nodeId (entry.first)

§ 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

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