Skip to content

Commit 8c466dd

Browse files
committed
Implement improvements to the Manager class
This implements several changes to the Manager class to improve the user experience when performing time-stepping simulation in OpenSim. The changes include support for the SimTK::CPodesIntegrator, the ability to re-initialize a Manager, many improvements to the documention, and the deprecation of unused legacy features.
1 parent 74e1b2e commit 8c466dd

File tree

9 files changed

+1376
-1310
lines changed

9 files changed

+1376
-1310
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
find_package(Catch2 REQUIRED
2+
HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2")
13

24
file(GLOB TEST_PROGS "test*.cpp")
35
file(GLOB TEST_FILES *.osim *.xml *.sto *.mot)
46

57
OpenSimAddTests(
68
TESTPROGRAMS ${TEST_PROGS}
79
DATAFILES ${TEST_FILES}
8-
LINKLIBS osimTools
10+
LINKLIBS osimTools Catch2::Catch2WithMain
911
)

Applications/Forward/test/testForward.cpp

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,20 @@
2020
* See the License for the specific language governing permissions and *
2121
* limitations under the License. *
2222
* -------------------------------------------------------------------------- */
23-
// forward.cpp
24-
// author: Frank C. Anderson, Ajay Seth
2523

26-
// INCLUDE
2724
#include <OpenSim/Simulation/Control/Controller.h>
2825
#include <OpenSim/Simulation/Model/Model.h>
26+
#include <OpenSim/Simulation/Manager/Manager.h>
2927
#include <OpenSim/Tools/ForwardTool.h>
3028
#include <OpenSim/Auxiliary/auxiliaryTestFunctions.h>
31-
#include "SimTKmath.h"
29+
#include <OpenSim/Actuators/ModelFactory.h>
30+
31+
#include <catch2/catch_all.hpp>
3232

3333
using namespace OpenSim;
3434
using namespace std;
3535

36-
void testPendulum();
37-
void testPendulumExternalLoad();
38-
void testPendulumExternalLoadWithPointInGround();
39-
void testArm26();
40-
void testGait2354();
41-
void testGait2354WithController();
42-
void testGait2354WithControllerGUI();
43-
44-
45-
int main() {
46-
Object::renameType("Thelen2003Muscle", "Thelen2003Muscle_Deprecated");
47-
48-
SimTK_START_TEST("testForward");
49-
// test manager/integration process
50-
SimTK_SUBTEST(testPendulum);
51-
// test application of external loads point in pendulum
52-
SimTK_SUBTEST(testPendulumExternalLoad);
53-
// test application of external loads with point moving in ground
54-
SimTK_SUBTEST(testPendulumExternalLoadWithPointInGround);
55-
// now add computation of controls and generation of muscle forces
56-
SimTK_SUBTEST(testArm26);
57-
// controlled muscles and ground reactions forces
58-
SimTK_SUBTEST(testGait2354);
59-
// included additional controller
60-
SimTK_SUBTEST(testGait2354WithController);
61-
// implements steps GUI takes to provide a model
62-
SimTK_SUBTEST(testGait2354WithControllerGUI);
63-
SimTK_END_TEST();
64-
}
65-
66-
void testPendulum() {
36+
TEST_CASE("testPendulum") {
6737
ForwardTool forward("pendulum_Setup_Forward.xml");
6838
forward.run();
6939
Storage storage("Results/pendulum_states.sto");
@@ -86,8 +56,7 @@ void testPendulum() {
8656
ASSERT(previousTime == 1.0);
8757
}
8858

89-
90-
void testPendulumExternalLoad() {
59+
TEST_CASE("testPendulumExternalLoad") {
9160
ForwardTool forward("pendulum_ext_gravity_Setup_Forward.xml");
9261
forward.run();
9362
Storage results("Results/pendulum_ext_gravity_states.sto");
@@ -115,8 +84,7 @@ void testPendulumExternalLoad() {
11584
}
11685
}
11786

118-
119-
void testPendulumExternalLoadWithPointInGround() {
87+
TEST_CASE("testPendulumExternalLoadWithPointInGround") {
12088
ForwardTool forward("pendulum_ext_point_in_ground_Setup_Forward.xml");
12189
forward.run();
12290

@@ -143,8 +111,9 @@ void testPendulumExternalLoadWithPointInGround() {
143111
}
144112
}
145113

114+
TEST_CASE("testArm26") {
115+
Object::renameType("Thelen2003Muscle", "Thelen2003Muscle_Deprecated");
146116

147-
void testArm26() {
148117
ForwardTool forward("arm26_Setup_Forward.xml");
149118
forward.run();
150119

@@ -157,6 +126,7 @@ void testArm26() {
157126
Array<double> data;
158127
data.setSize(state->getSize());
159128
standard->getDataAtTime(time, state->getSize(), data);
129+
160130
for (int j = 0; j < state->getSize(); ++j) {
161131
stringstream message;
162132
message << "t=" << time <<" state# "<< j << " " << standard->getColumnLabels()[j+1] << " std=" << data[j] <<" computed=" << state->getData()[j] << endl;
@@ -179,8 +149,9 @@ void testArm26() {
179149
}
180150
}
181151

182-
void testGait2354()
183-
{
152+
TEST_CASE("testGait2354") {
153+
Object::renameType("Thelen2003Muscle", "Thelen2003Muscle_Deprecated");
154+
184155
ForwardTool forward("subject01_Setup_Forward.xml");
185156
forward.run();
186157
Storage results("Results/subject01_states.sto");
@@ -203,8 +174,9 @@ void testGait2354()
203174
__FILE__, __LINE__, "testGait2354 failed");
204175
}
205176

177+
TEST_CASE("testGait2354WithController") {
178+
Object::renameType("Thelen2003Muscle", "Thelen2003Muscle_Deprecated");
206179

207-
void testGait2354WithController() {
208180
ForwardTool forward("subject01_Setup_Forward_Controller.xml");
209181
forward.run();
210182
Storage results("ResultsCorrectionController/subject01_states.sto");
@@ -226,7 +198,8 @@ void testGait2354WithController() {
226198
__FILE__, __LINE__, "testGait2354WithController failed");
227199
}
228200

229-
void testGait2354WithControllerGUI() {
201+
TEST_CASE("testGait2354WithControllerGUI") {
202+
Object::renameType("Thelen2003Muscle", "Thelen2003Muscle_Deprecated");
230203

231204
// The following lines are the steps from ForwardToolModel.java that
232205
// associates the a previous (orgiModel) model with the ForwardTool
@@ -259,3 +232,34 @@ void testGait2354WithControllerGUI() {
259232

260233
delete model;
261234
}
235+
236+
TEST_CASE("testForwardToolVersusManager") {
237+
Model model = ModelFactory::createNLinkPendulum(3);
238+
SimTK::State state = model.initSystem();
239+
240+
Manager manager(model);
241+
manager.setIntegratorMinimumStepSize(1e-8);
242+
manager.setIntegratorMaximumStepSize(10.0);
243+
manager.setIntegratorAccuracy(1e-4);
244+
manager.initialize(state);
245+
manager.integrate(1.0);
246+
manager.getStateStorage().print(
247+
"testForwardToolVersusManager_manager_states.sto");
248+
249+
ForwardTool forward;
250+
forward.setModel(model);
251+
forward.setName("testForwardToolVersusManager_forward");
252+
forward.setMinDT(1e-8);
253+
forward.setMaxDT(10.0);
254+
forward.setErrorTolerance(1e-4);
255+
forward.run();
256+
257+
Storage managerStates("testForwardToolVersusManager_manager_states.sto");
258+
Storage forwardStates("testForwardToolVersusManager_forward_states.sto");
259+
CHECK(managerStates.getSize() == forwardStates.getSize());
260+
261+
std::vector<double> rms_tols(state.getNY(), SimTK::SqrtEps);
262+
CHECK_STORAGE_AGAINST_STANDARD(forwardStates, managerStates, rms_tols,
263+
__FILE__, __LINE__, "testForwardToolVersusManager failed");
264+
265+
}

0 commit comments

Comments
 (0)