Simbody  3.5
SimTK::Measure_< T >::Differentiate Class Reference

This Measure operator returns the time derivative of its operand measure, or a numerical approximation of the time derivative if an analytic one is not available. More...

+ Inheritance diagram for SimTK::Measure_< T >::Differentiate:

Classes

class  Implementation
 

Public Member Functions

 SimTK_MEASURE_HANDLE_PREAMBLE (Differentiate, Measure_< T >)
 
 Differentiate (Subsystem &subsystem, const Measure_< T > &operand)
 Create a measure whose value is the time derivative of the given operand measure. More...
 
bool isUsingApproximation () const
 Test whether the derivative returned as the value of this measure is being estimated numerically, either because the operand measure is unable to supply its derivative or because setForceUseApproximation(true) has been called. More...
 
const Measure_< T > & getOperandMeasure () const
 Get a reference to the measure that is being differentiated by this measure. More...
 
DifferentiatesetOperandMeasure (const Measure_< T > &operand)
 Set the measure that is to be differentiated by this measure. More...
 
void setForceUseApproximation (bool mustApproximate)
 Force use of numerical approximation for the derivative, even if the operand measure can supply its own derivative. More...
 
bool getForceUseApproximation () const
 Check the current value of the flag which forces this measure to use numerical approximation regardless of whether the operand can supply its own derivative. More...
 
 SimTK_MEASURE_HANDLE_POSTSCRIPT (Differentiate, Measure_< T >)
 
- Public Member Functions inherited from SimTK::Measure_< T >
 SimTK_MEASURE_HANDLE_PREAMBLE_ABSTRACT (Measure_, AbstractMeasure)
 This class is still abstract so we don't want it to allocate an Implementation object in its default constructor. More...
 
const T & getValue (const State &s, int derivOrder=0) const
 Retrieve the Value of this Measure or one of its time derivatives, assuming the supplied State has been realized to at least the required stage for the selected value or derivative, as reported by getDependsOnStage(). More...
 
Measure_setDefaultValue (const T &defaultValue)
 Change the default value associated with this Measure. More...
 
const T & getDefaultValue () const
 Obtain a reference to the default value associated with this Measure. More...
 
 SimTK_MEASURE_HANDLE_POSTSCRIPT (Measure_, AbstractMeasure)
 
