initialising dummy arguments with None, making few changes on what is_complete should do

This commit is contained in:
Sharan 2022-11-11 01:14:16 +01:00
parent 443d796643
commit 13df12be1b
3 changed files with 43 additions and 42 deletions

View File

@ -160,7 +160,7 @@ class ConfigMaterial(Config):
pass
base_config = ConfigMaterial({'phase':{k if isinstance(k,int) else str(k):'t.b.d.' for k in np.unique(phase)},
base_config = ConfigMaterial({'phase':{k if isinstance(k,int) else str(k): None for k in np.unique(phase)},
'homogenization':{'direct':{'N_constituents':1}}})
constituent = {k:np.atleast_1d(v[idx].squeeze()) for k,v in zip(['O','phase'],[O,phase])}
@ -209,8 +209,8 @@ class ConfigMaterial(Config):
v: 1.0
phase: Steel
homogenization: SX
homogenization: {SX: {t.b.d}}
phase: {Aluminum: {t.b.d}, Steel: {t.b.d}}
homogenization: {SX: null}
phase: {Aluminum: null, Steel: null}
>>> cm.from_table(t,O='qu',phase='phase',homogenization='single_crystal')
material:
@ -224,8 +224,8 @@ class ConfigMaterial(Config):
v: 1.0
phase: Steel
homogenization: single_crystal
homogenization: {single_crystal: {t.b.d}}
phase: {Aluminum: {t.b.d}, Steel: {t.b.d}}
homogenization: {single_crystal: null}
phase: {Aluminum: null, Steel: null}
"""
kwargs_ = {k:table.get(v) if v in table.labels else np.atleast_2d([v]*len(table)).T for k,v in kwargs.items()}
@ -282,22 +282,22 @@ class ConfigMaterial(Config):
print(f'No phase specified in constituent {ii} of material {i}')
ok = False
for k,v in self['phase'].items():
if 'lattice' not in v:
print(f'No lattice specified in phase {k}')
if self['phase'] is None:
print('Description of phase dictionary is missing')
ok = False
else:
if phase - set(self['phase']):
print(f'Phase(s) {phase-set(self["phase"])} missing')
ok = False
for k,v in self['homogenization'].items():
if 'N_constituents' not in v:
print(f'No. of constituents not specified in homogenization {k}')
if self['homogenization'] is None:
print('Description of homogenization dictionary is missing')
ok = False
else:
if homogenization - set(self['homogenization']):
print(f'Homogenization(s) {homogenization-set(self["homogenization"])} missing')
ok = False
if phase - set(self['phase']):
print(f'Phase(s) {phase-set(self["phase"])} missing')
ok = False
if homogenization - set(self['homogenization']):
print(f'Homogenization(s) {homogenization-set(self["homogenization"])} missing')
ok = False
return ok
@ -320,7 +320,7 @@ class ConfigMaterial(Config):
if 'phase' in self:
for k,v in self['phase'].items():
if 'lattice' in v:
if v is not None and 'lattice' in v:
try:
Orientation(lattice=v['lattice'])
except KeyError:
@ -445,8 +445,8 @@ class ConfigMaterial(Config):
v: 1.0
phase: Martensite
homogenization: SX
homogenization: {SX: {t.b.d}}
phase: {Ferrite: {t.b.d}, Martensite: {t.b.d}}
homogenization: {SX: null}
phase: {Ferrite: null, Martensite: null}
Create a duplex stainless steel microstructure for forming simulations:
@ -474,8 +474,8 @@ class ConfigMaterial(Config):
O: [0.6545817158479885, -0.08004812803625233, -0.6226561293931374, 0.4212059104577611]
v: 0.8
homogenization: Taylor
homogenization: {Taylor: {t.b.d}}
phase: {Austenite: {t.b.d}, Ferrite: {t.b.d}}
homogenization: {Taylor: null}
phase: {Austenite: null, Ferrite: null}
"""
N,n,shaped = 1,1,{}
@ -505,9 +505,9 @@ class ConfigMaterial(Config):
dup = self.copy()
dup['material'] = dup['material'] + mat if 'material' in dup else mat
for k in np.unique(shaped['phase']):
if k not in dup['phase']: dup['phase'][str(k)] = {'t.b.d'}
for k in np.unique(shaped['homogenization']):
if k not in dup['homogenization']: dup['homogenization'][str(k)] = {'t.b.d'}
for what in ['phase','homogenization']:
for k in np.unique(shaped[what]):
if k not in dup[what]: dup[what][str(k)] = None
return dup

View File

@ -1,4 +1,4 @@
phase: {'1': t.b.d., '2': t.b.d.}
phase: {'1': null, '2': null}
homogenization:
direct: {N_constituents: 1}

View File

@ -65,17 +65,6 @@ class TestConfigMaterial:
del material_config['material'][0]['homogenization']
assert not material_config.is_complete
def test_incomplete_homogenization_N_constituents(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
for h in material_config['homogenization'].keys():
del material_config['homogenization'][h]['N_constituents']
assert not material_config.is_complete
def test_incomplete_phase_lattice(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
del material_config['phase']['Aluminum']['lattice']
assert not material_config.is_complete
def test_incomplete_wrong_phase(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
new = material_config.material_rename_phase({'Steel':'FeNbC'})
@ -86,6 +75,16 @@ class TestConfigMaterial:
new = material_config.material_rename_homogenization({'Taylor':'isostrain'})
assert not new.is_complete
def test_empty_phase(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
material_config['phase'] = None
assert not material_config.is_complete
def test_empty_homogenization(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
material_config['homogenization'] = None
assert not material_config.is_complete
def test_from_table(self):
N = np.random.randint(3,10)
a = np.vstack((np.hstack((np.arange(N),np.arange(N)[::-1])),
@ -100,10 +99,12 @@ class TestConfigMaterial:
def test_updated_dicts(self,ref_path):
m1 = ConfigMaterial().material_add(phase=['Aluminum'],O=[1.0,0.0,0.0,0.0],homogenization='SX')
m2 = ConfigMaterial.load(ref_path/'material.yaml').material_add(phase=['Aluminum'],O=[1.0,0.0,0.0,0.0],homogenization='SX')
assert m1['phase'] == {'Aluminum': {'t.b.d'}}
assert m1['homogenization'] == {'SX': {'t.b.d'}}
assert not m2['phase']['Aluminum'] == {}
m2 = ConfigMaterial.load(ref_path/'material.yaml')
for k in m2['phase']:
m2 = m2.material_add(phase=[k],O=[1.0,0.0,0.0,0.0],homogenization='SX')
assert not m2['phase'].get(k) is None
assert m1['phase'].get('Aluminum') is None
assert m1['homogenization'].get('SX') is None
def test_from_table_with_constant(self):
N = np.random.randint(3,10)