Skip to content

Commit

Permalink
Merge pull request #728 from adtzlr/change-evaluate-fieldcontainer
Browse files Browse the repository at this point in the history
Add `field.EvaluateFieldContainer(field)`
  • Loading branch information
adtzlr authored Mar 29, 2024
2 parents f4c6bc1 + 899d149 commit f89efe8
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 120 deletions.
9 changes: 7 additions & 2 deletions docs/felupe/field.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Available kinds of fields:

**Detailed API Reference**

.. autoclass:: felupe.FieldsMixed
.. autoclass:: felupe.FieldContainer
:members:
:undoc-members:
:inherited-members:

.. autoclass:: felupe.FieldContainer
.. autoclass:: felupe.field.EvaluateFieldContainer
:members:
:undoc-members:
:inherited-members:
Expand All @@ -55,3 +55,8 @@ Available kinds of fields:
:members:
:undoc-members:
:inherited-members:

.. autoclass:: felupe.FieldsMixed
:members:
:undoc-members:
:inherited-members:
2 changes: 1 addition & 1 deletion src/felupe/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "8.2.0"
__version__ = "8.3.0-dev"
3 changes: 2 additions & 1 deletion src/felupe/field/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ._axi import FieldAxisymmetric
from ._base import Field
from ._container import FieldContainer
from ._container import EvaluateFieldContainer, FieldContainer
from ._dual import FieldDual
from ._fields import FieldsMixed
from ._planestrain import FieldPlaneStrain
Expand All @@ -12,4 +12,5 @@
"FieldsMixed",
"FieldPlaneStrain",
"FieldDual",
"EvaluateFieldContainer",
]
248 changes: 133 additions & 115 deletions src/felupe/field/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,134 @@
from ..tools._plot import ViewField


class Evaluate:
"A class with evaluate methods of a field container."
class EvaluateFieldContainer:
"""Methods to evaluate the deformation gradient and strain measures of a field
container.
def __init__(self, deformation_gradient, strain, log_strain, green_lagrange_strain):
self.deformation_gradient = deformation_gradient
self.strain = strain
self.log_strain = log_strain
self.green_lagrange_strain = green_lagrange_strain
Parameters
----------
field : FieldContainer
A container for fields.
"""

def __init__(self, field):
self.field = field

def deformation_gradient(self):
r"""Return the Deformation gradient tensor.
.. math::
:label: deformation-gradient-tensor
\boldsymbol{F} &= \frac{\partial \boldsymbol{x}}{\partial \boldsymbol{X}}
\boldsymbol{F} &= \sum_\alpha \lambda_\alpha
\ \boldsymbol{n}_\alpha \otimes \boldsymbol{N}_\alpha
"""
return self.field[0].extract()

def strain(self, fun=strain_stretch_1d, tensor=True, asvoigt=False, n=0, **kwargs):
r"""Return the Lagrangian strain tensor or its principal values.
.. math::
:label: seth-hill-strain-tensor
\boldsymbol{E} = \sum_\alpha \frac{1}{k} \left( \lambda_\alpha^k - 1 \right)
\ \boldsymbol{N}_\alpha \otimes \boldsymbol{N}_\alpha
Parameters
----------
fun : callable, optional
A callable for the one-dimensional strain-stretch relation. Its Signature
must be ``lambda stretch, **kwargs: strain`` (default is the log. strain,
:func:`~felupe.math.strain_stretch_1d` with ``k=0``).
tensor : bool, optional
Assemble and return the strain tensor if True or return its principal values
only if False. Default is True.
asvoigt : bool, optional
Return the symmetric strain tensor in reduced vector storage (default is
False).
n : int, optional
The index of the displacement field (default is 0).
**kwargs : dict, optional
Optional keyword-arguments are passed to the 1d strain-stretch relation.
Returns
-------
ndarray of shape (N, N, ...) tensor, (N!, ...) asvoigt or (N, ...) princ. values
The strain tensor or its principal values.
See Also
-------
math.strain : Compute a Lagrangian strain tensor.
math.strain_stretch_1d : Compute the Seth-Hill strains.
"""
return strain(self.field, tensor=tensor, asvoigt=asvoigt, n=0, **kwargs)

