adtzlr / matadi

Material Definition with Automatic Differentiation
GNU General Public License v3.0
21 stars 2 forks source link

Add gradient- and hessian-vector-product methods #77

Closed adtzlr closed 2 years ago

adtzlr commented 2 years ago

fixes #76.

This PR enables

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])
codecov-commenter commented 2 years ago

Codecov Report

Merging #77 (036193b) into main (1090bcc) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #77   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        19           
  Lines          606       637   +31     
=========================================
+ Hits           606       637   +31     
Impacted Files Coverage Δ
matadi/__about__.py 100.00% <100.00%> (ø)
matadi/_material.py 100.00% <100.00%> (ø)
matadi/_templates.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1090bcc...036193b. Read the comment docs.