Skip to content

Commit

Permalink
update: moduli assignment for Cosserat Rod
Browse files Browse the repository at this point in the history
The logging level of some messages are lowered (warning->info) in order
to avoid unnecessary logging.
  • Loading branch information
skim0119 committed Apr 10, 2022
1 parent 001bb6f commit 209d3c1
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions elastica/rod/factory_function.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
__doc__ = """ Factory function to allocate variables for Cosserat Rod"""
__all__ = ["allocate"]
import typing
from typing import Optional
import warnings
import logging
import numpy as np
from numpy.testing import assert_allclose
from elastica.utils import MaxDimension, Tolerance
Expand All @@ -16,8 +19,9 @@ def allocate(
base_radius,
density,
nu,
youngs_modulus,
# poisson_ratio,
youngs_modulus:float,
poisson_ratio:Optional[float]=None,
shear_modulus:Optional[float]=None,
# alpha_c=0.964,
*args,
**kwargs
Expand Down Expand Up @@ -215,7 +219,7 @@ def allocate(
)

# Shear/Stretch matrix
shear_modulus = get_shear_modulus(youngs_modulus, kwargs)
shear_modulus = get_shear_modulus(youngs_modulus, poisson_ratio, shear_modulus)

# Value taken based on best correlation for Poisson ratio = 0.5, from
# "On Timoshenko's correction for shear in vibrating beams" by Kaneko, 1975
Expand Down Expand Up @@ -398,31 +402,34 @@ def allocate(
)


def get_shear_modulus(youngs_modulus, kwargs):
def get_shear_modulus(youngs_modulus:float, poisson_ratio:Optional[float], shear_modulus:Optional[float]):
"""
From the kwargs get shear modulus, or compute it. This function contains warnining messages.
From the kwargs get shear modulus, or compute it. This function contains logging messages.
Parameters
----------
youngs_modulus : float
kwargs
poisson_ratio: Optional[float]
shear_modulus: Optional[float]
Returns
-------
shear_modulus: float
"""

log = logging.getLogger("rod constructor: get_shear_modulus")

# Shear/Stretch matrix
if kwargs.__contains__("shear_modulus"):
if shear_modulus and not poisson_ratio:
# User set shear modulus use that.
shear_modulus = kwargs.get("shear_modulus")
pass

if kwargs.__contains__("shear_modulus") and kwargs.__contains__("poisson_ratio"):
if shear_modulus and poisson_ratio:
# User set shear modulus and also a poisson ratio. Do not use poisson ratio and raise warning.
shear_modulus = kwargs.get("shear_modulus")
poisson_ratio = kwargs.get("poisson_ratio")
message = (
"Both a Poisson ratio and a shear modulus are provided. "
"In such case, we prioritize the shear modulus."
"The Poisson ratio is only used to compute a shear modulus "
"so the provided Poisson ratio of ( "
+ str(poisson_ratio)
Expand All @@ -432,12 +439,8 @@ def get_shear_modulus(youngs_modulus, kwargs):
)
warnings.warn(message, category=UserWarning)

if kwargs.__contains__("poisson_ratio") and (
not kwargs.__contains__("shear_modulus")
):
# User set poisson ratio but not the shear modulus. Then use poisson ratio to compute shear modulus, and
# raise a warning.
poisson_ratio = kwargs.get("poisson_ratio")
if poisson_ratio and not shear_modulus:
# Use poisson ratio to compute shear modulus
shear_modulus = youngs_modulus / (poisson_ratio + 1.0)

message = (
Expand All @@ -450,14 +453,11 @@ def get_shear_modulus(youngs_modulus, kwargs):
"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. \n"
)
warnings.warn(message, category=UserWarning)
log.info(message)

if not (
kwargs.__contains__("poisson_ratio") or kwargs.__contains__("shear_modulus")
):
if not poisson_ratio and not shear_modulus:
# If user does not set poisson ratio or shear modulus, then take poisson ratio as 0.5 and raise warning.
poisson_ratio = 0.5

shear_modulus = youngs_modulus / (poisson_ratio + 1.0)

message = (
Expand All @@ -469,7 +469,6 @@ def get_shear_modulus(youngs_modulus, kwargs):
+ ", "
"using the equation: shear_modulus = youngs_modulus / (poisson_ratio + 1.0)."
)

warnings.warn(message, category=UserWarning)
log.info(message)

return shear_modulus

0 comments on commit 209d3c1

Please sign in to comment.