Merge branch 'development' into '285-attributes-of-damask-result-should-depend-on-view'

# Conflicts:
#   python/damask/_result.py
This commit is contained in:
Philip Eisenlohr 2023-12-20 19:14:40 +00:00
commit 42a752aa6b
4 changed files with 29 additions and 18 deletions

View File

@ -1 +1 @@
3.0.0-alpha8-169-g85191cd02
3.0.0-alpha8-172-gec624a86a

View File

@ -114,8 +114,6 @@ class Result:
self.cells = f['geometry'].attrs['cells']
self.size = f['geometry'].attrs['size']
self.origin = f['geometry'].attrs['origin']
else:
self.add_curl = self.add_divergence = self.add_gradient = None # type: ignore
r = re.compile(rf'{prefix_inc}([0-9]+)')
self._increments = sorted([i for i in f.keys() if r.match(i)],key=util.natural_sort)
@ -1346,8 +1344,8 @@ class Result:
Notes
-----
This function is only available for structured grids,
i.e. fields resulting from the grid solver.
This function is implemented only for structured grids
with one constituent and a single phase.
"""
def curl(f: DADF5Dataset, size: np.ndarray) -> DADF5Dataset:
@ -1375,8 +1373,8 @@ class Result:
Notes
-----
This function is only available for structured grids,
i.e. fields resulting from the grid solver.
This function is implemented only for structured grids
with one constituent and a single phase.
"""
def divergence(f: DADF5Dataset, size: np.ndarray) -> DADF5Dataset:
@ -1404,8 +1402,8 @@ class Result:
Notes
-----
This function is only available for structured grids,
i.e. fields resulting from the grid solver.
This function is implemented only for structured grids
with one constituent and a single phase.
"""
def gradient(f: DADF5Dataset, size: np.ndarray) -> DADF5Dataset:
@ -1443,13 +1441,13 @@ class Result:
Arguments parsed to func.
"""
if len(datasets) != 1 or self.N_constituents != 1:
raise NotImplementedError
if self.N_constituents != 1 or len(datasets) != 1 or not self.structured:
raise NotImplementedError('not a structured grid with one constituent and a single phase')
at_cell_ph,in_data_ph,at_cell_ho,in_data_ho = self._mappings()
increments = self.place(list(datasets.values()),False)
if not increments: raise RuntimeError("received invalid dataset")
if not increments: raise RuntimeError('received invalid dataset')
with h5py.File(self.fname, 'a') as f:
for increment in increments.items():
for ty in increment[1].items():
@ -1753,9 +1751,14 @@ class Result:
Defaults to False, i.e. the XDMF file expects the
DADF5 file at a stable relative path.
Notes
-----
This function is implemented only for structured grids with
one constituent and a single phase.
"""
if self.N_constituents != 1 or len(self._phases) != 1 or not self.structured:
raise TypeError('XDMF output requires structured grid with single phase and single constituent.')
if self.N_constituents != 1 or len(self.phases) != 1 or not self.structured:
raise NotImplementedError('not a structured grid with one constituent and a single phase')
attribute_type_map = defaultdict(lambda:'Matrix', ( ((),'Scalar'), ((3,),'Vector'), ((3,3),'Tensor')) )
@ -1979,6 +1982,11 @@ class Result:
target_dir : str or pathlib.Path, optional
Directory to save DREAM3D files. Will be created if non-existent.
Notes
-----
This function is implemented only for structured grids with
one constituent.
"""
def add_attribute(obj,name,data):
"""DREAM.3D requires fixed length string."""
@ -1994,11 +2002,10 @@ class Result:
return obj[name]
if self.N_constituents != 1 or not self.structured:
raise TypeError('DREAM3D output requires structured grid with single constituent.')
raise NotImplementedError('not a structured grid with one constituent')
N_digits = int(np.floor(np.log10(max(1,self._incs[-1]))))+1
at_cell_ph,in_data_ph,_,_ = self._mappings()
out_dir = Path.cwd() if target_dir is None else Path(target_dir)

View File

@ -620,7 +620,7 @@ def _docstringer(docstring: _Union[str, _Callable],
adopted_,
flags=_re.MULTILINE|_re.DOTALL).group('content')
except AttributeError:
raise RuntimeError(f"Function docstring passed for docstring section '{key}' is invalid:\n{docstring}")
raise RuntimeError(f"function docstring passed for docstring section '{key}' is invalid:\n{docstring}")
docstring_indent, adopted_indent = (min([len(line)-len(line.lstrip()) for line in section.split('\n') if line.strip()])
for section in [docstring_, adopted_])

View File

@ -495,6 +495,10 @@ class TestResult:
for attr in dset.attrs:
assert np.array_equal(dset.attrs[attr],cur[path].attrs[attr])
def test_export_DREAM3D_invalid(self,res_path):
with pytest.raises(NotImplementedError):
Result(res_path/'4grains2x4x3_compressionY.hdf5').export_DREAM3D()
def test_XDMF_datatypes(self,tmp_path,single_phase,update,res_path):
for what,shape in {'scalar':(),'vector':(3,),'tensor':(3,3),'matrix':(12,)}.items():
@ -526,7 +530,7 @@ class TestResult:
assert dim_vti == dim_xdmf and bounds_vti == bounds_xdmf
def test_XDMF_invalid(self,default):
with pytest.raises(TypeError):
with pytest.raises(NotImplementedError):
default.export_XDMF()
def test_XDMF_custom_path(self,single_phase,tmp_path):