o
    GZh                     @   s  d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZmZ ddlmZ ddlmZmZmZmZmZm Z m!Z!m"Z" ddl#m$Z$m%Z%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 G dd dZ5G dd dZ6ej78de%gG dd dZ9ej78de%ee!e"eeeee dfgG dd dZ:ej78de%ee!e"eeeee dfgG d d! d!Z;G d"d# d#Z<dS )$zETests for the ``sympy.physics.biomechanics.musculotendon.py`` module.    N)UnevaluatedExpr)FloatIntegerRational)Symbol)exp)tanh)sqrt)sin)MutableDenseMatrixeyezeros) FirstOrderActivationDeGroote2016)CharacteristicCurveCollection"FiberForceLengthActiveDeGroote2016#FiberForceLengthPassiveDeGroote2016*FiberForceLengthPassiveInverseDeGroote2016FiberForceVelocityDeGroote2016%FiberForceVelocityInverseDeGroote2016TendonForceLengthDeGroote2016$TendonForceLengthInverseDeGroote2016)MusculotendonBaseMusculotendonDeGroote2016MusculotendonFormulation)_NamedMixin)ForceActuator)LinearPathway)ReferenceFrame)dynamicsymbols)Point)simplifyc                   @   sH   e Zd Zedd Zedd Zedd Zedd Zed	d
 ZdS )TestMusculotendonFormulationc                   C   "   t ddksJ t jdksJ d S )Nr   )r   RIGID_TENDON r$   r$   b/var/www/auris/lib/python3.10/site-packages/sympy/physics/biomechanics/tests/test_musculotendon.pytest_rigid_tendon_member+      z5TestMusculotendonFormulation.test_rigid_tendon_memberc                   C   r"   )N   )r   FIBER_LENGTH_EXPLICITr$   r$   r$   r%   !test_fiber_length_explicit_member0   r'   z>TestMusculotendonFormulation.test_fiber_length_explicit_memberc                   C   r"   )N   )r   TENDON_FORCE_EXPLICITr$   r$   r$   r%   !test_tendon_force_explicit_member5   r'   z>TestMusculotendonFormulation.test_tendon_force_explicit_memberc                   C   r"   )N   )r   ZFIBER_LENGTH_IMPLICITr$   r$   r$   r%   !test_fiber_length_implicit_member:   r'   z>TestMusculotendonFormulation.test_fiber_length_implicit_memberc                   C   r"   )N   )r   ZTENDON_FORCE_IMPLICITr$   r$   r$   r%   !test_tendon_force_implicit_member?   r'   z>TestMusculotendonFormulation.test_tendon_force_implicit_memberN)	__name__
__module____qualname__staticmethodr&   r*   r-   r/   r1   r$   r$   r$   r%   r!   *   s    



r!   c                   @   s0   e Zd Zedd Zedd Zedd ZdS )TestMusculotendonBasec                   C   s   t ttjsJ d S N)
issubclassr   abcABCr$   r$   r$   r%   test_is_abstract_base_classG   s   z1TestMusculotendonBase.test_is_abstract_base_classc                   C   .   t ttsJ t ttsJ tjdksJ d S )Nr   )r8   r   r   r   r2   r$   r$   r$   r%   
test_classK      z TestMusculotendonBase.test_classc                  C   s6   t t t } W d    d S 1 sw   Y  d S r7   )pytestraises	TypeErrorr   )_r$   r$   r%    test_cannot_instantiate_directlyQ   s   "z6TestMusculotendonBase.test_cannot_instantiate_directlyN)r2   r3   r4   r5   r;   r=   rC   r$   r$   r$   r%   r6   E   s    

