o
    g                     @   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$   j/var/www/visachat/venv/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   FIBER_LENGTH_IMPLICITr$   r$   r$   r%   !test_fiber_length_implicit_member:   r'   z>TestMusculotendonFormulation.test_fiber_length_implicit_memberc                   C   r"   )N   )r   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-   r0   r3   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   )r:   r   r   r   r4   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 r9   )pytestraises	TypeErrorr   )_r$   r$   r%    test_cannot_instantiate_directlyQ   s   "z6TestMusculotendonBase.test_cannot_instantiate_directlyN)r4   r5   r6   r7   r=   r?   rE   r$   r$   r$   r%   r8   E   s    

r8   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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.   )%rK   r   rL   r   rM   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   rP   rQ   rR   rS   rT   rU   instancer   r   da_expr)selfrF   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 )Nra   
state_varsr(   r(   )hasattrrn   ra   rs   Matrixrf   
isinstanceshaperp   
x_expectedr$   r$   r%   test_state_vars      z,TestMusculotendonRigidTendon.test_state_varsc                 C   rr   Nr
input_varsrt   ru   rn   r~   r   rv   re   rw   rx   rp   
r_expectedr$   r$   r%   test_input_vars   r|   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	constantsc_0_fl_T_namec_1_fl_T_namec_2_fl_T_namec_3_fl_T_namec_0_fl_M_pas_namec_1_fl_M_pas_namec_0_fl_M_act_namec_1_fl_M_act_namec_2_fl_M_act_namec_3_fl_M_act_namec_4_fl_M_act_namec_5_fl_M_act_namec_6_fl_M_act_namec_7_fl_M_act_namec_8_fl_M_act_namec_9_fl_M_act_namec_10_fl_M_act_namec_11_fl_M_act_namec_0_fv_M_namec_1_fv_M_namec_2_fv_M_namec_3_fv_M_name)   r(   )ru   rn   r   r   rv   rP   rQ   rR   rS   rT   rU   rh   rj   rl   r   rw   rx   rp   
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(   rt   )ru   rn   rv   r   rw   rx   rp   
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Frt   )ru   rn   rv   ro   r   rw   rx   rp   
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rhsrt   r(   )	ru   rn   rv   ro   r   rw   rx   r    r   rp   rhs_expectedr   r$   r$   r%   test_rhs   s   
z%TestMusculotendonRigidTendon.test_rhsN)r4   r5   r6   rA   fixturerq   r{   r   r   r   r   r   r$   r$   r$   r%   rH   W   s    

(.rH   zmusculotendon_concrete, curve)tendon_force_lengthtendon_force_length_inversefiber_force_length_passive"fiber_force_length_passive_inversefiber_force_length_activefiber_force_velocityfiber_force_velocity_inversec                   @   rG   )TestFiberLengthExplicitTrI   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 )NrK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   TrW   rX   rY   rZ   r[   r\   r]   with_defaultsl_M_tilde_namer+   r(   r.   )/rK   r   rL   r   rM   r   r^   r_   r`   ra   r   rb   r   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   r   r)   rm   r   rP   rQ   rR   rS   rT   rU   rn   	l_M_tildelengthr	   r
   r   r   r   r   r   dl_M_tilde_exprr   r   ro   )
rp   rF   curvel_MTl_Ml_T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 Nra   rs   r+   r(   )	ru   rn   ra   rs   rv   r   rf   rw   rx   ry   r$   r$   r%   r{   -     z'TestFiberLengthExplicit.test_state_varsc                 C   rr   r}   r   r   r$   r$   r%   r   9  r|   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(   ru   rn   r   r   rv   rP   rQ   rR   rS   rT   rU   rh   rj   rl   rw   rx   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+   ru   rn   r   r   rw   rv   rx   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   )ru   rn   rv   r   ro   r   rw   rx   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(   )
ru   rn   rv   r   ro   r   rw   rx   r    r   r   r$   r$   r%   r   k     
z TestFiberLengthExplicit.test_rhsN)r4   r5   r6   rA   r   r   r{   r   r   r   r   r   r$   r$   r$   r%   r      s    

9r   c                   @   rG   )TestTendonForceExplicitTrI   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 )NrK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   Tr   F_T_tilde_namer+   z0.2z33.93669377311689z0.995r(   r.   )3rK   r   rL   r   rM   r   r^   r_   r`   ra   r   rb   r   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   r   r,   rm   r   rP   rQ   rR   rS   rT   rU   rn   	F_T_tilder   r   r   extension_velocityr	   r
   r   r   r   r   r   r   dF_T_tilde_exprr   r   ro   )rp   rF   r   	l_T_tilder   v_MTr   r   r   	cos_alphaF_TF_M	F_M_tilder   r   fv_Mr   v_Mv_T	v_T_tilder$   r$   r%   ,_musculotendon_tendon_force_explicit_fixture  s   
















$



"((

zDTestTendonForceExplicit._musculotendon_tendon_force_explicit_fixturec                 C   r   r   )	ru   rn   ra   rs   rv   r   rf   rw   rx   ry   r$   r$   r%   r{     r   z'TestTendonForceExplicit.test_state_varsc                 C   rr   r}   r   r   r$   r$   r%   r     r|   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   )ru   rn   rv   r   ro   r   rw   rx   r   r$   r$   r%   r     r   zTestTendonForceExplicit.test_Fc                 C   r   r   )
ru   rn   rv   r   ro   r   rw   rx   r    r   r   r$   r$   r%   r   
  r   z TestTendonForceExplicit.test_rhsN)r4   r5   r6   rA   r   r   r{   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   )r:   r   r   r   r4   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 )NrN   rO   rM   rL   rK   rP   rQ   rR   rS   rT   rU   rV   )r   r`   r   r   ra   r   r   r   r   r   r#   rw   )r^   r_   rb   rc   rP   rQ   rR   rS   rT   rU   rn   r$   r$   r%   test_instance  s0   
