Merge branch 'result.incs' into 'development'

additional property shows integer list

See merge request damask/DAMASK!564
This commit is contained in:
Martin Diehl 2022-04-23 03:33:16 +00:00
commit 1f4ee0813f
1 changed files with 29 additions and 27 deletions

View File

@ -26,6 +26,7 @@ from . import util
h5py3 = h5py.__version__[0] == '3' h5py3 = h5py.__version__[0] == '3'
chunk_size = 1024**2//8 # for compression in HDF5 chunk_size = 1024**2//8 # for compression in HDF5
prefix_inc = 'increment_'
def _read(dataset): def _read(dataset):
"""Read a dataset and its metadata into a numpy.ndarray.""" """Read a dataset and its metadata into a numpy.ndarray."""
@ -112,9 +113,9 @@ class Result:
else: else:
self.add_curl = self.add_divergence = self.add_gradient = None self.add_curl = self.add_divergence = self.add_gradient = None
r=re.compile('increment_[0-9]+') 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) self.increments = sorted([i for i in f.keys() if r.match(i)],key=util.natural_sort)
self.times = [round(f[i].attrs['t/s'],12) for i in self.increments] self.times = [round(f[i].attrs['t/s'],12) for i in self.increments]
if len(self.increments) == 0: if len(self.increments) == 0:
raise ValueError('incomplete DADF5 file') raise ValueError('incomplete DADF5 file')
@ -207,9 +208,9 @@ class Result:
[datasets] [datasets]
if what == 'increments': if what == 'increments':
choice = [c if isinstance(c,str) and c.startswith('increment_') else choice = [c if isinstance(c,str) and c.startswith(prefix_inc) else
self.increments[c] if isinstance(c,int) and c<0 else self.increments[c] if isinstance(c,int) and c<0 else
f'increment_{c}' for c in choice] f'{prefix_inc}{c}' for c in choice]
elif what == 'times': elif what == 'times':
what = 'increments' what = 'increments'
if choice == ['*']: if choice == ['*']:
@ -240,16 +241,16 @@ class Result:
return dup return dup
def increments_in_range(self,start,end): def increments_in_range(self,start=None,end=None):
""" """
Get all increments within a given range. Get all increments within a given range.
Parameters Parameters
---------- ----------
start : int or str start : int or str, optional
Start increment. Start increment. Defaults to first.
end : int or str end : int or str, optional
End increment. End increment. Defaults to last.
Returns Returns
------- -------
@ -257,35 +258,31 @@ class Result:
Increment number of all increments within the given bounds. Increment number of all increments within the given bounds.
""" """
selected = [] s,e = map(lambda x: int(x[10:] if isinstance(x,str) and x.startswith(prefix_inc) else x),
for i,inc in enumerate([int(i[10:]) for i in self.increments]): (self.incs[ 0] if start is None else start,
s,e = map(lambda x: int(x[10:] if isinstance(x,str) and x.startswith('inc') else x), (start,end)) self.incs[-1] if end is None else end))
if s <= inc <= e: return [i for i in self.incs if s <= i <= e]
selected.append(self.increments[i])
return selected
def times_in_range(self,start,end): def times_in_range(self,start=None,end=None):
""" """
Get all increments within a given time range. Get all increments within a given time range.
Parameters Parameters
---------- ----------
start : float start : float, optional
Time of start increment. Time of start increment. Defaults to first.
end : float end : float, optional
Time of end increment. Time of end increment. Defaults to last.
Returns Returns
------- -------
times : list of float times : list of float
Simulation time of all increments within the given bounds. Time of each increment within the given bounds.
""" """
selected = [] s,e = (self.times[ 0] if start is None else start,
for i,time in enumerate(self.times): self.times[-1] if end is None else end)
if start <= time <= end: return [t for t in self.times if s <= t <= e]
selected.append(self.times[i])
return selected
def view(self,*, def view(self,*,
@ -541,6 +538,11 @@ class Result:
print(f'Function {func.__name__} enabled in add_calculation.') print(f'Function {func.__name__} enabled in add_calculation.')
@property
def incs(self):
return [int(i.split(prefix_inc)[-1]) for i in self.increments]
@property @property
def coordinates0_point(self): def coordinates0_point(self):
"""Initial/undeformed cell center coordinates.""" """Initial/undeformed cell center coordinates."""
@ -1602,7 +1604,7 @@ class Result:
v.comments = util.execution_stamp('Result','export_VTK') v.comments = util.execution_stamp('Result','export_VTK')
N_digits = int(np.floor(np.log10(max(1,int(self.increments[-1][10:])))))+1 N_digits = int(np.floor(np.log10(max(1,self.incs[-1]))))+1
constituents_ = constituents if isinstance(constituents,Iterable) else \ constituents_ = constituents if isinstance(constituents,Iterable) else \
(range(self.N_constituents) if constituents is None else [constituents]) (range(self.N_constituents) if constituents is None else [constituents])