Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev poisson ratio warning #26

Merged
merged 8 commits into from
Nov 29, 2021
4 changes: 0 additions & 4 deletions elastica/_elastica_numba/_rod/_cosserat_rod.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ def straight_rod(
density,
nu,
youngs_modulus,
poisson_ratio,
alpha_c=4.0 / 3.0,
*args,
**kwargs
):
Expand Down Expand Up @@ -182,8 +180,6 @@ def straight_rod(
density,
nu,
youngs_modulus,
poisson_ratio,
alpha_c=4.0 / 3.0,
*args,
**kwargs
)
Expand Down
4 changes: 0 additions & 4 deletions elastica/_elastica_numpy/_rod/_cosserat_rod.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ def straight_rod(
density,
nu,
youngs_modulus,
poisson_ratio,
alpha_c=4.0 / 3.0,
*args,
**kwargs
):
Expand Down Expand Up @@ -155,8 +153,6 @@ def straight_rod(
density,
nu,
youngs_modulus,
poisson_ratio,
alpha_c=4.0 / 3.0,
*args,
**kwargs
)
Expand Down
45 changes: 40 additions & 5 deletions elastica/rod/factory_function.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
__doc__ = """ Factory function to allocate variables for Cosserat Rod"""
__all__ = ["allocate"]
import warnings
import numpy as np
from numpy.testing import assert_allclose

from elastica.utils import MaxDimension, Tolerance

from elastica._linalg import _batch_cross, _batch_norm, _batch_dot


Expand All @@ -18,8 +17,8 @@ def allocate(
density,
nu,
youngs_modulus,
poisson_ratio,
alpha_c=4.0 / 3.0,
# poisson_ratio,
# alpha_c=4.0 / 3.0,
*args,
**kwargs
):
Expand Down Expand Up @@ -216,7 +215,43 @@ def allocate(
)

# Shear/Stretch matrix
shear_modulus = youngs_modulus / (poisson_ratio + 1.0)
if kwargs.__contains__("shear_modulus"):
shear_modulus = kwargs.get("shear_modulus")
if kwargs.__contains__("poisson_ratio"):
poisson_ratio = kwargs.get("poisson_ratio")
message = (
" Poisson ratio ( "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest:
"Both a Poisson ratio and a shear modulus are provided. The Poisson ratio is only used to compute a shear modulus so the provided Poisson ratio of ( "+ str(poisson_ratio)+ " ) is being ignored in favor of the provided shear modulus ( "+ str(shear_modulus)+ " ) \n"

+ str(poisson_ratio)
+ " ) given in kwargs is not used. \n"
+ "Since shear modulus ( "
+ str(shear_modulus)
+ " ) is given in kwargs. \n"
)
warnings.warn(message, category=UserWarning)
else:
if kwargs.__contains__("poisson_ratio"):
poisson_ratio = kwargs.get("poisson_ratio")
else:
message = "Shear modulus or poisson ratio cannot be found in kwargs. Poisson ratio is taken as 0.5"
warnings.warn(message, category=UserWarning)
poisson_ratio = 0.5

shear_modulus = youngs_modulus / (poisson_ratio + 1.0)

message = (
"Shear modulus cannot be found in kwargs. \n"
"Poisson ratio "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest the warning being:
"The given Poisson ratio of "+ str(poisson_ratio) + " is used only to compute a shear modulus of " + str(shear_modulus) + ", " "using the equation: shear_modulus = youngs_modulus / (poisson_ratio + 1.0). Use of a Poisson ratio will be depreciated in a future release. It is encouraged that you discontinue using a Poisson ratio and instead directly provide the shear_modulus"

+ str(poisson_ratio)
+ " is used to compute shear modulus "
+ str(shear_modulus)
+ ", "
"using the equation: shear_modulus = youngs_modulus / (poisson_ratio + 1.0)"
)

warnings.warn(message, category=UserWarning)

alpha_c = kwargs.get("alpha_c", 4.0 / 3.0)

shear_matrix = np.zeros(
(MaxDimension.value(), MaxDimension.value(), n_elements), np.float64
)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_elastica_numba/test_governing_equations_nb.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, n_elem, nu=0.0):
self.nu = nu
self.E = 1
self.poisson_ratio = 0.5
self.shear_modulus = self.E / (self.poisson_ratio + 1.0)


def constructor(n_elem, nu=0.0):
Expand All @@ -52,7 +53,7 @@ def constructor(n_elem, nu=0.0):
cls.density,
cls.nu,
cls.E,
cls.poisson_ratio,
shear_modulus=cls.shear_modulus,
)
return cls, rod

Expand Down
2 changes: 2 additions & 0 deletions tests/test_elastica_numpy/test_governing_equations_np.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, n_elem, nu=0.0):
self.nu = nu
self.E = 1
self.poisson_ratio = 0.5
self.shear_modulus = self.E / (self.poisson_ratio + 1.0)


# @pytest.fixture # (scope="function")
Expand All @@ -39,6 +40,7 @@ def constructor(n_elem, nu=0.0):
cls.nu,
cls.E,
cls.poisson_ratio,
shear_modulus=cls.shear_modulus,
)
return cls, rod

Expand Down
Loading