- Public Member Functions inherited from SimTK::AbstractMeasure
 AbstractMeasure (Implementation *g=0)
 Provide an Implementation for this AbstractMeasure and bump its reference count. More...
 
 AbstractMeasure (Subsystem &, Implementation *g, const SetHandle &)
 Construct this handle with a given Implementation object (whose reference count will be bumped) and then let the given Subsystem adopt this Measure (which will again bump the Implementation's reference count, leaving us with two new handles). More...
 
 AbstractMeasure (const AbstractMeasure &)
 Shallow copy constructor copies the pointer from the source Implementation object and bumps its reference count. More...
 
AbstractMeasureoperator= (const AbstractMeasure &source)
 Shallow assignment operator results in this handle referencing the same Implementation object as does the source. More...
 
 ~AbstractMeasure ()
 Destructor decrements the Implementation's reference count and deletes the object if the count goes to zero. More...
 
AbstractMeasureshallowAssign (const AbstractMeasure &)
 Shallow assignment operator destructs the current Implementation object (meaning its reference count is decremented and the object actually deleted only if the count goes to zero), then copies the Implementation pointer from the source and bumps its reference count. More...
 
AbstractMeasuredeepAssign (const AbstractMeasure &source)
 Deep assignment clones the Implementation object pointed to by the source handle, so that this handle ends up pointing to a new Measure object similar to the original but not yet contained in any Subsystem. More...
 
int getNumTimeDerivatives () const
 Every Measure can produce a value, and some can provide one or more total derivatives with respect to time of that value. More...
 
Stage getDependsOnStage (int derivOrder=0) const
 At what Stage can we expect the value of this AbstractMeasure or one of its time derivatives to be available? Users of Measures will typically impose restrictions on the levels they will accept. More...
 
bool isSameMeasure (const AbstractMeasure &other) const
 There can be multiple handles on the same Measure. More...
 
bool isEmptyHandle () const
 
bool isInSubsystem () const
 Test whether this Measure object has been adopted by a Subsystem. More...
 
const SubsystemgetSubsystem () const
 Return a reference to the Subsystem that owns this Measure. More...
 
MeasureIndex getSubsystemMeasureIndex () const
 Return the MeasureIndex by which this Measure is known to the Subsystem that owns it. More...
 
const ImplementationgetImpl () const
 
ImplementationupdImpl ()
 
bool hasImpl () const
 
int getRefCount () const
 

Detailed Description

template<class T>
class SimTK::Measure_< T >::Differentiate

This Measure operator returns the time derivative of its operand measure, or a numerical approximation of the time derivative if an analytic one is not available.

If the operand measure provides its own derivative measure, then the value of the Differentiate operator is just the value of the operand's derivative measure, and this measure will have one fewer available derivatives than does the operand. If the operand does not have a derivative, then we will estimate it by the following method:

  • retrieve the previous value f0 and previous derivative fdot0 of the operand measure, and their sample time t0
  • obtain the current value f(t) of the operand
  • estimate fdot(t)=2(f-f0)/(t-t0) - fdot0 (fit a quadratic)
  • record new samples f(t), fdot(t) with timestamp t

Special cases:

  • if t==t0 then fdot(t)=fdot0 (if available) else fdot(t)=0
  • if fdot0 not available, fdot(t)=(f-f0)/(t-t0) (first order estimate)

At initialization of a timestepping study beginning at t=t0, we sample the operand and record its initial value f0 at t0, and set fdot0=NaN. This ensures that we'll return zero as the initial derivative (for lack of anything better) and then use the first order method for the first step's derivative.

Constructor & Destructor Documentation

template<class T>
SimTK::Measure_< T >::Differentiate::Differentiate ( Subsystem subsystem,
const Measure_< T > &  operand 
)
inline

Create a measure whose value is the time derivative of the given operand measure.

Parameters
subsystemThe Subsystem into which this measure will be placed.
operandThe Measure to be differentiated.

Member Function Documentation

template<class T>
SimTK::Measure_< T >::Differentiate::SimTK_MEASURE_HANDLE_PREAMBLE ( Differentiate  ,
Measure_< T >   
)
template<class T>
bool SimTK::Measure_< T >::Differentiate::isUsingApproximation ( ) const
inline

Test whether the derivative returned as the value of this measure is being estimated numerically, either because the operand measure is unable to supply its derivative or because setForceUseApproximation(true) has been called.

template<class T>
const Measure_<T>& SimTK::Measure_< T >::Differentiate::getOperandMeasure ( ) const
inline

Get a reference to the measure that is being differentiated by this measure.

template<class T>
Differentiate& SimTK::Measure_< T >::Differentiate::setOperandMeasure ( const Measure_< T > &  operand)
inline

Set the measure that is to be differentiated by this measure.

This is a topology-stage change so you'll have to call realizeTopology() again on the enclosing System before using it.

template<class T>
void SimTK::Measure_< T >::Differentiate::setForceUseApproximation ( bool  mustApproximate)
inline

Force use of numerical approximation for the derivative, even if the operand measure can supply its own derivative.

This is not recommended! This is a Topology-stage change.

template<class T>
bool SimTK::Measure_< T >::Differentiate::getForceUseApproximation ( ) const
inline

Check the current value of the flag which forces this measure to use numerical approximation regardless of whether the operand can supply its own derivative.

Note that even if the flag is currently false (the default) we may still have to use approximation; see isUsingApproximation().

template<class T>
SimTK::Measure_< T >::Differentiate::SimTK_MEASURE_HANDLE_POSTSCRIPT ( Differentiate  ,
Measure_< T >   
)

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