Closed adtzlr closed 2 years ago
With the merged PR the following code is possible:
from matadi import MaterialHyperelastic
from matadi.models import neo_hooke
mat = MaterialHyperelastic(neo_hooke, C10=0.5)
# init some random deformation gradients
import numpy as np
defgrad = np.random.rand(3, 3, 5, 100) - 0.5
dF = np.random.rand(3, 3, 5, 100) - 0.5
for a in range(3):
defgrad[a, a] += 1.0
dWdF = mat.gradient([defgrad])
dW = mat.gradient_vector_product([defgrad], [dF])
dW_check = np.einsum("ij...,ij...->...", dWdF[0], dF)
assert np.allclose(dW_check, dW[0])
Enable evaluations of hyperelastic forms without explicit gradients and hessians evaluated by AD; only jacobian - vector products (
jtimes
) are generated.Material definition with Automatic Differentiation:
And here is the defintion of (bi-) linear forms with the above material class in scikit-fem:
```python umat = NeoHooke(mu=1.0, bulk=2.0) def deformation_gradient(w): dudX = grad(w["displacement"]) F = dudX + identity(dudX) return F @LinearForm(nthreads=4) def L(v, w): F = deformation_gradient(w) return umat.gradient_vector_product(F, grad(v)) @BilinearForm(nthreads=4) def a(u, v, w): F = deformation_gradient(w) return umat.hessian_vector_product(F, grad(v), grad(u)) ```Originally posted by @adtzlr in https://github.com/kinnala/scikit-fem/discussions/839#discussioncomment-1887176