r6   musculotendon_concretec                   @   P   e Zd Zejdddd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd ZdS )TestMusculotendonRigidTendonTZautousec                 C   s  d| _ td| _td| _td| _td| _| j| j| j| jj	  t
| j| j| _t| j | _| jj| _| jj| _| jj| _| jj| _| jj| _tj| _td| _td| _td| _td	| _td
| _td| _ || j | j| j| j| j| j| j| j| j| j d
| _!d| jt"ddt"dd| j    t"ddt"ddt#| j| j| j     t"ddt"dd| j  | j t"ddt"ddt#| j| j| j      | j| j  | _$d S )NnameNqpOpI	l_T_slackF_M_maxl_M_optv_M_max	alpha_optbetamusculotendon_dynamicstendon_slack_lengthpeak_isometric_forceoptimal_fiber_lengthmaximal_fiber_velocityoptimal_pennation_anglefiber_damping_coefficientr(   r+   r.   )%rH   r   rI   r   rJ   r   origin	insertionset_posxr   pathwayr   
activation
excitationeaactivation_time_constanttau_adeactivation_time_constanttau_dsmoothing_ratebr   r#   formulationr   rM   rN   rO   rP   rQ   rR   instancer   r   da_expr)selfrD   r$   r$   r%   #_musculotendon_rigid_tendon_fixtureZ   sR   














"((

z@TestMusculotendonRigidTendon._musculotendon_rigid_tendon_fixturec                 C      t | jdsJ t | jdsJ | jj| jjksJ t| jg}| jj|ks(J | jj|ks0J t| jjts9J t| jjtsBJ | jjjdksKJ | jjjdksTJ d S )Nr^   
state_varsr(   r(   )hasattrrk   r^   rp   Matrixrc   
isinstanceshaperm   Z
x_expectedr$   r$   r%   test_state_vars      z,TestMusculotendonRigidTendon.test_state_varsc                 C   ro   Nr
input_varsrq   rr   rk   rz   r{   rs   rb   rt   ru   rm   
r_expectedr$   r$   r%   test_input_vars   rx   z,TestMusculotendonRigidTendon.test_input_varsc                 C   s  t | jdsJ t | jdsJ | jj| jjksJ tg | j| j| j| j| j	| j
| j| j| jtdtdtdtdtdtdtd	td
tdtdtdtdtdtdtdtdtdtdtdtdtdtd}| jj|ksJ | jj|ksJ t| jjtsJ t| jjtsJ | jjjdksJ | jjjdksJ d S )Np	constantsZc_0_fl_T_nameZc_1_fl_T_nameZc_2_fl_T_nameZc_3_fl_T_nameZc_0_fl_M_pas_nameZc_1_fl_M_pas_nameZc_0_fl_M_act_nameZc_1_fl_M_act_nameZc_2_fl_M_act_nameZc_3_fl_M_act_nameZc_4_fl_M_act_nameZc_5_fl_M_act_nameZc_6_fl_M_act_nameZc_7_fl_M_act_nameZc_8_fl_M_act_nameZc_9_fl_M_act_nameZc_10_fl_M_act_nameZc_11_fl_M_act_nameZc_0_fv_M_nameZc_1_fv_M_nameZc_2_fv_M_nameZc_3_fv_M_name)   r(   )rr   rk   r   r   rs   rM   rN   rO   rP   rQ   rR   re   rg   ri   r   rt   ru   rm   Z
p_expectedr$   r$   r%   test_constants   s   	
#z+TestMusculotendonRigidTendon.test_constantsc                 C   sR   t | jdsJ tdg}| jj|ksJ t| jjtsJ | jjjdks'J d S )NMr(   rq   )rr   rk   rs   r   rt   ru   rm   Z
M_expectedr$   r$   r%   test_M   s
   
z#TestMusculotendonRigidTendon.test_Mc                 C   sT   t | jdsJ t| jg}| jj|ksJ t| jjtsJ | jjjdks(J d S )NFrq   )rr   rk   rs   rl   r   rt   ru   rm   Z
F_expectedr$   r$   r%   test_F   s
   z#TestMusculotendonRigidTendon.test_Fc                 C   s^   t | jdsJ t| jg}| j }t|tsJ |jdks!J t|| tdks-J d S )Nrhsrq   r(   )	rr   rk   rs   rl   r   rt   ru   r    r   rm   Zrhs_expectedr   r$   r$   r%   test_rhs   s   
