Skip to content

Commit

Permalink
remove ambiguity: np.integer -> np.int32, np.floating -> np.float64
Browse files Browse the repository at this point in the history
  • Loading branch information
skim0119 committed Jun 26, 2024
1 parent 9b267af commit e3ac13e
Show file tree
Hide file tree
Showing 56 changed files with 949 additions and 959 deletions.
24 changes: 12 additions & 12 deletions elastica/_calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@functools.lru_cache(maxsize=2)
def _get_zero_array(dim: int, ndim: int) -> Union[float, NDArray[np.floating], None]:
def _get_zero_array(dim: int, ndim: int) -> Union[float, NDArray[np.float64], None]:
if ndim == 1:
return 0.0
if ndim == 2:
Expand All @@ -22,7 +22,7 @@ def _get_zero_array(dim: int, ndim: int) -> Union[float, NDArray[np.floating], N


@njit(cache=True) # type: ignore
def _trapezoidal(array_collection: NDArray[np.floating]) -> NDArray[np.floating]:
def _trapezoidal(array_collection: NDArray[np.float64]) -> NDArray[np.float64]:
"""
Simple trapezoidal quadrature rule with zero at end-points, in a dimension agnostic way
Expand Down Expand Up @@ -69,8 +69,8 @@ def _trapezoidal(array_collection: NDArray[np.floating]) -> NDArray[np.floating]

@njit(cache=True) # type: ignore
def _trapezoidal_for_block_structure(
array_collection: NDArray[np.floating], ghost_idx: NDArray[np.integer]
) -> NDArray[np.floating]:
array_collection: NDArray[np.float64], ghost_idx: NDArray[np.int32]
) -> NDArray[np.float64]:
"""
Simple trapezoidal quadrature rule with zero at end-points, in a dimension agnostic way. This form
specifically for the block structure implementation and there is a reset function call, to reset
Expand Down Expand Up @@ -123,8 +123,8 @@ def _trapezoidal_for_block_structure(

@njit(cache=True) # type: ignore
def _two_point_difference(
array_collection: NDArray[np.floating],
) -> NDArray[np.floating]:
array_collection: NDArray[np.float64],
) -> NDArray[np.float64]:
"""
This function does differentiation.
Expand Down Expand Up @@ -166,8 +166,8 @@ def _two_point_difference(

@njit(cache=True) # type: ignore
def _two_point_difference_for_block_structure(
array_collection: NDArray[np.floating], ghost_idx: NDArray[np.integer]
) -> NDArray[np.floating]:
array_collection: NDArray[np.float64], ghost_idx: NDArray[np.int32]
) -> NDArray[np.float64]:
"""
This function does the differentiation, for Cosserat rod model equations. This form
specifically for the block structure implementation and there is a reset function call, to
Expand Down Expand Up @@ -218,7 +218,7 @@ def _two_point_difference_for_block_structure(


@njit(cache=True) # type: ignore
def _difference(vector: NDArray[np.floating]) -> NDArray[np.floating]:
def _difference(vector: NDArray[np.float64]) -> NDArray[np.float64]:
"""
This function computes difference between elements of a batch vector.
Expand Down Expand Up @@ -249,7 +249,7 @@ def _difference(vector: NDArray[np.floating]) -> NDArray[np.floating]:


@njit(cache=True) # type: ignore
def _average(vector: NDArray[np.floating]) -> NDArray[np.floating]:
def _average(vector: NDArray[np.float64]) -> NDArray[np.float64]:
"""
This function computes the average between elements of a vector.
Expand Down Expand Up @@ -280,8 +280,8 @@ def _average(vector: NDArray[np.floating]) -> NDArray[np.floating]:

@njit(cache=True) # type: ignore
def _clip_array(
input_array: NDArray[np.floating], vmin: np.floating, vmax: np.floating
) -> NDArray[np.floating]:
input_array: NDArray[np.float64], vmin: np.float64, vmax: np.float64
) -> NDArray[np.float64]:
"""
This function clips an array values
between user defined minimum and maximum
Expand Down
210 changes: 105 additions & 105 deletions elastica/_contact_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@

@njit(cache=True) # type: ignore
def _calculate_contact_forces_rod_cylinder(
x_collection_rod: NDArray[np.floating],
edge_collection_rod: NDArray[np.floating],
x_cylinder_center: NDArray[np.floating],
x_cylinder_tip: NDArray[np.floating],
edge_cylinder: NDArray[np.floating],
radii_sum: NDArray[np.floating],
length_sum: NDArray[np.floating],
internal_forces_rod: NDArray[np.floating],
external_forces_rod: NDArray[np.floating],
external_forces_cylinder: NDArray[np.floating],
external_torques_cylinder: NDArray[np.floating],
cylinder_director_collection: NDArray[np.floating],
velocity_rod: NDArray[np.floating],
velocity_cylinder: NDArray[np.floating],
contact_k: np.floating,
contact_nu: np.floating,
velocity_damping_coefficient: np.floating,
friction_coefficient: np.floating,
x_collection_rod: NDArray[np.float64],
edge_collection_rod: NDArray[np.float64],
x_cylinder_center: NDArray[np.float64],
x_cylinder_tip: NDArray[np.float64],
edge_cylinder: NDArray[np.float64],
radii_sum: NDArray[np.float64],
length_sum: NDArray[np.float64],
internal_forces_rod: NDArray[np.float64],
external_forces_rod: NDArray[np.float64],
external_forces_cylinder: NDArray[np.float64],
external_torques_cylinder: NDArray[np.float64],
cylinder_director_collection: NDArray[np.float64],
velocity_rod: NDArray[np.float64],
velocity_cylinder: NDArray[np.float64],
contact_k: np.float64,
contact_nu: np.float64,
velocity_damping_coefficient: np.float64,
friction_coefficient: np.float64,
) -> None:
# We already pass in only the first n_elem x
n_points = x_collection_rod.shape[1]
Expand Down Expand Up @@ -157,22 +157,22 @@ def _calculate_contact_forces_rod_cylinder(

@njit(cache=True) # type: ignore
def _calculate_contact_forces_rod_rod(
x_collection_rod_one: NDArray[np.floating],
radius_rod_one: NDArray[np.floating],
length_rod_one: NDArray[np.floating],
tangent_rod_one: NDArray[np.floating],
velocity_rod_one: NDArray[np.floating],
internal_forces_rod_one: NDArray[np.floating],
external_forces_rod_one: NDArray[np.floating],
x_collection_rod_two: NDArray[np.floating],
radius_rod_two: NDArray[np.floating],
length_rod_two: NDArray[np.floating],
tangent_rod_two: NDArray[np.floating],
velocity_rod_two: NDArray[np.floating],
internal_forces_rod_two: NDArray[np.floating],
external_forces_rod_two: NDArray[np.floating],
contact_k: np.floating,
contact_nu: np.floating,
x_collection_rod_one: NDArray[np.float64],
radius_rod_one: NDArray[np.float64],
length_rod_one: NDArray[np.float64],
tangent_rod_one: NDArray[np.float64],
velocity_rod_one: NDArray[np.float64],
internal_forces_rod_one: NDArray[np.float64],
external_forces_rod_one: NDArray[np.float64],
x_collection_rod_two: NDArray[np.float64],
radius_rod_two: NDArray[np.float64],
length_rod_two: NDArray[np.float64],
tangent_rod_two: NDArray[np.float64],
velocity_rod_two: NDArray[np.float64],
internal_forces_rod_two: NDArray[np.float64],
external_forces_rod_two: NDArray[np.float64],
contact_k: np.float64,
contact_nu: np.float64,
) -> None:
# We already pass in only the first n_elem x
n_points_rod_one = x_collection_rod_one.shape[1]
Expand Down Expand Up @@ -274,14 +274,14 @@ def _calculate_contact_forces_rod_rod(

@njit(cache=True) # type: ignore
def _calculate_contact_forces_self_rod(
x_collection_rod: NDArray[np.floating],
radius_rod: NDArray[np.floating],
length_rod: NDArray[np.floating],
tangent_rod: NDArray[np.floating],
velocity_rod: NDArray[np.floating],
external_forces_rod: NDArray[np.floating],
contact_k: np.floating,
contact_nu: np.floating,
x_collection_rod: NDArray[np.float64],
radius_rod: NDArray[np.float64],
length_rod: NDArray[np.float64],
tangent_rod: NDArray[np.float64],
velocity_rod: NDArray[np.float64],
external_forces_rod: NDArray[np.float64],
contact_k: np.float64,
contact_nu: np.float64,
) -> None:
# We already pass in only the first n_elem x
n_points_rod = x_collection_rod.shape[1]
Expand Down Expand Up @@ -362,24 +362,24 @@ def _calculate_contact_forces_self_rod(

@njit(cache=True) # type: ignore
def _calculate_contact_forces_rod_sphere(
x_collection_rod: NDArray[np.floating],
edge_collection_rod: NDArray[np.floating],
x_sphere_center: NDArray[np.floating],
x_sphere_tip: NDArray[np.floating],
edge_sphere: NDArray[np.floating],
radii_sum: NDArray[np.floating],
length_sum: NDArray[np.floating],
internal_forces_rod: NDArray[np.floating],
external_forces_rod: NDArray[np.floating],
external_forces_sphere: NDArray[np.floating],
external_torques_sphere: NDArray[np.floating],
sphere_director_collection: NDArray[np.floating],
velocity_rod: NDArray[np.floating],
velocity_sphere: NDArray[np.floating],
contact_k: np.floating,
contact_nu: np.floating,
velocity_damping_coefficient: np.floating,
friction_coefficient: np.floating,
x_collection_rod: NDArray[np.float64],
edge_collection_rod: NDArray[np.float64],
x_sphere_center: NDArray[np.float64],
x_sphere_tip: NDArray[np.float64],
edge_sphere: NDArray[np.float64],
radii_sum: NDArray[np.float64],
length_sum: NDArray[np.float64],
internal_forces_rod: NDArray[np.float64],
external_forces_rod: NDArray[np.float64],
external_forces_sphere: NDArray[np.float64],
external_torques_sphere: NDArray[np.float64],
sphere_director_collection: NDArray[np.float64],
velocity_rod: NDArray[np.float64],
velocity_sphere: NDArray[np.float64],
contact_k: np.float64,
contact_nu: np.float64,
velocity_damping_coefficient: np.float64,
friction_coefficient: np.float64,
) -> None:
# We already pass in only the first n_elem x
n_points = x_collection_rod.shape[1]
Expand Down Expand Up @@ -488,18 +488,18 @@ def _calculate_contact_forces_rod_sphere(

@njit(cache=True) # type: ignore
def _calculate_contact_forces_rod_plane(
plane_origin: NDArray[np.floating],
plane_normal: NDArray[np.floating],
surface_tol: np.floating,
k: np.floating,
nu: np.floating,
radius: NDArray[np.floating],
mass: NDArray[np.floating],
position_collection: NDArray[np.floating],
velocity_collection: NDArray[np.floating],
internal_forces: NDArray[np.floating],
external_forces: NDArray[np.floating],
) -> tuple[NDArray[np.floating], NDArray[np.intp]]:
plane_origin: NDArray[np.float64],
plane_normal: NDArray[np.float64],
surface_tol: np.float64,
k: np.float64,
nu: np.float64,
radius: NDArray[np.float64],
mass: NDArray[np.float64],
position_collection: NDArray[np.float64],
velocity_collection: NDArray[np.float64],
internal_forces: NDArray[np.float64],
external_forces: NDArray[np.float64],
) -> tuple[NDArray[np.float64], NDArray[np.intp]]:
"""
This function computes the plane force response on the element, in the
case of contact. Contact model given in Eqn 4.8 Gazzola et. al. RSoS 2018 paper
Expand Down Expand Up @@ -573,29 +573,29 @@ def _calculate_contact_forces_rod_plane(

@njit(cache=True) # type: ignore
def _calculate_contact_forces_rod_plane_with_anisotropic_friction(
plane_origin: NDArray[np.floating],
plane_normal: NDArray[np.floating],
surface_tol: np.floating,
slip_velocity_tol: np.floating,
k: np.floating,
nu: np.floating,
kinetic_mu_forward: np.floating,
kinetic_mu_backward: np.floating,
kinetic_mu_sideways: np.floating,
static_mu_forward: np.floating,
static_mu_backward: np.floating,
static_mu_sideways: np.floating,
radius: NDArray[np.floating],
mass: NDArray[np.floating],
tangents: NDArray[np.floating],
position_collection: NDArray[np.floating],
director_collection: NDArray[np.floating],
velocity_collection: NDArray[np.floating],
omega_collection: NDArray[np.floating],
internal_forces: NDArray[np.floating],
external_forces: NDArray[np.floating],
internal_torques: NDArray[np.floating],
external_torques: NDArray[np.floating],
plane_origin: NDArray[np.float64],
plane_normal: NDArray[np.float64],
surface_tol: np.float64,
slip_velocity_tol: np.float64,
k: np.float64,
nu: np.float64,
kinetic_mu_forward: np.float64,
kinetic_mu_backward: np.float64,
kinetic_mu_sideways: np.float64,
static_mu_forward: np.float64,
static_mu_backward: np.float64,
static_mu_sideways: np.float64,
radius: NDArray[np.float64],
mass: NDArray[np.float64],
tangents: NDArray[np.float64],
position_collection: NDArray[np.float64],
director_collection: NDArray[np.float64],
velocity_collection: NDArray[np.float64],
omega_collection: NDArray[np.float64],
internal_forces: NDArray[np.float64],
external_forces: NDArray[np.float64],
internal_torques: NDArray[np.float64],
external_torques: NDArray[np.float64],
) -> None:
(
plane_response_force_mag,
Expand Down Expand Up @@ -786,16 +786,16 @@ def _calculate_contact_forces_rod_plane_with_anisotropic_friction(

@njit(cache=True) # type: ignore
def _calculate_contact_forces_cylinder_plane(
plane_origin: NDArray[np.floating],
plane_normal: NDArray[np.floating],
surface_tol: np.floating,
k: np.floating,
nu: np.floating,
length: NDArray[np.floating],
position_collection: NDArray[np.floating],
velocity_collection: NDArray[np.floating],
external_forces: NDArray[np.floating],
) -> tuple[NDArray[np.floating], NDArray[np.intp]]:
plane_origin: NDArray[np.float64],
plane_normal: NDArray[np.float64],
surface_tol: np.float64,
k: np.float64,
nu: np.float64,
length: NDArray[np.float64],
position_collection: NDArray[np.float64],
velocity_collection: NDArray[np.float64],
external_forces: NDArray[np.float64],
) -> tuple[NDArray[np.float64], NDArray[np.intp]]:

# Compute plane response force
# total_forces = system.internal_forces + system.external_forces
Expand Down
Loading

0 comments on commit e3ac13e

Please sign in to comment.