on_air/active are not clear. visible seems to be the most appropriate
name
This commit is contained in:
Martin Diehl 2019-09-13 21:49:22 -07:00
parent a6567e0cc6
commit c13db4b3ca
3 changed files with 49 additions and 50 deletions

View File

@ -59,7 +59,7 @@ for filename in options.filenames:
data = np.concatenate((data,coords),1) data = np.concatenate((data,coords),1)
header+=' 1_pos 2_pos 3_pos' header+=' 1_pos 2_pos 3_pos'
results.active['increments'] = [inc] results.visible['increments'] = [inc]
for label in options.con: for label in options.con:
for o in results.constituent_output_iter(): for o in results.constituent_output_iter():

View File

@ -60,7 +60,7 @@ for filename in options.filenames:
for i,inc in enumerate(results.increments): for i,inc in enumerate(results.increments):
print('Output step {}/{}'.format(i+1,len(results.increments))) print('Output step {}/{}'.format(i+1,len(results.increments)))
vtk_data = [] vtk_data = []
results.active['increments'] = [inc] results.visible['increments'] = [inc]
results.materialpoint_set([]) results.materialpoint_set([])
results.constituent_set(results.constituents) results.constituent_set(results.constituents)

View File

@ -58,8 +58,7 @@ class DADF5():
self.m_output_types.append(o) self.m_output_types.append(o)
self.m_output_types = list(set(self.m_output_types)) # make unique self.m_output_types = list(set(self.m_output_types)) # make unique
#self.on_air self.visible= {'increments': self.increments, # ToDo:simplify, activity only positions that translate into (no complex types)
self.active= {'increments': self.increments, # ToDo:simplify, activity only positions that translate into (no complex types)
'constituents': self.constituents, 'constituents': self.constituents,
'materialpoints': self.materialpoints, 'materialpoints': self.materialpoints,
'constituent': range(self.Nconstituents), # ToDo: stupid naming 'constituent': range(self.Nconstituents), # ToDo: stupid naming
@ -68,100 +67,100 @@ class DADF5():
self.filename = filename self.filename = filename
def __on_air_set(self,output,t,p): def __visible_set(self,output,t,p):
valid = set(p) valid = set(p)
choice = [output] if isinstance(output,str) else output choice = [output] if isinstance(output,str) else output
self.active[t] = list(valid.intersection(choice)) self.visible[t] = list(valid.intersection(choice))
def __on_air_add(self,output,t,p): def __visible_add(self,output,t,p):
choice = [output] if isinstance(output,str) else output choice = [output] if isinstance(output,str) else output
valid = set(p).intersection(choice) valid = set(p).intersection(choice)
existing = set(self.active[t]) existing = set(self.visible[t])
self.active[t] = list(existing.add(valid)) self.visible[t] = list(existing.add(valid))
def __on_air_del(self,output,t): def __visible_del(self,output,t):
choice = [output] if isinstance(output,str) else output choice = [output] if isinstance(output,str) else output
existing = set(self.active[t]) existing = set(self.visible[t])
self.active[t] = list(existing.remove(choice)) self.visible[t] = list(existing.remove(choice))
def __on_air_iter(self,t): def __visible_iter(self,t):
a = self.active[t] a = self.visible[t]
last_a = a.copy() last_a = a.copy()
for i in a: for i in a:
if last_a != self.active[t]: if last_a != self.visible[t]:
self.__on_air_set(a,t,a) self.__visible_set(a,t,a)
raise Exception raise Exception
self.__on_air_set(i,t,a) self.__visible_set(i,t,a)
last_a = self.active[t] last_a = self.visible[t]
yield i yield i
self.__on_air_set(a,t,a) self.__visible_set(a,t,a)
def constituent_output_iter(self): def constituent_output_iter(self):
return self.__on_air_iter('c_output_types') return self.__visible_iter('c_output_types')
def constituent_output_set(self,output): def constituent_output_set(self,output):
self.__on_air_set(output,'c_output_types',self.c_output_types) self.__visible_set(output,'c_output_types',self.c_output_types)
def constituent_output_add(self,output): def constituent_output_add(self,output):
self.__on_air_add(output,'c_output_types',self.c_output_types) self.__visible_add(output,'c_output_types',self.c_output_types)
def constituent_output_del(self,output): def constituent_output_del(self,output):
self.__on_air_del(output,'c_output_types') self.__visible_del(output,'c_output_types')
def materialpoint_output_iter(self): def materialpoint_output_iter(self):
return self.__on_air_iter('m_output_types') return self.__visible_iter('m_output_types')
def materialpoint_output_set(self,output): def materialpoint_output_set(self,output):
self.__on_air_set(output,'m_output_types',self.m_output_types) self.__visible_set(output,'m_output_types',self.m_output_types)
def materialpoint_output_add(self,output): def materialpoint_output_add(self,output):
self.__on_air_add(output,'m_output_types',self.m_output_types) self.__visible_add(output,'m_output_types',self.m_output_types)
def materialpoint_output_del(self,output): def materialpoint_output_del(self,output):
self.__on_air_del(output,'m_output_types') self.__visible_del(output,'m_output_types')
def constituent_iter(self): def constituent_iter(self):
return self.__on_air_iter('constituents') return self.__visible_iter('constituents')
def constituent_set(self,output): def constituent_set(self,output):
self.__on_air_set(output,'constituents',self.constituents) self.__visible_set(output,'constituents',self.constituents)
def constituent_add(self,output): def constituent_add(self,output):
self.__on_air_add(output,'constituents',self.constituents) self.__visible_add(output,'constituents',self.constituents)
def constituent_del(self,output): def constituent_del(self,output):
self.__on_air_del(output,'constituents') self.__visible_del(output,'constituents')
def materialpoint_iter(self): def materialpoint_iter(self):
return self.__on_air_iter('materialpoints') return self.__visible_iter('materialpoints')
def materialpoint_set(self,output): def materialpoint_set(self,output):
self.__on_air_set(output,'materialpoints',self.materialpoints) self.__visible_set(output,'materialpoints',self.materialpoints)
def materialpoint_add(self,output): def materialpoint_add(self,output):
self.__on_air_add(output,'materialpoints',self.materialpoints) self.__visible_add(output,'materialpoints',self.materialpoints)
def materialpoint_del(self,output): def materialpoint_del(self,output):
self.__on_air_del(output,'materialpoints') self.__visible_del(output,'materialpoints')
@ -191,13 +190,13 @@ class DADF5():
def get_active_groups(self): # rename: get_groups needed? merge with datasets and have [] and ['*'] def get_active_groups(self): # rename: get_groups needed? merge with datasets and have [] and ['*']
"""Get groups that are currently considered for evaluation.""" """Get groups that are currently considered for evaluation."""
groups = [] groups = []
for i in self.active['increments']: for i in self.visible['increments']:
group_inc = 'inc{:05}'.format(i['inc']) #ToDo: Merge path only once at the end '/'.join(listE) group_inc = 'inc{:05}'.format(i['inc']) #ToDo: Merge path only once at the end '/'.join(listE)
for c in self.active['constituents']: for c in self.visible['constituents']:
for t in self.active['c_output_types']: for t in self.visible['c_output_types']:
groups.append('/'.join([group_inc,'constituent',c,t])) groups.append('/'.join([group_inc,'constituent',c,t]))
for m in self.active['materialpoints']: for m in self.visible['materialpoints']:
for t in self.active['m_output_types']: for t in self.visible['m_output_types']:
groups.append('/'.join([group_inc,'materialpoint',m,t])) groups.append('/'.join([group_inc,'materialpoint',m,t]))
return groups return groups
@ -205,11 +204,11 @@ class DADF5():
def list_data(self): # print_datasets and have [] and ['*'], loop over all increment, soll auf anderen basieren (get groups with sternchen) def list_data(self): # print_datasets and have [] and ['*'], loop over all increment, soll auf anderen basieren (get groups with sternchen)
"""Shows information on all active datasets in the file.""" """Shows information on all active datasets in the file."""
with h5py.File(self.filename,'r') as f: with h5py.File(self.filename,'r') as f:
group_inc = 'inc{:05}'.format(self.active['increments'][0]['inc']) #ToDo: Merge path only once at the end '/'.join(listE) group_inc = 'inc{:05}'.format(self.visible['increments'][0]['inc']) #ToDo: Merge path only once at the end '/'.join(listE)
for c in self.active['constituents']: for c in self.visible['constituents']:
print('\n'+c) print('\n'+c)
group_constituent = group_inc+'/constituent/'+c group_constituent = group_inc+'/constituent/'+c
for t in self.active['c_output_types']: for t in self.visible['c_output_types']:
print(' {}'.format(t)) print(' {}'.format(t))
group_output_types = group_constituent+'/'+t group_output_types = group_constituent+'/'+t
try: try:
@ -217,9 +216,9 @@ class DADF5():
print(' {} ({})'.format(x,f[group_output_types+'/'+x].attrs['Description'].decode())) print(' {} ({})'.format(x,f[group_output_types+'/'+x].attrs['Description'].decode()))
except KeyError: except KeyError:
pass pass
for m in self.active['materialpoints']: for m in self.visible['materialpoints']:
group_materialpoint = group_inc+'/materialpoint/'+m group_materialpoint = group_inc+'/materialpoint/'+m
for t in self.active['m_output_types']: for t in self.visible['m_output_types']:
print(' {}'.format(t)) print(' {}'.format(t))
group_output_types = group_materialpoint+'/'+t group_output_types = group_materialpoint+'/'+t
try: try:
@ -233,11 +232,11 @@ class DADF5():
"""Returns the location of all active datasets with given label.""" #ToDo: Merge path only once at the end '/'.join(listE) """Returns the location of all active datasets with given label.""" #ToDo: Merge path only once at the end '/'.join(listE)
path = [] path = []
with h5py.File(self.filename,'r') as f: with h5py.File(self.filename,'r') as f:
for i in self.active['increments']: for i in self.visible['increments']:
group_inc = 'inc{:05}'.format(i['inc']) group_inc = 'inc{:05}'.format(i['inc'])
for c in self.active['constituents']: for c in self.visible['constituents']:
for t in self.active['c_output_types']: for t in self.visible['c_output_types']:
try: try:
p = '/'.join([group_inc,'constituent',c,t,label]) p = '/'.join([group_inc,'constituent',c,t,label])
f[p] f[p]
@ -245,8 +244,8 @@ class DADF5():
except KeyError as e: except KeyError as e:
print('unable to locate constituents dataset: '+ str(e)) print('unable to locate constituents dataset: '+ str(e))
for m in self.active['materialpoints']: for m in self.visible['materialpoints']:
for t in self.active['m_output_types']: for t in self.visible['m_output_types']:
try: try:
p = '/'.join([group_inc,'materialpoint',m,t,label]) p = '/'.join([group_inc,'materialpoint',m,t,label])
f[p] f[p]