Skip to content

Commit

Permalink
Merge branch 'master' into examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ankushaggarwal authored Sep 17, 2024
2 parents 03e4cac + 4c75a9e commit c82c341
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 10 deletions.
49 changes: 49 additions & 0 deletions Tests/test_arbitrary_MatModel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pymecht as pmt
import pytest
import numpy as np

def test_arbitrary_MatModel_I1():
model = pmt.ARB('mu/2.*(I1-3.)','mu=1.','mu=0.01','mu=10.')
mat = pmt.MatModel(model)
mat2 = pmt.MatModel('NH')
assert (mat.stress(random_F)-mat2.stress(random_F)) == pytest.approx(np.zeros((3,3)))

def test_arbitrary_MatModel_I2():
model = pmt.ARB('c1*(I1-3.) + c2*(I2-3.)','c1=1., c2=1.','c1=0.0001, c2=0.','c1=100., c2=100.')
mat = pmt.MatModel(model)
mat2 = pmt.MatModel('MR')
assert (mat.stress(random_F)-mat2.stress(random_F)) == pytest.approx(np.zeros((3,3)))

def test_arbitrary_MatModel_J():
model = pmt.ARB('kappa/2.*(J-1.)**2','kappa=1.','kappa=1.','kappa=1.')
mat = pmt.MatModel(model)
mat2 = pmt.MatModel('volPenalty')
assert (mat.stress(random_F)-mat2.stress(random_F)) == pytest.approx(np.zeros((3,3)))

def test_arbitrary_MatModel_I4():
model = pmt.ARB('d1*(I4-1.)+d2*(I4-1.)**2+d3*(I4-1.)**3', 'd1=0., d2=1., d3=1.', 'd1=0.0001, d2=0., d3=0.', 'd1=100., d2=100., d3=100.')
mat = pmt.MatModel(model)
(mat.models)[0].fiber_dirs = np.array([0.5,0.5,0])
mat2 = pmt.MatModel('polyI4')
(mat2.models)[0].fiber_dirs = np.array([0.5,0.5,0])
assert (mat.stress(random_F)-mat2.stress(random_F)) == pytest.approx(np.zeros((3,3)))

def test_combined_arbitrary_MatModel():
model_I1 = pmt.ARB('mu/2.*(I1-3.)','mu=1.','mu=0.01','mu=10.')
model_I2 = pmt.ARB('c1*(I1-3.) + c2*(I2-3.)','c1=1., c2=1.','c1=0.0001, c2=0.','c1=100., c2=100.')
model_J = pmt.ARB('kappa/2.*(J-1.)**2','kappa=1.','kappa=1.','kappa=1.')
model_I4 = pmt.ARB('d1*(I4-1.)+d2*(I4-1.)**2+d3*(I4-1.)**3', 'd1=0., d2=1., d3=1.', 'd1=0.0001, d2=0., d3=0.', 'd1=100., d2=100., d3=100.')
mat = pmt.MatModel(model_I1, model_I2, model_J, model_I4)
(mat.models)[-1].fiber_dirs = np.array([0.5,0.5,0])
mat2 = pmt.MatModel('NH', 'MR', 'volPenalty', 'polyI4')
(mat2.models)[-1].fiber_dirs = np.array([0.5,0.5,0])
assert (mat.stress(random_F)-mat2.stress(random_F)) == pytest.approx(np.zeros((3,3)))

# Define a random deformation gradient
random_F = np.array([[0.85862107, 0.91032637, 0.80119846], [0.16268142, 0.8596134, 0.17696991], [0.93450122, 0.30132757, 0.55042838]])

test_arbitrary_MatModel_I1()
test_arbitrary_MatModel_I2()
test_arbitrary_MatModel_J()
test_arbitrary_MatModel_I4()
test_combined_arbitrary_MatModel()
10 changes: 5 additions & 5 deletions Tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from Examples import *
import pytest

mat_model_list = ['nh','yeoh','ls','mn','expI1','goh','Holzapfel','hgo','hy','volPenalty','polyI4','ArrudaBoyce','Gent','splineI1I4','StructModel']
mat_model_list = ['nh', 'mr', 'yeoh','ls','mn','expI1','goh','Holzapfel','hgo','hy','volPenalty','polyI4','ArrudaBoyce','Gent','splineI1','splineI1I4','StructModel']
samples_list = [UniaxialExtension,PlanarBiaxialExtension,TubeInflation, LinearSpring]

def test_mat_creation():
Expand Down Expand Up @@ -30,7 +30,7 @@ def test_mat_addition():
def test_mat_reference():
#Test that reference stress and energy are correctly calculated
for mname in mat_model_list:
if mname in ['splineI1I4']: #TODO: splineI1I4 needs a spline setting
if mname in ['splineI1','splineI1I4']: #TODO: splineI1 and splineI1I4 need a spline setting
continue
model = MatModel(mname)
model.models[0].fiber_dirs = [np.array([1,0,0]),np.array([0.5,0.5,0])]
Expand All @@ -41,7 +41,7 @@ def test_mat_reference():
def test_mat_partial_derivs():
#Tests that the partial derivatives are correctly implemented
for mname in mat_model_list:
if mname in ['splineI1I4']:
if mname in ['splineI1','splineI1I4']: #TODO: splineI1 and splineI1I4 need a spline setting
continue
model = MatModel(mname)
model.models[0].fiber_dirs = [np.array([1,0,0]),np.array([0.5,0.5,0])]
Expand Down Expand Up @@ -73,15 +73,15 @@ def test_layered_samples():
material = MatModel('goh','nh')
mm = material.models
mm[0].fiber_dirs = [np.array([cos(0.),sin(0.),0])]
sample = LayeredUniaxial(UniaxialExtension(material),UniaxialExtension(material))
sample = LayeredUniaxial(UniaxialExtension(material, disp_measure='length', force_measure='force'),UniaxialExtension(material,disp_measure='length', force_measure='force'))
assert isinstance(sample, LayeredSamples)
assert len(sample._samples) == 2
assert sample._samples[0]._mat_model == material
assert sample._samples[1]._mat_model == material
assert sample.disp_controlled(sample._samples[0]._x0, sample.parameters) == pytest.approx(0.0)
assert sample.force_controlled(np.zeros_like(sample._samples[0]._x0), sample.parameters) == pytest.approx(sample._samples[0]._x0)

sample = LayeredPlanarBiaxial(PlanarBiaxialExtension(material,force_measure='force'),PlanarBiaxialExtension(material,force_measure='force'))
sample = LayeredPlanarBiaxial(PlanarBiaxialExtension(material,disp_measure='length',force_measure='force'),PlanarBiaxialExtension(material,disp_measure='length',force_measure='force'))
assert isinstance(sample, LayeredSamples)
assert len(sample._samples) == 2
assert sample._samples[0]._mat_model == material
Expand Down
Loading

0 comments on commit c82c341

Please sign in to comment.