additional property shows integer list

This commit is contained in:
Philip Eisenlohr 2022-04-01 18:04:50 -04:00
parent 4f646f03ee
commit 84ac426606
1 changed files with 19 additions and 16 deletions

View File

@ -112,10 +112,10 @@ 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(r'increment_([0-9]+)')
self.increments = sorted([i for i in f.keys() if r.match(i)],key=util.natural_sort) self.incs = sorted([int(m.group(1)) for i in f.keys() for m in (r.match(i),) if m])
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.incs) == 0:
raise ValueError('incomplete DADF5 file') raise ValueError('incomplete DADF5 file')
self.N_materialpoints, self.N_constituents = np.shape(f['cell_to/phase']) self.N_materialpoints, self.N_constituents = np.shape(f['cell_to/phase'])
@ -240,16 +240,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,12 +257,10 @@ 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('increment_') 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,end):
""" """
@ -541,6 +539,11 @@ class Result:
print(f'Function {func.__name__} enabled in add_calculation.') print(f'Function {func.__name__} enabled in add_calculation.')
@property
def increments(self):
return list(map(lambda i:f'increment_{i}',self.incs))
@property @property
def coordinates0_point(self): def coordinates0_point(self):
"""Initial/undeformed cell center coordinates.""" """Initial/undeformed cell center coordinates."""
@ -1602,7 +1605,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])