Page 1 of 1

Missing Parameters when Adding Ligaments / Wrap Sphere

Posted: Mon Sep 09, 2019 5:19 pm
by aafox
Hi All,

I have attempted running some code (via both Matlab and Python) to add a ligament to a models forceset. This works, however not all of the parameters for the ligament end up written in the model - only the resting length and PCSA force parameters go across. This is despite additional information, such as a spline function, seemingly being present within the object in Matlab/Python (i.e. when running the '.dump()' command the information is there). I have been adding the ligament to the model using the '.adoptAndAppend()' and '.finalizeConnections()' command to the forceset, which obviously works but doesn't take across all the parameters when printing the model. Has anyone had a similar experience or any advice in changing the approach to get all of the parameters across?

One additional problem I've also come across in this process is in he creation of a wrap sphere, there doesn't appear to be a command to set the radius of the sphere programatically (i.e. there is no '.setRadius()' or '.set_radius()' type commands for this class). When added to the model this parameter defaults to a -1 and can be changed manually in the printed model file. Is there such a method to do this in Matlab/Python?

Thanks,

Aaron

Re: Missing Parameters when Adding Ligaments / Wrap Sphere

Posted: Tue Sep 10, 2019 12:03 am
by mitkof6
Hi,

In this case you can navigate the source code to check there are some bugs in the internal implementation. For the ligament everything seems ok.

https://github.com/opensim-org/opensim- ... ment.h#L59

The above are the properties of the class, which you can set. These are macros that create setters and getters for the properties. They use the underscore and not the camel case convention. Therefore, to change the parameters of the ligament you do something like:

Code: Select all

ligament = Ligament()
ligament.set_rest_length(0.2)
ligament.set_pcsa_force(100)
function = GCVSpline(3, 10, X, Y)
ligament.set_force_length_curve(function)
model.addForce(ligament)


For the second issue, sometimes the code is not updated, therefore the old convention is used

https://github.com/opensim-org/opensim- ... here.h#L53

For you to update you have to access the property:

Code: Select all

sphere.updPropertyByName("radius").updValue() = 0.1
or setValue, I am not sure what is exposed for the bindings

Re: Missing Parameters when Adding Ligaments / Wrap Sphere

Posted: Thu Sep 19, 2019 4:06 am
by aafox
Hi Dimitar (and others),

As a follow-up question to this, do you know why the set parameters would not print to file/save in the model? I can create the ligament class and set all of the parameters (i.e. force, resting length, force function etc. etc.), and when I view (i.e. .dump()) the class object in Python all of the parameters are there. Even when I add it to the model and .dump() this all of these parameters are there. As soon as I either (1) print the model to file; or (2) print the ligament object to XML - the majority of the parameters disappear (I think only resting length and PCSA force is left). I haven't come across this weird behaviour before.

Any ideas?

Thanks,

Aaron

Re: Missing Parameters when Adding Ligaments / Wrap Sphere

Posted: Thu Sep 19, 2019 10:08 am
by aymanh
Hi Aaron,

The key maybe the actual values assigned to the properties being written. The code tries to avoid writing values that are equal to the defaults in the code in order to reduce the file size and to give class writers the opportunity to change the defaults if needed. Please compare the values you set to the defaults to see if this is the case.

-Ayman

Re: Missing Parameters when Adding Ligaments / Wrap Sphere

Posted: Thu Sep 19, 2019 5:33 pm
by aafox
Hi Ayman,

I'm not sure this was the case, as I changed a number of things (i.e. path points added, force function changed etc.) - and these do not match the default values.

I've developed a lazy work-around in writing the dumped model text to string and passing it to an XML parser in Python. This has allowed me to write and edit the parameters that weren't showing when using the internal print to XML function. An imperfect solution, but one that works nonetheless.

Thanks,

Aaron