From ae959b9cc27fdff24d8060880a5f5c43b91648eb Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 4 Nov 2020 18:08:04 +0100 Subject: [PATCH 01/10] allow '.' in filenames --- python/damask/_vtk.py | 7 +++---- python/tests/test_VTK.py | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index 10f3b482b..9cfcca2ec 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -197,11 +197,10 @@ class VTK: elif isinstance(self.vtk_data,vtk.vtkPolyData): writer = vtk.vtkXMLPolyDataWriter() - default_ext = writer.GetDefaultFileExtension() + default_ext = '.'+writer.GetDefaultFileExtension() ext = Path(fname).suffix - if ext and ext != '.'+default_ext: - raise ValueError(f'Given extension "{ext}" does not match default ".{default_ext}"') - writer.SetFileName(str(Path(fname).with_suffix('.'+default_ext))) + writer.SetFileName(str(fname)+default_ext if default_ext != ext else '') + if compress: writer.SetCompressorTypeToZLib() else: diff --git a/python/tests/test_VTK.py b/python/tests/test_VTK.py index 63adb6454..70d91659a 100644 --- a/python/tests/test_VTK.py +++ b/python/tests/test_VTK.py @@ -85,6 +85,12 @@ class TestVTK: assert(False) + @pytest.mark.parametrize('fname',['a','a.vtp','a.b','a.b.vtp']) + def test_filename_variations(self,tmp_path,fname): + points = np.random.rand(102,3) + v = VTK.from_poly_data(points) + v.save(tmp_path/fname) + @pytest.mark.parametrize('name,dataset_type',[('this_file_does_not_exist.vtk', None), ('this_file_does_not_exist.vtk','vtk'), ('this_file_does_not_exist.vtx', None)]) From 01af348cd973bca4ea9b43ed88d5cf78cc514e0d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 4 Nov 2020 21:14:08 +0100 Subject: [PATCH 02/10] symmetric behavior load/save default name reflects fact that material.yaml has a fixed name --- python/damask/_configmaterial.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index ed45f2662..cdeab3a53 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -24,6 +24,20 @@ class ConfigMaterial(Config): super().save(fname,**kwargs) + @classmethod + def load(cls,fname='material.yaml'): + """ + Load from yaml file. + + Parameters + ---------- + fname : file, str, or pathlib.Path, optional + Filename or file for writing. Defaults to 'material.yaml'. + + """ + return super(ConfigMaterial,cls).load(fname) + + @staticmethod def from_table(table,constituents={},**kwargs): """ From 7341b9830a1a9a9783c7d78ec17473df7f10be37 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 5 Nov 2020 05:39:45 +0100 Subject: [PATCH 03/10] h5py v 3.x handles strings differently --- python/damask/_result.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/damask/_result.py b/python/damask/_result.py index 3f4ca735c..66cc39785 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -21,6 +21,7 @@ from . import grid_filters from . import mechanics from . import util +h5py3 = h5py.__version__[0] == '3' class Result: """ From 1fcf9cb721aa5230f9e790bdd0a4b8d4e06a5d4f Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 5 Nov 2020 05:48:12 +0100 Subject: [PATCH 04/10] don't compute silently the wrong von Mises kind and allow the user to set it explicitly --- python/damask/_result.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index 66cc39785..9ac76259d 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -789,12 +789,17 @@ class Result: @staticmethod - def _add_Mises(T_sym): - t = 'strain' if T_sym['meta']['Unit'] == '1' else \ - 'stress' + def _add_Mises(T_sym,kind): + if kind is None: + if T_sym['meta']['Unit'] == '1': + k = 'strain' + elif T_sym['meta']['Unit'] == 'Pa': + k = 'stress' + if k not in ['stress', 'strain']: + raise ValueError('invalid von Mises kind {kind}') return { - 'data': (mechanics.Mises_strain if t=='strain' else mechanics.Mises_stress)(T_sym['data']), + 'data': (mechanics.Mises_strain if k=='strain' else mechanics.Mises_stress)(T_sym['data']), 'label': f"{T_sym['label']}_vM", 'meta': { 'Unit': T_sym['meta']['Unit'], @@ -802,7 +807,7 @@ class Result: 'Creator': 'add_Mises' } } - def add_Mises(self,T_sym): + def add_Mises(self,T_sym,kind=None): """ Add the equivalent Mises stress or strain of a symmetric tensor. @@ -810,9 +815,12 @@ class Result: ---------- T_sym : str Label of symmetric tensorial stress or strain dataset. + kind : {'stress', 'strain', None}, optional + Kind of the von Mises equivalent. Defaults to None, in which case + it is selected based on the unit of the dataset ('1' -> strain, 'Pa' -> stress'). """ - self._add_generic_pointwise(self._add_Mises,{'T_sym':T_sym}) + self._add_generic_pointwise(self._add_Mises,{'T_sym':T_sym},{'kind':kind}) @staticmethod From 708c83dcf1f59e1d7d896a03dafcf08ca58c09a1 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 5 Nov 2020 07:15:59 +0100 Subject: [PATCH 05/10] polishing --- python/damask/_result.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index 9ac76259d..c453d1097 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -94,7 +94,7 @@ class Result: def __repr__(self): - """Show selected data.""" + """Show summary of file content.""" all_selected_increments = self.selection['increments'] self.pick('increments',all_selected_increments[0:1]) @@ -281,7 +281,7 @@ class Result: for path_old in self.get_dataset_location(name_old): path_new = os.path.join(os.path.dirname(path_old),name_new) f[path_new] = f[path_old] - f[path_new].attrs['Renamed'] = 'Original name: {}'.encode() + f[path_new].attrs['Renamed'] = f'Original name: {name_old}'.encode() del f[path_old] else: raise PermissionError('Rename operation not permitted') From b535b7b805441b61f8576a056ea679aeb2ccd5c7 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 5 Nov 2020 21:13:12 +0100 Subject: [PATCH 06/10] polished tests + documentation --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index 52e51c6a6..92b7b1314 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 52e51c6a69dec5046eef3e369484256b655acbd9 +Subproject commit 92b7b1314a9c576a20f073a230e2aaf811cb932a From 68d384bbdd33330b28f563c6e3837f1d038eba9c Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 5 Nov 2020 21:14:02 +0100 Subject: [PATCH 07/10] bugfix: missing rename --- python/damask/_result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index c453d1097..ac542212d 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -803,7 +803,7 @@ class Result: 'label': f"{T_sym['label']}_vM", 'meta': { 'Unit': T_sym['meta']['Unit'], - 'Description': f"Mises equivalent {t} of {T_sym['label']} ({T_sym['meta']['Description']})", + 'Description': f"Mises equivalent {k} of {T_sym['label']} ({T_sym['meta']['Description']})", 'Creator': 'add_Mises' } } From 30938a8278a5e9ad800a2fb4b28a6c6a6ffb5191 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 5 Nov 2020 21:38:00 +0100 Subject: [PATCH 08/10] correct order (brackets) --- python/damask/_vtk.py | 2 +- python/tests/test_VTK.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index 9cfcca2ec..942be4f1f 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -199,7 +199,7 @@ class VTK: default_ext = '.'+writer.GetDefaultFileExtension() ext = Path(fname).suffix - writer.SetFileName(str(fname)+default_ext if default_ext != ext else '') + writer.SetFileName(str(fname)+(default_ext if default_ext != ext else '')) if compress: writer.SetCompressorTypeToZLib() diff --git a/python/tests/test_VTK.py b/python/tests/test_VTK.py index 70d91659a..bab6051b0 100644 --- a/python/tests/test_VTK.py +++ b/python/tests/test_VTK.py @@ -98,9 +98,10 @@ class TestVTK: with pytest.raises(TypeError): VTK.load(name,dataset_type) - def test_invalid_extension_write(self,default): - with pytest.raises(ValueError): - default.save('default.txt') + def test_add_extension(self,tmp_path,default): + default.save(tmp_path/'default.txt',parallel=False) + assert os.path.isfile(tmp_path/'default.txt.vtr') + def test_invalid_get(self,default): with pytest.raises(ValueError): From 58a5d2666c567ae1f938173c2ed2009bb16074a2 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 5 Nov 2020 23:47:37 +0100 Subject: [PATCH 09/10] ensure correct Mises mode --- python/damask/_result.py | 3 ++- python/tests/test_Result.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index ac542212d..a4130eff3 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -790,7 +790,8 @@ class Result: @staticmethod def _add_Mises(T_sym,kind): - if kind is None: + k = kind + if k is None: if T_sym['meta']['Unit'] == '1': k = 'strain' elif T_sym['meta']['Unit'] == 'Pa': diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index 5ef17cd26..261e6a26c 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -209,6 +209,22 @@ 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') + default.add_Mises('sigma_y') + assert default.get_dataset_location('sigma_y_vM') == [] + + def test_add_Mises_stress_strain(self,default): + default.add_Cauchy('P','F') + default.add_calculation('sigma_y','#sigma#',unit='y') + default.add_calculation('sigma_x','#sigma#',unit='x') + default.add_Mises('sigma_y',kind='strain') + default.add_Mises('sigma_x',kind='stress') + loc = {'y' :default.get_dataset_location('sigma_y_vM'), + 'x' :default.get_dataset_location('sigma_x_vM')} + assert not np.allclose(default.read_dataset(loc['y'],0),default.read_dataset(loc['x'],0)) def test_add_norm(self,default): default.add_norm('F',1) From 10b8a04d892339930ec33ec3ff390442ece4d504 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 6 Nov 2020 00:59:12 +0100 Subject: [PATCH 10/10] no need for fixed-length string --- src/homogenization.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/homogenization.f90 b/src/homogenization.f90 index 02f1d3bf0..33af8ff95 100644 --- a/src/homogenization.f90 +++ b/src/homogenization.f90 @@ -529,7 +529,7 @@ subroutine homogenization_results material_homogenization_type => homogenization_type integer :: p - character(len=pStringLen) :: group_base,group + character(len=:), allocatable :: group_base,group !real(pReal), dimension(:,:,:), allocatable :: temp