removed aliases

required bump of DADF5 version
This commit is contained in:
Martin Diehl 2020-11-18 14:52:16 +01:00
parent a0b6c2690b
commit 870c0f7aca
9 changed files with 85 additions and 106 deletions

View File

@ -20,9 +20,9 @@ parser.add_argument('filenames', nargs='+',
parser.add_argument('-d','--dir', dest='dir',default='postProc',metavar='string',
help='name of subdirectory relative to the location of the DADF5 file to hold output')
parser.add_argument('--mat', nargs='+',
help='labels for materialpoint',dest='mat')
help='labels for homogenization',dest='mat')
parser.add_argument('--con', nargs='+',
help='labels for constituent',dest='con')
help='labels for phase',dest='con')
options = parser.parse_args()
@ -41,15 +41,15 @@ for filename in options.filenames:
table = damask.Table(np.ones(np.product(results.grid),dtype=int)*int(inc[3:]),{'inc':(1,)})\
.add('pos',coords.reshape(-1,3))
results.pick('materialpoints',False)
results.pick('constituents', True)
results.pick('homogenizations',False)
results.pick('phases',True)
for label in options.con:
x = results.get_dataset_location(label)
if len(x) != 0:
table = table.add(label,results.read_dataset(x,0,plain=True).reshape(results.grid.prod(),-1))
results.pick('constituents', False)
results.pick('materialpoints',True)
results.pick('phases',False)
results.pick('homogenizations',True)
for label in options.mat:
x = results.get_dataset_location(label)
if len(x) != 0:

View File

