From b6e9f9f0220954d1f0fa6804a55f7dd9db7ce4aa Mon Sep 17 00:00:00 2001 From: adtzlr Date: Wed, 20 Apr 2022 14:29:52 +0200 Subject: [PATCH 1/3] add normal vector as argument to area-change --- felupe/constitution/_kinematics.py | 38 ++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/felupe/constitution/_kinematics.py b/felupe/constitution/_kinematics.py index 68b98e70..97f69db8 100644 --- a/felupe/constitution/_kinematics.py +++ b/felupe/constitution/_kinematics.py @@ -25,8 +25,17 @@ """ +import numpy as np + +try: + from einsumt import einsumt +except: + print("ImportWarning: Module `einsumt` not found. Fall back to `np.einsum()`.") + from numpy import einsum as einsumt + from ..math import ( transpose, + dot, inv, dya, cdya_ik, @@ -104,13 +113,15 @@ class AreaChange: def __init__(self, parallel=False): self.parallel = parallel - def function(self, F): + def function(self, F, N=None): """Area change. Arguments --------- F : ndarray Deformation gradient + N : ndarray or None, optional + Area normal vector (default is None) Returns ------- @@ -118,15 +129,23 @@ def function(self, F): Cofactor matrix of the deformation gradient """ J = det(F) - return J * transpose(inv(F, J)) - def gradient(self, F): + Fs = J * transpose(inv(F, J)) + + if N is None: + return Fs + else: + return dot(Fs, N, parallel=self.parallel) + + def gradient(self, F, N=None): """Gradient of area change. Arguments --------- F : ndarray Deformation gradient + N : ndarray or None, optional + Area normal vector (default is None) Returns ------- @@ -135,12 +154,23 @@ def gradient(self, F): """ J = det(F) + dJdF = self.function(F) - return ( + dFsdF = ( dya(dJdF, dJdF, parallel=self.parallel) - cdya_il(dJdF, dJdF, parallel=self.parallel) ) / J + if self.parallel: + einsum = einsumt + else: + einsum = np.einsum + + if N is None: + return dFsdF + else: + return einsum("ijkl...,j...->ikl...", dFsdF, N) + class VolumeChange: r"""Volume Change. From cd7a6dd2d3ff2e937b59780750688fa253530528 Mon Sep 17 00:00:00 2001 From: adtzlr Date: Wed, 20 Apr 2022 14:30:03 +0200 Subject: [PATCH 2/3] update tests for enhanced area-change --- tests/test_constitution.py | 8 ++++++++ tests/test_region.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_constitution.py b/tests/test_constitution.py index bad55472..183c53d7 100644 --- a/tests/test_constitution.py +++ b/tests/test_constitution.py @@ -197,6 +197,8 @@ def test_linear_planestrain(): def test_kinematics(): r, F = pre(sym=False, add_identity=True) + N = F[:, 0] + for parallel in [False, True]: lc = fe.constitution.LineChange(parallel=parallel) @@ -206,6 +208,9 @@ def test_kinematics(): xf = lc.function(F) xg = lc.gradient(F) + Yf = ac.function(F, N) + Yg = ac.gradient(F, N) + yf = ac.function(F) yg = ac.gradient(F) @@ -221,6 +226,9 @@ def test_kinematics(): assert yf.shape == (3, 3, *F.shape[-2:]) assert yg.shape == (3, 3, 3, 3, *F.shape[-2:]) + assert Yf.shape == (3, *F.shape[-2:]) + assert Yg.shape == (3, 3, 3, *F.shape[-2:]) + assert zf.shape == F.shape[-2:] assert zg.shape == (3, 3, *F.shape[-2:]) assert zh.shape == (3, 3, 3, 3, *F.shape[-2:]) diff --git a/tests/test_region.py b/tests/test_region.py index 8f89f8b6..b8534931 100644 --- a/tests/test_region.py +++ b/tests/test_region.py @@ -37,7 +37,7 @@ def test_region(): r = fe.RegionQuad(mesh) r = fe.RegionQuadBoundary(mesh) r = fe.RegionConstantQuad(mesh) - + mesh.cell_type = "some_fancy_cell_type" with pytest.raises(NotImplementedError): r = fe.RegionBoundary(mesh, fe.Quad(), fe.GaussLegendreBoundary(order=1, dim=2)) From 4eef3fa8cfe7b84198a55859e349c8c99298bc63 Mon Sep 17 00:00:00 2001 From: adtzlr Date: Wed, 20 Apr 2022 14:31:00 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a29d7a0d..048f4b0a 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ All notable changes to this project will be documented in this file. The format - Add parallel versions of math helpers (`dya`, `cdya`, `dot`, `ddot`) using [einsumt](https://pypi.org/project/einsumt/). - Add `parallel` keyword to constitutive models (`NeoHooke`, `LinearElasticTensorNotation` and `ThreeFieldVariation`). - Add `RegionBoundary` along with template regions for `Quad` and `Hexahedron` and `GaussLegendreBoundary`. +- Add optional normal vector argument for function and gradient methods of `AreaChange`. ### Changed - Enforce consistent arguments for functions inside `mesh.tools` (`points, cells, cell_data` or `Mesh`).