
    \hc                         S r SSKJrJr  SSKJr  SSKJr  SSKJ	r	J
r
Jr  SSKJr  SSKJrJr  SSKJr  SS	KJr  / S
Qr " S S\\5      r " S S\5      r " S S\5      rg)aL  Activation dynamics for musclotendon models.

Musculotendon models are able to produce active force when they are activated,
which is when a chemical process has taken place within the muscle fibers
causing them to voluntarily contract. Biologically this chemical process (the
diffusion of :math:`\textrm{Ca}^{2+}` ions) is not the input in the system,
electrical signals from the nervous system are. These are termed excitations.
Activation dynamics, which relates the normalized excitation level to the
normalized activation level, can be modeled by the models present in this
module.

    )ABCabstractmethod)cached_property)Symbol)FloatIntegerRational)tanh)MutableDenseMatrixzeros)_NamedMixin)dynamicsymbols)ActivationBase FirstOrderActivationDeGroote2016ZerothOrderActivationc                   ~   \ rS rSrSrS r\\S 5       5       r\	S 5       r
\	S 5       r\	S 5       r\	S 5       r\	\S	 5       5       r\	\S
 5       5       r\	\S 5       5       r\	\S 5       5       r\	\S 5       5       r\	\S 5       5       r\	\S 5       5       r\	\S 5       5       r\	\S 5       5       r\S 5       rS rS rSrg)r       zAbstract base class for all activation dynamics classes to inherit from.

Notes
=====

Instances of this class cannot be directly instantiated by users. However,
it can be used to created custom activation dynamics types through
subclassing.

c                 p    [        U5      U l        [        SU 35      U l        [        SU 35      U l        g)z#Initializer for ``ActivationBase``.e_a_N)strnamer   _e_a)selfr   s     ]/var/www/auris/envauris/lib/python3.13/site-packages/sympy/physics/biomechanics/activation.py__init__ActivationBase.__init__,   s3    I	 !2dV- 2dV-    c                     g)zGAlternate constructor that provides recommended defaults for
constants.N clsr   s     r   with_defaultsActivationBase.with_defaults4   s    
 	r   c                     U R                   $ )zDynamic symbol representing excitation.

Explanation
===========

The alias ``e`` can also be used to access the same attribute.

r   r   s    r   
excitationActivationBase.excitation;        wwr   c                     U R                   $ )zDynamic symbol representing excitation.

Explanation
===========

The alias ``excitation`` can also be used to access the same attribute.

r'   r(   s    r   eActivationBase.eG   r+   r   c                     U R                   $ )zDynamic symbol representing activation.

Explanation
===========

The alias ``a`` can also be used to access the same attribute.

r   r(   s    r   
activationActivationBase.activationS   r+   r   c                     U R                   $ )zDynamic symbol representing activation.

Explanation
===========

The alias ``activation`` can also be used to access the same attribute.

r0   r(   s    r   aActivationBase.a_   r+   r   c                     g):Order of the (differential) equation governing activation.Nr!   r(   s    r   orderActivationBase.orderk   s     	r   c                     g)Ordered column matrix of functions of time that represent the state
variables.

Explanation
===========

The alias ``x`` can also be used to access the same attribute.

Nr!   r(   s    r   
state_varsActivationBase.state_varsq        	r   c                     g)Ordered column matrix of functions of time that represent the state
variables.

Explanation
===========

The alias ``state_vars`` can also be used to access the same attribute.

Nr!   r(   s    r   xActivationBase.x   r>   r   c                     g)Ordered column matrix of functions of time that represent the input
variables.

Explanation
===========

The alias ``r`` can also be used to access the same attribute.

Nr!   r(   s    r   
input_varsActivationBase.input_vars   r>   r   c                     g)Ordered column matrix of functions of time that represent the input
variables.

Explanation
===========

The alias ``input_vars`` can also be used to access the same attribute.

Nr!   r(   s    r   rActivationBase.r   r>   r   c                     g)"  Ordered column matrix of non-time varying symbols present in ``M``
and ``F``.