z%TestMusculotendonRigidTendon.test_rhsN)r2   r3   r4   r?   fixturern   rw   r   r   r   r   r   r$   r$   r$   r%   rF   W   s    

(.rF   zmusculotendon_concrete, curve)tendon_force_lengthtendon_force_length_inversefiber_force_length_passiveZ"fiber_force_length_passive_inversefiber_force_length_activeZfiber_force_velocityfiber_force_velocity_inversec                   @   rE   )TestFiberLengthExplicitTrG   c           
      C   sl  d| _ td| _td| _td| _td| _| j| j| j| jj	  t
| j| j| _t| j | _| jj| _| jj| _| jj| _| jj| _| jj| _tj| _td| _td| _td| _td	| _td
| _td| _ || j | j| j| j| j| j| j| j| j| j dd| _!td| _"| jj#}| j"| j }|t$|d | jt%| j d   }|j&'|| j }|j('| j"}|j)'| j"}|j*'|| j || |  | j | | j|  }	| j| j |	 | _+d| jt,ddt,dd| j    t,ddt,ddt-| j| j| j     t,ddt,dd| j  | j t,ddt,ddt-| j| j| j      | j| j  | _.d S )NrH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   TrT   rU   rV   rW   rX   rY   rZ   with_defaultsZl_M_tilde_namer+   r(   r.   )/rH   r   rI   r   rJ   r   r[   r\   r]   r^   r   r_   r   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   r   r)   rj   r   rM   rN   rO   rP   rQ   rR   rk   	l_M_tildelengthr	   r
   r   r   r   r   r   dl_M_tilde_exprr   r   rl   )
rm   rD   curvel_MTl_Ml_TZfl_Tfl_M_pasfl_M_act	v_M_tilder$   r$   r%   ,_musculotendon_fiber_length_explicit_fixture   sn   















$"((

zDTestFiberLengthExplicit._musculotendon_fiber_length_explicit_fixturec                 C      t | jdsJ t | jdsJ | jj| jjksJ t| j| jg}| jj|ks*J | jj|ks2J t| jjts;J t| jjtsDJ | jjjdksMJ | jjjdksVJ d S Nr^   rp   r+   r(   )	rr   rk   r^   rp   rs   r   rc   rt   ru   rv   r$   r$   r%   rw   -     z'TestFiberLengthExplicit.test_state_varsc                 C   ro   ry   r|   r}   r$   r$   r%   r   9  rx   z'TestFiberLengthExplicit.test_input_varsc              
   C      t | jdsJ t | jdsJ | jj| jjksJ t| j| j| j| j| j	| j
| j| j| jg	}| jj|ks8J | jj|ks@J t| jjtsIJ t| jjtsRJ | jjjdks[J | jjjdksdJ d S Nr   r   )	   r(   rr   rk   r   r   rs   rM   rN   rO   rP   rQ   rR   re   rg   ri   rt   ru   r   r$   r$   r%   r   E  *   z&TestFiberLengthExplicit.test_constantsc                 C   P   t | jdsJ td}| jj|ksJ t| jjtsJ | jjjdks&J d S Nr   r+   )r+   r+   rr   rk   r   r   rt   rs   ru   r   r$   r$   r%   r   ]  
   zTestFiberLengthExplicit.test_Mc                 C   X   t | jdsJ t| j| jg}| jj|ksJ t| jjts!J | jjjdks*J d S Nr   r   )rr   rk   rs   r   rl   r   rt   ru   r   r$   r$   r%   r   d  
   zTestFiberLengthExplicit.test_Fc                 C   d   t | jdsJ t| j| jg}| j }t|tsJ |jdks#J t|| t	ddks0J d S Nr   r   r+   r(   )
