diff --git a/examples/ContinuumSnakeWithLiftingWaveCase/continuum_snake_with_lifting_wave.py b/examples/ContinuumSnakeWithLiftingWaveCase/continuum_snake_with_lifting_wave.py index ba18b198f..fec1fc909 100755 --- a/examples/ContinuumSnakeWithLiftingWaveCase/continuum_snake_with_lifting_wave.py +++ b/examples/ContinuumSnakeWithLiftingWaveCase/continuum_snake_with_lifting_wave.py @@ -13,7 +13,7 @@ plot_curvature, ) from snake_forcing import ( - MuscleTorques_lifting, + MuscleTorquesLifting, ) from snake_contact import SnakeRodPlaneContact @@ -113,8 +113,7 @@ def run_snake( lift_ratio = 1.0 # switch of lifting wave phase = 0.5 snake_sim.add_forcing_to(shearable_rod).using( - MuscleTorques_lifting, - base_length=base_length, + MuscleTorquesLifting, b_coeff=snake_torque_liftratio * lift_ratio * lift_amp, period=period, wave_number=2.0 * np.pi / (lift_wave_length), diff --git a/examples/ContinuumSnakeWithLiftingWaveCase/snake_contact.py b/examples/ContinuumSnakeWithLiftingWaveCase/snake_contact.py index e2c0da834..68dea81dd 100755 --- a/examples/ContinuumSnakeWithLiftingWaveCase/snake_contact.py +++ b/examples/ContinuumSnakeWithLiftingWaveCase/snake_contact.py @@ -275,7 +275,7 @@ def __init__( 1D (3,) array containing data with 'float' type. [forward, backward, sideways] kinetic friction coefficients. """ - super(SnakeRodPlaneContact, self).__init__() + super().__init__() self.k = k self.nu = nu self.surface_tol = 1e-4 diff --git a/examples/ContinuumSnakeWithLiftingWaveCase/snake_forcing.py b/examples/ContinuumSnakeWithLiftingWaveCase/snake_forcing.py index 31664e1c8..3b471acad 100755 --- a/examples/ContinuumSnakeWithLiftingWaveCase/snake_forcing.py +++ b/examples/ContinuumSnakeWithLiftingWaveCase/snake_forcing.py @@ -16,7 +16,7 @@ ) -class MuscleTorques_lifting(NoForces): +class MuscleTorquesLifting(NoForces): """ This class applies muscle torques along the body. The applied muscle torques are treated as applied external forces. This class can apply lifting @@ -43,7 +43,6 @@ class MuscleTorques_lifting(NoForces): def __init__( self, - base_length, b_coeff, period, wave_number, @@ -53,15 +52,11 @@ def __init__( ramp_up_time=0.0, with_spline=False, switch_on_time=0.0, - *args, - **kwargs, ): """ Parameters ---------- - base_length: float - Rest length of the rod-like object. b_coeff: nump.ndarray 1D array containing data with 'float' type. Beta coefficients for beta-spline. @@ -81,7 +76,7 @@ def __init__( time to switch on the muscle activation. """ - super(MuscleTorques_lifting, self).__init__() + super().__init__() self.direction = direction # Direction torque applied self.angular_frequency = 2.0 * np.pi / period @@ -104,32 +99,16 @@ def __init__( if with_spline: assert b_coeff.size != 0, "Beta spline coefficient array (t_coeff) is empty" - my_spline, ctr_pts, ctr_coeffs = _bspline(b_coeff) - self.my_spline = my_spline(self.s) + spline, ctr_pts, ctr_coeffs = _bspline(b_coeff) + self.spline = spline(self.s) else: - - def constant_function(input): - """ - Return array of ones same as the size of the input array. This - function is called when Beta spline function is not used. - - Parameters - ---------- - input - - Returns - ------- - - """ - return np.ones(input.shape) - - self.my_spline = constant_function(self.s) + self.spline = np.full_like(self.s) def apply_torques(self, system, time: np.float64 = 0.0): self.compute_muscle_torques( time, - self.my_spline, + self.spline, self.s, self.angular_frequency, self.wave_number, @@ -146,7 +125,7 @@ def apply_torques(self, system, time: np.float64 = 0.0): @njit(cache=True) def compute_muscle_torques( time, - my_spline, + spline, s, angular_frequency, wave_number, @@ -167,7 +146,7 @@ def compute_muscle_torques( # front of wave number is positive, in Elastica cpp it is negative. torque_mag = ( factor - * my_spline + * spline * np.sin( angular_frequency * (time - switch_on_time - phase_shift) - wave_number * s