Only symbolic constants are returned. If a numeric type (e.g. ``Float``)
has been used instead of ``Symbol`` for a constant then that attribute
will not be included in the matrix returned by this property. This is
because the primary use of this property attribute is to provide an
ordered sequence of the still-free symbols that require numeric values
during code generation.

Explanation
===========

The alias ``p`` can also be used to access the same attribute.

Nr!   r(   s    r   	constantsActivationBase.constants       & 	r   c                     g)a*  Ordered column matrix of non-time varying symbols present in ``M``
and ``F``.

Only symbolic constants are returned. If a numeric type (e.g. ``Float``)
has been used instead of ``Symbol`` for a constant then that attribute
will not be included in the matrix returned by this property. This is
because the primary use of this property attribute is to provide an
ordered sequence of the still-free symbols that require numeric values
during code generation.

Explanation
===========

The alias ``constants`` can also be used to access the same attribute.

Nr!   r(   s    r   pActivationBase.p   rO   r   c                     g)  Ordered square matrix of coefficients on the LHS of ``M x' = F``.

Explanation
===========

The square matrix that forms part of the LHS of the linear system of
ordinary differential equations governing the activation dynamics:

``M(x, r, t, p) x' = F(x, r, t, p)``.

Nr!   r(   s    r   MActivationBase.M        	r   c                     g)  Ordered column matrix of equations on the RHS of ``M x' = F``.

Explanation
===========

The column matrix that forms the RHS of the linear system of ordinary
differential equations governing the activation dynamics:

``M(x, r, t, p) x' = F(x, r, t, p)``.

Nr!   r(   s    r   FActivationBase.F   rW   r   c                     g)z

Explanation
===========

The solution to the linear system of ordinary differential equations
governing the activation dynamics:

``M(x, r, t, p) x' = F(x, r, t, p)``.

Nr!   r(   s    r   rhsActivationBase.rhs   s     	r   c                 l    [        U 5      [        U5      :w  a  gU R                  UR                  :w  a  gg)z'Equality check for activation dynamics.FT)typer   )r   others     r   __eq__ActivationBase.__eq__  s+    :e$99

"r   c                 P    U R                   R                   SU R                  < S3$ )z.Default representation of activation dynamics.())	__class____name__r   r(   s    r   __repr__ActivationBase.__repr__
  s$    ..))*!DII=::r   )r   r   r   N)rh   
__module____qualname____firstlineno____doc__r   classmethodr   r$   propertyr)   r-   r1   r4   r8   r<   rA   rE   rI   rM   rQ   rU   rZ   r]   rb   ri   __static_attributes__r!   r   r   r   r       s   	.   
 	 	 	 	 	 	 	 	    
  
 
  
 
  
 
  
   &   &        ;r   r   c                      ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r	\S 5       r
\S 5       r\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       rS rSrU =r$ )r   i  a  Simple zeroth-order activation dynamics mapping excitation to
activation.

Explanation
===========

Zeroth-order activation dynamics are useful in instances where you want to
reduce the complexity of your musculotendon dynamics as they simple map
exictation to activation. As a result, no additional state equations are
introduced to your system. They also remove a potential source of delay
between the input and dynamics of your system as no (ordinary) differential
equations are involved.

c                 F   > [         TU ]  U5        U R                  U l        g)zInitializer for ``ZerothOrderActivation``.

Parameters
==========

name : str
    The name identifier associated with the instance. Must be a string
    of length at least 1.

N)superr   r   r   )r   r   rg   s     r   r   ZerothOrderActivation.__init__  s     	 ''r   c                     U " U5      $ )a~  Alternate constructor that provides recommended defaults for
constants.

Explanation
===========

As this concrete class doesn't implement any constants associated with
its dynamics, this ``classmethod`` simply creates a standard instance
of ``ZerothOrderActivation``. An implementation is provided to ensure
a consistent interface between all ``ActivationBase`` concrete classes.

