Go to the documentation of this file. 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(); }
135 virtual void realizeTopology(
State&)
const = 0;
148 virtual Stage getDependsOnStageVirtual(
int order)
const = 0;
155 MeasureIndex myIndex;
159 mutable int refCount;
179 "An empty Measure handle can't be put in a Subsystem.");
196 if (impl != src.impl) {
212 impl = src.impl->
clone();
252 template <
class T>
class Measure_Num {
255 template <>
class Measure_Num<float> {
257 typedef float Element;
258 static int size(
const float&) {
return 1;}
259 static const float& get(
const float& v,
int i) {assert(i==0);
return v;}
260 static float& upd(
float& v,
int i) {assert(i==0);
return v;}
261 static void makeNaNLike(
const float&,
float& nanValue)
263 static void makeZeroLike(
const float&,
float& zeroValue) {zeroValue=0.f;}
266 template <>
class Measure_Num<double> {
268 typedef double Element;
269 static int size(
const double&) {
return 1;}
270 static const double& get(
const double& v,
int i) {assert(i==0);
return v;}
271 static double& upd(
double& v,
int i) {assert(i==0);
return v;}
272 static void makeNaNLike(
const double&,
double& nanValue)
274 static void makeZeroLike(
const double&,
double& zeroValue) {zeroValue=0.;}
278 template <
int M,
class E>
279 class Measure_Num< Vec<M,
E,1> > {
280 typedef Vec<M,E,1> T;
283 static int size(
const T&) {
return M;}
284 static const E& get(
const T& v,
int i) {
return v[i];}
285 static E& upd(T& v,
int i) {
return v[i];}
286 static void makeNaNLike (
const T&, T& nanValue) {nanValue.setToNaN();}
287 static void makeZeroLike(
const T&, T& zeroValue) {zeroValue.setToZero();}
291 template <
int M,
int N,
class E>
292 class Measure_Num< Mat<M,N,
E> > {
293 typedef Mat<M,N,E> T;
296 static int size(
const T&) {
return N;}
297 static const typename T::TCol& get(
const T& m,
int j) {
return m.col(j);}
298 static typename T::TCol& upd(T& m,
int j) {
return m.col(j);}
299 static void makeNaNLike (
const T&, T& nanValue) {nanValue.setToNaN();}
300 static void makeZeroLike(
const T&, T& zeroValue) {zeroValue.setToZero();}
305 class Measure_Num< Vector_<
E> > {
306 typedef Vector_<E> T;
309 static int size(
const T& v) {
return v.size();}
310 static const E& get(
const T& v,
int i) {
return v[i];}
311 static E& upd(T& v,
int i) {
return v[i];}
312 static void makeNaNLike(
const T& v, T& nanValue)
313 { nanValue.resize(v.size()); nanValue.setToNaN(); }
314 static void makeZeroLike(
const T& v, T& zeroValue)
315 { zeroValue.resize(v.size()); zeroValue.setToZero(); }
320 class Measure_Num< Rotation_<
E> > {
321 typedef Rotation_<E> T;
324 static int size(
const T&) {
return 1;}
325 static const T& get(
const T& v,
int i) {assert(i==0);
return v;}
326 static T& upd(T& v,
int i) {assert(i==0);
return v;}
327 static void makeNaNLike(
const T&, T& nanValue)
328 { nanValue.setRotationToNaN(); }
329 static void makeZeroLike(
const T&, T& zeroValue)
330 { zeroValue.setRotationToIdentityMatrix(); }
334 class Measure_Num< Transform_<
E> > {
335 typedef Transform_<E> T;
338 static int size(
const T&) {
return 1;}
339 static const T& get(
const T& v,
int i) {assert(i==0);
return v;}
340 static T& upd(T& v,
int i) {assert(i==0);
return v;}
341 static void makeNaNLike(
const T&, T& nanValue)
342 { nanValue.setToNaN(); }
343 static void makeZeroLike(
const T&, T& zeroValue)
344 { zeroValue.setToZero(); }
363 "Measure_<T>::getValue()",
364 "derivOrder %d was out of range; this Measure allows 0-%d.",
378 "Measure_<T>::getValue()",
379 "Expected State to have been realized to at least stage "
380 "%s but stage was %s.",
386 if (derivOrder < getNumCacheEntries()) {
387 if (!isCacheValueRealized(s,derivOrder)) {
388 T& value = updCacheEntry(s,derivOrder);
389 calcCachedValueVirtual(s, derivOrder, value);
390 markCacheValueRealized(s,derivOrder);
393 return getCacheEntry(s,derivOrder);
398 return getUncachedValueVirtual(s,derivOrder);
404 this->defaultValue = defaultValue;
405 Measure_Num<T>::makeZeroLike(defaultValue, zeroValue);
406 this->invalidateTopologyCache();
415 { presumeValidAtDependsOnStage = presume;
416 this->invalidateTopologyCache(); }
419 {
return presumeValidAtDependsOnStage; }
423 : presumeValidAtDependsOnStage(false),
424 defaultValue(defaultValue),
425 derivIx(numCacheEntries)
427 Measure_Num<T>::makeZeroLike(defaultValue, zeroValue);
434 : presumeValidAtDependsOnStage(false),
436 derivIx(numCacheEntries)
438 Measure_Num<T>::makeZeroLike(defaultValue, zeroValue);
445 : presumeValidAtDependsOnStage(source.presumeValidAtDependsOnStage),
446 defaultValue(source.defaultValue),
447 derivIx(source.derivIx.size())
449 Measure_Num<T>::makeZeroLike(defaultValue, zeroValue);
455 int size()
const {
return Measure_Num<T>::size(defaultValue);}
465 SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
466 "Measure_<T>::Implementation::getCacheEntry()",
467 "Derivative order %d is out of range; only %d cache entries"
468 " were allocated.", derivOrder, getNumCacheEntries());
471 this->
getSubsystem().getCacheEntry(s, derivIx[derivOrder]));
478 SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
479 "Measure_<T>::Implementation::updCacheEntry()",
480 "Derivative order %d is out of range; only %d cache entries"
481 " were allocated.", derivOrder, getNumCacheEntries());
484 this->
getSubsystem().updCacheEntry(s, derivIx[derivOrder]));
490 SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
491 "Measure_<T>::Implementation::isCacheValueRealized()",
492 "Derivative order %d is out of range; only %d cache entries"
493 " were allocated.", derivOrder, getNumCacheEntries());
502 SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
503 "Measure_<T>::Implementation::markCacheValueRealized()",
504 "Derivative order %d is out of range; only %d cache entries"
505 " were allocated.", derivOrder, getNumCacheEntries());
515 SimTK_ERRCHK2(0 <= derivOrder && derivOrder < getNumCacheEntries(),
516 "Measure_<T>::Implementation::markCacheValueNotRealized()",
517 "Derivative order %d is out of range; only %d cache entries"
518 " were allocated.", derivOrder, getNumCacheEntries());
534 "Measure_<T>::Implementation::calcCachedValueVirtual()",
535 "This method should have been overridden by the derived"
536 " Measure but was not. It is needed to calculate the"
537 " cached value for derivOrder=%d.", derivOrder); }
547 "Measure_<T>::Implementation::getUncachedValueVirtual()",
548 "This method should have been overridden by the derived"
549 " Measure but was not. It is needed to return the uncached"
550 " value at derivOrder=%d.", derivOrder);
551 return *
reinterpret_cast<T*
>(0);
562 void realizeTopology(
State& s)
const override final {
566 if (getNumCacheEntries()) {
567 derivIx[0] = presumeValidAtDependsOnStage
573 if (getNumCacheEntries() > 1) {
574 T nanValue; Measure_Num<T>::makeNaNLike(defaultValue, nanValue);
575 for (
int i=1; i < getNumCacheEntries(); ++i) {
576 derivIx[i] = presumeValidAtDependsOnStage
586 realizeMeasureTopologyVirtual(s);
592 bool presumeValidAtDependsOnStage;
597 mutable Array_<CacheEntryIndex> derivIx;
625 {
return derivOrder>0 ? this->getValueZero() : this->
getDefaultValue(); }
643 template <
class T>
inline
645 template <
class T>
inline
653 template <
class T>
inline
655 template <
class T>
inline
685 {
return derivOrder==0 ? s.
getTime()
715 invalidatedStage(
Stage::Empty) {}
719 invalidatedStage(invalidated) {}
724 invalidatedStage(source.invalidatedStage) {}
727 invalidatedStage = invalidates;
728 this->invalidateTopologyCache();
737 { updVarValue(state) = value; }
753 {
return derivOrder>0 ? this->getValueZero() : getVarValue(s); }
762 const T& getVarValue(
const State& s)
const {
763 assert(discreteVarIndex.isValid());
765 this->
getSubsystem().getDiscreteVariable(s, discreteVarIndex));
767 T& updVarValue(
State& s)
const {
768 assert(discreteVarIndex.isValid());
770 this->
getSubsystem().updDiscreteVariable(s, discreteVarIndex));
774 Stage invalidatedStage;
797 dependsOnStage(dependsOn==
Stage::Empty ?
Stage::Topology : dependsOn),
798 invalidatedStage(invalidated)
800 "Got invalidated stage %s and dependsOn stage %s which is illegal "
801 "because the invalidated stage must be later than dependsOn.",
808 dependsOnStage(source.dependsOnStage),
809 invalidatedStage(source.invalidatedStage) {}
814 "Measure::Result::setDependsOnStage()",
815 "The provided dependsOn stage %s is illegal because it is not "
816 "less than the current invalidated stage %s. Change the "
817 "invalidated stage first with setInvalidatedStage().",
819 getInvalidatedStage().getName().c_str());
821 dependsOnStage = dependsOn;
822 this->invalidateTopologyCache();
827 "Measure::Result::setInvalidatedStage()",
828 "The provided invalidated stage %s is illegal because it is not "
829 "greater than the current dependsOn stage %s. Change the "
830 "dependsOn stage first with setDependsOnStage().",
834 invalidatedStage = invalidated;
835 this->invalidateTopologyCache();
846 "Measure::Result::markAsValid()",
847 "This Result Measure cannot be marked valid in a State where this "
848 "measure's Subsystem has been realized only to stage %s, because "
849 "its value was declared to depend on stage %s. To mark it valid, "
850 "we require that the State have been realized at least to the "
851 "previous stage (%s in this case); that is, you must at least be "
852 "*working on* the dependsOn stage in order to claim this result is "
854 subsystemStage.
getName().c_str(),
857 this->markCacheValueRealized(state, 0); }
860 {
return this->isCacheValueRealized(state, 0); }
863 { this->markCacheValueNotRealized(state, 0);
867 { markAsNotValid(state);
return this->updCacheEntry(state, 0); }
884 "Measure_<T>::Result::getValue()",
885 "Measure_<T>::Result::getValue() was called when the value was not "
886 "yet valid. For most Measure types, this would have initiated "
887 "computation of the value, but Result measures must have their values "
888 "calculated and set externally, and then marked valid."); }
892 Stage dependsOnStage;
893 Stage invalidatedStage;
905 static const int NumDerivs = 3;
909 a(
CNT<T>::getNaN()), w(
CNT<T>::getNaN()), p(
CNT<T>::getNaN()) {}
915 a(amplitude), w(frequency), p(phase) {}
933 using std::sin;
using std::cos;
935 assert(NumDerivs == 3);
937 const T arg = w*t + p;
939 switch (derivOrder) {
940 case 0: value = a*sin(arg);
break;
941 case 1: value = w*a*cos(arg);
break;
942 case 2: value = -w*w*a*sin(arg);
break;
943 case 3: value = -w*w*w*a*cos(arg);
break;
945 "Measure::Sinusoid::Implementation::calcCachedValueVirtual():"
946 " derivOrder %d is out of range 0-3.", derivOrder);
974 : left(left), right(right) {}
993 right.getDependsOnStage(order))); }
999 value = left.getValue(s,derivOrder) + right.getValue(s,derivOrder);
1027 : left(left), right(right) {}
1046 right.getDependsOnStage(order))); }
1052 value = left.getValue(s,derivOrder) - right.getValue(s,derivOrder);
1081 : factor(factor), operand(operand) {}
1088 this->invalidateTopologyCache();
1109 {
return operand.getDependsOnStage(order); }
1115 value = factor * operand.getValue(s,derivOrder);
1151 const T& defaultValue)
1153 derivMeasure(deriv), icMeasure(ic) {}
1159 derivMeasure(source.derivMeasure), icMeasure(source.icMeasure) {}
1165 { assert(zIndex >= 0);
1166 for (
int i=0; i < this->size(); ++i)
1168 Measure_Num<T>::get(value, i); }
1172 "Measure_<T>::Integrate::getDerivativeMeasure()",
1173 "No derivative measure is available for this integrated measure.");
1174 return derivMeasure; }
1178 "Measure_<T>::Integrate::getInitialConditionMeasure()",
1179 "No initial condition measure is available for this "
1180 "integrated measure.");
1184 { derivMeasure = d; this->invalidateTopologyCache(); }
1186 { icMeasure = ic; this->invalidateTopologyCache(); }
1196 {
int integralDerivs = getDerivativeMeasure().getNumTimeDerivatives();
1200 return integralDerivs; }
1204 { assert(derivOrder == 0);
1205 assert(Measure_Num<T>::size(value) == this->size());
1206 assert(zIndex.isValid());
1208 for (
int i=0; i < this->size(); ++i)
1209 Measure_Num<T>::upd(value,i) = allZ[zIndex+i];
1214 { assert(derivOrder > 0);
1215 return getDerivativeMeasure().getValue(s, derivOrder-1);
1219 {
return derivOrder>0
1220 ? getDerivativeMeasure().getDependsOnStage(derivOrder-1)
1226 assert(zIndex.isValid());
1228 if (!icMeasure.isEmptyHandle()) {
1230 .
realize(s, icMeasure.getDependsOnStage());
1231 const T& ic = icMeasure.getValue(s);
1232 for (
int i=0; i < this->size(); ++i)
1233 allZ[zIndex+i] = Measure_Num<T>::get(ic,i);
1235 for (
int i=0; i < this->size(); ++i)
1245 Vector init(this->size());
1246 for (
int i=0; i < this->size(); ++i)
1254 assert(zIndex.isValid());
1256 if (!derivMeasure.isEmptyHandle()) {
1257 const T& deriv = derivMeasure.getValue(s);
1258 for (
int i=0; i < this->size(); ++i)
1259 allZDot[zIndex+i] = Measure_Num<T>::get(deriv,i);
1261 allZDot(zIndex,this->size()) = 0;
1289 class Measure_Differentiate_Result {
1291 Measure_Differentiate_Result() : derivIsGood(false) {}
1302 typedef Measure_Differentiate_Result<T> Result;
1309 operand(operand), forceUseApprox(false), isApproxInUse(false) {}
1315 forceUseApprox = mustApproximate;
1316 this->invalidateTopologyCache();
1320 this->operand = operand;
1321 this->invalidateTopologyCache();
1336 {
if (!isApproxInUse)
return operand.getNumTimeDerivatives()-1;
1340 {
if (!isApproxInUse)
return operand.getDependsOnStage(order+1);
1341 else return operand.getDependsOnStage(order); }
1349 {
if (!isApproxInUse)
1350 return operand.getValue(s, derivOrder+1);
1352 ensureDerivativeIsRealized(s);
1356 return result.operandDot;
1360 if (!isApproxInUse)
return;
1362 assert(resultIx.isValid());
1367 result.operand = operand.getValue(s);
1368 result.operandDot = this->getValueZero();
1369 result.derivIsGood =
false;
1373 isApproxInUse = (forceUseApprox || operand.getNumTimeDerivatives()==0);
1385 ensureDerivativeIsRealized(s);
1389 assert(resultIx.isValid());
1397 const T& f0 = prevResult.operand;
1398 const T& fdot0 = prevResult.operandDot;
1399 const bool good0 = prevResult.derivIsGood;
1404 T& f = result.operand;
1405 T& fdot = result.operandDot;
1406 bool& good = result.derivIsGood;
1408 f = operand.getValue(s);
1411 fdot = this->getValueZero();
1416 fdot = (f-f0)/(t-t0);
1418 fdot =
Real(2)*fdot - fdot0;
1426 bool forceUseApprox;
1429 mutable bool isApproxInUse;
1461 this->operand = operand;
1462 this->invalidateTopologyCache();
1469 this->operation = op;
1470 this->invalidateTopologyCache();
1483 assert(extremeIx.isValid());
1495 const bool hasNewExtreme = ensureExtremeHasBeenUpdated(s);
1513 {
return operand.getNumTimeDerivatives(); }
1518 {
return operand.getDependsOnStage(order); }
1528 const bool hasNewExtreme = ensureExtremeHasBeenUpdated(s);
1529 if (derivOrder > 0) {
1533 return hasNewExtreme ? operand.getValue(s, derivOrder)
1534 : this->getValueZero();
1536 if (hasNewExtreme) {
1551 setValue(s, operand.getValue(s));
1568 case MaxAbs: initVal = 0;
break;
1573 new Value<T>(initVal), operand.getDependsOnStage(0));
1577 new Value<bool>(
false), operand.getDependsOnStage(0));
1583 ensureExtremeHasBeenUpdated(s);
1592 assert(extremeIx.isValid() && isNewExtremeIx.isValid());
1608 const T& currentVal = operand.getValue(s);
1611 bool foundNewExt =
false;
1612 for (
int i=0; i < this->size() && !foundNewExt; ++i)
1613 foundNewExt = isNewExtreme(Measure_Num<T>::get(currentVal,i),
1614 Measure_Num<T>::get(prevExtreme,i));
1638 for (
int i=0; i < this->size(); ++i)
1639 Measure_Num<T>::upd(newExtreme,i) =
1640 extremeOf(Measure_Num<T>::get(currentVal,i),
1641 Measure_Num<T>::get(prevExtreme,i));
1650 bool isNewExtreme(
const typename Measure_Num<T>::Element& newVal,
1651 const typename Measure_Num<T>::Element& oldExtreme)
const
1653 switch (operation) {
1660 "Measure::Extreme::Implementation::isNewExtreme(): "
1661 "unrecognized operation %d", (
int)operation);
1668 bool isExtremeDir(
const typename Measure_Num<T>::Element& value,
1669 const typename Measure_Num<T>::Element& deriv)
const
1671 const int sv =
sign(value), sd =
sign(deriv);
1672 if (sd == 0)
return false;
1673 switch (operation) {
1680 "Measure::Extreme::Implementation::isExtremeDir(): "
1681 "unrecognized operation %d", (
int)operation);
1685 typename Measure_Num<T>::Element
1686 extremeOf(
const typename Measure_Num<T>::Element& newVal,
1687 const typename Measure_Num<T>::Element& oldExtreme)
const
1689 return isNewExtreme(newVal,oldExtreme) ? newVal : oldExtreme;
1693 Measure_<T> operand;
1742 class Measure_Delay_Buffer {
1744 explicit Measure_Delay_Buffer() {initDataMembers();}
1745 void clear() {initDataMembers();}
1746 int size()
const {
return m_size;}
1747 int capacity()
const {
return m_times.size();}
1748 bool empty()
const {
return size()==0;}
1749 bool full()
const {
return size()==capacity();}
1751 double getEntryTime(
int i)
const
1752 { assert(i < size());
return m_times[getArrayIndex(i)];}
1753 const T& getEntryValue(
int i)
const
1754 { assert(i < size());
return m_values[getArrayIndex(i)];}
1757 InitialAllocation = 8,
1759 MaxShrinkProofSize = 16,
1765 void append(
double tEarliest,
double tNow,
const T& valueNow) {
1766 forgetEntriesMuchOlderThan(tEarliest);
1767 removeEntriesLaterOrEq(tNow);
1770 else if (capacity() >
std::max((
int)MaxShrinkProofSize,
1771 (
int)TooBigFactor * (size()+1)))
1773 const int nextFree = getArrayIndex(m_size++);
1774 m_times[nextFree] = tNow;
1775 m_values[nextFree] = valueNow;
1776 m_maxSize =
std::max(m_maxSize, size());
1780 void prepend(
double tNewOldest,
const T& value) {
1781 assert(empty() || tNewOldest < m_times[m_oldest]);
1782 if (full()) makeMoreRoom();
1783 m_oldest = empty() ? 0 : getArrayIndex(-1);
1784 m_times[m_oldest] = tNewOldest;
1785 m_values[m_oldest] = value;
1787 m_maxSize =
std::max(m_maxSize, size());
1796 void copyInAndUpdate(
const Measure_Delay_Buffer& oldBuf,
double tEarliest,
1797 double tNow,
const T& valueNow) {
1799 m_oldest = m_size = 0;
1802 int firstNeeded = oldBuf.countNumUnneededOldEntries(tEarliest);
1803 int lastNeeded = oldBuf.findLastEarlier(tNow);
1804 int numOldEntriesToKeep = lastNeeded-firstNeeded+1;
1805 int newSize = numOldEntriesToKeep+1;
1807 int newSizeRequest = -1;
1808 if (capacity() < newSize) {
1809 newSizeRequest =
std::max((
int)InitialAllocation,
1810 (
int)GrowthFactor * newSize);
1812 }
else if (capacity() >
std::max((
int)MaxShrinkProofSize,
1813 (
int)TooBigFactor * newSize)) {
1814 newSizeRequest =
std::max((
int)MaxShrinkProofSize,
1815 (
int)GrowthFactor * newSize);
1820 if (newSizeRequest != -1) {
1821 const double dNaN = NTraits<double>::getNaN();
1822 m_values.resize(newSizeRequest);
1823 if (m_values.capacity() > m_values.size())
1824 m_values.resize(m_values.capacity());
1825 m_times.resize(m_values.size(), dNaN);
1828 m_maxCapacity =
std::max(m_maxCapacity, capacity());
1832 for (
int i=firstNeeded; i<=lastNeeded; ++i, ++nxt) {
1833 m_times[nxt] = oldBuf.getEntryTime(i);
1834 m_values[nxt] = oldBuf.getEntryValue(i);
1837 m_times[nxt] = tNow;
1838 m_values[nxt] = valueNow;
1839 assert(nxt+1==newSize);
1841 m_maxSize =
std::max(m_maxSize, size());
1847 T calcValueAtTime(
double tDelay,
double tNow,
const T& valueNow)
const;
1852 void calcValueAtTimeLinearOnly(
double tDelay, T& delayedValue)
const {
1856 Measure_Num<T>::makeNaNLike(T(), delayedValue);
1860 int firstLater = findFirstLaterOrEq(tDelay);
1862 if (firstLater > 0) {
1864 int firstEarlier = firstLater-1;
1865 double t0=getEntryTime(firstEarlier), t1=getEntryTime(firstLater);
1866 const T& v0=getEntryValue(firstEarlier);
1867 const T& v1=getEntryValue(firstLater);
1868 Real fraction =
Real((tDelay-t0)/(t1-t0));
1869 delayedValue = T(v0 + fraction*(v1-v0));
1873 if (firstLater==0) {
1876 delayedValue = getEntryValue(firstLater);
1885 delayedValue = getEntryValue(0);
1890 double t0=getEntryTime(size()-2), t1=getEntryTime(size()-1);
1891 const T& v0=getEntryValue(size()-2);
1892 const T& v1=getEntryValue(size()-1);
1893 Real fraction =
Real((tDelay-t0)/(t1-t0));
1894 assert(fraction > 1.0);
1895 delayedValue = T(v0 + fraction*(v1-v0));
1899 int getNumGrows()
const {
return m_nGrows;}
1902 int getNumShrinks()
const {
return m_nShrinks;}
1904 int getMaxSize()
const {
return m_maxSize;}
1906 int getMaxCapacity()
const {
return m_maxCapacity;}
1911 int getArrayIndex(
int i)
const
1912 { assert(-1<=i && i<=size());
1913 const int rawIndex = m_oldest + i;
1914 if (rawIndex < 0)
return rawIndex + capacity();
1915 else return rawIndex % capacity(); }
1918 void forgetEntriesMuchOlderThan(
double tEarliest) {
1919 const int numToRemove = countNumUnneededOldEntries(tEarliest);
1921 m_oldest = getArrayIndex(numToRemove);
1922 m_size -= numToRemove;
1929 int countNumUnneededOldEntries(
double tEarliest)
const {
1930 const int firstLater = findFirstLaterOrEq(tEarliest);
1936 void removeEntriesLaterOrEq(
double t) {
1937 int lastEarlier = findLastEarlier(t);
1938 m_size = lastEarlier+1;
1939 if (m_size==0) m_oldest=0;
1944 int findFirstLaterOrEq(
double tDelay)
const {
1945 for (
int i=0; i < size(); ++i)
1946 if (getEntryTime(i) >= tDelay)
1953 int findLastEarlier(
double t)
const {
1954 for (
int i=size()-1; i>=0; --i)
1955 if (getEntryTime(i) < t)
1962 void makeMoreRoom() {
1963 const int newSizeRequest =
std::max((
int)InitialAllocation,
1964 (
int)GrowthFactor * size());
1965 resize(newSizeRequest);
1967 m_maxCapacity =
std::max(m_maxCapacity, capacity());
1972 void makeLessRoom() {
1973 const int targetMaxSize =
std::max((
int)MaxShrinkProofSize,
1974 (
int)GrowthFactor * size());
1975 if (capacity() > targetMaxSize) {
1976 resize(targetMaxSize);
1986 void resize(
int newSizeRequest) {
1987 assert(newSizeRequest >= size());
1988 const double dNaN = NTraits<double>::getNaN();
1989 Array_<T,int> newValues(newSizeRequest);
1990 if (newValues.capacity() > newValues.size())
1991 newValues.resize(newValues.capacity());
1992 Array_<double,int> newTimes(newValues.size(), dNaN);
1995 for (
int i=0; i < size(); ++i) {
1996 const int ix = getArrayIndex(i);
1997 newTimes[i] = m_times[ix];
1998 newValues[i] = m_values[ix];
2000 m_times.swap(newTimes);
2001 m_values.swap(newValues);
2006 void initDataMembers() {
2007 m_times.clear(); m_values.clear();
2009 m_nGrows=m_nShrinks=m_maxSize=m_maxCapacity=0;
2013 Array_<double,int> m_times;
2014 Array_<T,int> m_values;
2019 int m_nGrows, m_nShrinks, m_maxSize, m_maxCapacity;
2025 typedef Measure_Delay_Buffer<T> Buffer;
2031 m_canUseCurrentValue(false), m_useLinearInterpolationOnly(false) {}
2035 m_canUseCurrentValue(false), m_useLinearInterpolationOnly(false) {}
2042 this->m_source = source;
2043 this->invalidateTopologyCache();
2048 if (delay != this->m_delay) {
2049 this->m_delay = delay;
2050 this->invalidateTopologyCache();
2055 if (linearOnly != this->m_useLinearInterpolationOnly) {
2056 this->m_useLinearInterpolationOnly = linearOnly;
2057 this->invalidateTopologyCache();
2062 if (canUseCurrentValue != this->m_canUseCurrentValue) {
2063 this->m_canUseCurrentValue = canUseCurrentValue;
2064 this->invalidateTopologyCache();
2071 {
return this->m_useLinearInterpolationOnly; }
2073 {
return this->m_canUseCurrentValue; }
2090 {
return this->m_canUseCurrentValue ? m_source.getDependsOnStage(order)
2101 buffer.calcValueAtTimeLinearOnly(s.
getTime()-m_delay, value);
2105 assert(m_bufferIx.isValid());
2111 buffer.append(s.
getTime()-m_delay, s.
getTime(), m_source.getValue(s));
2130 assert(m_bufferIx.isValid());
2140 nextBuffer.copyInAndUpdate(prevBuffer, t-m_delay,
2141 t, m_source.getValue(s));
2149 bool m_canUseCurrentValue;
2150 bool m_useLinearInterpolationOnly;
2162 #endif // SimTK_SimTKCOMMON_MEASURE_IMPLEMENTATION_H_
void markDiscreteVarUpdateValueRealized(const State &s, DiscreteVariableIndex dx) const
Definition: Subsystem.h:268
@ MaxAbs
Definition: Measure.h:840
bool isInSubsystem() const
Test whether this Measure object has been adopted by a Subsystem.
Definition: MeasureImplementation.h:225
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:280
virtual int getNumTimeDerivativesVirtual() const
Definition: MeasureImplementation.h:147
Measure_ & setDefaultValue(const T &defaultValue)
Change the default value associated with this Measure.
Definition: Measure.h:283
AbstractValue & updDiscreteVariable(State &s, DiscreteVariableIndex index) const
Definition: Subsystem.h:247
void updateBuffer(const State &s) const
Definition: MeasureImplementation.h:2129
Implementation(const Measure_< T > &left, const Measure_< T > &right)
Definition: MeasureImplementation.h:972
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:2079
This is the base Implementation class for all Measures whose value type is known.
Definition: MeasureImplementation.h:359
Stage getDependsOnStageVirtual(int order) const override
Definition: MeasureImplementation.h:991
#define SimTK_ERRCHK2_ALWAYS(cond, whereChecked, fmt, a1, a2)
Definition: ExceptionMacros.h:289
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:1244
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:545
bool getUseLinearInterpolationOnly() const
Definition: MeasureImplementation.h:2070
Stage getDependsOnStageVirtual(int order) const override
Definition: MeasureImplementation.h:925
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:1040
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:928
int getNumCacheEntries() const
Return the number of cache entries allocated for the value and derivatives of this Measure.
Definition: MeasureImplementation.h:459
AbstractMeasure(Implementation *g=0)
Provide an Implementation for this AbstractMeasure and bump its reference count.
Definition: MeasureImplementation.h:171
Implementation(const Implementation &source)
Copy constructor copies the number of cache entries from the source, but not the cache indices themse...
Definition: MeasureImplementation.h:444
A Subsystem is expected to be part of a larger System and to have interdependencies with other subsys...
Definition: Subsystem.h:55
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:996
Operation getOperation() const
Return the particular operation being performed by this Extreme measure.
Definition: MeasureImplementation.h:1478
AbstractMeasure & shallowAssign(const AbstractMeasure &)
Shallow assignment operator destructs the current Implementation object (meaning its reference count ...
Definition: MeasureImplementation.h:195
Stage getInvalidatedStage() const
Definition: MeasureImplementation.h:840
void setValue(State &s, const T &value) const
Set the current extreme value stored in this Extreme measure's state variable.
Definition: MeasureImplementation.h:1482
void realizeMeasureAccelerationVirtual(const State &s) const override
Set the zdots to the integrand (derivative measure) value.
Definition: MeasureImplementation.h:1253
Stage getDependsOnStageVirtual(int derivOrder) const override
Definition: MeasureImplementation.h:692
Stage getDependsOnStageVirtual(int order) const override
Definition: MeasureImplementation.h:2089
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:1524
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:2095
Real getDiscreteVarLastUpdateTime(const State &s, DiscreteVariableIndex dx) const
Definition: Subsystem.h:253
Stage getDependsOnStageVirtual(int derivOrder) const override
Definition: MeasureImplementation.h:630
void setDependsOnStage(Stage dependsOn)
Definition: MeasureImplementation.h:811
bool isValid(const State &state) const
Definition: MeasureImplementation.h:859
The abstract parent of all Measure Implementation classes.
Definition: MeasureImplementation.h:48
bool getIsPresumedValidAtDependsOnStage() const
Definition: MeasureImplementation.h:418
void setSourceMeasure(const Measure_< T > &source)
Definition: MeasureImplementation.h:2040
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:1191
void initializeVirtual(State &s) const override
Definition: MeasureImplementation.h:2104
Implementation(const Implementation &source)
Definition: MeasureImplementation.h:806
String getName() const
Return a printable name corresponding to the stage level currently stored in this Stage.
Definition: Stage.h:144
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:489
const Subsystem & getSubsystem() const
Definition: MeasureImplementation.h:119
bool isCacheValueRealized(const State &s, CacheEntryIndex cx) const
Definition: Subsystem.h:271
void setSubsystem(Subsystem &sub, MeasureIndex mx)
Definition: MeasureImplementation.h:114
T & updValue(const State &state) const
Definition: MeasureImplementation.h:866
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:982
bool isFinite(const negator< float > &x)
Definition: negator.h:285
void setOperandMeasure(const Measure_< T > &operand)
Definition: MeasureImplementation.h:1319
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:871
int getRefCount() const
Definition: MeasureImplementation.h:245
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:1035
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:751
const AbstractValue & getDiscreteVarUpdateValue(const State &s, DiscreteVariableIndex dx) const
Definition: Subsystem.h:259
void realizeModel(State &s) const
Definition: MeasureImplementation.h:89
void setValue(State &state, const T &value) const
Change the value of this Measure in the given state.
Definition: MeasureImplementation.h:736
#define SimTK_ERRCHK(cond, whereChecked, msg)
Definition: ExceptionMacros.h:324
int getRefCount() const
Definition: MeasureImplementation.h:79
bool hasImpl() const
Definition: Measure.h:242
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:1099
AbstractValue & updDiscreteVarUpdateValue(const State &s, DiscreteVariableIndex dx) const
Definition: Subsystem.h:262
virtual void realizeMeasureDynamicsVirtual(const State &) const
Definition: MeasureImplementation.h:142
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:632
Implementation()
Definition: MeasureImplementation.h:2029
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:623
This is a System that represents the dynamics of a particle moving along a smooth surface.
Definition: Assembler.h:37
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:1549
void initializeVirtual(State &s) const override
Definition: MeasureImplementation.h:1359
void setInitialConditionMeasure(const Measure_< T > &ic)
Definition: MeasureImplementation.h:1185
#define SimTK_ASSERT1_ALWAYS(cond, msg, a1)
Definition: ExceptionMacros.h:351
void markAsNotValid(const State &state) const
Definition: MeasureImplementation.h:862
CacheEntryIndex allocateLazyCacheEntry(const State &state, Stage earliest, AbstractValue *v) const
Definition: Subsystem.h:111
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:532
@ Model
Modeling choices made.
Definition: Stage.h:71
Implementation()
Definition: MeasureImplementation.h:713
Implementation(const T &litude, const T &frequency, const T &phase=T(0))
Definition: MeasureImplementation.h:911
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:1384
const Real NaN
This is the IEEE "not a number" constant for this implementation of the default-precision Real type; ...
@ Report
Report-only quantities evaluated.
Definition: Stage.h:78
virtual void realizeMeasureTopologyVirtual(State &) const
Concrete measures can override this to allocate Topology-stage resources.
Definition: MeasureImplementation.h:527
void setForceUseApproximation(bool mustApproximate)
Definition: MeasureImplementation.h:1314
Implementation(int numCacheEntries=1)
Argument numCacheEntries should be one greater than the number of derivatives; that is,...
Definition: MeasureImplementation.h:433
Definition: MeasureImplementation.h:1072
int decrRefCount() const
Definition: MeasureImplementation.h:76
The abstract parent of all Subsystem implementation classes.
Definition: SubsystemGuts.h:47
virtual ~Implementation()
Definition: MeasureImplementation.h:132
Implementation()
Definition: MeasureImplementation.h:970
void realizeMeasureTopologyVirtual(State &s) const override
Concrete measures can override this to allocate Topology-stage resources.
Definition: MeasureImplementation.h:1372
virtual void realizeMeasureReportVirtual(const State &) const
Definition: MeasureImplementation.h:144
Implementation(const Implementation &src)
Base class copy constructor removes the Subsystem and sets the reference count to zero.
Definition: MeasureImplementation.h:57
#define SimTK_ERRCHK2(cond, whereChecked, fmt, a1, a2)
Definition: ExceptionMacros.h:328
void realizePosition(const State &s) const
Definition: MeasureImplementation.h:92
Zero()
Definition: MeasureImplementation.h:644
void invalidateTopologyCache() const
Definition: MeasureImplementation.h:125
@ Empty
Lower than any legitimate Stage.
Definition: Stage.h:69
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:617
Stage getDependsOnStageVirtual(int derivOrder) const override
Definition: MeasureImplementation.h:748
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:241
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:1335
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:501
void markAsValid(const State &state) const
Definition: MeasureImplementation.h:843
One()
Definition: MeasureImplementation.h:654
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:874
const Measure_< T > & getOperandMeasure() const
Definition: MeasureImplementation.h:1326
Definition: MeasureImplementation.h:606
This is the base class for all Measure handle classes.
Definition: Measure.h:151
Track the value of the operand that is of minimum absolute value (not very useful).
Definition: Measure.h:914
int size() const
Return the number of elements in the data type of this Measure; for Vector measures this is determine...
Definition: MeasureImplementation.h:455
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:2083
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:878
Implementation()
Definition: MeasureImplementation.h:611
#define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:224
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:1347
int getNumTimeDerivatives() const
Every Measure can produce a value, and some can provide one or more total derivatives with respect to...
Definition: MeasureImplementation.h:237
Subsystem & updSubsystem()
Definition: MeasureImplementation.h:120
Stage getDependsOnStageVirtual(int order) const override
The depends-on stage for this measure is the same as for its operand.
Definition: MeasureImplementation.h:1517
Implementation & operator=(const Implementation &src)
Base class copy assignment operator removes the Subsystem, and sets the reference count to zero.
Definition: MeasureImplementation.h:63
@ Topology
System topology realized.
Definition: Stage.h:70
@ MinAbs
Definition: Measure.h:842
virtual void realizeMeasurePositionVirtual(const State &) const
Definition: MeasureImplementation.h:140
const Real & getTime() const
You can call these as long as system stage >= Model.
T & updCacheEntry(const State &s, int derivOrder) const
Get a writable reference to the value stored in one of this Measure's cache entries,...
Definition: MeasureImplementation.h:477
void realizeAcceleration(const State &s) const
Definition: MeasureImplementation.h:95
void setDerivativeMeasure(const Measure_< T > &d)
Definition: MeasureImplementation.h:1183
Stage getStage(const State &s) const
Definition: Subsystem.h:239
const Measure_< T > & getOperandMeasure() const
Definition: MeasureImplementation.h:1091
void setInvalidatedStage(Stage invalidated)
Definition: MeasureImplementation.h:825
Real getDelay() const
Definition: MeasureImplementation.h:2069
Implementation()
The derivative and initialConditions Measures will be empty handles if this is default constructed.
Definition: MeasureImplementation.h:1146
ELEM max(const VectorBase< ELEM > &v)
Definition: VectorMath.h:251
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:139
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:1591
bool isUsingApproximation() const
Definition: MeasureImplementation.h:1325
Definition: MeasureImplementation.h:786
Stage getDependsOnStageVirtual(int order) const override
Definition: MeasureImplementation.h:1044
Implementation * clone() const
This is a deep copy of the concrete Implementation object, except the Subsystem will have been remove...
Definition: MeasureImplementation.h:86
virtual void realizeMeasureModelVirtual(State &) const
Definition: MeasureImplementation.h:137
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:1112
virtual void realizeMeasureTimeVirtual(const State &) const
Definition: MeasureImplementation.h:139
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:1582
void realize(const State &state, Stage stage=Stage::HighestRuntime) const
Realize the given state to the indicated stage.
Stage getDependsOnStageVirtual(int derivOrder) const override
Definition: MeasureImplementation.h:1218
Implementation(const Measure_< T > &source, Real delay)
Definition: MeasureImplementation.h:2033
#define SimTK_ERRCHK_ALWAYS(cond, whereChecked, msg)
Definition: ExceptionMacros.h:281
Definition: MeasureImplementation.h:1019
int getCopyNumber() const
Definition: MeasureImplementation.h:81
Stage getDependsOnStageVirtual(int order) const override
Definition: MeasureImplementation.h:1339
@ Dynamics
Forces calculated.
Definition: Stage.h:76
void setScaleFactor(Real sf)
Definition: MeasureImplementation.h:1086
Implementation(const Measure_< T > &operand)
Definition: MeasureImplementation.h:1307
Vector & updZ(State &s) const
Definition: Subsystem.h:137
SubsystemIndex getSubsystemIndex() const
Definition: MeasureImplementation.h:122
#define SimTK_ERRCHK3_ALWAYS(cond, whereChecked, fmt, a1, a2, a3)
Definition: ExceptionMacros.h:293
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:1212
bool isInSubsystem() const
Definition: MeasureImplementation.h:118
ZIndex allocateZ(State &s, const Vector &zInit) const
Definition: Subsystem.h:92
const Measure_< T > & getDerivativeMeasure() const
Definition: MeasureImplementation.h:1170
Concrete templatized class derived from AbstractValue, adding generic value type-specific functionali...
Definition: Value.h:39
This class is basically a glorified enumerated type, type-safe and range checked but permitting conve...
Definition: Stage.h:66
DiscreteVariableIndex allocateDiscreteVariable(State &s, Stage g, AbstractValue *v) const
Definition: Subsystem.h:96
An object of this type is used as a dummy argument to make sure the automatically-generated handle co...
Definition: Measure.h:156
const AbstractValue & getDiscreteVariable(const State &s, DiscreteVariableIndex index) const
Definition: Subsystem.h:245
Stage getDependsOnStage(int derivOrder) const
Definition: MeasureImplementation.h:105
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:1150
Stage getInvalidatedStage() const
Definition: MeasureImplementation.h:731
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:683
This creates a Measure whose value is a Topology-stage constant of any type T.
Definition: Measure.h:339
Definition: MeasureImplementation.h:1439
void setOperation(Operation op)
Set the particular operation to be performed by this Extreme measure; this is a Topology stage change...
Definition: MeasureImplementation.h:1468
Definition: MeasureImplementation.h:966
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:1202
Specialized information about Composite Numerical Types which allows us to define appropriate templat...
Definition: CompositeNumericalTypes.h:136
Implementation(const Implementation &source)
Definition: MeasureImplementation.h:722
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:987
void realizeMeasureTopologyVirtual(State &s) const override
Allocate the auto-updated state variable that holds the extreme seen so far.
Definition: MeasureImplementation.h:1561
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:412
virtual void realizeMeasureAccelerationVirtual(const State &) const
Definition: MeasureImplementation.h:143
virtual void realizeMeasureInstanceVirtual(const State &) const
Definition: MeasureImplementation.h:138
const Measure_< T > & getInitialConditionMeasure() const
Definition: MeasureImplementation.h:1176
MeasureIndex getSubsystemMeasureIndex() const
Return the MeasureIndex by which this Measure is known to the Subsystem that owns it.
Definition: MeasureImplementation.h:233
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:690
void realizeInstance(const State &s) const
Definition: MeasureImplementation.h:90
Implementation()
Default constructor leaves the operand measure unspecified; no base class cache entries are allocated...
Definition: MeasureImplementation.h:1446
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:920
Definition: MeasureImplementation.h:1299
void realizeReport(const State &s) const
Definition: MeasureImplementation.h:96
#define SimTK_ERRCHK1_ALWAYS(cond, whereChecked, fmt, a1)
Definition: ExceptionMacros.h:285
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:740
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
Stage getDependsOnStage() const
Definition: MeasureImplementation.h:839
Track the minimum value of the operand (signed).
Definition: Measure.h:883
Track the maximum value of the operand (signed).
Definition: Measure.h:893
void markCacheValueRealized(const State &s, CacheEntryIndex cx) const
Definition: Subsystem.h:273
MeasureIndex adoptMeasure(AbstractMeasure &)
Obtain the Subsystem name if one was given on construction of the concrete Subsystem.
Definition: SubsystemGuts.h:509
Implementation(const Measure_< T > &left, const Measure_< T > &right)
Definition: MeasureImplementation.h:1025
const Stage & getSystemStage() const
This returns the global stage for this State.
Implementation()
Definition: MeasureImplementation.h:791
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:696
Operation
Definition: Measure.h:839
AbstractMeasure & deepAssign(const AbstractMeasure &source)
Deep assignment clones the Implementation object pointed to by the source handle, so that this handle...
Definition: MeasureImplementation.h:208
const Real E
e = Real(exp(1))
void markCacheValueNotRealized(const State &s, CacheEntryIndex cx) const
Definition: Subsystem.h:275
Implementation()
Definition: MeasureImplementation.h:907
void realizeVelocity(const State &s) const
Definition: MeasureImplementation.h:93
Implementation()
Definition: MeasureImplementation.h:677
const T & getDefaultValue() const
Obtain a reference to the default value associated with this Measure.
Definition: Measure.h:288
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:464
CacheEntryIndex allocateCacheEntry(const State &s, Stage dependsOn, Stage computedBy, AbstractValue *v) const
Definition: Subsystem.h:103
const System & getSystem() const
Return a const reference to the System that contains this Subsystem.
Definition: SubsystemGuts.h:520
const T & getValue(const State &s, int derivOrder) const
Definition: MeasureImplementation.h:361
const Vector & getZ(const State &s) const
Definition: Subsystem.h:128
Vector & updZDot(const State &s) const
Definition: Subsystem.h:152
virtual void initializeVirtual(State &) const
Definition: MeasureImplementation.h:146
@ Time
A new time has been realized.
Definition: Stage.h:73
void setValue(State &s, const T &value) const
Set the value of the state variables(s) that hold the integral.
Definition: MeasureImplementation.h:1164
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:606
bool isDiscreteVarUpdateValueRealized(const State &s, DiscreteVariableIndex dx) const
Definition: Subsystem.h:265
void setCanUseCurrentValue(bool canUseCurrentValue)
Definition: MeasureImplementation.h:2061
const Real Infinity
This is the IEEE positive infinity constant for this implementation of the default-precision Real typ...
void setIsPresumedValidAtDependsOnStage(bool presume)
Definition: MeasureImplementation.h:414
Definition: MeasureImplementation.h:669
void setDefaultValue(const T &defaultValue)
Set a new default value for this Measure.
Definition: MeasureImplementation.h:403
int getNumTimeDerivativesVirtual() const override
This measure has one more time derivative than the integrand.
Definition: MeasureImplementation.h:1195
static Value & updDowncast(AbstractValue &value)
Downcast a writable reference to an AbstractValue to a writable reference to this type Value<T>.
Definition: Value.h:225
void setInvalidatedStage(Stage invalidates)
Definition: MeasureImplementation.h:726
MeasureIndex getSubsystemMeasureIndex() const
Definition: MeasureImplementation.h:121
Track the value of the operand that is of maximum absolute value.
Definition: Measure.h:903
Implementation(const T &value)
Definition: MeasureImplementation.h:612
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:1225
static K getNaN()
Definition: CompositeNumericalTypes.h:246
virtual void realizeMeasureVelocityVirtual(const State &) const
Definition: MeasureImplementation.h:141
@ Maximum
Definition: Measure.h:841
static const Value & downcast(const AbstractValue &value)
Downcast a const reference to an AbstractValue to a const reference to this type Value<T>.
Definition: Value.h:219
void realizeMeasureTopologyVirtual(State &s) const override
Concrete measures can override this to allocate Topology-stage resources.
Definition: MeasureImplementation.h:2114
bool isSameMeasure(const AbstractMeasure &other) const
There can be multiple handles on the same Measure.
Definition: Measure.h:220
This Measure tracks extreme values attained by the elements of its source operand since the last init...
Definition: Measure.h:835
int incrRefCount() const
Definition: MeasureImplementation.h:73
void ensureDerivativeIsRealized(const State &s) const
Definition: MeasureImplementation.h:1388
This is the base handle class for all Measures whose value type is known, including all the Simbody b...
Definition: Measure.h:261
const T & getValueZero() const
Return a reference to a zero of the same type and size as this Measure's value.
Definition: MeasureImplementation.h:556
const Implementation & getImpl() const
Definition: Measure.h:240
bool getCanUseCurrentValue() const
Definition: MeasureImplementation.h:2072
RowVectorBase< typename CNT< ELEM >::TAbs > abs(const RowVectorBase< ELEM > &v)
Definition: VectorMath.h:120
Implementation()
Definition: MeasureImplementation.h:1023
void setDelay(Real delay)
Definition: MeasureImplementation.h:2047
const Measure_< T > & getSourceMeasure() const
Definition: MeasureImplementation.h:2068
Implementation(Real factor, const Measure_< T > &operand)
Definition: MeasureImplementation.h:1080
DiscreteVariableIndex allocateAutoUpdateDiscreteVariable(State &s, Stage invalidates, AbstractValue *v, Stage updateDependsOn) const
Definition: Subsystem.h:99
Implementation()
Definition: MeasureImplementation.h:1078
Implementation()
Definition: MeasureImplementation.h:1305
The implementation for Integrate measures allocates a continuous state variable or variables from the...
Definition: MeasureImplementation.h:1141
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:1460
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:1512
void invalidateAllCacheAtOrAbove(Stage) const
If any subsystem or the system stage is currently at or higher than the passed-in one,...
Definition: MeasureImplementation.h:902
Implementation(const T &defaultValue, int numCacheEntries=1)
Definition: MeasureImplementation.h:422
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:1104
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:1507
~AbstractMeasure()
Destructor decrements the Implementation's reference count and deletes the object if the count goes t...
Definition: MeasureImplementation.h:221
const Subsystem & getSubsystem() const
Return a reference to the Subsystem that owns this Measure.
Definition: MeasureImplementation.h:229
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:743
Implementation(Stage dependsOn, Stage invalidated)
Definition: MeasureImplementation.h:795
void realizeDynamics(const State &s) const
Definition: MeasureImplementation.h:94
Stage getDependsOnStageVirtual(int order) const override
Definition: MeasureImplementation.h:1108
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:1451
bool getForceUseApproximation() const
Definition: MeasureImplementation.h:1324
void realizeTime(const State &s) const
Definition: MeasureImplementation.h:91
Stage getStage(const State &s) const
Definition: MeasureImplementation.h:128
void setUseLinearInterpolationOnly(bool linearOnly)
Definition: MeasureImplementation.h:2054
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:628
const Measure_< T > & getOperandMeasure() const
Return a reference to the operand measure for this Extreme measure.
Definition: MeasureImplementation.h:1474
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:881
Definition: MeasureImplementation.h:2024
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:1049
Implementation(Stage invalidated, const T &defaultValue)
Definition: MeasureImplementation.h:717
int getNumTimeDerivatives() const
Definition: MeasureImplementation.h:103
unsigned int sign(unsigned char u)
Definition: Scalar.h:311
int getNumTimeDerivativesVirtual() const override
Definition: MeasureImplementation.h:923
void realizeMeasureTopologyVirtual(State &s) const override
Concrete measures can override this to allocate Topology-stage resources.
Definition: MeasureImplementation.h:757
Implementation()
This default constructor is for use by concrete measure implementation classes.
Definition: MeasureImplementation.h:52
Implementation * cloneVirtual() const override
Definition: MeasureImplementation.h:1331
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:2122
@ Minimum
Definition: Measure.h:843
Real getTimeOfExtremeValue(const State &s) const
Return the time at which the extreme was last updated.
Definition: MeasureImplementation.h:1493
Implementation(const Implementation &source)
Copy constructor shallow-copies the referenced measures, but we don't want to share our state variabl...
Definition: MeasureImplementation.h:1157
Definition: MeasureImplementation.h:706
void markCacheValueNotRealized(const State &s, int derivOrder) const
Invalidate one of this Measure's cache entries.
Definition: MeasureImplementation.h:514
friend class Implementation
Definition: Measure.h:251