From 4d531d536d5ec4b509c26a2349f999d503aece4b Mon Sep 17 00:00:00 2001 From: Test User Date: Wed, 18 Nov 2020 16:12:38 +0100 Subject: [PATCH 1/7] [skip ci] updated version information after successful test of v3.0.0-alpha-782-ga0b6c2690 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index fe2e304cb..d50ee7c7e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-777-g523a0979e +v3.0.0-alpha-782-ga0b6c2690 From 564ee6c96a6d1896de1a0eb5353e62b5ce66d11b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 18 Nov 2020 16:45:53 +0100 Subject: [PATCH 2/7] make uvw/hkl keyword-only arguments avoid to prefer one over the other, since they are mutually exclusive --- python/damask/_orientation.py | 24 +++++++++++++++--------- python/damask/_result.py | 2 +- python/tests/test_Orientation.py | 12 ++++++------ python/tests/test_Result.py | 4 ++-- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index e60459489..f91cc9850 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -802,7 +802,7 @@ class Orientation(Rotation): return np.all(components >= 0.0,axis=-1) - def IPF_color(self,vector,proper=False): + def IPF_color(self,vector,in_SST=True,proper=False): """ Map vector to RGB color within standard stereographic triangle of own symmetry. @@ -810,6 +810,9 @@ class Orientation(Rotation): ---------- vector : numpy.ndarray of shape (...,3) Vector to colorize. + in_SST : bool, optional + Consider symmetrically equivalent orientations such that poles are located in SST. + Defaults to True. proper : bool, optional Consider only vectors with z >= 0, hence combine two neighboring SSTs (with mirrored colors). Defaults to False. @@ -824,7 +827,7 @@ class Orientation(Rotation): Inverse pole figure color of the e_3 direction for a crystal in "Cube" orientation with cubic symmetry: >>> o = damask.Orientation(lattice='cubic') - >>> o.IPF_color(o.to_SST([0,0,1])) + >>> o.IPF_color([0,0,1]) array([1., 0., 0.]) References @@ -847,10 +850,13 @@ class Orientation(Rotation): ... } """ - vector_ = np.array(vector) - if vector_.shape[-1] != 3: + if np.array(vector).shape[-1] != 3: raise ValueError('Input is not a field of three-dimensional vectors.') + vector_ = self.to_SST(vector,proper) if in_SST else \ + self @ np.broadcast_to(vector,self.shape+(3,)) + + if self.family == 'cubic': basis = {'improper':np.array([ [-1. , 0. , 1. ], [ np.sqrt(2.) , -np.sqrt(2.) , 0. ], @@ -1076,7 +1082,7 @@ class Orientation(Rotation): @classmethod - def Bravais_to_Miller(cls,uvtw=None,hkil=None): + def Bravais_to_Miller(cls,*,uvtw=None,hkil=None): """ Transform 4 Miller–Bravais indices to 3 Miller indices of crystal direction [uvw] or plane normal (hkl). @@ -1104,7 +1110,7 @@ class Orientation(Rotation): @classmethod - def Miller_to_Bravais(cls,uvw=None,hkl=None): + def Miller_to_Bravais(cls,*,uvw=None,hkl=None): """ Transform 3 Miller indices to 4 Miller–Bravais indices of crystal direction [uvtw] or plane normal (hkil). @@ -1133,7 +1139,7 @@ class Orientation(Rotation): return np.einsum('il,...l->...i',basis,axis) - def to_lattice(self,direction=None,plane=None): + def to_lattice(self,*,direction=None,plane=None): """ Calculate lattice vector corresponding to crystal frame direction or plane normal. @@ -1157,7 +1163,7 @@ class Orientation(Rotation): return np.einsum('il,...l->...i',basis,axis) - def to_frame(self,uvw=None,hkl=None,with_symmetry=False): + def to_frame(self,*,uvw=None,hkl=None,with_symmetry=False): """ Calculate crystal frame vector along lattice direction [uvw] or plane normal (hkl). @@ -1185,7 +1191,7 @@ class Orientation(Rotation): np.einsum('il,...l->...i',basis,axis)) - def to_pole(self,uvw=None,hkl=None,with_symmetry=False): + def to_pole(self,*,uvw=None,hkl=None,with_symmetry=False): """ Calculate lab frame vector along lattice direction [uvw] or plane normal (hkl). diff --git a/python/damask/_result.py b/python/damask/_result.py index 45a7fafc6..579e4f00b 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -746,7 +746,7 @@ class Result: 'hex':'hP'}[q['meta']['Lattice']]) return { - 'data': np.uint8(o.IPF_color(o.to_SST(l))*255), + 'data': np.uint8(o.IPF_color(l)*255), 'label': 'IPFcolor_[{} {} {}]'.format(*m), 'meta' : { 'Unit': '8-bit RGB', diff --git a/python/tests/test_Orientation.py b/python/tests/test_Orientation.py index 3e6aad134..ccd757e06 100644 --- a/python/tests/test_Orientation.py +++ b/python/tests/test_Orientation.py @@ -231,11 +231,11 @@ class TestOrientation: @pytest.mark.parametrize('shape',[(1),(2,3),(4,3,2)]) @pytest.mark.parametrize('vector',np.array([[1,0,0],[1,2,3],[-1,1,-1]])) @pytest.mark.parametrize('proper',[True,False]) - def test_IPF_color_vectorization(self,lattice,shape,vector,proper): + @pytest.mark.parametrize('in_SST',[True,False]) + def test_IPF_color_vectorization(self,lattice,shape,vector,proper,in_SST): o = Orientation.from_random(lattice=lattice,shape=shape) - poles = o.to_SST(vector=vector,proper=proper) - for r, theO in zip(o.IPF_color(poles,proper=proper).reshape((-1,3)),o.flatten()): - assert np.allclose(r,theO.IPF_color(theO.to_SST(vector=vector,proper=proper),proper=proper)) + for r, theO in zip(o.IPF_color(vector,in_SST=in_SST,proper=proper).reshape((-1,3)),o.flatten()): + assert np.allclose(r,theO.IPF_color(vector,in_SST=in_SST,proper=proper)) @pytest.mark.parametrize('lattice',Orientation.crystal_families) @pytest.mark.parametrize('a,b',[ @@ -263,14 +263,14 @@ class TestOrientation: cube = Orientation(lattice='cubic') for direction in set(permutations(np.array(color['direction']))): assert np.allclose(np.array(color['RGB']), - cube.IPF_color(cube.to_SST(vector=np.array(direction),proper=proper),proper=proper)) + cube.IPF_color(vector=np.array(direction),proper=proper)) @pytest.mark.parametrize('lattice',Orientation.crystal_families) @pytest.mark.parametrize('proper',[True,False]) def test_IPF_equivalent(self,set_of_quaternions,lattice,proper): direction = np.random.random(3)*2.0-1.0 o = Orientation(rotation=set_of_quaternions,lattice=lattice).equivalent - color = o.IPF_color(o.to_SST(vector=direction,proper=proper),proper=proper) + color = o.IPF_color(vector=direction,proper=proper) assert np.allclose(np.broadcast_to(color[0,...],color.shape),color) @pytest.mark.parametrize('lattice',Orientation.crystal_families) diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index 929c0ef44..ba599366a 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -177,7 +177,7 @@ class TestResult: lattice={'fcc':'cF', 'bcc':'cI', 'hex':'hP'}[crystal_structure]) - in_memory = np.uint8(c.IPF_color(c.to_SST(np.array(d)))*255) + in_memory = np.uint8(c.IPF_color(np.array(d))*255) in_file = default.read_dataset(loc['color']) assert np.allclose(in_memory,in_file) @@ -210,7 +210,7 @@ class TestResult: in_memory = mechanics.Mises_stress(default.read_dataset(loc['sigma'],0)).reshape(-1,1) in_file = default.read_dataset(loc['sigma_vM'],0) assert np.allclose(in_memory,in_file) - + def test_add_Mises_invalid(self,default): default.add_Cauchy('P','F') default.add_calculation('sigma_y','#sigma#',unit='y') From 8b49a4904276e27c6fbe3ef77d7d8e1257de1e50 Mon Sep 17 00:00:00 2001 From: Test User Date: Thu, 19 Nov 2020 01:11:46 +0100 Subject: [PATCH 3/7] [skip ci] updated version information after successful test of v3.0.0-alpha-785-gb22ef7c54 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index d50ee7c7e..4727ed6eb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-782-ga0b6c2690 +v3.0.0-alpha-785-gb22ef7c54 From 96826dca735443f695075603b162581d40510b3e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 19 Nov 2020 09:40:19 +0100 Subject: [PATCH 4/7] Geom.load_ASCII now auto-shifts material indices --- python/damask/_geom.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index f75a48fff..5b545fa41 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -228,7 +228,7 @@ class Geom: else: comments.append(line.strip()) - material = np.empty(grid.prod()) # initialize as flat array + material = np.empty(grid.prod()) # initialize as flat array i = 0 for line in content[header_length:]: items = line.split('#')[0].split() @@ -246,8 +246,8 @@ class Geom: if i != grid.prod(): raise TypeError(f'Invalid file: expected {grid.prod()} entries, found {i}') - if not np.any(np.mod(material,1) != 0.0): # no float present - material = material.astype('int') + if not np.any(np.mod(material,1) != 0.0): # no float present + material = material.astype('int') - (1 if material.min() > 0 else 0) return Geom(material.reshape(grid,order='F'),size,origin,comments) From af3a87b197140e06e1c63625b08077ae653a9b48 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 19 Nov 2020 11:34:55 +0100 Subject: [PATCH 5/7] adjust to new auto-convert of 1-based geom files --- python/tests/test_Geom.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tests/test_Geom.py b/python/tests/test_Geom.py index 5fd4d3b1c..0eeffd7b8 100644 --- a/python/tests/test_Geom.py +++ b/python/tests/test_Geom.py @@ -73,8 +73,8 @@ class TestGeom: size=np.ones(2)) def test_save_load_ASCII(self,default,tmp_path): - default.save_ASCII(tmp_path/'ASCII') - assert geom_equal(Geom.load_ASCII(tmp_path/'ASCII'),default) + default.renumber().save_ASCII(tmp_path/'ASCII') + assert geom_equal(Geom.load_ASCII(tmp_path/'ASCII'),default.renumber()) def test_invalid_origin(self,default): with pytest.raises(ValueError): From 662a033d9199aa12d1b43e667edf3a6775655fc8 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 19 Nov 2020 14:26:15 -0500 Subject: [PATCH 6/7] adapted to VTR geom files --- PRIVATE | 2 +- processing/pre/geom_grainGrowth.py | 8 ++++---- processing/pre/mentat_pbcOnBoxMesh.py | 3 +-- processing/pre/mentat_spectralBox.py | 6 +++--- python/damask/_geom.py | 5 ++--- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/PRIVATE b/PRIVATE index 2d00aa541..d04e6753e 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 2d00aa541f071dbfc200f32e358d324995a061f5 +Subproject commit d04e6753e7e6cea9089ee1d1602c55a715f73d45 diff --git a/processing/pre/geom_grainGrowth.py b/processing/pre/geom_grainGrowth.py index 249cb07f5..5c751d662 100755 --- a/processing/pre/geom_grainGrowth.py +++ b/processing/pre/geom_grainGrowth.py @@ -15,8 +15,8 @@ scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) -getInterfaceEnergy = lambda A,B: np.float32((A*B != 0)*(A != B)*1.0) # 1.0 if A & B are distinct & nonzero, 0.0 otherwise -struc = ndimage.generate_binary_structure(3,1) # 3D von Neumann neighborhood +getInterfaceEnergy = lambda A,B: np.float32((A != B)*1.0) # 1.0 if A & B are distinct, 0.0 otherwise +struc = ndimage.generate_binary_structure(3,1) # 3D von Neumann neighborhood #-------------------------------------------------------------------------------------------------- @@ -62,7 +62,7 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - geom = damask.Geom.load_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name) + geom = damask.Geom.load(StringIO(''.join(sys.stdin.read())) if name is None else name) grid_original = geom.grid damask.util.croak(geom) @@ -174,4 +174,4 @@ for name in filenames: origin = geom.origin, comments = geom.comments + [scriptID + ' ' + ' '.join(sys.argv[1:])], )\ - .save_ASCII(sys.stdout if name is None else name) + .save(sys.stdout if name is None else name) diff --git a/processing/pre/mentat_pbcOnBoxMesh.py b/processing/pre/mentat_pbcOnBoxMesh.py index e03a4e5c5..4a4f3d642 100755 --- a/processing/pre/mentat_pbcOnBoxMesh.py +++ b/processing/pre/mentat_pbcOnBoxMesh.py @@ -11,8 +11,6 @@ import numpy as np import damask -sys.path.append(str(damask.solver.Marc().library_path)) - scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) @@ -235,6 +233,7 @@ if remote and filenames != []: if filenames == []: filenames = [None] if remote: + sys.path.append(str(damask.solver.Marc().library_path)) import py_mentat damask.util.report(scriptName, 'waiting to connect...') diff --git a/processing/pre/mentat_spectralBox.py b/processing/pre/mentat_spectralBox.py index 57c2644c2..d182a6d54 100755 --- a/processing/pre/mentat_spectralBox.py +++ b/processing/pre/mentat_spectralBox.py @@ -9,7 +9,6 @@ import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) -sys.path.append(str(damask.solver.Marc().library_path)) #------------------------------------------------------------------------------------------------- def outMentat(cmd,locals): @@ -185,9 +184,10 @@ parser.set_defaults(port = None, if options.port is not None: try: + sys.path.append(str(damask.solver.Marc().library_path)) import py_mentat except ImportError: - parser.error('no valid Mentat release found.') + parser.error('no valid Mentat release found') # --- loop over input files ------------------------------------------------------------------------ @@ -196,7 +196,7 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - geom = damask.Geom.load_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name) + geom = damask.Geom.load(StringIO(''.join(sys.stdin.read())) if name is None else name) material = geom.material.flatten(order='F') cmds = [\ diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 5b545fa41..b4806a008 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -213,9 +213,8 @@ class Geom: if not keyword.startswith('head') or header_length < 3: raise TypeError('Header length information missing or invalid') - content = f.readlines() - comments = [] + content = f.readlines() for i,line in enumerate(content[:header_length]): items = line.split('#')[0].lower().strip().split() key = items[0] if items else '' @@ -510,7 +509,7 @@ class Geom: Parameters ---------- - fname : str or or pathlib.Path + fname : str or pathlib.Path Filename to write. Valid extension is .vtr, it will be appended if not given. compress : bool, optional Compress with zlib algorithm. Defaults to True. From c354a85f68324be79a0ad3b76e3e86432a248fd3 Mon Sep 17 00:00:00 2001 From: Test User Date: Fri, 20 Nov 2020 05:01:40 +0100 Subject: [PATCH 7/7] [skip ci] updated version information after successful test of v3.0.0-alpha-791-g662a033d9 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 4727ed6eb..2d0bbc133 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-785-gb22ef7c54 +v3.0.0-alpha-791-g662a033d9