def log_strain(self, tensor=True, asvoigt=False, n=0):
r"""Return the logarithmic Lagrangian strain tensor or its principal values.
.. math::
:label: log-strain-tensor
\boldsymbol{E} = \sum_\alpha \ln(\lambda_\alpha) \
\boldsymbol{N}_\alpha \otimes \boldsymbol{N}_\alpha
Parameters
----------
tensor : bool, optional
Assemble and return the strain tensor if True or return its principal values
only if False. Default is True.
asvoigt : bool, optional
Return the symmetric strain tensor in reduced vector storage (default is
False).
n : int, optional
The index of the displacement field (default is 0).
Returns
-------
ndarray of shape (N, N, ...) tensor, (N!, ...) asvoigt or (N, ...) princ. values
The strain tensor or its principal values.
See Also
-------
math.strain_stretch_1d : Compute the Seth-Hill strains.
math.strain : Compute a Lagrangian strain tensor.
"""
return strain(self.field, tensor=tensor, asvoigt=asvoigt, k=0)

def green_lagrange_strain(self, tensor=True, asvoigt=False, n=0):
r"""Return the Green-Lagrange Lagrangian strain tensor or its principal values.
.. math::
:label: seth-hill-strain-tensor
\boldsymbol{E} = \sum_\alpha \frac{1}{2} \left( \lambda_\alpha^2 - 1 \right)
\ \boldsymbol{N}_\alpha \otimes \boldsymbol{N}_\alpha
Parameters
----------
tensor : bool, optional
Assemble and return the strain tensor if True or return its principal values
only if False. Default is True.
asvoigt : bool, optional
Return the symmetric strain tensor in reduced vector storage (default is
False).
n : int, optional
The index of the displacement field (default is 0).
Returns
-------
ndarray of shape (N, N, ...) tensor, (N!, ...) asvoigt or (N, ...) princ. values
The strain tensor or its principal values.
See Also
-------
math.strain : Compute a Lagrangian strain tensor.
math.strain_stretch_1d : Compute the Seth-Hill strains.
"""
return strain(self.field, tensor=tensor, asvoigt=asvoigt, k=2)


class FieldContainer:
Expand All @@ -43,6 +163,11 @@ class FieldContainer:
fields : list or tuple of Field, FieldAxisymmetric or FieldPlaneStrain
List with fields. The region is linked to the first field.
Attributes
----------
evaluate : field.EvaluateFieldContainer
Methods to evaluate the deformation gradient and strain measures.
Examples
--------
>>> import felupe as fem
Expand Down Expand Up @@ -101,12 +226,7 @@ def __init__(self, fields):
self.fieldsizes = [f.indices.dof.size for f in self.fields]
self.offsets = np.cumsum(self.fieldsizes)[:-1]

self.evaluate = Evaluate(
deformation_gradient=self.fields[0].extract,
strain=self._strain,
log_strain=self._log_strain,
green_lagrange_strain=self._green_lagrange_strain,
)
self.evaluate = EvaluateFieldContainer(self)

def __repr__(self):
header = "<felupe FieldContainer object>"
Expand Down Expand Up @@ -257,108 +377,6 @@ def imshow(self, *args, ax=None, dpi=None, **kwargs):

return ax