rr   rk   rs   r   rl   r   rt   ru   r    r   r   r$   r$   r%   r   k     
z TestFiberLengthExplicit.test_rhsN)r2   r3   r4   r?   r   r   rw   r   r   r   r   r   r$   r$   r$   r%   r      s    

9r   c                   @   rE   )TestTendonForceExplicitTrG   c                 C   s  d| _ td| _td| _td| _td| _| j| j| j| jj	  t
| j| j| _t| j | _| jj| _| jj| _| jj| _| jj| _| jj| _tj| _td| _td| _td| _td	| _td
| _td| _ || j | j| j| j| j| j| j| j| j| j dd| _!td| _"|j#$| j"}| jj%}| jj&}|| j }t'|| d | jt(| j d  }|| j }|| | }	| j"| j }
|
|	 }|| j }|j)$|}|j*$|}|| | j|  }|j+$|}|| j }|||	  }|| j }t,dt,d t-t,dt.|t,d   | | _/d| jt0ddt0dd| j    t0ddt0ddt1| j| j| j     t0ddt0dd| j  | j t0ddt0ddt1| j| j| j      | j| j  | _2d S )NrH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   Tr   ZF_T_tilde_namer+   z0.2z33.93669377311689z0.995r(   r.   )3rH   r   rI   r   rJ   r   r[   r\   r]   r^   r   r_   r   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   r   r,   rj   r   rM   rN   rO   rP   rQ   rR   rk   	F_T_tilder   r   r   Zextension_velocityr	   r
   r   r   r   r   r   r   dF_T_tilde_exprr   r   rl   )rm   rD   r   Z	l_T_tilder   Zv_MTr   r   r   Z	cos_alphaZF_TZF_MZ	F_M_tilder   r   Zfv_Mr   Zv_MZv_TZ	v_T_tilder$   r$   r%   ,_musculotendon_tendon_force_explicit_fixture  s   
















$



"((

zDTestTendonForceExplicit._musculotendon_tendon_force_explicit_fixturec                 C   r   r   )	rr   rk   r^   rp   rs   r   rc   rt   ru   rv   r$   r$   r%   rw     r   z'TestTendonForceExplicit.test_state_varsc                 C   ro   ry   r|   r}   r$   r$   r%   r     rx   z'TestTendonForceExplicit.test_input_varsc              
   C   r   r   r   r   r$   r$   r%   r     r   z&TestTendonForceExplicit.test_constantsc                 C   r   r   r   r   r$   r$   r%   r     r   zTestTendonForceExplicit.test_Mc                 C   r   r   )rr   rk   rs   r   rl   r   rt   ru   r   r$   r$   r%   r     r   zTestTendonForceExplicit.test_Fc                 C   r   r   )
rr   rk   rs   r   rl   r   rt   ru   r    r   r   r$   r$   r%   r   
  r   z TestTendonForceExplicit.test_rhsN)r2   r3   r4   r?   r   r   rw   r   r   r   r   r   r$   r$   r$   r%   r   t  s    

Dr   c                
   @   s>  e Zd Zedd Zedd Zejdddd Zd	d
 Z	ej
