Skip to content

Commit

Permalink
Merge branch 'update-0.3.1' into 169_update_visualization_example
Browse files Browse the repository at this point in the history
  • Loading branch information
bhosale2 authored Feb 24, 2023
2 parents 253c057 + addd631 commit b44dbb1
Show file tree
Hide file tree
Showing 61 changed files with 1,198 additions and 604 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10"]
os: [ubuntu-latest, macos-latest] #, windows-latest] # Run macos tests if really required, since they charge 10 times more for macos
include:
- os: ubuntu-latest
path: ~/.cache/pip
- os: macos-latest
path: ~/Library/Caches/pip
# - os: windows-latest
# path: ~\AppData\Local\pip\Cache
#- os: windows-latest
# path: ~\AppData\Local\pip\Cache
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand Down Expand Up @@ -102,6 +102,6 @@ jobs:
run: |
make test_coverage_xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#* Variables
PYTHON := python3
PYTHONPATH := `pwd`
AUTOFLAKE8_ARGS := -r --exclude '__init__.py' --keep-pass-after-docstring
#* Poetry
.PHONY: poetry-download
poetry-download:
Expand Down Expand Up @@ -46,6 +47,17 @@ flake8:
poetry run flake8 --version
poetry run flake8 elastica tests

.PHONY: autoflake8-check
autoflake8-check:
poetry run autoflake8 --version
poetry run autoflake8 $(AUTOFLAKE8_ARGS) elastica tests examples
poetry run autoflake8 --check $(AUTOFLAKE8_ARGS) elastica tests examples

.PHONY: autoflake8-format
autoflake8-format:
poetry run autoflake8 --version
poetry run autoflake8 --in-place $(AUTOFLAKE8_ARGS) elastica tests examples

.PHONY: format-codestyle
format-codestyle: black flake8

Expand All @@ -62,7 +74,7 @@ test_coverage_xml:
NUMBA_DISABLE_JIT=1 poetry run pytest --cov=elastica --cov-report=xml

.PHONY: check-codestyle
check-codestyle: black-check flake8
check-codestyle: black-check flake8 autoflake8-check

.PHONY: formatting
formatting: format-codestyle
Expand Down
1 change: 0 additions & 1 deletion elastica/_calculus.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__doc__ = """ Quadrature and difference kernels """
import numpy as np
from numpy import zeros, empty
import numba
from numba import njit
from elastica.reset_functions_for_block_structure._reset_ghost_vector_or_scalar import (
_reset_vector_ghost,
Expand Down
1 change: 0 additions & 1 deletion elastica/_linalg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
__doc__ = """ Convenient linear algebra kernels """
import numpy as np
import numba
from numba import njit
from numpy import sqrt
import functools
Expand Down
1 change: 0 additions & 1 deletion elastica/_rotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from numpy import sqrt
from numpy import arccos

import numba
from numba import njit

from elastica._linalg import _batch_matmul
Expand Down
81 changes: 29 additions & 52 deletions elastica/boundary_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@
]

import warnings
from typing import Optional, Type, Union
from typing import Optional

import numpy as np

from abc import ABC, abstractmethod

import numba
from numba import njit

from elastica._linalg import _batch_matvec, _batch_matrix_transpose
from elastica._rotations import _get_rotation_matrix
from elastica.rod import RodBase
from elastica.rigidbody import RigidBodyBase
from elastica.typing import SystemType
from elastica.typing import SystemType, RodType


class ConstraintBase(ABC):
Expand All @@ -41,7 +38,7 @@ class ConstraintBase(ABC):
"""

_system: Union[Type[RodBase], Type[RigidBodyBase]]
_system: SystemType
_constrained_position_idx: np.ndarray
_constrained_director_idx: np.ndarray

Expand All @@ -61,7 +58,7 @@ def __init__(self, *args, **kwargs):
)

@property
def system(self) -> Union[Type[RodBase], Type[RigidBodyBase]]:
def system(self) -> SystemType:
"""get system (rod or rigid body) reference"""
return self._system

Expand All @@ -78,33 +75,29 @@ def constrained_director_idx(self) -> Optional[np.ndarray]:
return self._constrained_director_idx

@abstractmethod
def constrain_values(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
def constrain_values(self, system: SystemType, time: float) -> None:
# TODO: In the future, we can remove rod and use self.system
"""
Constrain values (position and/or directors) of a rod object.
Parameters
----------
rod : Union[Type[RodBase], Type[RigidBodyBase]]
system : SystemType
Rod or rigid-body object.
time : float
The time of simulation.
"""
pass

@abstractmethod
def constrain_rates(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
def constrain_rates(self, system: SystemType, time: float) -> None:
# TODO: In the future, we can remove rod and use self.system
"""
Constrain rates (velocity and/or omega) of a rod object.
Parameters
----------
rod : Union[Type[RodBase], Type[RigidBodyBase]]
system : SystemType
Rod or rigid-body object.
time : float
The time of simulation.
Expand All @@ -121,15 +114,11 @@ class FreeBC(ConstraintBase):
def __init__(self, **kwargs):
super().__init__(**kwargs)

