Make F0 vary with time to simulate muscle fatigue

Hello Anybody,

My name is Lin, and I’m a researcher at The Hong Kong Polytechnic University. I’m trying to simulate muscle fatigue by making the muscle strength parameter (F0) decrease over time following a predefined curve.

I tried in a simple model by directly writing F0=1000-t:
AnyViaPointMuscle Quadriceps = {
AnyMuscleModel Model = {
F0 = 1000-t;
};
AnyRefFrame &origin = .Femur.QuadOri;
AnyRefFrame &insertion = .Patella.Quad;
AnyDrawMuscle drw = {};
};

but the model cannot load and I get:

ERROR(SCR.EXP0) : Knee_origin.any(195) : F0 : Error in evaluation. Please refer to the following error messages for details ...
ERROR(SCR.EXP10) : Knee_origin.any(195) : Model.F0 : Expression evaluation failed at moment 'DesignVar' :
Knee_origin.any(194) : Model.t : argument will not be ready for evaluation until moment 'TimeVar'
Model loading skipped

From the forum I learned that AnyFunExMonoPy could be used.
So I wrote a simple Python function in f0_function.py:

def muscle_force(context,t):
return 100 - t

And made change in AnyScript:

AnyFunEx PyForce = {

AnyFloat Return = 0;
AnyFunExMonoPy muscle_force = {
ModuleFile = "f0_function.py";
ArgList = {
AnyFloat t = 0;
};
};
};
AnyViaPointMuscle Quadriceps = {
AnyMuscleModel Model = {
F0 = Main.MyModel.PyForce(Main.MyModel.Quadriceps.t);
};

  AnyRefFrame &origin = .Femur.QuadOri;
  AnyRefFrame &insertion = .Patella.Quad;
  AnyDrawMuscle drw = {};
};

Unfortunately, this still gives me an error:
ERROR(SCR.EXP0) : Knee.any(206) : F0 : Error in evaluation. Please refer to the following error messages for details ...
ERROR(SCR.EXP10) : Knee.any(206) : Model.F0 : Expression evaluation failed at moment 'DesignVar' :
Knee.any(204) : Quadriceps.t : argument will not be ready for evaluation until moment 'TimeVar'

Anybody also provides built-in fatigue models (AnyFatigueModelM and AnyFatigueModel3CM), but they don’t allow me to impose a specific fatigue curve.
When I try to add time as a parameter, I still not work.

Question: What is the correct way to make F0 time-dependent in Anybody? Ideally, I’d like to prescribe a custom function of time to represent fatigue.
Any hints, explanations, or sample code would be greatly appreciated. If anyone could kindly point me in the right direction, I would be truly grateful.

Lin

Hi Lin

Welcome to the AnyScript forum!

You say you have a predefined curve of the muscle strength. And you are interested in time dependence of muscle strength.

The error that you are seeing is due to the use of AnyMuscleModel, which expects F0 to be a constant. You can use AnyMuscleModelUsr1 to define your own function for muscle strength, which can also be a function of time. So, you would be able to implement your function within AnyScript without needing the Python hook. Further, if you have predefined values of strength, you can create an interpolation function using AnyFunInterpol and AnyInputFile. Please see the reference manual for more information on these classes and demo examples.

Please also see the tutorial on muscle modeling.

I hope that helps.

Best regards,
Dave

Hi Dave,

I followed your suggestion and used AnyMuscleModelUsr1 to define the muscle strength as a function of time, which successfully resolved the issue. Thank you for your helpful response!

Best regards,
Lin