Skip to content

Commit d992a93

Browse files
committed
Merge branch '137-support-for-multiple-homogenization-schemes' into 'development'
Resolve "support for multiple homogenization schemes" Closes #137 See merge request damask/DAMASK!1244
2 parents 4219fcf + f19b113 commit d992a93

4 files changed

Lines changed: 60 additions & 12 deletions

File tree

python/damask/_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def __init__(self, fname: str | PathLike):
201201
self.homogenization = f['cell_to/homogenization']['label'].astype('str')
202202
self._homogenizations = sorted(np.unique(self.homogenization),key=util.natural_sort)
203203
self.phase = f['cell_to/phase']['label'].astype('str')
204-
self._phases = sorted(np.unique(self.phase),key=util.natural_sort)
204+
self._phases = sorted(np.unique(self.phase[self.phase != '']), key=util.natural_sort)
205205

206206
fields = []
207207
for kind, labels in zip(['phase','homogenization'],[self._phases,self._homogenizations]):

src/material.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ subroutine parse()
195195
material_entry_homogenization(ce) = counterHomogenization(ho)
196196
end do
197197

198-
do co = 1, size(ph_of(ma,:)>0)
198+
do co = 1, count(ph_of(ma,:)>0)
199199

200200
v = v_of(ma,co)
201201
ph = ph_of(ma,co)

