From b383a4530e66b03b3d811e384cc7fa8ef3ecc5b9 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 30 Sep 2020 07:53:25 +0200 Subject: [PATCH 01/39] better name, subclassing for easy extension to load --- python/damask/__init__.py | 29 ++++---- python/damask/_config.py | 66 +++++++++++++++++++ .../{_material.py => _configmaterial.py} | 51 +------------- .../material.yaml | 0 ...est_Material.py => test_MaterialConfig.py} | 24 +++---- 5 files changed, 95 insertions(+), 75 deletions(-) create mode 100644 python/damask/_config.py rename python/damask/{_material.py => _configmaterial.py} (80%) rename python/tests/reference/{Material => ConfigMaterial}/material.yaml (100%) rename python/tests/{test_Material.py => test_MaterialConfig.py} (68%) diff --git a/python/damask/__init__.py b/python/damask/__init__.py index e21ebd03d..955993607 100644 --- a/python/damask/__init__.py +++ b/python/damask/__init__.py @@ -10,20 +10,21 @@ with open(_Path(__file__).parent/_Path('VERSION')) as _f: # make classes directly accessible as damask.Class from ._environment import Environment as _ # noqa environment = _() -from ._table import Table # noqa -from ._vtk import VTK # noqa -from ._colormap import Colormap # noqa -from ._rotation import Rotation # noqa -from ._lattice import Symmetry, Lattice# noqa -from ._orientation import Orientation # noqa -from ._result import Result # noqa -from ._geom import Geom # noqa -from ._material import Material # noqa -from . import solver # noqa -from . import util # noqa -from . import seeds # noqa -from . import grid_filters # noqa -from . import mechanics # noqa +from ._table import Table # noqa +from ._vtk import VTK # noqa +from ._colormap import Colormap # noqa +from ._rotation import Rotation # noqa +from ._lattice import Symmetry, Lattice# noqa +from ._orientation import Orientation # noqa +from ._result import Result # noqa +from ._geom import Geom # noqa +from ._config import Config # noqa +from ._configmaterial import ConfigMaterial # noqa +from . import solver # noqa +from . import util # noqa +from . import seeds # noqa +from . import grid_filters # noqa +from . import mechanics # noqa diff --git a/python/damask/_config.py b/python/damask/_config.py new file mode 100644 index 000000000..0e21286aa --- /dev/null +++ b/python/damask/_config.py @@ -0,0 +1,66 @@ +from io import StringIO +import abc + +import yaml +import numpy as np + +class NiceDumper(yaml.SafeDumper): + """Make YAML readable for humans.""" + + def write_line_break(self, data=None): + super().write_line_break(data) + + if len(self.indents) == 1: + super().write_line_break() + + def increase_indent(self, flow=False, indentless=False): + return super().increase_indent(flow, False) + + +class Config(dict): + """YAML-based configuration.""" + + def __repr__(self): + """Show as in file.""" + output = StringIO() + self.save(output) + output.seek(0) + return ''.join(output.readlines()) + + @classmethod + def load(cls,fname): + """Load from yaml file.""" + try: + fhandle = open(fname) + except TypeError: + fhandle = fname + return cls(yaml.safe_load(fhandle)) + + def save(self,fname='material.yaml'): + """ + Save to yaml file. + + Parameters + ---------- + fname : file, str, or pathlib.Path + Filename or file for reading. + + """ + try: + fhandle = open(fname,'w') + except TypeError: + fhandle = fname + fhandle.write(yaml.dump(dict(self),width=256,default_flow_style=None,Dumper=NiceDumper)) + + + @property + @abc.abstractmethod + def is_complete(self): + """Check for completeness.""" + pass + + @property + @abc.abstractmethod + def is_valid(self): + """Check for valid file layout.""" + pass diff --git a/python/damask/_material.py b/python/damask/_configmaterial.py similarity index 80% rename from python/damask/_material.py rename to python/damask/_configmaterial.py index 106d1582e..861e41464 100644 --- a/python/damask/_material.py +++ b/python/damask/_configmaterial.py @@ -1,61 +1,14 @@ -from io import StringIO import copy -import yaml import numpy as np +from . import Config from . import Lattice from . import Rotation -class NiceDumper(yaml.SafeDumper): - """Make YAML readable for humans.""" - - def write_line_break(self, data=None): - super().write_line_break(data) - - if len(self.indents) == 1: - super().write_line_break() - - def increase_indent(self, flow=False, indentless=False): - return super().increase_indent(flow, False) - - -class Material(dict): +class ConfigMaterial(Config): """Material configuration.""" - def __repr__(self): - """Show as in file.""" - output = StringIO() - self.save(output) - output.seek(0) - return ''.join(output.readlines()) - - @staticmethod - def load(fname): - """Load from yaml file.""" - try: - fhandle = open(fname) - except TypeError: - fhandle = fname - return Material(yaml.safe_load(fhandle)) - - def save(self,fname='material.yaml'): - """ - Save to yaml file. - - Parameters - ---------- - fname : file, str, or pathlib.Path - Filename or file for reading. - - """ - try: - fhandle = open(fname,'w') - except TypeError: - fhandle = fname - fhandle.write(yaml.dump(dict(self),width=256,default_flow_style=None,Dumper=NiceDumper)) - - @property def is_complete(self): """Check for completeness.""" diff --git a/python/tests/reference/Material/material.yaml b/python/tests/reference/ConfigMaterial/material.yaml similarity index 100% rename from python/tests/reference/Material/material.yaml rename to python/tests/reference/ConfigMaterial/material.yaml diff --git a/python/tests/test_Material.py b/python/tests/test_MaterialConfig.py similarity index 68% rename from python/tests/test_Material.py rename to python/tests/test_MaterialConfig.py index 567dfe646..1be07fe58 100644 --- a/python/tests/test_Material.py +++ b/python/tests/test_MaterialConfig.py @@ -2,60 +2,60 @@ import os import pytest -from damask import Material +from damask import ConfigMaterial @pytest.fixture def reference_dir(reference_dir_base): """Directory containing reference results.""" - return reference_dir_base/'Material' + return reference_dir_base/'ConfigMaterial' class TestMaterial: @pytest.mark.parametrize('fname',[None,'test.yaml']) def test_load_save(self,reference_dir,tmp_path,fname): - reference = Material.load(reference_dir/'material.yaml') + reference = ConfigMaterial.load(reference_dir/'material.yaml') os.chdir(tmp_path) if fname is None: reference.save() - new = Material.load('material.yaml') + new = ConfigMaterial.load('material.yaml') else: reference.save(fname) - new = Material.load(fname) + new = ConfigMaterial.load(fname) assert reference == new def test_valid_complete(self,reference_dir): - material_config = Material.load(reference_dir/'material.yaml') + material_config = ConfigMaterial.load(reference_dir/'material.yaml') assert material_config.is_valid and material_config.is_complete def test_invalid_lattice(self,reference_dir): - material_config = Material.load(reference_dir/'material.yaml') + material_config = ConfigMaterial.load(reference_dir/'material.yaml') material_config['phase']['Aluminum']['lattice']='fxc' assert not material_config.is_valid def test_invalid_orientation(self,reference_dir): - material_config = Material.load(reference_dir/'material.yaml') + material_config = ConfigMaterial.load(reference_dir/'material.yaml') material_config['microstructure'][0]['constituents'][0]['orientation']=[0,0,0,0] assert not material_config.is_valid def test_invalid_fraction(self,reference_dir): - material_config = Material.load(reference_dir/'material.yaml') + material_config = ConfigMaterial.load(reference_dir/'material.yaml') material_config['microstructure'][0]['constituents'][0]['fraction']=.9 assert not material_config.is_valid @pytest.mark.parametrize('item',['homogenization','phase','microstructure']) def test_incomplete_missing(self,reference_dir,item): - material_config = Material.load(reference_dir/'material.yaml') + material_config = ConfigMaterial.load(reference_dir/'material.yaml') del material_config[item] assert not material_config.is_complete def test_incomplete_wrong_phase(self,reference_dir): - material_config = Material.load(reference_dir/'material.yaml') + material_config = ConfigMaterial.load(reference_dir/'material.yaml') new = material_config.microstructure_rename_phase({'Steel':'FeNbC'}) assert not new.is_complete def test_incomplete_wrong_homogenization(self,reference_dir): - material_config = Material.load(reference_dir/'material.yaml') + material_config = ConfigMaterial.load(reference_dir/'material.yaml') new = material_config.microstructure_rename_homogenization({'Taylor':'isostrain'}) assert not new.is_complete From bbed4f9c6e200fe9da587fc81bfd5aefb4b5ef48 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 30 Sep 2020 08:15:02 +0200 Subject: [PATCH 02/39] nice formatting will be checked by pre-receive hook --- .../SpectralMethod/Polycrystal/material.yaml | 205 +++++++++--------- .../reference/ConfigMaterial/material.yaml | 10 +- 2 files changed, 108 insertions(+), 107 deletions(-) diff --git a/examples/SpectralMethod/Polycrystal/material.yaml b/examples/SpectralMethod/Polycrystal/material.yaml index 16c6042a6..a3b75c5a3 100644 --- a/examples/SpectralMethod/Polycrystal/material.yaml +++ b/examples/SpectralMethod/Polycrystal/material.yaml @@ -1,107 +1,109 @@ homogenization: SX: mech: {type: none} + microstructure: -- constituents: - - fraction: 1.0 - orientation: [1.0, 0.0, 0.0, 0.0] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.7936696712125002, -0.28765777461664166, -0.3436487135089419, 0.4113964260949434] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.3986143167493579, -0.7014883552495493, 0.2154871765709027, 0.5500781677772945] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.28645844315788244, -0.022571491243423537, -0.467933059311115, -0.8357456192708106] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.33012772942625784, -0.6781865350268957, 0.6494525351030648, 0.09638521992649676] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.43596817439583935, -0.5982537129781701, 0.046599032277502436, 0.6707106499919265] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.169734823419553, -0.699615227367322, -0.6059581215838098, -0.33844257746495854] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.9698864809294915, 0.1729052643205874, -0.15948307917616958, 0.06315956884687175] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.46205660912967883, 0.3105054068891252, -0.617849551030653, 0.555294529545738] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.4512443497461787, -0.7636045534540555, -0.04739348426715133, -0.45939142396805815] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.2161856212656443, -0.6581450184826598, -0.5498086209601588, 0.4667112513346289] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.8753220715350803, -0.4561599367657419, -0.13298279533852678, -0.08969369719975541] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.11908260752431069, 0.18266024809834172, -0.7144822594012615, -0.664807992845101] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.751104669484278, 0.5585633382623958, -0.34579336397009175, 0.06538900566860861] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.08740438971703973, 0.8991264096610437, -0.4156704205935976, 0.10559485570696363] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.5584325870096193, 0.6016408353068798, -0.14280340445801173, 0.5529814994483859] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.4052725440888093, 0.25253073423599154, 0.5693263597910454, -0.669215876471182] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.7570164606888676, 0.15265448024694664, -0.5998021466848317, 0.20942796551297105] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.6987659297138081, -0.132172211261028, -0.19693254724422338, 0.6748883269678543] - phase: Aluminum - homogenization: SX -- constituents: - - fraction: 1.0 - orientation: [0.7729330445886478, 0.21682179052722322, -0.5207379472917645, 0.2905078484066341] - phase: Aluminum - homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [1.0, 0.0, 0.0, 0.0] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.7936696712125002, -0.28765777461664166, -0.3436487135089419, 0.4113964260949434] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.3986143167493579, -0.7014883552495493, 0.2154871765709027, 0.5500781677772945] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.28645844315788244, -0.022571491243423537, -0.467933059311115, -0.8357456192708106] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.33012772942625784, -0.6781865350268957, 0.6494525351030648, 0.09638521992649676] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.43596817439583935, -0.5982537129781701, 0.046599032277502436, 0.6707106499919265] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.169734823419553, -0.699615227367322, -0.6059581215838098, -0.33844257746495854] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.9698864809294915, 0.1729052643205874, -0.15948307917616958, 0.06315956884687175] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.46205660912967883, 0.3105054068891252, -0.617849551030653, 0.555294529545738] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.4512443497461787, -0.7636045534540555, -0.04739348426715133, -0.45939142396805815] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.2161856212656443, -0.6581450184826598, -0.5498086209601588, 0.4667112513346289] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.8753220715350803, -0.4561599367657419, -0.13298279533852678, -0.08969369719975541] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.11908260752431069, 0.18266024809834172, -0.7144822594012615, -0.664807992845101] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.751104669484278, 0.5585633382623958, -0.34579336397009175, 0.06538900566860861] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.08740438971703973, 0.8991264096610437, -0.4156704205935976, 0.10559485570696363] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.5584325870096193, 0.6016408353068798, -0.14280340445801173, 0.5529814994483859] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.4052725440888093, 0.25253073423599154, 0.5693263597910454, -0.669215876471182] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.7570164606888676, 0.15265448024694664, -0.5998021466848317, 0.20942796551297105] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.6987659297138081, -0.132172211261028, -0.19693254724422338, 0.6748883269678543] + phase: Aluminum + homogenization: SX + - constituents: + - fraction: 1.0 + orientation: [0.7729330445886478, 0.21682179052722322, -0.5207379472917645, 0.2905078484066341] + phase: Aluminum + homogenization: SX + phase: Aluminum: elasticity: {C_11: 106.75e9, C_12: 60.41e9, C_44: 28.34e9, type: hooke} @@ -117,7 +119,6 @@ phase: h_sl_sl: [1, 1, 1.4, 1.4, 1.4, 1.4] n_sl: 20 output: [xi_sl] + type: phenopowerlaw xi_0_sl: [31e6] xi_inf_sl: [63e6] - type: phenopowerlaw - diff --git a/python/tests/reference/ConfigMaterial/material.yaml b/python/tests/reference/ConfigMaterial/material.yaml index 1d3cf08a8..395c38373 100644 --- a/python/tests/reference/ConfigMaterial/material.yaml +++ b/python/tests/reference/ConfigMaterial/material.yaml @@ -2,7 +2,7 @@ homogenization: SX: mech: {type: none} Taylor: - mech: {type: isostrain, N_constituents: 2} + mech: {N_constituents: 2, type: isostrain} microstructure: - constituents: @@ -20,14 +20,14 @@ microstructure: orientation: [0.3986143167493579, -0.7014883552495493, 0.2154871765709027, 0.5500781677772945] phase: Aluminum homogenization: SX - - homogenization: Taylor - constituents: - - fraction: .5 + - constituents: + - fraction: 0.5 orientation: [0.28645844315788244, -0.022571491243423537, -0.467933059311115, -0.8357456192708106] phase: Aluminum - - fraction: .5 + - fraction: 0.5 orientation: [0.3986143167493579, -0.7014883552495493, 0.2154871765709027, 0.5500781677772945] phase: Steel + homogenization: Taylor phase: Aluminum: From fdfcb16d150b1089f74ea34ff2fd3d047aca2bd1 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 30 Sep 2020 08:16:12 +0200 Subject: [PATCH 03/39] not needed --- python/damask/_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/damask/_config.py b/python/damask/_config.py index 0e21286aa..8fd52a046 100644 --- a/python/damask/_config.py +++ b/python/damask/_config.py @@ -2,7 +2,6 @@ from io import StringIO import abc import yaml -import numpy as np class NiceDumper(yaml.SafeDumper): """Make YAML readable for humans.""" From 5ad46ae02134c6f9276b0818519af0548fdafd0a Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 30 Sep 2020 08:49:55 +0200 Subject: [PATCH 04/39] completely tested --- python/damask/_config.py | 14 ++++++-- python/damask/_configmaterial.py | 12 +++++++ python/tests/test_Config.py | 34 +++++++++++++++++++ ...terialConfig.py => test_ConfigMaterial.py} | 29 ++++++++++++---- 4 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 python/tests/test_Config.py rename python/tests/{test_MaterialConfig.py => test_ConfigMaterial.py} (73%) diff --git a/python/damask/_config.py b/python/damask/_config.py index 8fd52a046..7b9d950a7 100644 --- a/python/damask/_config.py +++ b/python/damask/_config.py @@ -28,21 +28,29 @@ class Config(dict): @classmethod def load(cls,fname): - """Load from yaml file.""" + """ + Load from yaml file. + + Parameters + ---------- + fname : file, str, or pathlib.Path + Filename or file for writing. + + """ try: fhandle = open(fname) except TypeError: fhandle = fname return cls(yaml.safe_load(fhandle)) - def save(self,fname='material.yaml'): + def save(self,fname): """ Save to yaml file. Parameters ---------- fname : file, str, or pathlib.Path - Filename or file for reading. + Filename or file for writing. """ try: diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index 861e41464..8b6739763 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -9,6 +9,18 @@ from . import Rotation class ConfigMaterial(Config): """Material configuration.""" + def save(self,fname='material.yaml'): + """ + Save to yaml file. + + Parameters + ---------- + fname : file, str, or pathlib.Path, optional + Filename or file for writing. Defaults to 'material.yaml'. + + """ + super().save(fname) + @property def is_complete(self): """Check for completeness.""" diff --git a/python/tests/test_Config.py b/python/tests/test_Config.py new file mode 100644 index 000000000..e4d05cffb --- /dev/null +++ b/python/tests/test_Config.py @@ -0,0 +1,34 @@ +from damask import Config + +class TestConfig: + + def test_load_save_str(self,tmp_path): + config = Config() + config['A'] = 1 + config['B'] = [2,3] + config.save(tmp_path/'config.yaml') + assert Config.load(tmp_path/'config.yaml') == config + + def test_load_save_file(self,tmp_path): + config = Config() + config['A'] = 1 + config['B'] = [2,3] + with open(tmp_path/'config.yaml','w') as f: + config.save(f) + with open(tmp_path/'config.yaml') as f: + assert Config.load(f) == config + + def test_repr(self,tmp_path): + config = Config() + config['A'] = 1 + config['B'] = [2,3] + with open(tmp_path/'config.yaml','w') as f: + f.write(config.__repr__()) + assert Config.load(tmp_path/'config.yaml') == config + + + def test_abstract_is_valid(self): + assert Config().is_valid is None + + def test_abstract_is_complete(self): + assert Config().is_complete is None diff --git a/python/tests/test_MaterialConfig.py b/python/tests/test_ConfigMaterial.py similarity index 73% rename from python/tests/test_MaterialConfig.py rename to python/tests/test_ConfigMaterial.py index 1be07fe58..27889d564 100644 --- a/python/tests/test_MaterialConfig.py +++ b/python/tests/test_ConfigMaterial.py @@ -10,8 +10,8 @@ def reference_dir(reference_dir_base): return reference_dir_base/'ConfigMaterial' -class TestMaterial: - +class TestConfigMaterial: + @pytest.mark.parametrize('fname',[None,'test.yaml']) def test_load_save(self,reference_dir,tmp_path,fname): reference = ConfigMaterial.load(reference_dir/'material.yaml') @@ -32,29 +32,44 @@ class TestMaterial: material_config = ConfigMaterial.load(reference_dir/'material.yaml') material_config['phase']['Aluminum']['lattice']='fxc' assert not material_config.is_valid - + def test_invalid_orientation(self,reference_dir): material_config = ConfigMaterial.load(reference_dir/'material.yaml') material_config['microstructure'][0]['constituents'][0]['orientation']=[0,0,0,0] assert not material_config.is_valid - + def test_invalid_fraction(self,reference_dir): material_config = ConfigMaterial.load(reference_dir/'material.yaml') material_config['microstructure'][0]['constituents'][0]['fraction']=.9 assert not material_config.is_valid - @pytest.mark.parametrize('item',['homogenization','phase','microstructure']) def test_incomplete_missing(self,reference_dir,item): material_config = ConfigMaterial.load(reference_dir/'material.yaml') del material_config[item] assert not material_config.is_complete - + + @pytest.mark.parametrize('item',['orientation','phase']) + def test_incomplete_material_constituent(self,reference_dir,item): + material_config = ConfigMaterial.load(reference_dir/'material.yaml') + del material_config['microstructure'][0]['constituents'][0][item] + assert not material_config.is_complete + + def test_incomplete_material_homogenization(self,reference_dir): + material_config = ConfigMaterial.load(reference_dir/'material.yaml') + del material_config['microstructure'][0]['homogenization'] + assert not material_config.is_complete + + def test_incomplete_phase_lattice(self,reference_dir): + material_config = ConfigMaterial.load(reference_dir/'material.yaml') + del material_config['phase']['Aluminum']['lattice'] + assert not material_config.is_complete + def test_incomplete_wrong_phase(self,reference_dir): material_config = ConfigMaterial.load(reference_dir/'material.yaml') new = material_config.microstructure_rename_phase({'Steel':'FeNbC'}) assert not new.is_complete - + def test_incomplete_wrong_homogenization(self,reference_dir): material_config = ConfigMaterial.load(reference_dir/'material.yaml') new = material_config.microstructure_rename_homogenization({'Taylor':'isostrain'}) From 33685bc493b6e80b559f602323623205e3cf704a Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 30 Sep 2020 12:32:37 +0200 Subject: [PATCH 05/39] allow user do control output style (numerics.yaml looks strange otherwise) --- python/damask/_config.py | 11 +++++++++-- python/damask/_configmaterial.py | 6 ++++-- python/tests/test_Config.py | 7 +++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/python/damask/_config.py b/python/damask/_config.py index 7b9d950a7..c9130d7aa 100644 --- a/python/damask/_config.py +++ b/python/damask/_config.py @@ -43,7 +43,7 @@ class Config(dict): fhandle = fname return cls(yaml.safe_load(fhandle)) - def save(self,fname): + def save(self,fname,**kwargs): """ Save to yaml file. @@ -51,13 +51,20 @@ class Config(dict): ---------- fname : file, str, or pathlib.Path Filename or file for writing. + **kwargs : dict + Keyword arguments parsed to yaml.dump. """ try: fhandle = open(fname,'w') except TypeError: fhandle = fname - fhandle.write(yaml.dump(dict(self),width=256,default_flow_style=None,Dumper=NiceDumper)) + + if 'width' not in kwargs: + kwargs['width'] = 256 + if 'default_flow_style' not in kwargs: + kwargs['default_flow_style'] = None + fhandle.write(yaml.dump(dict(self),Dumper=NiceDumper,**kwargs)) @property diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index 8b6739763..3eb7180e2 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -9,7 +9,7 @@ from . import Rotation class ConfigMaterial(Config): """Material configuration.""" - def save(self,fname='material.yaml'): + def save(self,fname='material.yaml',**kwargs): """ Save to yaml file. @@ -17,9 +17,11 @@ class ConfigMaterial(Config): ---------- fname : file, str, or pathlib.Path, optional Filename or file for writing. Defaults to 'material.yaml'. + **kwargs : dict + Keyword arguments parsed to yaml.dump. """ - super().save(fname) + super().save(fname,**kwargs) @property def is_complete(self): diff --git a/python/tests/test_Config.py b/python/tests/test_Config.py index e4d05cffb..e715ad763 100644 --- a/python/tests/test_Config.py +++ b/python/tests/test_Config.py @@ -1,12 +1,15 @@ +import pytest + from damask import Config class TestConfig: - def test_load_save_str(self,tmp_path): + @pytest.mark.parametrize('flow_style',[None,True,False]) + def test_load_save_str(self,tmp_path,flow_style): config = Config() config['A'] = 1 config['B'] = [2,3] - config.save(tmp_path/'config.yaml') + config.save(tmp_path/'config.yaml',default_flow_style=flow_style) assert Config.load(tmp_path/'config.yaml') == config def test_load_save_file(self,tmp_path): From 898306f82e2b666bb3a9f265d5dbeda4f8828336 Mon Sep 17 00:00:00 2001 From: Sharan Roongta Date: Wed, 30 Sep 2020 23:33:09 +0200 Subject: [PATCH 06/39] sanity check for key mismatch --- src/IO.f90 | 3 +++ src/YAML_types.f90 | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/IO.f90 b/src/IO.f90 index 0542e7a62..ee35cf1bc 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -498,6 +498,9 @@ subroutine IO_error(error_ID,el,ip,g,instance,ext_msg) msg = 'Abrupt end of file' case (708) msg = '--- expected after YAML file header' + case (710) + msg = 'key mismatch' + !------------------------------------------------------------------------------------------------- ! errors related to the grid solver diff --git a/src/YAML_types.f90 b/src/YAML_types.f90 index cc1c85efd..86acf05be 100644 --- a/src/YAML_types.f90 +++ b/src/YAML_types.f90 @@ -952,6 +952,9 @@ function tNode_get_byKey_asIndex(self,key) result(keyIndex) endif enddo + if(keyIndex == -1) call IO_error(710,ext_msg=key) + + end function tNode_get_byKey_asIndex From 85b96209e3a43aea264947a456f4517e5c3b00a0 Mon Sep 17 00:00:00 2001 From: Sharan Roongta Date: Thu, 1 Oct 2020 01:51:31 +0200 Subject: [PATCH 07/39] use existing error description --- src/IO.f90 | 3 --- src/YAML_types.f90 | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/IO.f90 b/src/IO.f90 index ee35cf1bc..0542e7a62 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -498,9 +498,6 @@ subroutine IO_error(error_ID,el,ip,g,instance,ext_msg) msg = 'Abrupt end of file' case (708) msg = '--- expected after YAML file header' - case (710) - msg = 'key mismatch' - !------------------------------------------------------------------------------------------------- ! errors related to the grid solver diff --git a/src/YAML_types.f90 b/src/YAML_types.f90 index 86acf05be..09a2d0592 100644 --- a/src/YAML_types.f90 +++ b/src/YAML_types.f90 @@ -952,7 +952,7 @@ function tNode_get_byKey_asIndex(self,key) result(keyIndex) endif enddo - if(keyIndex == -1) call IO_error(710,ext_msg=key) + if(keyIndex == -1) call IO_error(140,ext_msg=key) end function tNode_get_byKey_asIndex From 1b18cae46bc5a2195cfb2fb675b3518306cb084a Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 2 Oct 2020 17:49:52 +0200 Subject: [PATCH 08/39] adjusted to new names --- .../tests/reference/ConfigMaterial/material.yaml | 12 ++++++------ python/tests/test_ConfigMaterial.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/python/tests/reference/ConfigMaterial/material.yaml b/python/tests/reference/ConfigMaterial/material.yaml index 395c38373..5c006c99c 100644 --- a/python/tests/reference/ConfigMaterial/material.yaml +++ b/python/tests/reference/ConfigMaterial/material.yaml @@ -4,28 +4,28 @@ homogenization: Taylor: mech: {N_constituents: 2, type: isostrain} -microstructure: +material: - constituents: - fraction: 1.0 - orientation: [1.0, 0.0, 0.0, 0.0] + O: [1.0, 0.0, 0.0, 0.0] phase: Aluminum homogenization: SX - constituents: - fraction: 1.0 - orientation: [0.7936696712125002, -0.28765777461664166, -0.3436487135089419, 0.4113964260949434] + O: [0.7936696712125002, -0.28765777461664166, -0.3436487135089419, 0.4113964260949434] phase: Aluminum homogenization: SX - constituents: - fraction: 1.0 - orientation: [0.3986143167493579, -0.7014883552495493, 0.2154871765709027, 0.5500781677772945] + O: [0.3986143167493579, -0.7014883552495493, 0.2154871765709027, 0.5500781677772945] phase: Aluminum homogenization: SX - constituents: - fraction: 0.5 - orientation: [0.28645844315788244, -0.022571491243423537, -0.467933059311115, -0.8357456192708106] + O: [0.28645844315788244, -0.022571491243423537, -0.467933059311115, -0.8357456192708106] phase: Aluminum - fraction: 0.5 - orientation: [0.3986143167493579, -0.7014883552495493, 0.2154871765709027, 0.5500781677772945] + O: [0.3986143167493579, -0.7014883552495493, 0.2154871765709027, 0.5500781677772945] phase: Steel homogenization: Taylor diff --git a/python/tests/test_ConfigMaterial.py b/python/tests/test_ConfigMaterial.py index 27889d564..4863a8ac4 100644 --- a/python/tests/test_ConfigMaterial.py +++ b/python/tests/test_ConfigMaterial.py @@ -35,29 +35,29 @@ class TestConfigMaterial: def test_invalid_orientation(self,reference_dir): material_config = ConfigMaterial.load(reference_dir/'material.yaml') - material_config['microstructure'][0]['constituents'][0]['orientation']=[0,0,0,0] + material_config['material'][0]['constituents'][0]['O']=[0,0,0,0] assert not material_config.is_valid def test_invalid_fraction(self,reference_dir): material_config = ConfigMaterial.load(reference_dir/'material.yaml') - material_config['microstructure'][0]['constituents'][0]['fraction']=.9 + material_config['material'][0]['constituents'][0]['fraction']=.9 assert not material_config.is_valid - @pytest.mark.parametrize('item',['homogenization','phase','microstructure']) + @pytest.mark.parametrize('item',['homogenization','phase','material']) def test_incomplete_missing(self,reference_dir,item): material_config = ConfigMaterial.load(reference_dir/'material.yaml') del material_config[item] assert not material_config.is_complete - @pytest.mark.parametrize('item',['orientation','phase']) + @pytest.mark.parametrize('item',['O','phase']) def test_incomplete_material_constituent(self,reference_dir,item): material_config = ConfigMaterial.load(reference_dir/'material.yaml') - del material_config['microstructure'][0]['constituents'][0][item] + del material_config['material'][0]['constituents'][0][item] assert not material_config.is_complete def test_incomplete_material_homogenization(self,reference_dir): material_config = ConfigMaterial.load(reference_dir/'material.yaml') - del material_config['microstructure'][0]['homogenization'] + del material_config['material'][0]['homogenization'] assert not material_config.is_complete def test_incomplete_phase_lattice(self,reference_dir): @@ -67,10 +67,10 @@ class TestConfigMaterial: def test_incomplete_wrong_phase(self,reference_dir): material_config = ConfigMaterial.load(reference_dir/'material.yaml') - new = material_config.microstructure_rename_phase({'Steel':'FeNbC'}) + new = material_config.material_rename_phase({'Steel':'FeNbC'}) assert not new.is_complete def test_incomplete_wrong_homogenization(self,reference_dir): material_config = ConfigMaterial.load(reference_dir/'material.yaml') - new = material_config.microstructure_rename_homogenization({'Taylor':'isostrain'}) + new = material_config.material_rename_homogenization({'Taylor':'isostrain'}) assert not new.is_complete From 3d49678e9360fec6d7c90beca24c747c6ad4b914 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 2 Oct 2020 17:51:33 +0200 Subject: [PATCH 09/39] new names part 2 --- python/damask/_configmaterial.py | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index 3eb7180e2..26006fef7 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -27,34 +27,34 @@ class ConfigMaterial(Config): def is_complete(self): """Check for completeness.""" ok = True - for top_level in ['homogenization','phase','microstructure']: + for top_level in ['homogenization','phase','material']: # ToDo: With python 3.8 as prerequisite we can shorten with := ok &= top_level in self if top_level not in self: print(f'{top_level} entry missing') if ok: - ok &= len(self['microstructure']) > 0 - if len(self['microstructure']) < 1: print('Incomplete microstructure definition') + ok &= len(self['material']) > 0 + if len(self['material']) < 1: print('Incomplete material definition') if ok: homogenization = set() phase = set() - for i,v in enumerate(self['microstructure']): + for i,v in enumerate(self['material']): if 'homogenization' in v: homogenization.add(v['homogenization']) else: - print(f'No homogenization specified in microstructure {i}') + print(f'No homogenization specified in material {i}') ok = False if 'constituents' in v: for ii,vv in enumerate(v['constituents']): - if 'orientation' not in vv: - print('No orientation specified in constituent {ii} of microstructure {i}') + if 'O' not in vv: + print('No orientation specified in constituent {ii} of material {i}') ok = False if 'phase' in vv: phase.add(vv['phase']) else: - print(f'No phase specified in constituent {ii} of microstructure {i}') + print(f'No phase specified in constituent {ii} of material {i}') ok = False for k,v in self['phase'].items(): @@ -92,42 +92,42 @@ class ConfigMaterial(Config): print(f"Invalid lattice: '{s}' in phase '{k}'") ok = False - if 'microstructure' in self: - for i,v in enumerate(self['microstructure']): + if 'material' in self: + for i,v in enumerate(self['material']): if 'constituents' in v: f = 0.0 for c in v['constituents']: f+= float(c['fraction']) - if 'orientation' in c: + if 'O' in c: try: - Rotation.from_quaternion(c['orientation']) + Rotation.from_quaternion(c['O']) except ValueError: - o = c['orientation'] - print(f"Invalid orientation: '{o}' in microstructure '{i}'") + o = c['O'] + print(f"Invalid orientation: '{o}' in material '{i}'") ok = False if not np.isclose(f,1.0): - print(f"Invalid total fraction '{f}' in microstructure '{i}'") + print(f"Invalid total fraction '{f}' in material '{i}'") ok = False return ok - def microstructure_rename_phase(self,mapping,ID=None,constituent=None): + def material_rename_phase(self,mapping,ID=None,constituent=None): """ - Change phase name in microstructure. + Change phase name in material. Parameters ---------- mapping: dictionary Mapping from old name to new name ID: list of ints, optional - Limit renaming to selected microstructure IDs. + Limit renaming to selected material IDs. constituent: list of ints, optional Limit renaming to selected constituents. """ dup = copy.deepcopy(self) - for i,m in enumerate(dup['microstructure']): + for i,m in enumerate(dup['material']): if ID and i not in ID: continue for c in m['constituents']: if constituent is not None and c not in constituent: continue @@ -138,9 +138,9 @@ class ConfigMaterial(Config): return dup - def microstructure_rename_homogenization(self,mapping,ID=None): + def material_rename_homogenization(self,mapping,ID=None): """ - Change homogenization name in microstructure. + Change homogenization name in material. Parameters ---------- @@ -151,7 +151,7 @@ class ConfigMaterial(Config): """ dup = copy.deepcopy(self) - for i,m in enumerate(dup['microstructure']): + for i,m in enumerate(dup['material']): if ID and i not in ID: continue try: m['homogenization'] = mapping[m['homogenization']] From 46973508a2c9763bcdef8c509da3abde1b5ae929 Mon Sep 17 00:00:00 2001 From: Sharan Roongta Date: Mon, 5 Oct 2020 18:53:05 +0200 Subject: [PATCH 10/39] allow multi line flow yaml --- src/YAML_parse.f90 | 125 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 113 insertions(+), 12 deletions(-) diff --git a/src/YAML_parse.f90 b/src/YAML_parse.f90 index cb5b726dc..2beab6fe8 100644 --- a/src/YAML_parse.f90 +++ b/src/YAML_parse.f90 @@ -222,11 +222,24 @@ logical function isKey(line) else isKey = IO_rmComment(line(len(IO_rmComment(line)):len(IO_rmComment(line)))) == ':' & .and. .not. isFlow(line) + isKey = isKey .and. index(IO_rmComment(line),':') == index(IO_rmComment(line),':',back =.true.) endif end function isKey +!-------------------------------------------------------------------------------------------------- +! @brief check whether a string is a list in flow style +!-------------------------------------------------------------------------------------------------- +logical function isFlowList(line) + + character(len=*), intent(in) :: line + + isFlowList = index(adjustl(line),'[') == 1 + +end function isFlowList + + !-------------------------------------------------------------------------------------------------- ! @brief skip empty lines ! @details update start position in the block by skipping empty lines if present. @@ -272,6 +285,57 @@ subroutine skip_file_header(blck,s_blck) end subroutine skip_file_header +!-------------------------------------------------------------------------------------------------- +!> @brief check if the flow line contains line break +!-------------------------------------------------------------------------------------------------- +logical function is_end(str,e_char) + + character(len=*), intent(in) :: str + character, intent(in) :: e_char !< end of list/dict ( '}' or ']') + integer :: N_sq, & !< number of open square brackets + N_cu, & !< number of open curly brackets + i + character(len=:), allocatable:: line + + is_end = .false. + N_sq = 0 + N_cu = 0 + if(e_char == ']') line = str(index(str(:),'[')+1:) + if(e_char == '}') line = str(index(str(:),'{')+1:) + + do i = 1, len_trim(line) + is_end = (N_sq==0 .and. N_cu==0 .and. scan(line(i:i),e_char) == 1) + N_sq = N_sq + merge(1,0,line(i:i) == '[') + N_cu = N_cu + merge(1,0,line(i:i) == '{') + N_sq = N_sq - merge(1,0,line(i:i) == ']') + N_cu = N_cu - merge(1,0,line(i:i) == '}') + enddo + + +end function is_end + +!-------------------------------------------------------------------------------------------------- +!> @brief return the flow YAML line without line break +!-------------------------------------------------------------------------------------------------- +subroutine line_break(blck,s_blck,e_char,flow_sgl) + + character(len=*), intent(in) :: blck !< YAML in mixed style + integer, intent(inout) :: s_blck + character, intent(in) :: e_char !< end of list/dict ( '}' or ']') + character(len=:), allocatable, intent(out) :: flow_sgl + logical :: line_end + + line_end =.false. + flow_sgl = '' + + do while(.not.line_end) + flow_sgl = flow_sgl//IO_rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))//' ' + line_end = is_end(flow_sgl,e_char) + s_blck = s_blck + index(blck(s_blck:),IO_EOL) + enddo + +end subroutine line_break + !-------------------------------------------------------------------------------------------------- ! @brief reads a line of YAML block which is already in flow style @@ -402,7 +466,7 @@ recursive subroutine lst(blck,flow,s_blck,s_flow,offset) integer, intent(inout) :: s_blck, & !< start position in blck s_flow, & !< start position in flow offset !< stores leading '- ' in nested lists - character(len=:), allocatable :: line + character(len=:), allocatable :: line,flow_sgl integer :: e_blck,indent indent = indentDepth(blck(s_blck:),offset) @@ -437,8 +501,12 @@ recursive subroutine lst(blck,flow,s_blck,s_flow,offset) s_blck = e_blck +2 offset = 0 elseif(isFlow(line)) then - call line_isFlow(flow,s_flow,line) - s_blck = e_blck +2 + if(isFlowList(line)) then + call line_break(blck,s_blck,']',flow_sgl) + else + call line_break(blck,s_blck,'}',flow_sgl) + endif + call line_isFlow(flow,s_flow,flow_sgl) offset = 0 endif else ! list item in the same line @@ -448,8 +516,13 @@ recursive subroutine lst(blck,flow,s_blck,s_flow,offset) s_blck = e_blck +2 offset = 0 elseif(isFlow(line)) then - call line_isFlow(flow,s_flow,line) - s_blck = e_blck +2 + s_blck = s_blck + index(blck(s_blck:),'-') + if(isFlowList(line)) then + call line_break(blck,s_blck,']',flow_sgl) + else + call line_break(blck,s_blck,'}',flow_sgl) + endif + call line_isFlow(flow,s_flow,flow_sgl) offset = 0 else ! non scalar list item offset = offset + indentDepth(blck(s_blck:))+1 ! offset in spaces to be ignored @@ -486,8 +559,8 @@ recursive subroutine dct(blck,flow,s_blck,s_flow,offset) s_flow, & !< start position in flow offset - character(len=:), allocatable :: line - integer :: e_blck,indent + character(len=:), allocatable :: line,flow_sgl + integer :: e_blck,indent,col_pos logical :: previous_isKey previous_isKey = .false. @@ -521,12 +594,22 @@ recursive subroutine dct(blck,flow,s_blck,s_flow,offset) endif if(isKeyValue(line)) then - call keyValue_toFlow(flow,s_flow,line) + col_pos = index(line,':') + if(isFlow(line(col_pos+1:))) then + if(isFlowList(line(col_pos+1:))) then + call line_break(blck,s_blck,']',flow_sgl) + else + call line_break(blck,s_blck,'}',flow_sgl) + endif + call keyValue_toFlow(flow,s_flow,flow_sgl) + else + call keyValue_toFlow(flow,s_flow,line) + s_blck = e_blck + 2 + endif else call line_toFlow(flow,s_flow,line) + s_blck = e_blck + 2 endif - - s_blck = e_blck +2 end if if(isScalar(line) .or. isKeyValue(line)) then @@ -559,7 +642,7 @@ recursive subroutine decide(blck,flow,s_blck,s_flow,offset) s_flow, & !< start position in flow offset integer :: e_blck - character(len=:), allocatable :: line + character(len=:), allocatable :: line,flow_sgl if(s_blck <= len(blck)) then call skip_empty_lines(blck,s_blck) @@ -583,8 +666,12 @@ recursive subroutine decide(blck,flow,s_blck,s_flow,offset) flow(s_flow:s_flow) = '}' s_flow = s_flow + 1 elseif(isFlow(line)) then + if(isFlowList(line)) then + call line_break(blck,s_blck,']',flow_sgl) + else + call line_break(blck,s_blck,'}',flow_sgl) + endif call line_isFlow(flow,s_flow,line) - s_blck = e_blck +2 else line = line(indentDepth(line)+1:) call line_toFlow(flow,s_flow,line) @@ -723,6 +810,20 @@ subroutine selfTest if (.not. to_flow(flow_mixed_braces) == flow) error stop 'to_flow' end block basic_flow + multi_line_flow: block + character(len=*), parameter :: flow_multi = & + "%YAML 1.1"//IO_EOL//& + "---"//IO_EOL//& + "a: [b,"//IO_EOL//& + "c: "//IO_EOL//& + "d, e]"//IO_EOL + character(len=*), parameter :: flow = & + "{a: [b, {c: d}, e]}" + + if( .not. to_flow(flow_multi) == flow) error stop 'to_flow' + end block multi_line_flow + + basic_mixed: block character(len=*), parameter :: block_flow = & "%YAML 1.1"//IO_EOL//& From 22143ea02418adb7f6a043b5ecd3b56ca04a41f1 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 5 Oct 2020 19:06:19 +0200 Subject: [PATCH 11/39] new tests --- .gitlab-ci.yml | 12 +++++++++++- PRIVATE | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4e83757e5..722811446 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -193,6 +193,8 @@ grid_mech_compile_Intel: - module load $IntelCompiler $MPICH_Intel $PETSc_MPICH_Intel - cp -r grid_mech_compile grid_mech_compile_Intel - grid_mech_compile_Intel/test.py + - cd pytest + - pytest -k 'compile and grid' except: - master - release @@ -203,6 +205,8 @@ Compile_FEM_Intel: - module load $IntelCompiler $MPICH_Intel $PETSc_MPICH_Intel - cp -r FEM_compile FEM_compile_Intel - FEM_compile_Intel/test.py + - cd pytest + - pytest -k 'compile and mesh' except: - master - release @@ -213,6 +217,8 @@ grid_mech_compile_GNU: - module load $GNUCompiler $MPICH_GNU $PETSc_MPICH_GNU - cp -r grid_mech_compile grid_mech_compile_GNU - grid_mech_compile_GNU/test.py + - cd pytest + - pytest -k 'compile and grid' except: - master - release @@ -223,6 +229,8 @@ Compile_FEM_GNU: - module load $GNUCompiler $MPICH_GNU $PETSc_MPICH_GNU - cp -r FEM_compile FEM_compile_GNU - FEM_compile_GNU/test.py + - cd pytest + - pytest -k 'compile and mesh' except: - master - release @@ -244,7 +252,7 @@ Pytest_grid: script: - module load $IntelCompiler $MPICH_Intel $PETSc_MPICH_Intel - cd pytest - - pytest + - pytest -m 'not compile' except: - master - release @@ -320,6 +328,8 @@ Marc_compileIfort: script: - module load $IntelMarc $HDF5Marc $MSC - Marc_compileIfort/test.py + - cd pytest + - pytest -k 'compile and Marc' except: - master - release diff --git a/PRIVATE b/PRIVATE index 64e62f805..fc9172ede 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 64e62f805b5ad784e3397ee5f735aaeb3cc134c2 +Subproject commit fc9172ede32ba5609d494a03c1d11bcd60d48cb8 From 6dff0396b6df5b8a376e6a0d11d29d05e2f258fb Mon Sep 17 00:00:00 2001 From: Sharan Roongta Date: Mon, 5 Oct 2020 19:13:40 +0200 Subject: [PATCH 12/39] [skip sc] more testing --- .../SpectralMethod/Polycrystal/material.yaml | 14 ++++++++++--- src/YAML_parse.f90 | 20 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/examples/SpectralMethod/Polycrystal/material.yaml b/examples/SpectralMethod/Polycrystal/material.yaml index 16c6042a6..9da5a1358 100644 --- a/examples/SpectralMethod/Polycrystal/material.yaml +++ b/examples/SpectralMethod/Polycrystal/material.yaml @@ -1,6 +1,8 @@ +--- homogenization: SX: - mech: {type: none} + mech: {type: +none} microstructure: - constituents: - fraction: 1.0 @@ -9,7 +11,8 @@ microstructure: homogenization: SX - constituents: - fraction: 1.0 - orientation: [0.7936696712125002, -0.28765777461664166, -0.3436487135089419, 0.4113964260949434] + orientation: [0.7936696712125002, -0.28765777461664166, + -0.3436487135089419, 0.4113964260949434] phase: Aluminum homogenization: SX - constituents: @@ -19,7 +22,12 @@ microstructure: homogenization: SX - constituents: - fraction: 1.0 - orientation: [0.28645844315788244, -0.022571491243423537, -0.467933059311115, -0.8357456192708106] + orientation: [0.28645844315788244, + + + +-0.022571491243423537, + -0.467933059311115, -0.8357456192708106] phase: Aluminum homogenization: SX - constituents: diff --git a/src/YAML_parse.f90 b/src/YAML_parse.f90 index 2beab6fe8..d8d320ad1 100644 --- a/src/YAML_parse.f90 +++ b/src/YAML_parse.f90 @@ -810,19 +810,35 @@ subroutine selfTest if (.not. to_flow(flow_mixed_braces) == flow) error stop 'to_flow' end block basic_flow - multi_line_flow: block + multi_line_flow1: block character(len=*), parameter :: flow_multi = & "%YAML 1.1"//IO_EOL//& "---"//IO_EOL//& "a: [b,"//IO_EOL//& "c: "//IO_EOL//& "d, e]"//IO_EOL + character(len=*), parameter :: flow = & "{a: [b, {c: d}, e]}" if( .not. to_flow(flow_multi) == flow) error stop 'to_flow' - end block multi_line_flow + end block multi_line_flow1 + multi_line_flow2: block + character(len=*), parameter :: flow_multi = & + "%YAML 1.1"//IO_EOL//& + "---"//IO_EOL//& + "-"//IO_EOL//& + " a: {b:"//IO_EOL//& + "[c,"//IO_EOL//& + "d"//IO_EOL//& + "e, f]}"//IO_EOL + + character(len=*), parameter :: flow = & + "[{a: {b: [c, d e, f]}}]" + + if( .not. to_flow(flow_multi) == flow) error stop 'to_flow' + end block multi_line_flow2 basic_mixed: block character(len=*), parameter :: block_flow = & From 09ddbedb2140340f7dd1e42d0dc3276a11633166 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 5 Oct 2020 21:52:38 +0200 Subject: [PATCH 13/39] updated documentation in test --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index fc9172ede..3f0dae61d 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit fc9172ede32ba5609d494a03c1d11bcd60d48cb8 +Subproject commit 3f0dae61db57d33612507e2813ad222cca5ac790 From 9e0222db7139170dc51d8a8856c64a7c00af62cd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 5 Oct 2020 22:41:12 +0200 Subject: [PATCH 14/39] just a wrapper to scipy, requires special layout --- processing/post/addGaussian.py | 76 ---------------------------------- 1 file changed, 76 deletions(-) delete mode 100755 processing/post/addGaussian.py diff --git a/processing/post/addGaussian.py b/processing/post/addGaussian.py deleted file mode 100755 index f00122c63..000000000 --- a/processing/post/addGaussian.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys -from io import StringIO -from optparse import OptionParser - -from scipy import ndimage - -import damask - - -scriptName = os.path.splitext(os.path.basename(__file__))[0] -scriptID = ' '.join([scriptName,damask.version]) - - -# -------------------------------------------------------------------- -# MAIN -# -------------------------------------------------------------------- - -parser = OptionParser(option_class=damask.extendableOption, usage='%prog option [ASCIItable(s)]', description = """ -Add column(s) containing Gaussian filtered values of requested column(s). -Operates on periodic and non-periodic ordered three-dimensional data sets. -For details see scipy.ndimage documentation. - -""", version = scriptID) - -parser.add_option('-p','--pos','--periodiccellcenter', - dest = 'pos', - type = 'string', metavar = 'string', - help = 'label of coordinates [%default]') -parser.add_option('-s','--scalar', - dest = 'labels', - action = 'extend', metavar = '', - help = 'label(s) of scalar field values') -parser.add_option('-o','--order', - dest = 'order', - type = int, - metavar = 'int', - help = 'order of the filter [%default]') -parser.add_option('--sigma', - dest = 'sigma', - type = float, - metavar = 'float', - help = 'standard deviation [%default]') -parser.add_option('--periodic', - dest = 'periodic', - action = 'store_true', - help = 'assume periodic grain structure') - - - -parser.set_defaults(pos = 'pos', - order = 0, - sigma = 1, - ) - -(options,filenames) = parser.parse_args() -if filenames == []: filenames = [None] - -if options.labels is None: parser.error('no data column specified.') - -for name in filenames: - damask.util.report(scriptName,name) - - table = damask.Table.load(StringIO(''.join(sys.stdin.read())) if name is None else name) - damask.grid_filters.coord0_check(table.get(options.pos)) - - for label in options.labels: - table = table.add('Gauss{}({})'.format(options.sigma,label), - ndimage.filters.gaussian_filter(table.get(label).reshape(-1), - options.sigma,options.order, - mode = 'wrap' if options.periodic else 'nearest'), - scriptID+' '+' '.join(sys.argv[1:])) - - table.save((sys.stdout if name is None else name), legacy=True) From 8f7ec3f2833d759155f4896b991627fdbef3cb41 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 6 Oct 2020 06:39:03 +0200 Subject: [PATCH 15/39] fix for MSC.Marc compilation test --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index 3f0dae61d..226ea5596 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 3f0dae61db57d33612507e2813ad222cca5ac790 +Subproject commit 226ea55968c756ae1abbdf51230756bb80696cb0 From 08ab4a0b888abdab71f79adfd442ea6d9f75af16 Mon Sep 17 00:00:00 2001 From: Sharan Roongta Date: Tue, 6 Oct 2020 18:09:53 +0200 Subject: [PATCH 16/39] better names --- src/YAML_parse.f90 | 54 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/YAML_parse.f90 b/src/YAML_parse.f90 index d8d320ad1..8197782b2 100644 --- a/src/YAML_parse.f90 +++ b/src/YAML_parse.f90 @@ -257,7 +257,6 @@ subroutine skip_empty_lines(blck,s_blck) if(empty) s_blck = s_blck + index(blck(s_blck:),IO_EOL) enddo - end subroutine skip_empty_lines @@ -285,10 +284,11 @@ subroutine skip_file_header(blck,s_blck) end subroutine skip_file_header + !-------------------------------------------------------------------------------------------------- -!> @brief check if the flow line contains line break +!> @brief check if a line in flow YAML starts and ends in the same line !-------------------------------------------------------------------------------------------------- -logical function is_end(str,e_char) +logical function flow_is_closed(str,e_char) character(len=*), intent(in) :: str character, intent(in) :: e_char !< end of list/dict ( '}' or ']') @@ -297,44 +297,44 @@ logical function is_end(str,e_char) i character(len=:), allocatable:: line - is_end = .false. + flow_is_closed = .false. N_sq = 0 N_cu = 0 if(e_char == ']') line = str(index(str(:),'[')+1:) if(e_char == '}') line = str(index(str(:),'{')+1:) do i = 1, len_trim(line) - is_end = (N_sq==0 .and. N_cu==0 .and. scan(line(i:i),e_char) == 1) + flow_is_closed = (N_sq==0 .and. N_cu==0 .and. scan(line(i:i),e_char) == 1) N_sq = N_sq + merge(1,0,line(i:i) == '[') N_cu = N_cu + merge(1,0,line(i:i) == '{') N_sq = N_sq - merge(1,0,line(i:i) == ']') N_cu = N_cu - merge(1,0,line(i:i) == '}') enddo +end function flow_is_closed -end function is_end !-------------------------------------------------------------------------------------------------- !> @brief return the flow YAML line without line break !-------------------------------------------------------------------------------------------------- -subroutine line_break(blck,s_blck,e_char,flow_sgl) +subroutine remove_line_break(blck,s_blck,e_char,flow_line) character(len=*), intent(in) :: blck !< YAML in mixed style integer, intent(inout) :: s_blck character, intent(in) :: e_char !< end of list/dict ( '}' or ']') - character(len=:), allocatable, intent(out) :: flow_sgl + character(len=:), allocatable, intent(out) :: flow_line logical :: line_end line_end =.false. - flow_sgl = '' + flow_line = '' do while(.not.line_end) - flow_sgl = flow_sgl//IO_rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))//' ' - line_end = is_end(flow_sgl,e_char) - s_blck = s_blck + index(blck(s_blck:),IO_EOL) + flow_line = flow_line//IO_rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))//' ' + line_end = flow_is_closed(flow_line,e_char) + s_blck = s_blck + index(blck(s_blck:),IO_EOL) enddo -end subroutine line_break +end subroutine remove_line_break !-------------------------------------------------------------------------------------------------- @@ -466,7 +466,7 @@ recursive subroutine lst(blck,flow,s_blck,s_flow,offset) integer, intent(inout) :: s_blck, & !< start position in blck s_flow, & !< start position in flow offset !< stores leading '- ' in nested lists - character(len=:), allocatable :: line,flow_sgl + character(len=:), allocatable :: line,flow_line integer :: e_blck,indent indent = indentDepth(blck(s_blck:),offset) @@ -502,11 +502,11 @@ recursive subroutine lst(blck,flow,s_blck,s_flow,offset) offset = 0 elseif(isFlow(line)) then if(isFlowList(line)) then - call line_break(blck,s_blck,']',flow_sgl) + call remove_line_break(blck,s_blck,']',flow_line) else - call line_break(blck,s_blck,'}',flow_sgl) + call remove_line_break(blck,s_blck,'}',flow_line) endif - call line_isFlow(flow,s_flow,flow_sgl) + call line_isFlow(flow,s_flow,flow_line) offset = 0 endif else ! list item in the same line @@ -518,11 +518,11 @@ recursive subroutine lst(blck,flow,s_blck,s_flow,offset) elseif(isFlow(line)) then s_blck = s_blck + index(blck(s_blck:),'-') if(isFlowList(line)) then - call line_break(blck,s_blck,']',flow_sgl) + call remove_line_break(blck,s_blck,']',flow_line) else - call line_break(blck,s_blck,'}',flow_sgl) + call remove_line_break(blck,s_blck,'}',flow_line) endif - call line_isFlow(flow,s_flow,flow_sgl) + call line_isFlow(flow,s_flow,flow_line) offset = 0 else ! non scalar list item offset = offset + indentDepth(blck(s_blck:))+1 ! offset in spaces to be ignored @@ -559,7 +559,7 @@ recursive subroutine dct(blck,flow,s_blck,s_flow,offset) s_flow, & !< start position in flow offset - character(len=:), allocatable :: line,flow_sgl + character(len=:), allocatable :: line,flow_line integer :: e_blck,indent,col_pos logical :: previous_isKey @@ -597,11 +597,11 @@ recursive subroutine dct(blck,flow,s_blck,s_flow,offset) col_pos = index(line,':') if(isFlow(line(col_pos+1:))) then if(isFlowList(line(col_pos+1:))) then - call line_break(blck,s_blck,']',flow_sgl) + call remove_line_break(blck,s_blck,']',flow_line) else - call line_break(blck,s_blck,'}',flow_sgl) + call remove_line_break(blck,s_blck,'}',flow_line) endif - call keyValue_toFlow(flow,s_flow,flow_sgl) + call keyValue_toFlow(flow,s_flow,flow_line) else call keyValue_toFlow(flow,s_flow,line) s_blck = e_blck + 2 @@ -642,7 +642,7 @@ recursive subroutine decide(blck,flow,s_blck,s_flow,offset) s_flow, & !< start position in flow offset integer :: e_blck - character(len=:), allocatable :: line,flow_sgl + character(len=:), allocatable :: line,flow_line if(s_blck <= len(blck)) then call skip_empty_lines(blck,s_blck) @@ -667,9 +667,9 @@ recursive subroutine decide(blck,flow,s_blck,s_flow,offset) s_flow = s_flow + 1 elseif(isFlow(line)) then if(isFlowList(line)) then - call line_break(blck,s_blck,']',flow_sgl) + call remove_line_break(blck,s_blck,']',flow_line) else - call line_break(blck,s_blck,'}',flow_sgl) + call remove_line_break(blck,s_blck,'}',flow_line) endif call line_isFlow(flow,s_flow,line) else From 84ab21e82e083e987fa1c99bfbc2a8736516f77c Mon Sep 17 00:00:00 2001 From: Test User Date: Tue, 6 Oct 2020 20:35:44 +0200 Subject: [PATCH 17/39] [skip ci] updated version information after successful test of v3.0.0-alpha-454-g8d4adebea --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 260159fc8..a386c6e63 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-452-gd3f068cd7 +v3.0.0-alpha-454-g8d4adebea From 5c3426075515346813fb27038fb94b0d1714bf5b Mon Sep 17 00:00:00 2001 From: Test User Date: Tue, 6 Oct 2020 23:42:41 +0200 Subject: [PATCH 18/39] [skip ci] updated version information after successful test of v3.0.0-alpha-459-gf221d6e43 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 260159fc8..6f080d4e4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-452-gd3f068cd7 +v3.0.0-alpha-459-gf221d6e43 From d474e3402b71553b3e1fe0ffd426f6f70fa2607d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 7 Oct 2020 09:11:45 +0200 Subject: [PATCH 19/39] not needed for explicit calculation of nonlocal density flow --- src/crystallite.f90 | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/crystallite.f90 b/src/crystallite.f90 index 0b19afac1..54ea8ca16 100644 --- a/src/crystallite.f90 +++ b/src/crystallite.f90 @@ -441,8 +441,6 @@ function crystallite_stress() enddo elementLooping3 !$OMP END PARALLEL DO - call nonlocalConvergenceCheck - !-------------------------------------------------------------------------------------------------- ! integrate --- requires fully defined state array (basic + dependent state) where(.not. crystallite_converged .and. crystallite_subStep > num%subStepMinCryst) & ! do not try non-converged but fully cutbacked any further @@ -1526,38 +1524,6 @@ subroutine integrateStateRK(g,i,e,A,B,CC,DB) end subroutine integrateStateRK -!-------------------------------------------------------------------------------------------------- -!> @brief sets convergence flag for nonlocal calculations -!> @details one non-converged nonlocal sets all other nonlocals to non-converged to trigger cut back -!-------------------------------------------------------------------------------------------------- -subroutine nonlocalConvergenceCheck - - integer :: e,i,p - logical :: nonlocal_broken - - nonlocal_broken = .false. - !$OMP PARALLEL DO PRIVATE(p) - do e = FEsolving_execElem(1),FEsolving_execElem(2) - p = material_phaseAt(1,e) - do i = FEsolving_execIP(1),FEsolving_execIP(2) - if(plasticState(p)%nonlocal .and. .not. crystallite_converged(1,i,e)) nonlocal_broken = .true. - enddo - enddo - !$OMP END PARALLEL DO - - if(.not. nonlocal_broken) return - !$OMP PARALLEL DO PRIVATE(p) - do e = FEsolving_execElem(1),FEsolving_execElem(2) - p = material_phaseAt(1,e) - do i = FEsolving_execIP(1),FEsolving_execIP(2) - if(plasticState(p)%nonlocal) crystallite_converged(1,i,e) = .false. - enddo - enddo - !$OMP END PARALLEL DO - -end subroutine nonlocalConvergenceCheck - - !-------------------------------------------------------------------------------------------------- !> @brief determines whether a point is converged !-------------------------------------------------------------------------------------------------- From 2a23b5eaa9cc070497086e4a94e77b97477f204a Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 7 Oct 2020 09:37:48 +0200 Subject: [PATCH 20/39] simplified --- src/YAML_parse.f90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/YAML_parse.f90 b/src/YAML_parse.f90 index 8197782b2..8e20e0c29 100644 --- a/src/YAML_parse.f90 +++ b/src/YAML_parse.f90 @@ -220,9 +220,9 @@ logical function isKey(line) if(len(IO_rmComment(line)) == 0) then isKey = .false. else - isKey = IO_rmComment(line(len(IO_rmComment(line)):len(IO_rmComment(line)))) == ':' & - .and. .not. isFlow(line) - isKey = isKey .and. index(IO_rmComment(line),':') == index(IO_rmComment(line),':',back =.true.) + isKey = index(IO_rmComment(line),':',back=.false.) == len(IO_rmComment(line)) .and. & + index(IO_rmComment(line),':',back=.true.) == len(IO_rmComment(line)) .and. & + .not. isFlow(line) endif end function isKey From 7ffa77b8edeca6f1d37a5439c80e3237491659c3 Mon Sep 17 00:00:00 2001 From: Test User Date: Wed, 7 Oct 2020 22:06:47 +0200 Subject: [PATCH 21/39] [skip ci] updated version information after successful test of v3.0.0-alpha-472-g16e47956a --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index a386c6e63..e7674c155 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-454-g8d4adebea +v3.0.0-alpha-472-g16e47956a From 3e4330d10abef1f41198b536ff5dada1775cf0ae Mon Sep 17 00:00:00 2001 From: Sharan Roongta Date: Wed, 7 Oct 2020 22:15:13 +0200 Subject: [PATCH 22/39] partition, not partion --- src/constitutive.f90 | 10 +-- src/crystallite.f90 | 136 ++++++++++++++++---------------- src/homogenization.f90 | 10 +-- src/homogenization_mech_RGC.f90 | 4 +- src/prec.f90 | 2 +- 5 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/constitutive.f90 b/src/constitutive.f90 index 62846359d..64d3f2d31 100644 --- a/src/constitutive.f90 +++ b/src/constitutive.f90 @@ -452,11 +452,11 @@ subroutine constitutive_init PhaseLoop2:do p = 1,phases%length !-------------------------------------------------------------------------------------------------- ! partition and initialize state - plasticState(p)%partionedState0 = plasticState(p)%state0 - plasticState(p)%state = plasticState(p)%partionedState0 + plasticState(p)%partitionedState0 = plasticState(p)%state0 + plasticState(p)%state = plasticState(p)%partitionedState0 forall(s = 1:phase_Nsources(p)) - sourceState(p)%p(s)%partionedState0 = sourceState(p)%p(s)%state0 - sourceState(p)%p(s)%state = sourceState(p)%p(s)%partionedState0 + sourceState(p)%p(s)%partitionedState0 = sourceState(p)%p(s)%state0 + sourceState(p)%p(s)%state = sourceState(p)%p(s)%partitionedState0 end forall constitutive_source_maxSizeDotState = max(constitutive_source_maxSizeDotState, & @@ -922,7 +922,7 @@ subroutine constitutive_allocateState(state, & allocate(state%atol (sizeState), source=0.0_pReal) allocate(state%state0 (sizeState,NipcMyPhase), source=0.0_pReal) - allocate(state%partionedState0(sizeState,NipcMyPhase), source=0.0_pReal) + allocate(state%partitionedState0(sizeState,NipcMyPhase), source=0.0_pReal) allocate(state%subState0 (sizeState,NipcMyPhase), source=0.0_pReal) allocate(state%state (sizeState,NipcMyPhase), source=0.0_pReal) diff --git a/src/crystallite.f90 b/src/crystallite.f90 index 0b19afac1..667398390 100644 --- a/src/crystallite.f90 +++ b/src/crystallite.f90 @@ -44,30 +44,30 @@ module crystallite ! crystallite_Fp, & !< current plastic def grad (end of converged time step) crystallite_Fp0, & !< plastic def grad at start of FE inc - crystallite_partionedFp0,& !< plastic def grad at start of homog inc + crystallite_partitionedFp0,& !< plastic def grad at start of homog inc crystallite_subFp0,& !< plastic def grad at start of crystallite inc ! crystallite_Fi, & !< current intermediate def grad (end of converged time step) crystallite_Fi0, & !< intermediate def grad at start of FE inc - crystallite_partionedFi0,& !< intermediate def grad at start of homog inc + crystallite_partitionedFi0,& !< intermediate def grad at start of homog inc crystallite_subFi0,& !< intermediate def grad at start of crystallite inc ! crystallite_Lp0, & !< plastic velocitiy grad at start of FE inc - crystallite_partionedLp0, & !< plastic velocity grad at start of homog inc + crystallite_partitionedLp0, & !< plastic velocity grad at start of homog inc ! crystallite_Li, & !< current intermediate velocitiy grad (end of converged time step) crystallite_Li0, & !< intermediate velocitiy grad at start of FE inc - crystallite_partionedLi0, & !< intermediate velocity grad at start of homog inc + crystallite_partitionedLi0, & !< intermediate velocity grad at start of homog inc ! crystallite_S0, & !< 2nd Piola-Kirchhoff stress vector at start of FE inc - crystallite_partionedS0 !< 2nd Piola-Kirchhoff stress vector at start of homog inc + crystallite_partitionedS0 !< 2nd Piola-Kirchhoff stress vector at start of homog inc real(pReal), dimension(:,:,:,:,:), allocatable, public, protected :: & crystallite_P, & !< 1st Piola-Kirchhoff stress per grain crystallite_Lp, & !< current plastic velocitiy grad (end of converged time step) crystallite_S, & !< current 2nd Piola-Kirchhoff stress vector (end of converged time step) - crystallite_partionedF0 !< def grad at start of homog inc + crystallite_partitionedF0 !< def grad at start of homog inc real(pReal), dimension(:,:,:,:,:), allocatable, public :: & - crystallite_partionedF !< def grad to be reached at end of homog inc + crystallite_partitionedF !< def grad to be reached at end of homog inc logical, dimension(:,:,:), allocatable, public :: & crystallite_requested !< used by upper level (homogenization) to request crystallite calculation @@ -166,20 +166,20 @@ subroutine crystallite_init iMax = discretization_nIP eMax = discretization_nElem - allocate(crystallite_partionedF(3,3,cMax,iMax,eMax),source=0.0_pReal) + allocate(crystallite_partitionedF(3,3,cMax,iMax,eMax),source=0.0_pReal) allocate(crystallite_S0, & crystallite_F0, crystallite_Fi0,crystallite_Fp0, & crystallite_Li0,crystallite_Lp0, & - crystallite_partionedS0, & - crystallite_partionedF0,crystallite_partionedFp0,crystallite_partionedFi0, & - crystallite_partionedLp0,crystallite_partionedLi0, & + crystallite_partitionedS0, & + crystallite_partitionedF0,crystallite_partitionedFp0,crystallite_partitionedFi0, & + crystallite_partitionedLp0,crystallite_partitionedLi0, & crystallite_S,crystallite_P, & crystallite_Fe,crystallite_Fi,crystallite_Fp, & crystallite_Li,crystallite_Lp, & crystallite_subF,crystallite_subF0, & crystallite_subFp0,crystallite_subFi0, & - source = crystallite_partionedF) + source = crystallite_partitionedF) allocate(crystallite_dt(cMax,iMax,eMax),source=0.0_pReal) allocate(crystallite_subdt,crystallite_subFrac,crystallite_subStep, & @@ -269,10 +269,10 @@ subroutine crystallite_init !$OMP END PARALLEL DO - crystallite_partionedFp0 = crystallite_Fp0 - crystallite_partionedFi0 = crystallite_Fi0 - crystallite_partionedF0 = crystallite_F0 - crystallite_partionedF = crystallite_F0 + crystallite_partitionedFp0 = crystallite_Fp0 + crystallite_partitionedFi0 = crystallite_Fi0 + crystallite_partitionedF0 = crystallite_F0 + crystallite_partitionedF = crystallite_F0 call crystallite_orientations() @@ -280,8 +280,8 @@ subroutine crystallite_init do e = FEsolving_execElem(1),FEsolving_execElem(2) do i = FEsolving_execIP(1),FEsolving_execIP(2) do c = 1,homogenization_Ngrains(material_homogenizationAt(e)) - call constitutive_dependentState(crystallite_partionedF0(1:3,1:3,c,i,e), & - crystallite_partionedFp0(1:3,1:3,c,i,e), & + call constitutive_dependentState(crystallite_partitionedF0(1:3,1:3,c,i,e), & + crystallite_partitionedFp0(1:3,1:3,c,i,e), & c,i,e) ! update dependent state variables to be consistent with basic states enddo enddo @@ -325,8 +325,8 @@ function crystallite_stress() todo = .false. - subLp0 = crystallite_partionedLp0 - subLi0 = crystallite_partionedLi0 + subLp0 = crystallite_partitionedLp0 + subLi0 = crystallite_partitionedLi0 @@ -338,15 +338,15 @@ function crystallite_stress() do i = FEsolving_execIP(1),FEsolving_execIP(2); do c = 1,homogenization_Ngrains(material_homogenizationAt(e)) homogenizationRequestsCalculation: if (crystallite_requested(c,i,e)) then plasticState (material_phaseAt(c,e))%subState0( :,material_phaseMemberAt(c,i,e)) = & - plasticState (material_phaseAt(c,e))%partionedState0(:,material_phaseMemberAt(c,i,e)) + plasticState (material_phaseAt(c,e))%partitionedState0(:,material_phaseMemberAt(c,i,e)) do s = 1, phase_Nsources(material_phaseAt(c,e)) sourceState(material_phaseAt(c,e))%p(s)%subState0( :,material_phaseMemberAt(c,i,e)) = & - sourceState(material_phaseAt(c,e))%p(s)%partionedState0(:,material_phaseMemberAt(c,i,e)) + sourceState(material_phaseAt(c,e))%p(s)%partitionedState0(:,material_phaseMemberAt(c,i,e)) enddo - crystallite_subFp0(1:3,1:3,c,i,e) = crystallite_partionedFp0(1:3,1:3,c,i,e) - crystallite_subFi0(1:3,1:3,c,i,e) = crystallite_partionedFi0(1:3,1:3,c,i,e) - crystallite_subF0(1:3,1:3,c,i,e) = crystallite_partionedF0(1:3,1:3,c,i,e) + crystallite_subFp0(1:3,1:3,c,i,e) = crystallite_partitionedFp0(1:3,1:3,c,i,e) + crystallite_subFi0(1:3,1:3,c,i,e) = crystallite_partitionedFi0(1:3,1:3,c,i,e) + crystallite_subF0(1:3,1:3,c,i,e) = crystallite_partitionedF0(1:3,1:3,c,i,e) crystallite_subFrac(c,i,e) = 0.0_pReal crystallite_subStep(c,i,e) = 1.0_pReal/num%subStepSizeCryst todo(c,i,e) = .true. @@ -426,8 +426,8 @@ function crystallite_stress() ! prepare for integration if (todo(c,i,e)) then crystallite_subF(1:3,1:3,c,i,e) = crystallite_subF0(1:3,1:3,c,i,e) & - + crystallite_subStep(c,i,e) *( crystallite_partionedF (1:3,1:3,c,i,e) & - -crystallite_partionedF0(1:3,1:3,c,i,e)) + + crystallite_subStep(c,i,e) *( crystallite_partitionedF (1:3,1:3,c,i,e) & + -crystallite_partitionedF0(1:3,1:3,c,i,e)) crystallite_Fe(1:3,1:3,c,i,e) = matmul(matmul(crystallite_subF(1:3,1:3,c,i,e), & math_inv33(crystallite_Fp(1:3,1:3,c,i,e))), & math_inv33(crystallite_Fi(1:3,1:3,c,i,e))) @@ -475,17 +475,17 @@ subroutine crystallite_initializeRestorationPoints(i,e) s do c = 1,homogenization_Ngrains(material_homogenizationAt(e)) - crystallite_partionedFp0(1:3,1:3,c,i,e) = crystallite_Fp0(1:3,1:3,c,i,e) - crystallite_partionedLp0(1:3,1:3,c,i,e) = crystallite_Lp0(1:3,1:3,c,i,e) - crystallite_partionedFi0(1:3,1:3,c,i,e) = crystallite_Fi0(1:3,1:3,c,i,e) - crystallite_partionedLi0(1:3,1:3,c,i,e) = crystallite_Li0(1:3,1:3,c,i,e) - crystallite_partionedF0(1:3,1:3,c,i,e) = crystallite_F0(1:3,1:3,c,i,e) - crystallite_partionedS0(1:3,1:3,c,i,e) = crystallite_S0(1:3,1:3,c,i,e) + crystallite_partitionedFp0(1:3,1:3,c,i,e) = crystallite_Fp0(1:3,1:3,c,i,e) + crystallite_partitionedLp0(1:3,1:3,c,i,e) = crystallite_Lp0(1:3,1:3,c,i,e) + crystallite_partitionedFi0(1:3,1:3,c,i,e) = crystallite_Fi0(1:3,1:3,c,i,e) + crystallite_partitionedLi0(1:3,1:3,c,i,e) = crystallite_Li0(1:3,1:3,c,i,e) + crystallite_partitionedF0(1:3,1:3,c,i,e) = crystallite_F0(1:3,1:3,c,i,e) + crystallite_partitionedS0(1:3,1:3,c,i,e) = crystallite_S0(1:3,1:3,c,i,e) - plasticState(material_phaseAt(c,e))%partionedState0(:,material_phasememberAt(c,i,e)) = & + plasticState(material_phaseAt(c,e))%partitionedState0(:,material_phasememberAt(c,i,e)) = & plasticState(material_phaseAt(c,e))%state0( :,material_phasememberAt(c,i,e)) do s = 1, phase_Nsources(material_phaseAt(c,e)) - sourceState(material_phaseAt(c,e))%p(s)%partionedState0(:,material_phasememberAt(c,i,e)) = & + sourceState(material_phaseAt(c,e))%p(s)%partitionedState0(:,material_phasememberAt(c,i,e)) = & sourceState(material_phaseAt(c,e))%p(s)%state0( :,material_phasememberAt(c,i,e)) enddo enddo @@ -506,17 +506,17 @@ subroutine crystallite_windForward(i,e) s do c = 1,homogenization_Ngrains(material_homogenizationAt(e)) - crystallite_partionedF0 (1:3,1:3,c,i,e) = crystallite_partionedF(1:3,1:3,c,i,e) - crystallite_partionedFp0(1:3,1:3,c,i,e) = crystallite_Fp (1:3,1:3,c,i,e) - crystallite_partionedLp0(1:3,1:3,c,i,e) = crystallite_Lp (1:3,1:3,c,i,e) - crystallite_partionedFi0(1:3,1:3,c,i,e) = crystallite_Fi (1:3,1:3,c,i,e) - crystallite_partionedLi0(1:3,1:3,c,i,e) = crystallite_Li (1:3,1:3,c,i,e) - crystallite_partionedS0 (1:3,1:3,c,i,e) = crystallite_S (1:3,1:3,c,i,e) + crystallite_partitionedF0 (1:3,1:3,c,i,e) = crystallite_partitionedF(1:3,1:3,c,i,e) + crystallite_partitionedFp0(1:3,1:3,c,i,e) = crystallite_Fp (1:3,1:3,c,i,e) + crystallite_partitionedLp0(1:3,1:3,c,i,e) = crystallite_Lp (1:3,1:3,c,i,e) + crystallite_partitionedFi0(1:3,1:3,c,i,e) = crystallite_Fi (1:3,1:3,c,i,e) + crystallite_partitionedLi0(1:3,1:3,c,i,e) = crystallite_Li (1:3,1:3,c,i,e) + crystallite_partitionedS0 (1:3,1:3,c,i,e) = crystallite_S (1:3,1:3,c,i,e) - plasticState (material_phaseAt(c,e))%partionedState0(:,material_phasememberAt(c,i,e)) = & + plasticState (material_phaseAt(c,e))%partitionedState0(:,material_phasememberAt(c,i,e)) = & plasticState (material_phaseAt(c,e))%state (:,material_phasememberAt(c,i,e)) do s = 1, phase_Nsources(material_phaseAt(c,e)) - sourceState(material_phaseAt(c,e))%p(s)%partionedState0(:,material_phasememberAt(c,i,e)) = & + sourceState(material_phaseAt(c,e))%p(s)%partitionedState0(:,material_phasememberAt(c,i,e)) = & sourceState(material_phaseAt(c,e))%p(s)%state (:,material_phasememberAt(c,i,e)) enddo enddo @@ -540,18 +540,18 @@ subroutine crystallite_restore(i,e,includeL) do c = 1,homogenization_Ngrains(material_homogenizationAt(e)) if (includeL) then - crystallite_Lp(1:3,1:3,c,i,e) = crystallite_partionedLp0(1:3,1:3,c,i,e) - crystallite_Li(1:3,1:3,c,i,e) = crystallite_partionedLi0(1:3,1:3,c,i,e) + crystallite_Lp(1:3,1:3,c,i,e) = crystallite_partitionedLp0(1:3,1:3,c,i,e) + crystallite_Li(1:3,1:3,c,i,e) = crystallite_partitionedLi0(1:3,1:3,c,i,e) endif ! maybe protecting everything from overwriting makes more sense - crystallite_Fp(1:3,1:3,c,i,e) = crystallite_partionedFp0(1:3,1:3,c,i,e) - crystallite_Fi(1:3,1:3,c,i,e) = crystallite_partionedFi0(1:3,1:3,c,i,e) - crystallite_S (1:3,1:3,c,i,e) = crystallite_partionedS0 (1:3,1:3,c,i,e) + crystallite_Fp(1:3,1:3,c,i,e) = crystallite_partitionedFp0(1:3,1:3,c,i,e) + crystallite_Fi(1:3,1:3,c,i,e) = crystallite_partitionedFi0(1:3,1:3,c,i,e) + crystallite_S (1:3,1:3,c,i,e) = crystallite_partitionedS0 (1:3,1:3,c,i,e) plasticState (material_phaseAt(c,e))%state( :,material_phasememberAt(c,i,e)) = & - plasticState (material_phaseAt(c,e))%partionedState0(:,material_phasememberAt(c,i,e)) + plasticState (material_phaseAt(c,e))%partitionedState0(:,material_phasememberAt(c,i,e)) do s = 1, phase_Nsources(material_phaseAt(c,e)) sourceState(material_phaseAt(c,e))%p(s)%state( :,material_phasememberAt(c,i,e)) = & - sourceState(material_phaseAt(c,e))%p(s)%partionedState0(:,material_phasememberAt(c,i,e)) + sourceState(material_phaseAt(c,e))%p(s)%partitionedState0(:,material_phasememberAt(c,i,e)) enddo enddo @@ -758,7 +758,7 @@ subroutine crystallite_results do o = 1, size(output_constituent(p)%label) select case (output_constituent(p)%label(o)) case('F') - selected_tensors = select_tensors(crystallite_partionedF,p) + selected_tensors = select_tensors(crystallite_partitionedF,p) call results_writeDataset(group,selected_tensors,output_constituent(p)%label(o),& 'deformation gradient','1') case('Fe') @@ -943,7 +943,7 @@ function integrateStress(ipc,ip,el,timeFraction) result(broken) F = crystallite_subF(1:3,1:3,ipc,ip,el) endif - call constitutive_dependentState(crystallite_partionedF(1:3,1:3,ipc,ip,el), & + call constitutive_dependentState(crystallite_partitionedF(1:3,1:3,ipc,ip,el), & crystallite_Fp(1:3,1:3,ipc,ip,el),ipc,ip,el) Lpguess = crystallite_Lp(1:3,1:3,ipc,ip,el) ! take as first guess @@ -1120,9 +1120,9 @@ subroutine integrateStateFPI(g,i,e) c = material_phaseMemberAt(g,i,e) broken = constitutive_collectDotState(crystallite_S(1:3,1:3,g,i,e), & - crystallite_partionedF0, & + crystallite_partitionedF0, & crystallite_Fi(1:3,1:3,g,i,e), & - crystallite_partionedFp0, & + crystallite_partitionedFp0, & crystallite_subdt(g,i,e), g,i,e,p,c) if(broken) return @@ -1152,9 +1152,9 @@ subroutine integrateStateFPI(g,i,e) if(broken) exit iteration broken = constitutive_collectDotState(crystallite_S(1:3,1:3,g,i,e), & - crystallite_partionedF0, & + crystallite_partitionedF0, & crystallite_Fi(1:3,1:3,g,i,e), & - crystallite_partionedFp0, & + crystallite_partitionedFp0, & crystallite_subdt(g,i,e), g,i,e,p,c) if(broken) exit iteration @@ -1243,9 +1243,9 @@ subroutine integrateStateEuler(g,i,e) c = material_phaseMemberAt(g,i,e) broken = constitutive_collectDotState(crystallite_S(1:3,1:3,g,i,e), & - crystallite_partionedF0, & + crystallite_partitionedF0, & crystallite_Fi(1:3,1:3,g,i,e), & - crystallite_partionedFp0, & + crystallite_partitionedFp0, & crystallite_subdt(g,i,e), g,i,e,p,c) if(broken) return @@ -1296,9 +1296,9 @@ subroutine integrateStateAdaptiveEuler(g,i,e) c = material_phaseMemberAt(g,i,e) broken = constitutive_collectDotState(crystallite_S(1:3,1:3,g,i,e), & - crystallite_partionedF0, & + crystallite_partitionedF0, & crystallite_Fi(1:3,1:3,g,i,e), & - crystallite_partionedFp0, & + crystallite_partitionedFp0, & crystallite_subdt(g,i,e), g,i,e,p,c) if(broken) return @@ -1325,9 +1325,9 @@ subroutine integrateStateAdaptiveEuler(g,i,e) if(broken) return broken = constitutive_collectDotState(crystallite_S(1:3,1:3,g,i,e), & - crystallite_partionedF0, & + crystallite_partitionedF0, & crystallite_Fi(1:3,1:3,g,i,e), & - crystallite_partionedFp0, & + crystallite_partitionedFp0, & crystallite_subdt(g,i,e), g,i,e,p,c) if(broken) return @@ -1434,9 +1434,9 @@ subroutine integrateStateRK(g,i,e,A,B,CC,DB) c = material_phaseMemberAt(g,i,e) broken = constitutive_collectDotState(crystallite_S(1:3,1:3,g,i,e), & - crystallite_partionedF0, & + crystallite_partitionedF0, & crystallite_Fi(1:3,1:3,g,i,e), & - crystallite_partionedFp0, & + crystallite_partitionedFp0, & crystallite_subdt(g,i,e), g,i,e,p,c) if(broken) return @@ -1476,9 +1476,9 @@ subroutine integrateStateRK(g,i,e,A,B,CC,DB) if(broken) exit broken = constitutive_collectDotState(crystallite_S(1:3,1:3,g,i,e), & - crystallite_partionedF0, & + crystallite_partitionedF0, & crystallite_Fi(1:3,1:3,g,i,e), & - crystallite_partionedFp0, & + crystallite_partitionedFp0, & crystallite_subdt(g,i,e)*CC(stage), g,i,e,p,c) if(broken) exit @@ -1590,7 +1590,7 @@ subroutine crystallite_restartWrite write(fileName,'(a,i0,a)') trim(getSolverJobName())//'_',worldrank,'.hdf5' fileHandle = HDF5_openFile(fileName,'a') - call HDF5_write(fileHandle,crystallite_partionedF,'F') + call HDF5_write(fileHandle,crystallite_partitionedF,'F') call HDF5_write(fileHandle,crystallite_Fp, 'Fp') call HDF5_write(fileHandle,crystallite_Fi, 'Fi') call HDF5_write(fileHandle,crystallite_Lp, 'Lp') @@ -1665,7 +1665,7 @@ subroutine crystallite_forward integer :: i, j - crystallite_F0 = crystallite_partionedF + crystallite_F0 = crystallite_partitionedF crystallite_Fp0 = crystallite_Fp crystallite_Lp0 = crystallite_Lp crystallite_Fi0 = crystallite_Fi diff --git a/src/homogenization.f90 b/src/homogenization.f90 index de003fbc3..5aa10fcf3 100644 --- a/src/homogenization.f90 +++ b/src/homogenization.f90 @@ -404,16 +404,16 @@ subroutine partitionDeformation(subF,ip,el) chosenHomogenization: select case(homogenization_type(material_homogenizationAt(el))) case (HOMOGENIZATION_NONE_ID) chosenHomogenization - crystallite_partionedF(1:3,1:3,1,ip,el) = subF + crystallite_partitionedF(1:3,1:3,1,ip,el) = subF case (HOMOGENIZATION_ISOSTRAIN_ID) chosenHomogenization call mech_isostrain_partitionDeformation(& - crystallite_partionedF(1:3,1:3,1:homogenization_Ngrains(material_homogenizationAt(el)),ip,el), & + crystallite_partitionedF(1:3,1:3,1:homogenization_Ngrains(material_homogenizationAt(el)),ip,el), & subF) case (HOMOGENIZATION_RGC_ID) chosenHomogenization call mech_RGC_partitionDeformation(& - crystallite_partionedF(1:3,1:3,1:homogenization_Ngrains(material_homogenizationAt(el)),ip,el), & + crystallite_partitionedF(1:3,1:3,1:homogenization_Ngrains(material_homogenizationAt(el)),ip,el), & subF,& ip, & el) @@ -448,8 +448,8 @@ function updateState(subdt,subF,ip,el) updateState = & updateState .and. & mech_RGC_updateState(crystallite_P(1:3,1:3,1:homogenization_Ngrains(material_homogenizationAt(el)),ip,el), & - crystallite_partionedF(1:3,1:3,1:homogenization_Ngrains(material_homogenizationAt(el)),ip,el), & - crystallite_partionedF0(1:3,1:3,1:homogenization_Ngrains(material_homogenizationAt(el)),ip,el),& + crystallite_partitionedF(1:3,1:3,1:homogenization_Ngrains(material_homogenizationAt(el)),ip,el), & + crystallite_partitionedF0(1:3,1:3,1:homogenization_Ngrains(material_homogenizationAt(el)),ip,el),& subF,& subdt, & dPdFs, & diff --git a/src/homogenization_mech_RGC.f90 b/src/homogenization_mech_RGC.f90 index 6c015eea8..7d85e3a9c 100644 --- a/src/homogenization_mech_RGC.f90 +++ b/src/homogenization_mech_RGC.f90 @@ -212,7 +212,7 @@ end subroutine mech_RGC_init !-------------------------------------------------------------------------------------------------- module subroutine mech_RGC_partitionDeformation(F,avgF,instance,of) - real(pReal), dimension (:,:,:), intent(out) :: F !< partioned F per grain + real(pReal), dimension (:,:,:), intent(out) :: F !< partitioned F per grain real(pReal), dimension (3,3), intent(in) :: avgF !< averaged F integer, intent(in) :: & @@ -867,7 +867,7 @@ module procedure mech_RGC_updateState !-------------------------------------------------------------------------------------------------- subroutine grainDeformation(F, avgF, instance, of) - real(pReal), dimension(:,:,:), intent(out) :: F !< partioned F per grain + real(pReal), dimension(:,:,:), intent(out) :: F !< partitioned F per grain real(pReal), dimension(:,:), intent(in) :: avgF !< averaged F integer, intent(in) :: & diff --git a/src/prec.f90 b/src/prec.f90 index cec4928ba..b2866a4f4 100644 --- a/src/prec.f90 +++ b/src/prec.f90 @@ -47,7 +47,7 @@ module prec dotState, & !< rate of state change deltaState !< increment of state change real(pReal), allocatable, dimension(:,:) :: & - partionedState0, & + partitionedState0, & subState0 end type From 264fab44d0990c6ffb1dfb7c94f5f8115bc11e7b Mon Sep 17 00:00:00 2001 From: Test User Date: Thu, 8 Oct 2020 07:22:44 +0200 Subject: [PATCH 23/39] [skip ci] updated version information after successful test of v3.0.0-alpha-482-g846cbdd2e --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index e7674c155..ed080a275 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-472-g16e47956a +v3.0.0-alpha-482-g846cbdd2e From 3050471a2d95e4d036918ba5e3480426b617f4f3 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 8 Oct 2020 18:05:03 +0200 Subject: [PATCH 24/39] avoid circular inclusion --- python/damask/__init__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/python/damask/__init__.py b/python/damask/__init__.py index 955993607..600f64138 100644 --- a/python/damask/__init__.py +++ b/python/damask/__init__.py @@ -10,21 +10,21 @@ with open(_Path(__file__).parent/_Path('VERSION')) as _f: # make classes directly accessible as damask.Class from ._environment import Environment as _ # noqa environment = _() -from ._table import Table # noqa -from ._vtk import VTK # noqa -from ._colormap import Colormap # noqa -from ._rotation import Rotation # noqa -from ._lattice import Symmetry, Lattice# noqa -from ._orientation import Orientation # noqa -from ._result import Result # noqa -from ._geom import Geom # noqa -from ._config import Config # noqa -from ._configmaterial import ConfigMaterial # noqa -from . import solver # noqa from . import util # noqa from . import seeds # noqa -from . import grid_filters # noqa from . import mechanics # noqa +from . import solver # noqa +from . import grid_filters # noqa +from ._lattice import Symmetry, Lattice# noqa +from ._table import Table # noqa +from ._rotation import Rotation # noqa +from ._vtk import VTK # noqa +from ._colormap import Colormap # noqa +from ._orientation import Orientation # noqa +from ._config import Config # noqa +from ._configmaterial import ConfigMaterial # noqa +from ._geom import Geom # noqa +from ._result import Result # noqa From bdfbd2c62ea468f5a896a0c8dd7483b5de3f8d29 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 8 Oct 2020 18:05:15 +0200 Subject: [PATCH 25/39] dream3d file in an HDF5 file --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index b096658f8..c2785cf15 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,6 +8,7 @@ *.jpg binary *.hdf5 binary *.pdf binary +*.dream3d binary # ignore files from MSC.Marc in language statistics installation/mods_MarcMentat/20*/* linguist-vendored From 952ad4f8fec00552c2f100151b88e145368c7fd2 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 8 Oct 2020 18:33:40 +0200 Subject: [PATCH 26/39] functionality for geom generation in python lib --- processing/pre/geom_fromDREAM3D.py | 88 ++---------------------------- processing/pre/geom_fromTable.py | 57 ++----------------- python/damask/_geom.py | 38 ++++++++++++- 3 files changed, 44 insertions(+), 139 deletions(-) diff --git a/processing/pre/geom_fromDREAM3D.py b/processing/pre/geom_fromDREAM3D.py index daf7d2ab9..54ed4ca0a 100755 --- a/processing/pre/geom_fromDREAM3D.py +++ b/processing/pre/geom_fromDREAM3D.py @@ -1,12 +1,8 @@ #!/usr/bin/env python3 import os -import sys from optparse import OptionParser -import h5py -import numpy as np - import damask @@ -64,88 +60,12 @@ parser.set_defaults(pointwise = 'CellData', if options.basegroup is None: parser.error('No base group selected') -rootDir ='DataContainers' - - if filenames == []: parser.error('no input file specified.') for name in filenames: - damask.util.report(scriptName,name) + damask.util.report(scriptName,name) - errors = [] + geom = damask.Geom.load_DREAM3D(name,options.basegroup,options.pointwise) + damask.util.croak(geom) - inFile = h5py.File(name, 'r') - group_geom = os.path.join(rootDir,options.basegroup,'_SIMPL_GEOMETRY') - try: - size = inFile[os.path.join(group_geom,'DIMENSIONS')][...] \ - * inFile[os.path.join(group_geom,'SPACING')][...] - grid = inFile[os.path.join(group_geom,'DIMENSIONS')][...] - origin = inFile[os.path.join(group_geom,'ORIGIN')][...] - except KeyError: - errors.append('Geometry data ({}) not found'.format(group_geom)) - - - group_pointwise = os.path.join(rootDir,options.basegroup,options.pointwise) - if options.average is None: - label = 'Point' - - dataset = os.path.join(group_pointwise,options.quaternion) - try: - quats = np.reshape(inFile[dataset][...],(np.product(grid),4)) - rot = [damask.Rotation.from_quaternion(q,True,P=+1) for q in quats] - except KeyError: - errors.append('Pointwise orientation (quaternion) data ({}) not readable'.format(dataset)) - - dataset = os.path.join(group_pointwise,options.phase) - try: - phase = np.reshape(inFile[dataset][...],(np.product(grid))) - except KeyError: - errors.append('Pointwise phase data ({}) not readable'.format(dataset)) - - microstructure = np.arange(1,np.product(grid)+1,dtype=int).reshape(grid,order='F') - - - else: - label = 'Grain' - - dataset = os.path.join(group_pointwise,options.microstructure) - try: - microstructure = np.transpose(inFile[dataset][...].reshape(grid[::-1]),(2,1,0)) # convert from C ordering - except KeyError: - errors.append('Link between pointwise and grain average data ({}) not readable'.format(dataset)) - - group_average = os.path.join(rootDir,options.basegroup,options.average) - - dataset = os.path.join(group_average,options.quaternion) - try: - rot = [damask.Rotation.from_quaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed) - except KeyError: - errors.append('Average orientation data ({}) not readable'.format(dataset)) - - dataset = os.path.join(group_average,options.phase) - try: - phase = [i[0] for i in inFile[dataset][...]][1:] # skip first entry (unindexed) - except KeyError: - errors.append('Average phase data ({}) not readable'.format(dataset)) - - if errors != []: - damask.util.croak(errors) - continue - - config_header = [''] - for i in range(np.nanmax(microstructure)): - config_header += ['[{}{}]'.format(label,i+1), - '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*rot[i].as_Eulers(degrees = True)), - ] - config_header += [''] - for i in range(np.nanmax(microstructure)): - config_header += ['[{}{}]'.format(label,i+1), - '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(phase[i],i+1), - ] - - header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ - + config_header - geom = damask.Geom(microstructure,size,origin,comments=header) - damask.util.croak(geom) - - geom.save_ASCII(os.path.splitext(name)[0]+'.geom',compress=False) + geom.save_ASCII(os.path.splitext(name)[0]+'.geom',compress=False) diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py index a0de6a4c5..d3cb2d50d 100755 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -2,11 +2,8 @@ import os import sys -from io import StringIO from optparse import OptionParser -import numpy as np - import damask @@ -40,64 +37,20 @@ parser.add_option('-q', '--quaternion', dest = 'quaternion', type = 'string', metavar='string', help = 'quaternion label') -parser.add_option('--axes', - dest = 'axes', - type = 'string', nargs = 3, metavar = ' '.join(['string']*3), - help = 'orientation coordinate frame in terms of position coordinate frame [+x +y +z]') - -parser.set_defaults(pos = 'pos', - ) +parser.set_defaults(pos= 'pos') (options,filenames) = parser.parse_args() if filenames == []: filenames = [None] -if np.sum([options.quaternion is not None, - options.microstructure is not None]) != 1: - parser.error('need either microstructure or quaternion (and optionally phase) as input.') -if options.microstructure is not None and options.phase is not None: - parser.error('need either microstructure or phase (and mandatory quaternion) as input.') -if options.axes is not None and not set(options.axes).issubset(set(['x','+x','-x','y','+y','-y','z','+z','-z'])): - parser.error('invalid axes {} {} {}.'.format(*options.axes)) - for name in filenames: damask.util.report(scriptName,name) - table = damask.Table.load(StringIO(''.join(sys.stdin.read())) if name is None else name) - table.sort_by(['{}_{}'.format(i,options.pos) for i in range(3,0,-1)]) # x fast, y slow - grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos)) + labels = [] + for l in [options.quaternion,options.phase,options.microstructure]: + if l is not None: labels.append(l) - config_header = table.comments - - if options.microstructure: - microstructure = table.get(options.microstructure).reshape(grid,order='F') - - elif options.quaternion: - q = table.get(options.quaternion) - phase = table.get(options.phase).astype(int) if options.phase else \ - np.ones((table.data.shape[0],1),dtype=int) - - unique,unique_inverse = np.unique(np.hstack((q,phase)),return_inverse=True,axis=0) - microstructure = unique_inverse.reshape(grid,order='F') + 1 - - config_header = [''] - for i,data in enumerate(unique): - ori = damask.Rotation(data[0:4]) - config_header += ['[Grain{}]'.format(i+1), - '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*ori.as_Eulers(degrees = True)), - ] - if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] - - config_header += [''] - for i,data in enumerate(unique): - config_header += ['[Grain{}]'.format(i+1), - '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(int(data[4]),i+1), - ] - - header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ - + config_header - geom = damask.Geom(microstructure,size,origin, - comments=header) + geom = damask.Geom.load_table(name,options.pos,labels) damask.util.croak(geom) geom.save_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',compress=False) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 2ccbb1988..ec65154bb 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -1,15 +1,18 @@ import copy import multiprocessing as mp from functools import partial +from os import path import numpy as np +import h5py from scipy import ndimage,spatial from . import environment -from . import Rotation from . import VTK from . import util from . import grid_filters +from . import Table +from . import Rotation class Geom: @@ -353,7 +356,7 @@ class Geom: Number of periods per unit cell. Defaults to 1. materials : (int, int), optional Material IDs. Defaults to (1,2). - + Notes ----- The following triply-periodic minimal surfaces are implemented: @@ -397,6 +400,35 @@ class Geom: ) + @staticmethod + def load_DREAM3D(fname,base_group,point_data=None,material='FeatureIds'): + root_dir ='DataContainers' + f = h5py.File(fname, 'r') + g = path.join(root_dir,base_group,'_SIMPL_GEOMETRY') + size = f[path.join(g,'DIMENSIONS')][()] * f[path.join(g,'SPACING')][()] + grid = f[path.join(g,'DIMENSIONS')][()] + origin = f[path.join(g,'ORIGIN')][()] + group_pointwise = path.join(root_dir,base_group,point_data) + + ma = np.arange(1,np.product(grid)+1,dtype=int) if point_data is None else \ + np.reshape(f[path.join(group_pointwise,material)],grid.prod()) + + return Geom(ma.reshape(grid,order='F'),size,origin,util.execution_stamp('Geom','from_DREAM3D')) + + + @staticmethod + def load_table(fname,coordinates,labels): + table = Table.load(fname).sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) + + grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(table.get(coordinates)) + + labels_ = [labels] if isinstance(labels,str) else labels + _,unique_inverse = np.unique(np.hstack([table.get(l) for l in labels_]),return_inverse=True,axis=0) + ma = unique_inverse.reshape(grid,order='F') + 1 + + return Geom(ma,size,origin,util.execution_stamp('Geom','from_table')) + + def save(self,fname,compress=True): """ Generates vtk rectilinear grid. @@ -536,7 +568,7 @@ class Geom: coords_rot = R.broadcast_to(tuple(self.grid))@coords with np.errstate(all='ignore'): - mask = np.where(np.sum(np.power(coords_rot/r,2.0**exponent),axis=-1) > 1.0,True,False) + mask = np.sum(np.power(coords_rot/r,2.0**np.array(exponent)),axis=-1) > 1.0 if periodic: # translate back to center mask = np.roll(mask,((c-np.ones(3)*.5)*self.grid).astype(int),(0,1,2)) From 6ecaaa31c93ad9d41524f1abe8b93c6aafff1a32 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 8 Oct 2020 21:29:58 +0200 Subject: [PATCH 27/39] fairly general function to generate material configuration --- python/damask/_configmaterial.py | 62 +++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index 26006fef7..dacc0d080 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -62,10 +62,10 @@ class ConfigMaterial(Config): print(f'No lattice specified in phase {k}') ok = False - #for k,v in self['homogenization'].items(): - # if 'N_constituents' not in v: - # print(f'No. of constituents not specified in homogenization {k}'} - # ok = False + for k,v in self['homogenization'].items(): + if 'N_constituents' not in v: + print(f'No. of constituents not specified in homogenization {k}') + ok = False if phase - set(self['phase']): print(f'Phase(s) {phase-set(self["phase"])} missing') @@ -158,3 +158,57 @@ class ConfigMaterial(Config): except KeyError: continue return dup + + + def material_add(self,constituents,**kwargs): + """ + Add material entries. + + Parameters + ---------- + constituents: scalar or numpy.ndarray + **kwargs: tbd + + Examples + -------- + m = damask.ConfigMaterial() + O = damask.Rotation.from_random(3).as_quaternion() + phase = ['Aluminum','Steel','Aluminum'] + + m.material_add(constituents={'phase':phase,'O':O},homogenization='SX') + + """ + c = [{'constituents':u} for u in ConfigMaterial._constituents(**constituents)] + for k,v in kwargs.items(): + if isinstance(v,np.ndarray): + for i,vv in enumerate(v): + c[i][k] = [w.item() for w in vv] if isinstance(vv,np.ndarray) else vv.item() + else: + for i in range(len(c)): + c[i][k] = v + dup = copy.deepcopy(self) + if 'material' not in dup: dup['material'] = [] + dup['material'] +=c + + return dup + + + @staticmethod + def _constituents(N=1,**kwargs): + for v in kwargs.values(): + if hasattr(v,'__len__') and not isinstance(v,str): N_material = len(v) + + if N == 1: + m = [[{'fraction':1.0}] for _ in range(N_material)] + for k,v in kwargs.items(): + if hasattr(v,'__len__') and not isinstance(v,str): + if len(v) != N_material: + raise ValueError + for i,vv in enumerate(np.array(v)): + m[i][0][k] = [w.item() for w in vv] if isinstance(vv,np.ndarray) else vv.item() + else: + for i in range(N_material): + m[i][0][k] = v + return m + else: + raise NotImplementedError From 0c68d293b643005b9fef3f1dbf9f8bdef4f27989 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 9 Oct 2020 07:44:05 +0200 Subject: [PATCH 28/39] N_constituents is now a general homog property --- python/tests/reference/ConfigMaterial/material.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/tests/reference/ConfigMaterial/material.yaml b/python/tests/reference/ConfigMaterial/material.yaml index 5c006c99c..97c6504bb 100644 --- a/python/tests/reference/ConfigMaterial/material.yaml +++ b/python/tests/reference/ConfigMaterial/material.yaml @@ -1,8 +1,10 @@ homogenization: SX: + N_constituents: 2 mech: {type: none} Taylor: - mech: {N_constituents: 2, type: isostrain} + N_constituents: 2 + mech: {type: isostrain} material: - constituents: From 75401dd280ea9f86074652b049a0247c7a5cad53 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 9 Oct 2020 07:45:20 +0200 Subject: [PATCH 29/39] generate configuration from table --- python/damask/_configmaterial.py | 24 ++++++++++++++++++++++-- python/damask/_table.py | 4 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index dacc0d080..0ad76d99c 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -5,6 +5,7 @@ import numpy as np from . import Config from . import Lattice from . import Rotation +from . import Table class ConfigMaterial(Config): """Material configuration.""" @@ -23,6 +24,22 @@ class ConfigMaterial(Config): """ super().save(fname,**kwargs) + + @staticmethod + def load_table(fname,coordinates=None,constituents={},**kwargs): + t = Table.load(fname) + if coordinates is not None: t = t.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) + constituents_ = {k:t.get(v) for k,v in constituents.items()} + kwargs_ = {k:t.get(v) for k,v in kwargs.items()} + + _,idx = np.unique(np.hstack(list({**constituents_,**kwargs_}.values())),return_index=True,axis=0) + + constituents_ = {k:v[idx].squeeze() for k,v in constituents_.items()} + kwargs_ = {k:v[idx].squeeze() for k,v in kwargs_.items()} + + return ConfigMaterial().material_add(constituents_,**kwargs_) + + @property def is_complete(self): """Check for completeness.""" @@ -180,7 +197,9 @@ class ConfigMaterial(Config): """ c = [{'constituents':u} for u in ConfigMaterial._constituents(**constituents)] for k,v in kwargs.items(): - if isinstance(v,np.ndarray): + if hasattr(v,'__len__') and not isinstance(v,str): + if len(v) != len(c): + raise ValueError('len mismatch 1') for i,vv in enumerate(v): c[i][k] = [w.item() for w in vv] if isinstance(vv,np.ndarray) else vv.item() else: @@ -195,6 +214,7 @@ class ConfigMaterial(Config): @staticmethod def _constituents(N=1,**kwargs): + """Construct list of constituents.""" for v in kwargs.values(): if hasattr(v,'__len__') and not isinstance(v,str): N_material = len(v) @@ -203,7 +223,7 @@ class ConfigMaterial(Config): for k,v in kwargs.items(): if hasattr(v,'__len__') and not isinstance(v,str): if len(v) != N_material: - raise ValueError + raise ValueError('len mismatch 2') for i,vv in enumerate(np.array(v)): m[i][0][k] = [w.item() for w in vv] if isinstance(vv,np.ndarray) else vv.item() else: diff --git a/python/damask/_table.py b/python/damask/_table.py index 431cf1886..dd8df97b0 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -33,6 +33,10 @@ class Table: """Brief overview.""" return util.srepr(self.comments)+'\n'+self.data.__repr__() + def __len__(self): + """Number of rows.""" + return len(self.data) + def __copy__(self): """Copy Table.""" return copy.deepcopy(self) From 8a6287ec5f96f32abd882fba5b544cdc78fa3142 Mon Sep 17 00:00:00 2001 From: Test User Date: Fri, 9 Oct 2020 09:18:17 +0200 Subject: [PATCH 30/39] [skip ci] updated version information after successful test of v3.0.0-alpha-485-g754d56da4 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ed080a275..558076550 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-482-g846cbdd2e +v3.0.0-alpha-485-g754d56da4 From 9012df4655028623e9d01419d25cd62870b585ed Mon Sep 17 00:00:00 2001 From: Test User Date: Fri, 9 Oct 2020 12:23:00 +0200 Subject: [PATCH 31/39] [skip ci] updated version information after successful test of v3.0.0-alpha-485-g754d56da4 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ed080a275..558076550 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-482-g846cbdd2e +v3.0.0-alpha-485-g754d56da4 From 347c88cbb66afae7e24764e814ade89aad19b2ed Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 9 Oct 2020 14:19:19 +0200 Subject: [PATCH 32/39] documented --- python/damask/_configmaterial.py | 83 ++++++++++++++++++++++++---- python/damask/_geom.py | 94 ++++++++++++++++++++++---------- 2 files changed, 137 insertions(+), 40 deletions(-) diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index 0ad76d99c..3b3d22a0e 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -2,6 +2,7 @@ import copy import numpy as np +from . import grid_filters from . import Config from . import Lattice from . import Rotation @@ -18,7 +19,7 @@ class ConfigMaterial(Config): ---------- fname : file, str, or pathlib.Path, optional Filename or file for writing. Defaults to 'material.yaml'. - **kwargs : dict + **kwargs Keyword arguments parsed to yaml.dump. """ @@ -27,8 +28,50 @@ class ConfigMaterial(Config): @staticmethod def load_table(fname,coordinates=None,constituents={},**kwargs): + """ + Load from an ASCII table. + + Parameters + ---------- + fname : str, file handle, or damask.Table + Table that contains material information. + coordinates : str, optional + Label of spatial coordiates. Used for sorting and performing a + sanity check. Default to None, in which case no sorting or checking is + peformed. + constituents : dict, optional + Entries for 'constituents'. The key is the name and the value specifies + the label of the data column in the table + **kwargs + Keyword arguments where the key is the name and the value specifies + the label of the data column in the table + + Examples + -------- + >>> import damask + >>> import damask.ConfigMaterial as cm + >>> damask.Table.load('small.txt') + 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 + >>> cm.load_table('small.txt','pos',{'O':'qu','phase':'phase'},homogenization='h') + material: + - constituents: + - O: [0.19, 0.8, 0.24, -0.51] + fraction: 1.0 + phase: Aluminum + homogenization: SX + - constituents: + - O: [0.8, 0.19, 0.24, -0.51] + fraction: 1.0 + phase: Steel + homogenization: SX + + """ t = Table.load(fname) - if coordinates is not None: t = t.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) + if coordinates is not None: + t = t.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) + grid_filters.coord0_check(t.get(coordinates)) constituents_ = {k:t.get(v) for k,v in constituents.items()} kwargs_ = {k:t.get(v) for k,v in kwargs.items()} @@ -183,17 +226,37 @@ class ConfigMaterial(Config): Parameters ---------- - constituents: scalar or numpy.ndarray - **kwargs: tbd + constituents : dict + Entries for 'constituents'. The key is the name and the value specifies + the label of the data column in the table + **kwargs + Keyword arguments where the key is the name and the value specifies + the label of the data column in the table Examples -------- - m = damask.ConfigMaterial() - O = damask.Rotation.from_random(3).as_quaternion() - phase = ['Aluminum','Steel','Aluminum'] - - m.material_add(constituents={'phase':phase,'O':O},homogenization='SX') - + >>> import damask + >>> m = damask.ConfigMaterial() + >>> O = damask.Rotation.from_random(3).as_quaternion() + >>> phase = ['Aluminum','Steel','Aluminum'] + >>> m.material_add(constituents={'phase':phase,'O':O},homogenization='SX') + material: + - constituents: + - O: [0.577764, -0.146299, -0.617669, 0.513010] + fraction: 1.0 + phase: Aluminum + homogenization: SX + - constituents: + - O: [0.184176, 0.340305, 0.737247, 0.553840] + fraction: 1.0 + phase: Steel + homogenization: SX + - constituents: + - O: [0.0886257, -0.144848, 0.615674, -0.769487] + fraction: 1.0 + phase: Aluminum + homogenization: SX + """ c = [{'constituents':u} for u in ConfigMaterial._constituents(**constituents)] for k,v in kwargs.items(): diff --git a/python/damask/_geom.py b/python/damask/_geom.py index ec65154bb..7a5b20fcc 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -210,6 +210,69 @@ class Geom: return Geom(material.reshape(grid,order='F'),size,origin,comments) + + @staticmethod + def load_DREAM3D(fname,base_group,point_data=None,material='FeatureIds'): + """ + Load a DREAM.3D file. + + Parameters + ---------- + fname : str + Filename of the DREAM.3D file + base_group : str + Name of the group (folder) below 'DataContainers'. For example + 'SyntheticVolumeDataContainer'. + point_data : str, optional + Name of the group (folder) containing the point wise material data, + for example 'CellData'. Defaults to None, in which case points consecutively numbered. + material : str, optional + Name of the dataset containing the material ID. Defaults to + 'FeatureIds'. + + """ + root_dir ='DataContainers' + f = h5py.File(fname, 'r') + g = path.join(root_dir,base_group,'_SIMPL_GEOMETRY') + size = f[path.join(g,'DIMENSIONS')][()] * f[path.join(g,'SPACING')][()] + grid = f[path.join(g,'DIMENSIONS')][()] + origin = f[path.join(g,'ORIGIN')][()] + group_pointwise = path.join(root_dir,base_group,point_data) + + ma = np.arange(1,np.product(grid)+1,dtype=int) if point_data is None else \ + np.reshape(f[path.join(group_pointwise,material)],grid.prod()) + + return Geom(ma.reshape(grid,order='F'),size,origin,util.execution_stamp('Geom','load_DREAM3D')) + + + @staticmethod + def load_table(fname,coordinates,labels): + """ + Load an ASCII table. + + Parameters + ---------- + fname : str, file handle, or damask.Table + Table that contains geometry information. + coordinates : str + Label of the column containing the spatial coordinates. + labels : str or list of str + Label(s) of the columns containing the material definition. + Each unique combintation of values results in a material. + + """ + table = (fname if isinstance(fname,Table) else Table.load(fname)). \ + sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) + + grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(table.get(coordinates)) + + labels_ = [labels] if isinstance(labels,str) else labels + _,unique_inverse = np.unique(np.hstack([table.get(l) for l in labels_]),return_inverse=True,axis=0) + ma = unique_inverse.reshape(grid,order='F') + 1 + + return Geom(ma,size,origin,util.execution_stamp('Geom','load_table')) + + @staticmethod def _find_closest_seed(seeds, weights, point): return np.argmin(np.sum((np.broadcast_to(point,(len(seeds),3))-seeds)**2,axis=1) - weights) @@ -400,38 +463,9 @@ class Geom: ) - @staticmethod - def load_DREAM3D(fname,base_group,point_data=None,material='FeatureIds'): - root_dir ='DataContainers' - f = h5py.File(fname, 'r') - g = path.join(root_dir,base_group,'_SIMPL_GEOMETRY') - size = f[path.join(g,'DIMENSIONS')][()] * f[path.join(g,'SPACING')][()] - grid = f[path.join(g,'DIMENSIONS')][()] - origin = f[path.join(g,'ORIGIN')][()] - group_pointwise = path.join(root_dir,base_group,point_data) - - ma = np.arange(1,np.product(grid)+1,dtype=int) if point_data is None else \ - np.reshape(f[path.join(group_pointwise,material)],grid.prod()) - - return Geom(ma.reshape(grid,order='F'),size,origin,util.execution_stamp('Geom','from_DREAM3D')) - - - @staticmethod - def load_table(fname,coordinates,labels): - table = Table.load(fname).sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) - - grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(table.get(coordinates)) - - labels_ = [labels] if isinstance(labels,str) else labels - _,unique_inverse = np.unique(np.hstack([table.get(l) for l in labels_]),return_inverse=True,axis=0) - ma = unique_inverse.reshape(grid,order='F') + 1 - - return Geom(ma,size,origin,util.execution_stamp('Geom','from_table')) - - def save(self,fname,compress=True): """ - Generates vtk rectilinear grid. + Store as vtk rectilinear grid. Parameters ---------- From 6d806669293ebfb60b7c0f8a6f27608adef90979 Mon Sep 17 00:00:00 2001 From: Test User Date: Fri, 9 Oct 2020 18:35:34 +0200 Subject: [PATCH 33/39] [skip ci] updated version information after successful test of v3.0.0-alpha-488-gbe89b7ab9 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 558076550..e9c998baf 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-485-g754d56da4 +v3.0.0-alpha-488-gbe89b7ab9 From 57180952ecc3a2d8b36c7c26f2aa993bebb67a75 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 9 Oct 2020 19:05:05 +0200 Subject: [PATCH 34/39] typo --- python/damask/_configmaterial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index 3b3d22a0e..2d897e79f 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -54,7 +54,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 - >>> cm.load_table('small.txt','pos',{'O':'qu','phase':'phase'},homogenization='h') + >>> cm.load_table('small.txt','pos',{'O':'qu','phase':'phase'},homogenization='homog') material: - constituents: - O: [0.19, 0.8, 0.24, -0.51] From 06d11a72da97f25b6c6c82f9b2a75998915bd089 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 9 Oct 2020 19:19:05 +0200 Subject: [PATCH 35/39] better fitting name load implies a more direct takeover. --- processing/pre/geom_fromTable.py | 3 ++- python/damask/_configmaterial.py | 18 ++++++++++-------- python/damask/_geom.py | 16 +++++++--------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py index d3cb2d50d..29a8b8852 100755 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -50,7 +50,8 @@ for name in filenames: for l in [options.quaternion,options.phase,options.microstructure]: if l is not None: labels.append(l) - geom = damask.Geom.load_table(name,options.pos,labels) + t = damask.Table.load(name) + geom = damask.Geom.from_table(t,options.pos,labels) damask.util.croak(geom) geom.save_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',compress=False) diff --git a/python/damask/_configmaterial.py b/python/damask/_configmaterial.py index 2d897e79f..a7ecec108 100644 --- a/python/damask/_configmaterial.py +++ b/python/damask/_configmaterial.py @@ -6,7 +6,6 @@ from . import grid_filters from . import Config from . import Lattice from . import Rotation -from . import Table class ConfigMaterial(Config): """Material configuration.""" @@ -27,13 +26,13 @@ class ConfigMaterial(Config): @staticmethod - def load_table(fname,coordinates=None,constituents={},**kwargs): + def from_table(table,coordinates=None,constituents={},**kwargs): """ Load from an ASCII table. Parameters ---------- - fname : str, file handle, or damask.Table + table : damask.Table Table that contains material information. coordinates : str, optional Label of spatial coordiates. Used for sorting and performing a @@ -50,11 +49,12 @@ class ConfigMaterial(Config): -------- >>> import damask >>> import damask.ConfigMaterial as cm - >>> damask.Table.load('small.txt') + >>> t = damask.Table.load('small.txt') + >>> t 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 - >>> cm.load_table('small.txt','pos',{'O':'qu','phase':'phase'},homogenization='homog') + >>> cm.from_table(t,'pos',{'O':'qu','phase':'phase'},homogenization='homog') material: - constituents: - O: [0.19, 0.8, 0.24, -0.51] @@ -68,10 +68,12 @@ class ConfigMaterial(Config): homogenization: SX """ - t = Table.load(fname) if coordinates is not None: - t = t.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) + t = table.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) grid_filters.coord0_check(t.get(coordinates)) + else: + t = table + constituents_ = {k:t.get(v) for k,v in constituents.items()} kwargs_ = {k:t.get(v) for k,v in kwargs.items()} @@ -256,7 +258,7 @@ class ConfigMaterial(Config): fraction: 1.0 phase: Aluminum homogenization: SX - + """ c = [{'constituents':u} for u in ConfigMaterial._constituents(**constituents)] for k,v in kwargs.items(): diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 7a5b20fcc..eb4dd055e 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -11,7 +11,6 @@ from . import environment from . import VTK from . import util from . import grid_filters -from . import Table from . import Rotation @@ -246,14 +245,14 @@ class Geom: @staticmethod - def load_table(fname,coordinates,labels): + def from_table(table,coordinates,labels): """ Load an ASCII table. Parameters ---------- - fname : str, file handle, or damask.Table - Table that contains geometry information. + table : damask.Table + Table that contains material information. coordinates : str Label of the column containing the spatial coordinates. labels : str or list of str @@ -261,16 +260,15 @@ class Geom: Each unique combintation of values results in a material. """ - table = (fname if isinstance(fname,Table) else Table.load(fname)). \ - sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) + t = table.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)]) - grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(table.get(coordinates)) + grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(t.get(coordinates)) labels_ = [labels] if isinstance(labels,str) else labels - _,unique_inverse = np.unique(np.hstack([table.get(l) for l in labels_]),return_inverse=True,axis=0) + _,unique_inverse = np.unique(np.hstack([t.get(l) for l in labels_]),return_inverse=True,axis=0) ma = unique_inverse.reshape(grid,order='F') + 1 - return Geom(ma,size,origin,util.execution_stamp('Geom','load_table')) + return Geom(ma,size,origin,util.execution_stamp('Geom','from_table')) @staticmethod From 02e6ff85a3718cdbfc5405355479a32053d5898d Mon Sep 17 00:00:00 2001 From: Test User Date: Sat, 10 Oct 2020 13:12:27 +0200 Subject: [PATCH 36/39] [skip ci] updated version information after successful test of v3.0.0-alpha-491-ge44a1dd2e --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index e9c998baf..66ab78bcb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-488-gbe89b7ab9 +v3.0.0-alpha-491-ge44a1dd2e From c8a9bc60d32bb624dd1fcfcb5502caaedfd3c390 Mon Sep 17 00:00:00 2001 From: Test User Date: Sun, 11 Oct 2020 23:28:10 +0200 Subject: [PATCH 37/39] [skip ci] updated version information after successful test of v3.0.0-alpha-502-g8ab405e5d --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 66ab78bcb..41d9ce4ba 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0-alpha-491-ge44a1dd2e +v3.0.0-alpha-502-g8ab405e5d From 5267aff1a2546aa2f540851d0435002bc39c8955 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 12 Oct 2020 05:29:48 +0200 Subject: [PATCH 38/39] natural Fortran order --- src/rotations.f90 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rotations.f90 b/src/rotations.f90 index 0b72c1dd5..ea4a8a9d8 100644 --- a/src/rotations.f90 +++ b/src/rotations.f90 @@ -737,13 +737,13 @@ pure function eu2om(eu) result(om) s = sin(eu) om(1,1) = c(1)*c(3)-s(1)*s(3)*c(2) - om(1,2) = s(1)*c(3)+c(1)*s(3)*c(2) - om(1,3) = s(3)*s(2) om(2,1) = -c(1)*s(3)-s(1)*c(3)*c(2) - om(2,2) = -s(1)*s(3)+c(1)*c(3)*c(2) - om(2,3) = c(3)*s(2) om(3,1) = s(1)*s(2) + om(1,2) = s(1)*c(3)+c(1)*s(3)*c(2) + om(2,2) = -s(1)*s(3)+c(1)*c(3)*c(2) om(3,2) = -c(1)*s(2) + om(1,3) = s(3)*s(2) + om(2,3) = c(3)*s(2) om(3,3) = c(2) where(abs(om)<1.0e-12_pReal) om = 0.0_pReal From 19dba92235710ce589f5134bf0dd151664f0f525 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 12 Oct 2020 05:33:32 +0200 Subject: [PATCH 39/39] material.config -> material.yaml --- .../Phase_Phenopowerlaw_BCC-Ferrite.config | 21 ------------------- .../Phase_Phenopowerlaw_BCC-Ferrite.yaml | 16 ++++++++++++++ .../Phase_Phenopowerlaw_BCC-Martensite.config | 21 ------------------- .../Phase_Phenopowerlaw_BCC-Martensite.yaml | 16 ++++++++++++++ 4 files changed, 32 insertions(+), 42 deletions(-) delete mode 100644 examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Ferrite.config create mode 100644 examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Ferrite.yaml delete mode 100644 examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Martensite.config create mode 100644 examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Martensite.yaml diff --git a/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Ferrite.config b/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Ferrite.config deleted file mode 100644 index 5af1eee11..000000000 --- a/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Ferrite.config +++ /dev/null @@ -1,21 +0,0 @@ -# Tasan et.al. 2015 Acta Materalia -# Tasan et.al. 2015 International Journal of Plasticity -# Diehl et.al. 2015 Meccanica -[BCC-Ferrite] - -elasticity hooke -plasticity phenopowerlaw - -lattice_structure bcc -Nslip 12 12 # per family -Ntwin 0 # per family -c11 233.3e9 -c12 135.5e9 -c44 118.0e9 -gdot0_slip 0.001 -n_slip 20 -tau0_slip 95.e6 97.e6 # per family, optimization long simplex 109 -tausat_slip 222.e6 412.7e6 # per family, optimization long simplex 109 -h0_slipslip 1000.0e6 -interaction_slipslip 1 1 1.4 1.4 1.4 1.4 -a_slip 2.0 diff --git a/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Ferrite.yaml b/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Ferrite.yaml new file mode 100644 index 000000000..4940ca8bd --- /dev/null +++ b/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Ferrite.yaml @@ -0,0 +1,16 @@ +# Tasan et.al. 2015 Acta Materalia +# Tasan et.al. 2015 International Journal of Plasticity +# Diehl et.al. 2015 Meccanica +Ferrite: + elasticity: {C_11: 233.3e9, C_12: 135.5e9, C_44: 118.0e9, type: hooke} + lattice: bcc + plasticity: + N_sl: [12, 12] + a_sl: 2.0 + dot_gamma_0_sl: 0.001 + h_0_sl_sl: 1000.0e6 + h_sl_sl: [1, 1, 1.4, 1.4, 1.4, 1.4] + n_sl: 20 + type: phenopowerlaw + xi_0_sl: [95.e6, 96.e6] + xi_inf_sl: [222.e6, 412.7e6] diff --git a/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Martensite.config b/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Martensite.config deleted file mode 100644 index a04f27e7f..000000000 --- a/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Martensite.config +++ /dev/null @@ -1,21 +0,0 @@ -# Tasan et.al. 2015 Acta Materalia -# Tasan et.al. 2015 International Journal of Plasticity -# Diehl et.al. 2015 Meccanica -[BCC-Martensite] - -elasticity hooke -plasticity phenopowerlaw - -lattice_structure bcc -Nslip 12 12 # per family -Ntwin 0 # per family -c11 417.4e9 -c12 242.4e9 -c44 211.1e9 -gdot0_slip 0.001 -n_slip 20 -tau0_slip 405.8e6 456.7e6 # per family -tausat_slip 872.9e6 971.2e6 # per family -h0_slipslip 563.0e9 -interaction_slipslip 1 1 1.4 1.4 1.4 1.4 -a_slip 2.0 diff --git a/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Martensite.yaml b/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Martensite.yaml new file mode 100644 index 000000000..b207d7b34 --- /dev/null +++ b/examples/ConfigFiles/Phase_Phenopowerlaw_BCC-Martensite.yaml @@ -0,0 +1,16 @@ +# Tasan et.al. 2015 Acta Materalia +# Tasan et.al. 2015 International Journal of Plasticity +# Diehl et.al. 2015 Meccanica +Martensite: + elasticity: {C_11: 417.4e9, C_12: 242.4e9, C_44: 211.1e9, type: hooke} + lattice: bcc + plasticity: + N_sl: [12, 12] + a_sl: 2.0 + dot_gamma_0_sl: 0.001 + h_0_sl_sl: 563.0e9 + h_sl_sl: [1, 1, 1.4, 1.4, 1.4, 1.4] + n_sl: 20 + type: phenopowerlaw + xi_0_sl: [405.8e6, 456.7e6] + xi_inf_sl: [872.9e6, 971.2e6]