Merge branch 'python-polishing' into 'development'

fixed a few small inconsistencies

See merge request damask/DAMASK!367
This commit is contained in:
Sharan Roongta 2021-04-12 07:43:14 +00:00
commit c55724d95d
8 changed files with 544 additions and 536 deletions

View File

@ -1044,7 +1044,8 @@ class Result:
collection = ET.SubElement(domain, 'Grid')
collection.attrib={'GridType': 'Collection',
'CollectionType': 'Temporal'}
'CollectionType': 'Temporal',
'Name': 'Increments'}
time = ET.SubElement(collection, 'Time')
time.attrib={'TimeType': 'List'}
@ -1106,7 +1107,7 @@ class Result:
unit = f[name].attrs[u] if h5py3 else f[name].attrs[u].decode()
attributes.append(ET.SubElement(grid, 'Attribute'))
attributes[-1].attrib = {'Name': name.split('/',2)[2]+f' / {unit}',
attributes[-1].attrib = {'Name': '/'.join([ty,field,out])+f' / {unit}',
'Center': 'Cell',
'AttributeType': attribute_type_map[shape]}
data_items.append(ET.SubElement(attributes[-1], 'DataItem'))
@ -1265,7 +1266,7 @@ class Result:
if prune: r = util.dict_prune(r)
if flatten: r = util.dict_flatten(r)
return r
return None if (type(r) == dict and r == {}) else r
def place(self,output='*',flatten=True,prune=True,constituents=None,fill_float=np.nan,fill_int=0):
@ -1352,4 +1353,4 @@ class Result:
if prune: r = util.dict_prune(r)
if flatten: r = util.dict_flatten(r)
return r
return None if (type(r) == dict and r == {}) else r

View File

@ -137,7 +137,7 @@ def show_progress(iterable,N_iter=None,prefix='',bar_length=50):
Character length of bar. Defaults to 50.
"""
if N_iter == 1 or (hasattr(iterable,'__len__') and len(iterable) == 1):
if N_iter in [0,1] or (hasattr(iterable,'__len__') and len(iterable) <= 1):
for item in iterable:
yield item
else:

View File

@ -65,14 +65,17 @@ class TestResult:
assert dict_equal(a,default.view('times','*').get('F'))
assert dict_equal(a,default.view('times',default.times_in_range(0.0,np.inf)).get('F'))
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
@pytest.mark.parametrize('what',['increments','times','phases','fields']) # ToDo: discuss homogenizations
def test_view_none(self,default,what):
a = default.view(what,False).get('F')
b = default.view(what,[]).get('F')
n0 = default.view(what,False)
n1 = default.view(what,[])
assert a == b == {}
label = 'increments' if what == 'times' else what
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
assert n0.get('F') is n1.get('F') is None and \
len(n0.visible[label]) == len(n1.visible[label]) == 0
@pytest.mark.parametrize('what',['increments','times','phases','fields']) # ToDo: discuss homogenizations
def test_view_more(self,default,what):
empty = default.view(what,False)
@ -81,14 +84,17 @@ class TestResult:
assert dict_equal(a,b)
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
@pytest.mark.parametrize('what',['increments','times','phases','fields']) # ToDo: discuss homogenizations
def test_view_less(self,default,what):
full = default.view(what,True)
a = full.view_less(what,'*').get('F')
b = full.view_less(what,True).get('F')
n0 = full.view_less(what,'*')
n1 = full.view_less(what,True)
assert a == b == {}
label = 'increments' if what == 'times' else what
assert n0.get('F') is n1.get('F') is None and \
len(n0.visible[label]) == len(n1.visible[label]) == 0
def test_view_invalid(self,default):
with pytest.raises(AttributeError):
@ -189,7 +195,7 @@ class TestResult:
default.add_stress_Cauchy('P','F')
default.add_calculation('sigma_y','#sigma#',unit='y')
default.add_equivalent_Mises('sigma_y')
assert default.get('sigma_y_vM') == {}
assert default.get('sigma_y_vM') is None
def test_add_Mises_stress_strain(self,default):
default.add_stress_Cauchy('P','F')
@ -380,8 +386,8 @@ class TestResult:
pickle.dump(cur,f)
with bz2.BZ2File((ref_path/'get'/fname).with_suffix('.pbz2')) as f:
assert dict_equal(cur,pickle.load(f))
ref = pickle.load(f)
assert cur is None if ref is None else dict_equal(cur,ref)
@pytest.mark.parametrize('view,output,flatten,constituents,prune',
[({},['F','P','F','L_p','F_e','F_p'],True,True,None),
@ -405,4 +411,5 @@ class TestResult:
pickle.dump(cur,f)
with bz2.BZ2File((ref_path/'place'/fname).with_suffix('.pbz2')) as f:
assert dict_equal(cur,pickle.load(f))
ref = pickle.load(f)
assert cur is None if ref is None else dict_equal(cur,ref)