opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
801 stars 324 forks source link

Adding a cache variable to `ExpressionBasedBushingForce` leads to out-of-date cache entry in `testComponents.cpp` #3881

Open nickbianco opened 3 months ago

nickbianco commented 3 months ago

When attempting to add a cache variable to ExpressionBasedBushingForce for the purposes of returning an Output value, I encountered the following error when running testComponents:

Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Dynamics. This entry depends on version 1 of Stage Velocity but was last updated at version 0.

The error occurs when calling getValueAsString() at this line. Strangely, modifying auxiliaryTestFunctions for randomizing Vec6 properties to the following somehow fixes the issue (or at least hides it):

} else if (ts == "Vec6" && !isList) {
      Property<SimTK::Vec6>& prop = Property<SimTK::Vec6>::updAs(ap);
      prop = SimTK::Vec6(abs(rand()), abs(rand()), abs(rand()), 
               abs(rand()), abs(rand()), abs(rand()));

The only property that uses Vec6 is Body's inertia property. I'm not sure what the interaction between the property and cache variable is, or whether or not the issue is specific to ExpressionBasedBushingForce or TwoFrameLinker in general.