r!   r"   s     r   r$   #ZerothOrderActivation.with_defaults0  s     4yr   c                     g)r7   r   r!   r(   s    r   r8   ZerothOrderActivation.order@       r   c                     [        SS5      $ )ak  Ordered column matrix of functions of time that represent the state
variables.

Explanation
===========

As zeroth-order activation dynamics simply maps excitation to
activation, this class has no associated state variables and so this
property return an empty column ``Matrix`` with shape (0, 1).

The alias ``x`` can also be used to access the same attribute.

r      r   r(   s    r   r<    ZerothOrderActivation.state_varsE       Q{r   c                     [        SS5      $ )at  Ordered column matrix of functions of time that represent the state
variables.

Explanation
===========

As zeroth-order activation dynamics simply maps excitation to
activation, this class has no associated state variables and so this
property return an empty column ``Matrix`` with shape (0, 1).

The alias ``state_vars`` can also be used to access the same attribute.

r   r|   r}   r(   s    r   rA   ZerothOrderActivation.xV  r   r   c                 .    [        U R                  /5      $ )aE  Ordered column matrix of functions of time that represent the input
variables.

Explanation
===========

Excitation is the only input in zeroth-order activation dynamics and so
this property returns a column ``Matrix`` with one entry, ``e``, and
shape (1, 1).

The alias ``r`` can also be used to access the same attribute.

Matrixr   r(   s    r   rE    ZerothOrderActivation.input_varsg       twwi  r   c                 .    [        U R                  /5      $ )aN  Ordered column matrix of functions of time that represent the input
variables.

Explanation
===========

Excitation is the only input in zeroth-order activation dynamics and so
this property returns a column ``Matrix`` with one entry, ``e``, and
shape (1, 1).

The alias ``input_vars`` can also be used to access the same attribute.

r   r(   s    r   rI   ZerothOrderActivation.rx  r   r   c                     [        SS5      $ )a  Ordered column matrix of non-time varying symbols present in ``M``
and ``F``.

Only symbolic constants are returned. If a numeric type (e.g. ``Float``)
has been used instead of ``Symbol`` for a constant then that attribute
will not be included in the matrix returned by this property. This is
because the primary use of this property attribute is to provide an
ordered sequence of the still-free symbols that require numeric values
during code generation.

Explanation
===========

As zeroth-order activation dynamics simply maps excitation to
activation, this class has no associated constants and so this property
return an empty column ``Matrix`` with shape (0, 1).

The alias ``p`` can also be used to access the same attribute.

r   r|   r}   r(   s    r   rM   ZerothOrderActivation.constants      , Q{r   c                     [        SS5      $ )a  Ordered column matrix of non-time varying symbols present in ``M``
and ``F``.

Only symbolic constants are returned. If a numeric type (e.g. ``Float``)
has been used instead of ``Symbol`` for a constant then that attribute
will not be included in the matrix returned by this property. This is
because the primary use of this property attribute is to provide an
ordered sequence of the still-free symbols that require numeric values
during code generation.

Explanation
===========

As zeroth-order activation dynamics simply maps excitation to
activation, this class has no associated constants and so this property
return an empty column ``Matrix`` with shape (0, 1).

The alias ``constants`` can also be used to access the same attribute.

r   r|   r}   r(   s    r   rQ   ZerothOrderActivation.p  r   r   c                     [        / 5      $ )a  Ordered square matrix of coefficients on the LHS of ``M x' = F``.

Explanation
===========

The square matrix that forms part of the LHS of the linear system of
ordinary differential equations governing the activation dynamics:

``M(x, r, t, p) x' = F(x, r, t, p)``.

As zeroth-order activation dynamics have no state variables, this
linear system has dimension 0 and therefore ``M`` is an empty square
``Matrix`` with shape (0, 0).

)r   r(   s    r   rU   ZerothOrderActivation.M  s    " bzr   c                     [        SS5      $ )a  Ordered column matrix of equations on the RHS of ``M x' = F``.

Explanation
===========

The column matrix that forms the RHS of the linear system of ordinary
differential equations governing the activation dynamics:

``M(x, r, t, p) x' = F(x, r, t, p)``.

As zeroth-order activation dynamics have no state variables, this
linear system has dimension 0 and therefore ``F`` is an empty column
``Matrix`` with shape (0, 1).

r   r|   r}   r(   s    r   rZ   ZerothOrderActivation.F  s    " Q{r   c                     [        SS5      $ )a  Ordered column matrix of equations for the solution of ``M x' = F``.

Explanation
===========

The solution to the linear system of ordinary differential equations
governing the activation dynamics:

``M(x, r, t, p) x' = F(x, r, t, p)``.

As zeroth-order activation dynamics have no state variables, this
linear has dimension 0 and therefore this method returns an empty
column ``Matrix`` with shape (0, 1).

r   r|   r}   r(   s    r   r]   ZerothOrderActivation.rhs  s      Q{r   r0   )rh   rk   rl   rm   rn   r   ro   r$   rp   r8   r<   rA   rE   rI   rM   rQ   rU   rZ   r]   rq   __classcell__rg   s   @r   r   r     s    "           ! !  ! !   .  .  $  $ r   r   c                     ^  \ rS rSrSr   SU 4S jjr\S 5       r\S 5       r	\	R                  S 5       r	\S 5       r\S 5       r\R                  S	 5       r\S
 5       r\S 5       r\R                  S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS r\S 5       rS rS rSrU =r$ )r   i  a  First-order activation dynamics based on De Groote et al., 2016 [1]_.

Explanation
===========

Gives the first-order activation dynamics equation for the rate of change
of activation with respect to time as a function of excitation and
activation.

The function is defined by the equation:

.. math::

    \frac{da}{dt} = \left(\frac{\frac{1}{2} + a0}{\tau_a \left(\frac{1}{2}
        + \frac{3a}{2}\right)} + \frac{\left(\frac{1}{2}
        + \frac{3a}{2}\right) \left(\frac{1}{2} - a0\right)}{\tau_d}\right)
        \left(e - a\right)

where

.. math::

    a0 = \frac{\tanh{\left(b \left(e - a\right) \right)}}{2}

with constant values of :math:`tau_a = 0.015`, :math:`tau_d = 0.060`, and
:math:`b = 10`.

References
==========

.. [1] De Groote, F., Kinney, A. L., Rao, A. V., & Fregly, B. J., Evaluation
       of direct collocation optimal control problem formulations for
       solving the muscle redundancy problem, Annals of biomedical
       engineering, 44(10), (2016) pp. 2922-2936

c                 H   > [         TU ]  U5        X l        X0l        X@l        g)a  Initializer for ``FirstOrderActivationDeGroote2016``.

Parameters
==========
activation time constant : Symbol | Number | None
    The value of the activation time constant governing the delay
    between excitation and activation when excitation exceeds
    activation.
deactivation time constant : Symbol | Number | None
    The value of the deactivation time constant governing the delay
    between excitation and activation when activation exceeds
    excitation.
smoothing_rate : Symbol | Number | None
    The slope of the hyperbolic tangent function used to smooth between
    the switching of the equations where excitation exceed activation
    and where activation exceeds excitation. The recommended value to
    use is ``10``, but values between ``0.1`` and ``100`` can be used.

N)rt   r   activation_time_constantdeactivation_time_constantsmoothing_rate)r   r   r   r   r   rg   s        r   r   )FirstOrderActivationDeGroote2016.__init__  s'    2 	 )A%*D',r   c                 V    [        S5      n[        S5      n[        S5      nU " XX45      $ )a/  Alternate constructor that will use the published constants.

Explanation
===========

Returns an instance of ``FirstOrderActivationDeGroote2016`` using the
three constant values specified in the original publication.

These have the values:

:math:`tau_a = 0.015`
:math:`tau_d = 0.060`
:math:`b = 10`

z0.015z0.060z10.0)r   )r#   r   tau_atau_dbs        r   r$   .FirstOrderActivationDeGroote2016.with_defaults8  s,    " gg&M4))r   c                     U R                   $ )z~Delay constant for activation.

Explanation
===========

The alias ```tau_a`` can also be used to access the same attribute.

_tau_ar(   s    r   r   9FirstOrderActivationDeGroote2016.activation_time_constantN       {{r   c                     [        U S5      (       a'  S[        U5       SU R                   S3n[        U5      eUc  [	        SU R
                   35      U l        g UU l        g )Nr   z2Can't set attribute `activation_time_constant` to * as it is immutable and already has value .tau_a_)hasattrreprr   AttributeErrorr   r   )r   r   msgs      r   r   r   Z  sa    4""E;-I;;-q" 
 !%%6;mfvdii[12r   c                     U R                   $ )zDelay constant for activation.

Explanation
===========

The alias ``activation_time_constant`` can also be used to access the
same attribute.

r   r(   s    r   r   &FirstOrderActivationDeGroote2016.tau_ae       {{r   c                     U R                   $ )zDelay constant for deactivation.

Explanation
===========

The alias ``tau_d`` can also be used to access the same attribute.

_tau_dr(   s    r   r   ;FirstOrderActivationDeGroote2016.deactivation_time_constantr  r   r   c                     [        U S5      (       a'  S[        U5       SU R                   S3n[        U5      eUc  [	        SU R
                   35      U l        g UU l        g )Nr   z4Can't set attribute `deactivation_time_constant` to r   r   tau_d_)r   r   r   r   r   r   )r   r   r   s      r   r   r   ~  sa    4""G;-I;;-q" 
 !%%6;mfvdii[12r   c                     U R                   $ )zDelay constant for deactivation.

Explanation
===========

The alias ``deactivation_time_constant`` can also be used to access the
same attribute.

r   r(   s    r   r   &FirstOrderActivationDeGroote2016.tau_d  r   r   c                     U R                   $ )zSmoothing constant for the hyperbolic tangent term.

Explanation
===========

The alias ``b`` can also be used to access the same attribute.

_br(   s    r   r   /FirstOrderActivationDeGroote2016.smoothing_rate  r+   r   c                     [        U S5      (       a   SU< SU R                  < S3n[        U5      eUc  [        SU R                   35      U l        g UU l        g )Nr   z(Can't set attribute `smoothing_rate` to r   r   b_)r   r   r   r   r   )r   r   r   s      r   r   r     s`    4;A5 A33777+Q@  !%%./i&2dii[)*Qr   c                     U R                   $ )zSmoothing constant for the hyperbolic tangent term.

