2020-09-19 16:31:19 +05:30
|
|
|
import os
|
|
|
|
|
|
|
|
import pytest
|
2020-10-29 12:12:41 +05:30
|
|
|
import numpy as np
|
2020-09-19 16:31:19 +05:30
|
|
|
|
2020-09-30 11:23:25 +05:30
|
|
|
from damask import ConfigMaterial
|
2020-10-29 12:12:41 +05:30
|
|
|
from damask import Table
|
2020-09-19 16:31:19 +05:30
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def reference_dir(reference_dir_base):
|
|
|
|
"""Directory containing reference results."""
|
2020-09-30 11:23:25 +05:30
|
|
|
return reference_dir_base/'ConfigMaterial'
|
2020-09-19 16:31:19 +05:30
|
|
|
|
|
|
|
|
2020-09-30 12:19:55 +05:30
|
|
|
class TestConfigMaterial:
|
|
|
|
|
2020-09-19 16:31:19 +05:30
|
|
|
@pytest.mark.parametrize('fname',[None,'test.yaml'])
|
|
|
|
def test_load_save(self,reference_dir,tmp_path,fname):
|
2020-09-30 11:23:25 +05:30
|
|
|
reference = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-09-19 16:31:19 +05:30
|
|
|
os.chdir(tmp_path)
|
|
|
|
if fname is None:
|
|
|
|
reference.save()
|
2020-09-30 11:23:25 +05:30
|
|
|
new = ConfigMaterial.load('material.yaml')
|
2020-09-19 16:31:19 +05:30
|
|
|
else:
|
|
|
|
reference.save(fname)
|
2020-09-30 11:23:25 +05:30
|
|
|
new = ConfigMaterial.load(fname)
|
2020-09-19 16:31:19 +05:30
|
|
|
assert reference == new
|
|
|
|
|
|
|
|
def test_valid_complete(self,reference_dir):
|
2020-09-30 11:23:25 +05:30
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-09-19 16:31:19 +05:30
|
|
|
assert material_config.is_valid and material_config.is_complete
|
|
|
|
|
|
|
|
def test_invalid_lattice(self,reference_dir):
|
2020-09-30 11:23:25 +05:30
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-09-19 16:31:19 +05:30
|
|
|
material_config['phase']['Aluminum']['lattice']='fxc'
|
|
|
|
assert not material_config.is_valid
|
2020-09-30 12:19:55 +05:30
|
|
|
|
2020-09-19 16:31:19 +05:30
|
|
|
def test_invalid_orientation(self,reference_dir):
|
2020-09-30 11:23:25 +05:30
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-10-02 21:19:52 +05:30
|
|
|
material_config['material'][0]['constituents'][0]['O']=[0,0,0,0]
|
2020-09-19 16:31:19 +05:30
|
|
|
assert not material_config.is_valid
|
2020-09-30 12:19:55 +05:30
|
|
|
|
2020-09-19 16:31:19 +05:30
|
|
|
def test_invalid_fraction(self,reference_dir):
|
2020-09-30 11:23:25 +05:30
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-10-02 21:19:52 +05:30
|
|
|
material_config['material'][0]['constituents'][0]['fraction']=.9
|
2020-09-19 16:31:19 +05:30
|
|
|
assert not material_config.is_valid
|
|
|
|
|
2020-10-02 21:19:52 +05:30
|
|
|
@pytest.mark.parametrize('item',['homogenization','phase','material'])
|
2020-09-19 16:31:19 +05:30
|
|
|
def test_incomplete_missing(self,reference_dir,item):
|
2020-09-30 11:23:25 +05:30
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-09-19 16:31:19 +05:30
|
|
|
del material_config[item]
|
|
|
|
assert not material_config.is_complete
|
2020-09-30 12:19:55 +05:30
|
|
|
|
2020-10-02 21:19:52 +05:30
|
|
|
@pytest.mark.parametrize('item',['O','phase'])
|
2020-09-30 12:19:55 +05:30
|
|
|
def test_incomplete_material_constituent(self,reference_dir,item):
|
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-10-02 21:19:52 +05:30
|
|
|
del material_config['material'][0]['constituents'][0][item]
|
2020-09-30 12:19:55 +05:30
|
|
|
assert not material_config.is_complete
|
|
|
|
|
|
|
|
def test_incomplete_material_homogenization(self,reference_dir):
|
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-10-02 21:19:52 +05:30
|
|
|
del material_config['material'][0]['homogenization']
|
2020-09-30 12:19:55 +05:30
|
|
|
assert not material_config.is_complete
|
|
|
|
|
|
|
|
def test_incomplete_phase_lattice(self,reference_dir):
|
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
|
|
|
del material_config['phase']['Aluminum']['lattice']
|
|
|
|
assert not material_config.is_complete
|
|
|
|
|
2020-09-19 16:31:19 +05:30
|
|
|
def test_incomplete_wrong_phase(self,reference_dir):
|
2020-09-30 11:23:25 +05:30
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-10-02 21:19:52 +05:30
|
|
|
new = material_config.material_rename_phase({'Steel':'FeNbC'})
|
2020-09-19 16:31:19 +05:30
|
|
|
assert not new.is_complete
|
2020-09-30 12:19:55 +05:30
|
|
|
|
2020-09-19 16:31:19 +05:30
|
|
|
def test_incomplete_wrong_homogenization(self,reference_dir):
|
2020-09-30 11:23:25 +05:30
|
|
|
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
2020-10-02 21:19:52 +05:30
|
|
|
new = material_config.material_rename_homogenization({'Taylor':'isostrain'})
|
2020-09-19 16:31:19 +05:30
|
|
|
assert not new.is_complete
|
2020-10-29 12:12:41 +05:30
|
|
|
|
|
|
|
def test_from_table(self):
|
|
|
|
N = np.random.randint(3,10)
|
|
|
|
a = np.vstack((np.hstack((np.arange(N),np.arange(N)[::-1])),np.ones(N*2),np.zeros(N*2),np.ones(N*2))).T
|
|
|
|
t = Table(a,{'varying':2,'constant':2})
|
|
|
|
c = ConfigMaterial.from_table(t,constituents={'a':'varying','b':'1_constant'},c='2_constant')
|
|
|
|
assert len(c['material']) == N
|
|
|
|
for i,m in enumerate(c['material']):
|
|
|
|
c = m['constituents'][0]
|
|
|
|
assert m['c'] == 1 and c['b'] == 0 and c['a'] == [i,1]
|
|
|
|
|