def _strain(self, fun=strain_stretch_1d, tensor=True, asvoigt=False, n=0, **kwargs):
r"""Return the Lagrangian strain tensor or its principal values.
.. math::
:label: seth-hill-strain-tensor
\boldsymbol{E} = \sum_\alpha \frac{1}{k} \left( \lambda_\alpha^k - 1 \right)
\ \boldsymbol{N}_\alpha \otimes \boldsymbol{N}_\alpha
Parameters
----------
fun : callable, optional
A callable for the one-dimensional strain-stretch relation. Its Signature
must be ``lambda stretch, **kwargs: strain`` (default is the log. strain,
:func:`~felupe.math.strain_stretch_1d` with ``k=0``).
tensor : bool, optional
Assemble and return the strain tensor if True or return its principal values
only if False. Default is True.
asvoigt : bool, optional
Return the symmetric strain tensor in reduced vector storage (default is
False).
n : int, optional
The index of the displacement field (default is 0).
**kwargs : dict, optional
Optional keyword-arguments are passed to the 1d strain-stretch relation.
Returns
-------
ndarray of shape (N, N, ...) tensor, (N!, ...) asvoigt or (N, ...) princ. values
The strain tensor or its principal values.
See Also
-------
math.strain : Compute a Lagrangian strain tensor.
math.strain_stretch_1d : Compute the Seth-Hill strains.
"""
return strain(self, tensor=tensor, asvoigt=asvoigt, n=0, **kwargs)

def _log_strain(self, tensor=True, asvoigt=False, n=0):
r"""Return the logarithmic Lagrangian strain tensor or its principal values.
.. math::
:label: log-strain-tensor
\boldsymbol{E} = \sum_\alpha \ln(\lambda_\alpha) \
\boldsymbol{N}_\alpha \otimes \boldsymbol{N}_\alpha
Parameters
----------
tensor : bool, optional
Assemble and return the strain tensor if True or return its principal values
only if False. Default is True.
asvoigt : bool, optional
Return the symmetric strain tensor in reduced vector storage (default is
False).
n : int, optional
The index of the displacement field (default is 0).
Returns
-------
ndarray of shape (N, N, ...) tensor, (N!, ...) asvoigt or (N, ...) princ. values
The strain tensor or its principal values.
See Also
-------
math.strain_stretch_1d : Compute the Seth-Hill strains.
math.strain : Compute a Lagrangian strain tensor.
"""
return strain(self, tensor=tensor, asvoigt=asvoigt, k=0)

def _green_lagrange_strain(self, tensor=True, asvoigt=False, n=0):
r"""Return the Green-Lagrange Lagrangian strain tensor or its principal values.
.. math::
:label: seth-hill-strain-tensor
\boldsymbol{E} = \sum_\alpha \frac{1}{2} \left( \lambda_\alpha^2 - 1 \right)
\ \boldsymbol{N}_\alpha \otimes \boldsymbol{N}_\alpha
Parameters
----------
tensor : bool, optional
Assemble and return the strain tensor if True or return its principal values
only if False. Default is True.
asvoigt : bool, optional
Return the symmetric strain tensor in reduced vector storage (default is
False).
n : int, optional
The index of the displacement field (default is 0).
Returns
-------
ndarray of shape (N, N, ...) tensor, (N!, ...) asvoigt or (N, ...) princ. values
The strain tensor or its principal values.
See Also
-------
math.strain : Compute a Lagrangian strain tensor.
math.strain_stretch_1d : Compute the Seth-Hill strains.
"""
return strain(self, tensor=tensor, asvoigt=asvoigt, k=2)

def __add__(self, newvalues):
fields = deepcopy(self)
if len(newvalues) != len(self.fields):
Expand Down
2 changes: 1 addition & 1 deletion src/felupe/quadrature/_gausslegendre.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GaussLegendre(Scheme):
>>> import felupe as fem
>>>
>>> element = fem.Line()
>>> quadrature = fem.GaussLegendre(order=1, dim=1)
>>> quadrature = fem.GaussLegendre(order=2, dim=1)
>>> quadrature.plot(
>>> plotter=element.plot(add_point_labels=False, show_points=False),
>>> weighted=True,
Expand Down

0 comments on commit f89efe8

Please sign in to comment.