musculotendon.py 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. """Implementations of musculotendon models.
  2. Musculotendon models are a critical component of biomechanical models, one that
  3. differentiates them from pure multibody systems. Musculotendon models produce a
  4. force dependent on their level of activation, their length, and their
  5. extension velocity. Length- and extension velocity-dependent force production
  6. are governed by force-length and force-velocity characteristics.
  7. These are normalized functions that are dependent on the musculotendon's state
  8. and are specific to a given musculotendon model.
  9. """
  10. from abc import abstractmethod
  11. from enum import IntEnum, unique
  12. from sympy.core.numbers import Float, Integer
  13. from sympy.core.symbol import Symbol, symbols
  14. from sympy.functions.elementary.miscellaneous import sqrt
  15. from sympy.functions.elementary.trigonometric import cos, sin
  16. from sympy.matrices.dense import MutableDenseMatrix as Matrix, diag, eye, zeros
  17. from sympy.physics.biomechanics.activation import ActivationBase
  18. from sympy.physics.biomechanics.curve import (
  19. CharacteristicCurveCollection,
  20. FiberForceLengthActiveDeGroote2016,
  21. FiberForceLengthPassiveDeGroote2016,
  22. FiberForceLengthPassiveInverseDeGroote2016,
  23. FiberForceVelocityDeGroote2016,
  24. FiberForceVelocityInverseDeGroote2016,
  25. TendonForceLengthDeGroote2016,
  26. TendonForceLengthInverseDeGroote2016,
  27. )
  28. from sympy.physics.biomechanics._mixin import _NamedMixin
  29. from sympy.physics.mechanics.actuator import ForceActuator
  30. from sympy.physics.vector.functions import dynamicsymbols
  31. __all__ = [
  32. 'MusculotendonBase',
  33. 'MusculotendonDeGroote2016',
  34. 'MusculotendonFormulation',
  35. ]
  36. @unique
  37. class MusculotendonFormulation(IntEnum):
  38. """Enumeration of types of musculotendon dynamics formulations.
  39. Explanation
  40. ===========
  41. An (integer) enumeration is used as it allows for clearer selection of the
  42. different formulations of musculotendon dynamics.
  43. Members
  44. =======
  45. RIGID_TENDON : 0
  46. A rigid tendon model.
  47. FIBER_LENGTH_EXPLICIT : 1
  48. An explicit elastic tendon model with the muscle fiber length (l_M) as
  49. the state variable.
  50. TENDON_FORCE_EXPLICIT : 2
  51. An explicit elastic tendon model with the tendon force (F_T) as the
  52. state variable.
  53. FIBER_LENGTH_IMPLICIT : 3
  54. An implicit elastic tendon model with the muscle fiber length (l_M) as
  55. the state variable and the muscle fiber velocity as an additional input
  56. variable.
  57. TENDON_FORCE_IMPLICIT : 4
  58. An implicit elastic tendon model with the tendon force (F_T) as the
  59. state variable as the muscle fiber velocity as an additional input
  60. variable.
  61. """
  62. RIGID_TENDON = 0
  63. FIBER_LENGTH_EXPLICIT = 1
  64. TENDON_FORCE_EXPLICIT = 2
  65. FIBER_LENGTH_IMPLICIT = 3
  66. TENDON_FORCE_IMPLICIT = 4
  67. def __str__(self):
  68. """Returns a string representation of the enumeration value.
  69. Notes
  70. =====
  71. This hard coding is required due to an incompatibility between the
  72. ``IntEnum`` implementations in Python 3.10 and Python 3.11
  73. (https://github.com/python/cpython/issues/84247). From Python 3.11
  74. onwards, the ``__str__`` method uses ``int.__str__``, whereas prior it
  75. used ``Enum.__str__``. Once Python 3.11 becomes the minimum version
  76. supported by SymPy, this method override can be removed.
  77. """
  78. return str(self.value)
  79. _DEFAULT_MUSCULOTENDON_FORMULATION = MusculotendonFormulation.RIGID_TENDON
  80. class MusculotendonBase(ForceActuator, _NamedMixin):
  81. r"""Abstract base class for all musculotendon classes to inherit from.
  82. Explanation
  83. ===========
  84. A musculotendon generates a contractile force based on its activation,
  85. length, and shortening velocity. This abstract base class is to be inherited
  86. by all musculotendon subclasses that implement different characteristic
  87. musculotendon curves. Characteristic musculotendon curves are required for
  88. the tendon force-length, passive fiber force-length, active fiber force-
  89. length, and fiber force-velocity relationships.
  90. Parameters
  91. ==========
  92. name : str
  93. The name identifier associated with the musculotendon. This name is used
  94. as a suffix when automatically generated symbols are instantiated. It
  95. must be a string of nonzero length.
  96. pathway : PathwayBase
  97. The pathway that the actuator follows. This must be an instance of a
  98. concrete subclass of ``PathwayBase``, e.g. ``LinearPathway``.
  99. activation_dynamics : ActivationBase
  100. The activation dynamics that will be modeled within the musculotendon.
  101. This must be an instance of a concrete subclass of ``ActivationBase``,
  102. e.g. ``FirstOrderActivationDeGroote2016``.
  103. musculotendon_dynamics : MusculotendonFormulation | int
  104. The formulation of musculotendon dynamics that should be used
  105. internally, i.e. rigid or elastic tendon model, the choice of
  106. musculotendon state etc. This must be a member of the integer
  107. enumeration ``MusculotendonFormulation`` or an integer that can be cast
  108. to a member. To use a rigid tendon formulation, set this to
  109. ``MusculotendonFormulation.RIGID_TENDON`` (or the integer value ``0``,
  110. which will be cast to the enumeration member). There are four possible
  111. formulations for an elastic tendon model. To use an explicit formulation
  112. with the fiber length as the state, set this to
  113. ``MusculotendonFormulation.FIBER_LENGTH_EXPLICIT`` (or the integer value
  114. ``1``). To use an explicit formulation with the tendon force as the
  115. state, set this to ``MusculotendonFormulation.TENDON_FORCE_EXPLICIT``
  116. (or the integer value ``2``). To use an implicit formulation with the
  117. fiber length as the state, set this to
  118. ``MusculotendonFormulation.FIBER_LENGTH_IMPLICIT`` (or the integer value
  119. ``3``). To use an implicit formulation with the tendon force as the
  120. state, set this to ``MusculotendonFormulation.TENDON_FORCE_IMPLICIT``
  121. (or the integer value ``4``). The default is
  122. ``MusculotendonFormulation.RIGID_TENDON``, which corresponds to a rigid
  123. tendon formulation.
  124. tendon_slack_length : Expr | None
  125. The length of the tendon when the musculotendon is in its unloaded
  126. state. In a rigid tendon model the tendon length is the tendon slack
  127. length. In all musculotendon models, tendon slack length is used to
  128. normalize tendon length to give
  129. :math:`\tilde{l}^T = \frac{l^T}{l^T_{slack}}`.
  130. peak_isometric_force : Expr | None
  131. The maximum force that the muscle fiber can produce when it is
  132. undergoing an isometric contraction (no lengthening velocity). In all
  133. musculotendon models, peak isometric force is used to normalized tendon
  134. and muscle fiber force to give
  135. :math:`\tilde{F}^T = \frac{F^T}{F^M_{max}}`.
  136. optimal_fiber_length : Expr | None
  137. The muscle fiber length at which the muscle fibers produce no passive
  138. force and their maximum active force. In all musculotendon models,
  139. optimal fiber length is used to normalize muscle fiber length to give
  140. :math:`\tilde{l}^M = \frac{l^M}{l^M_{opt}}`.
  141. maximal_fiber_velocity : Expr | None
  142. The fiber velocity at which, during muscle fiber shortening, the muscle
  143. fibers are unable to produce any active force. In all musculotendon
  144. models, maximal fiber velocity is used to normalize muscle fiber
  145. extension velocity to give :math:`\tilde{v}^M = \frac{v^M}{v^M_{max}}`.
  146. optimal_pennation_angle : Expr | None
  147. The pennation angle when muscle fiber length equals the optimal fiber
  148. length.
  149. fiber_damping_coefficient : Expr | None
  150. The coefficient of damping to be used in the damping element in the
  151. muscle fiber model.
  152. with_defaults : bool
  153. Whether ``with_defaults`` alternate constructors should be used when
  154. automatically constructing child classes. Default is ``False``.
  155. """
  156. def __init__(
  157. self,
  158. name,
  159. pathway,
  160. activation_dynamics,
  161. *,
  162. musculotendon_dynamics=_DEFAULT_MUSCULOTENDON_FORMULATION,
  163. tendon_slack_length=None,
  164. peak_isometric_force=None,
  165. optimal_fiber_length=None,
  166. maximal_fiber_velocity=None,
  167. optimal_pennation_angle=None,
  168. fiber_damping_coefficient=None,
  169. with_defaults=False,
  170. ):
  171. self.name = name
  172. # Supply a placeholder force to the super initializer, this will be
  173. # replaced later
  174. super().__init__(Symbol('F'), pathway)
  175. # Activation dynamics
  176. if not isinstance(activation_dynamics, ActivationBase):
  177. msg = (
  178. f'Can\'t set attribute `activation_dynamics` to '
  179. f'{activation_dynamics} as it must be of type '
  180. f'`ActivationBase`, not {type(activation_dynamics)}.'
  181. )
  182. raise TypeError(msg)
  183. self._activation_dynamics = activation_dynamics
  184. self._child_objects = (self._activation_dynamics, )
  185. # Constants
  186. if tendon_slack_length is not None:
  187. self._l_T_slack = tendon_slack_length
  188. else:
  189. self._l_T_slack = Symbol(f'l_T_slack_{self.name}')
  190. if peak_isometric_force is not None:
  191. self._F_M_max = peak_isometric_force
  192. else:
  193. self._F_M_max = Symbol(f'F_M_max_{self.name}')
  194. if optimal_fiber_length is not None:
  195. self._l_M_opt = optimal_fiber_length
  196. else:
  197. self._l_M_opt = Symbol(f'l_M_opt_{self.name}')
  198. if maximal_fiber_velocity is not None:
  199. self._v_M_max = maximal_fiber_velocity
  200. else:
  201. self._v_M_max = Symbol(f'v_M_max_{self.name}')
  202. if optimal_pennation_angle is not None:
  203. self._alpha_opt = optimal_pennation_angle
  204. else:
  205. self._alpha_opt = Symbol(f'alpha_opt_{self.name}')
  206. if fiber_damping_coefficient is not None:
  207. self._beta = fiber_damping_coefficient
  208. else:
  209. self._beta = Symbol(f'beta_{self.name}')
  210. # Musculotendon dynamics
  211. self._with_defaults = with_defaults
  212. if musculotendon_dynamics == MusculotendonFormulation.RIGID_TENDON:
  213. self._rigid_tendon_musculotendon_dynamics()
  214. elif musculotendon_dynamics == MusculotendonFormulation.FIBER_LENGTH_EXPLICIT:
  215. self._fiber_length_explicit_musculotendon_dynamics()
  216. elif musculotendon_dynamics == MusculotendonFormulation.TENDON_FORCE_EXPLICIT:
  217. self._tendon_force_explicit_musculotendon_dynamics()
  218. elif musculotendon_dynamics == MusculotendonFormulation.FIBER_LENGTH_IMPLICIT:
  219. self._fiber_length_implicit_musculotendon_dynamics()
  220. elif musculotendon_dynamics == MusculotendonFormulation.TENDON_FORCE_IMPLICIT:
  221. self._tendon_force_implicit_musculotendon_dynamics()
  222. else:
  223. msg = (
  224. f'Musculotendon dynamics {repr(musculotendon_dynamics)} '
  225. f'passed to `musculotendon_dynamics` was of type '
  226. f'{type(musculotendon_dynamics)}, must be '
  227. f'{MusculotendonFormulation}.'
  228. )
  229. raise TypeError(msg)
  230. self._musculotendon_dynamics = musculotendon_dynamics
  231. # Must override the placeholder value in `self._force` now that the
  232. # actual force has been calculated by
  233. # `self._<MUSCULOTENDON FORMULATION>_musculotendon_dynamics`.
  234. # Note that `self._force` assumes forces are expansile, musculotendon
  235. # forces are contractile hence the minus sign preceding `self._F_T`
  236. # (the tendon force).
  237. self._force = -self._F_T
  238. @classmethod
  239. def with_defaults(
  240. cls,
  241. name,
  242. pathway,
  243. activation_dynamics,
  244. *,
  245. musculotendon_dynamics=_DEFAULT_MUSCULOTENDON_FORMULATION,
  246. tendon_slack_length=None,
  247. peak_isometric_force=None,
  248. optimal_fiber_length=None,
  249. maximal_fiber_velocity=Float('10.0'),
  250. optimal_pennation_angle=Float('0.0'),
  251. fiber_damping_coefficient=Float('0.1'),
  252. ):
  253. r"""Recommended constructor that will use the published constants.
  254. Explanation
  255. ===========
  256. Returns a new instance of the musculotendon class using recommended
  257. values for ``v_M_max``, ``alpha_opt``, and ``beta``. The values are:
  258. :math:`v^M_{max} = 10`
  259. :math:`\alpha_{opt} = 0`
  260. :math:`\beta = \frac{1}{10}`
  261. The musculotendon curves are also instantiated using the constants from
  262. the original publication.
  263. Parameters
  264. ==========
  265. name : str
  266. The name identifier associated with the musculotendon. This name is
  267. used as a suffix when automatically generated symbols are
  268. instantiated. It must be a string of nonzero length.
  269. pathway : PathwayBase
  270. The pathway that the actuator follows. This must be an instance of a
  271. concrete subclass of ``PathwayBase``, e.g. ``LinearPathway``.
  272. activation_dynamics : ActivationBase
  273. The activation dynamics that will be modeled within the
  274. musculotendon. This must be an instance of a concrete subclass of
  275. ``ActivationBase``, e.g. ``FirstOrderActivationDeGroote2016``.
  276. musculotendon_dynamics : MusculotendonFormulation | int
  277. The formulation of musculotendon dynamics that should be used
  278. internally, i.e. rigid or elastic tendon model, the choice of
  279. musculotendon state etc. This must be a member of the integer
  280. enumeration ``MusculotendonFormulation`` or an integer that can be
  281. cast to a member. To use a rigid tendon formulation, set this to
  282. ``MusculotendonFormulation.RIGID_TENDON`` (or the integer value
  283. ``0``, which will be cast to the enumeration member). There are four
  284. possible formulations for an elastic tendon model. To use an
  285. explicit formulation with the fiber length as the state, set this to
  286. ``MusculotendonFormulation.FIBER_LENGTH_EXPLICIT`` (or the integer
  287. value ``1``). To use an explicit formulation with the tendon force
  288. as the state, set this to
  289. ``MusculotendonFormulation.TENDON_FORCE_EXPLICIT`` (or the integer
  290. value ``2``). To use an implicit formulation with the fiber length
  291. as the state, set this to
  292. ``MusculotendonFormulation.FIBER_LENGTH_IMPLICIT`` (or the integer
  293. value ``3``). To use an implicit formulation with the tendon force
  294. as the state, set this to
  295. ``MusculotendonFormulation.TENDON_FORCE_IMPLICIT`` (or the integer
  296. value ``4``). The default is
  297. ``MusculotendonFormulation.RIGID_TENDON``, which corresponds to a
  298. rigid tendon formulation.
  299. tendon_slack_length : Expr | None
  300. The length of the tendon when the musculotendon is in its unloaded
  301. state. In a rigid tendon model the tendon length is the tendon slack
  302. length. In all musculotendon models, tendon slack length is used to
  303. normalize tendon length to give
  304. :math:`\tilde{l}^T = \frac{l^T}{l^T_{slack}}`.
  305. peak_isometric_force : Expr | None
  306. The maximum force that the muscle fiber can produce when it is
  307. undergoing an isometric contraction (no lengthening velocity). In
  308. all musculotendon models, peak isometric force is used to normalized
  309. tendon and muscle fiber force to give
  310. :math:`\tilde{F}^T = \frac{F^T}{F^M_{max}}`.
  311. optimal_fiber_length : Expr | None
  312. The muscle fiber length at which the muscle fibers produce no
  313. passive force and their maximum active force. In all musculotendon
  314. models, optimal fiber length is used to normalize muscle fiber
  315. length to give :math:`\tilde{l}^M = \frac{l^M}{l^M_{opt}}`.
  316. maximal_fiber_velocity : Expr | None
  317. The fiber velocity at which, during muscle fiber shortening, the
  318. muscle fibers are unable to produce any active force. In all
  319. musculotendon models, maximal fiber velocity is used to normalize
  320. muscle fiber extension velocity to give
  321. :math:`\tilde{v}^M = \frac{v^M}{v^M_{max}}`.
  322. optimal_pennation_angle : Expr | None
  323. The pennation angle when muscle fiber length equals the optimal
  324. fiber length.
  325. fiber_damping_coefficient : Expr | None
  326. The coefficient of damping to be used in the damping element in the
  327. muscle fiber model.
  328. """
  329. return cls(
  330. name,
  331. pathway,
  332. activation_dynamics=activation_dynamics,
  333. musculotendon_dynamics=musculotendon_dynamics,
  334. tendon_slack_length=tendon_slack_length,
  335. peak_isometric_force=peak_isometric_force,
  336. optimal_fiber_length=optimal_fiber_length,
  337. maximal_fiber_velocity=maximal_fiber_velocity,
  338. optimal_pennation_angle=optimal_pennation_angle,
  339. fiber_damping_coefficient=fiber_damping_coefficient,
  340. with_defaults=True,
  341. )
  342. @abstractmethod
  343. def curves(cls):
  344. """Return a ``CharacteristicCurveCollection`` of the curves related to
  345. the specific model."""
  346. pass
  347. @property
  348. def tendon_slack_length(self):
  349. r"""Symbol or value corresponding to the tendon slack length constant.
  350. Explanation
  351. ===========
  352. The length of the tendon when the musculotendon is in its unloaded
  353. state. In a rigid tendon model the tendon length is the tendon slack
  354. length. In all musculotendon models, tendon slack length is used to
  355. normalize tendon length to give
  356. :math:`\tilde{l}^T = \frac{l^T}{l^T_{slack}}`.
  357. The alias ``l_T_slack`` can also be used to access the same attribute.
  358. """
  359. return self._l_T_slack
  360. @property
  361. def l_T_slack(self):
  362. r"""Symbol or value corresponding to the tendon slack length constant.
  363. Explanation
  364. ===========
  365. The length of the tendon when the musculotendon is in its unloaded
  366. state. In a rigid tendon model the tendon length is the tendon slack
  367. length. In all musculotendon models, tendon slack length is used to
  368. normalize tendon length to give
  369. :math:`\tilde{l}^T = \frac{l^T}{l^T_{slack}}`.
  370. The alias ``tendon_slack_length`` can also be used to access the same
  371. attribute.
  372. """
  373. return self._l_T_slack
  374. @property
  375. def peak_isometric_force(self):
  376. r"""Symbol or value corresponding to the peak isometric force constant.
  377. Explanation
  378. ===========
  379. The maximum force that the muscle fiber can produce when it is
  380. undergoing an isometric contraction (no lengthening velocity). In all
  381. musculotendon models, peak isometric force is used to normalized tendon
  382. and muscle fiber force to give
  383. :math:`\tilde{F}^T = \frac{F^T}{F^M_{max}}`.
  384. The alias ``F_M_max`` can also be used to access the same attribute.
  385. """
  386. return self._F_M_max
  387. @property
  388. def F_M_max(self):
  389. r"""Symbol or value corresponding to the peak isometric force constant.
  390. Explanation
  391. ===========
  392. The maximum force that the muscle fiber can produce when it is
  393. undergoing an isometric contraction (no lengthening velocity). In all
  394. musculotendon models, peak isometric force is used to normalized tendon
  395. and muscle fiber force to give
  396. :math:`\tilde{F}^T = \frac{F^T}{F^M_{max}}`.
  397. The alias ``peak_isometric_force`` can also be used to access the same
  398. attribute.
  399. """
  400. return self._F_M_max
  401. @property
  402. def optimal_fiber_length(self):
  403. r"""Symbol or value corresponding to the optimal fiber length constant.
  404. Explanation
  405. ===========
  406. The muscle fiber length at which the muscle fibers produce no passive
  407. force and their maximum active force. In all musculotendon models,
  408. optimal fiber length is used to normalize muscle fiber length to give
  409. :math:`\tilde{l}^M = \frac{l^M}{l^M_{opt}}`.
  410. The alias ``l_M_opt`` can also be used to access the same attribute.
  411. """
  412. return self._l_M_opt
  413. @property
  414. def l_M_opt(self):
  415. r"""Symbol or value corresponding to the optimal fiber length constant.
  416. Explanation
  417. ===========
  418. The muscle fiber length at which the muscle fibers produce no passive
  419. force and their maximum active force. In all musculotendon models,
  420. optimal fiber length is used to normalize muscle fiber length to give
  421. :math:`\tilde{l}^M = \frac{l^M}{l^M_{opt}}`.
  422. The alias ``optimal_fiber_length`` can also be used to access the same
  423. attribute.
  424. """
  425. return self._l_M_opt
  426. @property
  427. def maximal_fiber_velocity(self):
  428. r"""Symbol or value corresponding to the maximal fiber velocity constant.
  429. Explanation
  430. ===========
  431. The fiber velocity at which, during muscle fiber shortening, the muscle
  432. fibers are unable to produce any active force. In all musculotendon
  433. models, maximal fiber velocity is used to normalize muscle fiber
  434. extension velocity to give :math:`\tilde{v}^M = \frac{v^M}{v^M_{max}}`.
  435. The alias ``v_M_max`` can also be used to access the same attribute.
  436. """
  437. return self._v_M_max
  438. @property
  439. def v_M_max(self):
  440. r"""Symbol or value corresponding to the maximal fiber velocity constant.
  441. Explanation
  442. ===========
  443. The fiber velocity at which, during muscle fiber shortening, the muscle
  444. fibers are unable to produce any active force. In all musculotendon
  445. models, maximal fiber velocity is used to normalize muscle fiber
  446. extension velocity to give :math:`\tilde{v}^M = \frac{v^M}{v^M_{max}}`.
  447. The alias ``maximal_fiber_velocity`` can also be used to access the same
  448. attribute.
  449. """
  450. return self._v_M_max
  451. @property
  452. def optimal_pennation_angle(self):
  453. """Symbol or value corresponding to the optimal pennation angle
  454. constant.
  455. Explanation
  456. ===========
  457. The pennation angle when muscle fiber length equals the optimal fiber
  458. length.
  459. The alias ``alpha_opt`` can also be used to access the same attribute.
  460. """
  461. return self._alpha_opt
  462. @property
  463. def alpha_opt(self):
  464. """Symbol or value corresponding to the optimal pennation angle
  465. constant.
  466. Explanation
  467. ===========
  468. The pennation angle when muscle fiber length equals the optimal fiber
  469. length.
  470. The alias ``optimal_pennation_angle`` can also be used to access the
  471. same attribute.
  472. """
  473. return self._alpha_opt
  474. @property
  475. def fiber_damping_coefficient(self):
  476. """Symbol or value corresponding to the fiber damping coefficient
  477. constant.
  478. Explanation
  479. ===========
  480. The coefficient of damping to be used in the damping element in the
  481. muscle fiber model.
  482. The alias ``beta`` can also be used to access the same attribute.
  483. """
  484. return self._beta
  485. @property
  486. def beta(self):
  487. """Symbol or value corresponding to the fiber damping coefficient
  488. constant.
  489. Explanation
  490. ===========
  491. The coefficient of damping to be used in the damping element in the
  492. muscle fiber model.
  493. The alias ``fiber_damping_coefficient`` can also be used to access the
  494. same attribute.
  495. """
  496. return self._beta
  497. @property
  498. def activation_dynamics(self):
  499. """Activation dynamics model governing this musculotendon's activation.
  500. Explanation
  501. ===========
  502. Returns the instance of a subclass of ``ActivationBase`` that governs
  503. the relationship between excitation and activation that is used to
  504. represent the activation dynamics of this musculotendon.
  505. """
  506. return self._activation_dynamics
  507. @property
  508. def excitation(self):
  509. """Dynamic symbol representing excitation.
  510. Explanation
  511. ===========
  512. The alias ``e`` can also be used to access the same attribute.
  513. """
  514. return self._activation_dynamics._e
  515. @property
  516. def e(self):
  517. """Dynamic symbol representing excitation.
  518. Explanation
  519. ===========
  520. The alias ``excitation`` can also be used to access the same attribute.
  521. """
  522. return self._activation_dynamics._e
  523. @property
  524. def activation(self):
  525. """Dynamic symbol representing activation.
  526. Explanation
  527. ===========
  528. The alias ``a`` can also be used to access the same attribute.
  529. """
  530. return self._activation_dynamics._a
  531. @property
  532. def a(self):
  533. """Dynamic symbol representing activation.
  534. Explanation
  535. ===========
  536. The alias ``activation`` can also be used to access the same attribute.
  537. """
  538. return self._activation_dynamics._a
  539. @property
  540. def musculotendon_dynamics(self):
  541. """The choice of rigid or type of elastic tendon musculotendon dynamics.
  542. Explanation
  543. ===========
  544. The formulation of musculotendon dynamics that should be used
  545. internally, i.e. rigid or elastic tendon model, the choice of
  546. musculotendon state etc. This must be a member of the integer
  547. enumeration ``MusculotendonFormulation`` or an integer that can be cast
  548. to a member. To use a rigid tendon formulation, set this to
  549. ``MusculotendonFormulation.RIGID_TENDON`` (or the integer value ``0``,
  550. which will be cast to the enumeration member). There are four possible
  551. formulations for an elastic tendon model. To use an explicit formulation
  552. with the fiber length as the state, set this to
  553. ``MusculotendonFormulation.FIBER_LENGTH_EXPLICIT`` (or the integer value
  554. ``1``). To use an explicit formulation with the tendon force as the
  555. state, set this to ``MusculotendonFormulation.TENDON_FORCE_EXPLICIT``
  556. (or the integer value ``2``). To use an implicit formulation with the
  557. fiber length as the state, set this to
  558. ``MusculotendonFormulation.FIBER_LENGTH_IMPLICIT`` (or the integer value
  559. ``3``). To use an implicit formulation with the tendon force as the
  560. state, set this to ``MusculotendonFormulation.TENDON_FORCE_IMPLICIT``
  561. (or the integer value ``4``). The default is
  562. ``MusculotendonFormulation.RIGID_TENDON``, which corresponds to a rigid
  563. tendon formulation.
  564. """
  565. return self._musculotendon_dynamics
  566. def _rigid_tendon_musculotendon_dynamics(self):
  567. """Rigid tendon musculotendon."""
  568. self._l_MT = self.pathway.length
  569. self._v_MT = self.pathway.extension_velocity
  570. self._l_T = self._l_T_slack
  571. self._l_T_tilde = Integer(1)
  572. self._l_M = sqrt((self._l_MT - self._l_T)**2 + (self._l_M_opt*sin(self._alpha_opt))**2)
  573. self._l_M_tilde = self._l_M/self._l_M_opt
  574. self._v_M = self._v_MT*(self._l_MT - self._l_T_slack)/self._l_M
  575. self._v_M_tilde = self._v_M/self._v_M_max
  576. if self._with_defaults:
  577. self._fl_T = self.curves.tendon_force_length.with_defaults(self._l_T_tilde)
  578. self._fl_M_pas = self.curves.fiber_force_length_passive.with_defaults(self._l_M_tilde)
  579. self._fl_M_act = self.curves.fiber_force_length_active.with_defaults(self._l_M_tilde)
  580. self._fv_M = self.curves.fiber_force_velocity.with_defaults(self._v_M_tilde)
  581. else:
  582. fl_T_constants = symbols(f'c_0:4_fl_T_{self.name}')
  583. self._fl_T = self.curves.tendon_force_length(self._l_T_tilde, *fl_T_constants)
  584. fl_M_pas_constants = symbols(f'c_0:2_fl_M_pas_{self.name}')
  585. self._fl_M_pas = self.curves.fiber_force_length_passive(self._l_M_tilde, *fl_M_pas_constants)
  586. fl_M_act_constants = symbols(f'c_0:12_fl_M_act_{self.name}')
  587. self._fl_M_act = self.curves.fiber_force_length_active(self._l_M_tilde, *fl_M_act_constants)
  588. fv_M_constants = symbols(f'c_0:4_fv_M_{self.name}')
  589. self._fv_M = self.curves.fiber_force_velocity(self._v_M_tilde, *fv_M_constants)
  590. self._F_M_tilde = self.a*self._fl_M_act*self._fv_M + self._fl_M_pas + self._beta*self._v_M_tilde
  591. self._F_T_tilde = self._F_M_tilde
  592. self._F_M = self._F_M_tilde*self._F_M_max
  593. self._cos_alpha = cos(self._alpha_opt)
  594. self._F_T = self._F_M*self._cos_alpha
  595. # Containers
  596. self._state_vars = zeros(0, 1)
  597. self._input_vars = zeros(0, 1)
  598. self._state_eqns = zeros(0, 1)
  599. self._curve_constants = Matrix(
  600. fl_T_constants
  601. + fl_M_pas_constants
  602. + fl_M_act_constants
  603. + fv_M_constants
  604. ) if not self._with_defaults else zeros(0, 1)
  605. def _fiber_length_explicit_musculotendon_dynamics(self):
  606. """Elastic tendon musculotendon using `l_M_tilde` as a state."""
  607. self._l_M_tilde = dynamicsymbols(f'l_M_tilde_{self.name}')
  608. self._l_MT = self.pathway.length
  609. self._v_MT = self.pathway.extension_velocity
  610. self._l_M = self._l_M_tilde*self._l_M_opt
  611. self._l_T = self._l_MT - sqrt(self._l_M**2 - (self._l_M_opt*sin(self._alpha_opt))**2)
  612. self._l_T_tilde = self._l_T/self._l_T_slack
  613. self._cos_alpha = (self._l_MT - self._l_T)/self._l_M
  614. if self._with_defaults:
  615. self._fl_T = self.curves.tendon_force_length.with_defaults(self._l_T_tilde)
  616. self._fl_M_pas = self.curves.fiber_force_length_passive.with_defaults(self._l_M_tilde)
  617. self._fl_M_act = self.curves.fiber_force_length_active.with_defaults(self._l_M_tilde)
  618. else:
  619. fl_T_constants = symbols(f'c_0:4_fl_T_{self.name}')
  620. self._fl_T = self.curves.tendon_force_length(self._l_T_tilde, *fl_T_constants)
  621. fl_M_pas_constants = symbols(f'c_0:2_fl_M_pas_{self.name}')
  622. self._fl_M_pas = self.curves.fiber_force_length_passive(self._l_M_tilde, *fl_M_pas_constants)
  623. fl_M_act_constants = symbols(f'c_0:12_fl_M_act_{self.name}')
  624. self._fl_M_act = self.curves.fiber_force_length_active(self._l_M_tilde, *fl_M_act_constants)
  625. self._F_T_tilde = self._fl_T
  626. self._F_T = self._F_T_tilde*self._F_M_max
  627. self._F_M = self._F_T/self._cos_alpha
  628. self._F_M_tilde = self._F_M/self._F_M_max
  629. self._fv_M = (self._F_M_tilde - self._fl_M_pas)/(self.a*self._fl_M_act)
  630. if self._with_defaults:
  631. self._v_M_tilde = self.curves.fiber_force_velocity_inverse.with_defaults(self._fv_M)
  632. else:
  633. fv_M_constants = symbols(f'c_0:4_fv_M_{self.name}')
  634. self._v_M_tilde = self.curves.fiber_force_velocity_inverse(self._fv_M, *fv_M_constants)
  635. self._dl_M_tilde_dt = (self._v_M_max/self._l_M_opt)*self._v_M_tilde
  636. self._state_vars = Matrix([self._l_M_tilde])
  637. self._input_vars = zeros(0, 1)
  638. self._state_eqns = Matrix([self._dl_M_tilde_dt])
  639. self._curve_constants = Matrix(
  640. fl_T_constants
  641. + fl_M_pas_constants
  642. + fl_M_act_constants
  643. + fv_M_constants
  644. ) if not self._with_defaults else zeros(0, 1)
  645. def _tendon_force_explicit_musculotendon_dynamics(self):
  646. """Elastic tendon musculotendon using `F_T_tilde` as a state."""
  647. self._F_T_tilde = dynamicsymbols(f'F_T_tilde_{self.name}')
  648. self._l_MT = self.pathway.length
  649. self._v_MT = self.pathway.extension_velocity
  650. self._fl_T = self._F_T_tilde
  651. if self._with_defaults:
  652. self._fl_T_inv = self.curves.tendon_force_length_inverse.with_defaults(self._fl_T)
  653. else:
  654. fl_T_constants = symbols(f'c_0:4_fl_T_{self.name}')
  655. self._fl_T_inv = self.curves.tendon_force_length_inverse(self._fl_T, *fl_T_constants)
  656. self._l_T_tilde = self._fl_T_inv
  657. self._l_T = self._l_T_tilde*self._l_T_slack
  658. self._l_M = sqrt((self._l_MT - self._l_T)**2 + (self._l_M_opt*sin(self._alpha_opt))**2)
  659. self._l_M_tilde = self._l_M/self._l_M_opt
  660. if self._with_defaults:
  661. self._fl_M_pas = self.curves.fiber_force_length_passive.with_defaults(self._l_M_tilde)
  662. self._fl_M_act = self.curves.fiber_force_length_active.with_defaults(self._l_M_tilde)
  663. else:
  664. fl_M_pas_constants = symbols(f'c_0:2_fl_M_pas_{self.name}')
  665. self._fl_M_pas = self.curves.fiber_force_length_passive(self._l_M_tilde, *fl_M_pas_constants)
  666. fl_M_act_constants = symbols(f'c_0:12_fl_M_act_{self.name}')
  667. self._fl_M_act = self.curves.fiber_force_length_active(self._l_M_tilde, *fl_M_act_constants)
  668. self._cos_alpha = (self._l_MT - self._l_T)/self._l_M
  669. self._F_T = self._F_T_tilde*self._F_M_max
  670. self._F_M = self._F_T/self._cos_alpha
  671. self._F_M_tilde = self._F_M/self._F_M_max
  672. self._fv_M = (self._F_M_tilde - self._fl_M_pas)/(self.a*self._fl_M_act)
  673. if self._with_defaults:
  674. self._fv_M_inv = self.curves.fiber_force_velocity_inverse.with_defaults(self._fv_M)
  675. else:
  676. fv_M_constants = symbols(f'c_0:4_fv_M_{self.name}')
  677. self._fv_M_inv = self.curves.fiber_force_velocity_inverse(self._fv_M, *fv_M_constants)
  678. self._v_M_tilde = self._fv_M_inv
  679. self._v_M = self._v_M_tilde*self._v_M_max
  680. self._v_T = self._v_MT - (self._v_M/self._cos_alpha)
  681. self._v_T_tilde = self._v_T/self._l_T_slack
  682. if self._with_defaults:
  683. self._fl_T = self.curves.tendon_force_length.with_defaults(self._l_T_tilde)
  684. else:
  685. self._fl_T = self.curves.tendon_force_length(self._l_T_tilde, *fl_T_constants)
  686. self._dF_T_tilde_dt = self._fl_T.diff(dynamicsymbols._t).subs({self._l_T_tilde.diff(dynamicsymbols._t): self._v_T_tilde})
  687. self._state_vars = Matrix([self._F_T_tilde])
  688. self._input_vars = zeros(0, 1)
  689. self._state_eqns = Matrix([self._dF_T_tilde_dt])
  690. self._curve_constants = Matrix(
  691. fl_T_constants
  692. + fl_M_pas_constants
  693. + fl_M_act_constants
  694. + fv_M_constants
  695. ) if not self._with_defaults else zeros(0, 1)
  696. def _fiber_length_implicit_musculotendon_dynamics(self):
  697. raise NotImplementedError
  698. def _tendon_force_implicit_musculotendon_dynamics(self):
  699. raise NotImplementedError
  700. @property
  701. def state_vars(self):
  702. """Ordered column matrix of functions of time that represent the state
  703. variables.
  704. Explanation
  705. ===========
  706. The alias ``x`` can also be used to access the same attribute.
  707. """
  708. state_vars = [self._state_vars]
  709. for child in self._child_objects:
  710. state_vars.append(child.state_vars)
  711. return Matrix.vstack(*state_vars)
  712. @property
  713. def x(self):
  714. """Ordered column matrix of functions of time that represent the state
  715. variables.
  716. Explanation
  717. ===========
  718. The alias ``state_vars`` can also be used to access the same attribute.
  719. """
  720. state_vars = [self._state_vars]
  721. for child in self._child_objects:
  722. state_vars.append(child.state_vars)
  723. return Matrix.vstack(*state_vars)
  724. @property
  725. def input_vars(self):
  726. """Ordered column matrix of functions of time that represent the input
  727. variables.
  728. Explanation
  729. ===========
  730. The alias ``r`` can also be used to access the same attribute.
  731. """
  732. input_vars = [self._input_vars]
  733. for child in self._child_objects:
  734. input_vars.append(child.input_vars)
  735. return Matrix.vstack(*input_vars)
  736. @property
  737. def r(self):
  738. """Ordered column matrix of functions of time that represent the input
  739. variables.
  740. Explanation
  741. ===========
  742. The alias ``input_vars`` can also be used to access the same attribute.
  743. """
  744. input_vars = [self._input_vars]
  745. for child in self._child_objects:
  746. input_vars.append(child.input_vars)
  747. return Matrix.vstack(*input_vars)
  748. @property
  749. def constants(self):
  750. """Ordered column matrix of non-time varying symbols present in ``M``
  751. and ``F``.
  752. Explanation
  753. ===========
  754. Only symbolic constants are returned. If a numeric type (e.g. ``Float``)
  755. has been used instead of ``Symbol`` for a constant then that attribute
  756. will not be included in the matrix returned by this property. This is
  757. because the primary use of this property attribute is to provide an
  758. ordered sequence of the still-free symbols that require numeric values
  759. during code generation.
  760. The alias ``p`` can also be used to access the same attribute.
  761. """
  762. musculotendon_constants = [
  763. self._l_T_slack,
  764. self._F_M_max,
  765. self._l_M_opt,
  766. self._v_M_max,
  767. self._alpha_opt,
  768. self._beta,
  769. ]
  770. musculotendon_constants = [
  771. c for c in musculotendon_constants if not c.is_number
  772. ]
  773. constants = [
  774. Matrix(musculotendon_constants)
  775. if musculotendon_constants
  776. else zeros(0, 1)
  777. ]
  778. for child in self._child_objects:
  779. constants.append(child.constants)
  780. constants.append(self._curve_constants)
  781. return Matrix.vstack(*constants)
  782. @property
  783. def p(self):
  784. """Ordered column matrix of non-time varying symbols present in ``M``
  785. and ``F``.
  786. Explanation
  787. ===========
  788. Only symbolic constants are returned. If a numeric type (e.g. ``Float``)
  789. has been used instead of ``Symbol`` for a constant then that attribute
  790. will not be included in the matrix returned by this property. This is
  791. because the primary use of this property attribute is to provide an
  792. ordered sequence of the still-free symbols that require numeric values
  793. during code generation.
  794. The alias ``constants`` can also be used to access the same attribute.
  795. """
  796. musculotendon_constants = [
  797. self._l_T_slack,
  798. self._F_M_max,
  799. self._l_M_opt,
  800. self._v_M_max,
  801. self._alpha_opt,
  802. self._beta,
  803. ]
  804. musculotendon_constants = [
  805. c for c in musculotendon_constants if not c.is_number
  806. ]
  807. constants = [
  808. Matrix(musculotendon_constants)
  809. if musculotendon_constants
  810. else zeros(0, 1)
  811. ]
  812. for child in self._child_objects:
  813. constants.append(child.constants)
  814. constants.append(self._curve_constants)
  815. return Matrix.vstack(*constants)
  816. @property
  817. def M(self):
  818. """Ordered square matrix of coefficients on the LHS of ``M x' = F``.
  819. Explanation
  820. ===========
  821. The square matrix that forms part of the LHS of the linear system of
  822. ordinary differential equations governing the activation dynamics:
  823. ``M(x, r, t, p) x' = F(x, r, t, p)``.
  824. As zeroth-order activation dynamics have no state variables, this
  825. linear system has dimension 0 and therefore ``M`` is an empty square
  826. ``Matrix`` with shape (0, 0).
  827. """
  828. M = [eye(len(self._state_vars))]
  829. for child in self._child_objects:
  830. M.append(child.M)
  831. return diag(*M)
  832. @property
  833. def F(self):
  834. """Ordered column matrix of equations on the RHS of ``M x' = F``.
  835. Explanation
  836. ===========
  837. The column matrix that forms the RHS of the linear system of ordinary
  838. differential equations governing the activation dynamics:
  839. ``M(x, r, t, p) x' = F(x, r, t, p)``.
  840. As zeroth-order activation dynamics have no state variables, this
  841. linear system has dimension 0 and therefore ``F`` is an empty column
  842. ``Matrix`` with shape (0, 1).
  843. """
  844. F = [self._state_eqns]
  845. for child in self._child_objects:
  846. F.append(child.F)
  847. return Matrix.vstack(*F)
  848. def rhs(self):
  849. """Ordered column matrix of equations for the solution of ``M x' = F``.
  850. Explanation
  851. ===========
  852. The solution to the linear system of ordinary differential equations
  853. governing the activation dynamics:
  854. ``M(x, r, t, p) x' = F(x, r, t, p)``.
  855. As zeroth-order activation dynamics have no state variables, this
  856. linear has dimension 0 and therefore this method returns an empty
  857. column ``Matrix`` with shape (0, 1).
  858. """
  859. is_explicit = (
  860. MusculotendonFormulation.FIBER_LENGTH_EXPLICIT,
  861. MusculotendonFormulation.TENDON_FORCE_EXPLICIT,
  862. )
  863. if self.musculotendon_dynamics is MusculotendonFormulation.RIGID_TENDON:
  864. child_rhs = [child.rhs() for child in self._child_objects]
  865. return Matrix.vstack(*child_rhs)
  866. elif self.musculotendon_dynamics in is_explicit:
  867. rhs = self._state_eqns
  868. child_rhs = [child.rhs() for child in self._child_objects]
  869. return Matrix.vstack(rhs, *child_rhs)
  870. return self.M.solve(self.F)
  871. def __repr__(self):
  872. """Returns a string representation to reinstantiate the model."""
  873. return (
  874. f'{self.__class__.__name__}({self.name!r}, '
  875. f'pathway={self.pathway!r}, '
  876. f'activation_dynamics={self.activation_dynamics!r}, '
  877. f'musculotendon_dynamics={self.musculotendon_dynamics}, '
  878. f'tendon_slack_length={self._l_T_slack!r}, '
  879. f'peak_isometric_force={self._F_M_max!r}, '
  880. f'optimal_fiber_length={self._l_M_opt!r}, '
  881. f'maximal_fiber_velocity={self._v_M_max!r}, '
  882. f'optimal_pennation_angle={self._alpha_opt!r}, '
  883. f'fiber_damping_coefficient={self._beta!r})'
  884. )
  885. def __str__(self):
  886. """Returns a string representation of the expression for musculotendon
  887. force."""
  888. return str(self.force)
  889. class MusculotendonDeGroote2016(MusculotendonBase):
  890. r"""Musculotendon model using the curves of De Groote et al., 2016 [1]_.
  891. Examples
  892. ========
  893. This class models the musculotendon actuator parametrized by the
  894. characteristic curves described in De Groote et al., 2016 [1]_. Like all
  895. musculotendon models in SymPy's biomechanics module, it requires a pathway
  896. to define its line of action. We'll begin by creating a simple
  897. ``LinearPathway`` between two points that our musculotendon will follow.
  898. We'll create a point ``O`` to represent the musculotendon's origin and
  899. another ``I`` to represent its insertion.
  900. >>> from sympy import symbols
  901. >>> from sympy.physics.mechanics import (LinearPathway, Point,
  902. ... ReferenceFrame, dynamicsymbols)
  903. >>> N = ReferenceFrame('N')
  904. >>> O, I = O, P = symbols('O, I', cls=Point)
  905. >>> q, u = dynamicsymbols('q, u', real=True)
  906. >>> I.set_pos(O, q*N.x)
  907. >>> O.set_vel(N, 0)
  908. >>> I.set_vel(N, u*N.x)
  909. >>> pathway = LinearPathway(O, I)
  910. >>> pathway.attachments
  911. (O, I)
  912. >>> pathway.length
  913. Abs(q(t))
  914. >>> pathway.extension_velocity
  915. sign(q(t))*Derivative(q(t), t)
  916. A musculotendon also takes an instance of an activation dynamics model as
  917. this will be used to provide symbols for the activation in the formulation
  918. of the musculotendon dynamics. We'll use an instance of
  919. ``FirstOrderActivationDeGroote2016`` to represent first-order activation
  920. dynamics. Note that a single name argument needs to be provided as SymPy
  921. will use this as a suffix.
  922. >>> from sympy.physics.biomechanics import FirstOrderActivationDeGroote2016
  923. >>> activation = FirstOrderActivationDeGroote2016('muscle')
  924. >>> activation.x
  925. Matrix([[a_muscle(t)]])
  926. >>> activation.r
  927. Matrix([[e_muscle(t)]])
  928. >>> activation.p
  929. Matrix([
  930. [tau_a_muscle],
  931. [tau_d_muscle],
  932. [ b_muscle]])
  933. >>> activation.rhs()
  934. Matrix([[((1/2 - tanh(b_muscle*(-a_muscle(t) + e_muscle(t)))/2)*(3*...]])
  935. The musculotendon class requires symbols or values to be passed to represent
  936. the constants in the musculotendon dynamics. We'll use SymPy's ``symbols``
  937. function to create symbols for the maximum isometric force ``F_M_max``,
  938. optimal fiber length ``l_M_opt``, tendon slack length ``l_T_slack``, maximum
  939. fiber velocity ``v_M_max``, optimal pennation angle ``alpha_opt, and fiber
  940. damping coefficient ``beta``.
  941. >>> F_M_max = symbols('F_M_max', real=True)
  942. >>> l_M_opt = symbols('l_M_opt', real=True)
  943. >>> l_T_slack = symbols('l_T_slack', real=True)
  944. >>> v_M_max = symbols('v_M_max', real=True)
  945. >>> alpha_opt = symbols('alpha_opt', real=True)
  946. >>> beta = symbols('beta', real=True)
  947. We can then import the class ``MusculotendonDeGroote2016`` from the
  948. biomechanics module and create an instance by passing in the various objects
  949. we have previously instantiated. By default, a musculotendon model with
  950. rigid tendon musculotendon dynamics will be created.
  951. >>> from sympy.physics.biomechanics import MusculotendonDeGroote2016
  952. >>> rigid_tendon_muscle = MusculotendonDeGroote2016(
  953. ... 'muscle',
  954. ... pathway,
  955. ... activation,
  956. ... tendon_slack_length=l_T_slack,
  957. ... peak_isometric_force=F_M_max,
  958. ... optimal_fiber_length=l_M_opt,
  959. ... maximal_fiber_velocity=v_M_max,
  960. ... optimal_pennation_angle=alpha_opt,
  961. ... fiber_damping_coefficient=beta,
  962. ... )
  963. We can inspect the various properties of the musculotendon, including
  964. getting the symbolic expression describing the force it produces using its
  965. ``force`` attribute.
  966. >>> rigid_tendon_muscle.force
  967. -F_M_max*(beta*(-l_T_slack + Abs(q(t)))*sign(q(t))*Derivative(q(t), t)...
  968. When we created the musculotendon object, we passed in an instance of an
  969. activation dynamics object that governs the activation within the
  970. musculotendon. SymPy makes a design choice here that the activation dynamics
  971. instance will be treated as a child object of the musculotendon dynamics.
  972. Therefore, if we want to inspect the state and input variables associated
  973. with the musculotendon model, we will also be returned the state and input
  974. variables associated with the child object, or the activation dynamics in
  975. this case. As the musculotendon model that we created here uses rigid tendon
  976. dynamics, no additional states or inputs relating to the musculotendon are
  977. introduces. Consequently, the model has a single state associated with it,
  978. the activation, and a single input associated with it, the excitation. The
  979. states and inputs can be inspected using the ``x`` and ``r`` attributes
  980. respectively. Note that both ``x`` and ``r`` have the alias attributes of
  981. ``state_vars`` and ``input_vars``.
  982. >>> rigid_tendon_muscle.x
  983. Matrix([[a_muscle(t)]])
  984. >>> rigid_tendon_muscle.r
  985. Matrix([[e_muscle(t)]])
  986. To see which constants are symbolic in the musculotendon model, we can use
  987. the ``p`` or ``constants`` attribute. This returns a ``Matrix`` populated
  988. by the constants that are represented by a ``Symbol`` rather than a numeric
  989. value.
  990. >>> rigid_tendon_muscle.p
  991. Matrix([
  992. [ l_T_slack],
  993. [ F_M_max],
  994. [ l_M_opt],
  995. [ v_M_max],
  996. [ alpha_opt],
  997. [ beta],
  998. [ tau_a_muscle],
  999. [ tau_d_muscle],
  1000. [ b_muscle],
  1001. [ c_0_fl_T_muscle],
  1002. [ c_1_fl_T_muscle],
  1003. [ c_2_fl_T_muscle],
  1004. [ c_3_fl_T_muscle],
  1005. [ c_0_fl_M_pas_muscle],
  1006. [ c_1_fl_M_pas_muscle],
  1007. [ c_0_fl_M_act_muscle],
  1008. [ c_1_fl_M_act_muscle],
  1009. [ c_2_fl_M_act_muscle],
  1010. [ c_3_fl_M_act_muscle],
  1011. [ c_4_fl_M_act_muscle],
  1012. [ c_5_fl_M_act_muscle],
  1013. [ c_6_fl_M_act_muscle],
  1014. [ c_7_fl_M_act_muscle],
  1015. [ c_8_fl_M_act_muscle],
  1016. [ c_9_fl_M_act_muscle],
  1017. [c_10_fl_M_act_muscle],
  1018. [c_11_fl_M_act_muscle],
  1019. [ c_0_fv_M_muscle],
  1020. [ c_1_fv_M_muscle],
  1021. [ c_2_fv_M_muscle],
  1022. [ c_3_fv_M_muscle]])
  1023. Finally, we can call the ``rhs`` method to return a ``Matrix`` that
  1024. contains as its elements the righthand side of the ordinary differential
  1025. equations corresponding to each of the musculotendon's states. Like the
  1026. method with the same name on the ``Method`` classes in SymPy's mechanics
  1027. module, this returns a column vector where the number of rows corresponds to
  1028. the number of states. For our example here, we have a single state, the
  1029. dynamic symbol ``a_muscle(t)``, so the returned value is a 1-by-1
  1030. ``Matrix``.
  1031. >>> rigid_tendon_muscle.rhs()
  1032. Matrix([[((1/2 - tanh(b_muscle*(-a_muscle(t) + e_muscle(t)))/2)*(3*...]])
  1033. The musculotendon class supports elastic tendon musculotendon models in
  1034. addition to rigid tendon ones. You can choose to either use the fiber length
  1035. or tendon force as an additional state. You can also specify whether an
  1036. explicit or implicit formulation should be used. To select a formulation,
  1037. pass a member of the ``MusculotendonFormulation`` enumeration to the
  1038. ``musculotendon_dynamics`` parameter when calling the constructor. This
  1039. enumeration is an ``IntEnum``, so you can also pass an integer, however it
  1040. is recommended to use the enumeration as it is clearer which formulation you
  1041. are actually selecting. Below, we'll use the ``FIBER_LENGTH_EXPLICIT``
  1042. member to create a musculotendon with an elastic tendon that will use the
  1043. (normalized) muscle fiber length as an additional state and will produce
  1044. the governing ordinary differential equation in explicit form.
  1045. >>> from sympy.physics.biomechanics import MusculotendonFormulation
  1046. >>> elastic_tendon_muscle = MusculotendonDeGroote2016(
  1047. ... 'muscle',
  1048. ... pathway,
  1049. ... activation,
  1050. ... musculotendon_dynamics=MusculotendonFormulation.FIBER_LENGTH_EXPLICIT,
  1051. ... tendon_slack_length=l_T_slack,
  1052. ... peak_isometric_force=F_M_max,
  1053. ... optimal_fiber_length=l_M_opt,
  1054. ... maximal_fiber_velocity=v_M_max,
  1055. ... optimal_pennation_angle=alpha_opt,
  1056. ... fiber_damping_coefficient=beta,
  1057. ... )
  1058. >>> elastic_tendon_muscle.force
  1059. -F_M_max*TendonForceLengthDeGroote2016((-sqrt(l_M_opt**2*...
  1060. >>> elastic_tendon_muscle.x
  1061. Matrix([
  1062. [l_M_tilde_muscle(t)],
  1063. [ a_muscle(t)]])
  1064. >>> elastic_tendon_muscle.r
  1065. Matrix([[e_muscle(t)]])
  1066. >>> elastic_tendon_muscle.p
  1067. Matrix([
  1068. [ l_T_slack],
  1069. [ F_M_max],
  1070. [ l_M_opt],
  1071. [ v_M_max],
  1072. [ alpha_opt],
  1073. [ beta],
  1074. [ tau_a_muscle],
  1075. [ tau_d_muscle],
  1076. [ b_muscle],
  1077. [ c_0_fl_T_muscle],
  1078. [ c_1_fl_T_muscle],
  1079. [ c_2_fl_T_muscle],
  1080. [ c_3_fl_T_muscle],
  1081. [ c_0_fl_M_pas_muscle],
  1082. [ c_1_fl_M_pas_muscle],
  1083. [ c_0_fl_M_act_muscle],
  1084. [ c_1_fl_M_act_muscle],
  1085. [ c_2_fl_M_act_muscle],
  1086. [ c_3_fl_M_act_muscle],
  1087. [ c_4_fl_M_act_muscle],
  1088. [ c_5_fl_M_act_muscle],
  1089. [ c_6_fl_M_act_muscle],
  1090. [ c_7_fl_M_act_muscle],
  1091. [ c_8_fl_M_act_muscle],
  1092. [ c_9_fl_M_act_muscle],
  1093. [c_10_fl_M_act_muscle],
  1094. [c_11_fl_M_act_muscle],
  1095. [ c_0_fv_M_muscle],
  1096. [ c_1_fv_M_muscle],
  1097. [ c_2_fv_M_muscle],
  1098. [ c_3_fv_M_muscle]])
  1099. >>> elastic_tendon_muscle.rhs()
  1100. Matrix([
  1101. [v_M_max*FiberForceVelocityInverseDeGroote2016((l_M_opt*...],
  1102. [ ((1/2 - tanh(b_muscle*(-a_muscle(t) + e_muscle(t)))/2)*(3*...]])
  1103. It is strongly recommended to use the alternate ``with_defaults``
  1104. constructor when creating an instance because this will ensure that the
  1105. published constants are used in the musculotendon characteristic curves.
  1106. >>> elastic_tendon_muscle = MusculotendonDeGroote2016.with_defaults(
  1107. ... 'muscle',
  1108. ... pathway,
  1109. ... activation,
  1110. ... musculotendon_dynamics=MusculotendonFormulation.FIBER_LENGTH_EXPLICIT,
  1111. ... tendon_slack_length=l_T_slack,
  1112. ... peak_isometric_force=F_M_max,
  1113. ... optimal_fiber_length=l_M_opt,
  1114. ... )
  1115. >>> elastic_tendon_muscle.x
  1116. Matrix([
  1117. [l_M_tilde_muscle(t)],
  1118. [ a_muscle(t)]])
  1119. >>> elastic_tendon_muscle.r
  1120. Matrix([[e_muscle(t)]])
  1121. >>> elastic_tendon_muscle.p
  1122. Matrix([
  1123. [ l_T_slack],
  1124. [ F_M_max],
  1125. [ l_M_opt],
  1126. [tau_a_muscle],
  1127. [tau_d_muscle],
  1128. [ b_muscle]])
  1129. Parameters
  1130. ==========
  1131. name : str
  1132. The name identifier associated with the musculotendon. This name is used
  1133. as a suffix when automatically generated symbols are instantiated. It
  1134. must be a string of nonzero length.
  1135. pathway : PathwayBase
  1136. The pathway that the actuator follows. This must be an instance of a
  1137. concrete subclass of ``PathwayBase``, e.g. ``LinearPathway``.
  1138. activation_dynamics : ActivationBase
  1139. The activation dynamics that will be modeled within the musculotendon.
  1140. This must be an instance of a concrete subclass of ``ActivationBase``,
  1141. e.g. ``FirstOrderActivationDeGroote2016``.
  1142. musculotendon_dynamics : MusculotendonFormulation | int
  1143. The formulation of musculotendon dynamics that should be used
  1144. internally, i.e. rigid or elastic tendon model, the choice of
  1145. musculotendon state etc. This must be a member of the integer
  1146. enumeration ``MusculotendonFormulation`` or an integer that can be cast
  1147. to a member. To use a rigid tendon formulation, set this to
  1148. ``MusculotendonFormulation.RIGID_TENDON`` (or the integer value ``0``,
  1149. which will be cast to the enumeration member). There are four possible
  1150. formulations for an elastic tendon model. To use an explicit formulation
  1151. with the fiber length as the state, set this to
  1152. ``MusculotendonFormulation.FIBER_LENGTH_EXPLICIT`` (or the integer value
  1153. ``1``). To use an explicit formulation with the tendon force as the
  1154. state, set this to ``MusculotendonFormulation.TENDON_FORCE_EXPLICIT``
  1155. (or the integer value ``2``). To use an implicit formulation with the
  1156. fiber length as the state, set this to
  1157. ``MusculotendonFormulation.FIBER_LENGTH_IMPLICIT`` (or the integer value
  1158. ``3``). To use an implicit formulation with the tendon force as the
  1159. state, set this to ``MusculotendonFormulation.TENDON_FORCE_IMPLICIT``
  1160. (or the integer value ``4``). The default is
  1161. ``MusculotendonFormulation.RIGID_TENDON``, which corresponds to a rigid
  1162. tendon formulation.
  1163. tendon_slack_length : Expr | None
  1164. The length of the tendon when the musculotendon is in its unloaded
  1165. state. In a rigid tendon model the tendon length is the tendon slack
  1166. length. In all musculotendon models, tendon slack length is used to
  1167. normalize tendon length to give
  1168. :math:`\tilde{l}^T = \frac{l^T}{l^T_{slack}}`.
  1169. peak_isometric_force : Expr | None
  1170. The maximum force that the muscle fiber can produce when it is
  1171. undergoing an isometric contraction (no lengthening velocity). In all
  1172. musculotendon models, peak isometric force is used to normalized tendon
  1173. and muscle fiber force to give
  1174. :math:`\tilde{F}^T = \frac{F^T}{F^M_{max}}`.
  1175. optimal_fiber_length : Expr | None
  1176. The muscle fiber length at which the muscle fibers produce no passive
  1177. force and their maximum active force. In all musculotendon models,
  1178. optimal fiber length is used to normalize muscle fiber length to give
  1179. :math:`\tilde{l}^M = \frac{l^M}{l^M_{opt}}`.
  1180. maximal_fiber_velocity : Expr | None
  1181. The fiber velocity at which, during muscle fiber shortening, the muscle
  1182. fibers are unable to produce any active force. In all musculotendon
  1183. models, maximal fiber velocity is used to normalize muscle fiber
  1184. extension velocity to give :math:`\tilde{v}^M = \frac{v^M}{v^M_{max}}`.
  1185. optimal_pennation_angle : Expr | None
  1186. The pennation angle when muscle fiber length equals the optimal fiber
  1187. length.
  1188. fiber_damping_coefficient : Expr | None
  1189. The coefficient of damping to be used in the damping element in the
  1190. muscle fiber model.
  1191. with_defaults : bool
  1192. Whether ``with_defaults`` alternate constructors should be used when
  1193. automatically constructing child classes. Default is ``False``.
  1194. References
  1195. ==========
  1196. .. [1] De Groote, F., Kinney, A. L., Rao, A. V., & Fregly, B. J., Evaluation
  1197. of direct collocation optimal control problem formulations for
  1198. solving the muscle redundancy problem, Annals of biomedical
  1199. engineering, 44(10), (2016) pp. 2922-2936
  1200. """
  1201. curves = CharacteristicCurveCollection(
  1202. tendon_force_length=TendonForceLengthDeGroote2016,
  1203. tendon_force_length_inverse=TendonForceLengthInverseDeGroote2016,
  1204. fiber_force_length_passive=FiberForceLengthPassiveDeGroote2016,
  1205. fiber_force_length_passive_inverse=FiberForceLengthPassiveInverseDeGroote2016,
  1206. fiber_force_length_active=FiberForceLengthActiveDeGroote2016,
  1207. fiber_force_velocity=FiberForceVelocityDeGroote2016,
  1208. fiber_force_velocity_inverse=FiberForceVelocityInverseDeGroote2016,
  1209. )