@ -41,14 +41,10 @@ class Result:
"""
with h5py.File(fname,'r') as f:
try:
self.version_major = f.attrs['DADF5_version_major']
self.version_minor = f.attrs['DADF5_version_minor']
except KeyError:
self.version_major = f.attrs['DADF5-major']
self.version_minor = f.attrs['DADF5-minor']
if self.version_major != 0 or not 2 <= self.version_minor <= 7:
if self.version_major != 0 or not 7 <= self.version_minor <= 8:
raise TypeError(f'Unsupported DADF5 version {self.version_major}.{self.version_minor}')
self.structured = 'grid' in f['geometry'].attrs.keys()
@ -56,35 +52,33 @@ class Result:
if self.structured:
self.grid = f['geometry'].attrs['grid']
self.size = f['geometry'].attrs['size']
self.origin = f['geometry'].attrs['origin'] if self.version_major == 0 and self.version_minor >= 5 else \
np.zeros(3)
self.origin = f['geometry'].attrs['origin']
r=re.compile('inc[0-9]+')
increments_unsorted = {int(i[3:]):i for i in f.keys() if r.match(i)}
self.increments = [increments_unsorted[i] for i in sorted(increments_unsorted)]
self.times = [round(f[i].attrs['time/s'],12) for i in self.increments]
self.Nmaterialpoints, self.Nconstituents = np.shape(f['mapping/cellResults/constituent'])
self.materialpoints = [m.decode() for m in np.unique(f['mapping/cellResults/materialpoint']['Name'])]
self.constituents = [c.decode() for c in np.unique(f['mapping/cellResults/constituent'] ['Name'])]
self.N_materialpoints, self.N_constituents = np.shape(f['mapping/phase'])
# faster, but does not work with (deprecated) DADF5_postResults
#self.materialpoints = [m for m in f['inc0/materialpoint']]
#self.constituents = [c for c in f['inc0/constituent']]
self.homogenizations = [m.decode() for m in np.unique(f['mapping/homogenization']['Name'])]
self.phases = [c.decode() for c in np.unique(f['mapping/phase']['Name'])]
self.con_physics = []
for c in self.constituents:
self.con_physics += f['/'.join([self.increments[0],'constituent',c])].keys()
self.con_physics = list(set(self.con_physics)) # make unique
self.out_type_ph = []
for c in self.phases:
self.out_type_ph += f['/'.join([self.increments[0],'phase',c])].keys()
self.out_type_ph = list(set(self.out_type_ph)) # make unique
self.mat_physics = []
for m in self.materialpoints:
self.mat_physics += f['/'.join([self.increments[0],'materialpoint',m])].keys()
self.mat_physics = list(set(self.mat_physics)) # make unique
self.out_type_ho = []
for m in self.homogenizations:
self.out_type_ho += f['/'.join([self.increments[0],'homogenization',m])].keys()
self.out_type_ho = list(set(self.out_type_ho)) # make unique
self.selection = {'increments': self.increments,
'constituents': self.constituents,'materialpoints': self.materialpoints,
'con_physics': self.con_physics, 'mat_physics': self.mat_physics
'phases': self.phases,
'homogenizations': self.homogenizations,
'out_type_ph': self.out_type_ph,
'out_type_ho': self.out_type_ho
}
self.fname = Path(fname).absolute()
@ -295,16 +289,16 @@ class Result:
Must not mix nodal end cell data.
Only data within
- inc?????/constituent/*_*/*
- inc?????/materialpoint/*_*/*
- inc?????/geometry/*
- inc*/phase/*/*
- inc*/homogenization/*/*
- inc*/geometry/*
are considered.
Parameters
----------
datasets : iterable or str
component : int
homogenization component to consider for constituent data
Constituent to consider for phase data
tagged : bool
tag Table.column name with '#component'
defaults to False
@ -313,8 +307,8 @@ class Result:
defaults to True
"""
sets = datasets if hasattr(datasets,'__iter__') and not isinstance(datasets,str) \
else [datasets]
sets = datasets if hasattr(datasets,'__iter__') and not isinstance(datasets,str) else \
[datasets]
tag = f'#{component}' if tagged else ''
tbl = {} if split else None
inGeom = {}
@ -327,15 +321,15 @@ class Result:
key = '/'.join([prop,name+tag])
if key not in inGeom:
if prop == 'geometry':
inGeom[key] = inData[key] = np.arange(self.Nmaterialpoints)
elif prop == 'constituent':
inGeom[key] = np.where(f['mapping/cellResults/constituent'][:,component]['Name'] == str.encode(name))[0]
inData[key] = f['mapping/cellResults/constituent'][inGeom[key],component]['Position']
else:
inGeom[key] = np.where(f['mapping/cellResults/materialpoint']['Name'] == str.encode(name))[0]
inData[key] = f['mapping/cellResults/materialpoint'][inGeom[key].tolist()]['Position']
inGeom[key] = inData[key] = np.arange(self.N_materialpoints)
elif prop == 'phase':
inGeom[key] = np.where(f['mapping/phase'][:,component]['Name'] == str.encode(name))[0]
inData[key] = f['mapping/phase'][inGeom[key],component]['Position']
elif prop == 'homogenization':
inGeom[key] = np.where(f['mapping/homogenization']['Name'] == str.encode(name))[0]
inData[key] = f['mapping/homogenization'][inGeom[key].tolist()]['Position']
shape = np.shape(f[path])
data = np.full((self.Nmaterialpoints,) + (shape[1:] if len(shape)>1 else (1,)),
data = np.full((self.N_materialpoints,) + (shape[1:] if len(shape)>1 else (1,)),
np.nan,
dtype=np.dtype(f[path]))
data[inGeom[key]] = (f[path] if len(shape)>1 else np.expand_dims(f[path],1))[inData[key]]
@ -344,12 +338,12 @@ class Result:
try:
tbl[inc].add(path,data)
except KeyError:
tbl[inc] = Table(data.reshape(self.Nmaterialpoints,-1),{path:data.shape[1:]})
tbl[inc] = Table(data.reshape(self.N_materialpoints,-1),{path:data.shape[1:]})
else:
try:
tbl.add(path,data)
except AttributeError:
tbl = Table(data.reshape(self.Nmaterialpoints,-1),{path:data.shape[1:]})
tbl = Table(data.reshape(self.N_materialpoints,-1),{path:data.shape[1:]})
return tbl
@ -359,8 +353,8 @@ class Result:
Return groups that contain all requested datasets.
Only groups within
- inc*/constituent/*/*
- inc*/materialpoint/*/*
- inc*/phase/*/*
- inc*/homogenization/*/*
- inc*/geometry/*
are considered as they contain user-relevant data.
@ -392,7 +386,7 @@ class Result:
with h5py.File(self.fname,'r') as f:
for i in self.iterate('increments'):
for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']):
for o,p in zip(['phases','homogenizations'],['out_type_ph','out_type_ho']):
for oo in self.iterate(o):
for pp in self.iterate(p):
group = '/'.join([i,o[:-1],oo,pp]) # o[:-1]: plural/singular issue
@ -411,7 +405,7 @@ class Result:
with h5py.File(self.fname,'r') as f:
for i in self.iterate('increments'):
message += f'\n{i} ({self.times[self.increments.index(i)]}s)\n'
for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']):
for o,p in zip(['phases','homogenizations'],['out_type_ph','out_type_ho']):
message += f' {o[:-1]}\n'
for oo in self.iterate(o):
message += f' {oo}\n'
@ -445,7 +439,7 @@ class Result:
path.append(k)
except KeyError:
pass
for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']):
for o,p in zip(['phases','homogenizations'],['out_type_ph','out_type_ho']):
for oo in self.iterate(o):
for pp in self.iterate(p):
k = '/'.join([i,o[:-1],oo,pp,label])
@ -460,7 +454,7 @@ class Result:
def get_constituent_ID(self,c=0):
"""Pointwise constituent ID."""
with h5py.File(self.fname,'r') as f:
names = f['/mapping/cellResults/constituent']['Name'][:,c].astype('str')
names = f['/mapping/phase']['Name'][:,c].astype('str')
return np.array([int(n.split('_')[0]) for n in names.tolist()],dtype=np.int32)
@ -483,7 +477,7 @@ class Result:
If more than one path is given, the dataset is composed of the individual contributions.
"""
with h5py.File(self.fname,'r') as f:
shape = (self.Nmaterialpoints,) + np.shape(f[path[0]])[1:]
shape = (self.N_materialpoints,) + np.shape(f[path[0]])[1:]
if len(shape) == 1: shape = shape +(1,)
dataset = np.full(shape,np.nan,dtype=np.dtype(f[path[0]]))
for pa in path:
@ -493,17 +487,17 @@ class Result:
dataset = np.array(f[pa])
continue
p = np.where(f['mapping/cellResults/constituent'][:,c]['Name'] == str.encode(label))[0]
p = np.where(f['mapping/phase'][:,c]['Name'] == str.encode(label))[0]
if len(p)>0:
u = (f['mapping/cellResults/constituent']['Position'][p,c])
u = (f['mapping/phase']['Position'][p,c])
a = np.array(f[pa])
if len(a.shape) == 1:
a=a.reshape([a.shape[0],1])
dataset[p,:] = a[u,:]
p = np.where(f['mapping/cellResults/materialpoint']['Name'] == str.encode(label))[0]
p = np.where(f['mapping/homogenization']['Name'] == str.encode(label))[0]
if len(p)>0:
u = (f['mapping/cellResults/materialpoint']['Position'][p.tolist()])
u = (f['mapping/homogenization']['Position'][p.tolist()])
a = np.array(f[pa])
if len(a.shape) == 1:
a=a.reshape([a.shape[0],1])
@ -1132,7 +1126,7 @@ class Result:
This works only for scalar, 3-vector and 3x3-tensor data.
Selection is not taken into account.
"""
if len(self.constituents) != 1 or not self.structured:
if self.N_constituents != 1 or not self.structured:
raise NotImplementedError('XDMF only available for grid results with 1 constituent.')
xdmf=ET.Element('Xdmf')
@ -1194,7 +1188,7 @@ class Result:
'Dimensions': '{} {} {} 3'.format(*(self.grid+1))}
data_items[-1].text=f'{os.path.split(self.fname)[1]}:/{inc}/geometry/u_n'
for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']):
for o,p in zip(['phases','homogenizations'],['out_type_ph','out_type_ho']):
for oo in getattr(self,o):
for pp in getattr(self,p):
g = '/'.join([inc,o[:-1],oo,pp])
@ -1250,12 +1244,12 @@ class Result:
for inc in util.show_progress(self.iterate('increments'),len(self.selection['increments'])):
materialpoints_backup = self.selection['materialpoints'].copy()
self.pick('materialpoints',False)
picked_backup_ho = self.selection['homogenizations'].copy()
self.pick('homogenizations',False)
for label in (labels if isinstance(labels,list) else [labels]):
for p in self.iterate('con_physics'):
for p in self.iterate('out_type_ph'):
if p != 'generic':
for c in self.iterate('constituents'):
for c in self.iterate('phases'):
x = self.get_dataset_location(label)
if len(x) == 0:
continue
@ -1266,17 +1260,17 @@ class Result:
if len(x) == 0:
continue
array = self.read_dataset(x,0)
ph_name = re.compile(r'(?<=(constituent\/))(.*?)(?=(generic))') # identify phase name
ph_name = re.compile(r'(?<=(phase\/))(.*?)(?=(generic))') # identify phase name
dset_name = '1_' + re.sub(ph_name,r'',x[0].split('/',1)[1]) # removing phase name
v.add(array,dset_name)
self.pick('materialpoints',materialpoints_backup)
self.pick('homogenizations',picked_backup_ho)
constituents_backup = self.selection['constituents'].copy()
self.pick('constituents',False)
picked_backup_ph = self.selection['phases'].copy()
self.pick('phases',False)
for label in (labels if isinstance(labels,list) else [labels]):
for p in self.iterate('mat_physics'):
for p in self.iterate('out_type_ho'):
if p != 'generic':
for m in self.iterate('materialpoints'):
for m in self.iterate('homogenizations'):
x = self.get_dataset_location(label)
if len(x) == 0:
continue
@ -1288,7 +1282,7 @@ class Result:
continue
array = self.read_dataset(x,0)
v.add(array,'1_'+x[0].split('/',1)[1])
self.pick('constituents',constituents_backup)
self.pick('phases',picked_backup_ph)
u = self.read_dataset(self.get_dataset_location('u_n' if mode.lower() == 'cell' else 'u_p'))
v.add(u,'u')

View File

@ -58,7 +58,7 @@ class TestResult:
f = default.get_dataset_location('F')
assert a == b == c == d == e ==f
@pytest.mark.parametrize('what',['increments','times','constituents']) # ToDo: discuss materialpoints
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
def test_pick_none(self,default,what):
default.pick(what,False)
a = default.get_dataset_location('F')
@ -67,7 +67,7 @@ class TestResult:
assert a == b == []
@pytest.mark.parametrize('what',['increments','times','constituents']) # ToDo: discuss materialpoints
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
def test_pick_more(self,default,what):
default.pick(what,False)
default.pick_more(what,'*')
@ -78,7 +78,7 @@ class TestResult:
assert a == b
@pytest.mark.parametrize('what',['increments','times','constituents']) # ToDo: discuss materialpoints
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
def test_pick_less(self,default,what):
default.pick(what,True)
default.pick_less(what,'*')

View File

@ -225,7 +225,7 @@ module subroutine damage_results
do p = 1, size(material_name_phase)
sourceLoop: do i = 1, phase_Nsources(p)
group = trim('current/constituent')//'/'//trim(material_name_phase(p))
group = trim('current/phase')//'/'//trim(material_name_phase(p))
group = trim(group)//'/sources'
call results_closeGroup(results_addGroup(group))

View File

@ -457,7 +457,7 @@ module subroutine plastic_results
character(len=pStringLen) :: group
plasticityLoop: do p=1,size(material_name_phase)
group = trim('current/constituent')//'/'//trim(material_name_phase(p))
group = trim('current/phase')//'/'//trim(material_name_phase(p))
call results_closeGroup(results_addGroup(group))
group = trim(group)//'/plastic'

View File

@ -739,7 +739,7 @@ subroutine crystallite_results
character(len=:), allocatable :: group,structureLabel
do p=1,size(material_name_phase)
group = trim('current/constituent')//'/'//trim(material_name_phase(p))//'/mechanics'
group = trim('current/phase')//'/'//trim(material_name_phase(p))//'/mechanics'
call results_closeGroup(results_addGroup(group))
@ -772,11 +772,11 @@ subroutine crystallite_results
case('P')
selected_tensors = select_tensors(crystallite_P,p)
call results_writeDataset(group,selected_tensors,output_constituent(p)%label(o),&
'First Piola-Kirchoff stress','Pa')
'First Piola-Kirchhoff stress','Pa')
case('S')
selected_tensors = select_tensors(crystallite_S,p)
call results_writeDataset(group,selected_tensors,output_constituent(p)%label(o),&
'Second Piola-Kirchoff stress','Pa')
'Second Piola-Kirchhoff stress','Pa')
case('O')
select case(lattice_structure(p))
case(lattice_ISO_ID)
@ -1553,16 +1553,16 @@ subroutine crystallite_restartWrite
call HDF5_write(fileHandle,crystallite_Li, 'L_i')
call HDF5_write(fileHandle,crystallite_S, 'S')
groupHandle = HDF5_addGroup(fileHandle,'constituent')
groupHandle = HDF5_addGroup(fileHandle,'phase')
do i = 1,size(material_name_phase)
write(datasetName,'(i0,a)') i,'_omega_plastic'
write(datasetName,'(i0,a)') i,'_omega'
call HDF5_write(groupHandle,plasticState(i)%state,datasetName)
enddo
call HDF5_closeGroup(groupHandle)
groupHandle = HDF5_addGroup(fileHandle,'materialpoint')
groupHandle = HDF5_addGroup(fileHandle,'homogenization')
do i = 1, size(material_name_homogenization)
write(datasetName,'(i0,a)') i,'_omega_homogenization'
write(datasetName,'(i0,a)') i,'_omega'
call HDF5_write(groupHandle,homogState(i)%state,datasetName)
enddo
call HDF5_closeGroup(groupHandle)
@ -1594,16 +1594,16 @@ subroutine crystallite_restartRead
call HDF5_read(fileHandle,crystallite_Li0,'L_i')
call HDF5_read(fileHandle,crystallite_S0, 'S')
groupHandle = HDF5_openGroup(fileHandle,'constituent')
groupHandle = HDF5_openGroup(fileHandle,'phase')
do i = 1,size(material_name_phase)
write(datasetName,'(i0,a)') i,'_omega_plastic'
write(datasetName,'(i0,a)') i,'_omega'
call HDF5_read(groupHandle,plasticState(i)%state0,datasetName)
enddo
call HDF5_closeGroup(groupHandle)
groupHandle = HDF5_openGroup(fileHandle,'materialpoint')
groupHandle = HDF5_openGroup(fileHandle,'homogenization')
do i = 1,size(material_name_homogenization)
write(datasetName,'(i0,a)') i,'_omega_homogenization'
write(datasetName,'(i0,a)') i,'_omega'
call HDF5_read(groupHandle,homogState(i)%state0,datasetName)
enddo
call HDF5_closeGroup(groupHandle)

View File

@ -534,7 +534,7 @@ subroutine homogenization_results
!real(pReal), dimension(:,:,:), allocatable :: temp
do p=1,size(material_name_homogenization)
group_base = 'current/materialpoint/'//trim(material_name_homogenization(p))
group_base = 'current/homogenization/'//trim(material_name_homogenization(p))
call results_closeGroup(results_addGroup(group_base))
group = trim(group_base)//'/generic'

View File

@ -395,12 +395,10 @@ function getKeys(dict)
character(len=pStringLen), dimension(:), allocatable :: getKeys
integer :: i
character(len=pStringLen) :: sectionName
allocate(getKeys(dict%length))
do i=1, dict%length
write(sectionName,'(i0,a)') i,'_'
getKeys(i) = trim(adjustl(sectionName))//dict%getKey(i) !ToDo: remove prefix
getKeys(i) = dict%getKey(i)
enddo
end function getKeys

View File

@ -74,12 +74,11 @@ subroutine results_init(restart)
if(.not. restart) then
resultsFile = HDF5_openFile(trim(getSolverJobName())//'.hdf5','w',.true.)
call results_addAttribute('DADF5_version_major',0)
call results_addAttribute('DADF5_version_minor',7)
call results_addAttribute('DADF5_version_minor',8)
call results_addAttribute('DAMASK_version',DAMASKVERSION)
call get_command(commandLine)
call results_addAttribute('call',trim(commandLine))
call results_closeGroup(results_addGroup('mapping'))
call results_closeGroup(results_addGroup('mapping/cellResults'))
call results_closeJobFile
endif
@ -122,12 +121,6 @@ subroutine results_addIncrement(inc,time)
call results_closeGroup(results_addGroup('current/phase'))
call results_closeGroup(results_addGroup('current/homogenization'))
! for backward compatibility
call results_setLink(trim('/inc'//trim(adjustl(incChar)))//'/phase',&
trim('/inc'//trim(adjustl(incChar)))//'/constituent')
call results_setLink(trim('/inc'//trim(adjustl(incChar)))//'/homogenization',&
trim('/inc'//trim(adjustl(incChar)))//'/materialpoint')
end subroutine results_addIncrement
@ -656,9 +649,6 @@ subroutine results_mapping_constituent(phaseAt,memberAtLocal,label)
if(hdferr < 0) error stop 'HDF5 error'
call h5tclose_f(position_id, hdferr)
! for backward compatibility
call results_setLink('/mapping/phase','/mapping/cellResults/constituent')
end subroutine results_mapping_constituent
@ -814,9 +804,6 @@ subroutine results_mapping_homogenization(homogenizationAt,memberAtLocal,label)
call h5tclose_f(position_id, hdferr)
if(hdferr < 0) error stop 'HDF5 error'
! for backward compatibility
call results_setLink('/mapping/homogenization','/mapping/cellResults/materialpoint')
end subroutine results_mapping_homogenization