src/result.f90

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ subroutine result_init(restart)
103103
if (.not. file_exists .or. .not. restart) then
104104
call result_createJobFile()
105105
call result_addAttribute('DADF5_version_major',1)
106-
call result_addAttribute('DADF5_version_minor',3)
106+
call result_addAttribute('DADF5_version_minor',4)
107107
call get_command_argument(0,commandLine)
108108
call result_addAttribute('creator',trim(commandLine)//' '//DAMASK_VERSION)
109109
call result_addAttribute('created',now())
@@ -533,10 +533,11 @@ end subroutine result_writeVectorDataset_int
533533
!--------------------------------------------------------------------------------------------------
534534
subroutine result_mapping_phase(ID,entry,label)
535535

536-
integer, dimension(:,:), intent(in) :: ID !< phase ID at (co,ce)
536+
integer, dimension(:,:), intent(in) :: ID !< phase ID at (co,ce), 0 for padding
537537
integer, dimension(:,:), intent(in) :: entry !< phase entry at (co,ce)
538538
character(len=*), dimension(:), intent(in) :: label !< label of each phase section
539539

540+
character(len=len(label)), dimension(size(ID,1),size(ID,2)) :: labelPadded !< phase string at (co,ce), padded with '' for empty constituents
540541
integer(pI64), dimension(size(entry,1),size(entry,2)) :: entryGlobal
541542
integer(pI64), dimension(size(label),0:worldsize-1) :: entryOffset !< offset in entry counting per process
542543
integer(MPI_INTEGER_KIND), dimension(0:worldsize-1) :: writeSize !< amount of data written per process
@@ -580,15 +581,18 @@ subroutine result_mapping_phase(ID,entry,label)
580581
entryOffset = 0_pI64
581582
do co = 1, size(ID,1)
582583
do ce = 1, size(ID,2)
583-
entryOffset(ID(co,ce),worldrank) = entryOffset(ID(co,ce),worldrank) +1_pI64
584+
if (ID(co,ce) /= 0) &
585+
entryOffset(ID(co,ce),worldrank) = entryOffset(ID(co,ce),worldrank) +1_pI64
584586
end do
585587
end do
586588
call MPI_Allreduce(MPI_IN_PLACE,entryOffset,size(entryOffset),MPI_INTEGER8,MPI_SUM,MPI_COMM_WORLD,err_MPI)! get offset at each process
587589
call parallelization_chkerr(err_MPI)
588590
entryOffset(:,worldrank) = sum(entryOffset(:,0:worldrank-1),2)
591+
entryGlobal = -1_pI64
589592
do co = 1, size(ID,1)
590593
do ce = 1, size(ID,2)
591-
entryGlobal(co,ce) = int(entry(co,ce),pI64) -1_pI64 + entryOffset(ID(co,ce),worldrank)
594+
if (ID(co,ce) /= 0) &
595+
entryGlobal(co,ce) = int(entry(co,ce),pI64) -1_pI64 + entryOffset(ID(co,ce),worldrank)
592596
end do
593597
end do
594598
#endif
@@ -601,7 +605,7 @@ subroutine result_mapping_phase(ID,entry,label)
601605
! compound type: label(ID) + entry
602606
call H5Tcopy_f(H5T_NATIVE_CHARACTER, dt_id, hdferr)
603607
call HDF5_chkerr(hdferr)
604-
call H5Tset_size_f(dt_id, int(len(label(1)),SIZE_T), hdferr)
608+
call H5Tset_size_f(dt_id, int(len(label),SIZE_T), hdferr)
605609
call HDF5_chkerr(hdferr)
606610
call H5Tget_size_f(dt_id, type_size_str, hdferr)
607611
call HDF5_chkerr(hdferr)
@@ -652,10 +656,17 @@ subroutine result_mapping_phase(ID,entry,label)
652656
call H5Dcreate_f(loc_id, 'phase', dtype_id, filespace_id, dset_id, hdferr)
653657
call HDF5_chkerr(hdferr)
654658

655-
call H5Dwrite_f(dset_id, label_id, reshape(label(pack(ID,.true.)),myShape), &
659+
labelPadded = ''
660+
do co = 1, size(ID,1)
661+
do ce = 1, size(ID,2)
662+
if (ID(co,ce) > 0) &
663+
labelPadded(co,ce) = label(ID(co,ce))
664+
end do
665+
end do
666+
call H5Dwrite_f(dset_id, label_id, labelPadded, &
656667
myShape, hdferr, file_space_id = filespace_id, mem_space_id = memspace_id, xfer_prp = plist_id)
657668
call HDF5_chkerr(hdferr)
658-
call H5Dwrite_f(dset_id, entry_id, reshape(pack(entryGlobal,.true.),myShape), &
669+
call H5Dwrite_f(dset_id, entry_id, entryGlobal, &
659670
myShape, hdferr, file_space_id = filespace_id, mem_space_id = memspace_id, xfer_prp = plist_id)
660671
call HDF5_chkerr(hdferr)
661672

@@ -750,7 +761,7 @@ subroutine result_mapping_homogenization(ID,entry,label)
750761
! compound type: label(ID) + entry
751762
call H5Tcopy_f(H5T_NATIVE_CHARACTER, dt_id, hdferr)
752763
call HDF5_chkerr(hdferr)
753-
call H5Tset_size_f(dt_id, int(len(label(1)),SIZE_T), hdferr)
764+
call H5Tset_size_f(dt_id, int(len(label),SIZE_T), hdferr)
754765
call HDF5_chkerr(hdferr)
755766
call H5Tget_size_f(dt_id, type_size_str, hdferr)
756767
call HDF5_chkerr(hdferr)
@@ -801,10 +812,10 @@ subroutine result_mapping_homogenization(ID,entry,label)
801812
call H5Dcreate_f(loc_id, 'homogenization', dtype_id, filespace_id, dset_id, hdferr)
802813
call HDF5_chkerr(hdferr)
803814

804-
call H5Dwrite_f(dset_id, label_id, reshape(label(pack(ID,.true.)),myShape), &
815+
call H5Dwrite_f(dset_id, label_id, label(ID), &
805816
myShape, hdferr, file_space_id = filespace_id, mem_space_id = memspace_id, xfer_prp = plist_id)
806817
call HDF5_chkerr(hdferr)
807-
call H5Dwrite_f(dset_id, entry_id, reshape(pack(entryGlobal,.true.),myShape), &
818+
call H5Dwrite_f(dset_id, entry_id, entryGlobal, &
808819
myShape, hdferr, file_space_id = filespace_id, mem_space_id = memspace_id, xfer_prp = plist_id)
809820
call HDF5_chkerr(hdferr)
810821

tests/integration/test_homogenization.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: AGPL-3.0-or-later
22
import copy
33

4+
import h5py
45
import pytest
56
import numpy as np
67

@@ -60,6 +61,42 @@ def test_homogenization_equivalent(res_path,tmp_path,copy_files,phase,homogeniza
6061
0.99 < results[phase]['P']/P_11 < 1.01
6162

6263

64+
def test_multiple_homogenization_schemes_and_constituent_numbers(res_path,tmp_path,copy_files,np_rng):
65+
copy_files(res_path,tmp_path)
66+
67+
load = 'compressionX'
68+
material = 'material'
69+
job = f'combined_{load}'
70+
71+
schemes = ['RGC','none','Taylor2','RGC']
72+
damask.GeomGrid(np.arange(len(schemes)).reshape(len(schemes),1,1),
73+
np.array([len(schemes),1,1])*1e-4).save(tmp_path/'combined.vti')
74+
75+
material_config = damask.ConfigMaterial.load(tmp_path/f'{material}.yaml')
76+
N_constituents = [material_config['homogenization'][ho]['N_constituents'] for ho in schemes]
77+
assert len(set(N_constituents)) > 1 # make sure we also test different numbers of constituents
78+
O = damask.Rotation.from_random((len(schemes),max(N_constituents)),rng_seed=np_rng)
79+
material_config['material'] = [
80+
dict(homogenization=ho,
81+
constituents=[
82+
dict(phase='Isotropic' if ho=='none' or (ho=='Taylor2' and co==0) else 'Phenopowerlaw',
83+
v=1/N,
84+
O=O[ma,co].as_quaternion().tolist()
85+
) for co in range(N)]
86+
) for ma,(ho,N) in enumerate(zip(schemes,N_constituents))]
87+
material_config.save(tmp_path/f'{material}.yaml')
88+
89+
damask.util.run(f'damask_grid -l {load}.yaml -g combined.vti -m {material}.yaml -j {job}',
90+
wd=tmp_path)
91+
result = damask.Result(tmp_path/f'{job}.hdf5')
92+
assert result.phases == ['Isotropic', 'Phenopowerlaw']
93+
with h5py.File(tmp_path/f'{job}.hdf5','r') as f:
94+
label = f['cell_to/phase']['label'][()].astype(str)
95+
entry = f['cell_to/phase']['entry'][()]
96+
97+
assert np.array_equal(np.sum(label != '',axis=1),N_constituents)
98+
assert np.all(entry[label == ''] == -1)
99+
63100
def test_homogenization_many(tmp_path,res_path,copy_files,np_rng):
64101
grid = damask.GeomGrid(np.zeros([2,1,1],int),np.array([2,1,1])*1e-4)
65102
grid.save(tmp_path/'small')

0 commit comments

Comments
 (0)