brief but comprehensive "is_complete" reporting
This commit is contained in:
parent
4fc5ba54df
commit
2e7d59ab43
|
@ -245,7 +245,7 @@ class ConfigMaterial(Config):
|
||||||
Check for completeness.
|
Check for completeness.
|
||||||
|
|
||||||
Only the general file layout is considered.
|
Only the general file layout is considered.
|
||||||
This check does not consider whether parameters for
|
This check does not consider whether specific parameters for
|
||||||
a particular phase/homogenization model are missing.
|
a particular phase/homogenization model are missing.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
|
@ -255,51 +255,53 @@ class ConfigMaterial(Config):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ok = True
|
ok = True
|
||||||
for top_level in ['homogenization','phase','material']:
|
msg = []
|
||||||
ok &= top_level in self
|
all = set(['homogenization','phase','material'])
|
||||||
if top_level not in self: print(f'{top_level} entry missing')
|
miss = set([item for item in all if item not in self])
|
||||||
|
empty = set([item for item in all-miss if self[item] is None])
|
||||||
|
|
||||||
|
if miss:
|
||||||
|
msg.append(f'Top-level{"s" if len(miss)>1 else ""} {util.srepr(miss,",",quote=True)} missing')
|
||||||
|
ok = False
|
||||||
|
if empty:
|
||||||
|
msg.append(f'Top-level{"s" if len(empty)>1 else ""} {util.srepr(empty,",",quote=True)} empty')
|
||||||
|
|
||||||
if ok:
|
if ok:
|
||||||
ok &= len(self['material']) > 0
|
ok &= len(self['material']) > 0
|
||||||
if len(self['material']) < 1: print('Incomplete material definition')
|
if len(self['material']) < 1: msg.append('No materials defined')
|
||||||
|
|
||||||
if ok:
|
|
||||||
homogenization = set()
|
homogenization = set()
|
||||||
phase = set()
|
phase = set()
|
||||||
for i,v in enumerate(self['material']):
|
for i,v in enumerate(self['material']):
|
||||||
if 'homogenization' in v:
|
if 'homogenization' in v:
|
||||||
homogenization.add(v['homogenization'])
|
homogenization.add(v['homogenization'])
|
||||||
else:
|
else:
|
||||||
print(f'No homogenization specified in material {i}')
|
msg.append(f'No homogenization specified for material {i}')
|
||||||
ok = False
|
ok = False
|
||||||
|
|
||||||
if 'constituents' in v:
|
if 'constituents' in v:
|
||||||
for ii,vv in enumerate(v['constituents']):
|
for ii,vv in enumerate(v['constituents']):
|
||||||
if 'O' not in vv:
|
if 'O' not in vv:
|
||||||
print('No orientation specified in constituent {ii} of material {i}')
|
msg.append(f'No orientation specified for constituent {ii} of material {i}')
|
||||||
ok = False
|
ok = False
|
||||||
if 'phase' in vv:
|
if 'phase' in vv:
|
||||||
phase.add(vv['phase'])
|
phase.add(vv['phase'])
|
||||||
else:
|
else:
|
||||||
print(f'No phase specified in constituent {ii} of material {i}')
|
msg.append(f'No phase specified for constituent {ii} of material {i}')
|
||||||
ok = False
|
ok = False
|
||||||
|
|
||||||
if self['phase'] is None:
|
for v,other in {'phase':phase,
|
||||||
print('Description of phase dictionary is missing')
|
'homogenization':homogenization}.items():
|
||||||
|
me = set([] if v in empty else self[v])
|
||||||
|
if _miss := other - me:
|
||||||
|
msg.append(f'{v.capitalize()}{"s" if len(_miss)>1 else ""} {util.srepr(_miss,",",quote=True)} missing')
|
||||||
ok = False
|
ok = False
|
||||||
else:
|
_empty = [item for item in me if self[v][item] is None]
|
||||||
if phase - set(self['phase']):
|
if len(_empty) > 0:
|
||||||
print(f'Phase(s) {phase-set(self["phase"])} missing')
|
msg.append(f'{v.capitalize()}{"s" if len(_empty)>1 else ""} {util.srepr(_empty,",",quote=True)} undefined')
|
||||||
ok = False
|
|
||||||
|
|
||||||
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
|
ok = False
|
||||||
|
|
||||||
|
print(util.srepr(msg))
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,10 @@ _colors = {
|
||||||
# Functions
|
# Functions
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
def srepr(msg,
|
def srepr(msg,
|
||||||
glue: str = '\n') -> str:
|
glue: str = '\n',
|
||||||
|
quote: bool = False) -> str:
|
||||||
r"""
|
r"""
|
||||||
Join items with glue string.
|
Join (quoted) items with glue string.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -50,19 +51,22 @@ def srepr(msg,
|
||||||
Items to join.
|
Items to join.
|
||||||
glue : str, optional
|
glue : str, optional
|
||||||
Glue used for joining operation. Defaults to '\n'.
|
Glue used for joining operation. Defaults to '\n'.
|
||||||
|
quote : bool, optional
|
||||||
|
Quote items. Defaults to False.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
joined : str
|
joined : str
|
||||||
String representation of the joined items.
|
String representation of the joined and quoted items.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
q = '"' if quote else ''
|
||||||
if (not hasattr(msg, 'strip') and
|
if (not hasattr(msg, 'strip') and
|
||||||
(hasattr(msg, '__getitem__') or
|
(hasattr(msg, '__getitem__') or
|
||||||
hasattr(msg, '__iter__'))):
|
hasattr(msg, '__iter__'))):
|
||||||
return glue.join(str(x) for x in msg)
|
return glue.join(q+str(x)+q for x in msg)
|
||||||
else:
|
else:
|
||||||
return msg if isinstance(msg,str) else repr(msg)
|
return q+(msg if isinstance(msg,str) else repr(msg))+q
|
||||||
|
|
||||||
|
|
||||||
def emph(msg) -> str:
|
def emph(msg) -> str:
|
||||||
|
|
Loading…
Reference in New Issue