Skip to content

Commit

Permalink
Minor name and style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-7800 committed Dec 3, 2023
1 parent c447ae1 commit 1273c13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
plot_curvature,
)
from snake_forcing import (
MuscleTorques_lifting,
MuscleTorquesLifting,
)
from snake_contact import SnakeRodPlaneContact

Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 8 additions & 29 deletions examples/ContinuumSnakeWithLiftingWaveCase/snake_forcing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +43,6 @@ class MuscleTorques_lifting(NoForces):

def __init__(
self,
base_length,
b_coeff,
period,
wave_number,
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 1273c13

Please sign in to comment.