1 #ifndef SimTK_SimTKCOMMON_MEASURE_IMPLEMENTATION_H_     2 #define SimTK_SimTKCOMMON_MEASURE_IMPLEMENTATION_H_    58     :   copyNumber(src.copyNumber+1), mySubsystem(0), refCount(0) {}
    65         {   copyNumber=src.copyNumber+1;
    66             refCount=0; mySubsystem=0; }
   106         SimTK_ERRCHK2(0 <= derivOrder && derivOrder <= getNumTimeDerivatives(),
   107             "Measure::getDependsOnStage()",
   108             "derivOrder %d was out of range; this Measure allows 0-%d.",
   109             derivOrder, getNumTimeDerivatives()); 
   110         return getDependsOnStageVirtual(derivOrder); 
   115     {   assert(!mySubsystem && mx.isValid()); 
   116         mySubsystem = ⊂ myIndex = mx; }
   123     {   
return getSubsystem().getMySubsystemIndex(); }
   126     {   
if (isInSubsystem()) getSubsystem().invalidateSubsystemTopologyCache(); }
   137     virtual void realizeTopology(
State&)
const = 0;
   152           getDependsOnStageVirtual(
int order) 
const = 0;
   159     MeasureIndex    myIndex;
   163     mutable int     refCount;
   183         "An empty Measure handle can't be put in a Subsystem.");
   200     if (impl != src.impl) {
   216             impl = src.impl->
clone();
   256 template <
class T> 
class Measure_Num {
   259 template <> 
class Measure_Num<float> {
   261     typedef float Element;
   262     static int size(
const float&) {
return 1;}
   263     static const float& 
get(
const float& v, 
int i) {assert(i==0); 
return v;}
   264     static float& upd(
float& v, 
int i) {assert(i==0); 
return v;}
   265     static void makeNaNLike(
const float&, 
float& nanValue) 
   267     static void makeZeroLike(
const float&, 
float& zeroValue) {zeroValue=0.f;}
   270 template <> 
class Measure_Num<double> {
   272     typedef double Element;
   273     static int size(
const double&) {
return 1;}
   274     static const double& 
get(
const double& v, 
int i) {assert(i==0); 
return v;}
   275     static double& upd(
double& v, 
int i) {assert(i==0); 
return v;}
   276     static void makeNaNLike(
const double&, 
double& nanValue) 
   278     static void makeZeroLike(
const double&, 
double& zeroValue) {zeroValue=0.;}
   282 template <
int M, 
class E>
   283 class Measure_Num< Vec<M,E,1> > {
   287     static int size(
const T&) {
return M;}
   288     static const E& 
get(
const T& v, 
int i) {
return v[i];}
   289     static E& upd(T& v, 
int i) {
return v[i];}
   290     static void makeNaNLike (
const T&, T& nanValue)  {nanValue.setToNaN();}
   291     static void makeZeroLike(
const T&, T& zeroValue) {zeroValue.setToZero();}
   295 template <
int M, 
int N, 
class E>
   296 class Measure_Num< Mat<M,N,E> > {
   300     static int size(
const T&) {
return N;} 
   301     static const typename T::TCol& 
get(
const T& m, 
int j) {
return m.col(j);}
   302     static typename T::TCol& upd(T& m, 
int j) {
return m.col(j);}
   303     static void makeNaNLike (
const T&, T& nanValue)  {nanValue.setToNaN();}
   304     static void makeZeroLike(
const T&, T& zeroValue) {zeroValue.setToZero();}
   309 class Measure_Num< Vector_<E> > {
   313     static int size(
const T& v) {
return v.size();}
   314     static const E& 
get(
const T& v, 
int i) {
return v[i];}
   315     static E& upd(T& v, 
int i) {
return v[i];}
   316     static void makeNaNLike(
const T& v, T& nanValue) 
   317     {   nanValue.resize(v.size()); nanValue.setToNaN(); }
   318     static void makeZeroLike(
const T& v, T& zeroValue)
   319     {   zeroValue.resize(v.size()); zeroValue.setToZero(); }
   324 class Measure_Num< Rotation_<E> > {
   328     static int size(
const T&) {
return 1;}
   329     static const T& 
get(
const T& v, 
int i) {assert(i==0); 
return v;}
   330     static T& upd(T& v, 
int i) {assert(i==0); 
return v;}
   331     static void makeNaNLike(
const T&, T& nanValue) 
   332     {   nanValue.setRotationToNaN(); }
   333     static void makeZeroLike(
const T&, T& zeroValue) 
   334     {   zeroValue.setRotationToIdentityMatrix(); }
   338 class Measure_Num< Transform_<E> > {
   342     static int size(
const T&) {
return 1;}
   343     static const T& 
get(
const T& v, 
int i) {assert(i==0); 
return v;}
   344     static T& upd(T& v, 
int i) {assert(i==0); 
return v;}
   345     static void makeNaNLike(
const T&, T& nanValue) 
   346     {   nanValue.setToNaN(); }
   347     static void makeZeroLike(
const T&, T& zeroValue) 
   348     {   zeroValue.setToZero(); }
   367             "Measure_<T>::getValue()",
   368             "derivOrder %d was out of range; this Measure allows 0-%d.",
   382                 "Measure_<T>::getValue()",
   383                 "Expected State to have been realized to at least stage "   384                 "%s but stage was %s.", 
   390         if (derivOrder < getNumCacheEntries()) {
   391             if (!isCacheValueRealized(s,derivOrder)) {
   392                 T& value = updCacheEntry(s,derivOrder);
   393                 calcCachedValueVirtual(s, derivOrder, value);
   394                 markCacheValueRealized(s,derivOrder);
   397             return getCacheEntry(s,derivOrder);
   402         return getUncachedValueVirtual(s,derivOrder); 
   408         this->defaultValue = defaultValue;
   409         Measure_Num<T>::makeZeroLike(defaultValue, zeroValue);
   410         this->invalidateTopologyCache(); 
   419     {   presumeValidAtDependsOnStage = presume;
   420         this->invalidateTopologyCache(); }
   423     {   
return presumeValidAtDependsOnStage; }
   427     :   presumeValidAtDependsOnStage(false),
   428         defaultValue(defaultValue),
   429         derivIx(numCacheEntries) 
   431         Measure_Num<T>::makeZeroLike(defaultValue, zeroValue);
   438     :   presumeValidAtDependsOnStage(false),
   440         derivIx(numCacheEntries) 
   442         Measure_Num<T>::makeZeroLike(defaultValue, zeroValue);
   449     :   presumeValidAtDependsOnStage(source.presumeValidAtDependsOnStage),
   450         defaultValue(source.defaultValue),
   451         derivIx(source.derivIx.size()) 
   453         Measure_Num<T>::makeZeroLike(defaultValue, zeroValue);
   459     int size()
 const {
return Measure_Num<T>::size(defaultValue);}
   469         SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
   470             "Measure_<T>::Implementation::getCacheEntry()",
   471             "Derivative order %d is out of range; only %d cache entries"   472             " were allocated.", derivOrder, getNumCacheEntries());
   475             this->
getSubsystem().getCacheEntry(s, derivIx[derivOrder]));
   482         SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
   483             "Measure_<T>::Implementation::updCacheEntry()",
   484             "Derivative order %d is out of range; only %d cache entries"   485             " were allocated.", derivOrder, getNumCacheEntries());
   488             this->
getSubsystem().updCacheEntry(s, derivIx[derivOrder]));
   494         SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
   495             "Measure_<T>::Implementation::isCacheValueRealized()",
   496             "Derivative order %d is out of range; only %d cache entries"   497             " were allocated.", derivOrder, getNumCacheEntries());
   506         SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
   507             "Measure_<T>::Implementation::markCacheValueRealized()",
   508             "Derivative order %d is out of range; only %d cache entries"   509             " were allocated.", derivOrder, getNumCacheEntries());
   519         SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
   520             "Measure_<T>::Implementation::markCacheValueNotRealized()",
   521             "Derivative order %d is out of range; only %d cache entries"   522             " were allocated.", derivOrder, getNumCacheEntries());
   541         "Measure_<T>::Implementation::calcCachedValueVirtual()",
   542         "This method should have been overridden by the derived"   543         " Measure but was not. It is needed to calculate the"   544         " cached value for derivOrder=%d.", derivOrder); }
   554             "Measure_<T>::Implementation::getUncachedValueVirtual()",
   555             "This method should have been overridden by the derived"   556             " Measure but was not. It is needed to return the uncached"   557             " value at derivOrder=%d.", derivOrder);
   558         return *
reinterpret_cast<T*
>(0);
   573         if (getNumCacheEntries()) {
   574             derivIx[0] = presumeValidAtDependsOnStage 
   580             if (getNumCacheEntries() > 1) {
   581                 T nanValue; Measure_Num<T>::makeNaNLike(defaultValue, nanValue);
   582                 for (
int i=1; i < getNumCacheEntries(); ++i) {
   583                     derivIx[i] = presumeValidAtDependsOnStage 
   593         realizeMeasureTopologyVirtual(s);
   599     bool    presumeValidAtDependsOnStage;
   624     void setValue(
const T& v) {this->setDefaultValue(v);}
   632     {   
return derivOrder>0 ? this->getValueZero() : this->getDefaultValue(); }
   650 template <
class T> 
inline   652 template <
class T> 
inline   660 template <
class T> 
inline   662 template <
class T> 
inline   692     {   
return derivOrder==0 ? s.getTime()
   722         invalidatedStage(
Stage::Empty) {}
   726         invalidatedStage(invalidated) {}
   731         invalidatedStage(source.invalidatedStage) {}
   734         invalidatedStage = invalidates;
   735         this->invalidateTopologyCache();
   744     {   updVarValue(state) = value; }
   760     {   
return derivOrder>0 ? this->getValueZero() : getVarValue(s); }
   769     const T& getVarValue(
const State& s)
 const {
   770         assert(discreteVarIndex.isValid());
   772             this->
getSubsystem().getDiscreteVariable(s, discreteVarIndex));
   774     T& updVarValue(
State& s)
 const {
   775         assert(discreteVarIndex.isValid());
   777             this->
getSubsystem().updDiscreteVariable(s, discreteVarIndex));
   781     Stage   invalidatedStage; 
   804         dependsOnStage(dependsOn==
Stage::Empty ? 
Stage::Topology : dependsOn), 
   805         invalidatedStage(invalidated)
   807             "Got invalidated stage %s and dependsOn stage %s which is illegal "   808             "because the invalidated stage must be later than dependsOn.",
   815         dependsOnStage(source.dependsOnStage), 
   816         invalidatedStage(source.invalidatedStage) {} 
   821             "Measure::Result::setDependsOnStage()",
   822             "The provided dependsOn stage %s is illegal because it is not "   823             "less than the current invalidated stage %s. Change the "   824             "invalidated stage first with setInvalidatedStage().",
   826             getInvalidatedStage().getName().c_str());
   828         dependsOnStage = dependsOn;
   829         this->invalidateTopologyCache();
   834             "Measure::Result::setInvalidatedStage()",
   835             "The provided invalidated stage %s is illegal because it is not "   836             "greater than the current dependsOn stage %s. Change the "   837             "dependsOn stage first with setDependsOnStage().",
   841         invalidatedStage = invalidated;
   842         this->invalidateTopologyCache();
   853             "Measure::Result::markAsValid()",
   854             "This Result Measure cannot be marked valid in a State where this "   855             "measure's Subsystem has been realized only to stage %s, because "   856             "its value was declared to depend on stage %s. To mark it valid, "   857             "we require that the State have been realized at least to the "   858             "previous stage (%s in this case); that is, you must at least be "   859             "*working on* the dependsOn stage in order to claim this result is "   861             subsystemStage.
getName().c_str(),
   864         this->markCacheValueRealized(state, 0); }
   867     {   
return this->isCacheValueRealized(state, 0); }
   870     {   this->markCacheValueNotRealized(state, 0); 
   874     {   markAsNotValid(state); 
return this->updCacheEntry(state, 0); }
   891         "Measure_<T>::Result::getValue()",
   892         "Measure_<T>::Result::getValue() was called when the value was not "   893         "yet valid. For most Measure types, this would have initiated "   894         "computation of the value, but Result measures must have their values "   895         "calculated and set externally, and then marked valid."); }
   899     Stage   dependsOnStage;
   900     Stage   invalidatedStage;
   912     static const int NumDerivs = 3;
   916         a(
CNT<T>::getNaN()), w(
CNT<T>::getNaN()), p(
CNT<T>::getNaN()) {}
   922         a(amplitude), w(frequency), p(phase) {}
   940         using std::sin; 
using std::cos;
   942         assert(NumDerivs == 3);
   943         const Real t = s.getTime();
   944         const T arg = w*t + p;
   946         switch (derivOrder) {
   947         case 0: value =        a*sin(arg); 
break;
   948         case 1: value =      w*a*cos(arg); 
break;
   949         case 2: value =   -w*w*a*sin(arg); 
break;
   950         case 3: value = -w*w*w*a*cos(arg); 
break;
   952                      "Measure::Sinusoid::Implementation::calcCachedValueVirtual():"   953                      " derivOrder %d is out of range 0-3.", derivOrder);
   981     :   left(left), right(right) {}
  1000                               right.getDependsOnStage(order))); }
  1006         value = left.getValue(s,derivOrder) + right.getValue(s,derivOrder);
  1034     :   left(left), right(right) {}
  1053                               right.getDependsOnStage(order))); }
  1059         value = left.getValue(s,derivOrder) - right.getValue(s,derivOrder);
  1088     :   factor(factor), operand(operand) {}
  1095         this->invalidateTopologyCache();
  1116     {   
return operand.getDependsOnStage(order); }
  1122         value = factor * operand.getValue(s,derivOrder);
  1158                    const T& defaultValue)
  1160         derivMeasure(deriv), icMeasure(ic) {}
  1166         derivMeasure(source.derivMeasure), icMeasure(source.icMeasure) {}
  1172     {   assert(zIndex >= 0);
  1173         for (
int i=0; i < this->size(); ++i)
  1175                 Measure_Num<T>::get(value, i); }
  1179             "Measure_<T>::Integrate::getDerivativeMeasure()",
  1180             "No derivative measure is available for this integrated measure."); 
  1181         return derivMeasure; }
  1185             "Measure_<T>::Integrate::getInitialConditionMeasure()",
  1186             "No initial condition measure is available for this "  1187             "integrated measure."); 
  1191     {   derivMeasure = d; this->invalidateTopologyCache(); }
  1193     {   icMeasure = ic; this->invalidateTopologyCache(); }
  1203     {   
int integralDerivs = getDerivativeMeasure().getNumTimeDerivatives();
  1207         return integralDerivs; }
  1211     {   assert(derivOrder == 0); 
  1212         assert(Measure_Num<T>::size(value) == this->size());
  1213         assert(zIndex.isValid());
  1215         for (
int i=0; i < this->size(); ++i)
  1216             Measure_Num<T>::upd(value,i) = allZ[zIndex+i];
  1221     {   assert(derivOrder > 0); 
  1222         return getDerivativeMeasure().getValue(s, derivOrder-1);
  1226     {   
return derivOrder>0 
  1227             ? getDerivativeMeasure().getDependsOnStage(derivOrder-1)
  1233         assert(zIndex.isValid());
  1235         if (!icMeasure.isEmptyHandle()) {
  1237                 .
realize(s, icMeasure.getDependsOnStage());
  1238             const T& ic = icMeasure.
getValue(s);
  1239             for (
int i=0; i < this->size(); ++i)
  1240                 allZ[zIndex+i] = Measure_Num<T>::get(ic,i);
  1242             for (
int i=0; i < this->size(); ++i)
  1252         Vector init(this->size());
  1253         for (
int i=0; i < this->size(); ++i) 
  1261         assert(zIndex.isValid());
  1263         if (!derivMeasure.isEmptyHandle()) {
  1264             const T& deriv = derivMeasure.
getValue(s);
  1265              for (
int i=0; i < this->size(); ++i)
  1266                  allZDot[zIndex+i] = Measure_Num<T>::get(deriv,i);
  1268             allZDot(zIndex,this->size()) = 0; 
  1296 class Measure_Differentiate_Result {
  1298     Measure_Differentiate_Result() : derivIsGood(
false) {}
  1309     typedef Measure_Differentiate_Result<T> Result;
  1316         operand(operand), forceUseApprox(false), isApproxInUse(false) {}
  1322         forceUseApprox = mustApproximate;
  1323         this->invalidateTopologyCache();
  1327         this->operand = operand;
  1328         this->invalidateTopologyCache();
  1343     {   
if (!isApproxInUse) 
return operand.getNumTimeDerivatives()-1;
  1347     {   
if (!isApproxInUse) 
return operand.getDependsOnStage(order+1);
  1348         else return operand.getDependsOnStage(order); }
  1356     {   
if (!isApproxInUse) 
  1357             return operand.getValue(s, derivOrder+1);
  1359         ensureDerivativeIsRealized(s);
  1363         return result.operandDot; 
  1367         if (!isApproxInUse) 
return;
  1369         assert(resultIx.isValid());
  1372                             (subsys.updDiscreteVariable(s,resultIx));
  1374         result.operand = operand.getValue(s);
  1375         result.operandDot = this->getValueZero();
  1376         result.derivIsGood = 
false;
  1380         isApproxInUse = (forceUseApprox || operand.getNumTimeDerivatives()==0);
  1392         ensureDerivativeIsRealized(s);
  1396         assert(resultIx.isValid());
  1398         if (subsys.isDiscreteVarUpdateValueRealized(s,resultIx))
  1401         const Real t0 = subsys.getDiscreteVarLastUpdateTime(s,resultIx);
  1403            (subsys.getDiscreteVariable(s,resultIx));
  1404         const T&   f0         = prevResult.operand;
  1405         const T&   fdot0      = prevResult.operandDot;   
  1406         const bool good0      = prevResult.derivIsGood;
  1410            (subsys.updDiscreteVarUpdateValue(s,resultIx));
  1411         T&         f          = result.operand;          
  1412         T&         fdot       = result.operandDot;
  1413         bool&      good       = result.derivIsGood;
  1415         f = operand.getValue(s);
  1418             fdot = this->getValueZero(); 
  1423             fdot = (f-f0)/(t-t0); 
  1425                 fdot = 
Real(2)*fdot - fdot0; 
  1428         subsys.markDiscreteVarUpdateValueRealized(s,resultIx);
  1433     bool            forceUseApprox;
  1436     mutable bool                    isApproxInUse;
  1468         this->operand = operand;
  1469         this->invalidateTopologyCache();
  1476         this->operation = op;
  1477         this->invalidateTopologyCache();
  1490         assert(extremeIx.isValid());
  1493                             (subsys.updDiscreteVariable(s,extremeIx));
  1502         const bool hasNewExtreme = ensureExtremeHasBeenUpdated(s);
  1520     {   
return operand.getNumTimeDerivatives(); }
  1525     {   
return operand.getDependsOnStage(order); }
  1535         const bool hasNewExtreme = ensureExtremeHasBeenUpdated(s);
  1536         if (derivOrder > 0) {
  1540             return hasNewExtreme ? operand.getValue(s, derivOrder)
  1541                                  : this->getValueZero();
  1543         if (hasNewExtreme) {
  1575         case MaxAbs:  initVal = 0; 
break;
  1580                 new Value<T>(initVal), operand.getDependsOnStage(0));
  1584                 new Value<bool>(
false), operand.getDependsOnStage(0));
  1590         ensureExtremeHasBeenUpdated(s);
  1599         assert(extremeIx.isValid() && isNewExtremeIx.isValid());
  1604         if (subsys.isDiscreteVarUpdateValueRealized(s, isNewExtremeIx))
  1606                (subsys.getDiscreteVarUpdateValue(s,isNewExtremeIx));
  1614                                     (subsys.getDiscreteVariable(s,extremeIx));
  1615         const T& currentVal = operand.
getValue(s);
  1618         bool foundNewExt = 
false;
  1619         for (
int i=0; i < this->size() && !foundNewExt; ++i) 
  1620             foundNewExt = isNewExtreme(Measure_Num<T>::get(currentVal,i), 
  1621                                        Measure_Num<T>::get(prevExtreme,i));
  1628            (subsys.updDiscreteVarUpdateValue(s,isNewExtremeIx)) = foundNewExt;
  1629         subsys.markDiscreteVarUpdateValueRealized(s,isNewExtremeIx);
  1643                                 (subsys.updDiscreteVarUpdateValue(s,extremeIx));
  1645         for (
int i=0; i < this->size(); ++i)
  1646             Measure_Num<T>::upd(newExtreme,i) =
  1647                 extremeOf(Measure_Num<T>::get(currentVal,i),
  1648                           Measure_Num<T>::get(prevExtreme,i));
  1651         subsys.markDiscreteVarUpdateValueRealized(s,extremeIx);
  1657     bool isNewExtreme(
const typename Measure_Num<T>::Element& newVal,
  1658                       const typename Measure_Num<T>::Element& oldExtreme)
 const  1660         switch (operation) {
  1667             "Measure::Extreme::Implementation::isNewExtreme(): "  1668             "unrecognized operation %d", (
int)operation);
  1675     bool isExtremeDir(
const typename Measure_Num<T>::Element& value,
  1676                       const typename Measure_Num<T>::Element& deriv)
 const   1678         const int sv = 
sign(value), sd = 
sign(deriv);
  1679         if (sd == 0) 
return false; 
  1680         switch (operation) {
  1687             "Measure::Extreme::Implementation::isExtremeDir(): "  1688             "unrecognized operation %d", (
int)operation);
  1692     typename Measure_Num<T>::Element 
  1693     extremeOf(
const typename Measure_Num<T>::Element& newVal,
  1694               const typename Measure_Num<T>::Element& oldExtreme)
 const  1696         return isNewExtreme(newVal,oldExtreme) ? newVal : oldExtreme;
  1701     Operation                       operation;
  1749 class Measure_Delay_Buffer {
  1751     explicit Measure_Delay_Buffer() {initDataMembers();}
  1752     void clear() {initDataMembers();}
  1753     int  size()
 const {
return m_size;} 
  1754     int  capacity()
 const {
return m_times.size();}
  1755     bool empty()
 const {
return size()==0;}
  1756     bool full()
  const {
return size()==capacity();}
  1758     double getEntryTime(
int i)
 const  1759     {   assert(i < size()); 
return m_times[getArrayIndex(i)];}
  1760     const T& getEntryValue(
int i)
 const  1761     {   assert(i < size()); 
return m_values[getArrayIndex(i)];}
  1764         InitialAllocation  = 8,  
  1766         MaxShrinkProofSize = 16, 
  1772     void append(
double tEarliest, 
double tNow, 
const T& valueNow) {
  1773         forgetEntriesMuchOlderThan(tEarliest);
  1774         removeEntriesLaterOrEq(tNow);
  1777         else if (capacity() > 
std::max((
int)MaxShrinkProofSize, 
  1778                                        (
int)TooBigFactor * (size()+1)))
  1780         const int nextFree = getArrayIndex(m_size++);
  1781         m_times[nextFree] = tNow;
  1782         m_values[nextFree] = valueNow;
  1783         m_maxSize = 
std::max(m_maxSize, size());
  1787     void prepend(
double tNewOldest, 
const T& value) {
  1788         assert(empty() || tNewOldest < m_times[m_oldest]);
  1789         if (full()) makeMoreRoom();
  1790         m_oldest = empty() ? 0 : getArrayIndex(-1);
  1791         m_times[m_oldest] = tNewOldest;
  1792         m_values[m_oldest] = value;
  1794         m_maxSize = 
std::max(m_maxSize, size());
  1803     void copyInAndUpdate(
const Measure_Delay_Buffer& oldBuf, 
double tEarliest,
  1804                          double tNow, 
const T& valueNow) {
  1806         m_oldest = m_size = 0;
  1809         int firstNeeded = oldBuf.countNumUnneededOldEntries(tEarliest);
  1810         int lastNeeded  = oldBuf.findLastEarlier(tNow); 
  1811         int numOldEntriesToKeep = lastNeeded-firstNeeded+1;
  1812         int newSize = numOldEntriesToKeep+1; 
  1814         int newSizeRequest = -1;
  1815         if (capacity() < newSize) {
  1816             newSizeRequest = 
std::max((
int)InitialAllocation, 
  1817                                       (
int)GrowthFactor * newSize);
  1819         } 
else if (capacity() > 
std::max((
int)MaxShrinkProofSize, 
  1820                                          (
int)TooBigFactor * newSize)) {
  1821             newSizeRequest = 
std::max((
int)MaxShrinkProofSize, 
  1822                                       (
int)GrowthFactor * newSize);
  1827         if (newSizeRequest != -1) {
  1829             m_values.resize(newSizeRequest); 
  1830             if (m_values.capacity() > m_values.size())
  1831                 m_values.resize(m_values.capacity()); 
  1832             m_times.resize(m_values.size(), dNaN); 
  1835         m_maxCapacity = 
std::max(m_maxCapacity, capacity());
  1839         for (
int i=firstNeeded; i<=lastNeeded; ++i, ++nxt) {
  1840             m_times[nxt]  = oldBuf.getEntryTime(i);
  1841             m_values[nxt] = oldBuf.getEntryValue(i);
  1844         m_times[nxt]  = tNow;
  1845         m_values[nxt] = valueNow;
  1846         assert(nxt+1==newSize);
  1848         m_maxSize = 
std::max(m_maxSize, size());
  1854     T calcValueAtTime(
double tDelay, 
double tNow, 
const T& valueNow) 
const;
  1859     void calcValueAtTimeLinearOnly(
double tDelay, T& delayedValue)
 const {
  1863             Measure_Num<T>::makeNaNLike(T(), delayedValue);
  1867         int firstLater = findFirstLaterOrEq(tDelay);
  1869         if (firstLater > 0) {
  1871             int firstEarlier = firstLater-1;
  1872             double t0=getEntryTime(firstEarlier), t1=getEntryTime(firstLater);
  1873             const T& v0=getEntryValue(firstEarlier);
  1874             const T& v1=getEntryValue(firstLater);
  1875             Real fraction = 
Real((tDelay-t0)/(t1-t0));
  1876             delayedValue = T(v0 + fraction*(v1-v0));
  1880         if (firstLater==0) {
  1883             delayedValue = getEntryValue(firstLater);
  1892             delayedValue = getEntryValue(0);
  1897         double t0=getEntryTime(size()-2), t1=getEntryTime(size()-1);
  1898         const T& v0=getEntryValue(size()-2);
  1899         const T& v1=getEntryValue(size()-1);
  1900         Real fraction = 
Real((tDelay-t0)/(t1-t0));  
  1901         assert(fraction > 1.0);
  1902         delayedValue = T(v0 + fraction*(v1-v0));   
  1906     int getNumGrows()
 const {
return m_nGrows;}
  1909     int getNumShrinks()
 const {
return m_nShrinks;}
  1911     int getMaxSize()
 const {
return m_maxSize;}
  1913     int getMaxCapacity()
 const {
return m_maxCapacity;}
  1918     int getArrayIndex(
int i)
 const   1919     {   assert(-1<=i && i<=size()); 
  1920         const int rawIndex = m_oldest + i;
  1921         if (rawIndex < 0) 
return rawIndex + capacity();
  1922         else return rawIndex % capacity(); }
  1925     void forgetEntriesMuchOlderThan(
double tEarliest) {
  1926         const int numToRemove = countNumUnneededOldEntries(tEarliest);
  1928             m_oldest = getArrayIndex(numToRemove);
  1929             m_size -= numToRemove;
  1936     int countNumUnneededOldEntries(
double tEarliest)
 const {
  1937         const int firstLater = findFirstLaterOrEq(tEarliest);
  1943     void removeEntriesLaterOrEq(
double t) {
  1944         int lastEarlier = findLastEarlier(t);
  1945         m_size = lastEarlier+1;
  1946         if (m_size==0) m_oldest=0; 
  1951     int findFirstLaterOrEq(
double tDelay)
 const {
  1952         for (
int i=0; i < size(); ++i)
  1953             if (getEntryTime(i) >= tDelay)
  1960     int findLastEarlier(
double t)
 const {
  1961         for (
int i=size()-1; i>=0; --i)
  1962             if (getEntryTime(i) < t)
  1969     void makeMoreRoom() {
  1970         const int newSizeRequest = 
std::max((
int)InitialAllocation, 
  1971                                             (
int)GrowthFactor * size());
  1972         resize(newSizeRequest);
  1974         m_maxCapacity = 
std::max(m_maxCapacity, capacity());
  1979     void makeLessRoom() {
  1980         const int targetMaxSize = 
std::max((
int)MaxShrinkProofSize, 
  1981                                            (
int)GrowthFactor * size());
  1982         if (capacity() > targetMaxSize) {
  1983             resize(targetMaxSize);
  1993     void resize(
int newSizeRequest) {
  1994         assert(newSizeRequest >= size());
  2002         for (
int i=0; i < size(); ++i) {
  2003             const int ix = getArrayIndex(i);
  2004             newTimes[i]  = m_times[ix];
  2005             newValues[i] = m_values[ix];
  2007         m_times.
swap(newTimes); 
  2008         m_values.swap(newValues);
  2013     void initDataMembers() {
  2014         m_times.clear(); m_values.clear();
  2016         m_nGrows=m_nShrinks=m_maxSize=m_maxCapacity=0;
  2026     int m_nGrows, m_nShrinks, m_maxSize, m_maxCapacity;
  2032     typedef Measure_Delay_Buffer<T> Buffer;
  2038         m_canUseCurrentValue(false), m_useLinearInterpolationOnly(false) {}
  2042         m_canUseCurrentValue(false), m_useLinearInterpolationOnly(false) {}
  2049             this->m_source = source;
  2050             this->invalidateTopologyCache();
  2055         if (delay != this->m_delay) {
  2056             this->m_delay = delay;
  2057             this->invalidateTopologyCache();
  2062         if (linearOnly != this->m_useLinearInterpolationOnly) {
  2063             this->m_useLinearInterpolationOnly = linearOnly;
  2064             this->invalidateTopologyCache();
  2069         if (canUseCurrentValue != this->m_canUseCurrentValue) {
  2070             this->m_canUseCurrentValue = canUseCurrentValue;
  2071             this->invalidateTopologyCache();
  2078     {   
return this->m_useLinearInterpolationOnly; }
  2080     {   
return this->m_canUseCurrentValue; }
  2097     {   
return this->m_canUseCurrentValue ? m_source.getDependsOnStage(order)
  2108         buffer.calcValueAtTimeLinearOnly(s.getTime()-m_delay, value);
  2112         assert(m_bufferIx.isValid());
  2115                             (subsys.updDiscreteVariable(s,m_bufferIx));
  2118         buffer.append(s.getTime()-m_delay, s.getTime(), m_source.getValue(s));
  2137         assert(m_bufferIx.isValid());
  2141            (subsys.getDiscreteVariable(s,m_bufferIx));
  2144            (subsys.updDiscreteVarUpdateValue(s,m_bufferIx));
  2147         nextBuffer.copyInAndUpdate(prevBuffer, t-m_delay, 
  2148                                    t, m_source.getValue(s));
  2150         subsys.markDiscreteVarUpdateValueRealized(s,m_bufferIx);
  2156     bool            m_canUseCurrentValue;
  2157     bool            m_useLinearInterpolationOnly;
  2169 #endif // SimTK_SimTKCOMMON_MEASURE_IMPLEMENTATION_H_ void calcCachedValueVirtual(const State &, int derivOrder, T &value) const  override
Concrete measures must override this if the state cache is used for precalculated values or derivativ...
Definition: MeasureImplementation.h:888
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:1514
 
virtual void realizeMeasureModelVirtual(State &) const 
Definition: MeasureImplementation.h:139
 
Stage getDependsOnStageVirtual(int order) const  override
Definition: MeasureImplementation.h:998
 
Definition: MeasureImplementation.h:2031
 
virtual void realizeMeasureReportVirtual(const State &) const 
Definition: MeasureImplementation.h:146
 
void setIsPresumedValidAtDependsOnStage(bool presume)
Definition: MeasureImplementation.h:418
 
Definition: MeasureImplementation.h:613
 
Implementation()
Definition: MeasureImplementation.h:914
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:703
 
Stage getDependsOnStageVirtual(int order) const  override
Definition: MeasureImplementation.h:2096
 
const Measure_< T > & getOperandMeasure() const 
Definition: MeasureImplementation.h:1098
 
A Subsystem is expected to be part of a larger System and to have interdependencies with other subsys...
Definition: Subsystem.h:55
 
void setOperandMeasure(const Measure_< T > &operand)
Set the operand measure for this Extreme measure; this is a Topology stage change so you'll have to c...
Definition: MeasureImplementation.h:1467
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:930
 
int getNumTimeDerivativesVirtual() const  override
Extreme(f(t)) has the same number of derivatives as f except that they are all zero unless f(t) is a ...
Definition: MeasureImplementation.h:1519
 
void initializeVirtual(State &s) const  override
Definition: MeasureImplementation.h:1366
 
#define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:218
 
bool isUsingApproximation() const 
Definition: MeasureImplementation.h:1332
 
DiscreteVariableIndex allocateAutoUpdateDiscreteVariable(State &s, Stage invalidates, AbstractValue *v, Stage updateDependsOn) const 
Definition: Subsystem.h:99
 
virtual void realizeMeasureTimeVirtual(const State &) const 
Definition: MeasureImplementation.h:141
 
#define SimTK_ASSERT1_ALWAYS(cond, msg, a1)
Definition: ExceptionMacros.h:351
 
This is the vector class intended to appear in user code for large, variable size column vectors...
Definition: BigMatrix.h:171
 
Implementation(Stage invalidated, const T &defaultValue)
Definition: MeasureImplementation.h:724
 
Definition: MeasureImplementation.h:676
 
Modeling choices made. 
Definition: Stage.h:55
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:2086
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:750
 
Implementation(const Implementation &src)
Base class copy constructor removes the Subsystem and sets the reference count to zero...
Definition: MeasureImplementation.h:57
 
Implementation(const Implementation &source)
Copy constructor copies the number of cache entries from the source, but not the cache indices themse...
Definition: MeasureImplementation.h:448
 
friend class Implementation
Definition: Measure.h:251
 
bool getIsPresumedValidAtDependsOnStage() const 
Definition: MeasureImplementation.h:422
 
bool isInSubsystem() const 
Definition: MeasureImplementation.h:118
 
MeasureIndex adoptMeasure(AbstractMeasure &)
Obtain the Subsystem name if one was given on construction of the concrete Subsystem. 
Definition: SubsystemGuts.h:507
 
void calcCachedValueVirtual(const State &s, int derivOrder, T &value) const  override
Concrete measures must override this if the state cache is used for precalculated values or derivativ...
Definition: MeasureImplementation.h:1119
 
void realizeMeasureAccelerationVirtual(const State &s) const  override
In case no one has updated the value of this measure yet, we have to make sure it gets updated before...
Definition: MeasureImplementation.h:1589
 
Implementation(const Measure_< T > &operand)
Definition: MeasureImplementation.h:1314
 
int decrRefCount() const 
Definition: MeasureImplementation.h:76
 
Implementation * clone() const 
This is a deep copy of the concrete Implementation object, except the Subsystem will have been remove...
Definition: MeasureImplementation.h:86
 
void initializeVirtual(State &s) const  override
Initialize the state to the current value of the initial condition measure, if there is one...
Definition: MeasureImplementation.h:1232
 
Stage getDependsOnStageVirtual(int order) const  override
Definition: MeasureImplementation.h:932
 
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
 
void setValue(State &s, const T &value) const 
Set the value of the state variables(s) that hold the integral. 
Definition: MeasureImplementation.h:1171
 
Implementation(const T &defaultValue, int numCacheEntries=1)
Definition: MeasureImplementation.h:426
 
Stage prev() const 
Return the Stage before this one, with Stage::Empty returned if this Stage is already at its lowest v...
Definition: Stage.h:123
 
const Stage & getSystemStage() const 
This returns the *global* stage for this State. 
 
int size() const 
Return the number of elements in the data type of this Measure; for Vector measures this is determine...
Definition: MeasureImplementation.h:459
 
void resize(size_type n)
Change the size of this Array, preserving all the elements that will still fit, and default construct...
Definition: Array.h:2053
 
void setInvalidatedStage(Stage invalidated)
Definition: MeasureImplementation.h:832
 
const Subsystem & getSubsystem() const 
Definition: MeasureImplementation.h:119
 
virtual ~Implementation()
Definition: MeasureImplementation.h:134
 
Real getDiscreteVarLastUpdateTime(const State &s, DiscreteVariableIndex dx) const 
Definition: Subsystem.h:253
 
void realize(const State &state, Stage stage=Stage::HighestRuntime) const 
Realize the given state to the indicated stage. 
 
Lower than any legitimate Stage. 
Definition: Stage.h:53
 
virtual void realizeMeasureVelocityVirtual(const State &) const 
Definition: MeasureImplementation.h:143
 
void setOperandMeasure(const Measure_< T > &operand)
Definition: MeasureImplementation.h:1326
 
const T & getUncachedValueVirtual(const State &s, int derivOrder) const  override
We're not using the Measure_<T> base class cache services, but we do have one of our own...
Definition: MeasureImplementation.h:1531
 
void setCanUseCurrentValue(bool canUseCurrentValue)
Definition: MeasureImplementation.h:2068
 
virtual void realizeMeasurePositionVirtual(const State &) const 
Definition: MeasureImplementation.h:142
 
void setInitialConditionMeasure(const Measure_< T > &ic)
Definition: MeasureImplementation.h:1192
 
The Rotation class is a Mat33 that guarantees that the matrix can be interpreted as a legitimate 3x3 ...
Definition: Quaternion.h:40
 
void realizeDynamics(const State &s) const 
Definition: MeasureImplementation.h:94
 
Implementation(const Measure_< T > &source, Real delay)
Definition: MeasureImplementation.h:2040
 
This class is basically a glorified enumerated type, type-safe and range checked but permitting conve...
Definition: Stage.h:50
 
void realizeMeasureTopologyVirtual(State &s) const  override
Concrete measures can override this to allocate Topology-stage resources. 
Definition: MeasureImplementation.h:2121
 
int getNumTimeDerivativesVirtual() const  override
This measure has one more time derivative than the integrand. 
Definition: MeasureImplementation.h:1202
 
void realizeInstance(const State &s) const 
Definition: MeasureImplementation.h:90
 
Track the value of the operand that is of maximum absolute value. 
Definition: Measure.h:903
 
virtual const T & getUncachedValueVirtual(const State &, int derivOrder) const 
This is only called when derivOrder >= the number of cache entries we have, but still <= the number o...
Definition: MeasureImplementation.h:552
 
The abstract parent of all Measure Implementation classes. 
Definition: MeasureImplementation.h:48
 
const T & getUncachedValueVirtual(const State &s, int derivOrder) const  override
This is only called when derivOrder >= the number of cache entries we have, but still <= the number o...
Definition: MeasureImplementation.h:758
 
MeasureIndex getSubsystemMeasureIndex() const 
Return the MeasureIndex by which this Measure is known to the Subsystem that owns it...
Definition: MeasureImplementation.h:237
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:881
 
#define SimTK_ERRCHK2_ALWAYS(cond, whereChecked, fmt, a1, a2)          
Definition: ExceptionMacros.h:289
 
void ensureDerivativeIsRealized(const State &s) const 
Definition: MeasureImplementation.h:1395
 
This is the base Implementation class for all Measures whose value type is known. ...
Definition: MeasureImplementation.h:363
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:697
 
Definition: MeasureImplementation.h:793
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:1338
 
String getName() const 
Return a printable name corresponding to the stage level currently stored in this Stage...
Definition: Stage.h:128
 
void setValue(State &state, const T &value) const 
Change the value of this Measure in the given state. 
Definition: MeasureImplementation.h:743
 
bool isCacheValueRealized(const State &s, int derivOrder) const 
Determine whether a particular one of this Measure's cache entries has already been realized since th...
Definition: MeasureImplementation.h:493
 
const T & getDefaultValue() const 
Obtain a reference to the default value associated with this Measure. 
Definition: Measure.h:288
 
Implementation()
The derivative and initialConditions Measures will be empty handles if this is default constructed...
Definition: MeasureImplementation.h:1153
 
void setDelay(Real delay)
Definition: MeasureImplementation.h:2054
 
int incrRefCount() const 
Definition: MeasureImplementation.h:73
 
size_type size() const 
Return the current number of elements stored in this array. 
Definition: Array.h:2037
 
const AbstractValue & getDiscreteVariable(const State &s, DiscreteVariableIndex index) const 
Definition: Subsystem.h:245
 
This is the base class for all Measure handle classes. 
Definition: Measure.h:151
 
Stage getDependsOnStageVirtual(int order) const  override
The depends-on stage for this measure is the same as for its operand. 
Definition: MeasureImplementation.h:1524
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:2090
 
Implementation()
This default constructor is for use by concrete measure implementation classes. 
Definition: MeasureImplementation.h:52
 
SimTK_Real Real
This is the default compiled-in floating point type for SimTK, either float or double. 
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:593
 
#define SimTK_ERRCHK2(cond, whereChecked, fmt, a1, a2)                            
Definition: ExceptionMacros.h:328
 
virtual void realizeMeasureTopologyVirtual(State &) const 
Concrete measures can override this to allocate Topology-stage resources. 
Definition: MeasureImplementation.h:533
 
#define SimTK_ERRCHK_ALWAYS(cond, whereChecked, msg)                        
Definition: ExceptionMacros.h:281
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:747
 
bool isInSubsystem() const 
Test whether this Measure object has been adopted by a Subsystem. 
Definition: MeasureImplementation.h:229
 
This Measure tracks extreme values attained by the elements of its source operand since the last init...
Definition: Measure.h:835
 
Vector & updZ(State &s) const 
Definition: Subsystem.h:137
 
CacheEntryIndex allocateCacheEntry(const State &s, Stage dependsOn, Stage computedBy, AbstractValue *v) const 
Definition: Subsystem.h:103
 
Track the minimum value of the operand (signed). 
Definition: Measure.h:883
 
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:276
 
bool getCanUseCurrentValue() const 
Definition: MeasureImplementation.h:2079
 
This file declares the base class AbstractMeasure for all derived Measure handle classes, and the handle classes for built-in Measures. 
 
int getRefCount() const 
Definition: MeasureImplementation.h:79
 
const Real NaN
This is the IEEE "not a number" constant for this implementation of the default-precision Real type; ...
 
Definition: MeasureImplementation.h:1026
 
Stage getDependsOnStageVirtual(int order) const  override
Definition: MeasureImplementation.h:1346
 
const Measure_< T > & getDerivativeMeasure() const 
Definition: MeasureImplementation.h:1177
 
Real getTimeOfExtremeValue(const State &s) const 
Return the time at which the extreme was last updated. 
Definition: MeasureImplementation.h:1500
 
void markAsNotValid(const State &state) const 
Definition: MeasureImplementation.h:869
 
Stage getStage(const State &s) const 
Definition: Subsystem.h:239
 
Implementation(const T &litude, const T &frequency, const T &phase=T(0))
Definition: MeasureImplementation.h:918
 
Stage getDependsOnStageVirtual(int derivOrder) const  override
Definition: MeasureImplementation.h:637
 
Implementation()
Definition: MeasureImplementation.h:1312
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:994
 
bool isFinite(const negator< float > &x)
Definition: negator.h:287
 
void calcCachedValueVirtual(const State &s, int derivOrder, T &value) const  override
Concrete measures must override this if the state cache is used for precalculated values or derivativ...
Definition: MeasureImplementation.h:1056
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:1342
 
Stage getDependsOnStage(int derivOrder) const 
Definition: MeasureImplementation.h:105
 
void setValue(const T &v)
Changing the value of a Constant measure is a topological change; if this is a Vector measure you can...
Definition: MeasureImplementation.h:624
 
void setSourceMeasure(const Measure_< T > &source)
Definition: MeasureImplementation.h:2047
 
void markCacheValueNotRealized(const State &s, CacheEntryIndex cx) const 
Definition: Subsystem.h:275
 
Implementation(const Implementation &source)
Definition: MeasureImplementation.h:729
 
const Measure_< T > & getOperandMeasure() const 
Return a reference to the operand measure for this Extreme measure. 
Definition: MeasureImplementation.h:1481
 
This is a fixed-length column vector designed for no-overhead inline computation. ...
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:605
 
Report-only quantities evaluated. 
Definition: Stage.h:62
 
ZIndex allocateZ(State &s, const Vector &zInit) const 
Definition: Subsystem.h:92
 
int getCopyNumber() const 
Definition: MeasureImplementation.h:81
 
#define SimTK_ERRCHK1_ALWAYS(cond, whereChecked, fmt, a1)                
Definition: ExceptionMacros.h:285
 
bool isSameMeasure(const AbstractMeasure &other) const 
There can be multiple handles on the same Measure. 
Definition: Measure.h:220
 
const Measure_< T > & getOperandMeasure() const 
Definition: MeasureImplementation.h:1333
 
bool isCacheValueRealized(const State &s, CacheEntryIndex cx) const 
Definition: Subsystem.h:271
 
Definition: MeasureImplementation.h:973
 
void markAsValid(const State &state) const 
Definition: MeasureImplementation.h:850
 
const AbstractValue & getDiscreteVarUpdateValue(const State &s, DiscreteVariableIndex dx) const 
Definition: Subsystem.h:259
 
Definition: MeasureImplementation.h:1079
 
const T & getCacheEntry(const State &s, int derivOrder) const 
Get a const reference to the value stored in one of this Measure's cache entries, indexed by the deri...
Definition: MeasureImplementation.h:468
 
System topology realized. 
Definition: Stage.h:54
 
SubsystemIndex getSubsystemIndex() const 
Definition: MeasureImplementation.h:122
 
#define OVERRIDE_11
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:267
 
bool hasImpl() const 
Definition: Measure.h:242
 
DiscreteVariableIndex allocateDiscreteVariable(State &s, Stage g, AbstractValue *v) const 
Definition: Subsystem.h:96
 
bool getForceUseApproximation() const 
Definition: MeasureImplementation.h:1331
 
void realizeMeasureAccelerationVirtual(const State &s) const  override
Set the zdots to the integrand (derivative measure) value. 
Definition: MeasureImplementation.h:1260
 
Implementation(Stage dependsOn, Stage invalidated)
Definition: MeasureImplementation.h:802
 
Implementation()
Definition: MeasureImplementation.h:720
 
Forces calculated. 
Definition: Stage.h:60
 
Implementation()
Definition: MeasureImplementation.h:2036
 
Implementation()
Definition: MeasureImplementation.h:1030
 
The SimTK::Array_<T> container class is a plug-compatible replacement for the C++ standard template l...
Definition: Array.h:50
 
void realizeAcceleration(const State &s) const 
Definition: MeasureImplementation.h:95
 
void realizeMeasureAccelerationVirtual(const State &s) const  override
In case no one has updated the value of this measure yet, we have to make sure it gets updated before...
Definition: MeasureImplementation.h:1391
 
void setOperation(Operation op)
Set the particular operation to be performed by this Extreme measure; this is a Topology stage change...
Definition: MeasureImplementation.h:1475
 
int getNumTimeDerivatives() const 
Every Measure can produce a value, and some can provide one or more total derivatives with respect to...
Definition: MeasureImplementation.h:241
 
Unique integer type for Subsystem-local z indexing. 
 
CacheEntryIndex allocateLazyCacheEntry(const State &state, Stage earliest, AbstractValue *v) const 
Definition: Subsystem.h:111
 
void initialize(State &s) const 
This should be called at the start of a time stepping study to cause this Measure to set its state va...
Definition: MeasureImplementation.h:101
 
Implementation(const Measure_< T > &left, const Measure_< T > &right)
Definition: MeasureImplementation.h:1032
 
Implementation & operator=(const Implementation &src)
Base class copy assignment operator removes the Subsystem, and sets the reference count to zero...
Definition: MeasureImplementation.h:63
 
Stage getInvalidatedStage() const 
Definition: MeasureImplementation.h:847
 
Operation getOperation() const 
Return the particular operation being performed by this Extreme measure. 
Definition: MeasureImplementation.h:1485
 
Implementation()
Definition: MeasureImplementation.h:684
 
int getRefCount() const 
Definition: MeasureImplementation.h:249
 
virtual void realizeMeasureDynamicsVirtual(const State &) const 
Definition: MeasureImplementation.h:144
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:1106
 
void realizeMeasureTopologyVirtual(State &s) const  override
Concrete measures can override this to allocate Topology-stage resources. 
Definition: MeasureImplementation.h:1379
 
const Subsystem & getSubsystem() const 
Return a reference to the Subsystem that owns this Measure. 
Definition: MeasureImplementation.h:233
 
void markCacheValueRealized(const State &s, CacheEntryIndex cx) const 
Definition: Subsystem.h:273
 
ELEM max(const VectorBase< ELEM > &v)
Definition: VectorMath.h:251
 
const Real & getUncachedValueVirtual(const State &s, int derivOrder) const  override
This is only called when derivOrder >= the number of cache entries we have, but still <= the number o...
Definition: MeasureImplementation.h:690
 
void invalidateTopologyCache() const 
Definition: MeasureImplementation.h:125
 
Implementation(const Measure_< T > &left, const Measure_< T > &right)
Definition: MeasureImplementation.h:979
 
void calcCachedValueVirtual(const State &s, int derivOrder, T &value) const  override
Concrete measures must override this if the state cache is used for precalculated values or derivativ...
Definition: MeasureImplementation.h:2102
 
This creates a Measure whose value is a Topology-stage constant of any type T. 
Definition: Measure.h:339
 
Stage getDependsOnStageVirtual(int order) const  override
Definition: MeasureImplementation.h:1051
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:989
 
void updateBuffer(const State &s) const 
Definition: MeasureImplementation.h:2136
 
virtual void calcCachedValueVirtual(const State &, int derivOrder, T &value) const 
Concrete measures must override this if the state cache is used for precalculated values or derivativ...
Definition: MeasureImplementation.h:539
 
Stage getDependsOnStageVirtual(int derivOrder) const  override
Definition: MeasureImplementation.h:1225
 
void calcCachedValueVirtual(const State &s, int derivOrder, T &value) const  override
Concrete measures must override this if the state cache is used for precalculated values or derivativ...
Definition: MeasureImplementation.h:935
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:1111
 
void realizeReport(const State &s) const 
Definition: MeasureImplementation.h:96
 
void setForceUseApproximation(bool mustApproximate)
Definition: MeasureImplementation.h:1321
 
#define SimTK_ERRCHK(cond, whereChecked, msg)                                          
Definition: ExceptionMacros.h:324
 
Subsystem & updSubsystem()
Definition: MeasureImplementation.h:120
 
The abstract parent of all Subsystem implementation classes. 
Definition: SubsystemGuts.h:47
 
const Vector & getZ(const State &s) const 
Definition: Subsystem.h:128
 
Zero()
Definition: MeasureImplementation.h:651
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:1042
 
#define SimTK_ERRCHK3_ALWAYS(cond, whereChecked, fmt, a1, a2, a3)    
Definition: ExceptionMacros.h:293
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:927
 
void calcCachedValueVirtual(const State &s, int derivOrder, T &value) const  override
Concrete measures must override this if the state cache is used for precalculated values or derivativ...
Definition: MeasureImplementation.h:1003
 
virtual void realizeMeasureAccelerationVirtual(const State &) const 
Definition: MeasureImplementation.h:145
 
Stage getDependsOnStageVirtual(int derivOrder) const  override
Definition: MeasureImplementation.h:755
 
MeasureIndex getSubsystemMeasureIndex() const 
Definition: MeasureImplementation.h:121
 
Implementation()
Definition: MeasureImplementation.h:977
 
~AbstractMeasure()
Destructor decrements the Implementation's reference count and deletes the object if the count goes t...
Definition: MeasureImplementation.h:225
 
T & updValue(const State &state) const 
Definition: MeasureImplementation.h:873
 
const System & getSystem() const 
Return a const reference to the System that contains this Subsystem. 
Definition: SubsystemGuts.h:518
 
RowVectorBase< typename CNT< ELEM >::TAbs > abs(const RowVectorBase< ELEM > &v)
Definition: VectorMath.h:120
 
const T & getUncachedValueVirtual(const State &s, int derivOrder) const  override
This is only called when derivOrder >= the number of cache entries we have, but still <= the number o...
Definition: MeasureImplementation.h:1354
 
void initializeVirtual(State &s) const  override
At start of a time stepping study, this should be called to set the current extreme value to the curr...
Definition: MeasureImplementation.h:1556
 
void swap(Array_ &other)
This is a specialized algorithm providing constant time exchange of data with another array that has ...
Definition: Array.h:1946
 
Stage getStage(const State &s) const 
Definition: MeasureImplementation.h:128
 
const T & getValue(const State &s, int derivOrder) const 
Definition: MeasureImplementation.h:365
 
const Measure_< T > & getSourceMeasure() const 
Definition: MeasureImplementation.h:2075
 
const Measure_< T > & getInitialConditionMeasure() const 
Definition: MeasureImplementation.h:1183
 
const Real Infinity
This is the IEEE positive infinity constant for this implementation of the default-precision Real typ...
 
Specialized information about Composite Numerical Types which allows us to define appropriate templat...
Definition: CompositeNumericalTypes.h:136
 
Definition: MeasureImplementation.h:909
 
int getNumCacheEntries() const 
Return the number of cache entries allocated for the value and derivatives of this Measure...
Definition: MeasureImplementation.h:463
 
One()
Definition: MeasureImplementation.h:661
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:1198
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:878
 
Declares the user-visible part of a SimTK::State, the implementation is done in a separate internal c...
 
Definition: MeasureImplementation.h:1446
 
bool isValid(const State &state) const 
Definition: MeasureImplementation.h:866
 
const T & getDefaultValue() const 
Return a reference to the value that this Measure will use to initialize its value-level state resour...
Definition: MeasureImplementation.h:416
 
Implementation(const Measure_< T > &deriv, const Measure_< T > &ic, const T &defaultValue)
Here we're shallow-copying the Measure handles so we'll be referring to the original Measures...
Definition: MeasureImplementation.h:1157
 
This unique integer type is for selecting discrete variables. 
 
The implementation for Integrate measures allocates a continuous state variable or variables from the...
Definition: MeasureImplementation.h:1148
 
Implementation(const T &value)
Definition: MeasureImplementation.h:619
 
void realizeVelocity(const State &s) const 
Definition: MeasureImplementation.h:93
 
T & updCacheEntry(const State &s, int derivOrder) const 
Get a writable reference to the value stored in one of this Measure's cache entries, indexed by the derivative order (with the value treated as the 0th derivative). 
Definition: MeasureImplementation.h:481
 
unsigned int sign(unsigned char u)
Definition: Scalar.h:311
 
void initializeVirtual(State &s) const  override
Definition: MeasureImplementation.h:2111
 
Implementation(const Implementation &source)
Definition: MeasureImplementation.h:813
 
#define FINAL_11
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:268
 
Implementation()
Default constructor leaves the operand measure unspecified; no base class cache entries are allocated...
Definition: MeasureImplementation.h:1453
 
void realizeMeasureAccelerationVirtual(const State &s) const  override
In case no one has updated the value of this measure yet, we have to make sure it gets updated before...
Definition: MeasureImplementation.h:2129
 
const T & getUncachedValueVirtual(const State &, int derivOrder) const  override
This is only called when derivOrder >= the number of cache entries we have, but still <= the number o...
Definition: MeasureImplementation.h:630
 
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 be...
Definition: Measure.h:274
 
void setDerivativeMeasure(const Measure_< T > &d)
Definition: MeasureImplementation.h:1190
 
void realizeMeasureTopologyVirtual(State &s) const  override
Allocate the auto-updated state variable that holds the extreme seen so far. 
Definition: MeasureImplementation.h:1568
 
Track the maximum value of the operand (signed). 
Definition: Measure.h:893
 
AbstractMeasure & deepAssign(const AbstractMeasure &source)
Deep assignment clones the Implementation object pointed to by the source handle, so that this handle...
Definition: MeasureImplementation.h:212
 
Implementation(int numCacheEntries=1)
Argument numCacheEntries should be one greater than the number of derivatives; that is...
Definition: MeasureImplementation.h:437
 
Provide a unique integer type for identifying Subsystems. 
 
const Implementation & getImpl() const 
Definition: Measure.h:240
 
void setUseLinearInterpolationOnly(bool linearOnly)
Definition: MeasureImplementation.h:2061
 
void realizeMeasureTopologyVirtual(State &s) const  override
Concrete measures can override this to allocate Topology-stage resources. 
Definition: MeasureImplementation.h:764
 
int getNumTimeDerivatives() const 
Definition: MeasureImplementation.h:103
 
Implementation(const Measure_< T > &operand, Operation op)
Construct a measure that returns the extreme value taken on by the operand measure during a time step...
Definition: MeasureImplementation.h:1458
 
Implementation * cloneVirtual() const  override
Definition: MeasureImplementation.h:635
 
Operation
Definition: Measure.h:839
 
Track the value of the operand that is of minimum absolute value (not very useful). 
Definition: Measure.h:914
 
This class represents a small matrix whose size is known at compile time, containing elements of any ...
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:607
 
Implementation()
Definition: MeasureImplementation.h:1085
 
An object of this type is used as a dummy argument to make sure the automatically-generated handle co...
Definition: Measure.h:156
 
const Real & getTime() const 
You can call these as long as *system* stage >= Model. 
 
void setScaleFactor(Real sf)
Definition: MeasureImplementation.h:1093
 
void setDependsOnStage(Stage dependsOn)
Definition: MeasureImplementation.h:818
 
Implementation(Real factor, const Measure_< T > &operand)
Definition: MeasureImplementation.h:1087
 
void setSubsystem(Subsystem &sub, MeasureIndex mx)
Definition: MeasureImplementation.h:114
 
AbstractMeasure(Implementation *g=0)
Provide an Implementation for this AbstractMeasure and bump its reference count. 
Definition: MeasureImplementation.h:175
 
void setDefaultValue(const T &defaultValue)
Set a new default value for this Measure. 
Definition: MeasureImplementation.h:407
 
AbstractMeasure & shallowAssign(const AbstractMeasure &)
Shallow assignment operator destructs the current Implementation object (meaning its reference count ...
Definition: MeasureImplementation.h:199
 
Definition: MeasureImplementation.h:713
 
Constant & setValue(const T &value)
Change the value returned by this Measure. 
Definition: Measure.h:356
 
Stage getInvalidatedStage() const 
Definition: MeasureImplementation.h:738
 
void realizeTime(const State &s) const 
Definition: MeasureImplementation.h:91
 
A new time has been realized. 
Definition: Stage.h:57
 
const T & getValueZero() const 
Return a reference to a zero of the same type and size as this Measure's value. 
Definition: MeasureImplementation.h:563
 
This is the header which should be included in user programs that would like to make use of all the S...
 
static K getNaN()
Definition: CompositeNumericalTypes.h:246
 
Implementation(const Implementation &source)
Copy constructor shallow-copies the referenced measures, but we don't want to share our state variabl...
Definition: MeasureImplementation.h:1164
 
virtual void realizeMeasureInstanceVirtual(const State &) const 
Definition: MeasureImplementation.h:140
 
bool getUseLinearInterpolationOnly() const 
Definition: MeasureImplementation.h:2077
 
const T & getUncachedValueVirtual(const State &s, int derivOrder) const  override
This is only called when derivOrder >= the number of cache entries we have, but still <= the number o...
Definition: MeasureImplementation.h:1219
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:639
 
Includes internal headers providing declarations for the basic SimTK Core classes. 
 
size_type capacity() const 
Return the number of elements this array can currently hold without requiring reallocation. 
Definition: Array.h:2047
 
void setValue(State &s, const T &value) const 
Set the current extreme value stored in this Extreme measure's state variable. 
Definition: MeasureImplementation.h:1489
 
Stage getDependsOnStageVirtual(int derivOrder) const  override
Cache value is available after its "depends on" stage has been realized; but all its derivatives are ...
Definition: MeasureImplementation.h:885
 
void setInvalidatedStage(Stage invalidates)
Definition: MeasureImplementation.h:733
 
void realizeMeasureTopologyVirtual(State &s) const  override
Allocate one Real continuous state variable z per element of this Measure's data type T...
Definition: MeasureImplementation.h:1251
 
bool ensureExtremeHasBeenUpdated(const State &s) const 
Here we make sure that the cache entry is updated if the current value of the operand is more extreme...
Definition: MeasureImplementation.h:1598
 
void invalidateAllCacheAtOrAbove(Stage) const 
If any subsystem or the system stage is currently at or higher than the passed-in one...
 
Real getDelay() const 
Definition: MeasureImplementation.h:2076
 
int getNumTimeDerivativesVirtual() const  override
Definition: MeasureImplementation.h:1047
 
Stage getDependsOnStage() const 
Definition: MeasureImplementation.h:846
 
virtual void initializeVirtual(State &) const 
Definition: MeasureImplementation.h:148
 
void realizePosition(const State &s) const 
Definition: MeasureImplementation.h:92
 
void realizeModel(State &s) const 
Definition: MeasureImplementation.h:89
 
Vector & updZDot(const State &s) const 
Definition: Subsystem.h:152
 
Definition: MeasureImplementation.h:1306
 
Implementation()
Definition: MeasureImplementation.h:798
 
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 av...
Definition: MeasureImplementation.h:245
 
void calcCachedValueVirtual(const State &s, int derivOrder, T &value) const  override
Concrete measures must override this if the state cache is used for precalculated values or derivativ...
Definition: MeasureImplementation.h:1209
 
void markCacheValueNotRealized(const State &s, int derivOrder) const 
Invalidate one of this Measure's cache entries. 
Definition: MeasureImplementation.h:518
 
void markCacheValueRealized(const State &s, int derivOrder) const 
Mark one of this Measure's cache entries up to date; call this after you have calculated a value or d...
Definition: MeasureImplementation.h:505
 
Stage getDependsOnStageVirtual(int order) const  override
Definition: MeasureImplementation.h:1115
 
This is the base handle class for all Measures whose value type is known, including all the Simbody b...
Definition: Measure.h:261
 
virtual int getNumTimeDerivativesVirtual() const 
Definition: MeasureImplementation.h:150
 
Stage getDependsOnStageVirtual(int derivOrder) const  override
Definition: MeasureImplementation.h:699
 
Implementation()
Definition: MeasureImplementation.h:618
 
Templatized version of the abstract class, providing generic type-specific functionality that does no...
Definition: Value.h:67