-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
organizing constitutive models based on types and moving all interfac…
…es from F to grad u so it will be consistent across all physics.
- Loading branch information
Showing
8 changed files
with
128 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from .base import BaseConstitutiveModel | ||
from .base import ConstitutiveModel | ||
from .properties import BoundedProperty, FixedProperty, Property | ||
|
||
# models | ||
from .blatz_ko import BlatzKo | ||
from .gent import Gent | ||
from .neohookean import NeoHookean | ||
from .swanson import Swanson | ||
from .mechanics.hyperelasticity.blatz_ko import BlatzKo | ||
from .mechanics.hyperelasticity.gent import Gent | ||
from .mechanics.hyperelasticity.neohookean import NeoHookean | ||
from .mechanics.hyperelasticity.swanson import Swanson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,13 @@ | ||
from abc import abstractmethod | ||
from jaxtyping import Array, Float | ||
from typing import Tuple | ||
import equinox as eqx | ||
import jax | ||
import jax.numpy as jnp | ||
|
||
|
||
Scalar = float | ||
State = Float[Array, "ns"] | ||
Tensor = Float[Array, "3 3"] | ||
Vector = Float[Array, "3"] | ||
|
||
|
||
class BaseConstitutiveModel(eqx.Module): | ||
def cauchy_stress(self, grad_u: Tensor) -> Tensor: | ||
F = grad_u + jnp.eye(3) | ||
J = self.jacobian(grad_u) | ||
P = self.pk1_stress(grad_u) | ||
return (1. / J) * P @ F.T | ||
|
||
def deformation_gradient(self, grad_u: Tensor) -> Tensor: | ||
F = grad_u + jnp.eye(3) | ||
return F | ||
|
||
@abstractmethod | ||
def energy(self, grad_u: Tensor) -> Scalar: | ||
""" | ||
This method returns the algorithmic strain energy density. | ||
""" | ||
pass | ||
|
||
def invariants(self, grad_u: Tensor) -> Tuple[Scalar, Scalar, Scalar]: | ||
I1 = self.I1(grad_u) | ||
I2 = self.I2(grad_u) | ||
I3 = self.I3(grad_u) | ||
return jnp.array([I1, I2, I3]) | ||
|
||
def I1(self, grad_u: Tensor) -> Scalar: | ||
r""" | ||
Calculates the first invariant | ||
- **grad_u**: the displacement gradient | ||
$$ | ||
I_1 = tr\left(\mathbf{F}^T\mathbf{F}\right) | ||
$$ | ||
""" | ||
F = self.deformation_gradient(grad_u) | ||
I1 = jnp.trace(F @ F.T) | ||
return I1 | ||
|
||
def I1_bar(self, grad_u: Tensor) -> Scalar: | ||
r""" | ||
Calculates the first distortional invariant | ||
- **grad_u**: the displacement gradient | ||
$$ | ||
\bar{I}_1 = J^{-2/3}tr\left(\mathbf{F}^T\mathbf{F}\right) | ||
$$ | ||
""" | ||
F = self.deformation_gradient(grad_u) | ||
I1 = jnp.trace(F @ F.T) | ||
J = self.jacobian(grad_u) | ||
return jnp.power(J, -2. / 3.) * I1 | ||
|
||
def I2(self, grad_u: Tensor) -> Scalar: | ||
F = self.deformation_gradient(grad_u) | ||
C = F.T @ F | ||
C2 = C @ C | ||
I1 = jnp.trace(C) | ||
I2 = 0.5 * (I1**2 - jnp.trace(C2)) | ||
return I2 | ||
|
||
def I2_bar(self, grad_u: Tensor) -> Scalar: | ||
F = self.deformation_gradient(grad_u) | ||
C = F.T @ F | ||
C2 = C @ C | ||
I1 = jnp.trace(C) | ||
I2 = 0.5 * (I1**2 - jnp.trace(C2)) | ||
J = self.jacobian(grad_u) | ||
return jnp.power(J, -4. / 3.) * I2 | ||
|
||
def I3(self, grad_u: Tensor) -> Scalar: | ||
J = self.jacobian(grad_u) | ||
return J * J | ||
|
||
def jacobian(self, grad_u: Tensor) -> Scalar: | ||
r""" | ||
This simply calculate the jacobian but with guard rails | ||
to return nonsensical numbers if a non-positive jacobian | ||
is encountered during training. | ||
- **grad_u**: the displacement gradient | ||
$$ | ||
J = det(\mathbf{F}) | ||
$$ | ||
""" | ||
F = self.deformation_gradient(grad_u) | ||
J = jnp.linalg.det(F) | ||
J = jax.lax.cond( | ||
J <= 0.0, | ||
lambda _: 1.0e3, | ||
lambda x: x, | ||
J | ||
) | ||
return J | ||
|
||
def pk1_stress(self, grad_u: Tensor) -> Tensor: | ||
return jax.grad(self.energy, argnums=0)(grad_u) | ||
|
||
class ConstitutiveModel(eqx.Module): | ||
def properties(self): | ||
return self.__dataclass_fields__ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
from abc import abstractmethod | ||
from ..base import ConstitutiveModel, Scalar, Tensor | ||
from typing import Tuple | ||
import jax | ||
import jax.numpy as jnp | ||
|
||
|
||
class MechanicsModel(ConstitutiveModel): | ||
def cauchy_stress(self, grad_u: Tensor, *args) -> Tensor: | ||
F = self.deformation_gradient(grad_u) | ||
J = self.jacobian(grad_u) | ||
P = self.pk1_stress(grad_u, *args) | ||
return (1. / J) * P @ F.T | ||
|
||
def deformation_gradient(self, grad_u: Tensor) -> Tensor: | ||
F = grad_u + jnp.eye(3) | ||
return F | ||
|
||
@abstractmethod | ||
def energy(self, grad_u: Tensor, *args) -> Scalar: | ||
""" | ||
This method returns the algorithmic strain energy density. | ||
""" | ||
pass | ||
|
||
def invariants(self, grad_u: Tensor) -> Tuple[Scalar, Scalar, Scalar]: | ||
I1 = self.I1(grad_u) | ||
I2 = self.I2(grad_u) | ||
I3 = self.I3(grad_u) | ||
return jnp.array([I1, I2, I3]) | ||
|
||
def I1(self, grad_u: Tensor) -> Scalar: | ||
r""" | ||
Calculates the first invariant | ||
- **grad_u**: the displacement gradient | ||
$$ | ||
I_1 = tr\left(\mathbf{F}^T\mathbf{F}\right) | ||
$$ | ||
""" | ||
F = self.deformation_gradient(grad_u) | ||
I1 = jnp.trace(F @ F.T) | ||
return I1 | ||
|
||
def I1_bar(self, grad_u: Tensor) -> Scalar: | ||
r""" | ||
Calculates the first distortional invariant | ||
- **grad_u**: the displacement gradient | ||
$$ | ||
\bar{I}_1 = J^{-2/3}tr\left(\mathbf{F}^T\mathbf{F}\right) | ||
$$ | ||
""" | ||
F = self.deformation_gradient(grad_u) | ||
I1 = jnp.trace(F @ F.T) | ||
J = self.jacobian(grad_u) | ||
return jnp.power(J, -2. / 3.) * I1 | ||
|
||
def I2(self, grad_u: Tensor) -> Scalar: | ||
F = self.deformation_gradient(grad_u) | ||
C = F.T @ F | ||
C2 = C @ C | ||
I1 = jnp.trace(C) | ||
I2 = 0.5 * (I1**2 - jnp.trace(C2)) | ||
return I2 | ||
|
||
def I2_bar(self, grad_u: Tensor) -> Scalar: | ||
F = self.deformation_gradient(grad_u) | ||
C = F.T @ F | ||
C2 = C @ C | ||
I1 = jnp.trace(C) | ||
I2 = 0.5 * (I1**2 - jnp.trace(C2)) | ||
J = self.jacobian(grad_u) | ||
return jnp.power(J, -4. / 3.) * I2 | ||
|
||
def I3(self, grad_u: Tensor) -> Scalar: | ||
J = self.jacobian(grad_u) | ||
return J * J | ||
|
||
def jacobian(self, grad_u: Tensor) -> Scalar: | ||
r""" | ||
This simply calculate the jacobian but with guard rails | ||
to return nonsensical numbers if a non-positive jacobian | ||
is encountered during training. | ||
- **grad_u**: the displacement gradient | ||
$$ | ||
J = det(\mathbf{F}) | ||
$$ | ||
""" | ||
F = self.deformation_gradient(grad_u) | ||
J = jnp.linalg.det(F) | ||
J = jax.lax.cond( | ||
J <= 0.0, | ||
lambda _: 1.0e3, | ||
lambda x: x, | ||
J | ||
) | ||
return J | ||
|
||
def pk1_stress(self, grad_u: Tensor, *args) -> Tensor: | ||
return jax.grad(self.energy, argnums=0)(grad_u, *args) | ||
|
||
|
||
class HyperelasticModel(MechanicsModel): | ||
pass |
6 changes: 3 additions & 3 deletions
6
pancax/constitutive_models/blatz_ko.py → ...els/mechanics/hyperelasticity/blatz_ko.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
pancax/constitutive_models/gent.py → ..._models/mechanics/hyperelasticity/gent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
pancax/constitutive_models/neohookean.py → ...s/mechanics/hyperelasticity/neohookean.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
pancax/constitutive_models/swanson.py → ...dels/mechanics/hyperelasticity/swanson.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters