From 69316f186b6271ca4fa8abe38af8cc7433b3a32a Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Tue, 23 Feb 2021 11:50:13 -0500 Subject: [PATCH] fixed ConfigMaterial.from_table; 2D grid.from_table now acceptable --- python/damask/_configmaterial.py | 9 +++------ python/damask/_grid.py | 4 ++-- python/tests/test_ConfigMaterial.py | 8 +++----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index a19f07a3a..54cc4fd7d 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -68,6 +68,7 @@ class ConfigMaterial(Config): pos pos pos qu qu qu qu phase homog 0 0 0 0 0.19 0.8 0.24 -0.51 Aluminum SX 1 1 0 0 0.8 0.19 0.24 -0.51 Steel SX + 1 1 1 0 0.8 0.19 0.24 -0.51 Steel SX >>> cm.from_table(t,O='qu',phase='phase',homogenization='homog') material: - constituents: @@ -84,15 +85,11 @@ class ConfigMaterial(Config): phase: {} """ - # constituents_ = {k:table.get(v) for k,v in constituents.items()} kwargs_ = {k:table.get(v) for k,v in kwargs.items()} - _,idx = np.unique(kwargs_.values(),return_index=True,axis=0) - # _,idx = np.unique(np.hstack(list({**constituents_,**kwargs_}.values())),return_index=True,axis=0) - + _,idx = np.unique(np.hstack(list(kwargs_.values())),return_index=True,axis=0) idx = np.sort(idx) - # constituents_ = {k:np.atleast_1d(v[idx].squeeze()) for k,v in constituents_.items()} - kwargs_ = {k:np.atleast_1d(v[idx].squeeze()) for k,v in kwargs_.items()} + kwargs_ = {k:np.atleast_1d(v[idx].squeeze()) for k,v in kwargs_.items()} return ConfigMaterial().material_add(**kwargs_) diff --git a/python/damask/_grid.py b/python/damask/_grid.py index 8125fb045..a58f2ca2c 100644 --- a/python/damask/_grid.py +++ b/python/damask/_grid.py @@ -122,7 +122,7 @@ class Grid: @size.setter def size(self,size): - if len(size) != 3 or any(np.array(size) <= 0): + if len(size) != 3 or any(np.array(size) < 0): raise ValueError(f'invalid size {size}') else: self._size = np.array(size) @@ -303,7 +303,7 @@ class Grid: Need to be ordered (1./x fast, 3./z slow). labels : str or list of str Label(s) of the columns containing the material definition. - Each unique combintation of values results in one material ID. + Each unique combination of values results in one material ID. """ cells,size,origin = grid_filters.cellsSizeOrigin_coordinates0_point(table.get(coordinates)) diff --git a/python/tests/test_ConfigMaterial.py b/python/tests/test_ConfigMaterial.py index ae99a0bc6..6c316aeaa 100644 --- a/python/tests/test_ConfigMaterial.py +++ b/python/tests/test_ConfigMaterial.py @@ -89,12 +89,10 @@ class TestConfigMaterial: a = np.vstack((np.hstack((np.arange(N),np.arange(N)[::-1])),np.ones(N*2),np.zeros(N*2),np.ones(N*2),np.ones(N*2))).T print(a) t = Table(a,{'varying':1,'constant':4}) - c = ConfigMaterial.from_table(t,**{'phase':'varying','O':'constant'}) + c = ConfigMaterial.from_table(t,**{'phase':'varying','O':'constant','homogenization':'4_constant'}) assert len(c['material']) == N - print(c) - # for i,m in enumerate(c['material']): - # c = m['constituents'][0] - # assert m['c'] == 1 and c['b'] == 0 and (c['a'] == [i,1]).all() + for i,m in enumerate(c['material']): + assert m['homogenization'] == 1 and (m['constituents'][0]['O'] == [1,0,1,1]).all() @pytest.mark.parametrize('N,n,kw',[ (1,1,{'phase':'Gold',