def constrain_values(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
def constrain_values(self, system: SystemType, time: float) -> None:
"""In FreeBC, this routine simply passes."""
pass

def constrain_rates(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
def constrain_rates(self, system: SystemType, time: float) -> None:
"""In FreeBC, this routine simply passes."""
pass

Expand Down Expand Up @@ -178,26 +167,22 @@ def __init__(self, fixed_position, fixed_directors, **kwargs):
self.fixed_position_collection = np.array(fixed_position)
self.fixed_directors_collection = np.array(fixed_directors)

def constrain_values(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
# rod.position_collection[..., 0] = self.fixed_position
# rod.director_collection[..., 0] = self.fixed_directors
def constrain_values(self, system: SystemType, time: float) -> None:
# system.position_collection[..., 0] = self.fixed_position
# system.director_collection[..., 0] = self.fixed_directors
self.compute_constrain_values(
rod.position_collection,
system.position_collection,
self.fixed_position_collection,
rod.director_collection,
system.director_collection,
self.fixed_directors_collection,
)

def constrain_rates(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
# rod.velocity_collection[..., 0] = 0.0
# rod.omega_collection[..., 0] = 0.0
def constrain_rates(self, system: SystemType, time: float) -> None:
# system.velocity_collection[..., 0] = 0.0
# system.omega_collection[..., 0] = 0.0
self.compute_constrain_rates(
rod.velocity_collection,
rod.omega_collection,
system.velocity_collection,
system.omega_collection,
)

@staticmethod
Expand Down Expand Up @@ -270,7 +255,7 @@ class GeneralConstraint(ConstraintBase):
--------
How to fix all translational and rotational dof except allowing twisting around the z-axis in an inertial frame:
>>> simulator.constrain(rod).using(
>>> simulator.constrain(system).using(
... GeneralConstraint,
... constrained_position_idx=(0,),
... constrained_director_idx=(0,),
Expand Down Expand Up @@ -531,33 +516,29 @@ def __init__(self, *args, **kwargs):
**kwargs,
)

def constrain_values(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
def constrain_values(self, system: SystemType, time: float) -> None:
if self.constrained_position_idx.size:
self.nb_constrain_translational_values(
rod.position_collection,
system.position_collection,
self.fixed_positions,
self.constrained_position_idx,
)
if self.constrained_director_idx.size:
self.nb_constraint_rotational_values(
rod.director_collection,
system.director_collection,
self.fixed_directors,
self.constrained_director_idx,
)

def constrain_rates(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
def constrain_rates(self, system: SystemType, time: float) -> None:
if self.constrained_position_idx.size:
self.nb_constrain_translational_rates(
rod.velocity_collection,
system.velocity_collection,
self.constrained_position_idx,
)
if self.constrained_director_idx.size:
self.nb_constrain_rotational_rates(
rod.omega_collection,
system.omega_collection,
self.constrained_director_idx,
)

Expand Down Expand Up @@ -745,19 +726,15 @@ def __init__(
@ director_end
) # rotation_matrix wants vectors 3,1

def constrain_values(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
def constrain_values(self, rod: RodType, time: float) -> None:
if time > self.twisting_time:
rod.position_collection[..., 0] = self.final_start_position
rod.position_collection[..., -1] = self.final_end_position

rod.director_collection[..., 0] = self.final_start_directors
rod.director_collection[..., -1] = self.final_end_directors

def constrain_rates(
self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float
) -> None:
def constrain_rates(self, rod: RodType, time: float) -> None:
if time > self.twisting_time:
rod.velocity_collection[..., 0] = 0.0
rod.omega_collection[..., 0] = 0.0
Expand Down
8 changes: 4 additions & 4 deletions elastica/dissipation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ def system(self): # -> SystemType: (Return type is not parsed with sphinx book.
return self._system

@abstractmethod
def dampen_rates(self, rod: SystemType, time: float):
def dampen_rates(self, system: SystemType, time: float):
# TODO: In the future, we can remove rod and use self.system
"""
Dampen rates (velocity and/or omega) of a rod object.
Parameters
----------
rod : Union[Type[RodBase], Type[RigidBodyBase]]
Rod or rigid-body object.
system : SystemType
System (rod or rigid-body) object.
time : float
The time of simulation.
Expand Down Expand Up @@ -144,7 +144,7 @@ def __init__(self, damping_constant, time_step, **kwargs):
* np.diagonal(self._system.inv_mass_second_moment_of_inertia).T
)

def dampen_rates(self, rod: SystemType, time: float):
def dampen_rates(self, rod: RodType, time: float):
rod.velocity_collection[:] = (
rod.velocity_collection * self.translational_damping_coefficient
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
__all__ = ["GenericSystemTypeFreeJoint", "GenericSystemTypeFixedJoint"]
from elastica.joint import FreeJoint, FixedJoint
from elastica.typing import SystemType
from elastica.utils import Tolerance, MaxDimension
import numpy as np
from typing import Optional

Expand Down
11 changes: 0 additions & 11 deletions elastica/experimental/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,16 @@

import numpy as np
from elastica.external_forces import NoForces
from elastica.interaction import *
from elastica.interaction import (
find_slipping_elements,
apply_normal_force_numba_rigid_body,
InteractionPlaneRigidBody,
)

import numba
from numba import njit
from elastica._linalg import (
_batch_matmul,
_batch_matvec,
_batch_cross,
_batch_norm,
_batch_dot,
_batch_product_i_k_to_ik,
_batch_product_i_ik_to_k,
_batch_product_k_ik_to_ik,
_batch_vector_sum,
_batch_matrix_transpose,
_batch_vec_oneD_vec_cross,
)


Expand Down
Loading

0 comments on commit b44dbb1

Please sign in to comment.