# hysteretic ligaments behavior

Good evening,

I´m contriving a knee model, with this kind of ligaments stress behavior:

Nevertheless, I would give to my model an hysteretic behavior, in order to obtain this kind of trade in the ligaments forces I should consider the elongation velocity of the ligaments, to simulate the presence of a damper. In this way when the ligament will pass from an elongation to a shortening it won´t follow the same curve. To do this I should use the following mathematical expression:

vel = (lin.Pos(t)-lin.Pos(t-Dt))/Dt

How I could implement something like that in AnyBody?

Thanks,
Best regards,
Giovanni

Good morning Anybody´s team,

I would use an external matlab function that takes as input the length of the ligaments and gives as output the Forces that the ligament should trasmit. is it possible? How I could improve something like this?

As ligaments model I´m using the AnyForce class.

Thanks,
best regards,
Giovanni

Hi,
In order to obtain what I have described until now, could I use some .dll functions?

Giovanni

Hi Giovanni,

Could you remind us what was wrong with using ‘F=k*.lin.Pos[0]+c*.lin.Vel[0]’?

Best regards,
Pavel

And regarding Matlab - it is not possible to use a Matlab function, but only Python and C++.

Please check the reference manual for AnyFunEx - a demo file has an example of how to use it.

Regards,
Pavel

Hi Pavel,

Unfortunately I cannot use F=klin.Pos[0]+clin.Vel[0], because during the Inverse Dynamics the program doesn’t calculate the velocity, but only the length of my ligaments (lin.Pos)!!

Best regards,
Giovanni

Hi pavel,

Could I obtain what i have described in the first two posts utilizing a Python function?

Thanks,
best regards,
Giovanni

Hi Giovanni,

It might be possible, but we have not tried it ourselves.
You need to output the lin.Pos component position into an output file (it will always happen for the computed time step), parse it using a Python function that will take lin.Pos as an input and will be parsing the last value from the output file. Please be aware that you would need to think how to handle the very first time step too.

Please try it on a simple example first.

Secondly, it may not be correct, since you’re using a velocity dependent value in the analysis, which assumes the velocities to be zero. Most likely there will be a convergence problem or it will take a long time.

So, please, check whether it makes sense on a simple example first.

Regards,
Pavel

Hi Pavel,

Is it enough to install the 2.7.3 version of Python or I should check for others settings changes of Anybody package?

Thanks,
Best regards,
Giovanni

Hi Giovanni,

I use PythonXY.

Regards,
Pavel

Hi Pavel,

The Anybody when I run the simple class example says me that AnyBody.Python extention module is not installed. I have the 5.3 Anybody’s version installed on my computer, so what should I do??

Thanks,
Very many regards,
Giovanni

Hi Giovanni,

Did you install PythonXY? Did you try to save the simple model somewhere or do you use it from [InstallationFolder]\Documentation\AnyScriptReference\demo\ClassExamples? Supposedly it should just work if you’re looking at the right one.

Please install PythonXY and make sure that it is being used if you have not done that.

Pavel

Hi Pavel,

Thanks for your last help, Now using Python(x,y) AnyBody is running. Nevertheless I have another problem, I´m using this function of Python to calculate and save the velocity of the ligament ( with the pickleACL1.txt file I´m saving the length of ligaments at previous step ):

``````import pickle
def doit(context, x0, x1):

inFile = open('pickleACL1.txt','rb')
inFile.close()
if x1==0:
position = x0[0]
tempo = 0
else:
tempo = 0
position = x0[0]
tempo = tempo + 0.0537

if tempo==0:
vel=0
else:

vel=(position-posizione)

outFile = open('pickleACL1.txt','wb')
pickle.dump(position,outFile)
outFile.close()
t = (vel,posizione)
return t

``````

This is linked with the following AnyBody request:

