inform the user about missing items in material.yaml

This commit is contained in:
Martin Diehl 2020-09-21 19:10:20 +02:00
parent 6f45203c98
commit 5ef761fb98
1 changed files with 50 additions and 13 deletions

View File

@ -59,18 +59,55 @@ class Material(dict):
@property @property
def is_complete(self): def is_complete(self):
"""Check for completeness.""" """Check for completeness."""
try: ok = True
ok = len(self['microstructure']) > 0 for top_level in ['homogenization','phase','microstructure']:
for m in self['microstructure']: # ToDo: With python 3.8 as prerequisite we can shorten with :=
ok &= m['homogenization'] in self['homogenization'] ok &= top_level in self
for c in m['constituents']: if top_level not in self: print(f'{top_level} entry missing')
c['orientation']
ok &= c['phase'] in self['phase'] if ok:
for p in self['phase'].values(): ok &= len(self['microstructure']) > 0
ok &= 'lattice' in p if len(self['microstructure']) < 1: print('Incomplete microstructure definition')
return ok
except KeyError: if ok:
return False homogenization = set()
phase = set()
for i,v in enumerate(self['microstructure']):
if 'homogenization' in v:
homogenization.add(v['homogenization'])
else:
print(f'No homogenization specified in microstructure {i}')
ok = False
if 'constituents' in v:
for ii,vv in enumerate(v['constituents']):
if 'orientation' not in vv:
print('No orientation specified in constituent {ii} of microstructure {i}')
ok = False
if 'phase' in vv:
phase.add(vv['phase'])
else:
print(f'No phase specified in constituent {ii} of microstructure {i}')
ok = False
for k,v in self['phase'].items():
if 'lattice' not in v:
print(f'No lattice specified in phase {k}')
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}'}
# 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
@property @property
@ -79,7 +116,7 @@ class Material(dict):
ok = True ok = True
if 'phase' in self: if 'phase' in self:
for k,v in zip(self['phase'].keys(),self['phase'].values()): for k,v in self['phase'].items():
if 'lattice' in v: if 'lattice' in v:
try: try:
Lattice(v['lattice']) Lattice(v['lattice'])