ddedfededfeddeddfededfgdd Zej
ddedfededfededfededfgdd Zej
ddedfededfeddeddfededfgdd Zej
d ded!fed"ed"fed#ed#fed$ed$fgd%d& Zej
d'ded(fed)ed)fed*ed*fed+ed+fgd,d- Zej
d.ded/fed0ed0fed*ed*fedd#edd#fed+ed+fgd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< ZdS )=TestMusculotendonDeGroote2016c                   C   r<   )Nr   )r8   r   r   r   r2   r$   r$   r$   r%   r=     r>   z(TestMusculotendonDeGroote2016.test_classc                  C   s   t d} t d}|| tdtdj  t| |}td}td}td}td}td	}td
}td}	td||t	j
||||||	d
}
t|
tsLJ d S )NrK   rL   rJ   rI   rH   rM   rN   rO   rP   rQ   rR   rS   )r   r]   r   r   r^   r   r   r   r   r   r#   rt   )r[   r\   r_   r`   rM   rN   rO   rP   rQ   rR   rk   r$   r$   r%   test_instance  s0   
z+TestMusculotendonDeGroote2016.test_instanceTrG   c                 C   s   d| _ td| _td| _td| _td| _| j| j| j| jj	  t
| j| j| _t| j | _td| _td| _td| _td	| _td
| _td| _d S )NrH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   )rH   r   rI   r   rJ   r   r[   r\   r]   r^   r   r_   r   r`   r   rM   rN   rO   rP   rQ   rR   )rm   r$   r$   r%   _musculotendon_fixture6  s   








z4TestMusculotendonDeGroote2016._musculotendon_fixturec              	   C   s   t d}t d}||tdtdj  t||}td}td}td}td}td	}td
}	td}
t	j
d||tj|||d}|j|ksJJ |j|ksQJ |j|ksXJ |j|ks_J |j|	ksfJ |j|
ksmJ d S )NrK   rL   rJ   rI   rH   rM   rN   rO   10.0z0.00.1)rT   rU   rV   rW   )r   r]   r   r   r^   r   r   r   r   r   r   r   r#   rU   rV   rW   rX   rY   rZ   )rm   r[   r\   r_   r`   rM   rN   rO   rP   rQ   rR   rk   r$   r$   r%   test_with_defaultsG  s4   
	z0TestMusculotendonDeGroote2016.test_with_defaultszl_T_slack, expectedNZl_T_slack_namerM   r(   r+   z0.5c                 C   sN   t | j| j| jtj|| j| j| j| j	| j
d
}|j|ksJ |j|ks%J d S NrS   )r   rH   r_   r`   r   r#   rN   rO   rP   rQ   rR   rM   rU   )rm   rM   expectedrk   r$   r$   r%   test_tendon_slack_lengthc  s   
z6TestMusculotendonDeGroote2016.test_tendon_slack_lengthzF_M_max, expectedZF_M_max_namerN   i  z1000.0c                 C   sN   t | j| j| jtj| j|| j| j| j	| j
d
}|j|ksJ |j|ks%J d S r   )r   rH   r_   r`   r   r#   rM   rO   rP   rQ   rR   rN   rV   )rm   rN   r   rk   r$   r$   r%   test_peak_isometric_force|  s   
z7TestMusculotendonDeGroote2016.test_peak_isometric_forcezl_M_opt, expectedZl_M_opt_namerO   c                 C   sN   t | j| j| jtj| j| j|| j| j	| j
d
}|j|ksJ |j|ks%J d S r   )r   rH   r_   r`   r   r#   rM   rN   rP   rQ   rR   rO   rW   )rm   rO   r   rk   r$   r$   r%   test_optimal_fiber_length  s   
z7TestMusculotendonDeGroote2016.test_optimal_fiber_lengthzv_M_max, expectedZv_M_max_namerP   
   r   c                 C   sN   t | j| j| jtj| j| j| j|| j	| j
d
}|j|ksJ |j|ks%J d S r   )r   rH   r_   r`   r   r#   rM   rN   rO   rQ   rR   rP   rX   )rm   rP   r   rk   r$   r$   r%   test_maximal_fiber_velocity  s   
z9TestMusculotendonDeGroote2016.test_maximal_fiber_velocityzalpha_opt, expectedZalpha_opt_namerQ   r   r   c                 C   sN   t | j| j| jtj| j| j| j| j	|| j
d
}|j|ksJ |j|ks%J d S r   )r   rH   r_   r`   r   r#   rM   rN   rO   rP   rR   rQ   rY   )rm   rQ   r   rk   r$   r$   r%   test_optimal_pennation_angle  s   
z:TestMusculotendonDeGroote2016.test_optimal_pennation_anglezbeta, expectedZ	beta_namerR   c                 C   sN   t | j| j| jtj| j| j| j| j	| j
|d
}|j|ksJ |j|ks%J d S r   )r   rH   r_   r`   r   r#   rM   rN   rO   rP   rQ   rR   rZ   )rm   rR   r   rk   r$   r$   r%   test_fiber_damping_coefficient  s   z<TestMusculotendonDeGroote2016.test_fiber_damping_coefficientc                 C   sf   t | j| j| j}t|dsJ t|dsJ td}|j|ks"J |j|ks)J |j|ju s1J d S )Nrb   ra   Ze_name)r   rH   r_   r`   rr   r   rb   ra   )rm   rk   Z
e_expectedr$   r$   r%   test_excitation  s   z-TestMusculotendonDeGroote2016.test_excitationc                 C   sx   t | j| j| j}tt d |_W d    n1 sw   Y  tt d |_W d    d S 1 s5w   Y  d S r7   )	r   rH   r_   r`   r?   r@   AttributeErrorrb   ra   rm   rk   r$   r$   r%   test_excitation_is_immutable     "z:TestMusculotendonDeGroote2016.test_excitation_is_immutablec                 C   sV   t | j| j| j}t|dsJ t|dsJ td}|j|ks"J |j|ks)J d S )Nrc   r`   a_name)r   rH   r_   r`   rr   r   rc   )rm   rk   Z
a_expectedr$   r$   r%   test_activation  s   z-TestMusculotendonDeGroote2016.test_activationc                 C   sx   t | j| j| j}tt d |_W d    n1 sw   Y  tt d |_W d    d S 1 s5w   Y  d S r7   )r   rH   r_   r`   r?   r@   r   rc   r   r$   r$   r%   test_activation_is_immutable  r   z:TestMusculotendonDeGroote2016.test_activation_is_immutablec                 C   sH   t | j| j| jtj| j| j| j| j	| j
| jd
}d}t||ks"J d S )NrS   a  MusculotendonDeGroote2016('name', pathway=LinearPathway(pO, pI), activation_dynamics=FirstOrderActivationDeGroote2016('name', activation_time_constant=tau_a_name, deactivation_time_constant=tau_d_name, smoothing_rate=b_name), musculotendon_dynamics=0, tendon_slack_length=l_T_slack, peak_isometric_force=F_M_max, optimal_fiber_length=l_M_opt, maximal_fiber_velocity=v_M_max, optimal_pennation_angle=alpha_opt, fiber_damping_coefficient=beta))r   rH   r_   r`   r   r#   rM   rN   rO   rP   rQ   rR   repr)rm   rk   r   r$   r$   r%   	test_repr)  s   z'TestMusculotendonDeGroote2016.test_repr)r2   r3   r4   r5   r=   r   r?   r   r   r   markparametrizer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   r$   r$   r%   r     s    





	

	

	

	

	


r   )=__doc__r9   r?   Zsympy.core.exprr   Zsympy.core.numbersr   r   r   Zsympy.core.symbolr   Z&sympy.functions.elementary.exponentialr   Z%sympy.functions.elementary.hyperbolicr   Z(sympy.functions.elementary.miscellaneousr	   Z(sympy.functions.elementary.trigonometricr
   Zsympy.matrices.denser   rs   r   r   Z%sympy.physics.biomechanics.activationr   Z sympy.physics.biomechanics.curver   r   r   r   r   r   r   r   Z(sympy.physics.biomechanics.musculotendonr   r   r   Z!sympy.physics.biomechanics._mixinr   Z sympy.physics.mechanics.actuatorr   Zsympy.physics.mechanics.pathwayr   Zsympy.physics.vector.framer   Zsympy.physics.vector.functionsr   Zsympy.physics.vector.pointr   Zsympy.simplify.simplifyr    r!   r6   r   r   rF   r   r   r   r$   r$   r$   r%   <module>   sz    (
 	  