20
20
* See the License for the specific language governing permissions and *
21
21
* limitations under the License. *
22
22
* -------------------------------------------------------------------------- */
23
- // forward.cpp
24
- // author: Frank C. Anderson, Ajay Seth
25
23
26
- // INCLUDE
27
24
#include < OpenSim/Simulation/Control/Controller.h>
28
25
#include < OpenSim/Simulation/Model/Model.h>
26
+ #include < OpenSim/Simulation/Manager/Manager.h>
29
27
#include < OpenSim/Tools/ForwardTool.h>
30
28
#include < OpenSim/Auxiliary/auxiliaryTestFunctions.h>
31
- #include " SimTKmath.h"
29
+ #include < OpenSim/Actuators/ModelFactory.h>
30
+
31
+ #include < catch2/catch_all.hpp>
32
32
33
33
using namespace OpenSim ;
34
34
using namespace std ;
35
35
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" ) {
67
37
ForwardTool forward (" pendulum_Setup_Forward.xml" );
68
38
forward.run ();
69
39
Storage storage (" Results/pendulum_states.sto" );
@@ -86,8 +56,7 @@ void testPendulum() {
86
56
ASSERT (previousTime == 1.0 );
87
57
}
88
58
89
-
90
- void testPendulumExternalLoad () {
59
+ TEST_CASE (" testPendulumExternalLoad" ) {
91
60
ForwardTool forward (" pendulum_ext_gravity_Setup_Forward.xml" );
92
61
forward.run ();
93
62
Storage results (" Results/pendulum_ext_gravity_states.sto" );
@@ -115,8 +84,7 @@ void testPendulumExternalLoad() {
115
84
}
116
85
}
117
86
118
-
119
- void testPendulumExternalLoadWithPointInGround () {
87
+ TEST_CASE (" testPendulumExternalLoadWithPointInGround" ) {
120
88
ForwardTool forward (" pendulum_ext_point_in_ground_Setup_Forward.xml" );
121
89
forward.run ();
122
90
@@ -143,8 +111,9 @@ void testPendulumExternalLoadWithPointInGround() {
143
111
}
144
112
}
145
113
114
+ TEST_CASE (" testArm26" ) {
115
+ Object::renameType (" Thelen2003Muscle" , " Thelen2003Muscle_Deprecated" );
146
116
147
- void testArm26 () {
148
117
ForwardTool forward (" arm26_Setup_Forward.xml" );
149
118
forward.run ();
150
119
@@ -157,6 +126,7 @@ void testArm26() {
157
126
Array<double > data;
158
127
data.setSize (state->getSize ());
159
128
standard->getDataAtTime (time, state->getSize (), data);
129
+
160
130
for (int j = 0 ; j < state->getSize (); ++j) {
161
131
stringstream message;
162
132
message << " t=" << time <<" state# " << j << " " << standard->getColumnLabels ()[j+1 ] << " std=" << data[j] <<" computed=" << state->getData ()[j] << endl;
@@ -179,8 +149,9 @@ void testArm26() {
179
149
}
180
150
}
181
151
182
- void testGait2354 ()
183
- {
152
+ TEST_CASE (" testGait2354" ) {
153
+ Object::renameType (" Thelen2003Muscle" , " Thelen2003Muscle_Deprecated" );
154
+
184
155
ForwardTool forward (" subject01_Setup_Forward.xml" );
185
156
forward.run ();
186
157
Storage results (" Results/subject01_states.sto" );
@@ -203,8 +174,9 @@ void testGait2354()
203
174
__FILE__, __LINE__, " testGait2354 failed" );
204
175
}
205
176
177
+ TEST_CASE (" testGait2354WithController" ) {
178
+ Object::renameType (" Thelen2003Muscle" , " Thelen2003Muscle_Deprecated" );
206
179
207
- void testGait2354WithController () {
208
180
ForwardTool forward (" subject01_Setup_Forward_Controller.xml" );
209
181
forward.run ();
210
182
Storage results (" ResultsCorrectionController/subject01_states.sto" );
@@ -226,7 +198,8 @@ void testGait2354WithController() {
226
198
__FILE__, __LINE__, " testGait2354WithController failed" );
227
199
}
228
200
229
- void testGait2354WithControllerGUI () {
201
+ TEST_CASE (" testGait2354WithControllerGUI" ) {
202
+ Object::renameType (" Thelen2003Muscle" , " Thelen2003Muscle_Deprecated" );
230
203
231
204
// The following lines are the steps from ForwardToolModel.java that
232
205
// associates the a previous (orgiModel) model with the ForwardTool
@@ -259,3 +232,34 @@ void testGait2354WithControllerGUI() {
259
232
260
233
delete model;
261
234
}
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