z+TestMusculotendonDeGroote2016.test_instanceTrI   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 )NrK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   )rK   r   rL   r   rM   r   r^   r_   r`   ra   r   rb   r   rc   r   rP   rQ   rR   rS   rT   rU   )rp   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 )NrN   rO   rM   rL   rK   rP   rQ   rR   10.0z0.00.1)rW   rX   rY   rZ   )r   r`   r   r   ra   r   r   r   r   r   r   r   r#   rX   rY   rZ   r[   r\   r]   )rp   r^   r_   rb   rc   rP   rQ   rR   rS   rT   rU   rn   r$   r$   r%   test_with_defaultsG  s4   
	z0TestMusculotendonDeGroote2016.test_with_defaultszl_T_slack, expectedNl_T_slack_namerP   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 NrV   )r   rK   rb   rc   r   r#   rQ   rR   rS   rT   rU   rP   rX   )rp   rP   expectedrn   r$   r$   r%   test_tendon_slack_lengthc  s   
z6TestMusculotendonDeGroote2016.test_tendon_slack_lengthzF_M_max, expectedF_M_max_namerQ   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   rK   rb   rc   r   r#   rP   rR   rS   rT   rU   rQ   rY   )rp   rQ   r   rn   r$   r$   r%   test_peak_isometric_force|  s   
z7TestMusculotendonDeGroote2016.test_peak_isometric_forcezl_M_opt, expectedl_M_opt_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   rK   rb   rc   r   r#   rP   rQ   rS   rT   rU   rR   rZ   )rp   rR   r   rn   r$   r$   r%   test_optimal_fiber_length  s   
z7TestMusculotendonDeGroote2016.test_optimal_fiber_lengthzv_M_max, expectedv_M_max_namerS   
   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   rK   rb   rc   r   r#   rP   rQ   rR   rT   rU   rS   r[   )rp   rS   r   rn   r$   r$   r%   test_maximal_fiber_velocity  s   
z9TestMusculotendonDeGroote2016.test_maximal_fiber_velocityzalpha_opt, expectedalpha_opt_namerT   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   rK   rb   rc   r   r#   rP   rQ   rR   rS   rU   rT   r\   )rp   rT   r   rn   r$   r$   r%   test_optimal_pennation_angle  s   
z:TestMusculotendonDeGroote2016.test_optimal_pennation_anglezbeta, expected	beta_namerU   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   rK   rb   rc   r   r#   rP   rQ   rR   rS   rT   rU   r]   )rp   rU   r   rn   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 )Nre   rd   e_name)r   rK   rb   rc   ru   r   re   rd   )rp   rn   
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 r9   )	r   rK   rb   rc   rA   rB   AttributeErrorre   rd   rp   rn   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 )Nrf   rc   a_name)r   rK   rb   rc   ru   r   rf   )rp   rn   
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 r9   )r   rK   rb   rc   rA   rB   r   rf   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 )NrV   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   rK   rb   rc   r   r#   rP   rQ   rR   rS   rT   rU   repr)rp   rn   r   r$   r$   r%   	test_repr)  s   z'TestMusculotendonDeGroote2016.test_repr)r4   r5   r6   r7   r?   r   rA   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__r;   rA   sympy.core.exprr   sympy.core.numbersr   r   r   sympy.core.symbolr   &sympy.functions.elementary.exponentialr   %sympy.functions.elementary.hyperbolicr   (sympy.functions.elementary.miscellaneousr	   (sympy.functions.elementary.trigonometricr
   sympy.matrices.denser   rv   r   r   %sympy.physics.biomechanics.activationr    sympy.physics.biomechanics.curver   r   r   r   r   r   r   r   (sympy.physics.biomechanics.musculotendonr   r   r   !sympy.physics.biomechanics._mixinr    sympy.physics.mechanics.actuatorr   sympy.physics.mechanics.pathwayr   sympy.physics.vector.framer   sympy.physics.vector.functionsr   sympy.physics.vector.pointr   sympy.simplify.simplifyr    r!   r8   r	  r
  rH   r   r   r   r$   r$   r$   r%   <module>   sz    (
 	  