-
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.
Merge pull request #5 from adtzlr/fix-equal-eigvals
Fix equal eigvals
- Loading branch information
Showing
8 changed files
with
83 additions
and
89 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
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 +1 @@ | ||
__version__ = "0.0.4" | ||
__version__ = "0.0.5" |
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
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
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
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
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
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,51 +1,44 @@ | ||
import numpy as np | ||
|
||
from matadi import Variable, Material | ||
from matadi.math import det, transpose, trace | ||
from matadi.math import det, transpose, trace, invariants, sqrt | ||
|
||
|
||
def test_modify(): | ||
|
||
# variables | ||
F = Variable("F", 3, 3) | ||
|
||
def neohooke(x, mu=1.0, bulk=200.0): | ||
def neohooke(x, mu=1.0, bulk=200.0): | ||
"""Strain energy density function of nearly-incompressible | ||
Neo-Hookean isotropic hyperelastic material formulation.""" | ||
|
||
F = x[0] | ||
|
||
J = det(F) | ||
C = transpose(F) @ F | ||
I1_iso = J ** (-2 / 3) * trace(C) | ||
|
||
I1, I2, I3 = invariants(C) | ||
J = sqrt(I3) | ||
|
||
I1_iso = I3 ** (-1 / 3) * trace(C) | ||
|
||
return mu * (I1_iso - 3) + bulk * (J - 1) ** 2 / 2 | ||
|
||
|
||
def test_simple(): | ||
|
||
# variables | ||
F = Variable("F", 3, 3) | ||
|
||
# data | ||
FF = np.random.rand(3, 3, 5, 100) | ||
for a in range(3): | ||
FF[a, a] += 1 | ||
|
||
# init Material | ||
W = Material( | ||
x=[F], | ||
fun=neohooke, | ||
kwargs={"mu": 1.0, "bulk": 10.0}, | ||
) | ||
W = Material(x=[F], fun=neohooke, kwargs={"mu": 1.0, "bulk": 10.0},) | ||
|
||
dW = W.gradient([FF]) | ||
DW = W.hessian([FF]) | ||
|
||
dW2 = W.gradient([FF], modify=[True]) | ||
DW2 = W.hessian([FF], modify=[True]) | ||
|
||
# dW and DW are always lists... | ||
assert dW[0].shape == (3, 3, 5, 100) | ||
assert DW[0].shape == (3, 3, 3, 3, 5, 100) | ||
|
||
assert dW2[0].shape == (3, 3, 5, 100) | ||
assert DW2[0].shape == (3, 3, 3, 3, 5, 100) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_modify() | ||
test_simple() |