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

Remove temporary kwargs in core constitutive materials #843

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ All notable changes to this project will be documented in this file. The format
- Isolate the submodules, i.e. a submodule only uses the public API of another submodule. If necessary, this will help to change one or more modules to a future extension package.
- Enforce contiguous arrays for the region shape-function and -gradient arrays `h` and `dhdX`. This recovers the integral-form assembly performance from v8.6.0.
- Make the private basis classes public (`assembly.expression.Basis`, `assembly.expression.BasisField` and `assembly.expression.BasisArray`) as especially their docstrings are useful to understand how a *Basis* is created on a field.
- Remove material parameter keyword-arguments in the `function()`-, `gradient()`- and `hessian()`-methods of the core constitutive material formulations. This removes the ability for temporary material parameters in `LinearElastic(E=None, nu=0.3).gradient(x, E=1.0)`, use `LinearElastic(E=1.0, nu=0.3).gradient(x)` instead. This affects the material formulations `LinearElastic`, `LinearElasticPlaneStrain`, `LinearElasticPlaneStress`, `LinearElasticLargeStrain`, `NeoHooke` and `NeoHookeCompressible`. `None` is still supported for the material parameters of `NeoHooke` and `NeoHookeCompressible`.

### Deprecated
- Deprecate `SolidBodyGravity`, `SolidBodyForce` should be used instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class NeoHookeCompressible(ConstitutiveMaterial):

Parameters
----------
mu : float
Shear modulus (second Lamé constant)
lmbda : float
First Lamé constant
mu : float or None, optional
Shear modulus (second Lamé constant). Default is None.
lmbda : float or None, optional
First Lamé constant (default is None)

Notes
-----
Expand Down Expand Up @@ -115,27 +115,20 @@ def __init__(self, mu=None, lmbda=None, parallel=False):
# ``self.gradient(self.x)`` and ``self.hessian(self.x)``
self.x = [np.eye(3), np.zeros(0)]

def function(self, x, mu=None, lmbda=None):
def function(self, x):
"""Strain energy density function per unit undeformed volume of the Neo-Hookean
material formulation.

Parameters
----------
x : list of ndarray
List with the Deformation gradient ``F`` (3x3) as first item
mu : float, optional
Shear modulus (default is None)
lmbda : float, optional
First Lamé constant (default is None)
"""

F = x[0]

if mu is None:
mu = self.mu

if lmbda is None:
lmbda = self.lmbda
mu = self.mu
lmbda = self.lmbda

lnJ = np.log(det(F))
C = dot(transpose(F), F, parallel=self.parallel)
Expand All @@ -147,29 +140,22 @@ def function(self, x, mu=None, lmbda=None):

return [W]

def gradient(self, x, mu=None, lmbda=None, out=None):
def gradient(self, x, out=None):
"""Gradient of the strain energy density function per unit undeformed volume of
the Neo-Hookean material formulation.

Parameters
----------
x : list of ndarray
List with the Deformation gradient ``F`` (3x3) as first item
mu : float, optional
Shear modulus (default is None)
lmbda : float, optional
First Lamé constant (default is None)
out : ndarray or None, optional
A location into which the result is stored (default is None).
"""

F, statevars = x[0], x[-1]

if mu is None:
mu = self.mu

if lmbda is None:
lmbda = self.lmbda
mu = self.mu
lmbda = self.lmbda

J = det(F)
iFT = transpose(inv(F, J))
Expand All @@ -187,29 +173,22 @@ def gradient(self, x, mu=None, lmbda=None, out=None):

return [P, statevars]

def hessian(self, x, mu=None, lmbda=None, out=None):
def hessian(self, x, out=None):
"""Hessian of the strain energy density function per unit undeformed volume of
the Neo-Hookean material formulation.

Parameters
----------
x : list of ndarray
List with the Deformation gradient ``F`` (3x3) as first item
mu : float, optional
Shear modulus (default is None)
lmbda : float, optional
First Lamé constant (default is None)
out : ndarray or None, optional
A location into which the result is stored (default is None).
"""

F = x[0]

if mu is None:
mu = self.mu

if lmbda is None:
lmbda = self.lmbda
mu = self.mu
lmbda = self.lmbda

J = det(F)
iFT = transpose(inv(F, J))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@


class NeoHooke(ConstitutiveMaterial):
r"""Nearly-incompressible isotropic hyperelastic Neo-Hookean material
formulation. The strain energy density function of the Neo-Hookean
material formulation is a linear function of the trace of the
isochoric part of the right Cauchy-Green deformation tensor.
r"""Nearly-incompressible isotropic hyperelastic Neo-Hookean material formulation.
The strain energy density function of the Neo-Hookean material formulation is a
linear function of the trace of the isochoric part of the right Cauchy-Green
deformation tensor.

Parameters
----------
mu : float or None, optional
Shear modulus
Shear modulus (default is None)
bulk : float or None, optional
Bulk modulus
Bulk modulus (default is None)

Notes
-----
Expand Down Expand Up @@ -208,27 +208,20 @@ def __init__(self, mu=None, bulk=None, parallel=False):
# ``self.gradient(self.x)`` and ``self.hessian(self.x)``
self.x = [np.eye(3), np.zeros(0)]

def function(self, x, mu=None, bulk=None):
"""Strain energy density function per unit undeformed volume of the
Neo-Hookean material formulation.
def function(self, x):
"""Strain energy density function per unit undeformed volume of the Neo-Hookean
material formulation.

Parameters
----------
x : list of ndarray
List with the Deformation gradient ``F`` (3x3) as first item
mu : float, optional
Shear modulus (default is None)
bulk : float, optional
Bulk modulus (default is None)
"""

F = x[0]

if mu is None:
mu = self.mu

if bulk is None:
bulk = self.bulk
mu = self.mu
bulk = self.bulk

J = det(F)
C = dot(transpose(F), F, parallel=self.parallel)
Expand All @@ -242,29 +235,22 @@ def function(self, x, mu=None, bulk=None):

return [W]

def gradient(self, x, mu=None, bulk=None, out=None):
"""Gradient of the strain energy density function per unit
undeformed volume of the Neo-Hookean material formulation.
def gradient(self, x, out=None):
"""Gradient of the strain energy density function per unit undeformed volume of
the Neo-Hookean material formulation.

Parameters
----------
x : list of ndarray
List with the Deformation gradient ``F`` (3x3) as first item
mu : float, optional
Shear modulus (default is None)
bulk : float, optional
Bulk modulus (default is None)
out : ndarray or None, optional
A location into which the result is stored (default is None).
"""

F, statevars = x[0], x[-1]

if mu is None:
mu = self.mu

if bulk is None:
bulk = self.bulk
mu = self.mu
bulk = self.bulk

J = det(F)
iFT = transpose(inv(F, J))
Expand Down Expand Up @@ -294,29 +280,22 @@ def gradient(self, x, mu=None, bulk=None, out=None):

return [P, statevars]

def hessian(self, x, mu=None, bulk=None, out=None):
"""Hessian of the strain energy density function per unit
undeformed volume of the Neo-Hookean material formulation.
def hessian(self, x, out=None):
"""Hessian of the strain energy density function per unit undeformed volume of
the Neo-Hookean material formulation.

Parameters
----------
x : list of ndarray
List with the Deformation gradient ``F`` (3x3) as first item
mu : float, optional
Shear modulus (default is None)
bulk : float, optional
Bulk modulus (default is None)
out : ndarray or None, optional
A location into which the result is stored (default is None).
"""

F = x[0]

if mu is None:
mu = self.mu

if bulk is None:
bulk = self.bulk
mu = self.mu
bulk = self.bulk

J = det(F)
iFT = transpose(inv(F, J))
Expand Down
18 changes: 9 additions & 9 deletions src/felupe/constitution/linear_elasticity/_lame_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ def lame_converter(E, nu):
Poisson ratio :math:`\nu` to first and second Lamé - constants :math:`\lambda` and
:math:`\mu`.

Notes
-----

.. math::

\lambda &= \frac{E \nu}{(1 + \nu) (1 - 2 \nu)}

\mu &= \frac{E}{2 (1 + \nu)}

Parameters
----------
E : float
Expand All @@ -44,6 +35,15 @@ def lame_converter(E, nu):
First Lamé - constant.
mu : float
Second Lamé - constant (shear modulus).

Notes
-----

.. math::

\lambda &= \frac{E \nu}{(1 + \nu) (1 - 2 \nu)}

\mu &= \frac{E}{2 (1 + \nu)}
"""

lmbda = E * nu / ((1 + nu) * (1 - 2 * nu))
Expand Down
Loading
Loading