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

Add SolidBody kirchhoff stress #221

Merged
merged 4 commits into from
May 17, 2022
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ All notable changes to this project will be documented in this file. The format

## [Unreleased]

### Added
- Add `SolidBody.evaluate.kirchhoff_stress()` method. Contrary to the Cauchy stress method, this gives correct results in incompressible plane stress.

### Fixed
- Fix `tovoigt()` helper for data with more or less than two trailing axes.
- Fix `tovoigt()` helper for data with more or less than two trailing axes and 2D tensors.

## [3.1.0] - 2022-05-02

Expand Down
8 changes: 6 additions & 2 deletions felupe/math/_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,12 @@ def ddot(A, B, n=2, parallel=False):

def tovoigt(A):
"Convert (3, 3) tensor to (6, ) voigt notation."
B = np.zeros((6, *A.shape[2:]))
ij = [(0, 0), (1, 1), (2, 2), (0, 1), (1, 2), (0, 2)]
if A.shape[0] * A.shape[1] == 4:
B = np.zeros((3, *A.shape[2:]))
ij = [(0, 0), (1, 1), (0, 1)]
else:
B = np.zeros((6, *A.shape[2:]))
ij = [(0, 0), (1, 1), (2, 2), (0, 1), (1, 2), (0, 2)]
for i6, (i, j) in enumerate(ij):
B[i6] = A[i, j]
return B
4 changes: 3 additions & 1 deletion felupe/mechanics/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ def __init__(self, vector, matrix):
class Evaluate:
"A class with evaluate methods of a SolidBody."

def __init__(self, gradient, hessian, cauchy_stress=None):
def __init__(self, gradient, hessian, cauchy_stress=None, kirchhoff_stress=None):
self.gradient = gradient
self.hessian = hessian

if cauchy_stress is not None:
self.cauchy_stress = cauchy_stress
self.kirchhoff_stress = kirchhoff_stress


class Results:
Expand All @@ -51,6 +52,7 @@ class Results:
def __init__(self, stress=False, elasticity=False):

self.force = None
self._force = None
self.stiffness = None
self.kinematics = None

Expand Down
21 changes: 18 additions & 3 deletions felupe/mechanics/_solidbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .._field import Field, FieldMixed, FieldsMixed, FieldAxisymmetric
from .._assembly import IntegralForm, IntegralFormMixed, IntegralFormAxisymmetric
from ..constitution import AreaChange
from ..math import inv, dot
from ..math import inv, dot, transpose, det
from ._helpers import Assemble, Evaluate, Results


Expand All @@ -54,6 +54,7 @@ def __init__(self, umat, field):
gradient=self._gradient,
hessian=self._hessian,
cauchy_stress=self._cauchy_stress,
kirchhoff_stress=self._kirchhoff_stress,
)

self._area_change = AreaChange()
Expand Down Expand Up @@ -141,6 +142,19 @@ def _hessian(self, field=None, args=(), kwargs={}):

return self.results.elasticity

def _kirchhoff_stress(self, field=None):

self._gradient(field)

if len(self.results.kinematics) > 1:
P = self.results.stress[0]
else:
P = self.results.stress

F = self.results.kinematics[0]

return dot(P, transpose(F))

def _cauchy_stress(self, field=None):

self._gradient(field)
Expand All @@ -150,6 +164,7 @@ def _cauchy_stress(self, field=None):
else:
P = self.results.stress

JiFT = self._area_change.function(self.results.kinematics[0])
F = self.results.kinematics[0]
J = det(F)

return dot(P, inv(JiFT))
return dot(P, transpose(F)) / J
1 change: 1 addition & 0 deletions tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def test_math():
fe.math.cdya(F, F)

fe.math.tovoigt(C)
fe.math.tovoigt(C[:2, :2])
fe.math.eigvals(C)
fe.math.eigvals(C[:2, :2])
fe.math.eigvals(C, shear=True)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_mechanics.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ def test_simple():
F = b.results.kinematics[0]
P = b.results.stress
s = b.evaluate.cauchy_stress()
t = b.evaluate.kirchhoff_stress()
C = b.results.elasticity

assert K.shape == (81, 81)
assert r.shape == (81, 1)
assert F.shape == (3, 3, 8, 8)
assert P.shape == (3, 3, 8, 8)
assert s.shape == (3, 3, 8, 8)
assert t.shape == (3, 3, 8, 8)
assert C.shape == (3, 3, 3, 3, 8, 8)


Expand Down Expand Up @@ -193,6 +195,10 @@ def test_solidbody():
s2 = b.evaluate.cauchy_stress(u)
assert np.allclose(s1, s2)

t1 = b.evaluate.kirchhoff_stress()
t2 = b.evaluate.kirchhoff_stress(u)
assert np.allclose(t1, t2)


def test_solidbody_axi():

Expand Down Expand Up @@ -234,6 +240,10 @@ def test_solidbody_axi():
s2 = b.evaluate.cauchy_stress(u)
assert np.allclose(s1, s2)

t1 = b.evaluate.kirchhoff_stress()
t2 = b.evaluate.kirchhoff_stress(u)
assert np.allclose(t1, t2)


def test_solidbody_mixed():

Expand Down Expand Up @@ -280,6 +290,10 @@ def test_solidbody_mixed():
s2 = b.evaluate.cauchy_stress(u)
assert np.allclose(s1, s2)

t1 = b.evaluate.kirchhoff_stress()
t2 = b.evaluate.kirchhoff_stress(u)
assert np.allclose(t1, t2)


if __name__ == "__main__":
test_simple()
Expand Down