Explanation
===========

The alias ``smoothing_rate`` can also be used to access the same
attribute.

r   r(   s    r   r   "FirstOrderActivationDeGroote2016.b  s     wwr   c                     g)r7   r|   r!   r(   s    r   r8   &FirstOrderActivationDeGroote2016.order  rz   r   c                 .    [        U R                  /5      $ )r;   r   r   r(   s    r   r<   +FirstOrderActivationDeGroote2016.state_vars       twwi  r   c                 .    [        U R                  /5      $ )r@   r   r(   s    r   rA   "FirstOrderActivationDeGroote2016.x  r   r   c                 .    [        U R                  /5      $ )rD   r   r(   s    r   rE   +FirstOrderActivationDeGroote2016.input_vars  r   r   c                 .    [        U R                  /5      $ )rH   r   r(   s    r   rI   "FirstOrderActivationDeGroote2016.r  r   r   c                     U R                   U R                  U R                  /nU Vs/ s H  o"R                  (       a  M  UPM     nnU(       a  [	        U5      $ [        SS5      $ s  snf )rL   r   r|   r   r   r   	is_numberr   r   r   rM   csymbolic_constantss       r   rM   *FirstOrderActivationDeGroote2016.constants  T    $ [[$++tww7	)2FA++aF-?v()PU1a[P G   A& A&c                     U R                   U R                  U R                  /nU Vs/ s H  o"R                  (       a  M  UPM     nnU(       a  [	        U5      $ [        SS5      $ s  snf )a*  Ordered column matrix of non-time varying symbols present in ``M``
and ``F``.

Explanation
===========

Only symbolic constants are returned. If a numeric type (e.g. ``Float``)
has been used instead of ``Symbol`` for a constant then that attribute
will not be included in the matrix returned by this property. This is
because the primary use of this property attribute is to provide an
ordered sequence of the still-free symbols that require numeric values
during code generation.

The alias ``constants`` can also be used to access the same attribute.

r   r|   r   r   s       r   rQ   "FirstOrderActivationDeGroote2016.p  r   r   c                 ,    [        [        S5      /5      $ )rT   r|   )r   r   r(   s    r   rU   "FirstOrderActivationDeGroote2016.M  s     wqzl##r   c                 .    [        U R                  /5      $ )rY   r   _da_eqnr(   s    r   rZ   "FirstOrderActivationDeGroote2016.F-  s     t||n%%r   c                 .    [        U R                  /5      $ )zOrdered column matrix of equations for the solution of ``M x' = F``.

Explanation
===========

The solution to the linear system of ordinary differential equations
governing the activation dynamics:

``M(x, r, t, p) x' = F(x, r, t, p)``.

r   r(   s    r   r]   $FirstOrderActivationDeGroote2016.rhs<  s     t||n%%r   c                 F   [        SS5      nU[        U R                  U R                  U R                  -
  -  5      -  nU[        SS5      U R                  -  -   nX-   U R
                  U-  -  nX1U-
  -  U R                  -  nXE-   U R                  U R                  -
  -  nU$ )Nr|         )r	   r
   r   r   r   r   r   )r   HALFa0a1a2a3activation_dynamics_equations          r   r   (FirstOrderActivationDeGroote2016._da_eqnJ  s    1~DDGGdgg$5677Xa^dgg--iDKK",-"9+(*DGGdgg4E'F$++r   c                     [        U 5      [        U5      :w  a  gU R                  U R                  U R                  U R                  4nUR                  UR                  UR                  UR                  4nX#:X  a  gg)z8Equality check for ``FirstOrderActivationDeGroote2016``.FT)r`   r   r   r   r   )r   ra   
self_attrsother_attrss       r   rb   'FirstOrderActivationDeGroote2016.__eq__T  s]    :e$iiTZZ@
zz5;;UWWE$r   c           
          U R                   R                   SU R                  < SU R                  < SU R                  < SU R
                  < S3
$ )z7Representation of ``FirstOrderActivationDeGroote2016``.re   z, activation_time_constant=z, deactivation_time_constant=z, smoothing_rate=rf   )rg   rh   r   r   r   r   r(   s    r   ri   )FirstOrderActivationDeGroote2016.__repr__^  sT     ~~&&'q 6((,

~ 6**.** 8"ffZq*	
r   )r   r   r   r   r   r   )NNN) rh   rk   rl   rm   rn   r   ro   r$   rp   r   setterr   r   r   r   r   r8   r<   rA   rE   rI   rM   rQ   rU   rZ   r]   r   r   rb   ri   rq   r   r   s   @r   r   r     s   #N "&#'	-@ * ** 	 	 $$O %O 
 
 	 	  &&O 'O 
 
 	 	 ? ? 
 
   
! 
! 
! 
! 
! 
! 
! 
! Q Q* Q Q* $ $ & && , ,
 
r   r   N)rn   abcr   r   	functoolsr   sympy.core.symbolr   sympy.core.numbersr   r   r	   %sympy.functions.elementary.hyperbolicr
   sympy.matrices.denser   r   r   !sympy.physics.biomechanics._mixinr   sympy.physics.mechanicsr   __all__r   r   r   r!   r   r   <module>r      s\    $ % $ 7 7 6 D 9 2l;S+ l;^`N `Fs
~ s
r   