From 102d1b79959d9110fea89a5a5e0b731cca4e9802 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 9 Jan 2023 23:38:51 +0100 Subject: [PATCH 1/8] avoid failing tests stiffness matrices should have non-zero diagonal entries, for this situation the implemented functionality works as expected --- src/lattice.f90 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lattice.f90 b/src/lattice.f90 index 107ea27fc..beded840b 100644 --- a/src/lattice.f90 +++ b/src/lattice.f90 @@ -405,13 +405,13 @@ module lattice contains !-------------------------------------------------------------------------------------------------- -!> @brief Module initialization +!> @brief Run self test. !-------------------------------------------------------------------------------------------------- -subroutine lattice_init +subroutine lattice_init() print'(/,1x,a)', '<<<+- lattice init -+>>>'; flush(IO_STDOUT) - call selfTest + call selfTest() end subroutine lattice_init @@ -2330,14 +2330,14 @@ subroutine selfTest lattice_isotropic_nu(C_tI,'isostress','tI'),1.0e-12_pReal)) error stop 'isotropic_nu/isostress/tI' call random_number(C) - C = lattice_symmetrize_C66(C,'cI') - if (dNeq(lattice_isotropic_mu(C,'isostrain','cI'), lattice_isotropic_mu(C,'isostrain','hP'), 5.0e-9_pReal)) & + C = lattice_symmetrize_C66(C+math_eye(6),'cI') + if (dNeq(lattice_isotropic_mu(C,'isostrain','cI'), lattice_isotropic_mu(C,'isostrain','hP'), 1.0e-12_pReal)) & error stop 'isotropic_mu/isostrain/cI-hP' - if (dNeq(lattice_isotropic_nu(C,'isostrain','cF'), lattice_isotropic_nu(C,'isostrain','cI'), 5.0e-9_pReal)) & + if (dNeq(lattice_isotropic_nu(C,'isostrain','cF'), lattice_isotropic_nu(C,'isostrain','cI'), 1.0e-12_pReal)) & error stop 'isotropic_nu/isostrain/cF-tI' - if (dNeq(lattice_isotropic_mu(C,'isostress','cI'), lattice_isotropic_mu(C,'isostress'), 5.0e-9_pReal)) & + if (dNeq(lattice_isotropic_mu(C,'isostress','cI'), lattice_isotropic_mu(C,'isostress'), 1.0e-12_pReal)) & error stop 'isotropic_mu/isostress/cI-hP' - if (dNeq(lattice_isotropic_nu(C,'isostress','cF'), lattice_isotropic_nu(C,'isostress'), 5.0e-9_pReal)) & + if (dNeq(lattice_isotropic_nu(C,'isostress','cF'), lattice_isotropic_nu(C,'isostress'), 1.0e-12_pReal)) & error stop 'isotropic_nu/isostress/cF-tI' end subroutine selfTest From 7b6abafbb78e5c1aa6a5b31663a9e2f874cf6a34 Mon Sep 17 00:00:00 2001 From: Sharan Date: Tue, 10 Jan 2023 01:09:57 +0100 Subject: [PATCH 2/8] store data directly in HDF5 --- src/grid/grid_mech_spectral_basic.f90 | 19 +++++++--------- src/grid/grid_mech_spectral_polarisation.f90 | 18 +++++++-------- src/grid/spectral_utilities.f90 | 24 +------------------- 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/src/grid/grid_mech_spectral_basic.f90 b/src/grid/grid_mech_spectral_basic.f90 index e337376ca..6f5a85815 100644 --- a/src/grid/grid_mech_spectral_basic.f90 +++ b/src/grid/grid_mech_spectral_basic.f90 @@ -77,6 +77,7 @@ module grid_mechanical_spectral_basic C_volAvgLastInc = 0.0_pReal, & !< previous volume average stiffness C_minMaxAvg = 0.0_pReal, & !< current (min+max)/2 stiffness C_minMaxAvgLastInc = 0.0_pReal, & !< previous (min+max)/2 stiffness + C_minMaxAvgRestart = 0.0_pReal, & !< (min+max)/2 stiffnes (restart) S = 0.0_pReal !< current compliance (filled up with zeros) real(pReal) :: & @@ -256,21 +257,17 @@ subroutine grid_mechanical_spectral_basic_init() call HDF5_read(C_volAvgLastInc,groupHandle,'C_volAvgLastInc',.false.) call MPI_Bcast(C_volAvgLastInc,81_MPI_INTEGER_KIND,MPI_DOUBLE,0_MPI_INTEGER_KIND,MPI_COMM_WORLD,err_MPI) if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' + call HDF5_read(C_minMaxAvg,groupHandle,'C_minMaxAvg',.false.) + call MPI_Bcast(C_minMaxAvg,81_MPI_INTEGER_KIND,MPI_DOUBLE,0_MPI_INTEGER_KIND,MPI_COMM_WORLD,err_MPI) + if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' call HDF5_closeGroup(groupHandle) call HDF5_closeFile(fileHandle) - call MPI_File_open(MPI_COMM_WORLD, trim(getSolverJobName())//'.C_ref', & - MPI_MODE_RDONLY,MPI_INFO_NULL,fileUnit,err_MPI) - if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' - call MPI_File_read(fileUnit,C_minMaxAvg,81_MPI_INTEGER_KIND,MPI_DOUBLE,status,err_MPI) - if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' - call MPI_File_close(fileUnit,err_MPI) - if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' end if restartRead2 call utilities_updateGamma(C_minMaxAvg) - call utilities_saveReferenceStiffness + C_minMaxAvgRestart = C_minMaxAvg end subroutine grid_mechanical_spectral_basic_init @@ -420,6 +417,8 @@ subroutine grid_mechanical_spectral_basic_restartWrite call DMDAVecGetArrayF90(da,solution_vec,F,err_PETSc) CHKERRQ(err_PETSc) + if (num%update_gamma) C_minMaxAvgRestart = C_minMaxAvg + print'(1x,a)', 'writing solver data required for restart to file'; flush(IO_STDOUT) fileHandle = HDF5_openFile(getSolverJobName()//'_restart.hdf5','w') @@ -438,13 +437,11 @@ subroutine grid_mechanical_spectral_basic_restartWrite call HDF5_write(F_aimDot,groupHandle,'F_aimDot',.false.) call HDF5_write(C_volAvg,groupHandle,'C_volAvg',.false.) call HDF5_write(C_volAvgLastInc,groupHandle,'C_volAvgLastInc',.false.) - call HDF5_write(C_minMaxAvg,groupHandle,'C_minMaxAvg',.false.) + call HDF5_write(C_minMaxAvgRestart,groupHandle,'C_minMaxAvg',.false.) call HDF5_closeGroup(groupHandle) call HDF5_closeFile(fileHandle) end if - if (num%update_gamma) call utilities_saveReferenceStiffness - call DMDAVecRestoreArrayF90(da,solution_vec,F,err_PETSc) CHKERRQ(err_PETSc) diff --git a/src/grid/grid_mech_spectral_polarisation.f90 b/src/grid/grid_mech_spectral_polarisation.f90 index bac8696ab..52b20dfbd 100644 --- a/src/grid/grid_mech_spectral_polarisation.f90 +++ b/src/grid/grid_mech_spectral_polarisation.f90 @@ -85,6 +85,7 @@ module grid_mechanical_spectral_polarisation C_volAvgLastInc = 0.0_pReal, & !< previous volume average stiffness C_minMaxAvg = 0.0_pReal, & !< current (min+max)/2 stiffness C_minMaxAvgLastInc = 0.0_pReal, & !< previous (min+max)/2 stiffness + C_minMaxAvgRestart = 0.0_pReal, & !< (min+max)/2 stiffnes (restart) S = 0.0_pReal, & !< current compliance (filled up with zeros) C_scale = 0.0_pReal, & S_scale = 0.0_pReal @@ -283,21 +284,17 @@ subroutine grid_mechanical_spectral_polarisation_init() call HDF5_read(C_volAvgLastInc,groupHandle,'C_volAvgLastInc',.false.) call MPI_Bcast(C_volAvgLastInc,81_MPI_INTEGER_KIND,MPI_DOUBLE,0_MPI_INTEGER_KIND,MPI_COMM_WORLD,err_MPI) if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' + call HDF5_read(C_minMaxAvg,groupHandle,'C_minMaxAvg',.false.) + call MPI_Bcast(C_minMaxAvg,81_MPI_INTEGER_KIND,MPI_DOUBLE,0_MPI_INTEGER_KIND,MPI_COMM_WORLD,err_MPI) + if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' call HDF5_closeGroup(groupHandle) call HDF5_closeFile(fileHandle) - call MPI_File_open(MPI_COMM_WORLD, trim(getSolverJobName())//'.C_ref', & - MPI_MODE_RDONLY,MPI_INFO_NULL,fileUnit,err_MPI) - if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' - call MPI_File_read(fileUnit,C_minMaxAvg,81_MPI_INTEGER_KIND,MPI_DOUBLE,status,err_MPI) - if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' - call MPI_File_close(fileUnit,err_MPI) - if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error' end if restartRead2 call utilities_updateGamma(C_minMaxAvg) - call utilities_saveReferenceStiffness + C_minMaxAvgRestart = C_minMaxAvg C_scale = C_minMaxAvg S_scale = math_invSym3333(C_minMaxAvg) @@ -477,6 +474,8 @@ subroutine grid_mechanical_spectral_polarisation_restartWrite F => FandF_tau(0: 8,:,:,:) F_tau => FandF_tau(9:17,:,:,:) + if (num%update_gamma) C_minMaxAvgRestart = C_minMaxAvg + print'(1x,a)', 'writing solver data required for restart to file'; flush(IO_STDOUT) fileHandle = HDF5_openFile(getSolverJobName()//'_restart.hdf5','w') @@ -497,12 +496,11 @@ subroutine grid_mechanical_spectral_polarisation_restartWrite call HDF5_write(F_aimDot,groupHandle,'F_aimDot',.false.) call HDF5_write(C_volAvg,groupHandle,'C_volAvg',.false.) call HDF5_write(C_volAvgLastInc,groupHandle,'C_volAvgLastInc',.false.) + call HDF5_write(C_minMaxAvgRestart,groupHandle,'C_minMaxAvg',.false.) call HDF5_closeGroup(groupHandle) call HDF5_closeFile(fileHandle) end if - if (num%update_gamma) call utilities_saveReferenceStiffness - call DMDAVecRestoreArrayF90(da,solution_vec,FandF_tau,err_PETSc) CHKERRQ(err_PETSc) diff --git a/src/grid/spectral_utilities.f90 b/src/grid/spectral_utilities.f90 index 22325c479..8fe62012b 100644 --- a/src/grid/spectral_utilities.f90 +++ b/src/grid/spectral_utilities.f90 @@ -126,8 +126,7 @@ module spectral_utilities utilities_constitutiveResponse, & utilities_calculateRate, & utilities_forwardField, & - utilities_updateCoords, & - utilities_saveReferenceStiffness + utilities_updateCoords contains @@ -1098,27 +1097,6 @@ subroutine utilities_updateCoords(F) end subroutine utilities_updateCoords -!--------------------------------------------------------------------------------------------------- -!> @brief Write out the current reference stiffness for restart. -!--------------------------------------------------------------------------------------------------- -subroutine utilities_saveReferenceStiffness() - - integer :: & - fileUnit,ierr - - - if (worldrank == 0) then - print'(/,1x,a)', '... writing reference stiffness data required for restart to file .........'; flush(IO_STDOUT) - open(newunit=fileUnit, file=getSolverJobName()//'.C_ref',& - status='replace',access='stream',action='write',iostat=ierr) - if (ierr /=0) call IO_error(100,ext_msg='could not open file '//getSolverJobName()//'.C_ref') - write(fileUnit) C_ref*wgt - close(fileUnit) - end if - -end subroutine utilities_saveReferenceStiffness - - !-------------------------------------------------------------------------------------------------- !> @brief Check correctness of forward-backward transform. !-------------------------------------------------------------------------------------------------- From b83a545401eafd196b0cc31ef13c241abbc0c54a Mon Sep 17 00:00:00 2001 From: Test User Date: Wed, 11 Jan 2023 21:53:20 +0100 Subject: [PATCH 3/8] [skip ci] updated version information after successful test of v3.0.0-alpha7-294-g1330a4cfc --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index f319686e0..1c4b1e843 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.0-alpha7-291-gd2ad37e7f +3.0.0-alpha7-294-g1330a4cfc From 1924df6c3e5098db2c1084570bb8a6ae61aa5be8 Mon Sep 17 00:00:00 2001 From: Test User Date: Sun, 15 Jan 2023 05:31:39 +0100 Subject: [PATCH 4/8] [skip ci] updated version information after successful test of v3.0.0-alpha7-297-g22de899aa --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 1c4b1e843..211a34cab 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.0-alpha7-294-g1330a4cfc +3.0.0-alpha7-297-g22de899aa From 1b8f3292f01bbf1000916c1c9902de8182fdde0b Mon Sep 17 00:00:00 2001 From: Daniel Otto de Mentock Date: Mon, 16 Jan 2023 11:44:19 +0100 Subject: [PATCH 5/8] test was not using parametrized values --- python/tests/test_util.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/python/tests/test_util.py b/python/tests/test_util.py index a7b94794b..4e6c31820 100644 --- a/python/tests/test_util.py +++ b/python/tests/test_util.py @@ -286,18 +286,6 @@ p2 : str, optional Remaining description """ - invalid_docstring = """ - Function description - - Parameters ---------- - p0 : numpy.ndarray, shape (...,4) - p0 description 1 - p0 description 2 - p1 : int, optional - p1 description - - Remaining description - """ expected = """ Function description From bdf5faf40ad9581a91a7e2519850d02ac52f2f26 Mon Sep 17 00:00:00 2001 From: Test User Date: Mon, 16 Jan 2023 17:31:38 +0100 Subject: [PATCH 6/8] [skip ci] updated version information after successful test of v3.0.0-alpha7-299-g1b8f3292f --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 211a34cab..478b2a13c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.0-alpha7-297-g22de899aa +3.0.0-alpha7-299-g1b8f3292f From 5edd001d4c54a99db4fd21037e5b29c0b63e2b9d Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 16 Jan 2023 23:53:49 +0000 Subject: [PATCH 7/8] Option to normalize rotation matrix --- python/damask/_rotation.py | 9 +++++++-- python/tests/test_Rotation.py | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index 6c5c143aa..f986a50b4 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -902,7 +902,8 @@ class Rotation: return Rotation(Rotation._om2qu(om)) @staticmethod - def from_matrix(R: np.ndarray) -> 'Rotation': + def from_matrix(R: np.ndarray, + normalize: bool = False) -> 'Rotation': """ Initialize from rotation matrix. @@ -910,13 +911,17 @@ class Rotation: ---------- R : numpy.ndarray, shape (...,3,3) Rotation matrix with det(R) = 1 and R.T ∙ R = I. + normalize : bool, optional + Rescales rotation matrix to unit determinant. Defaults to False. Returns ------- new : damask.Rotation """ - return Rotation.from_basis(R) + return Rotation.from_basis(np.array(R,dtype=float) * (np.linalg.det(R)**(-1./3.))[...,np.newaxis,np.newaxis] + if normalize else + R) @staticmethod def from_parallel(a: np.ndarray, diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index 3cce0fcf1..056af2a93 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -774,9 +774,11 @@ class TestRotation: ).all() - def test_matrix(self,multidim_rotations): + @pytest.mark.parametrize('normalize',[True,False]) + def test_matrix(self,multidim_rotations,normalize): m = multidim_rotations - o = Rotation.from_matrix(m.as_matrix()) + o = Rotation.from_matrix(m.as_matrix()*(0.9 if normalize else 1.0), + normalize=normalize) f = Rotation(np.where(np.isclose(m.as_quaternion()[...,0],0.0,atol=atol)[...,np.newaxis],~o,o)) assert np.logical_or(m.isclose(o,atol=atol), m.isclose(f,atol=atol) From 19f27e51ccc8b45c10f642f1680e822b6bdaa59f Mon Sep 17 00:00:00 2001 From: Test User Date: Tue, 17 Jan 2023 04:07:43 +0100 Subject: [PATCH 8/8] [skip ci] updated version information after successful test of v3.0.0-alpha7-302-g56ff8c769 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 478b2a13c..a539ee5e1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.0-alpha7-299-g1b8f3292f +3.0.0-alpha7-302-g56ff8c769