Speed up my Simulation using OpenSim-Matlab C++ Mex Interface

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Giuseppe Scaccuto
Posts: 20
Joined: Mon Sep 24, 2018 9:32 am

Speed up my Simulation using OpenSim-Matlab C++ Mex Interface

Post by Giuseppe Scaccuto » Thu Jan 10, 2019 9:00 am

Dear all,
I'm using this interface to create a forward simulation in Simulink for setting muscle excitations and retrieving some output information.

https://simtk.org/projects/opensimmatlab

I used an upper limb .osim model with 6 millard muscles and 2 DoF.

I setup a Manager object with Runge-Kutta Integrator and an accuracy value by 0.1 while, in Simulink settings, I have a fixed step time and an auto solver method, left untouched (I think Manager overwrite them). Then I launch my simulation (in Simulink) for a total time by 2 secs with a step time by 0.04 secs (automatically set by Simulink). It takes over 10 mins to complete so I want to ask you if there was any setting to configure to speed up this process.

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Speed up my Simulation using OpenSim-Matlab C++ Mex Interface

Post by Dimitar Stanev » Fri Jan 11, 2019 2:02 am

an accuracy value by 0.1
I am not sure if the accuracy should be so large. Please note that the accuracy option is different from the step size.

I suppose you are using the MoBL upper limb model. The reason why the simulation is slow is due to the model's constraints and muscles. It is possible that the muscles are not operating in their physiological ranges. You can further try to simplify the model by simplifying the shoulder model.

User avatar
Giuseppe Scaccuto
Posts: 20
Joined: Mon Sep 24, 2018 9:32 am

Re: Speed up my Simulation using OpenSim-Matlab C++ Mex Interface

Post by Giuseppe Scaccuto » Fri Jan 11, 2019 11:05 am

Yes, I'm using a modified version of the MoBL upper limb model with only the following muscles:
DELT3
PECM1
TRIlong
TRIlat
BICshort
BRA

Muscle parameters are taken from the original paper of the model: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4282829/

The unique parameter I changed is the contraction velocity that I set equal to 10.

I followed your tips:
-I changed all joints to weld type except for 1 shoulder joint (custom type), 1 elbow joint (pin type)
-I removed all constraints
-I left only 2 DoF (elv_angle, elbow_flexion)

Here attached the .osim file.

It seems that changes have no effect on total simulation time.
It is possible that the muscles are not operating in their physiological ranges.
How can I check if muscles are operating in their physiological ranges?
Attachments
ArmSix_semplified3.osim
(279.03 KiB) Downloaded 91 times

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Speed up my Simulation using OpenSim-Matlab C++ Mex Interface

Post by Dimitar Stanev » Fri Jan 11, 2019 1:09 pm

In this case, you can try to increase the step size to 0.1 (Simulink) by using a fix time step integrator.

There is one drawback of using Simulink and OpenSim in an iterative manner (as provided by this implementation): between consequent steps the value of the muscle activations as assigned by Simulink is kept constant (hold-on). Consequently, if you take large time steps in Simulink, then the input will be an approximation of the actual input. Please note that when you ask OpenSim to take a step of dt, then multiple smaller steps are performed in order to satisfy the accuracy tolerance of the integrator (adaptive time stepping), because Simulink and OpenSim use their own separate integration schemes.

In other worlds, if you want to increase the simulation time, you must increase the step size of the Simulink integrator to reduce the frequency of advancing the state in OpenSim.

User avatar
Giuseppe Scaccuto
Posts: 20
Joined: Mon Sep 24, 2018 9:32 am

Re: Speed up my Simulation using OpenSim-Matlab C++ Mex Interface

Post by Giuseppe Scaccuto » Mon Jan 28, 2019 3:36 am

Ok, I set up Simulink step to a fixed value (0.01) and I forced OpenSim to use same step size and make it constant with an integrator accuracy of 0.1.

Now my simulation results have a fixed number of steps and it takes less time.

I have another question. When I perform some test on that model, I notice something strange in the plot of fiberlength values on the Pectoral muscle in Simulink while I don't see it in OpenSim. Here's the screenshot.

Immagin.png
Immagin.png (41.55 KiB) Viewed 461 times

There's a problem with the accuracy value or anything else?

Thanks for your help.

POST REPLY