From 0ebb9b611d996c83707423891486825900a46c44 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 31 Oct 2020 20:46:21 +0100 Subject: [PATCH 01/10] functionality to sort material id convenient for layered materials --- python/damask/_geom.py | 14 ++++++++++++++ python/tests/test_Geom.py | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 48f022805..1035b92e1 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -800,6 +800,20 @@ class Geom: ) + def sort(self): + """Sort material indices such that min(material) is located at (0,0,0).""" + a = self.material.flatten(order='F') + from_ma = pd.unique(a) + sort_idx = np.argsort(from_ma) + ma = np.unique(a)[sort_idx][np.searchsorted(from_ma,a,sorter = sort_idx)] + + return Geom(material = ma.reshape(self.grid,order='F'), + size = self.size, + origin = self.origin, + comments = self.comments+[util.execution_stamp('Geom','sort')], + ) + + def vicinity_offset(self,vicinity=1,offset=None,trigger=[],periodic=True): """ Offset material index of points in the vicinity of xxx. diff --git a/python/tests/test_Geom.py b/python/tests/test_Geom.py index 0d393a4c4..c8197aa9f 100644 --- a/python/tests/test_Geom.py +++ b/python/tests/test_Geom.py @@ -6,6 +6,7 @@ from damask import Geom from damask import Table from damask import Rotation from damask import util +from damask import seeds from damask import grid_filters @@ -204,6 +205,12 @@ class TestGeom: assert np.array_equiv(t,f) or (not geom_equal(modified,default)) assert geom_equal(default, modified.substitute(t,f)) + def test_sort(self): + grid = np.random.randint(5,20,3) + m = Geom(np.random.randint(1,20,grid)*3,np.ones(3)).sort().material.flatten(order='F') + assert m[0] == m.min() + for i,v in enumerate(m[1:]): + assert v > m[:i+1].max() or v in m[:i+1] @pytest.mark.parametrize('axis_angle',[np.array([1,0,0,86.7]), np.array([0,1,0,90.4]), np.array([0,0,1,90]), np.array([1,0,0,175]),np.array([0,-1,0,178]),np.array([0,0,1,180])]) @@ -384,3 +391,13 @@ class TestGeom: t = Table(np.column_stack((coords,z)),{'coords':3,'z':1}) g = Geom.from_table(t,'coords',['1_coords','z']) assert g.N_materials == g.grid[0]*2 and (g.material[:,:,-1]-g.material[:,:,0] == grid[0]).all() + + + def test_from_table_recover(self,tmp_path): + grid = np.random.randint(60,100,3) + size = np.ones(3)+np.random.rand(3) + s = seeds.from_random(size,np.random.randint(60,100)) + geom = Geom.from_Voronoi_tessellation(grid,size,s) + coords = grid_filters.cell_coord0(grid,size) + t = Table(np.column_stack((coords.reshape(-1,3,order='F'),geom.material.flatten(order='F'))),{'c':3,'m':1}) + assert geom_equal(geom.sort().renumber(),Geom.from_table(t,'c',['m'])) From 212ed62b19eaa4a4b1bcf817d278525afaac20c5 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 2 Nov 2020 12:07:16 +0100 Subject: [PATCH 02/10] pytest-based tests removed unused functionality from deprecated python library modules --- PRIVATE | 2 +- python/damask/_asciitable.py | 35 ----------------------------------- python/damask/_test.py | 6 ------ 3 files changed, 1 insertion(+), 42 deletions(-) diff --git a/PRIVATE b/PRIVATE index e2301f7d1..5a948aff8 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit e2301f7d12ff0ae12218d9b58e33a814eb5431c9 +Subproject commit 5a948aff84c1e117dd0107185223622c5832bf61 diff --git a/python/damask/_asciitable.py b/python/damask/_asciitable.py index 9d762369a..de7596aea 100644 --- a/python/damask/_asciitable.py +++ b/python/damask/_asciitable.py @@ -385,38 +385,3 @@ class ASCIItable(): self.data = np.loadtxt(self.__IO__['in'],usecols=use,ndmin=2) return labels_missing - -# ------------------------------------------------------------------ - def data_write(self): - """Write current data array and report alive output back.""" - if len(self.data) == 0: return True - - if isinstance(self.data[0],list): - return self.output_write(['\t'.join(map(self._quote,items)) for items in self.data]) - else: - return self.output_write( '\t'.join(map(self._quote,self.data))) - -# ------------------------------------------------------------------ - def data_writeArray(self): - """Write whole numpy array data.""" - for row in self.data: - try: - output = list(map(repr,row)) - except Exception: - output = [repr(row)] - - try: - self.__IO__['out'].write('\t'.join(output) + '\n') - except Exception: - pass - -# ------------------------------------------------------------------ - def data_append(self, - what): - if isinstance(what, str): - self.data += [what] - else: - try: - for item in what: self.data_append(item) - except TypeError: - self.data += [str(what)] diff --git a/python/damask/_test.py b/python/damask/_test.py index 5cadc9dfe..000b76e0e 100644 --- a/python/damask/_test.py +++ b/python/damask/_test.py @@ -316,12 +316,6 @@ class Test: return self.compare_Array(refName,curName) - def compare_ArrayCurCur(self,cur0,cur1): - - cur0Name = self.fileInCurrent(cur0) - cur1Name = self.fileInCurrent(cur1) - return self.compare_Array(cur0Name,cur1Name) - def compare_Table(self,headings0,file0, headings1,file1, normHeadings='',normType=None, From 49599e2951ee9b1abcacd4f9e91e31db1e6032b2 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 2 Nov 2020 16:39:19 +0100 Subject: [PATCH 03/10] fixed test --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index 5a948aff8..52e51c6a6 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 5a948aff84c1e117dd0107185223622c5832bf61 +Subproject commit 52e51c6a69dec5046eef3e369484256b655acbd9 From 4d4278e6dd64c6abdfbd92bd4d7c331d7ee15bed Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 2 Nov 2020 18:20:52 -0500 Subject: [PATCH 04/10] shortened tainted_neighborhood logic --- python/damask/_geom.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 6cccad108..03179aac9 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -785,7 +785,7 @@ class Geom: """ def mp(entry,mapper): return mapper[entry] if entry in mapper else entry - + mp = np.vectorize(mp) mapper = dict(zip(from_material,to_material)) @@ -836,13 +836,9 @@ class Geom: def tainted_neighborhood(stencil,trigger): me = stencil[stencil.shape[0]//2] - if len(trigger) == 0: - return np.any(stencil != me) - if me in trigger: - trigger = set(trigger) - trigger.remove(me) - trigger = list(trigger) - return np.any(np.in1d(stencil,np.array(trigger))) + return np.any(stencil != me + if len(trigger) == 0 else + np.in1d(stencil,np.array(list(set(trigger) - {me})))) offset_ = np.nanmax(self.material) if offset is None else offset mask = ndimage.filters.generic_filter(self.material, From 4fa44d388db595d3dcecbe153e23d66359e5a9ce Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 2 Nov 2020 18:21:51 -0500 Subject: [PATCH 05/10] shortened test for monotonous increase of material index after sorting --- python/tests/test_Geom.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/tests/test_Geom.py b/python/tests/test_Geom.py index c8197aa9f..671a3ff4a 100644 --- a/python/tests/test_Geom.py +++ b/python/tests/test_Geom.py @@ -208,8 +208,7 @@ class TestGeom: def test_sort(self): grid = np.random.randint(5,20,3) m = Geom(np.random.randint(1,20,grid)*3,np.ones(3)).sort().material.flatten(order='F') - assert m[0] == m.min() - for i,v in enumerate(m[1:]): + for i,v in enumerate(m): assert v > m[:i+1].max() or v in m[:i+1] @pytest.mark.parametrize('axis_angle',[np.array([1,0,0,86.7]), np.array([0,1,0,90.4]), np.array([0,0,1,90]), From 2867050397e3ce1203ce78b025a2606dd1d28e18 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 2 Nov 2020 18:31:37 -0500 Subject: [PATCH 06/10] corrected shortened test logic --- python/tests/test_Geom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/test_Geom.py b/python/tests/test_Geom.py index 671a3ff4a..5c2777da7 100644 --- a/python/tests/test_Geom.py +++ b/python/tests/test_Geom.py @@ -209,7 +209,7 @@ class TestGeom: grid = np.random.randint(5,20,3) m = Geom(np.random.randint(1,20,grid)*3,np.ones(3)).sort().material.flatten(order='F') for i,v in enumerate(m): - assert v > m[:i+1].max() or v in m[:i+1] + assert i==0 or v > m[:i].max() or v in m[:i] @pytest.mark.parametrize('axis_angle',[np.array([1,0,0,86.7]), np.array([0,1,0,90.4]), np.array([0,0,1,90]), np.array([1,0,0,175]),np.array([0,-1,0,178]),np.array([0,0,1,180])]) From 7dd31658890a8c581559d1b00409506ec5f3814a Mon Sep 17 00:00:00 2001 From: Test User Date: Tue, 3 Nov 2020 11:27:31 +0100 Subject: [PATCH 07/10] [skip ci] updated version information after successful test of v3.0.0-alpha-651-g254e68de1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 888f52164..8789742fe 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-644-g063334fc1 +v3.0.0-alpha-651-g254e68de1 From 6a5f23a0bd2881ae276241e9dd63e472facde7d2 Mon Sep 17 00:00:00 2001 From: Test User Date: Tue, 3 Nov 2020 16:10:11 +0100 Subject: [PATCH 08/10] [skip ci] updated version information after successful test of v3.0.0-alpha-655-g11f1f4f55 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 8789742fe..7167bb8d4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-651-g254e68de1 +v3.0.0-alpha-655-g11f1f4f55 From eaceb16203504791f7a2ad2e43224fad1f7546fd Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Tue, 3 Nov 2020 17:43:57 -0500 Subject: [PATCH 09/10] added +1 to nanmax(material) as auto offset, now consistent with help and intention... --- python/damask/_geom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 03179aac9..9a8c55cd0 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -840,7 +840,7 @@ class Geom: if len(trigger) == 0 else np.in1d(stencil,np.array(list(set(trigger) - {me})))) - offset_ = np.nanmax(self.material) if offset is None else offset + offset_ = np.nanmax(self.material)+1 if offset is None else offset mask = ndimage.filters.generic_filter(self.material, tainted_neighborhood, size=1+2*vicinity, From b8503e84b7789394ea38b1e1abba28267025b05d Mon Sep 17 00:00:00 2001 From: Test User Date: Wed, 4 Nov 2020 06:51:07 +0100 Subject: [PATCH 10/10] [skip ci] updated version information after successful test of v3.0.0-alpha-658-g14209f3a1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7167bb8d4..6868fdf62 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-655-g11f1f4f55 +v3.0.0-alpha-658-g14209f3a1