``````
[SIZE=3]AnyForce[/SIZE] ACL1 =
{
[SIZE=3]AnyKinPLine[/SIZE] lin =
{
[SIZE=3]AnyRefNode[/SIZE] &Ori = Main.HumanModel.BodyModel.Right.Leg.Seg.Thigh.CruciatumAnterior1;
[SIZE=3]AnyRefNode[/SIZE] &Ins = Main.HumanModel.BodyModel.Right.Leg.Seg.Shank.CruciatumAnterior1;
[SIZE=3]AnyDrawPLine[/SIZE] drw =
{
Thickness = 0.0019;
RGB = {1,0,0};
};
};
[SIZE=3]AnyFloat[/SIZE] Dt = div (Main.Study.tEnd, Main.Study.nStep) ;
[SIZE=3]AnyFloat[/SIZE] i = div(Main.Study.t,Dt);
[SIZE=3]AnyVar[/SIZE] CSA = 0.000070*0.24;
[SIZE=3]AnyVar[/SIZE] eps0 = 0.02;
[SIZE=3]AnyVar[/SIZE] L0 = 0.03399856/(1+eps0);
[SIZE=3]AnyFloat[/SIZE] eps_a = (lin.Pos - L0)/L0*100;
[SIZE=3]AnyFloat[/SIZE] a = lin.Pos - L0;
[SIZE=3]AnyFloat[/SIZE] eps_e = (200000 * CSA+13);
[SIZE=3]AnyFloat[/SIZE] eps_h = (200000 * CSA+25);
[SIZE=3]AnyFloat[/SIZE] eps_r = (200000 * CSA+29);

[SIZE=3]AnyFunEx[/SIZE] FunPEx =
{
[SIZE=3]AnyVector[/SIZE] Return = {0,0};
[SIZE=3]AnyFunExMonoPy[/SIZE] doit =
{
ModuleFile = "AnyFunExACL1.py";

ArgList =
{
[SIZE=3]AnyVector[/SIZE] I = {0,0,0,0};
[SIZE=3]AnyFloat[/SIZE] Fe = 0.0;
};
};
};
[SIZE=3]AnyFunEx[/SIZE]& Fe = FunPEx;
[SIZE=3]AnyFloat[/SIZE] S2 = FunPEx({lin.Pos[0],CSA,Dt,L0}, i);

[SIZE=3][/SIZE]
[SIZE=3]AnyFloat[/SIZE] Length = 0.035^2/L0^2;
[SIZE=3][/SIZE][SIZE=3]AnyFloat[/SIZE][SIZE=3] [/SIZE]c_vog[SIZE=3] [/SIZE]=[SIZE=3] [/SIZE]2.2e8*[SIZE=3] [/SIZE]CSA[SIZE=3] [/SIZE]*[SIZE=3] [/SIZE]eps_a/Length;
[SIZE=3][/SIZE][SIZE=3]AnyFloat[/SIZE][SIZE=3] [/SIZE]c_max[SIZE=3] [/SIZE]=[SIZE=3] [/SIZE]c_vog;
[SIZE=3][/SIZE][SIZE=3]AnyFloat[/SIZE][SIZE=3] [/SIZE]damp[SIZE=3] [/SIZE]=[SIZE=3] [/SIZE]c_vog*0.5;
[SIZE=3]AnyFloat[/SIZE] h = iffun(gteqfun(eps_a[0],0.0),1.0,0.0);
[SIZE=3][/SIZE][SIZE=3]AnyFloat[/SIZE][SIZE=3] [/SIZE]v[SIZE=3] [/SIZE]=[SIZE=3] [/SIZE]S2[0]/Dt;
[SIZE=3][/SIZE][SIZE=3]AnyFloat[/SIZE][SIZE=3] [/SIZE]F_I[SIZE=3] [/SIZE]=[SIZE=3] [/SIZE]mult(c_max,a)[SIZE=3] [/SIZE]+[SIZE=3] [/SIZE]mult(damp,v);
F = F_I[0];
};

``````

I haven´t understood why with the kinematics, the Python function, gives me right values, but when I use the Inverse dynamics the function save wrong ligaments lengths!!!
Why the function works differently between kinematics and Inverse dynamics? Should AnyBody wait for the function answer before continue???

Thanks,
best regards,
Giovanni

Hi Giovanni,

If this analysis is using FDK - then kinematic changes and you get new values. I am not quite sure what has to be the right values. I recommend to use a very simple example with 1dof to check your Python code.

Regards,
Pavel