From 8286a289df62bb4f8ae2fbcab107356a70ab3eb4 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 12 May 2019 09:47:21 +0200 Subject: [PATCH 001/120] try to directly allocate pointers --- src/mesh/FEM_mech.f90 | 66 ++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/src/mesh/FEM_mech.f90 b/src/mesh/FEM_mech.f90 index dd9872110..d3a6e48c1 100644 --- a/src/mesh/FEM_mech.f90 +++ b/src/mesh/FEM_mech.f90 @@ -84,11 +84,9 @@ subroutine FEM_mech_init(fieldBC) PetscDS :: mechDS PetscDualSpace :: mechDualSpace DMLabel :: BCLabel - PetscInt, dimension(:), allocatable, target :: numComp, numDoF, bcField PetscInt, dimension(:), pointer :: pNumComp, pNumDof, pBcField, pBcPoint PetscInt :: numBC, bcSize, nc IS :: bcPoint - IS, allocatable, target :: bcComps(:), bcPoints(:) IS, pointer :: pBcComps(:), pBcPoints(:) PetscSection :: section PetscInt :: field, faceSet, topologDim, nNodalPoints @@ -98,7 +96,7 @@ subroutine FEM_mech_init(fieldBC) PetscScalar, pointer :: px_scal(:) PetscScalar, allocatable, target :: x_scal(:) PetscReal :: detJ - PetscReal, allocatable, target :: v0(:), cellJ(:), invcellJ(:), cellJMat(:,:) + PetscReal, allocatable, target :: cellJMat(:,:) PetscReal, pointer :: pV0(:), pCellJ(:), pInvcellJ(:) PetscInt :: cellStart, cellEnd, cell, basis character(len=7) :: prefix = 'mechFE_' @@ -139,26 +137,26 @@ subroutine FEM_mech_init(fieldBC) call DMGetLabel(mech_mesh,'Face Sets',BCLabel,ierr); CHKERRQ(ierr) call DMPlexLabelComplete(mech_mesh,BCLabel,ierr); CHKERRQ(ierr) call DMGetSection(mech_mesh,section,ierr); CHKERRQ(ierr) - allocate(numComp(1), source=dimPlex); pNumComp => numComp - allocate(numDof(dimPlex+1), source = 0); pNumDof => numDof + allocate(pnumComp(1), source=dimPlex) + allocate(pnumDof(dimPlex+1), source = 0) do topologDim = 0, dimPlex call DMPlexGetDepthStratum(mech_mesh,topologDim,cellStart,cellEnd,ierr) CHKERRQ(ierr) - call PetscSectionGetDof(section,cellStart,numDof(topologDim+1),ierr) + call PetscSectionGetDof(section,cellStart,pnumDof(topologDim+1),ierr) CHKERRQ(ierr) enddo numBC = 0 do field = 1, dimPlex; do faceSet = 1, mesh_Nboundaries if (fieldBC%componentBC(field)%Mask(faceSet)) numBC = numBC + 1 enddo; enddo - allocate(bcField(numBC), source=0); pBcField => bcField - allocate(bcComps(numBC)); pBcComps => bcComps - allocate(bcPoints(numBC)); pBcPoints => bcPoints + allocate(pbcField(numBC), source=0) + allocate(pbcComps(numBC)) + allocate(pbcPoints(numBC)) numBC = 0 do field = 1, dimPlex; do faceSet = 1, mesh_Nboundaries if (fieldBC%componentBC(field)%Mask(faceSet)) then numBC = numBC + 1 - call ISCreateGeneral(PETSC_COMM_WORLD,1,[field-1],PETSC_COPY_VALUES,bcComps(numBC),ierr) + call ISCreateGeneral(PETSC_COMM_WORLD,1,[field-1],PETSC_COPY_VALUES,pbcComps(numBC),ierr) CHKERRQ(ierr) call DMGetStratumSize(mech_mesh,'Face Sets',mesh_boundaries(faceSet),bcSize,ierr) CHKERRQ(ierr) @@ -166,12 +164,12 @@ subroutine FEM_mech_init(fieldBC) call DMGetStratumIS(mech_mesh,'Face Sets',mesh_boundaries(faceSet),bcPoint,ierr) CHKERRQ(ierr) call ISGetIndicesF90(bcPoint,pBcPoint,ierr); CHKERRQ(ierr) - call ISCreateGeneral(PETSC_COMM_WORLD,bcSize,pBcPoint,PETSC_COPY_VALUES,bcPoints(numBC),ierr) + call ISCreateGeneral(PETSC_COMM_WORLD,bcSize,pBcPoint,PETSC_COPY_VALUES,pbcPoints(numBC),ierr) CHKERRQ(ierr) call ISRestoreIndicesF90(bcPoint,pBcPoint,ierr); CHKERRQ(ierr) call ISDestroy(bcPoint,ierr); CHKERRQ(ierr) else - call ISCreateGeneral(PETSC_COMM_WORLD,0,[0],PETSC_COPY_VALUES,bcPoints(numBC),ierr) + call ISCreateGeneral(PETSC_COMM_WORLD,0,[0],PETSC_COPY_VALUES,pbcPoints(numBC),ierr) CHKERRQ(ierr) endif endif @@ -182,7 +180,7 @@ subroutine FEM_mech_init(fieldBC) CHKERRQ(ierr) call DMSetSection(mech_mesh,section,ierr); CHKERRQ(ierr) do faceSet = 1, numBC - call ISDestroy(bcPoints(faceSet),ierr); CHKERRQ(ierr) + call ISDestroy(pbcPoints(faceSet),ierr); CHKERRQ(ierr) enddo !-------------------------------------------------------------------------------------------------- @@ -213,13 +211,10 @@ subroutine FEM_mech_init(fieldBC) allocate(nodalWeights(1)) nodalPointsP => nodalPoints nodalWeightsP => nodalWeights - allocate(v0(dimPlex)) - allocate(cellJ(dimPlex*dimPlex)) - allocate(invcellJ(dimPlex*dimPlex)) + allocate(pv0(dimPlex)) + allocate(pcellJ(dimPlex*dimPlex)) + allocate(pinvcellJ(dimPlex*dimPlex)) allocate(cellJMat(dimPlex,dimPlex)) - pV0 => v0 - pCellJ => cellJ - pInvcellJ => invcellJ call DMGetSection(mech_mesh,section,ierr); CHKERRQ(ierr) call DMGetDS(mech_mesh,mechDS,ierr); CHKERRQ(ierr) call PetscDSGetDiscretization(mechDS,0,mechFE,ierr) @@ -325,22 +320,19 @@ subroutine FEM_mech_formResidual(dm_local,xx_local,f_local,dummy,ierr) PetscScalar, dimension(:), pointer :: x_scal, pf_scal PetscScalar, target :: f_scal(cellDof) PetscReal :: detJ, IcellJMat(dimPlex,dimPlex) - PetscReal, target :: v0(dimPlex), cellJ(dimPlex*dimPlex), & - invcellJ(dimPlex*dimPlex) - PetscReal, pointer :: pV0(:), pCellJ(:), pInvcellJ(:) - PetscReal, pointer :: basisField(:), basisFieldDer(:) + PetscReal, pointer,dimension(:) :: pV0, pCellJ, pInvcellJ, basisField, basisFieldDer PetscInt :: cellStart, cellEnd, cell, field, face, & qPt, basis, comp, cidx PetscReal :: detFAvg PetscReal :: BMat(dimPlex*dimPlex,cellDof) - PetscObject :: dummy + PetscObject,intent(in) :: dummy PetscInt :: bcSize IS :: bcPoints PetscErrorCode :: ierr - pV0 => v0 - pCellJ => cellJ - pInvcellJ => invcellJ + allocate(pV0(dimPlex)) + allocate(pcellJ(dimPlex**2)) + allocate(pinvcellJ(dimPlex**2)) call DMGetSection(dm_local,section,ierr); CHKERRQ(ierr) call DMGetDS(dm_local,prob,ierr); CHKERRQ(ierr) call PetscDSGetTabulation(prob,0,basisField,basisFieldDer,ierr) @@ -460,13 +452,11 @@ subroutine FEM_mech_formJacobian(dm_local,xx_local,Jac_pre,Jac,dummy,ierr) Vec :: x_local, xx_local Mat :: Jac_pre, Jac PetscSection :: section, gSection - PetscReal :: detJ, IcellJMat(dimPlex,dimPlex) - PetscReal, target :: v0(dimPlex), cellJ(dimPlex*dimPlex), & - invcellJ(dimPlex*dimPlex) + PetscReal :: detJ PetscReal, dimension(:), pointer :: basisField, basisFieldDer, & pV0, pCellJ, pInvcellJ PetscInt :: cellStart, cellEnd, cell, field, face, & - qPt, basis, comp, cidx + qPt, basis, comp, cidx,bcSize PetscScalar,dimension(cellDOF,cellDOF), target :: K_e, & K_eA , & K_eB @@ -477,14 +467,14 @@ subroutine FEM_mech_formJacobian(dm_local,xx_local,Jac_pre,Jac,dummy,ierr) MatB (1 ,cellDof) PetscScalar, dimension(:), pointer :: pK_e, x_scal PetscReal, dimension(3,3) :: F, FAvg, FInv - PetscObject :: dummy - PetscInt :: bcSize + PetscObject, intent(in) :: dummy IS :: bcPoints PetscErrorCode :: ierr - pV0 => v0 - pCellJ => cellJ - pInvcellJ => invcellJ + allocate(pV0(dimPlex)) + allocate(pcellJ(dimPlex**2)) + allocate(pinvcellJ(dimPlex**2)) + call MatSetOption(Jac,MAT_KEEP_NONZERO_PATTERN,PETSC_TRUE,ierr); CHKERRQ(ierr) call MatSetOption(Jac,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_FALSE,ierr); CHKERRQ(ierr) call MatZeroEntries(Jac,ierr); CHKERRQ(ierr) @@ -513,7 +503,6 @@ subroutine FEM_mech_formJacobian(dm_local,xx_local,Jac_pre,Jac,dummy,ierr) CHKERRQ(ierr) call DMPlexComputeCellGeometryAffineFEM(dm_local,cell,pV0,pCellJ,pInvcellJ,detJ,ierr) CHKERRQ(ierr) - IcellJMat = reshape(pInvcellJ, shape = [dimPlex,dimPlex]) K_eA = 0.0 K_eB = 0.0 MatB = 0.0 @@ -525,7 +514,8 @@ subroutine FEM_mech_formJacobian(dm_local,xx_local,Jac_pre,Jac,dummy,ierr) do comp = 0, dimPlex-1 cidx = basis*dimPlex+comp BMat(comp*dimPlex+1:(comp+1)*dimPlex,basis*dimPlex+comp+1) = & - matmul(IcellJMat,basisFieldDer((((qPt*nBasis + basis)*dimPlex + comp)*dimPlex+comp )*dimPlex+1: & + matmul( reshape(pInvcellJ, shape = [dimPlex,dimPlex]),& + basisFieldDer((((qPt*nBasis + basis)*dimPlex + comp)*dimPlex+comp )*dimPlex+1: & (((qPt*nBasis + basis)*dimPlex + comp)*dimPlex+comp+1)*dimPlex)) enddo enddo From f0f8be7840f618dd758db33ced3b92d2d429f3dc Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 12 May 2019 10:05:40 +0200 Subject: [PATCH 002/120] not used --- src/mesh/FEM_utilities.f90 | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/mesh/FEM_utilities.f90 b/src/mesh/FEM_utilities.f90 index a2ba2d345..937c46a32 100644 --- a/src/mesh/FEM_utilities.f90 +++ b/src/mesh/FEM_utilities.f90 @@ -24,9 +24,7 @@ use PETScis ! grid related information information real(pReal), public :: wgt !< weighting factor 1/Nelems -!-------------------------------------------------------------------------------------------------- -! output data - Vec, public :: coordinatesVec + !-------------------------------------------------------------------------------------------------- ! field labels information character(len=*), parameter, public :: & @@ -53,7 +51,6 @@ use PETScis type, public :: tSolutionState !< return type of solution from FEM solver variants logical :: converged = .true. logical :: stagConverged = .true. - logical :: regrid = .false. integer(pInt) :: iterationsNeeded = 0_pInt end type tSolutionState @@ -79,18 +76,6 @@ use PETScis integer(pInt), allocatable :: faceID(:) type(tFieldBC), allocatable :: fieldBC(:) end type tLoadCase - - type, public :: tFEMInterpolation - integer(pInt) :: n - real(pReal), dimension(:,:) , allocatable :: shapeFunc, shapeDerivReal, geomShapeDerivIso - real(pReal), dimension(:,:,:), allocatable :: shapeDerivIso - end type tFEMInterpolation - - type, public :: tQuadrature - integer(pInt) :: n - real(pReal), dimension(:) , allocatable :: Weights - real(pReal), dimension(:,:), allocatable :: Points - end type tQuadrature public :: & utilities_init, & From 7d5f5afe01610ad5f5be1c6f839748c63234abeb Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 12 May 2019 13:11:30 +0200 Subject: [PATCH 003/120] further cleaning --- src/grid/spectral_utilities.f90 | 7 +------ src/mesh/DAMASK_FEM.f90 | 14 ++++++-------- src/mesh/FEM_utilities.f90 | 23 ++--------------------- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/src/grid/spectral_utilities.f90 b/src/grid/spectral_utilities.f90 index 4c5dc3169..1d5e42070 100644 --- a/src/grid/spectral_utilities.f90 +++ b/src/grid/spectral_utilities.f90 @@ -942,9 +942,6 @@ subroutine utilities_constitutiveResponse(P,P_av,C_volAvg,C_minmaxAvg,& IO_error use numerics, only: & worldrank - use debug, only: & - debug_reset, & - debug_info use math, only: & math_rotate_forward33, & math_det33 @@ -977,7 +974,6 @@ subroutine utilities_constitutiveResponse(P,P_av,C_volAvg,C_minmaxAvg,& materialpoint_F = reshape(F,[3,3,1,product(grid(1:2))*grid3]) ! set materialpoint target F to estimated field - call debug_reset() ! this has no effect on rank >0 call materialpoint_stressAndItsTangent(.true.,timeinc) ! calculate P field P = reshape(materialpoint_P, [3,3,grid(1),grid(2),grid3]) @@ -1023,8 +1019,7 @@ subroutine utilities_constitutiveResponse(P,P_av,C_volAvg,C_minmaxAvg,& C_volAvg = sum(sum(materialpoint_dPdF,dim=6),dim=5) call MPI_Allreduce(MPI_IN_PLACE,C_volAvg,81,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD,ierr) C_volAvg = C_volAvg * wgt - - call debug_info() ! this has no effect on rank >0 + end subroutine utilities_constitutiveResponse diff --git a/src/mesh/DAMASK_FEM.f90 b/src/mesh/DAMASK_FEM.f90 index 611be46e0..052c30071 100644 --- a/src/mesh/DAMASK_FEM.f90 +++ b/src/mesh/DAMASK_FEM.f90 @@ -28,8 +28,7 @@ program DAMASK_FEM IO_intOut, & IO_warning use math ! need to include the whole module for FFTW - use CPFEM2, only: & - CPFEM_initAll + use CPFEM2 use FEsolving, only: & restartWrite, & restartInc @@ -114,7 +113,7 @@ program DAMASK_FEM write(6,'(/,a)') ' <<<+- DAMASK_FEM init -+>>>' ! reading basic information from load case file and allocate data structure containing load cases - call DMGetDimension(geomMesh,dimPlex,ierr)! CHKERRQ(ierr) !< dimension of mesh (2D or 3D) + call DMGetDimension(geomMesh,dimPlex,ierr); CHKERRA(ierr) !< dimension of mesh (2D or 3D) nActiveFields = 1 allocate(solres(nActiveFields)) @@ -394,8 +393,7 @@ program DAMASK_FEM cutBack = .False. if(.not. all(solres(:)%converged .and. solres(:)%stagConverged)) then ! no solution found if (cutBackLevel < maxCutBack) then ! do cut back - if (worldrank == 0) & - write(6,'(/,a)') ' cut back detected' + write(6,'(/,a)') ' cut back detected' cutBack = .True. stepFraction = (stepFraction - 1_pInt) * subStepFactor ! adjust to new denominator cutBackLevel = cutBackLevel + 1_pInt @@ -403,7 +401,7 @@ program DAMASK_FEM timeinc = timeinc/2.0_pReal else ! default behavior, exit if spectral solver does not converge call IO_warning(850_pInt) - call quit(-1_pInt*(lastRestartWritten+1_pInt)) ! quit and provide information about last restart inc written (e.g. for regridding) ! continue from non-converged solution and start guessing after accepted (sub)inc + call quit(-1_pInt*(lastRestartWritten+1_pInt)) ! quit and provide information about last restart inc written endif else guess = .true. ! start guessing after first converged (sub)inc @@ -428,7 +426,8 @@ program DAMASK_FEM endif; flush(6) if (mod(inc,loadCases(currentLoadCase)%outputFrequency) == 0_pInt) then ! at output frequency - write(6,'(1/,a)') ' ToDo: ... writing results to file ......................................' + write(6,'(1/,a)') ' ... writing results to file ......................................' + call CPFEM_results(totalIncsCounter,time) endif if ( loadCases(currentLoadCase)%restartFrequency > 0_pInt & ! writing of restart info requested ... .and. mod(inc,loadCases(currentLoadCase)%restartFrequency) == 0_pInt) then ! ... and at frequency of writing restart information @@ -452,7 +451,6 @@ program DAMASK_FEM real(convergedCounter, pReal)/& real(notConvergedCounter + convergedCounter,pReal)*100.0_pReal, ' %) increments converged!' flush(6) - call MPI_file_close(fileUnit,ierr) close(statUnit) if (notConvergedCounter > 0_pInt) call quit(2_pInt) ! error if some are not converged diff --git a/src/mesh/FEM_utilities.f90 b/src/mesh/FEM_utilities.f90 index 937c46a32..b2f9d35f5 100644 --- a/src/mesh/FEM_utilities.f90 +++ b/src/mesh/FEM_utilities.f90 @@ -104,11 +104,8 @@ subroutine utilities_init use math ! must use the whole module for use of FFTW use mesh, only: & mesh_NcpElemsGlobal, & - mesh_maxNips, & - geomMesh - - implicit none - + mesh_maxNips + character(len=1024) :: petsc_optionsPhysics PetscErrorCode :: ierr @@ -142,35 +139,21 @@ end subroutine utilities_init !> @brief calculates constitutive response !-------------------------------------------------------------------------------------------------- subroutine utilities_constitutiveResponse(timeinc,P_av,forwardData) - use math, only: & - math_det33 use FEsolving, only: & restartWrite use homogenization, only: & materialpoint_P, & materialpoint_stressAndItsTangent - implicit none real(pReal), intent(in) :: timeinc !< loading time logical, intent(in) :: forwardData !< age results real(pReal),intent(out), dimension(3,3) :: P_av !< average PK stress - logical :: & - age - PetscErrorCode :: ierr write(6,'(/,a)') ' ... evaluating constitutive response ......................................' - age = .False. - if (forwardData) then ! aging results - age = .True. - endif - if (cutBack) then ! restore saved variables - age = .False. - endif - call materialpoint_stressAndItsTangent(.true.,timeinc) ! calculate P field restartWrite = .false. ! reset restartWrite status @@ -187,8 +170,6 @@ end subroutine utilities_constitutiveResponse !-------------------------------------------------------------------------------------------------- subroutine utilities_projectBCValues(localVec,section,field,comp,bcPointsIS,BCValue,BCDotValue,timeinc) - implicit none - Vec :: localVec PetscInt :: field, comp, nBcPoints, point, dof, numDof, numComp, offset PetscSection :: section From 344e6ca51a32ffd0e2ab3f93901fee8520e3237b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 12 May 2019 23:56:44 +0200 Subject: [PATCH 004/120] IP volume is trivial for spectral solver --- src/mesh_grid.f90 | 79 +++-------------------------------------------- 1 file changed, 4 insertions(+), 75 deletions(-) diff --git a/src/mesh_grid.f90 b/src/mesh_grid.f90 index 7274582a2..f8a874c55 100644 --- a/src/mesh_grid.f90 +++ b/src/mesh_grid.f90 @@ -127,7 +127,6 @@ integer(pInt), dimension(:,:), allocatable, private :: & mesh_spectral_build_elements, & mesh_spectral_build_ipNeighborhood, & mesh_build_cellnodes, & - mesh_build_ipVolumes, & mesh_build_ipCoordinates type, public, extends(tMesh) :: tMesh_grid @@ -190,7 +189,7 @@ subroutine mesh_init(ip,el) implicit none include 'fftw3-mpi.f03' integer(C_INTPTR_T) :: devNull, local_K, local_K_offset - integer :: ierr, worldsize + integer :: ierr, worldsize, i integer(pInt), intent(in), optional :: el, ip integer(pInt) :: j logical :: myDebug @@ -244,7 +243,7 @@ subroutine mesh_init(ip,el) if (myDebug) write(6,'(a)') ' Built cell nodes'; flush(6) call mesh_build_ipCoordinates if (myDebug) write(6,'(a)') ' Built IP coordinates'; flush(6) - call mesh_build_ipVolumes + allocate(mesh_ipVolume(1,theMesh%nElems),source=product([geomSize(1:2),size3]/real([grid(1:2),grid3]))) if (myDebug) write(6,'(a)') ' Built IP volumes'; flush(6) call mesh_build_ipAreas if (myDebug) write(6,'(a)') ' Built IP areas'; flush(6) @@ -508,7 +507,7 @@ subroutine mesh_spectral_build_ipNeighborhood integer(pInt) :: & x,y,z, & e - allocate(mesh_ipNeighborhood(3,theMesh%elem%nIPneighbors,theMesh%elem%nIPs,theMesh%nElems),source=0_pInt) + allocate(mesh_ipNeighborhood(3,6,1,theMesh%nElems),source=0_pInt) e = 0_pInt do z = 0_pInt,grid3-1_pInt @@ -768,75 +767,6 @@ function mesh_build_cellnodes(nodes,Ncellnodes) end function mesh_build_cellnodes -!-------------------------------------------------------------------------------------------------- -!> @brief Calculates IP volume. Allocates global array 'mesh_ipVolume' -!> @details The IP volume is calculated differently depending on the cell type. -!> 2D cells assume an element depth of one in order to calculate the volume. -!> For the hexahedral cell we subdivide the cell into subvolumes of pyramidal -!> shape with a cell face as basis and the central ip at the tip. This subvolume is -!> calculated as an average of four tetrahedals with three corners on the cell face -!> and one corner at the central ip. -!-------------------------------------------------------------------------------------------------- -subroutine mesh_build_ipVolumes - use math, only: & - math_volTetrahedron, & - math_areaTriangle - - implicit none - integer(pInt) :: e,t,g,c,i,m,f,n - real(pReal), dimension(FE_maxNcellnodesPerCellface,FE_maxNcellfaces) :: subvolume - - - allocate(mesh_ipVolume(theMesh%elem%nIPs,theMesh%nElems),source=0.0_pReal) - - - !$OMP PARALLEL DO PRIVATE(t,g,c,m,subvolume) - do e = 1_pInt,theMesh%nElems ! loop over cpElems - select case (theMesh%elem%cellType) - - case (1_pInt) ! 2D 3node - forall (i = 1_pInt:theMesh%elem%nIPs) & ! loop over ips=cells in this element - mesh_ipVolume(i,e) = math_areaTriangle(mesh_cellnode(1:3,mesh_cell(1,i,e)), & - mesh_cellnode(1:3,mesh_cell(2,i,e)), & - mesh_cellnode(1:3,mesh_cell(3,i,e))) - - case (2_pInt) ! 2D 4node - forall (i = 1_pInt:theMesh%elem%nIPs) & ! loop over ips=cells in this element - mesh_ipVolume(i,e) = math_areaTriangle(mesh_cellnode(1:3,mesh_cell(1,i,e)), & ! here we assume a planar shape, so division in two triangles suffices - mesh_cellnode(1:3,mesh_cell(2,i,e)), & - mesh_cellnode(1:3,mesh_cell(3,i,e))) & - + math_areaTriangle(mesh_cellnode(1:3,mesh_cell(3,i,e)), & - mesh_cellnode(1:3,mesh_cell(4,i,e)), & - mesh_cellnode(1:3,mesh_cell(1,i,e))) - - case (3_pInt) ! 3D 4node - forall (i = 1_pInt:theMesh%elem%nIPs) & ! loop over ips=cells in this element - mesh_ipVolume(i,e) = math_volTetrahedron(mesh_cellnode(1:3,mesh_cell(1,i,e)), & - mesh_cellnode(1:3,mesh_cell(2,i,e)), & - mesh_cellnode(1:3,mesh_cell(3,i,e)), & - mesh_cellnode(1:3,mesh_cell(4,i,e))) - - case (4_pInt) - c = theMesh%elem%cellType ! 3D 8node - m = FE_NcellnodesPerCellface(c) - do i = 1_pInt,theMesh%elem%nIPs ! loop over ips=cells in this element - subvolume = 0.0_pReal - forall(f = 1_pInt:FE_NipNeighbors(c), n = 1_pInt:FE_NcellnodesPerCellface(c)) & - subvolume(n,f) = math_volTetrahedron(& - mesh_cellnode(1:3,mesh_cell(FE_cellface( n ,f,c),i,e)), & - mesh_cellnode(1:3,mesh_cell(FE_cellface(1+mod(n ,m),f,c),i,e)), & - mesh_cellnode(1:3,mesh_cell(FE_cellface(1+mod(n+1,m),f,c),i,e)), & - mesh_ipCoordinates(1:3,i,e)) - mesh_ipVolume(i,e) = 0.5_pReal * sum(subvolume) ! each subvolume is based on four tetrahedrons, altough the face consists of only two triangles -> averaging factor two - enddo - - end select - enddo - !$OMP END PARALLEL DO - -end subroutine mesh_build_ipVolumes - - !-------------------------------------------------------------------------------------------------- !> @brief Calculates IP Coordinates. Allocates global array 'mesh_ipCoordinates' ! Called by all solvers in mesh_init in order to initialize the ip coordinates. @@ -855,8 +785,7 @@ subroutine mesh_build_ipCoordinates integer(pInt) :: e,c,i,n real(pReal), dimension(3) :: myCoords - if (.not. allocated(mesh_ipCoordinates)) & - allocate(mesh_ipCoordinates(3,theMesh%elem%nIPs,theMesh%nElems),source=0.0_pReal) + allocate(mesh_ipCoordinates(3,theMesh%elem%nIPs,theMesh%nElems),source=0.0_pReal) !$OMP PARALLEL DO PRIVATE(c,myCoords) do e = 1_pInt,theMesh%nElems ! loop over cpElems From df01a3ff36ac227b41bef9ce13263835d0fcecda Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 13 May 2019 00:00:14 +0200 Subject: [PATCH 005/120] only for internal use --- src/mesh_grid.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh_grid.f90 b/src/mesh_grid.f90 index f8a874c55..094f7da4e 100644 --- a/src/mesh_grid.f90 +++ b/src/mesh_grid.f90 @@ -34,7 +34,7 @@ module mesh real(pReal), public, protected :: & mesh_unitlength !< physical length of one unit in mesh - real(pReal), dimension(:,:), allocatable, public :: & + real(pReal), dimension(:,:), allocatable, private :: & mesh_node, & !< node x,y,z coordinates (after deformation! ONLY FOR MARC!!!) mesh_cellnode !< cell node x,y,z coordinates (after deformation! ONLY FOR MARC!!!) From 4c148f1a07f8cbb5e8d3b546c09ea06e4f91f448 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 13 May 2019 08:47:53 +0200 Subject: [PATCH 006/120] not needed --- src/mesh_grid.f90 | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/src/mesh_grid.f90 b/src/mesh_grid.f90 index 094f7da4e..11afe0175 100644 --- a/src/mesh_grid.f90 +++ b/src/mesh_grid.f90 @@ -69,8 +69,6 @@ integer(pInt), dimension(:,:), allocatable, private :: & integer(pInt), parameter, private :: & FE_Ngeomtypes = 10_pInt, & FE_Ncelltypes = 4_pInt, & - FE_maxNmatchingNodesPerFace = 4_pInt, & - FE_maxNfaces = 6_pInt, & FE_maxNcellnodesPerCell = 8_pInt, & FE_maxNcellfaces = 6_pInt, & FE_maxNcellnodesPerCellface = 4_pInt @@ -116,8 +114,7 @@ integer(pInt), dimension(:,:), allocatable, private :: & size3offset !< (local) size offset in 3rd direction public :: & - mesh_init, & - mesh_cellCenterCoordinates + mesh_init private :: & mesh_build_cellconnectivity, & @@ -460,12 +457,8 @@ end subroutine mesh_spectral_build_nodes !-------------------------------------------------------------------------------------------------- !> @brief Store FEid, type, material, texture, and node list per element. !! Allocates global array 'mesh_element' -!> @todo does the IO_error makes sense? !-------------------------------------------------------------------------------------------------- subroutine mesh_spectral_build_elements() - use IO, only: & - IO_error - implicit none integer(pInt) :: & e, & elemOffset @@ -474,11 +467,9 @@ subroutine mesh_spectral_build_elements() allocate(mesh_element (4_pInt+8_pInt,theMesh%nElems), source = 0_pInt) elemOffset = product(grid(1:2))*grid3Offset - e = 0_pInt - do while (e < theMesh%nElems) ! fill expected number of elements, stop at end of data - e = e+1_pInt ! valid element entry + do e=1, theMesh%nElems mesh_element( 1,e) = -1_pInt ! DEPRECATED - mesh_element( 2,e) = 10_pInt + mesh_element( 2,e) = -1_pInt ! DEPRECATED mesh_element( 3,e) = mesh_homogenizationAt(e) mesh_element( 4,e) = microGlobal(e+elemOffset) ! microstructure mesh_element( 5,e) = e + (e-1_pInt)/grid(1) + & @@ -492,8 +483,6 @@ subroutine mesh_spectral_build_elements() mesh_element(12,e) = mesh_element(9,e) + grid(1) + 1_pInt enddo - if (e /= theMesh%nElems) call IO_error(880_pInt,e) - end subroutine mesh_spectral_build_elements @@ -803,27 +792,6 @@ subroutine mesh_build_ipCoordinates end subroutine mesh_build_ipCoordinates -!-------------------------------------------------------------------------------------------------- -!> @brief Calculates cell center coordinates. -!-------------------------------------------------------------------------------------------------- -pure function mesh_cellCenterCoordinates(ip,el) - - implicit none - integer(pInt), intent(in) :: el, & !< element number - ip !< integration point number - real(pReal), dimension(3) :: mesh_cellCenterCoordinates !< x,y,z coordinates of the cell center of the requested IP cell - integer(pInt) :: c,n - - c = theMesh%elem%cellType - mesh_cellCenterCoordinates = 0.0_pReal - do n = 1_pInt,FE_NcellnodesPerCell(c) ! loop over cell nodes in this cell - mesh_cellCenterCoordinates = mesh_cellCenterCoordinates + mesh_cellnode(1:3,mesh_cell(n,ip,el)) - enddo - mesh_cellCenterCoordinates = mesh_cellCenterCoordinates / real(FE_NcellnodesPerCell(c),pReal) - -end function mesh_cellCenterCoordinates - - !-------------------------------------------------------------------------------------------------- !> @brief calculation of IP interface areas, allocate globals '_ipArea', and '_ipAreaNormal' !-------------------------------------------------------------------------------------------------- From fb49acdb976c48fb088a0a057fcc3c7b46eda5de Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 13 May 2019 22:54:18 +0200 Subject: [PATCH 007/120] more explicit --- src/mesh_grid.f90 | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/mesh_grid.f90 b/src/mesh_grid.f90 index 11afe0175..39e0111c1 100644 --- a/src/mesh_grid.f90 +++ b/src/mesh_grid.f90 @@ -221,7 +221,8 @@ subroutine mesh_init(ip,el) mesh_Nnodes = product(grid(1:2) + 1_pInt)*(grid3 + 1_pInt) - call mesh_spectral_build_nodes() + mesh_node0 = mesh_spectral_build_nodes() + mesh_node = mesh_node0 if (myDebug) write(6,'(a)') ' Built nodes'; flush(6) call theMesh%init(mesh_node) @@ -429,29 +430,22 @@ end subroutine mesh_spectral_read_grid !> @brief Store x,y,z coordinates of all nodes in mesh. !! Allocates global arrays 'mesh_node0' and 'mesh_node' !-------------------------------------------------------------------------------------------------- -subroutine mesh_spectral_build_nodes() +pure function mesh_spectral_build_nodes() - implicit none - integer(pInt) :: n + real(pReal), dimension(3,mesh_Nnodes) :: mesh_spectral_build_nodes + integer :: n,a,b,c - allocate (mesh_node0 (3,mesh_Nnodes), source = 0.0_pReal) + n = 0 + do c = 0, grid3 + do b = 0, grid(2) + do a = 0, grid(1) + n = n + 1 + mesh_spectral_build_nodes(1:3,n) = geomSize/real(grid,pReal) * real([a,b,grid3Offset+c],pReal) + enddo + enddo + enddo - forall (n = 0_pInt:mesh_Nnodes-1_pInt) - mesh_node0(1,n+1_pInt) = mesh_unitlength * & - geomSize(1)*real(mod(n,(grid(1)+1_pInt) ),pReal) & - / real(grid(1),pReal) - mesh_node0(2,n+1_pInt) = mesh_unitlength * & - geomSize(2)*real(mod(n/(grid(1)+1_pInt),(grid(2)+1_pInt)),pReal) & - / real(grid(2),pReal) - mesh_node0(3,n+1_pInt) = mesh_unitlength * & - size3*real(mod(n/(grid(1)+1_pInt)/(grid(2)+1_pInt),(grid3+1_pInt)),pReal) & - / real(grid3,pReal) + & - size3offset - end forall - - mesh_node = mesh_node0 - -end subroutine mesh_spectral_build_nodes +end function mesh_spectral_build_nodes !-------------------------------------------------------------------------------------------------- From c8794af3bbbf5a771ee703fc6e82e505881055dd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 13 May 2019 23:18:02 +0200 Subject: [PATCH 008/120] better readable --- src/mesh_grid.f90 | 92 ++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 65 deletions(-) diff --git a/src/mesh_grid.f90 b/src/mesh_grid.f90 index 39e0111c1..e752f5d41 100644 --- a/src/mesh_grid.f90 +++ b/src/mesh_grid.f90 @@ -239,7 +239,7 @@ subroutine mesh_init(ip,el) if (myDebug) write(6,'(a)') ' Built cell connectivity'; flush(6) mesh_cellnode = mesh_build_cellnodes(mesh_node,mesh_Ncellnodes) if (myDebug) write(6,'(a)') ' Built cell nodes'; flush(6) - call mesh_build_ipCoordinates + mesh_ipCoordinates = mesh_build_ipCoordinates() if (myDebug) write(6,'(a)') ' Built IP coordinates'; flush(6) allocate(mesh_ipVolume(1,theMesh%nElems),source=product([geomSize(1:2),size3]/real([grid(1:2),grid3]))) if (myDebug) write(6,'(a)') ' Built IP volumes'; flush(6) @@ -391,7 +391,7 @@ subroutine mesh_spectral_read_grid() allocate(mesh_homogenizationAt(product(grid)), source = h) ! too large in case of MPI (shrink later, not very elegant) !-------------------------------------------------------------------------------------------------- -! read and interprete content +! read and interpret content e = 1_pInt do while (startPos < len(rawData)) endPos = startPos + index(rawData(startPos:),new_line('')) - 1_pInt @@ -426,10 +426,9 @@ subroutine mesh_spectral_read_grid() end subroutine mesh_spectral_read_grid -!-------------------------------------------------------------------------------------------------- -!> @brief Store x,y,z coordinates of all nodes in mesh. -!! Allocates global arrays 'mesh_node0' and 'mesh_node' -!-------------------------------------------------------------------------------------------------- +!--------------------------------------------------------------------------------------------------- +!> @brief Calculates position of nodes (pretend to be an element) +!--------------------------------------------------------------------------------------------------- pure function mesh_spectral_build_nodes() real(pReal), dimension(3,mesh_Nnodes) :: mesh_spectral_build_nodes @@ -448,6 +447,27 @@ pure function mesh_spectral_build_nodes() end function mesh_spectral_build_nodes +!--------------------------------------------------------------------------------------------------- +!> @brief Calculates position of IPs/cell centres (pretend to be an element) +!--------------------------------------------------------------------------------------------------- +function mesh_build_ipCoordinates() + + real(pReal), dimension(3,1,theMesh%nElems) :: mesh_build_ipCoordinates + integer :: n,a,b,c + + n = 0 + do c = 1, grid3 + do b = 1, grid(2) + do a = 1, grid(1) + n = n + 1 + mesh_build_ipCoordinates(1:3,1,n) = geomSize/real(grid,pReal) * (real([a,b,grid3Offset+c],pReal) -0.5_pReal) + enddo + enddo + enddo + +end function mesh_build_ipCoordinates + + !-------------------------------------------------------------------------------------------------- !> @brief Store FEid, type, material, texture, and node list per element. !! Allocates global array 'mesh_element' @@ -544,7 +564,6 @@ function mesh_nodesAroundCentres(gDim,Favg,centres) result(nodes) debug_level, & debug_levelBasic - implicit none real(pReal), intent(in), dimension(:,:,:,:) :: & centres real(pReal), dimension(3,size(centres,2)+1,size(centres,3)+1,size(centres,4)+1) :: & @@ -623,16 +642,6 @@ function mesh_nodesAroundCentres(gDim,Favg,centres) result(nodes) end function mesh_nodesAroundCentres -!################################################################################################################# -!################################################################################################################# -!################################################################################################################# -! The following routines are not solver specific and should be included in mesh_base (most likely in modified form) -!################################################################################################################# -!################################################################################################################# -!################################################################################################################# - - - !-------------------------------------------------------------------------------------------------- !> @brief Split CP elements into cells. !> @details Build a mapping between cells and the corresponding cell nodes ('mesh_cell'). @@ -762,28 +771,6 @@ end function mesh_build_cellnodes ! HAS TO BE CHANGED IN A LATER VERSION. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !-------------------------------------------------------------------------------------------------- -subroutine mesh_build_ipCoordinates - - implicit none - integer(pInt) :: e,c,i,n - real(pReal), dimension(3) :: myCoords - - allocate(mesh_ipCoordinates(3,theMesh%elem%nIPs,theMesh%nElems),source=0.0_pReal) - - !$OMP PARALLEL DO PRIVATE(c,myCoords) - do e = 1_pInt,theMesh%nElems ! loop over cpElems - c = theMesh%elem%cellType - do i = 1_pInt,theMesh%elem%nIPs ! loop over ips=cells in this element - myCoords = 0.0_pReal - do n = 1_pInt,FE_NcellnodesPerCell(c) ! loop over cell nodes in this cell - myCoords = myCoords + mesh_cellnode(1:3,mesh_cell(n,i,e)) - enddo - mesh_ipCoordinates(1:3,i,e) = myCoords / real(FE_NcellnodesPerCell(c),pReal) - enddo - enddo - !$OMP END PARALLEL DO - -end subroutine mesh_build_ipCoordinates !-------------------------------------------------------------------------------------------------- @@ -806,32 +793,7 @@ subroutine mesh_build_ipAreas c = theMesh%elem%cellType select case (c) - case (1_pInt,2_pInt) ! 2D 3 or 4 node - do i = 1_pInt,theMesh%elem%nIPs ! loop over ips=cells in this element - do f = 1_pInt,FE_NipNeighbors(c) ! loop over cell faces - forall(n = 1_pInt:FE_NcellnodesPerCellface(c)) & - nodePos(1:3,n) = mesh_cellnode(1:3,mesh_cell(FE_cellface(n,f,c),i,e)) - normal(1) = nodePos(2,2) - nodePos(2,1) ! x_normal = y_connectingVector - normal(2) = -(nodePos(1,2) - nodePos(1,1)) ! y_normal = -x_connectingVector - normal(3) = 0.0_pReal - mesh_ipArea(f,i,e) = norm2(normal) - mesh_ipAreaNormal(1:3,f,i,e) = normal / norm2(normal) ! ensure unit length of area normal - enddo - enddo - - case (3_pInt) ! 3D 4node - do i = 1_pInt,theMesh%elem%nIPs ! loop over ips=cells in this element - do f = 1_pInt,FE_NipNeighbors(c) ! loop over cell faces - forall(n = 1_pInt:FE_NcellnodesPerCellface(c)) & - nodePos(1:3,n) = mesh_cellnode(1:3,mesh_cell(FE_cellface(n,f,c),i,e)) - normal = math_crossproduct(nodePos(1:3,2) - nodePos(1:3,1), & - nodePos(1:3,3) - nodePos(1:3,1)) - mesh_ipArea(f,i,e) = norm2(normal) - mesh_ipAreaNormal(1:3,f,i,e) = normal / norm2(normal) ! ensure unit length of area normal - enddo - enddo - - case (4_pInt) ! 3D 8node + case (4_pInt) ! for this cell type we get the normal of the quadrilateral face as an average of ! four normals of triangular subfaces; since the face consists only of two triangles, ! the sum has to be divided by two; this whole prcedure tries to compensate for From cac472c506b135f5bb2bae8ddd8f792e5ef5ab63 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 May 2019 00:13:43 +0200 Subject: [PATCH 009/120] cleaning more complex initialization will be used by FEM solvers only --- src/mesh_grid.f90 | 295 ++++------------------------------------------ 1 file changed, 23 insertions(+), 272 deletions(-) diff --git a/src/mesh_grid.f90 b/src/mesh_grid.f90 index e752f5d41..a7da77bf0 100644 --- a/src/mesh_grid.f90 +++ b/src/mesh_grid.f90 @@ -35,8 +35,8 @@ module mesh mesh_unitlength !< physical length of one unit in mesh real(pReal), dimension(:,:), allocatable, private :: & - mesh_node, & !< node x,y,z coordinates (after deformation! ONLY FOR MARC!!!) - mesh_cellnode !< cell node x,y,z coordinates (after deformation! ONLY FOR MARC!!!) + mesh_node !< node x,y,z coordinates (after deformation! ONLY FOR MARC!!!) + real(pReal), dimension(:,:), allocatable, public, protected :: & mesh_ipVolume, & !< volume associated with IP (initially!) @@ -53,53 +53,14 @@ module mesh logical, dimension(3), public, parameter :: mesh_periodicSurface = .true. !< flag indicating periodic outer surfaces (used for fluxes) -integer(pInt), dimension(:,:), allocatable, private :: & - mesh_cellnodeParent !< cellnode's parent element ID, cellnode's intra-element ID integer(pInt),dimension(:,:,:), allocatable, private :: & mesh_cell !< cell connectivity for each element,ip/cell - integer(pInt), dimension(:,:,:), allocatable, private :: & - FE_cellface !< list of intra-cell cell node IDs that constitute the cell faces of a specific type of cell - - -! These definitions should actually reside in the FE-solver specific part (different for MARC/ABAQUS) -! Hence, I suggest to prefix with "FE_" - integer(pInt), parameter, private :: & FE_Ngeomtypes = 10_pInt, & FE_Ncelltypes = 4_pInt, & - FE_maxNcellnodesPerCell = 8_pInt, & - FE_maxNcellfaces = 6_pInt, & - FE_maxNcellnodesPerCellface = 4_pInt - - - - integer(pInt), dimension(FE_Ncelltypes), parameter, private :: FE_NcellnodesPerCell = & !< number of cell nodes in a specific cell type - int([ & - 3, & ! (2D 3node) - 4, & ! (2D 4node) - 4, & ! (3D 4node) - 8 & ! (3D 8node) - ],pInt) - - integer(pInt), dimension(FE_Ncelltypes), parameter, private :: FE_NcellnodesPerCellface = & !< number of cell nodes per cell face in a specific cell type - int([& - 2, & ! (2D 3node) - 2, & ! (2D 4node) - 3, & ! (3D 4node) - 4 & ! (3D 8node) - ],pInt) - - - integer(pInt), dimension(FE_Ncelltypes), parameter, private :: FE_NipNeighbors = & !< number of ip neighbors / cell faces in a specific cell type - int([& - 3, & ! (2D 3node) - 4, & ! (2D 4node) - 4, & ! (3D 4node) - 6 & ! (3D 8node) - ],pInt) - + FE_maxNcellnodesPerCell = 8_pInt integer(pInt), dimension(3), public, protected :: & grid !< (global) grid @@ -117,13 +78,10 @@ integer(pInt), dimension(:,:), allocatable, private :: & mesh_init private :: & - mesh_build_cellconnectivity, & mesh_build_ipAreas, & - mesh_build_FEdata, & mesh_spectral_build_nodes, & mesh_spectral_build_elements, & mesh_spectral_build_ipNeighborhood, & - mesh_build_cellnodes, & mesh_build_ipCoordinates type, public, extends(tMesh) :: tMesh_grid @@ -234,16 +192,14 @@ subroutine mesh_init(ip,el) if (myDebug) write(6,'(a)') ' Built elements'; flush(6) - call mesh_build_FEdata ! get properties of the different types of elements - call mesh_build_cellconnectivity - if (myDebug) write(6,'(a)') ' Built cell connectivity'; flush(6) - mesh_cellnode = mesh_build_cellnodes(mesh_node,mesh_Ncellnodes) + if (myDebug) write(6,'(a)') ' Built cell nodes'; flush(6) mesh_ipCoordinates = mesh_build_ipCoordinates() if (myDebug) write(6,'(a)') ' Built IP coordinates'; flush(6) allocate(mesh_ipVolume(1,theMesh%nElems),source=product([geomSize(1:2),size3]/real([grid(1:2),grid3]))) if (myDebug) write(6,'(a)') ' Built IP volumes'; flush(6) - call mesh_build_ipAreas + mesh_ipArea = mesh_build_ipAreas() + call mesh_build_ipAreas2 if (myDebug) write(6,'(a)') ' Built IP areas'; flush(6) call mesh_spectral_build_ipNeighborhood @@ -261,9 +217,6 @@ subroutine mesh_init(ip,el) !!!! COMPATIBILITY HACK !!!! -! for a homogeneous mesh, all elements have the same number of IPs and and cell nodes. -! hence, xxPerElem instead of maxXX -! better name theMesh%homogenizationAt = mesh_element(3,:) theMesh%microstructureAt = mesh_element(4,:) !!!!!!!!!!!!!!!!!!!!!!!! @@ -643,236 +596,34 @@ end function mesh_nodesAroundCentres !-------------------------------------------------------------------------------------------------- -!> @brief Split CP elements into cells. -!> @details Build a mapping between cells and the corresponding cell nodes ('mesh_cell'). -!> Cell nodes that are also matching nodes are unique in the list of cell nodes, -!> all others (currently) might be stored more than once. -!> Also allocates the 'mesh_node' array. +!> @brief calculation of IP interface areas, allocate globals '_ipArea', and '_ipAreaNormal' !-------------------------------------------------------------------------------------------------- -subroutine mesh_build_cellconnectivity +pure function mesh_build_ipAreas() - implicit none - integer(pInt), dimension(:), allocatable :: & - matchingNode2cellnode - integer(pInt), dimension(:,:), allocatable :: & - cellnodeParent - integer(pInt), dimension(theMesh%elem%Ncellnodes) :: & - localCellnode2globalCellnode - integer(pInt) :: & - e,n,i, & - matchingNodeID, & - localCellnodeID - - integer(pInt), dimension(FE_Ngeomtypes), parameter :: FE_NmatchingNodes = & !< number of nodes that are needed for face matching in a specific type of element geometry - int([ & - 3, & ! element 6 (2D 3node 1ip) - 3, & ! element 125 (2D 6node 3ip) - 4, & ! element 11 (2D 4node 4ip) - 4, & ! element 27 (2D 8node 9ip) - 4, & ! element 134 (3D 4node 1ip) - 4, & ! element 127 (3D 10node 4ip) - 6, & ! element 136 (3D 6node 6ip) - 8, & ! element 117 (3D 8node 1ip) - 8, & ! element 7 (3D 8node 8ip) - 8 & ! element 21 (3D 20node 27ip) - ],pInt) + real(pReal), dimension(6,1,theMesh%nElems) :: mesh_build_ipAreas - allocate(mesh_cell(FE_maxNcellnodesPerCell,theMesh%elem%nIPs,theMesh%nElems), source=0_pInt) - allocate(matchingNode2cellnode(theMesh%nNodes), source=0_pInt) - allocate(cellnodeParent(2_pInt,theMesh%elem%Ncellnodes*theMesh%nElems), source=0_pInt) - - mesh_Ncells = theMesh%nElems*theMesh%elem%nIPs -!-------------------------------------------------------------------------------------------------- -! Count cell nodes (including duplicates) and generate cell connectivity list - mesh_Ncellnodes = 0_pInt - - do e = 1_pInt,theMesh%nElems - localCellnode2globalCellnode = 0_pInt - do i = 1_pInt,theMesh%elem%nIPs - do n = 1_pInt,theMesh%elem%NcellnodesPerCell - localCellnodeID = theMesh%elem%cell(n,i) - if (localCellnodeID <= FE_NmatchingNodes(theMesh%elem%geomType)) then ! this cell node is a matching node - matchingNodeID = mesh_element(4_pInt+localCellnodeID,e) - if (matchingNode2cellnode(matchingNodeID) == 0_pInt) then ! if this matching node does not yet exist in the glbal cell node list ... - mesh_Ncellnodes = mesh_Ncellnodes + 1_pInt ! ... count it as cell node ... - matchingNode2cellnode(matchingNodeID) = mesh_Ncellnodes ! ... and remember its global ID - cellnodeParent(1_pInt,mesh_Ncellnodes) = e ! ... and where it belongs to - cellnodeParent(2_pInt,mesh_Ncellnodes) = localCellnodeID - endif - mesh_cell(n,i,e) = matchingNode2cellnode(matchingNodeID) - else ! this cell node is no matching node - if (localCellnode2globalCellnode(localCellnodeID) == 0_pInt) then ! if this local cell node does not yet exist in the global cell node list ... - mesh_Ncellnodes = mesh_Ncellnodes + 1_pInt ! ... count it as cell node ... - localCellnode2globalCellnode(localCellnodeID) = mesh_Ncellnodes ! ... and remember its global ID ... - cellnodeParent(1_pInt,mesh_Ncellnodes) = e ! ... and it belongs to - cellnodeParent(2_pInt,mesh_Ncellnodes) = localCellnodeID - endif - mesh_cell(n,i,e) = localCellnode2globalCellnode(localCellnodeID) - endif - enddo - enddo - enddo - - allocate(mesh_cellnodeParent(2_pInt,mesh_Ncellnodes)) - allocate(mesh_cellnode(3_pInt,mesh_Ncellnodes)) - - forall(n = 1_pInt:mesh_Ncellnodes) - mesh_cellnodeParent(1,n) = cellnodeParent(1,n) - mesh_cellnodeParent(2,n) = cellnodeParent(2,n) - endforall - -end subroutine mesh_build_cellconnectivity - - -!-------------------------------------------------------------------------------------------------- -!> @brief Calculate position of cellnodes from the given position of nodes -!> Build list of cellnodes' coordinates. -!> Cellnode coordinates are calculated from a weighted sum of node coordinates. -!-------------------------------------------------------------------------------------------------- -function mesh_build_cellnodes(nodes,Ncellnodes) - - implicit none - integer(pInt), intent(in) :: Ncellnodes !< requested number of cellnodes - real(pReal), dimension(3,mesh_Nnodes), intent(in) :: nodes - real(pReal), dimension(3,Ncellnodes) :: mesh_build_cellnodes - - integer(pInt) :: & - e,n,m, & - localCellnodeID - real(pReal), dimension(3) :: & - myCoords - - mesh_build_cellnodes = 0.0_pReal -!$OMP PARALLEL DO PRIVATE(e,localCellnodeID,myCoords) - do n = 1_pInt,Ncellnodes ! loop over cell nodes - e = mesh_cellnodeParent(1,n) - localCellnodeID = mesh_cellnodeParent(2,n) - myCoords = 0.0_pReal - do m = 1_pInt,theMesh%elem%nNodes - myCoords = myCoords + nodes(1:3,mesh_element(4_pInt+m,e)) & - * theMesh%elem%cellNodeParentNodeWeights(m,localCellnodeID) - enddo - mesh_build_cellnodes(1:3,n) = myCoords / sum(theMesh%elem%cellNodeParentNodeWeights(:,localCellnodeID)) - enddo -!$OMP END PARALLEL DO - -end function mesh_build_cellnodes - - -!-------------------------------------------------------------------------------------------------- -!> @brief Calculates IP Coordinates. Allocates global array 'mesh_ipCoordinates' -! Called by all solvers in mesh_init in order to initialize the ip coordinates. -! Later on the current ip coordinates are directly prvided by the spectral solver and by Abaqus, -! so no need to use this subroutine anymore; Marc however only provides nodal displacements, -! so in this case the ip coordinates are always calculated on the basis of this subroutine. -! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -! FOR THE MOMENT THIS SUBROUTINE ACTUALLY CALCULATES THE CELL CENTER AND NOT THE IP COORDINATES, -! AS THE IP IS NOT (ALWAYS) LOCATED IN THE CENTER OF THE IP VOLUME. -! HAS TO BE CHANGED IN A LATER VERSION. -! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!-------------------------------------------------------------------------------------------------- + mesh_build_ipAreas(1:2,1,:) = geomSize(2)/real(grid(2)) * geomSize(3)/real(grid(3)) + mesh_build_ipAreas(3:4,1,:) = geomSize(3)/real(grid(3)) * geomSize(1)/real(grid(1)) + mesh_build_ipAreas(5:6,1,:) = geomSize(1)/real(grid(1)) * geomSize(2)/real(grid(2)) + +end function mesh_build_ipAreas !-------------------------------------------------------------------------------------------------- !> @brief calculation of IP interface areas, allocate globals '_ipArea', and '_ipAreaNormal' !-------------------------------------------------------------------------------------------------- -subroutine mesh_build_ipAreas - use math, only: & - math_crossproduct +subroutine mesh_build_ipAreas2 - implicit none - integer(pInt) :: e,t,g,c,i,f,n,m - real(pReal), dimension (3,FE_maxNcellnodesPerCellface) :: nodePos, normals - real(pReal), dimension(3) :: normal + allocate(mesh_ipAreaNormal(3,6,1,theMesh%nElems), source=0.0_pReal) - allocate(mesh_ipArea(theMesh%elem%nIPneighbors,theMesh%elem%nIPs,theMesh%nElems), source=0.0_pReal) - allocate(mesh_ipAreaNormal(3_pInt,theMesh%elem%nIPneighbors,theMesh%elem%nIPs,theMesh%nElems), source=0.0_pReal) - - !$OMP PARALLEL DO PRIVATE(t,g,c,nodePos,normal,normals) - do e = 1_pInt,theMesh%nElems ! loop over cpElems - c = theMesh%elem%cellType - select case (c) - - case (4_pInt) - ! for this cell type we get the normal of the quadrilateral face as an average of - ! four normals of triangular subfaces; since the face consists only of two triangles, - ! the sum has to be divided by two; this whole prcedure tries to compensate for - ! probable non-planar cell surfaces - m = FE_NcellnodesPerCellface(c) - do i = 1_pInt,theMesh%elem%nIPs ! loop over ips=cells in this element - do f = 1_pInt,FE_NipNeighbors(c) ! loop over cell faces - forall(n = 1_pInt:FE_NcellnodesPerCellface(c)) & - nodePos(1:3,n) = mesh_cellnode(1:3,mesh_cell(FE_cellface(n,f,c),i,e)) - forall(n = 1_pInt:FE_NcellnodesPerCellface(c)) & - normals(1:3,n) = 0.5_pReal & - * math_crossproduct(nodePos(1:3,1+mod(n ,m)) - nodePos(1:3,n), & - nodePos(1:3,1+mod(n+1,m)) - nodePos(1:3,n)) - normal = 0.5_pReal * sum(normals,2) - mesh_ipArea(f,i,e) = norm2(normal) - mesh_ipAreaNormal(1:3,f,i,e) = normal / norm2(normal) - enddo - enddo - - end select - enddo - !$OMP END PARALLEL DO - -end subroutine mesh_build_ipAreas - - -!-------------------------------------------------------------------------------------------------- -!> @brief get properties of different types of finite elements -!> @details assign globals: FE_nodesAtIP, FE_ipNeighbor, FE_subNodeOnIPFace -!-------------------------------------------------------------------------------------------------- -subroutine mesh_build_FEdata - - implicit none - integer(pInt) :: me - allocate(FE_cellface(FE_maxNcellnodesPerCellface,FE_maxNcellfaces,FE_Ncelltypes), source=0_pInt) - - - ! *** FE_cellface *** - me = 0_pInt - - me = me + 1_pInt - FE_cellface(1:FE_NcellnodesPerCellface(me),1:FE_NipNeighbors(me),me) = & ! 2D 3node, VTK_TRIANGLE (5) - reshape(int([& - 2,3, & - 3,1, & - 1,2 & - ],pInt),[FE_NcellnodesPerCellface(me),FE_NipNeighbors(me)]) - - me = me + 1_pInt - FE_cellface(1:FE_NcellnodesPerCellface(me),1:FE_NipNeighbors(me),me) = & ! 2D 4node, VTK_QUAD (9) - reshape(int([& - 2,3, & - 4,1, & - 3,4, & - 1,2 & - ],pInt),[FE_NcellnodesPerCellface(me),FE_NipNeighbors(me)]) - - me = me + 1_pInt - FE_cellface(1:FE_NcellnodesPerCellface(me),1:FE_NipNeighbors(me),me) = & ! 3D 4node, VTK_TETRA (10) - reshape(int([& - 1,3,2, & - 1,2,4, & - 2,3,4, & - 1,4,3 & - ],pInt),[FE_NcellnodesPerCellface(me),FE_NipNeighbors(me)]) - - me = me + 1_pInt - FE_cellface(1:FE_NcellnodesPerCellface(me),1:FE_NipNeighbors(me),me) = & ! 3D 8node, VTK_HEXAHEDRON (12) - reshape(int([& - 2,3,7,6, & - 4,1,5,8, & - 3,4,8,7, & - 1,2,6,5, & - 5,6,7,8, & - 1,4,3,2 & - ],pInt),[FE_NcellnodesPerCellface(me),FE_NipNeighbors(me)]) + mesh_ipAreaNormal(1:3,1,1,:) = spread([+1.0_pReal, 0.0_pReal, 0.0_pReal],2,theMesh%nElems) + mesh_ipAreaNormal(1:3,2,1,:) = spread([-1.0_pReal, 0.0_pReal, 0.0_pReal],2,theMesh%nElems) + mesh_ipAreaNormal(1:3,3,1,:) = spread([ 0.0_pReal,+1.0_pReal, 0.0_pReal],2,theMesh%nElems) + mesh_ipAreaNormal(1:3,4,1,:) = spread([ 0.0_pReal,-1.0_pReal, 0.0_pReal],2,theMesh%nElems) + mesh_ipAreaNormal(1:3,5,1,:) = spread([ 0.0_pReal, 0.0_pReal,+1.0_pReal],2,theMesh%nElems) + mesh_ipAreaNormal(1:3,6,1,:) = spread([ 0.0_pReal, 0.0_pReal,-1.0_pReal],2,theMesh%nElems) - -end subroutine mesh_build_FEdata +end subroutine mesh_build_ipAreas2 end module mesh From c9f1f8756d48a632df05cb9bac2c35b500edd171 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 May 2019 06:06:01 +0200 Subject: [PATCH 010/120] better name/not needed --- src/mesh_grid.f90 | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/mesh_grid.f90 b/src/mesh_grid.f90 index a7da77bf0..320024dc3 100644 --- a/src/mesh_grid.f90 +++ b/src/mesh_grid.f90 @@ -35,7 +35,7 @@ module mesh mesh_unitlength !< physical length of one unit in mesh real(pReal), dimension(:,:), allocatable, private :: & - mesh_node !< node x,y,z coordinates (after deformation! ONLY FOR MARC!!!) + mesh_node !< node x,y,z coordinates (after deformation! ONLY FOR MARC!!!) real(pReal), dimension(:,:), allocatable, public, protected :: & @@ -54,14 +54,7 @@ module mesh logical, dimension(3), public, parameter :: mesh_periodicSurface = .true. !< flag indicating periodic outer surfaces (used for fluxes) - integer(pInt),dimension(:,:,:), allocatable, private :: & - mesh_cell !< cell connectivity for each element,ip/cell - - integer(pInt), parameter, private :: & - FE_Ngeomtypes = 10_pInt, & - FE_Ncelltypes = 4_pInt, & - FE_maxNcellnodesPerCell = 8_pInt - +! grid specific integer(pInt), dimension(3), public, protected :: & grid !< (global) grid integer(pInt), public, protected :: & @@ -79,6 +72,7 @@ module mesh private :: & mesh_build_ipAreas, & + mesh_build_ipNormals, & mesh_spectral_build_nodes, & mesh_spectral_build_elements, & mesh_spectral_build_ipNeighborhood, & @@ -198,8 +192,8 @@ subroutine mesh_init(ip,el) if (myDebug) write(6,'(a)') ' Built IP coordinates'; flush(6) allocate(mesh_ipVolume(1,theMesh%nElems),source=product([geomSize(1:2),size3]/real([grid(1:2),grid3]))) if (myDebug) write(6,'(a)') ' Built IP volumes'; flush(6) - mesh_ipArea = mesh_build_ipAreas() - call mesh_build_ipAreas2 + mesh_ipArea = mesh_build_ipAreas() + mesh_ipAreaNormal = mesh_build_ipNormals() if (myDebug) write(6,'(a)') ' Built IP areas'; flush(6) call mesh_spectral_build_ipNeighborhood @@ -220,7 +214,7 @@ subroutine mesh_init(ip,el) theMesh%homogenizationAt = mesh_element(3,:) theMesh%microstructureAt = mesh_element(4,:) !!!!!!!!!!!!!!!!!!!!!!!! - deallocate(mesh_cell) + end subroutine mesh_init @@ -612,18 +606,18 @@ end function mesh_build_ipAreas !-------------------------------------------------------------------------------------------------- !> @brief calculation of IP interface areas, allocate globals '_ipArea', and '_ipAreaNormal' !-------------------------------------------------------------------------------------------------- -subroutine mesh_build_ipAreas2 +pure function mesh_build_ipNormals() - allocate(mesh_ipAreaNormal(3,6,1,theMesh%nElems), source=0.0_pReal) + real, dimension(3,6,1,theMesh%nElems) :: mesh_build_ipNormals - mesh_ipAreaNormal(1:3,1,1,:) = spread([+1.0_pReal, 0.0_pReal, 0.0_pReal],2,theMesh%nElems) - mesh_ipAreaNormal(1:3,2,1,:) = spread([-1.0_pReal, 0.0_pReal, 0.0_pReal],2,theMesh%nElems) - mesh_ipAreaNormal(1:3,3,1,:) = spread([ 0.0_pReal,+1.0_pReal, 0.0_pReal],2,theMesh%nElems) - mesh_ipAreaNormal(1:3,4,1,:) = spread([ 0.0_pReal,-1.0_pReal, 0.0_pReal],2,theMesh%nElems) - mesh_ipAreaNormal(1:3,5,1,:) = spread([ 0.0_pReal, 0.0_pReal,+1.0_pReal],2,theMesh%nElems) - mesh_ipAreaNormal(1:3,6,1,:) = spread([ 0.0_pReal, 0.0_pReal,-1.0_pReal],2,theMesh%nElems) + mesh_build_ipNormals(1:3,1,1,:) = spread([+1.0_pReal, 0.0_pReal, 0.0_pReal],2,theMesh%nElems) + mesh_build_ipNormals(1:3,2,1,:) = spread([-1.0_pReal, 0.0_pReal, 0.0_pReal],2,theMesh%nElems) + mesh_build_ipNormals(1:3,3,1,:) = spread([ 0.0_pReal,+1.0_pReal, 0.0_pReal],2,theMesh%nElems) + mesh_build_ipNormals(1:3,4,1,:) = spread([ 0.0_pReal,-1.0_pReal, 0.0_pReal],2,theMesh%nElems) + mesh_build_ipNormals(1:3,5,1,:) = spread([ 0.0_pReal, 0.0_pReal,+1.0_pReal],2,theMesh%nElems) + mesh_build_ipNormals(1:3,6,1,:) = spread([ 0.0_pReal, 0.0_pReal,-1.0_pReal],2,theMesh%nElems) -end subroutine mesh_build_ipAreas2 +end function mesh_build_ipNormals end module mesh From 8dea95879c22fadfde569e8b6704246f8ddcd45a Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 May 2019 07:22:29 +0200 Subject: [PATCH 011/120] specific for nonlocal, can be calculated during post processing --- src/crystallite.f90 | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/crystallite.f90 b/src/crystallite.f90 index 02aec8b7a..41d1cb1c3 100644 --- a/src/crystallite.f90 +++ b/src/crystallite.f90 @@ -87,7 +87,6 @@ module crystallite enumerator :: undefined_ID, & phase_ID, & texture_ID, & - volume_ID, & orientation_ID, & grainrotation_ID, & defgrad_ID, & @@ -273,8 +272,6 @@ subroutine crystallite_init crystallite_outputID(o,c) = phase_ID case ('texture') outputName crystallite_outputID(o,c) = texture_ID - case ('volume') outputName - crystallite_outputID(o,c) = volume_ID case ('orientation') outputName crystallite_outputID(o,c) = orientation_ID case ('grainrotation') outputName @@ -323,7 +320,7 @@ subroutine crystallite_init do r = 1,size(config_crystallite) do o = 1,crystallite_Noutput(r) select case(crystallite_outputID(o,r)) - case(phase_ID,texture_ID,volume_ID) + case(phase_ID,texture_ID) mySize = 1 case(orientation_ID,grainrotation_ID) mySize = 4 @@ -948,7 +945,6 @@ function crystallite_postResults(ipc, ip, el) use mesh, only: & theMesh, & mesh_element, & - mesh_ipVolume, & mesh_ipNeighborhood use material, only: & plasticState, & @@ -999,11 +995,6 @@ function crystallite_postResults(ipc, ip, el) case (texture_ID) mySize = 1 crystallite_postResults(c+1) = real(material_texture(ipc,ip,el),pReal) ! textureID of grain - case (volume_ID) - mySize = 1 - detF = math_det33(crystallite_partionedF(1:3,1:3,ipc,ip,el)) ! V_current = det(F) * V_reference - crystallite_postResults(c+1) = detF * mesh_ipVolume(ip,el) & - / real(homogenization_Ngrains(mesh_element(3,el)),pReal) ! grain volume (not fraction but absolute) case (orientation_ID) mySize = 4 crystallite_postResults(c+1:c+mySize) = crystallite_orientation(ipc,ip,el)%asQuaternion() From a8b9b5d1c901ce6f5750a9c7807054d73794e3d8 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 May 2019 08:11:23 +0200 Subject: [PATCH 012/120] homogenizationAt array had wrong shape for MPI (too large) --- src/crystallite.f90 | 2 +- src/mesh_grid.f90 | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/crystallite.f90 b/src/crystallite.f90 index 41d1cb1c3..e972ff162 100644 --- a/src/crystallite.f90 +++ b/src/crystallite.f90 @@ -299,7 +299,7 @@ subroutine crystallite_init case ('neighboringelement') outputName ! ToDo: this is not a result, it is static. Should be written out by mesh crystallite_outputID(o,c) = neighboringelement_ID case default outputName - call IO_error(105,ext_msg=trim(str(o))//' (Crystallite)') + !call IO_error(105,ext_msg=trim(str(o))//' (Crystallite)') end select outputName enddo enddo diff --git a/src/mesh_grid.f90 b/src/mesh_grid.f90 index 320024dc3..685a53ba8 100644 --- a/src/mesh_grid.f90 +++ b/src/mesh_grid.f90 @@ -13,12 +13,7 @@ module mesh implicit none private integer(pInt), public, protected :: & - mesh_Nnodes, & !< total number of nodes in mesh - mesh_Ncellnodes, & !< total number of cell nodes in mesh (including duplicates) - mesh_Ncells, & !< total number of cells in mesh - mesh_maxNipNeighbors, & !< max number of IP neighbors in any CP element - mesh_maxNsharedElems !< max number of CP elements sharing a node - + mesh_Nnodes integer(pInt), dimension(:), allocatable, private :: & microGlobal @@ -138,9 +133,8 @@ subroutine mesh_init(ip,el) implicit none include 'fftw3-mpi.f03' integer(C_INTPTR_T) :: devNull, local_K, local_K_offset - integer :: ierr, worldsize, i + integer :: ierr, worldsize, j integer(pInt), intent(in), optional :: el, ip - integer(pInt) :: j logical :: myDebug write(6,'(/,a)') ' <<<+- mesh init -+>>>' @@ -179,10 +173,10 @@ subroutine mesh_init(ip,el) call theMesh%init(mesh_node) call theMesh%setNelems(product(grid(1:2))*grid3) - mesh_homogenizationAt = mesh_homogenizationAt(product(grid(1:2))*grid3) ! reallocate/shrink in case of MPI - mesh_maxNipNeighbors = theMesh%elem%nIPneighbors - call mesh_spectral_build_elements() + mesh_homogenizationAt = mesh_homogenizationAt(product(grid(1:2))*grid3Offset+1: & + product(grid(1:2))*(grid3Offset+grid3)) ! reallocate/shrink in case of MPI + if (myDebug) write(6,'(a)') ' Built elements'; flush(6) From 4bce087d3d44350aa591b9bfefd103d2e3aa446d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 May 2019 11:32:25 +0200 Subject: [PATCH 013/120] separating functionality (stub only) - mesh (initialization depends on type of solver) only provides information about number of elements, IPs and writes out displacements - new module (will get setter functions for solver specific initialization) will provide information that is only used by the nonlocal model --- src/commercialFEM_fileList.f90 | 1 + src/geometry_plastic_nonlocal.f90 | 28 ++++++++++++++++++++++++++++ src/plastic_nonlocal.f90 | 11 ++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/geometry_plastic_nonlocal.f90 diff --git a/src/commercialFEM_fileList.f90 b/src/commercialFEM_fileList.f90 index 0ae1323f0..ef3870ece 100644 --- a/src/commercialFEM_fileList.f90 +++ b/src/commercialFEM_fileList.f90 @@ -28,6 +28,7 @@ #endif #include "material.f90" #include "lattice.f90" +#include "geometry_plastic_nonlocal.f90" #include "source_thermal_dissipation.f90" #include "source_thermal_externalheat.f90" #include "source_damage_isoBrittle.f90" diff --git a/src/geometry_plastic_nonlocal.f90 b/src/geometry_plastic_nonlocal.f90 new file mode 100644 index 000000000..579004b2f --- /dev/null +++ b/src/geometry_plastic_nonlocal.f90 @@ -0,0 +1,28 @@ +!-------------------------------------------------------------------------------------------------- +!> @author Philip Eisenlohr, Max-Planck-Institut für Eisenforschung GmbH +!> @author Christoph Koords, Max-Planck-Institut für Eisenforschung GmbH +!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH +!> @brief Geometric information about the IP cells needed for the nonlocal +! plasticity model +!-------------------------------------------------------------------------------------------------- +module geometry_plastic_nonlocal + use prec + + implicit none + private + logical, dimension(3), public, parameter :: & + geometry_plastic_nonlocal_periodicSurface = .true. !< flag indicating periodic outer surfaces (used for fluxes) NEEDED? + + integer, dimension(:,:,:,:), allocatable, public, protected :: & + geometry_plastic_nonlocal_IPneighborhood !< 6 or less neighboring IPs as [element_num, IP_index, neighbor_index that points to me] + + real(pReal), dimension(:,:), allocatable, public, protected :: & + geometry_plastic_nonlocal_IPvolume !< volume associated with IP (initially!) + + real(pReal), dimension(:,:,:), allocatable, public, protected :: & + geometry_plastic_nonlocal_IParea !< area of interface to neighboring IP (initially!) + + real(pReal),dimension(:,:,:,:), allocatable, public, protected :: & + geometry_plastic_nonlocal_IPareaNormal !< area normal of interface to neighboring IP (initially!) + +end module geometry_plastic_nonlocal diff --git a/src/plastic_nonlocal.f90 b/src/plastic_nonlocal.f90 index 6097bbbc8..66e8f8980 100644 --- a/src/plastic_nonlocal.f90 +++ b/src/plastic_nonlocal.f90 @@ -5,10 +5,15 @@ !> @brief material subroutine for plasticity including dislocation flux !-------------------------------------------------------------------------------------------------- module plastic_nonlocal - use prec, only: & - pReal + use prec use future - + use geometry_plastic_nonlocal, only: & + periodicSurface => geometry_plastic_nonlocal_periodicSurface, & + IPneighborhood => geometry_plastic_nonlocal_IPneighborhood, & + IPvolume => geometry_plastic_nonlocal_IPvolume, & + IParea => geometry_plastic_nonlocal_IParea, & + IPareaNormal => geometry_plastic_nonlocal_IPareaNormal + implicit none private real(pReal), parameter, private :: & From 0dbc6fb435f0dc503410672894c08deb89de516e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 May 2019 11:52:28 +0200 Subject: [PATCH 014/120] usage example --- src/commercialFEM_fileList.f90 | 2 +- src/geometry_plastic_nonlocal.f90 | 24 ++++++++++++++++++++++++ src/mesh_grid.f90 | 4 +++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/commercialFEM_fileList.f90 b/src/commercialFEM_fileList.f90 index ef3870ece..1c7287813 100644 --- a/src/commercialFEM_fileList.f90 +++ b/src/commercialFEM_fileList.f90 @@ -14,6 +14,7 @@ #include "Lambert.f90" #include "rotations.f90" #include "FEsolving.f90" +#include "geometry_plastic_nonlocal.f90" #include "element.f90" #include "mesh_base.f90" #ifdef Abaqus @@ -28,7 +29,6 @@ #endif #include "material.f90" #include "lattice.f90" -#include "geometry_plastic_nonlocal.f90" #include "source_thermal_dissipation.f90" #include "source_thermal_externalheat.f90" #include "source_damage_isoBrittle.f90" diff --git a/src/geometry_plastic_nonlocal.f90 b/src/geometry_plastic_nonlocal.f90 index 579004b2f..0b63b7f9c 100644 --- a/src/geometry_plastic_nonlocal.f90 +++ b/src/geometry_plastic_nonlocal.f90 @@ -24,5 +24,29 @@ module geometry_plastic_nonlocal real(pReal),dimension(:,:,:,:), allocatable, public, protected :: & geometry_plastic_nonlocal_IPareaNormal !< area normal of interface to neighboring IP (initially!) + + public :: & + geometry_plastic_nonlocal_set_IPneighborhood, & + geometry_plastic_nonlocal_set_IPvolume + + contains + +subroutine geometry_plastic_nonlocal_set_IPneighborhood(IPneighborhood) + + integer, dimension(:,:,:,:), intent(in) :: IPneighborhood + + geometry_plastic_nonlocal_IPneighborhood = IPneighborhood + +end subroutine geometry_plastic_nonlocal_set_IPneighborhood + + +subroutine geometry_plastic_nonlocal_set_IPvolume(IPvolume) + + real(pReal), dimension(:,:), intent(in) :: IPvolume + + geometry_plastic_nonlocal_IPvolume = IPvolume + +end subroutine geometry_plastic_nonlocal_set_IPvolume + end module geometry_plastic_nonlocal diff --git a/src/mesh_grid.f90 b/src/mesh_grid.f90 index 685a53ba8..d873e3542 100644 --- a/src/mesh_grid.f90 +++ b/src/mesh_grid.f90 @@ -7,7 +7,8 @@ !-------------------------------------------------------------------------------------------------- module mesh use, intrinsic :: iso_c_binding - use prec, only: pReal, pInt + use prec + use geometry_plastic_nonlocal use mesh_base implicit none @@ -191,6 +192,7 @@ subroutine mesh_init(ip,el) if (myDebug) write(6,'(a)') ' Built IP areas'; flush(6) call mesh_spectral_build_ipNeighborhood + call geometry_plastic_nonlocal_set_IPneighborhood(mesh_ipNeighborhood) if (myDebug) write(6,'(a)') ' Built IP neighborhood'; flush(6) From 028bdcff22aed5717f70f63a07a8ee8f5fa3716d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 16 May 2019 22:24:42 +0200 Subject: [PATCH 015/120] less compiler complaints --- src/crystallite.f90 | 5 ----- src/damage_local.f90 | 2 +- src/kinematics_cleavage_opening.f90 | 2 +- src/kinematics_slipplane_opening.f90 | 2 +- src/thermal_adiabatic.f90 | 1 - 5 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/crystallite.f90 b/src/crystallite.f90 index 3116345b6..dce93695a 100644 --- a/src/crystallite.f90 +++ b/src/crystallite.f90 @@ -1125,9 +1125,6 @@ subroutine crystallite_results use config, only: & config_name_phase => phase_name ! anticipate logical name - use material, only: & - material_phase_plasticity_type => phase_plasticity - integer :: p,o real(pReal), allocatable, dimension(:,:,:) :: selected_tensors type(rotation), allocatable, dimension(:) :: selected_rotations @@ -2588,8 +2585,6 @@ logical function stateJump(ipc,ip,el) sourceState, & phase_Nsources, & phaseAt, phasememberAt - use mesh, only: & - mesh_element use constitutive, only: & constitutive_collectDeltaState diff --git a/src/damage_local.f90 b/src/damage_local.f90 index 1ec42f863..2db8cccc1 100644 --- a/src/damage_local.f90 +++ b/src/damage_local.f90 @@ -61,7 +61,7 @@ subroutine damage_local_init config_homogenization - integer :: maxNinstance,homog,instance,o,i + integer :: maxNinstance,homog,instance,i integer :: sizeState integer :: NofMyHomog, h integer(kind(undefined_ID)) :: & diff --git a/src/kinematics_cleavage_opening.f90 b/src/kinematics_cleavage_opening.f90 index 349551d4d..a79dc4042 100644 --- a/src/kinematics_cleavage_opening.f90 +++ b/src/kinematics_cleavage_opening.f90 @@ -71,7 +71,7 @@ subroutine kinematics_cleavage_opening_init() integer, allocatable, dimension(:) :: tempInt real(pReal), allocatable, dimension(:) :: tempFloat - integer :: maxNinstance,p,instance,kinematics + integer :: maxNinstance,p,instance write(6,'(/,a)') ' <<<+- kinematics_'//KINEMATICS_cleavage_opening_LABEL//' init -+>>>' diff --git a/src/kinematics_slipplane_opening.f90 b/src/kinematics_slipplane_opening.f90 index 7a0b2fe99..f29c0e252 100644 --- a/src/kinematics_slipplane_opening.f90 +++ b/src/kinematics_slipplane_opening.f90 @@ -57,7 +57,7 @@ subroutine kinematics_slipplane_opening_init() use lattice - integer :: maxNinstance,p,instance,kinematics + integer :: maxNinstance,p,instance write(6,'(/,a)') ' <<<+- kinematics_'//KINEMATICS_slipplane_opening_LABEL//' init -+>>>' diff --git a/src/thermal_adiabatic.f90 b/src/thermal_adiabatic.f90 index bfc34d1c4..bfd5633d1 100644 --- a/src/thermal_adiabatic.f90 +++ b/src/thermal_adiabatic.f90 @@ -163,7 +163,6 @@ subroutine thermal_adiabatic_getSourceAndItsTangent(Tdot, dTdot_dT, T, ip, el) use material, only: & homogenization_Ngrains, & material_homogenizationAt, & - mappingHomogenization, & phaseAt, & phasememberAt, & thermal_typeInstance, & From 01e3b646c288e1e35535491981cd8304e21f19dd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 16 May 2019 22:56:48 +0200 Subject: [PATCH 016/120] don't clutter the code with useless stuff we only need to be more strict about prefixing functions/subroutines/variables to see in which module they reside --- src/Lambert.f90 | 17 +- src/config.f90 | 42 ++-- src/crystallite.f90 | 323 +++-------------------------- src/lattice.f90 | 208 +++++-------------- src/plastic_dislotwin.f90 | 103 ++------- src/plastic_isotropic.f90 | 63 ++---- src/plastic_kinematichardening.f90 | 62 ++---- src/plastic_none.f90 | 7 +- src/plastic_phenopowerlaw.f90 | 50 ++--- src/quaternions.f90 | 5 +- src/rotations.f90 | 86 +------- 11 files changed, 184 insertions(+), 782 deletions(-) diff --git a/src/Lambert.f90 b/src/Lambert.f90 index c7b2c0d49..601cf9984 100644 --- a/src/Lambert.f90 +++ b/src/Lambert.f90 @@ -42,7 +42,8 @@ module Lambert implicit none private - real(pReal), parameter, private :: & + + real(pReal), parameter :: & SPI = sqrt(PI), & PREF = sqrt(6.0_pReal/PI), & A = PI**(5.0_pReal/6.0_pReal)/6.0_pReal**(1.0_pReal/6.0_pReal), & @@ -55,10 +56,8 @@ module Lambert PREK = R1 * 2.0_pReal**(1.0_pReal/4.0_pReal)/BETA public :: & - LambertCubeToBall, & - LambertBallToCube - private :: & - GetPyramidOrder + Lambert_CubeToBall, & + Lambert_BallToCube contains @@ -68,7 +67,7 @@ contains !> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH !> @brief map from 3D cubic grid to 3D ball !-------------------------------------------------------------------------- -function LambertCubeToBall(cube) result(ball) +function Lambert_CubeToBall(cube) result(ball) real(pReal), intent(in), dimension(3) :: cube real(pReal), dimension(3) :: ball, LamXYZ, XYZ @@ -116,7 +115,7 @@ function LambertCubeToBall(cube) result(ball) endif center -end function LambertCubeToBall +end function Lambert_CubeToBall !-------------------------------------------------------------------------- @@ -124,7 +123,7 @@ end function LambertCubeToBall !> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH !> @brief map from 3D ball to 3D cubic grid !-------------------------------------------------------------------------- -pure function LambertBallToCube(xyz) result(cube) +pure function Lambert_BallToCube(xyz) result(cube) real(pReal), intent(in), dimension(3) :: xyz real(pReal), dimension(3) :: cube, xyz1, xyz3 @@ -170,7 +169,7 @@ pure function LambertBallToCube(xyz) result(cube) endif center -end function LambertBallToCube +end function Lambert_BallToCube !-------------------------------------------------------------------------- diff --git a/src/config.f90 b/src/config.f90 index 6bc9e9c0b..8729014ce 100644 --- a/src/config.f90 +++ b/src/config.f90 @@ -7,21 +7,26 @@ !-------------------------------------------------------------------------------------------------- module config use prec + use DAMASK_interface + use IO + use debug use list implicit none private - type(tPartitionedStringList), public, protected, allocatable, dimension(:) :: & + + type(tPartitionedStringList), public, protected, allocatable, dimension(:) :: & config_phase, & config_microstructure, & config_homogenization, & config_texture, & config_crystallite - type(tPartitionedStringList), public, protected :: & + type(tPartitionedStringList), public, protected :: & config_numerics, & config_debug + !ToDo: bad names (how should one know that those variables are defined in config?) character(len=64), dimension(:), allocatable, public, protected :: & phase_name, & !< name of each phase homogenization_name, & !< name of each homogenization @@ -45,19 +50,9 @@ contains !> @brief reads material.config and stores its content per part !-------------------------------------------------------------------------------------------------- subroutine config_init - use DAMASK_interface, only: & - getSolverJobName - use IO, only: & - IO_read_ASCII, & - IO_error, & - IO_lc, & - IO_getTag - use debug, only: & - debug_level, & - debug_material, & - debug_levelBasic - integer :: myDebug,i + integer :: i + logical :: verbose character(len=pStringLen) :: & line, & @@ -67,7 +62,7 @@ subroutine config_init write(6,'(/,a)') ' <<<+- config init -+>>>' - myDebug = debug_level(debug_material) + verbose = iand(debug_level(debug_material),debug_levelBasic) /= 0 inquire(file=trim(getSolverJobName())//'.materialConfig',exist=fileExists) if(fileExists) then @@ -87,23 +82,23 @@ subroutine config_init case (trim('phase')) call parse_materialConfig(phase_name,config_phase,line,fileContent(i+1:)) - if (iand(myDebug,debug_levelBasic) /= 0) write(6,'(a)') ' Phase parsed'; flush(6) + if (verbose) write(6,'(a)') ' Phase parsed'; flush(6) case (trim('microstructure')) call parse_materialConfig(microstructure_name,config_microstructure,line,fileContent(i+1:)) - if (iand(myDebug,debug_levelBasic) /= 0) write(6,'(a)') ' Microstructure parsed'; flush(6) + if (verbose) write(6,'(a)') ' Microstructure parsed'; flush(6) case (trim('crystallite')) call parse_materialConfig(crystallite_name,config_crystallite,line,fileContent(i+1:)) - if (iand(myDebug,debug_levelBasic) /= 0) write(6,'(a)') ' Crystallite parsed'; flush(6) + if (verbose) write(6,'(a)') ' Crystallite parsed'; flush(6) case (trim('homogenization')) call parse_materialConfig(homogenization_name,config_homogenization,line,fileContent(i+1:)) - if (iand(myDebug,debug_levelBasic) /= 0) write(6,'(a)') ' Homogenization parsed'; flush(6) + if (verbose) write(6,'(a)') ' Homogenization parsed'; flush(6) case (trim('texture')) call parse_materialConfig(texture_name,config_texture,line,fileContent(i+1:)) - if (iand(myDebug,debug_levelBasic) /= 0) write(6,'(a)') ' Texture parsed'; flush(6) + if (verbose) write(6,'(a)') ' Texture parsed'; flush(6) end select @@ -141,8 +136,6 @@ contains !! Recursion is triggered by "{path/to/inputfile}" in a line !-------------------------------------------------------------------------------------------------- recursive function read_materialConfig(fileName,cnt) result(fileContent) - use IO, only: & - IO_warning character(len=*), intent(in) :: fileName integer, intent(in), optional :: cnt !< recursion counter @@ -226,9 +219,6 @@ end function read_materialConfig subroutine parse_materialConfig(sectionNames,part,line, & fileContent) - use IO, only: & - IO_intOut - character(len=64), allocatable, dimension(:), intent(out) :: sectionNames type(tPartitionedStringList), allocatable, dimension(:), intent(inout) :: part character(len=pStringLen), intent(inout) :: line @@ -298,8 +288,6 @@ end subroutine config_init !> @brief deallocates the linked lists that store the content of the configuration files !-------------------------------------------------------------------------------------------------- subroutine config_deallocate(what) - use IO, only: & - IO_error character(len=*), intent(in) :: what diff --git a/src/crystallite.f90 b/src/crystallite.f90 index dce93695a..31c859e30 100644 --- a/src/crystallite.f90 +++ b/src/crystallite.f90 @@ -9,36 +9,43 @@ !-------------------------------------------------------------------------------------------------- module crystallite - use prec, only: & - pReal, & - pStringLen - use rotations, only: & - rotation - use FEsolving, only: & - FEsolving_execElem, & - FEsolving_execIP - use material, only: & - homogenization_Ngrains + use prec + use IO + use config + use debug + use numerics + use rotations + use math + use mesh + use FEsolving + use material + use constitutive + use lattice use future + use plastic_nonlocal +#if defined(PETSc) || defined(DAMASK_HDF5) + use HDF5_utilities + use results +#endif implicit none private - character(len=64), dimension(:,:), allocatable, private :: & + character(len=64), dimension(:,:), allocatable :: & crystallite_output !< name of each post result output integer, public, protected :: & crystallite_maxSizePostResults !< description not available integer, dimension(:), allocatable, public, protected :: & crystallite_sizePostResults !< description not available - integer, dimension(:,:), allocatable, private :: & + integer, dimension(:,:), allocatable :: & crystallite_sizePostResult !< description not available real(pReal), dimension(:,:,:), allocatable, public :: & crystallite_dt !< requested time increment of each grain - real(pReal), dimension(:,:,:), allocatable, private :: & + real(pReal), dimension(:,:,:), allocatable :: & crystallite_subdt, & !< substepped time increment of each grain crystallite_subFrac, & !< already calculated fraction of increment crystallite_subStep !< size of next integration step - type(rotation), dimension(:,:,:), allocatable, private :: & + type(rotation), dimension(:,:,:), allocatable :: & crystallite_orientation, & !< orientation crystallite_orientation0 !< initial orientation real(pReal), dimension(:,:,:,:,:), allocatable, public, protected :: & @@ -63,7 +70,7 @@ module crystallite crystallite_Li, & !< current intermediate velocitiy grad (end of converged time step) crystallite_Li0, & !< intermediate velocitiy grad at start of FE inc crystallite_partionedLi0 !< intermediate velocity grad at start of homog inc - real(pReal), dimension(:,:,:,:,:), allocatable, private :: & + real(pReal), dimension(:,:,:,:,:), allocatable :: & crystallite_subS0, & !< 2nd Piola-Kirchhoff stress vector at start of crystallite inc crystallite_invFp, & !< inverse of current plastic def grad (end of converged time step) crystallite_subFp0,& !< plastic def grad at start of crystallite inc @@ -77,7 +84,7 @@ module crystallite crystallite_dPdF !< current individual dPdF per grain (end of converged time step) logical, dimension(:,:,:), allocatable, public :: & crystallite_requested !< used by upper level (homogenization) to request crystallite calculation - logical, dimension(:,:,:), allocatable, private :: & + logical, dimension(:,:,:), allocatable :: & crystallite_converged, & !< convergence flag crystallite_todo, & !< flag to indicate need for further computation crystallite_localPlasticity !< indicates this grain to have purely local constitutive law @@ -101,16 +108,16 @@ module crystallite neighboringip_ID, & neighboringelement_ID end enum - integer(kind(undefined_ID)),dimension(:,:), allocatable, private :: & + integer(kind(undefined_ID)),dimension(:,:), allocatable :: & crystallite_outputID !< ID of each post result output - type, private :: tOutput !< new requested output (per phase) + type :: tOutput !< new requested output (per phase) character(len=65536), allocatable, dimension(:) :: & label end type tOutput - type(tOutput), allocatable, dimension(:), private :: output_constituent + type(tOutput), allocatable, dimension(:) :: output_constituent - type, private :: tNumerics + type :: tNumerics integer :: & iJacoLpresiduum, & !< frequency of Jacobian update of residuum in Lp nState, & !< state loop limit @@ -138,15 +145,6 @@ module crystallite crystallite_push33ToRef, & crystallite_postResults, & crystallite_results - private :: & - integrateStress, & - integrateState, & - integrateStateFPI, & - integrateStateEuler, & - integrateStateAdaptiveEuler, & - integrateStateRK4, & - integrateStateRKCK45, & - stateJump contains @@ -155,39 +153,6 @@ contains !> @brief allocates and initialize per grain variables !-------------------------------------------------------------------------------------------------- subroutine crystallite_init -#ifdef DEBUG - use debug, only: & - debug_info, & - debug_reset, & - debug_level, & - debug_crystallite, & - debug_levelBasic -#endif - use numerics, only: & - numerics_integrator, & - worldrank, & - usePingPong - use math, only: & - math_I3, & - math_EulerToR, & - math_inv33 - use mesh, only: & - theMesh, & - mesh_element - use IO, only: & - IO_stringValue, & - IO_write_jobFile, & - IO_error - use material - use config, only: & - config_deallocate, & - config_crystallite, & - config_numerics, & - config_phase, & - crystallite_name - use constitutive, only: & - constitutive_initialFi, & - constitutive_microstructure ! derived (shortcut) quantities of given state integer, parameter :: FILEUNIT=434 logical, dimension(:,:), allocatable :: devNull @@ -478,34 +443,6 @@ end subroutine crystallite_init !> @brief calculate stress (P) !-------------------------------------------------------------------------------------------------- function crystallite_stress(dummyArgumentToPreventInternalCompilerErrorWithGCC) - use prec, only: & - tol_math_check, & - dNeq0 -#ifdef DEBUG - use debug, only: & - debug_level, & - debug_crystallite, & - debug_levelBasic, & - debug_levelExtensive, & - debug_levelSelective, & - debug_e, & - debug_i, & - debug_g -#endif - use IO, only: & - IO_warning, & - IO_error - use math, only: & - math_inv33 - use mesh, only: & - theMesh, & - mesh_element - use material, only: & - homogenization_Ngrains, & - plasticState, & - sourceState, & - phase_Nsources, & - phaseAt, phasememberAt logical, dimension(theMesh%elem%nIPs,theMesh%Nelems) :: crystallite_stress real(pReal), intent(in), optional :: & @@ -746,30 +683,6 @@ end function crystallite_stress !> @brief calculate tangent (dPdF) !-------------------------------------------------------------------------------------------------- subroutine crystallite_stressTangent - use prec, only: & - tol_math_check, & - dNeq0 - use IO, only: & - IO_warning, & - IO_error - use math, only: & - math_inv33, & - math_identity2nd, & - math_3333to99, & - math_99to3333, & - math_I3, & - math_mul3333xx3333, & - math_mul33xx33, & - math_invert2, & - math_det33 - use mesh, only: & - mesh_element - use material, only: & - homogenization_Ngrains - use constitutive, only: & - constitutive_SandItsTangents, & - constitutive_LpAndItsTangents, & - constitutive_LiAndItsTangents integer :: & c, & !< counter in integration point component loop @@ -910,19 +823,6 @@ end subroutine crystallite_stressTangent !> @brief calculates orientations !-------------------------------------------------------------------------------------------------- subroutine crystallite_orientations - use math, only: & - math_rotationalPart33, & - math_RtoQ - use material, only: & - plasticState, & - material_phase, & - homogenization_Ngrains - use mesh, only: & - mesh_element - use lattice, only: & - lattice_qDisorientation - use plastic_nonlocal, only: & - plastic_nonlocal_updateCompatibility integer & c, & !< counter in integration point component loop @@ -979,28 +879,6 @@ end function crystallite_push33ToRef !> @brief return results of particular grain !-------------------------------------------------------------------------------------------------- function crystallite_postResults(ipc, ip, el) - use math, only: & - math_det33, & - math_I3, & - inDeg - use mesh, only: & - theMesh, & - mesh_element, & - mesh_ipVolume, & - mesh_ipNeighborhood - use material, only: & - plasticState, & - sourceState, & - microstructure_crystallite, & - crystallite_Noutput, & - material_phase, & - material_texture, & - homogenization_Ngrains - use constitutive, only: & - constitutive_homogenizedC, & - constitutive_postResults - use rotations, only: & - rotation integer, intent(in):: & el, & !< element index @@ -1118,10 +996,6 @@ end function crystallite_postResults !-------------------------------------------------------------------------------------------------- subroutine crystallite_results #if defined(PETSc) || defined(DAMASK_HDF5) - use lattice - use results - use HDF5_utilities - use rotations use config, only: & config_name_phase => phase_name ! anticipate logical name @@ -1264,33 +1138,6 @@ end subroutine crystallite_results !> intermediate acceleration of the Newton-Raphson correction !-------------------------------------------------------------------------------------------------- logical function integrateStress(ipc,ip,el,timeFraction) - use, intrinsic :: & - IEEE_arithmetic - use prec, only: tol_math_check, & - dEq0 -#ifdef DEBUG - use debug, only: debug_level, & - debug_e, & - debug_i, & - debug_g, & - debug_crystallite, & - debug_levelBasic, & - debug_levelExtensive, & - debug_levelSelective -#endif - - use constitutive, only: constitutive_LpAndItsTangents, & - constitutive_LiAndItsTangents, & - constitutive_SandItsTangents - use math, only: math_mul33xx33, & - math_mul3333xx3333, & - math_inv33, & - math_det33, & - math_I3, & - math_identity2nd, & - math_3333to99, & - math_33to9, & - math_9to33 integer, intent(in):: el, & ! element index ip, & ! integration point index @@ -1690,27 +1537,6 @@ end function integrateStress !> using Fixed Point Iteration to adapt the stepsize !-------------------------------------------------------------------------------------------------- subroutine integrateStateFPI -#ifdef DEBUG - use debug, only: debug_level, & - debug_e, & - debug_i, & - debug_g, & - debug_crystallite, & - debug_levelBasic, & - debug_levelExtensive, & - debug_levelSelective -#endif - use mesh, only: & - mesh_element - use material, only: & - plasticState, & - sourceState, & - phaseAt, phasememberAt, & - phase_Nsources, & - homogenization_Ngrains - use constitutive, only: & - constitutive_plasticity_maxSizeDotState, & - constitutive_source_maxSizeDotState integer :: & NiterationState, & !< number of iterations in state loop @@ -1898,8 +1724,6 @@ end subroutine integrateStateFPI !> @brief integrate state with 1st order explicit Euler method !-------------------------------------------------------------------------------------------------- subroutine integrateStateEuler - use material, only: & - plasticState call update_dotState(1.0_pReal) call update_state(1.0_pReal) @@ -1916,19 +1740,6 @@ end subroutine integrateStateEuler !> @brief integrate stress, state with 1st order Euler method with adaptive step size !-------------------------------------------------------------------------------------------------- subroutine integrateStateAdaptiveEuler - use mesh, only: & - theMesh, & - mesh_element - use material, only: & - homogenization_Ngrains, & - plasticState, & - sourceState, & - phaseAt, phasememberAt, & - phase_Nsources, & - homogenization_maxNgrains - use constitutive, only: & - constitutive_plasticity_maxSizeDotState, & - constitutive_source_maxSizeDotState integer :: & e, & ! element index in element loop @@ -2022,14 +1833,6 @@ end subroutine integrateStateAdaptiveEuler ! ToDo: This is totally BROKEN: RK4dotState is never used!!! !-------------------------------------------------------------------------------------------------- subroutine integrateStateRK4 - use mesh, only: & - mesh_element - use material, only: & - homogenization_Ngrains, & - plasticState, & - sourceState, & - phase_Nsources, & - phaseAt, phasememberAt real(pReal), dimension(4), parameter :: & TIMESTEPFRACTION = [0.5_pReal, 0.5_pReal, 1.0_pReal, 1.0_pReal] ! factor giving the fraction of the original timestep used for Runge Kutta Integration @@ -2089,19 +1892,6 @@ end subroutine integrateStateRK4 !> adaptive step size (use 5th order solution to advance = "local extrapolation") !-------------------------------------------------------------------------------------------------- subroutine integrateStateRKCK45 - use mesh, only: & - mesh_element, & - theMesh - use material, only: & - homogenization_Ngrains, & - plasticState, & - sourceState, & - phase_Nsources, & - phaseAt, phasememberAt, & - homogenization_maxNgrains - use constitutive, only: & - constitutive_plasticity_maxSizeDotState, & - constitutive_source_maxSizeDotState real(pReal), dimension(5,5), parameter :: & A = reshape([& @@ -2284,8 +2074,6 @@ end subroutine nonlocalConvergenceCheck !> @details: For explicitEuler, RK4 and RKCK45, adaptive Euler and FPI have their on criteria !-------------------------------------------------------------------------------------------------- subroutine setConvergenceFlag - use mesh, only: & - mesh_element integer :: & e, & !< element index in element loop @@ -2324,8 +2112,6 @@ end subroutine setConvergenceFlag !> @brief Standard forwarding of state as state = state0 + dotState * (delta t) !-------------------------------------------------------------------------------------------------- subroutine update_stress(timeFraction) - use mesh, only: & - mesh_element real(pReal), intent(in) :: & timeFraction @@ -2357,8 +2143,6 @@ end subroutine update_stress !> @brief tbd !-------------------------------------------------------------------------------------------------- subroutine update_dependentState - use mesh, only: & - mesh_element use constitutive, only: & constitutive_dependentState => constitutive_microstructure @@ -2384,13 +2168,6 @@ end subroutine update_dependentState !> @brief Standard forwarding of state as state = state0 + dotState * (delta t) !-------------------------------------------------------------------------------------------------- subroutine update_state(timeFraction) - use material, only: & - plasticState, & - sourceState, & - phase_Nsources, & - phaseAt, phasememberAt - use mesh, only: & - mesh_element real(pReal), intent(in) :: & timeFraction @@ -2432,17 +2209,6 @@ end subroutine update_state !> if NaN occurs, crystallite_todo is set to FALSE. Any NaN in a nonlocal propagates to all others !-------------------------------------------------------------------------------------------------- subroutine update_dotState(timeFraction) - use, intrinsic :: & - IEEE_arithmetic - use material, only: & - plasticState, & - sourceState, & - phaseAt, phasememberAt, & - phase_Nsources - use mesh, only: & - mesh_element - use constitutive, only: & - constitutive_collectDotState real(pReal), intent(in) :: & timeFraction @@ -2489,19 +2255,7 @@ end subroutine update_DotState subroutine update_deltaState - use, intrinsic :: & - IEEE_arithmetic - use prec, only: & - dNeq0 - use mesh, only: & - mesh_element - use material, only: & - plasticState, & - sourceState, & - phase_Nsources, & - phaseAt, phasememberAt - use constitutive, only: & - constitutive_collectDeltaState + integer :: & e, & !< element index in element loop i, & !< integration point index in ip loop @@ -2566,27 +2320,6 @@ end subroutine update_deltaState !> returns true, if state jump was successfull or not needed. false indicates NaN in delta state !-------------------------------------------------------------------------------------------------- logical function stateJump(ipc,ip,el) - use, intrinsic :: & - IEEE_arithmetic - use prec, only: & - dNeq0 -#ifdef DEBUG - use debug, only: & - debug_e, & - debug_i, & - debug_g, & - debug_level, & - debug_crystallite, & - debug_levelExtensive, & - debug_levelSelective -#endif - use material, only: & - plasticState, & - sourceState, & - phase_Nsources, & - phaseAt, phasememberAt - use constitutive, only: & - constitutive_collectDeltaState integer, intent(in):: & el, & ! element index diff --git a/src/lattice.f90 b/src/lattice.f90 index 1a7508984..43fc25530 100644 --- a/src/lattice.f90 +++ b/src/lattice.f90 @@ -7,8 +7,10 @@ ! and cleavage as well as interaction among the various systems !-------------------------------------------------------------------------------------------------- module lattice - use prec, only: & - pReal + use prec + use IO + use config + use math use future implicit none @@ -28,25 +30,25 @@ module lattice !-------------------------------------------------------------------------------------------------- ! face centered cubic - integer, dimension(2), parameter, private :: & + integer, dimension(2), parameter :: & LATTICE_FCC_NSLIPSYSTEM = [12, 6] !< # of slip systems per family for fcc - integer, dimension(1), parameter, private :: & + integer, dimension(1), parameter :: & LATTICE_FCC_NTWINSYSTEM = [12] !< # of twin systems per family for fcc - integer, dimension(1), parameter, private :: & + integer, dimension(1), parameter :: & LATTICE_FCC_NTRANSSYSTEM = [12] !< # of transformation systems per family for fcc - integer, dimension(2), parameter, private :: & + integer, dimension(2), parameter :: & LATTICE_FCC_NCLEAVAGESYSTEM = [3, 4] !< # of cleavage systems per family for fcc - integer, parameter, private :: & + integer, parameter :: & LATTICE_FCC_NSLIP = sum(LATTICE_FCC_NSLIPSYSTEM), & !< total # of slip systems for fcc LATTICE_FCC_NTWIN = sum(LATTICE_FCC_NTWINSYSTEM), & !< total # of twin systems for fcc LATTICE_FCC_NTRANS = sum(LATTICE_FCC_NTRANSSYSTEM), & !< total # of transformation systems for fcc LATTICE_FCC_NCLEAVAGE = sum(LATTICE_FCC_NCLEAVAGESYSTEM) !< total # of cleavage systems for fcc - real(pReal), dimension(3+3,LATTICE_FCC_NSLIP), parameter, private :: & + real(pReal), dimension(3+3,LATTICE_FCC_NSLIP), parameter :: & LATTICE_FCC_SYSTEMSLIP = reshape(real([& ! Slip direction Plane normal ! SCHMID-BOAS notation 0, 1,-1, 1, 1, 1, & ! B2 @@ -70,11 +72,11 @@ module lattice 0, 1,-1, 0, 1, 1 & ],pReal),shape(LATTICE_FCC_SYSTEMSLIP)) !< Slip system <110>{111} directions. Sorted according to Eisenlohr & Hantcherli - character(len=*), dimension(2), parameter, private :: LATTICE_FCC_SLIPFAMILY_NAME = & + character(len=*), dimension(2), parameter :: LATTICE_FCC_SLIPFAMILY_NAME = & ['<0 1 -1>{1 1 1}', & '<0 1 -1>{0 1 1}'] - real(pReal), dimension(3+3,LATTICE_FCC_NTWIN), parameter, private :: & + real(pReal), dimension(3+3,LATTICE_FCC_NTWIN), parameter :: & LATTICE_FCC_SYSTEMTWIN = reshape(real( [& -2, 1, 1, 1, 1, 1, & 1,-2, 1, 1, 1, 1, & @@ -90,7 +92,7 @@ module lattice -1, 1, 2, -1, 1,-1 & ],pReal),shape(LATTICE_FCC_SYSTEMTWIN)) !< Twin system <112>{111} directions. Sorted according to Eisenlohr & Hantcherli - character(len=*), dimension(1), parameter, private :: LATTICE_FCC_TWINFAMILY_NAME = & + character(len=*), dimension(1), parameter :: LATTICE_FCC_TWINFAMILY_NAME = & ['<-2 1 1>{1 1 1}'] @@ -110,7 +112,7 @@ module lattice 10,11 & ],shape(LATTICE_FCC_TWINNUCLEATIONSLIPPAIR)) - real(pReal), dimension(3+3,LATTICE_FCC_NCLEAVAGE), parameter, private :: & + real(pReal), dimension(3+3,LATTICE_FCC_NCLEAVAGE), parameter :: & LATTICE_FCC_SYSTEMCLEAVAGE = reshape(real([& ! Cleavage direction Plane normal 0, 1, 0, 1, 0, 0, & @@ -124,21 +126,21 @@ module lattice !-------------------------------------------------------------------------------------------------- ! body centered cubic - integer, dimension(2), parameter, private :: & + integer, dimension(2), parameter :: & LATTICE_BCC_NSLIPSYSTEM = [12, 12] !< # of slip systems per family for bcc - integer, dimension(1), parameter, private :: & + integer, dimension(1), parameter :: & LATTICE_BCC_NTWINSYSTEM = [12] !< # of twin systems per family for bcc - integer, dimension(2), parameter, private :: & + integer, dimension(2), parameter :: & LATTICE_BCC_NCLEAVAGESYSTEM = [3, 6] !< # of cleavage systems per family for bcc - integer, parameter, private :: & + integer, parameter :: & LATTICE_BCC_NSLIP = sum(LATTICE_BCC_NSLIPSYSTEM), & !< total # of slip systems for bcc LATTICE_BCC_NTWIN = sum(LATTICE_BCC_NTWINSYSTEM), & !< total # of twin systems for bcc LATTICE_BCC_NCLEAVAGE = sum(LATTICE_BCC_NCLEAVAGESYSTEM) !< total # of cleavage systems for bcc - real(pReal), dimension(3+3,LATTICE_BCC_NSLIP), parameter, private :: & + real(pReal), dimension(3+3,LATTICE_BCC_NSLIP), parameter :: & LATTICE_BCC_SYSTEMSLIP = reshape(real([& ! Slip direction Plane normal ! Slip system <111>{110} @@ -169,11 +171,11 @@ module lattice 1, 1, 1, 1, 1,-2 & ],pReal),shape(LATTICE_BCC_SYSTEMSLIP)) - character(len=*), dimension(2), parameter, private :: LATTICE_BCC_SLIPFAMILY_NAME = & + character(len=*), dimension(2), parameter :: LATTICE_BCC_SLIPFAMILY_NAME = & ['<1 -1 1>{0 1 1}', & '<1 -1 1>{2 1 1}'] - real(pReal), dimension(3+3,LATTICE_BCC_NTWIN), parameter, private :: & + real(pReal), dimension(3+3,LATTICE_BCC_NTWIN), parameter :: & LATTICE_BCC_SYSTEMTWIN = reshape(real([& ! Twin system <111>{112} -1, 1, 1, 2, 1, 1, & @@ -190,10 +192,10 @@ module lattice 1, 1, 1, 1, 1,-2 & ],pReal),shape(LATTICE_BCC_SYSTEMTWIN)) - character(len=*), dimension(1), parameter, private :: LATTICE_BCC_TWINFAMILY_NAME = & + character(len=*), dimension(1), parameter :: LATTICE_BCC_TWINFAMILY_NAME = & ['<1 1 1>{2 1 1}'] - real(pReal), dimension(3+3,LATTICE_BCC_NCLEAVAGE), parameter, private :: & + real(pReal), dimension(3+3,LATTICE_BCC_NCLEAVAGE), parameter :: & LATTICE_BCC_SYSTEMCLEAVAGE = reshape(real([& ! Cleavage direction Plane normal 0, 1, 0, 1, 0, 0, & @@ -209,21 +211,21 @@ module lattice !-------------------------------------------------------------------------------------------------- ! hexagonal - integer, dimension(6), parameter, private :: & + integer, dimension(6), parameter :: & LATTICE_HEX_NSLIPSYSTEM = [3, 3, 3, 6, 12, 6] !< # of slip systems per family for hex - integer, dimension(4), parameter, private :: & + integer, dimension(4), parameter :: & LATTICE_HEX_NTWINSYSTEM = [6, 6, 6, 6] !< # of slip systems per family for hex - integer, dimension(1), parameter, private :: & + integer, dimension(1), parameter :: & LATTICE_HEX_NCLEAVAGESYSTEM = [3] !< # of cleavage systems per family for hex - integer, parameter, private :: & + integer, parameter :: & LATTICE_HEX_NSLIP = sum(LATTICE_HEX_NSLIPSYSTEM), & !< total # of slip systems for hex LATTICE_HEX_NTWIN = sum(LATTICE_HEX_NTWINSYSTEM), & !< total # of twin systems for hex LATTICE_HEX_NCLEAVAGE = sum(LATTICE_HEX_NCLEAVAGESYSTEM) !< total # of cleavage systems for hex - real(pReal), dimension(4+4,LATTICE_HEX_NSLIP), parameter, private :: & + real(pReal), dimension(4+4,LATTICE_HEX_NSLIP), parameter :: & LATTICE_HEX_SYSTEMSLIP = reshape(real([& ! Slip direction Plane normal ! Basal systems <11.0>{00.1} (independent of c/a-ratio, Bravais notation (4 coordinate base)) @@ -267,7 +269,7 @@ module lattice 1, 1, -2, 3, -1, -1, 2, 2 & ],pReal),shape(LATTICE_HEX_SYSTEMSLIP)) !< slip systems for hex sorted by A. Alankar & P. Eisenlohr - character(len=*), dimension(6), parameter, private :: LATTICE_HEX_SLIPFAMILY_NAME = & + character(len=*), dimension(6), parameter :: LATTICE_HEX_SLIPFAMILY_NAME = & ['<1 1 . 1>{0 0 . 1} ', & '<1 1 . 1>{1 0 . 0} ', & '<1 0 . 0>{1 1 . 0} ', & @@ -275,7 +277,7 @@ module lattice '<1 1 . 3>{-1 0 . 1} ', & '<1 1 . 3>{-1 -1 . 2}'] - real(pReal), dimension(4+4,LATTICE_HEX_NTWIN), parameter, private :: & + real(pReal), dimension(4+4,LATTICE_HEX_NTWIN), parameter :: & LATTICE_HEX_SYSTEMTWIN = reshape(real([& ! Compression or Tension =f(twinning shear=f(c/a)) for each metal ! (according to Yoo 1981) 1, -1, 0, 1, -1, 1, 0, 2, & ! <-10.1>{10.2} shear = (3-(c/a)^2)/(sqrt(3) c/a) @@ -307,13 +309,13 @@ module lattice 1, 1, -2, -3, 1, 1, -2, 2 & ],pReal),shape(LATTICE_HEX_SYSTEMTWIN)) !< twin systems for hex, order follows Prof. Tom Bieler's scheme - character(len=*), dimension(4), parameter, private :: LATTICE_HEX_TWINFAMILY_NAME = & + character(len=*), dimension(4), parameter :: LATTICE_HEX_TWINFAMILY_NAME = & ['<-1 0 . 1>{1 0 . 2} ', & '<1 1 . 6>{-1 -1 . 1}', & '<1 0 . -2>{1 0 . 1} ', & '<1 1 . -3>{1 1 . 2} '] - real(pReal), dimension(4+4,LATTICE_HEX_NCLEAVAGE), parameter, private :: & + real(pReal), dimension(4+4,LATTICE_HEX_NCLEAVAGE), parameter :: & LATTICE_HEX_SYSTEMCLEAVAGE = reshape(real([& ! Cleavage direction Plane normal 2,-1,-1, 0, 0, 0, 0, 1, & @@ -324,13 +326,13 @@ module lattice !-------------------------------------------------------------------------------------------------- ! body centered tetragonal - integer, dimension(13), parameter, private :: & + integer, dimension(13), parameter :: & LATTICE_BCT_NSLIPSYSTEM = [2, 2, 2, 4, 2, 4, 2, 2, 4, 8, 4, 8, 8 ] !< # of slip systems per family for bct (Sn) Bieler J. Electr Mater 2009 - integer, parameter, private :: & + integer, parameter :: & LATTICE_BCT_NSLIP = sum(LATTICE_BCT_NSLIPSYSTEM) !< total # of slip systems for bct - real(pReal), dimension(3+3,LATTICE_BCT_NSLIP), parameter, private :: & + real(pReal), dimension(3+3,LATTICE_BCT_NSLIP), parameter :: & LATTICE_BCT_SYSTEMSLIP = reshape(real([& ! Slip direction Plane normal ! Slip family 1 {100)<001] (Bravais notation {hkl) @brief Module initialization !-------------------------------------------------------------------------------------------------- subroutine lattice_init - use IO, only: & - IO_error - use config, only: & - config_phase integer :: Nphases character(len=65536) :: & @@ -654,15 +652,7 @@ end subroutine lattice_init !> @brief !!!!!!!DEPRECTATED!!!!!! !-------------------------------------------------------------------------------------------------- subroutine lattice_initializeStructure(myPhase,CoverA) - use prec, only: & - tol_math_check - use math, only: & - math_sym3333to66, & - math_Voigt66to3333, & - math_cross - use IO, only: & - IO_error - + integer, intent(in) :: myPhase real(pReal), intent(in) :: & CoverA @@ -690,9 +680,10 @@ subroutine lattice_initializeStructure(myPhase,CoverA) call IO_error(135,el=i,ip=myPhase,ext_msg='matrix diagonal "el"ement of phase "ip"') enddo - forall (i = 1:3) & + do i = 1,3 lattice_thermalExpansion33 (1:3,1:3,i,myPhase) = lattice_symmetrize33(lattice_structure(myPhase),& lattice_thermalExpansion33 (1:3,1:3,i,myPhase)) + enddo lattice_thermalConductivity33 (1:3,1:3,myPhase) = lattice_symmetrize33(lattice_structure(myPhase),& lattice_thermalConductivity33 (1:3,1:3,myPhase)) @@ -763,17 +754,17 @@ pure function lattice_symmetrizeC66(struct,C66) select case(struct) case (LATTICE_iso_ID) - forall(k=1:3) + do k=1,3 forall(j=1:3) lattice_symmetrizeC66(k,j) = C66(1,2) lattice_symmetrizeC66(k,k) = C66(1,1) lattice_symmetrizeC66(k+3,k+3) = 0.5_pReal*(C66(1,1)-C66(1,2)) - end forall + enddo case (LATTICE_fcc_ID,LATTICE_bcc_ID) - forall(k=1:3) + do k=1,3 forall(j=1:3) lattice_symmetrizeC66(k,j) = C66(1,2) lattice_symmetrizeC66(k,k) = C66(1,1) lattice_symmetrizeC66(k+3,k+3) = C66(4,4) - end forall + enddo case (LATTICE_hex_ID) lattice_symmetrizeC66(1,1) = C66(1,1) lattice_symmetrizeC66(2,2) = C66(1,1) @@ -834,7 +825,9 @@ pure function lattice_symmetrize33(struct,T33) select case(struct) case (LATTICE_iso_ID,LATTICE_fcc_ID,LATTICE_bcc_ID) - forall(k=1:3) lattice_symmetrize33(k,k) = T33(1,1) + do k=1,3 + lattice_symmetrize33(k,k) = T33(1,1) + enddo case (LATTICE_hex_ID) lattice_symmetrize33(1,1) = T33(1,1) lattice_symmetrize33(2,2) = T33(1,1) @@ -854,10 +847,6 @@ end function lattice_symmetrize33 !> @brief figures whether unit quat falls into stereographic standard triangle !-------------------------------------------------------------------------------------------------- logical pure function lattice_qInSST(Q, struct) - use, intrinsic :: & - IEEE_arithmetic - use math, only: & - math_qToRodrig real(pReal), dimension(4), intent(in) :: Q ! orientation integer(kind(LATTICE_undefined_ID)), intent(in) :: struct ! lattice structure @@ -888,11 +877,6 @@ end function lattice_qInSST !> @brief calculates the disorientation for 2 unit quaternions !-------------------------------------------------------------------------------------------------- pure function lattice_qDisorientation(Q1, Q2, struct) - use prec, only: & - tol_math_check - use math, only: & - math_qMul, & - math_qConj real(pReal), dimension(4) :: lattice_qDisorientation real(pReal), dimension(4), intent(in) :: & @@ -998,8 +982,6 @@ end function lattice_qDisorientation !> @brief Characteristic shear for twinning !-------------------------------------------------------------------------------------------------- function lattice_characteristicShear_Twin(Ntwin,structure,CoverA) result(characteristicShear) - use IO, only: & - IO_error integer, dimension(:), intent(in) :: Ntwin !< number of active twin systems per family character(len=*), intent(in) :: structure !< lattice structure @@ -1077,14 +1059,6 @@ end function lattice_characteristicShear_Twin !> @brief Rotated elasticity matrices for twinning in 66-vector notation !-------------------------------------------------------------------------------------------------- function lattice_C66_twin(Ntwin,C66,structure,CoverA) - use IO, only: & - IO_error - use math, only: & - PI, & - math_axisAngleToR, & - math_sym3333to66, & - math_66toSym3333, & - math_rotate_forward3333 integer, dimension(:), intent(in) :: Ntwin !< number of active twin systems per family character(len=*), intent(in) :: structure !< lattice structure @@ -1125,17 +1099,6 @@ end function lattice_C66_twin !-------------------------------------------------------------------------------------------------- function lattice_C66_trans(Ntrans,C_parent66,structure_target, & CoverA_trans,a_bcc,a_fcc) - use prec, only: & - tol_math_check - use IO, only: & - IO_error - use math, only: & - INRAD, & - MATH_I3, & - math_axisAngleToR, & - math_sym3333to66, & - math_66toSym3333, & - math_rotate_forward3333 integer, dimension(:), intent(in) :: Ntrans !< number of active twin systems per family character(len=*), intent(in) :: structure_target !< lattice structure @@ -1196,13 +1159,6 @@ function lattice_C66_trans(Ntrans,C_parent66,structure_target, & ! Gröger et al. 2008, Acta Materialia 56 (2008) 5412–5425, table 1 !-------------------------------------------------------------------------------------------------- function lattice_nonSchmidMatrix(Nslip,nonSchmidCoefficients,sense) result(nonSchmidMatrix) - use IO, only: & - IO_error - use math, only: & - INRAD, & - math_outer, & - math_cross, & - math_axisAngleToR integer, dimension(:), intent(in) :: Nslip !< number of active slip systems per family real(pReal), dimension(:), intent(in) :: nonSchmidCoefficients !< non-Schmid coefficients for projections @@ -1246,9 +1202,7 @@ end function lattice_nonSchmidMatrix !> details only active slip systems are considered !-------------------------------------------------------------------------------------------------- function lattice_interaction_SlipBySlip(Nslip,interactionValues,structure) result(interactionMatrix) - use IO, only: & - IO_error - + integer, dimension(:), intent(in) :: Nslip !< number of active slip systems per family real(pReal), dimension(:), intent(in) :: interactionValues !< values for slip-slip interaction character(len=*), intent(in) :: structure !< lattice structure @@ -1468,8 +1422,6 @@ end function lattice_interaction_SlipBySlip !> details only active twin systems are considered !-------------------------------------------------------------------------------------------------- function lattice_interaction_TwinByTwin(Ntwin,interactionValues,structure) result(interactionMatrix) - use IO, only: & - IO_error integer, dimension(:), intent(in) :: Ntwin !< number of active twin systems per family real(pReal), dimension(:), intent(in) :: interactionValues !< values for twin-twin interaction @@ -1571,8 +1523,6 @@ end function lattice_interaction_TwinByTwin !> details only active trans systems are considered !-------------------------------------------------------------------------------------------------- function lattice_interaction_TransByTrans(Ntrans,interactionValues,structure) result(interactionMatrix) - use IO, only: & - IO_error integer, dimension(:), intent(in) :: Ntrans !< number of active trans systems per family real(pReal), dimension(:), intent(in) :: interactionValues !< values for trans-trans interaction @@ -1618,8 +1568,6 @@ end function lattice_interaction_TransByTrans !> details only active slip and twin systems are considered !-------------------------------------------------------------------------------------------------- function lattice_interaction_SlipByTwin(Nslip,Ntwin,interactionValues,structure) result(interactionMatrix) - use IO, only: & - IO_error integer, dimension(:), intent(in) :: Nslip, & !< number of active slip systems per family Ntwin !< number of active twin systems per family @@ -1760,8 +1708,6 @@ end function lattice_interaction_SlipByTwin !> details only active slip and trans systems are considered !-------------------------------------------------------------------------------------------------- function lattice_interaction_SlipByTrans(Nslip,Ntrans,interactionValues,structure) result(interactionMatrix) - use IO, only: & - IO_error integer, dimension(:), intent(in) :: Nslip, & !< number of active slip systems per family Ntrans !< number of active trans systems per family @@ -1818,8 +1764,6 @@ function lattice_interaction_SlipByTrans(Nslip,Ntrans,interactionValues,structur !> details only active twin and slip systems are considered !-------------------------------------------------------------------------------------------------- function lattice_interaction_TwinBySlip(Ntwin,Nslip,interactionValues,structure) result(interactionMatrix) - use IO, only: & - IO_error integer, dimension(:), intent(in) :: Ntwin, & !< number of active twin systems per family Nslip !< number of active slip systems per family @@ -1898,13 +1842,6 @@ end function lattice_interaction_TwinBySlip !> details only active slip systems are considered !-------------------------------------------------------------------------------------------------- function lattice_SchmidMatrix_slip(Nslip,structure,cOverA) result(SchmidMatrix) - use prec, only: & - tol_math_check - use IO, only: & - IO_error - use math, only: & - math_trace33, & - math_outer integer, dimension(:), intent(in) :: Nslip !< number of active slip systems per family character(len=*), intent(in) :: structure !< lattice structure @@ -1957,13 +1894,6 @@ end function lattice_SchmidMatrix_slip !> details only active twin systems are considered !-------------------------------------------------------------------------------------------------- function lattice_SchmidMatrix_twin(Ntwin,structure,cOverA) result(SchmidMatrix) - use prec, only: & - tol_math_check - use IO, only: & - IO_error - use math, only: & - math_trace33, & - math_outer integer, dimension(:), intent(in) :: Ntwin !< number of active twin systems per family character(len=*), intent(in) :: structure !< lattice structure @@ -2013,8 +1943,6 @@ function lattice_SchmidMatrix_twin(Ntwin,structure,cOverA) result(SchmidMatrix) !> details only active twin systems are considered !-------------------------------------------------------------------------------------------------- function lattice_SchmidMatrix_trans(Ntrans,structure_target,cOverA,a_bcc,a_fcc) result(SchmidMatrix) - use IO, only: & - IO_error integer, dimension(:), intent(in) :: Ntrans !< number of active twin systems per family real(pReal), intent(in) :: cOverA !< c/a ratio @@ -2041,11 +1969,7 @@ end function lattice_SchmidMatrix_trans !> details only active cleavage systems are considered !-------------------------------------------------------------------------------------------------- function lattice_SchmidMatrix_cleavage(Ncleavage,structure,cOverA) result(SchmidMatrix) - use math, only: & - math_outer - use IO, only: & - IO_error - + integer, dimension(:), intent(in) :: Ncleavage !< number of active cleavage systems per family character(len=*), intent(in) :: structure !< lattice structure real(pReal), intent(in) :: cOverA !< c/a ratio @@ -2154,8 +2078,6 @@ end function lattice_slip_transverse !> @details: This projection is used to calculate forest hardening for edge dislocations !-------------------------------------------------------------------------------------------------- function slipProjection_transverse(Nslip,structure,cOverA) result(projection) - use math, only: & - math_inner integer, dimension(:), intent(in) :: Nslip !< number of active slip systems per family character(len=*), intent(in) :: structure !< lattice structure @@ -2179,8 +2101,6 @@ end function slipProjection_transverse !> @details: This projection is used to calculate forest hardening for screw dislocations !-------------------------------------------------------------------------------------------------- function slipProjection_direction(Nslip,structure,cOverA) result(projection) - use math, only: & - math_inner integer, dimension(:), intent(in) :: Nslip !< number of active slip systems per family character(len=*), intent(in) :: structure !< lattice structure @@ -2204,9 +2124,7 @@ end function slipProjection_direction !> @details Order: Direction, plane (normal), and common perpendicular !-------------------------------------------------------------------------------------------------- function coordinateSystem_slip(Nslip,structure,cOverA) result(coordinateSystem) - use IO, only: & - IO_error - + integer, dimension(:), intent(in) :: Nslip !< number of active slip systems per family character(len=*), intent(in) :: structure !< lattice structure real(pReal), intent(in) :: cOverA !< c/a ratio @@ -2249,8 +2167,6 @@ end function coordinateSystem_slip !> @brief Populates reduced interaction matrix !-------------------------------------------------------------------------------------------------- function buildInteraction(reacting_used,acting_used,reacting_max,acting_max,values,matrix) - use IO, only: & - IO_error integer, dimension(:), intent(in) :: & reacting_used, & !< # of reacting systems per family as specified in material.config @@ -2295,10 +2211,6 @@ end function buildInteraction !> @details Order: Direction, plane (normal), and common perpendicular !-------------------------------------------------------------------------------------------------- function buildCoordinateSystem(active,complete,system,structure,cOverA) - use IO, only: & - IO_error - use math, only: & - math_cross integer, dimension(:), intent(in) :: & active, & @@ -2370,16 +2282,6 @@ end function buildCoordinateSystem ! set a_bcc = 0.0 for fcc -> hex transformation !-------------------------------------------------------------------------------------------------- subroutine buildTransformationSystem(Q,S,Ntrans,cOverA,a_fcc,a_bcc) - use prec, only: & - dEq0 - use math, only: & - math_cross, & - math_outer, & - math_axisAngleToR, & - INRAD, & - MATH_I3 - use IO, only: & - IO_error integer, dimension(:), intent(in) :: & Ntrans diff --git a/src/plastic_dislotwin.f90 b/src/plastic_dislotwin.f90 index 7db1f5f7f..fd5d8b787 100644 --- a/src/plastic_dislotwin.f90 +++ b/src/plastic_dislotwin.f90 @@ -8,17 +8,26 @@ !> @details to be done !-------------------------------------------------------------------------------------------------- module plastic_dislotwin - use prec, only: & - pReal + use prec + use debug + use math + use IO + use material + use config + use lattice +#if defined(PETSc) || defined(DAMASK_HDF5) + use results +#endif implicit none private + integer, dimension(:,:), allocatable, target, public :: & plastic_dislotwin_sizePostResult !< size of each post result output character(len=64), dimension(:,:), allocatable, target, public :: & plastic_dislotwin_output !< name of each post result output - real(pReal), parameter, private :: & + real(pReal), parameter :: & kB = 1.38e-23_pReal !< Boltzmann constant in J/Kelvin enum, bind(c) @@ -39,7 +48,7 @@ module plastic_dislotwin f_tr_ID end enum - type, private :: tParameters + type :: tParameters real(pReal) :: & mu, & nu, & @@ -119,7 +128,7 @@ module plastic_dislotwin dipoleFormation !< flag indicating consideration of dipole formation end type !< container type for internal constitutive parameters - type, private :: tDislotwinState + type :: tDislotwinState real(pReal), dimension(:,:), pointer :: & rho_mob, & rho_dip, & @@ -128,7 +137,7 @@ module plastic_dislotwin f_tr end type tDislotwinState - type, private :: tDislotwinMicrostructure + type :: tDislotwinMicrostructure real(pReal), dimension(:,:), allocatable :: & Lambda_sl, & !* mean free path between 2 obstacles seen by a moving dislocation Lambda_tw, & !* mean free path between 2 obstacles seen by a growing twin @@ -144,11 +153,11 @@ module plastic_dislotwin !-------------------------------------------------------------------------------------------------- ! containers for parameters and state - type(tParameters), allocatable, dimension(:), private :: param - type(tDislotwinState), allocatable, dimension(:), private :: & + type(tParameters), allocatable, dimension(:) :: param + type(tDislotwinState), allocatable, dimension(:) :: & dotState, & state - type(tDislotwinMicrostructure), allocatable, dimension(:), private :: dependentState + type(tDislotwinMicrostructure), allocatable, dimension(:) :: dependentState public :: & plastic_dislotwin_init, & @@ -158,10 +167,6 @@ module plastic_dislotwin plastic_dislotwin_dotState, & plastic_dislotwin_postResults, & plastic_dislotwin_results - private :: & - kinetics_slip, & - kinetics_twin, & - kinetics_trans contains @@ -171,24 +176,6 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine plastic_dislotwin_init - use prec, only: & - pStringLen, & - dEq0, & - dNeq0, & - dNeq - use debug, only: & - debug_level,& - debug_constitutive,& - debug_levelBasic - use math, only: & - math_expand,& - PI - use IO, only: & - IO_error - use material - use config, only: & - config_phase - use lattice integer :: & Ninstance, & @@ -591,10 +578,6 @@ end subroutine plastic_dislotwin_init !> @brief returns the homogenized elasticity matrix !-------------------------------------------------------------------------------------------------- function plastic_dislotwin_homogenizedC(ipc,ip,el) result(homogenizedC) - use material, only: & - material_phase, & - phase_plasticityInstance, & - phasememberAt real(pReal), dimension(6,6) :: & homogenizedC @@ -634,14 +617,6 @@ end function plastic_dislotwin_homogenizedC !> @brief calculates plastic velocity gradient and its tangent !-------------------------------------------------------------------------------------------------- subroutine plastic_dislotwin_LpAndItsTangent(Lp,dLp_dMp,Mp,T,instance,of) - use prec, only: & - tol_math_check, & - dNeq0 - use math, only: & - math_eigenValuesVectorsSym, & - math_outer, & - math_symmetric33, & - math_mul33xx33 real(pReal), dimension(3,3), intent(out) :: Lp real(pReal), dimension(3,3,3,3), intent(out) :: dLp_dMp @@ -757,13 +732,6 @@ end subroutine plastic_dislotwin_LpAndItsTangent !> @brief calculates the rate of change of microstructure !-------------------------------------------------------------------------------------------------- subroutine plastic_dislotwin_dotState(Mp,T,instance,of) - use prec, only: & - tol_math_check, & - dEq0 - use math, only: & - math_clip, & - math_mul33xx33, & - PI real(pReal), dimension(3,3), intent(in):: & Mp !< Mandel stress @@ -854,8 +822,6 @@ end subroutine plastic_dislotwin_dotState !> @brief calculates derived quantities from state !-------------------------------------------------------------------------------------------------- subroutine plastic_dislotwin_dependentState(T,instance,of) - use math, only: & - PI integer, intent(in) :: & instance, & @@ -868,13 +834,13 @@ subroutine plastic_dislotwin_dependentState(T,instance,of) real(pReal) :: & sumf_twin,SFE,sumf_trans real(pReal), dimension(param(instance)%sum_N_sl) :: & - inv_lambda_sl_sl, & !* 1/mean free distance between 2 forest dislocations seen by a moving dislocation - inv_lambda_sl_tw, & !* 1/mean free distance between 2 twin stacks from different systems seen by a moving dislocation - inv_lambda_sl_tr !* 1/mean free distance between 2 martensite lamellar from different systems seen by a moving dislocation + inv_lambda_sl_sl, & !< 1/mean free distance between 2 forest dislocations seen by a moving dislocation + inv_lambda_sl_tw, & !< 1/mean free distance between 2 twin stacks from different systems seen by a moving dislocation + inv_lambda_sl_tr !< 1/mean free distance between 2 martensite lamellar from different systems seen by a moving dislocation real(pReal), dimension(param(instance)%sum_N_tw) :: & - inv_lambda_tw_tw !* 1/mean free distance between 2 twin stacks from different systems seen by a growing twin + inv_lambda_tw_tw !< 1/mean free distance between 2 twin stacks from different systems seen by a growing twin real(pReal), dimension(param(instance)%sum_N_tr) :: & - inv_lambda_tr_tr !* 1/mean free distance between 2 martensite stacks from different systems seen by a growing martensite (1/lambda_trans) + inv_lambda_tr_tr !< 1/mean free distance between 2 martensite stacks from different systems seen by a growing martensite real(pReal), dimension(:), allocatable :: & x0, & @@ -967,12 +933,6 @@ end subroutine plastic_dislotwin_dependentState !> @brief return array of constitutive results !-------------------------------------------------------------------------------------------------- function plastic_dislotwin_postResults(Mp,T,instance,of) result(postResults) - use prec, only: & - tol_math_check, & - dEq0 - use math, only: & - PI, & - math_mul33xx33 real(pReal), dimension(3,3),intent(in) :: & Mp !< 2nd Piola Kirchhoff stress tensor in Mandel notation @@ -1050,8 +1010,6 @@ end function plastic_dislotwin_postResults !-------------------------------------------------------------------------------------------------- subroutine plastic_dislotwin_results(instance,group) #if defined(PETSc) || defined(DAMASK_HDF5) - use results, only: & - results_writeDataset integer, intent(in) :: instance character(len=*) :: group @@ -1112,11 +1070,6 @@ end subroutine plastic_dislotwin_results !-------------------------------------------------------------------------------------------------- pure subroutine kinetics_slip(Mp,T,instance,of, & dot_gamma_sl,ddot_gamma_dtau_slip,tau_slip) - use prec, only: & - tol_math_check, & - dNeq0 - use math, only: & - math_mul33xx33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress @@ -1190,11 +1143,6 @@ end subroutine kinetics_slip !-------------------------------------------------------------------------------------------------- pure subroutine kinetics_twin(Mp,T,dot_gamma_sl,instance,of,& dot_gamma_twin,ddot_gamma_dtau_twin) - use prec, only: & - tol_math_check, & - dNeq0 - use math, only: & - math_mul33xx33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress @@ -1261,11 +1209,6 @@ end subroutine kinetics_twin !-------------------------------------------------------------------------------------------------- pure subroutine kinetics_trans(Mp,T,dot_gamma_sl,instance,of,& dot_gamma_tr,ddot_gamma_dtau_trans) - use prec, only: & - tol_math_check, & - dNeq0 - use math, only: & - math_mul33xx33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress diff --git a/src/plastic_isotropic.f90 b/src/plastic_isotropic.f90 index c572f0ded..46d0905dc 100644 --- a/src/plastic_isotropic.f90 +++ b/src/plastic_isotropic.f90 @@ -8,11 +8,19 @@ !! untextured polycrystal !-------------------------------------------------------------------------------------------------- module plastic_isotropic - use prec, only: & - pReal + use prec + use debug + use math + use IO + use material + use config +#if defined(PETSc) || defined(DAMASK_HDF5) + use results +#endif implicit none private + integer, dimension(:,:), allocatable, target, public :: & plastic_isotropic_sizePostResult !< size of each post result output character(len=64), dimension(:,:), allocatable, target, public :: & @@ -25,7 +33,7 @@ module plastic_isotropic dot_gamma_ID end enum - type, private :: tParameters + type :: tParameters real(pReal) :: & M, & !< Taylor factor xi_0, & !< initial critical stress @@ -49,7 +57,7 @@ module plastic_isotropic dilatation end type tParameters - type, private :: tIsotropicState + type :: tIsotropicState real(pReal), pointer, dimension(:) :: & xi, & gamma @@ -57,8 +65,8 @@ module plastic_isotropic !-------------------------------------------------------------------------------------------------- ! containers for parameters and state - type(tParameters), allocatable, dimension(:), private :: param - type(tIsotropicState), allocatable, dimension(:), private :: & + type(tParameters), allocatable, dimension(:) :: param + type(tIsotropicState), allocatable, dimension(:) :: & dotState, & state @@ -77,25 +85,7 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine plastic_isotropic_init - use prec, only: & - pStringLen - use debug, only: & -#ifdef DEBUG - debug_e, & - debug_i, & - debug_g, & - debug_levelExtensive, & -#endif - debug_level, & - debug_constitutive, & - debug_levelBasic - use IO, only: & - IO_error - use material - use config, only: & - config_phase - use lattice - + integer :: & Ninstance, & p, i, & @@ -235,16 +225,6 @@ end subroutine plastic_isotropic_init !> @brief calculates plastic velocity gradient and its tangent !-------------------------------------------------------------------------------------------------- subroutine plastic_isotropic_LpAndItsTangent(Lp,dLp_dMp,Mp,instance,of) -#ifdef DEBUG - use debug, only: & - debug_level, & - debug_constitutive,& - debug_levelExtensive, & - debug_levelSelective -#endif - use math, only: & - math_deviatoric33, & - math_mul33xx33 real(pReal), dimension(3,3), intent(out) :: & Lp !< plastic velocity gradient @@ -307,10 +287,6 @@ end subroutine plastic_isotropic_LpAndItsTangent ! ToDo: Rename Tstar to Mi? !-------------------------------------------------------------------------------------------------- subroutine plastic_isotropic_LiAndItsTangent(Li,dLi_dTstar,Tstar,instance,of) - use math, only: & - math_I3, & - math_spherical33, & - math_mul33xx33 real(pReal), dimension(3,3), intent(out) :: & Li !< inleastic velocity gradient @@ -362,11 +338,6 @@ subroutine plastic_isotropic_LiAndItsTangent(Li,dLi_dTstar,Tstar,instance,of) !> @brief calculates the rate of change of microstructure !-------------------------------------------------------------------------------------------------- subroutine plastic_isotropic_dotState(Mp,instance,of) - use prec, only: & - dEq0 - use math, only: & - math_mul33xx33, & - math_deviatoric33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress @@ -416,9 +387,6 @@ end subroutine plastic_isotropic_dotState !> @brief return array of constitutive results !-------------------------------------------------------------------------------------------------- function plastic_isotropic_postResults(Mp,instance,of) result(postResults) - use math, only: & - math_mul33xx33, & - math_deviatoric33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress @@ -468,7 +436,6 @@ end function plastic_isotropic_postResults !-------------------------------------------------------------------------------------------------- subroutine plastic_isotropic_results(instance,group) #if defined(PETSc) || defined(DAMASKHDF5) - use results integer, intent(in) :: instance character(len=*), intent(in) :: group diff --git a/src/plastic_kinematichardening.f90 b/src/plastic_kinematichardening.f90 index 861b98da3..ab68eb176 100644 --- a/src/plastic_kinematichardening.f90 +++ b/src/plastic_kinematichardening.f90 @@ -6,11 +6,20 @@ !! and a Voce-type kinematic hardening rule !-------------------------------------------------------------------------------------------------- module plastic_kinehardening - use prec, only: & - pReal + use prec + use debug + use math + use IO + use material + use config + use lattice +#if defined(PETSc) || defined(DAMASK_HDF5) + use results +#endif implicit none private + integer, dimension(:,:), allocatable, target, public :: & plastic_kinehardening_sizePostResult !< size of each post result output character(len=64), dimension(:,:), allocatable, target, public :: & @@ -29,7 +38,7 @@ module plastic_kinehardening resolvedstress_ID end enum - type, private :: tParameters + type :: tParameters real(pReal) :: & gdot0, & !< reference shear strain rate for slip n, & !< stress exponent for slip @@ -59,7 +68,7 @@ module plastic_kinehardening outputID !< ID of each post result output end type tParameters - type, private :: tKinehardeningState + type :: tKinehardeningState real(pReal), pointer, dimension(:,:) :: & !< vectors along NipcMyInstance crss, & !< critical resolved stress crss_back, & !< critical resolved back stress @@ -71,8 +80,8 @@ module plastic_kinehardening !-------------------------------------------------------------------------------------------------- ! containers for parameters and state - type(tParameters), allocatable, dimension(:), private :: param - type(tKinehardeningState), allocatable, dimension(:), private :: & + type(tParameters), allocatable, dimension(:) :: param + type(tKinehardeningState), allocatable, dimension(:) :: & dotState, & deltaState, & state @@ -84,8 +93,6 @@ module plastic_kinehardening plastic_kinehardening_deltaState, & plastic_kinehardening_postResults, & plastic_kinehardening_results - private :: & - kinetics contains @@ -95,27 +102,6 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine plastic_kinehardening_init - use prec, only: & - dEq0, & - pStringLen - use debug, only: & -#ifdef DEBUG - debug_e, & - debug_i, & - debug_g, & - debug_levelExtensive, & -#endif - debug_level, & - debug_constitutive,& - debug_levelBasic - use math, only: & - math_expand - use IO, only: & - IO_error - use material - use config, only: & - config_phase - use lattice integer :: & Ninstance, & @@ -417,16 +403,6 @@ end subroutine plastic_kinehardening_dotState !> @brief calculates (instantaneous) incremental change of microstructure !-------------------------------------------------------------------------------------------------- subroutine plastic_kinehardening_deltaState(Mp,instance,of) - use prec, only: & - dNeq, & - dEq0 -#ifdef DEBUG - use debug, only: & - debug_level, & - debug_constitutive,& - debug_levelExtensive, & - debug_levelSelective -#endif real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress @@ -475,8 +451,6 @@ end subroutine plastic_kinehardening_deltaState !> @brief return array of constitutive results !-------------------------------------------------------------------------------------------------- function plastic_kinehardening_postResults(Mp,instance,of) result(postResults) - use math, only: & - math_mul33xx33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress @@ -535,8 +509,6 @@ end function plastic_kinehardening_postResults !-------------------------------------------------------------------------------------------------- subroutine plastic_kinehardening_results(instance,group) #if defined(PETSc) || defined(DAMASK_HDF5) - use results, only: & - results_writeDataset integer, intent(in) :: instance character(len=*) :: group @@ -585,10 +557,6 @@ end subroutine plastic_kinehardening_results !-------------------------------------------------------------------------------------------------- pure subroutine kinetics(Mp,instance,of, & gdot_pos,gdot_neg,dgdot_dtau_pos,dgdot_dtau_neg) - use prec, only: & - dNeq0 - use math, only: & - math_mul33xx33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress diff --git a/src/plastic_none.f90 b/src/plastic_none.f90 index 4b14266f1..894cc9a40 100644 --- a/src/plastic_none.f90 +++ b/src/plastic_none.f90 @@ -5,6 +5,8 @@ !> @brief Dummy plasticity for purely elastic material !-------------------------------------------------------------------------------------------------- module plastic_none + use material + use debug implicit none private @@ -19,11 +21,6 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine plastic_none_init - use debug, only: & - debug_level, & - debug_constitutive, & - debug_levelBasic - use material integer :: & Ninstance, & diff --git a/src/plastic_phenopowerlaw.f90 b/src/plastic_phenopowerlaw.f90 index 196129f64..a31891573 100644 --- a/src/plastic_phenopowerlaw.f90 +++ b/src/plastic_phenopowerlaw.f90 @@ -5,11 +5,20 @@ !> @brief phenomenological crystal plasticity formulation using a powerlaw fitting !-------------------------------------------------------------------------------------------------- module plastic_phenopowerlaw - use prec, only: & - pReal + use prec + use debug + use math + use IO + use material + use config + use lattice +#if defined(PETSc) || defined(DAMASK_HDF5) + use results +#endif implicit none private + integer, dimension(:,:), allocatable, target, public :: & plastic_phenopowerlaw_sizePostResult !< size of each post result output character(len=64), dimension(:,:), allocatable, target, public :: & @@ -28,7 +37,7 @@ module plastic_phenopowerlaw resolvedstress_twin_ID end enum - type, private :: tParameters + type :: tParameters real(pReal) :: & gdot0_slip, & !< reference shear strain rate for slip gdot0_twin, & !< reference shear strain rate for twin @@ -73,7 +82,7 @@ module plastic_phenopowerlaw outputID !< ID of each post result output end type tParameters - type, private :: tPhenopowerlawState + type :: tPhenopowerlawState real(pReal), pointer, dimension(:,:) :: & xi_slip, & xi_twin, & @@ -83,8 +92,8 @@ module plastic_phenopowerlaw !-------------------------------------------------------------------------------------------------- ! containers for parameters and state - type(tParameters), allocatable, dimension(:), private :: param - type(tPhenopowerlawState), allocatable, dimension(:), private :: & + type(tParameters), allocatable, dimension(:) :: param + type(tPhenopowerlawState), allocatable, dimension(:) :: & dotState, & state @@ -94,9 +103,6 @@ module plastic_phenopowerlaw plastic_phenopowerlaw_dotState, & plastic_phenopowerlaw_postResults, & plastic_phenopowerlaw_results - private :: & - kinetics_slip, & - kinetics_twin contains @@ -106,20 +112,6 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine plastic_phenopowerlaw_init - use prec, only: & - pStringLen - use debug, only: & - debug_level, & - debug_constitutive,& - debug_levelBasic - use math, only: & - math_expand - use IO, only: & - IO_error - use material - use config, only: & - config_phase - use lattice integer :: & Ninstance, & @@ -484,8 +476,6 @@ end subroutine plastic_phenopowerlaw_dotState !> @brief return array of constitutive results !-------------------------------------------------------------------------------------------------- function plastic_phenopowerlaw_postResults(Mp,instance,of) result(postResults) - use math, only: & - math_mul33xx33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress @@ -552,8 +542,6 @@ end function plastic_phenopowerlaw_postResults !-------------------------------------------------------------------------------------------------- subroutine plastic_phenopowerlaw_results(instance,group) #if defined(PETSc) || defined(DAMASK_HDF5) - use results, only: & - results_writeDataset integer, intent(in) :: instance character(len=*), intent(in) :: group @@ -598,10 +586,6 @@ end subroutine plastic_phenopowerlaw_results !-------------------------------------------------------------------------------------------------- pure subroutine kinetics_slip(Mp,instance,of, & gdot_slip_pos,gdot_slip_neg,dgdot_dtau_slip_pos,dgdot_dtau_slip_neg) - use prec, only: & - dNeq0 - use math, only: & - math_mul33xx33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress @@ -674,10 +658,6 @@ end subroutine kinetics_slip !-------------------------------------------------------------------------------------------------- pure subroutine kinetics_twin(Mp,instance,of,& gdot_twin,dgdot_dtau_twin) - use prec, only: & - dNeq0 - use math, only: & - math_mul33xx33 real(pReal), dimension(3,3), intent(in) :: & Mp !< Mandel stress diff --git a/src/quaternions.f90 b/src/quaternions.f90 index fa9c13f38..47490daba 100644 --- a/src/quaternions.f90 +++ b/src/quaternions.f90 @@ -34,8 +34,7 @@ !> @details w is the real part, (x, y, z) are the imaginary parts. !--------------------------------------------------------------------------------------------------- module quaternions - use prec, only: & - pReal + use prec use future implicit none @@ -286,8 +285,6 @@ end function div_scal__ !> equality of two quaternions !--------------------------------------------------------------------------------------------------- logical elemental function eq__(self,other) - use prec, only: & - dEq class(quaternion), intent(in) :: self,other diff --git a/src/rotations.f90 b/src/rotations.f90 index 69529ed24..3a64f27b9 100644 --- a/src/rotations.f90 +++ b/src/rotations.f90 @@ -46,12 +46,15 @@ !--------------------------------------------------------------------------------------------------- module rotations - use prec, only: & - pReal + use prec + use IO + use math + use Lambert use quaternions implicit none private + type, public :: rotation type(quaternion), private :: q contains @@ -148,8 +151,6 @@ end subroutine !> @details: rotation is based on unit quaternion or rotation matrix (fallback) !--------------------------------------------------------------------------------------------------- function rotVector(self,v,active) - use prec, only: & - dEq real(pReal), dimension(3) :: rotVector class(rotation), intent(in) :: self @@ -260,10 +261,6 @@ end function qu2om !> @brief convert unit quaternion to Euler angles !--------------------------------------------------------------------------------------------------- pure function qu2eu(qu) result(eu) - use prec, only: & - dEq0 - use math, only: & - PI type(quaternion), intent(in) :: qu real(pReal), dimension(3) :: eu @@ -294,12 +291,6 @@ end function qu2eu !> @brief convert unit quaternion to axis angle pair !--------------------------------------------------------------------------------------------------- pure function qu2ax(qu) result(ax) - use prec, only: & - dEq0, & - dNeq0 - use math, only: & - PI, & - math_clip type(quaternion), intent(in) :: qu real(pReal), dimension(4) :: ax @@ -324,13 +315,6 @@ end function qu2ax !> @brief convert unit quaternion to Rodrigues vector !--------------------------------------------------------------------------------------------------- pure function qu2ro(qu) result(ro) - use, intrinsic :: IEEE_ARITHMETIC, only: & - IEEE_value, & - IEEE_positive_inf - use prec, only: & - dEq0 - use math, only: & - math_clip type(quaternion), intent(in) :: qu real(pReal), dimension(4) :: ro @@ -358,10 +342,6 @@ end function qu2ro !> @brief convert unit quaternion to homochoric !--------------------------------------------------------------------------------------------------- pure function qu2ho(qu) result(ho) - use prec, only: & - dEq0 - use math, only: & - math_clip type(quaternion), intent(in) :: qu real(pReal), dimension(3) :: ho @@ -415,8 +395,6 @@ end function om2qu !> @brief orientation matrix to Euler angles !--------------------------------------------------------------------------------------------------- pure function om2eu(om) result(eu) - use math, only: & - PI real(pReal), intent(in), dimension(3,3) :: om real(pReal), dimension(3) :: eu @@ -441,15 +419,6 @@ end function om2eu !> @brief convert orientation matrix to axis angle pair !--------------------------------------------------------------------------------------------------- function om2ax(om) result(ax) - use prec, only: & - dEq0, & - cEq, & - dNeq0 - use IO, only: & - IO_error - use math, only: & - math_clip, & - math_trace33 real(pReal), intent(in) :: om(3,3) real(pReal) :: ax(4) @@ -560,8 +529,6 @@ end function eu2qu !> @brief Euler angles to orientation matrix !--------------------------------------------------------------------------------------------------- pure function eu2om(eu) result(om) - use prec, only: & - dEq0 real(pReal), intent(in), dimension(3) :: eu real(pReal), dimension(3,3) :: om @@ -591,11 +558,6 @@ end function eu2om !> @brief convert euler to axis angle !--------------------------------------------------------------------------------------------------- pure function eu2ax(eu) result(ax) - use prec, only: & - dEq0, & - dEq - use math, only: & - PI real(pReal), intent(in), dimension(3) :: eu real(pReal), dimension(4) :: ax @@ -625,13 +587,6 @@ end function eu2ax !> @brief Euler angles to Rodrigues vector !--------------------------------------------------------------------------------------------------- pure function eu2ro(eu) result(ro) - use prec, only: & - dEq0 - use, intrinsic :: IEEE_ARITHMETIC, only: & - IEEE_value, & - IEEE_positive_inf - use math, only: & - PI real(pReal), intent(in), dimension(3) :: eu real(pReal), dimension(4) :: ro @@ -681,8 +636,6 @@ end function eu2cu !> @brief convert axis angle pair to quaternion !--------------------------------------------------------------------------------------------------- pure function ax2qu(ax) result(qu) - use prec, only: & - dEq0 real(pReal), intent(in), dimension(4) :: ax type(quaternion) :: qu @@ -755,13 +708,6 @@ end function ax2eu !> @brief convert axis angle pair to Rodrigues vector !--------------------------------------------------------------------------------------------------- pure function ax2ro(ax) result(ro) - use, intrinsic :: IEEE_ARITHMETIC, only: & - IEEE_value, & - IEEE_positive_inf - use prec, only: & - dEq0 - use math, only: & - PI real(pReal), intent(in), dimension(4) :: ax real(pReal), dimension(4) :: ro @@ -858,12 +804,6 @@ end function ro2eu !> @brief convert Rodrigues vector to axis angle pair !--------------------------------------------------------------------------------------------------- pure function ro2ax(ro) result(ax) - use, intrinsic :: IEEE_ARITHMETIC, only: & - IEEE_is_finite - use prec, only: & - dEq0 - use math, only: & - PI real(pReal), intent(in), dimension(4) :: ro real(pReal), dimension(4) :: ax @@ -890,12 +830,6 @@ end function ro2ax !> @brief convert Rodrigues vector to homochoric !--------------------------------------------------------------------------------------------------- pure function ro2ho(ro) result(ho) - use, intrinsic :: IEEE_ARITHMETIC, only: & - IEEE_is_finite - use prec, only: & - dEq0 - use math, only: & - PI real(pReal), intent(in), dimension(4) :: ro real(pReal), dimension(3) :: ho @@ -973,8 +907,6 @@ end function ho2eu !> @brief convert homochoric to axis angle pair !--------------------------------------------------------------------------------------------------- pure function ho2ax(ho) result(ax) - use prec, only: & - dEq0 real(pReal), intent(in), dimension(3) :: ho real(pReal), dimension(4) :: ax @@ -1029,13 +961,11 @@ end function ho2ro !> @brief convert homochoric to cubochoric !--------------------------------------------------------------------------------------------------- function ho2cu(ho) result(cu) - use Lambert, only: & - LambertBallToCube real(pReal), intent(in), dimension(3) :: ho real(pReal), dimension(3) :: cu - cu = LambertBallToCube(ho) + cu = Lambert_BallToCube(ho) end function ho2cu @@ -1115,13 +1045,11 @@ end function cu2ro !> @brief convert cubochoric to homochoric !--------------------------------------------------------------------------------------------------- function cu2ho(cu) result(ho) - use Lambert, only: & - LambertCubeToBall real(pReal), intent(in), dimension(3) :: cu real(pReal), dimension(3) :: ho - ho = LambertCubeToBall(cu) + ho = Lambert_CubeToBall(cu) end function cu2ho From 3df9a8d58c7741851517289ca158c0dcf9f3b245 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 16 May 2019 23:14:47 +0200 Subject: [PATCH 017/120] focus on the physics --- src/damage_local.f90 | 55 ++++----------------- src/damage_none.f90 | 16 ++----- src/damage_nonlocal.f90 | 71 ++++++---------------------- src/kinematics_cleavage_opening.f90 | 51 +++++++------------- src/kinematics_slipplane_opening.f90 | 42 +++++----------- src/kinematics_thermal_expansion.f90 | 50 +++++++------------- src/source_damage_anisoBrittle.f90 | 2 +- src/source_damage_isoBrittle.f90 | 2 +- 8 files changed, 76 insertions(+), 213 deletions(-) diff --git a/src/damage_local.f90 b/src/damage_local.f90 index 2db8cccc1..bd71ae95b 100644 --- a/src/damage_local.f90 +++ b/src/damage_local.f90 @@ -4,9 +4,13 @@ !-------------------------------------------------------------------------------------------------- module damage_local use prec + use material + use numerics + use config implicit none private + integer, dimension(:,:), allocatable, target, public :: & damage_local_sizePostResult !< size of each post result output @@ -20,23 +24,22 @@ module damage_local enumerator :: undefined_ID, & damage_ID end enum - integer(kind(undefined_ID)), dimension(:,:), allocatable, private :: & + integer(kind(undefined_ID)), dimension(:,:), allocatable :: & damage_local_outputID !< ID of each post result output - type, private :: tParameters + type :: tParameters integer(kind(undefined_ID)), dimension(:), allocatable :: & outputID end type tParameters - type(tparameters), dimension(:), allocatable, private :: & + type(tparameters), dimension(:), allocatable :: & param public :: & damage_local_init, & damage_local_updateState, & damage_local_postResults - private :: & - damage_local_getSourceAndItsTangent + contains @@ -45,21 +48,6 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine damage_local_init - use material, only: & - damage_type, & - damage_typeInstance, & - homogenization_Noutput, & - DAMAGE_local_label, & - DAMAGE_local_ID, & - material_homogenizationAt, & - mappingHomogenization, & - damageState, & - damageMapping, & - damage, & - damage_initialPhi - use config, only: & - config_homogenization - integer :: maxNinstance,homog,instance,i integer :: sizeState @@ -72,7 +60,7 @@ subroutine damage_local_init write(6,'(/,a)') ' <<<+- damage_'//DAMAGE_local_label//' init -+>>>' - maxNinstance = int(count(damage_type == DAMAGE_local_ID),pInt) + maxNinstance = count(damage_type == DAMAGE_local_ID) if (maxNinstance == 0) return allocate(damage_local_sizePostResult (maxval(homogenization_Noutput),maxNinstance),source=0) @@ -135,14 +123,6 @@ end subroutine damage_local_init !> @brief calculates local change in damage field !-------------------------------------------------------------------------------------------------- function damage_local_updateState(subdt, ip, el) - use numerics, only: & - residualStiffness, & - err_damage_tolAbs, & - err_damage_tolRel - use material, only: & - material_homogenizationAt, & - mappingHomogenization, & - damageState integer, intent(in) :: & ip, & !< integration point number @@ -177,17 +157,6 @@ end function damage_local_updateState !> @brief calculates homogenized local damage driving forces !-------------------------------------------------------------------------------------------------- subroutine damage_local_getSourceAndItsTangent(phiDot, dPhiDot_dPhi, phi, ip, el) - use material, only: & - homogenization_Ngrains, & - material_homogenizationAt, & - phaseAt, & - phasememberAt, & - phase_source, & - phase_Nsources, & - SOURCE_damage_isoBrittle_ID, & - SOURCE_damage_isoDuctile_ID, & - SOURCE_damage_anisoBrittle_ID, & - SOURCE_damage_anisoDuctile_ID use source_damage_isoBrittle, only: & source_damage_isobrittle_getRateAndItsTangent use source_damage_isoDuctile, only: & @@ -244,15 +213,11 @@ subroutine damage_local_getSourceAndItsTangent(phiDot, dPhiDot_dPhi, phi, ip, el end subroutine damage_local_getSourceAndItsTangent + !-------------------------------------------------------------------------------------------------- !> @brief return array of damage results !-------------------------------------------------------------------------------------------------- function damage_local_postResults(ip,el) - use material, only: & - material_homogenizationAt, & - damage_typeInstance, & - damageMapping, & - damage integer, intent(in) :: & ip, & !< integration point diff --git a/src/damage_none.f90 b/src/damage_none.f90 index aa2995ef5..5ffdba030 100644 --- a/src/damage_none.f90 +++ b/src/damage_none.f90 @@ -3,6 +3,8 @@ !> @brief material subroutine for constant damage field !-------------------------------------------------------------------------------------------------- module damage_none + use config + use material implicit none private @@ -15,18 +17,8 @@ contains !-------------------------------------------------------------------------------------------------- !> @brief allocates all neccessary fields, reads information from material configuration file !-------------------------------------------------------------------------------------------------- -subroutine damage_none_init() - use config, only: & - config_homogenization - use material, only: & - damage_initialPhi, & - damage, & - damage_type, & - material_homogenizationAt, & - damageState, & - DAMAGE_NONE_LABEL, & - DAMAGE_NONE_ID - +subroutine damage_none_init + integer :: & homog, & NofMyHomog diff --git a/src/damage_nonlocal.f90 b/src/damage_nonlocal.f90 index 9398b328a..81117e0eb 100644 --- a/src/damage_nonlocal.f90 +++ b/src/damage_nonlocal.f90 @@ -5,9 +5,16 @@ !-------------------------------------------------------------------------------------------------- module damage_nonlocal use prec + use material + use numerics + use config + use crystallite + use lattice + use mesh implicit none private + integer, dimension(:,:), allocatable, target, public :: & damage_nonlocal_sizePostResult !< size of each post result output @@ -22,12 +29,12 @@ module damage_nonlocal damage_ID end enum - type, private :: tParameters + type :: tParameters integer(kind(undefined_ID)), dimension(:), allocatable :: & outputID end type tParameters - type(tparameters), dimension(:), allocatable, private :: & + type(tparameters), dimension(:), allocatable :: & param public :: & @@ -45,21 +52,6 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine damage_nonlocal_init - use material, only: & - damage_type, & - damage_typeInstance, & - homogenization_Noutput, & - DAMAGE_nonlocal_label, & - DAMAGE_nonlocal_ID, & - material_homogenizationAt, & - mappingHomogenization, & - damageState, & - damageMapping, & - damage, & - damage_initialPhi - use config, only: & - config_homogenization - integer :: maxNinstance,homog,instance,o,i integer :: sizeState @@ -72,7 +64,7 @@ subroutine damage_nonlocal_init write(6,'(/,a)') ' <<<+- damage_'//DAMAGE_nonlocal_label//' init -+>>>' - maxNinstance = int(count(damage_type == DAMAGE_nonlocal_ID)) + maxNinstance = count(damage_type == DAMAGE_nonlocal_ID) if (maxNinstance == 0) return allocate(damage_nonlocal_sizePostResult (maxval(homogenization_Noutput),maxNinstance),source=0) @@ -131,17 +123,6 @@ end subroutine damage_nonlocal_init !> @brief calculates homogenized damage driving forces !-------------------------------------------------------------------------------------------------- subroutine damage_nonlocal_getSourceAndItsTangent(phiDot, dPhiDot_dPhi, phi, ip, el) - use material, only: & - homogenization_Ngrains, & - material_homogenizationAt, & - phaseAt, & - phasememberAt, & - phase_source, & - phase_Nsources, & - SOURCE_damage_isoBrittle_ID, & - SOURCE_damage_isoDuctile_ID, & - SOURCE_damage_anisoBrittle_ID, & - SOURCE_damage_anisoDuctile_ID use source_damage_isoBrittle, only: & source_damage_isobrittle_getRateAndItsTangent use source_damage_isoDuctile, only: & @@ -198,20 +179,11 @@ subroutine damage_nonlocal_getSourceAndItsTangent(phiDot, dPhiDot_dPhi, phi, ip, end subroutine damage_nonlocal_getSourceAndItsTangent + !-------------------------------------------------------------------------------------------------- !> @brief returns homogenized non local damage diffusion tensor in reference configuration !-------------------------------------------------------------------------------------------------- function damage_nonlocal_getDiffusion33(ip,el) - use numerics, only: & - charLength - use lattice, only: & - lattice_DamageDiffusion33 - use material, only: & - homogenization_Ngrains, & - material_phase, & - material_homogenizationAt - use crystallite, only: & - crystallite_push33ToRef integer, intent(in) :: & ip, & !< integration point number @@ -234,17 +206,11 @@ function damage_nonlocal_getDiffusion33(ip,el) end function damage_nonlocal_getDiffusion33 + !-------------------------------------------------------------------------------------------------- !> @brief Returns homogenized nonlocal damage mobility !-------------------------------------------------------------------------------------------------- real(pReal) function damage_nonlocal_getMobility(ip,el) - use mesh, only: & - mesh_element - use lattice, only: & - lattice_damageMobility - use material, only: & - material_phase, & - homogenization_Ngrains integer, intent(in) :: & ip, & !< integration point number @@ -263,14 +229,11 @@ real(pReal) function damage_nonlocal_getMobility(ip,el) end function damage_nonlocal_getMobility + !-------------------------------------------------------------------------------------------------- !> @brief updated nonlocal damage field with solution from damage phase field PDE !-------------------------------------------------------------------------------------------------- subroutine damage_nonlocal_putNonLocalDamage(phi,ip,el) - use material, only: & - material_homogenizationAt, & - damageMapping, & - damage integer, intent(in) :: & ip, & !< integration point number @@ -286,16 +249,12 @@ subroutine damage_nonlocal_putNonLocalDamage(phi,ip,el) damage(homog)%p(offset) = phi end subroutine damage_nonlocal_putNonLocalDamage - + + !-------------------------------------------------------------------------------------------------- !> @brief return array of damage results !-------------------------------------------------------------------------------------------------- function damage_nonlocal_postResults(ip,el) - use material, only: & - material_homogenizationAt, & - damage_typeInstance, & - damageMapping, & - damage integer, intent(in) :: & ip, & !< integration point diff --git a/src/kinematics_cleavage_opening.f90 b/src/kinematics_cleavage_opening.f90 index a79dc4042..60d9cb500 100644 --- a/src/kinematics_cleavage_opening.f90 +++ b/src/kinematics_cleavage_opening.f90 @@ -5,13 +5,20 @@ !> @details to be done !-------------------------------------------------------------------------------------------------- module kinematics_cleavage_opening - use prec + use prec + use IO + use config + use debug + use math + use lattice + use material implicit none private - integer, dimension(:), allocatable, private :: kinematics_cleavage_opening_instance - type, private :: tParameters !< container type for internal constitutive parameters + integer, dimension(:), allocatable :: kinematics_cleavage_opening_instance + + type :: tParameters !< container type for internal constitutive parameters integer :: & totalNcleavage integer, dimension(:), allocatable :: & @@ -25,17 +32,17 @@ module kinematics_cleavage_opening end type ! Begin Deprecated - integer, dimension(:), allocatable, private :: & + integer, dimension(:), allocatable :: & kinematics_cleavage_opening_totalNcleavage !< total number of cleavage systems - integer, dimension(:,:), allocatable, private :: & + integer, dimension(:,:), allocatable :: & kinematics_cleavage_opening_Ncleavage !< number of cleavage systems per family - real(pReal), dimension(:), allocatable, private :: & + real(pReal), dimension(:), allocatable :: & kinematics_cleavage_opening_sdot_0, & kinematics_cleavage_opening_N - real(pReal), dimension(:,:), allocatable, private :: & + real(pReal), dimension(:,:), allocatable :: & kinematics_cleavage_opening_critDisp, & kinematics_cleavage_opening_critLoad ! End Deprecated @@ -51,22 +58,7 @@ contains !> @brief module initialization !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- -subroutine kinematics_cleavage_opening_init() - use debug, only: & - debug_level,& - debug_constitutive,& - debug_levelBasic - use config, only: & - config_phase - use IO, only: & - IO_error - use material, only: & - phase_kinematics, & - KINEMATICS_cleavage_opening_label, & - KINEMATICS_cleavage_opening_ID - use lattice, only: & - lattice_maxNcleavageFamily, & - lattice_NcleavageSystem +subroutine kinematics_cleavage_opening_init integer, allocatable, dimension(:) :: tempInt real(pReal), allocatable, dimension(:) :: tempFloat @@ -75,7 +67,7 @@ subroutine kinematics_cleavage_opening_init() write(6,'(/,a)') ' <<<+- kinematics_'//KINEMATICS_cleavage_opening_LABEL//' init -+>>>' - maxNinstance = int(count(phase_kinematics == KINEMATICS_cleavage_opening_ID)) + maxNinstance = count(phase_kinematics == KINEMATICS_cleavage_opening_ID) if (maxNinstance == 0) return if (iand(debug_level(debug_constitutive),debug_levelBasic) /= 0) & @@ -127,17 +119,6 @@ end subroutine kinematics_cleavage_opening_init !> @brief contains the constitutive equation for calculating the velocity gradient !-------------------------------------------------------------------------------------------------- subroutine kinematics_cleavage_opening_LiAndItsTangent(Ld, dLd_dTstar, S, ipc, ip, el) - use math, only: & - math_mul33xx33 - use material, only: & - material_phase, & - material_homogenizationAt, & - damage, & - damageMapping - use lattice, only: & - lattice_Scleavage, & - lattice_maxNcleavageFamily, & - lattice_NcleavageSystem integer, intent(in) :: & ipc, & !< grain number diff --git a/src/kinematics_slipplane_opening.f90 b/src/kinematics_slipplane_opening.f90 index f29c0e252..3e37e4c0d 100644 --- a/src/kinematics_slipplane_opening.f90 +++ b/src/kinematics_slipplane_opening.f90 @@ -6,12 +6,19 @@ !-------------------------------------------------------------------------------------------------- module kinematics_slipplane_opening use prec + use config + use IO + use debug + use math + use lattice + use material implicit none private - integer, dimension(:), allocatable, private :: kinematics_slipplane_opening_instance + + integer, dimension(:), allocatable :: kinematics_slipplane_opening_instance - type, private :: tParameters !< container type for internal constitutive parameters + type :: tParameters !< container type for internal constitutive parameters integer :: & totalNslip integer, dimension(:), allocatable :: & @@ -19,7 +26,7 @@ module kinematics_slipplane_opening real(pReal) :: & sdot0, & n - real(pReal), dimension(:), allocatable :: & + real(pReal), dimension(:), allocatable :: & critLoad real(pReal), dimension(:,:), allocatable :: & slip_direction, & @@ -27,7 +34,8 @@ module kinematics_slipplane_opening slip_transverse end type tParameters - type(tParameters), dimension(:), allocatable, private :: param !< containers of constitutive parameters (len Ninstance) + type(tParameters), dimension(:), allocatable :: param !< containers of constitutive parameters (len Ninstance) + public :: & kinematics_slipplane_opening_init, & kinematics_slipplane_opening_LiAndItsTangent @@ -39,23 +47,7 @@ contains !> @brief module initialization !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- -subroutine kinematics_slipplane_opening_init() - use debug, only: & - debug_level,& - debug_constitutive,& - debug_levelBasic - use config, only: & - config_phase - use IO, only: & - IO_error - use math, only: & - math_expand - use material, only: & - phase_kinematics, & - KINEMATICS_slipplane_opening_label, & - KINEMATICS_slipplane_opening_ID - use lattice - +subroutine kinematics_slipplane_opening_init integer :: maxNinstance,p,instance @@ -111,14 +103,6 @@ end subroutine kinematics_slipplane_opening_init !> @brief contains the constitutive equation for calculating the velocity gradient !-------------------------------------------------------------------------------------------------- subroutine kinematics_slipplane_opening_LiAndItsTangent(Ld, dLd_dTstar, S, ipc, ip, el) - use math, only: & - math_mul33xx33, & - math_outer - use material, only: & - material_phase, & - material_homogenizationAt, & - damage, & - damageMapping integer, intent(in) :: & ipc, & !< grain number diff --git a/src/kinematics_thermal_expansion.f90 b/src/kinematics_thermal_expansion.f90 index 86932ea69..b4f23dfa7 100644 --- a/src/kinematics_thermal_expansion.f90 +++ b/src/kinematics_thermal_expansion.f90 @@ -5,11 +5,17 @@ !-------------------------------------------------------------------------------------------------- module kinematics_thermal_expansion use prec - + use IO + use config + use debug + use math + use lattice + use material + implicit none private - type, private :: tParameters + type :: tParameters real(pReal), allocatable, dimension(:,:,:) :: & expansion end type tParameters @@ -28,19 +34,9 @@ contains !> @brief module initialization !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- -subroutine kinematics_thermal_expansion_init() - use debug, only: & - debug_level,& - debug_constitutive,& - debug_levelBasic - use material, only: & - phase_kinematics, & - KINEMATICS_thermal_expansion_label, & - KINEMATICS_thermal_expansion_ID - use config, only: & - config_phase +subroutine kinematics_thermal_expansion_init - integer(pInt) :: & + integer :: & Ninstance, & p, i real(pReal), dimension(:), allocatable :: & @@ -48,14 +44,14 @@ subroutine kinematics_thermal_expansion_init() write(6,'(/,a)') ' <<<+- kinematics_'//KINEMATICS_thermal_expansion_LABEL//' init -+>>>' - Ninstance = int(count(phase_kinematics == KINEMATICS_thermal_expansion_ID),pInt) + Ninstance = count(phase_kinematics == KINEMATICS_thermal_expansion_ID) - if (iand(debug_level(debug_constitutive),debug_levelBasic) /= 0_pInt) & + if (iand(debug_level(debug_constitutive),debug_levelBasic) /= 0) & write(6,'(a16,1x,i5,/)') '# instances:',Ninstance allocate(param(Ninstance)) - do p = 1_pInt, size(phase_kinematics) + do p = 1, size(phase_kinematics) if (all(phase_kinematics(:,p) /= KINEMATICS_thermal_expansion_ID)) cycle ! ToDo: Here we need to decide how to extend the concept of instances to @@ -78,13 +74,8 @@ end subroutine kinematics_thermal_expansion_init !> @brief report initial thermal strain based on current temperature deviation from reference !-------------------------------------------------------------------------------------------------- pure function kinematics_thermal_expansion_initialStrain(homog,phase,offset) - use material, only: & - temperature - use lattice, only: & - lattice_thermalExpansion33, & - lattice_referenceTemperature - integer(pInt), intent(in) :: & + integer, intent(in) :: & phase, & homog, offset real(pReal), dimension(3,3) :: & @@ -106,17 +97,8 @@ end function kinematics_thermal_expansion_initialStrain !> @brief contains the constitutive equation for calculating the velocity gradient !-------------------------------------------------------------------------------------------------- subroutine kinematics_thermal_expansion_LiAndItsTangent(Li, dLi_dTstar, ipc, ip, el) - use material, only: & - material_phase, & - material_homogenizationAt, & - temperature, & - temperatureRate, & - thermalMapping - use lattice, only: & - lattice_thermalExpansion33, & - lattice_referenceTemperature - integer(pInt), intent(in) :: & + integer, intent(in) :: & ipc, & !< grain number ip, & !< integration point number el !< element number @@ -124,7 +106,7 @@ subroutine kinematics_thermal_expansion_LiAndItsTangent(Li, dLi_dTstar, ipc, ip, Li !< thermal velocity gradient real(pReal), intent(out), dimension(3,3,3,3) :: & dLi_dTstar !< derivative of Li with respect to Tstar (4th-order tensor defined to be zero) - integer(pInt) :: & + integer :: & phase, & homog, offset real(pReal) :: & diff --git a/src/source_damage_anisoBrittle.f90 b/src/source_damage_anisoBrittle.f90 index 494bbc6f0..2f5fc119f 100644 --- a/src/source_damage_anisoBrittle.f90 +++ b/src/source_damage_anisoBrittle.f90 @@ -101,7 +101,7 @@ subroutine source_damage_anisoBrittle_init write(6,'(/,a)') ' <<<+- source_'//SOURCE_DAMAGE_ANISOBRITTLE_LABEL//' init -+>>>' - Ninstance = int(count(phase_source == SOURCE_damage_anisoBrittle_ID)) + Ninstance = count(phase_source == SOURCE_damage_anisoBrittle_ID) if (Ninstance == 0) return if (iand(debug_level(debug_constitutive),debug_levelBasic) /= 0) & diff --git a/src/source_damage_isoBrittle.f90 b/src/source_damage_isoBrittle.f90 index 90aa5089f..3e0e94f82 100644 --- a/src/source_damage_isoBrittle.f90 +++ b/src/source_damage_isoBrittle.f90 @@ -84,7 +84,7 @@ subroutine source_damage_isoBrittle_init write(6,'(/,a)') ' <<<+- source_'//SOURCE_DAMAGE_ISOBRITTLE_LABEL//' init -+>>>' - Ninstance = int(count(phase_source == SOURCE_damage_isoBrittle_ID)) + Ninstance = count(phase_source == SOURCE_damage_isoBrittle_ID) if (Ninstance == 0) return if (iand(debug_level(debug_constitutive),debug_levelBasic) /= 0) & From 7b620e3ce92f5c2d9ba322069e5205eb4cc11904 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 17 May 2019 06:49:25 +0200 Subject: [PATCH 018/120] [skip ci] consistent with rest of the module --- src/math.f90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/math.f90 b/src/math.f90 index 1740ebdb7..f2c0303da 100644 --- a/src/math.f90 +++ b/src/math.f90 @@ -274,6 +274,7 @@ pure function math_identity2nd(dimen) end function math_identity2nd + !-------------------------------------------------------------------------------------------------- !> @brief symmetric fourth rank identity tensor of specified dimension ! from http://en.wikipedia.org/wiki/Tensor_derivative_(continuum_mechanics)#Derivative_of_a_second-order_tensor_with_respect_to_itself @@ -626,6 +627,7 @@ pure function math_skew33(m) end function math_skew33 + !-------------------------------------------------------------------------------------------------- !> @brief hydrostatic part of a 33 matrix !-------------------------------------------------------------------------------------------------- From 68d2d1dd5e23f765dae80269634ed343256378f4 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 17 May 2019 05:12:01 +0000 Subject: [PATCH 019/120] less complaints from the Intel compiler --- cmake/Compiler-Intel.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/Compiler-Intel.cmake b/cmake/Compiler-Intel.cmake index 998f60326..60ed46cbc 100644 --- a/cmake/Compiler-Intel.cmake +++ b/cmake/Compiler-Intel.cmake @@ -32,6 +32,8 @@ # disables warnings ... set (COMPILE_FLAGS "${COMPILE_FLAGS} 5268") # ... the text exceeds right hand column allowed on the line (we have only comments there) + set (COMPILE_FLAGS "${COMPILE_FLAGS},7624") + # ... about deprecated forall (has nice syntax and most likely a performance advantage) set (COMPILE_FLAGS "${COMPILE_FLAGS} -warn") # enables warnings ... From 7ac0013271e31a3267ec60417e1beef4c2f30a91 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 17 May 2019 05:24:01 +0000 Subject: [PATCH 020/120] more consistent private/public declarations --- src/Lambert.f90 | 1 + src/math.f90 | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Lambert.f90 b/src/Lambert.f90 index 601cf9984..a528ea8b0 100644 --- a/src/Lambert.f90 +++ b/src/Lambert.f90 @@ -38,6 +38,7 @@ !> Modeling and Simulations in Materials Science and Engineering 22, 075013 (2014). !-------------------------------------------------------------------------- module Lambert + use prec use math implicit none diff --git a/src/math.f90 b/src/math.f90 index f2c0303da..4a32be274 100644 --- a/src/math.f90 +++ b/src/math.f90 @@ -10,12 +10,20 @@ module math use future implicit none - real(pReal), parameter, public :: PI = acos(-1.0_pReal) !< ratio of a circle's circumference to its diameter - real(pReal), parameter, public :: INDEG = 180.0_pReal/PI !< conversion from radian into degree - real(pReal), parameter, public :: INRAD = PI/180.0_pReal !< conversion from degree into radian - complex(pReal), parameter, public :: TWOPIIMG = cmplx(0.0_pReal,2.0_pReal*PI) !< Re(0.0), Im(2xPi) + public +#if __INTEL_COMPILER >= 1900 + ! do not make use associated entities available to other modules + private :: & + prec, & + future +#endif - real(pReal), dimension(3,3), parameter, public :: & + real(pReal), parameter :: PI = acos(-1.0_pReal) !< ratio of a circle's circumference to its diameter + real(pReal), parameter :: INDEG = 180.0_pReal/PI !< conversion from radian into degree + real(pReal), parameter :: INRAD = PI/180.0_pReal !< conversion from degree into radian + complex(pReal), parameter :: TWOPIIMG = cmplx(0.0_pReal,2.0_pReal*PI) !< Re(0.0), Im(2xPi) + + real(pReal), dimension(3,3), parameter :: & MATH_I3 = reshape([& 1.0_pReal,0.0_pReal,0.0_pReal, & 0.0_pReal,1.0_pReal,0.0_pReal, & @@ -75,7 +83,7 @@ module math !--------------------------------------------------------------------------------------------------- private :: & - math_check + unitTest contains @@ -116,14 +124,15 @@ subroutine math_init write(6,'(a,4(/,26x,f17.14),/)') ' start of random sequence: ', randTest call random_seed(put = randInit) - call math_check + call unitTest end subroutine math_init + !-------------------------------------------------------------------------------------------------- !> @brief check correctness of (some) math functions !-------------------------------------------------------------------------------------------------- -subroutine math_check +subroutine unitTest use IO, only: IO_error character(len=64) :: error_msg @@ -145,7 +154,7 @@ subroutine math_check call IO_error(401,ext_msg=error_msg) endif -end subroutine math_check +end subroutine unitTest !-------------------------------------------------------------------------------------------------- From f20c8fcffdcbc17a0c5511e720ae2627759c3c77 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 24 May 2019 22:30:25 +0200 Subject: [PATCH 021/120] easier generation and modificaton of grid geometries fits better than the general ASCII table class --- python/damask/__init__.py | 2 +- python/damask/geom.py | 133 +++++++++++++++++++++++++++++ python/damask/geometry/__init__.py | 7 -- python/damask/geometry/geometry.py | 21 ----- python/damask/geometry/marc.py | 9 -- python/damask/geometry/spectral.py | 9 -- 6 files changed, 134 insertions(+), 47 deletions(-) create mode 100644 python/damask/geom.py delete mode 100644 python/damask/geometry/__init__.py delete mode 100644 python/damask/geometry/geometry.py delete mode 100644 python/damask/geometry/marc.py delete mode 100644 python/damask/geometry/spectral.py diff --git a/python/damask/__init__.py b/python/damask/__init__.py index 684ab48b5..c5677aaf5 100644 --- a/python/damask/__init__.py +++ b/python/damask/__init__.py @@ -18,7 +18,7 @@ from .dadf5 import DADF5 # noqa #from .block import Block # only one class from .result import Result # noqa -from .geometry import Geometry # noqa +from .geom import Geom # noqa from .solver import Solver # noqa from .test import Test # noqa from .util import extendableOption # noqa diff --git a/python/damask/geom.py b/python/damask/geom.py new file mode 100644 index 000000000..c1a119ca0 --- /dev/null +++ b/python/damask/geom.py @@ -0,0 +1,133 @@ +import numpy as np +import math +from io import StringIO +import io + +class Geom(): + + def __init__(self,size,microstructure,homogenization=1,comments=[]): + """Geometry definition for grid solvers""" + + if len(size) != 3 or any(np.array(size)<=0): + raise ValueError('invalid size') + else: + self.size = np.array(size) + + if len(microstructure.shape) != 3: + raise ValueError('invalid microstructure') + else: + self.microstructure = microstructure + + if not isinstance(homogenization,int) or homogenization < 1: + raise ValueError('invalid homogenization') + else: + self.homogenization = homogenization + + if not isinstance(comments,list): + self.comments = [str(comments)] + else: + self.comments = [str(comment) for comment in comments] + + def __repr__(self): + f=StringIO() + self.to_file(f) + f.seek(0) + return ''.join(f.readlines()) + + def add_comment(self,comment): + if not isinstance(comment,list): + self.comments += [str(comment)] + else: + self.comments += [str(c) for c in comment] + + def set_size(self,size): + self.size = np.array(size) + + def get_size(self): + return self.size + + def get_grid(self): + return np.array(self.microstructure.shape) + + def get_homogenization(self): + return self.homogenization + + @classmethod + def from_file(cls,fname): + if isinstance(fname,str): + with open(fname) as f: + header_length = int(f.readline().split()[0]) + comments_old = [f.readline() for i in range(header_length)] + else: + fname.seek(0) + header_length = int(fname.readline().split()[0]) + comments_old = [fname.readline() for i in range(header_length)] + + comments = [] + for i,line in enumerate(comments_old): + if line.lower().strip().startswith('grid'): + grid = np.array([int(line.split()[j]) for j in [2,4,6]]) # assume correct order (a,b,c) + elif line.lower().strip().startswith('size'): + size = np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) + elif line.lower().strip().startswith('homogenization'): + homogenization = int(line.split()[1]) + else: + comments.append(line[:-1]) + + try: + if isinstance(fname,io.TextIOWrapper) or isinstance(fname,io.StringIO): + fname.seek(0) + microstructure = np.loadtxt(fname,skiprows=header_length+1) + if np.any(np.mod(microstructure.flatten(),1)!=0.0): + pass + else: + microstructure = microstructure.astype('int') + except: # has 'to' and 'of' compression + if isinstance(fname,str): + with open(fname) as f: + raw = f.readlines()[header_length+1:] + else: + fname.seek(0) + raw = fname.readlines()[header_length+1:] + + microstructure = np.empty(grid.prod()) # initialize as flat array + i = 0 + + for line in raw: + items = line.split() + if len(items) == 3: + if items[1].lower() == 'of': + items = np.ones(int(items[0]))*int(items[2]) + elif items[1].lower() == 'to': + items = np.linspace(int(items[0]),int(items[2]), + abs(int(items[2])-int(items[0]))+1,dtype=int) + else: items = list(map(int,items)) + else: items = list(map(int,items)) + + microstructure[i:i+len(items)] = items + i += len(items) + microstructure = microstructure.reshape(grid,order='F') + + return cls(size,microstructure.reshape(grid),homogenization,comments) + + def to_file(self,fname): + grid = self.get_grid() + header = ['{} header'.format(len(self.comments)+3)] + header += self.comments + header.append('grid a {} b {} c {}'.format(*grid)) + header.append('size a {} b {} c {}'.format(*self.get_size())) + header.append('homogenization {}'.format(self.get_homogenization())) + if self.microstructure.dtype == 'int': + format_string='%{}i'.format(int(math.floor(math.log10(self.microstructure.max())+1))) + else: + format_string='%.18e' + np.savetxt(fname, self.microstructure.reshape([np.prod(grid[1:]),grid[0]],order='F'), + header='\n'.join(header), fmt=format_string, comments='') + + def info(self): + return ['grid a b c: {}'.format(' x '.join(map(str,self.get_grid()))), + 'size x y z: {}'.format(' x '.join(map(str,self.get_size()))), + 'homogenization: {}'.format(self.get_homogenization()), + '# microstructures: {}'.format(len(np.unique(self.microstructure))), + 'max microstructures: {}'.format(np.max(self.microstructure)), + ] diff --git a/python/damask/geometry/__init__.py b/python/damask/geometry/__init__.py deleted file mode 100644 index 51199965b..000000000 --- a/python/damask/geometry/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: UTF-8 no BOM -*- - -"""Aggregator for geometry handling""" - -from .geometry import Geometry # noqa -from .spectral import Spectral # noqa -from .marc import Marc # noqa diff --git a/python/damask/geometry/geometry.py b/python/damask/geometry/geometry.py deleted file mode 100644 index 0976299e3..000000000 --- a/python/damask/geometry/geometry.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: UTF-8 no BOM -*- - - -import damask.geometry - -class Geometry(): - """ - General class for geometry parsing. - - Sub-classed by the individual solvers. - """ - - def __init__(self,solver=''): - solverClass = { - 'spectral': damask.geometry.Spectral, - 'marc': damask.geometry.Marc, - } - if solver.lower() in list(solverClass.keys()): - self.__class__=solverClass[solver.lower()] - self.__init__() - diff --git a/python/damask/geometry/marc.py b/python/damask/geometry/marc.py deleted file mode 100644 index 405227664..000000000 --- a/python/damask/geometry/marc.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- coding: UTF-8 no BOM -*- - - -from .geometry import Geometry - -class Marc(Geometry): - - def __init__(self): - self.solver='Marc' diff --git a/python/damask/geometry/spectral.py b/python/damask/geometry/spectral.py deleted file mode 100644 index 0e4f19399..000000000 --- a/python/damask/geometry/spectral.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- coding: UTF-8 no BOM -*- - - -from .geometry import Geometry - -class Spectral(Geometry): - - def __init__(self): - self.solver='Spectral' From 420abfa162306ee7108c8c5230a2cb10a047f6b9 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 24 May 2019 22:31:34 +0200 Subject: [PATCH 022/120] use new class --- processing/pre/geom_fromMinimalSurface.py | 63 +++---------- processing/pre/geom_rotate.py | 110 ++++++---------------- python/damask/geom.py | 4 +- 3 files changed, 48 insertions(+), 129 deletions(-) diff --git a/processing/pre/geom_fromMinimalSurface.py b/processing/pre/geom_fromMinimalSurface.py index e0023e7ec..66e26c8e2 100755 --- a/processing/pre/geom_fromMinimalSurface.py +++ b/processing/pre/geom_fromMinimalSurface.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys +import math import numpy as np from optparse import OptionParser import damask @@ -71,60 +73,25 @@ parser.set_defaults(type = minimal_surfaces[0], if filenames == []: filenames = [None] for name in filenames: - try: - table = damask.ASCIItable(outname = name, - buffered = False, labeled = False) - except: continue + damask.util.report(scriptName,name) - -# ------------------------------------------ make grid ------------------------------------- - - info = { - 'grid': np.array(options.grid), - 'size': np.array(options.size), - 'origin': np.zeros(3,'d'), - 'microstructures': max(options.microstructure), - 'homogenization': options.homogenization - } - -#--- report --------------------------------------------------------------------------------------- - - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -#--- write header --------------------------------------------------------------------------------- - - table.labels_clear() - table.info_clear() - table.info_append([ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=info['microstructures']), - ]) - table.head_write() - -#--- write data ----------------------------------------------------------------------------------- - X = options.periods*2.0*math.pi*(np.arange(options.grid[0])+0.5)/options.grid[0] Y = options.periods*2.0*math.pi*(np.arange(options.grid[1])+0.5)/options.grid[1] Z = options.periods*2.0*math.pi*(np.arange(options.grid[2])+0.5)/options.grid[2] + microstructure = np.empty(options.grid,dtype='int') for z in range(options.grid[2]): for y in range(options.grid[1]): - table.data_clear() for x in range(options.grid[0]): - table.data_append(options.microstructure[options.threshold < surface[options.type](X[x],Y[y],Z[z])]) - table.data_write() + microstructure[x,y,z]=options.microstructure[options.threshold < surface[options.type](X[x],Y[y],Z[z])] + + geom=damask.Geom(options.size,microstructure,options.homogenization, + comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) - table.close() + damask.util.croak('\n'.join(geom.info())) + + if name is None: + sys.stdout.write(str(geom)) + else: + geom.to_file(name) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 7cce5800d..57f4eacbf 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -1,9 +1,11 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys import numpy as np import damask +from io import StringIO from scipy import ndimage from optparse import OptionParser @@ -42,15 +44,9 @@ parser.add_option('-q', '--quaternion', parser.add_option('-f', '--fill', dest = 'fill', type = 'int', metavar = 'int', - help = 'background grain index. "0" selects maximum microstructure index + 1 [%default]') -parser.add_option('--float', - dest = 'float', - action = 'store_true', - help = 'use float input') + help = 'background grain index, defaults to max + 1') parser.set_defaults(degrees = False, - fill = 0, - float = False, ) (options, filenames) = parser.parse_args() @@ -67,82 +63,38 @@ if options.matrix is not None: if options.eulers is not None: eulers = damask.Rotation.fromEulers(np.array(options.eulers),degrees=True).asEulers(degrees=True) -datatype = 'f' if options.float else 'i' - # --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: - try: - table = damask.ASCIItable(name = name, - buffered = False, - labeled = False) - except: continue + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + try: # really needed? Why not simply fail if file does not exists etc. + geom = damask.Geom.from_file(name) + except: continue damask.util.report(scriptName,name) -# --- interpret header ---------------------------------------------------------------------------- + microstructure = geom.microstructure + spacing = geom.get_size()/geom.get_grid() - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ------------------------------------------------------------------------------------ - - microstructure = table.microstructure_read(info['grid'],datatype).reshape(info['grid'],order='F') # read microstructure - - newGrainID = options.fill if options.fill != 0 else np.nanmax(microstructure)+1 - microstructure = ndimage.rotate(microstructure,eulers[2],(0,1),order=0,prefilter=False,output=int,cval=newGrainID) # rotation around Z - microstructure = ndimage.rotate(microstructure,eulers[1],(1,2),order=0,prefilter=False,output=int,cval=newGrainID) # rotation around X - microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0,prefilter=False,output=int,cval=newGrainID) # rotation around Z - -# --- do work ------------------------------------------------------------------------------------ - - newInfo = { - 'size': microstructure.shape*info['size']/info['grid'], - 'grid': microstructure.shape, - 'microstructures': len(np.unique(microstructure)), - } - -# --- report --------------------------------------------------------------------------------------- - - remarks = [] - if (any(newInfo['grid'] != info['grid'])): - remarks.append('--> grid a b c: {}'.format(' x '.join(map(str,newInfo['grid'])))) - if (any(newInfo['size'] != info['size'])): - remarks.append('--> size x y z: {}'.format(' x '.join(map(str,newInfo['size'])))) - if ( newInfo['microstructures'] != info['microstructures']): - remarks.append('--> microstructures: {}'.format(newInfo['microstructures'])) - if remarks != []: damask.util.croak(remarks) - -# --- write header --------------------------------------------------------------------------------- - - table.labels_clear() - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=newInfo['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=newInfo['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']), - ]) - table.head_write() - -# --- write microstructure information ------------------------------------------------------------ - - format = '%g' if options.float else '%{}i'.format(int(math.floor(math.log10(np.nanmax(microstructure))+1))) - table.data = microstructure.reshape((newInfo['grid'][0],np.prod(newInfo['grid'][1:])),order='F').transpose() - table.data_writeArray(format,delimiter=' ') - -# --- output finalization -------------------------------------------------------------------------- - - table.close() # close ASCII table + newGrainID = options.fill if options.fill is not None else np.nanmax(microstructure)+1 + microstructure = ndimage.rotate(microstructure,eulers[2],(0,1),order=0, + prefilter=False,output=microstructure.dtype,cval=newGrainID) # rotation around Z + microstructure = ndimage.rotate(microstructure,eulers[1],(1,2),order=0, + prefilter=False,output=microstructure.dtype,cval=newGrainID) # rotation around X + microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0, + prefilter=False,output=microstructure.dtype,cval=newGrainID) # rotation around Z + + geom.microstructure = microstructure + geom.set_size(microstructure.shape*spacing) + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + + damask.util.croak('\n'.join(geom.info())) + + if name is None: + sys.stdout.write(str(geom)) + else: + geom.to_file(name) diff --git a/python/damask/geom.py b/python/damask/geom.py index c1a119ca0..0f411458f 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -4,10 +4,9 @@ from io import StringIO import io class Geom(): + """Geometry definition for grid solvers""" def __init__(self,size,microstructure,homogenization=1,comments=[]): - """Geometry definition for grid solvers""" - if len(size) != 3 or any(np.array(size)<=0): raise ValueError('invalid size') else: @@ -29,6 +28,7 @@ class Geom(): self.comments = [str(comment) for comment in comments] def __repr__(self): + """Readable string""" f=StringIO() self.to_file(f) f.seek(0) From 7b6003fb3212c346076f209e119bd5d28bb4a2b9 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 08:17:51 +0200 Subject: [PATCH 023/120] no need for numpy.loadtxt (not compatible with 'to' and 'of' compression --- python/damask/geom.py | 62 ++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 0f411458f..45096a520 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -74,40 +74,36 @@ class Geom(): else: comments.append(line[:-1]) - try: - if isinstance(fname,io.TextIOWrapper) or isinstance(fname,io.StringIO): - fname.seek(0) - microstructure = np.loadtxt(fname,skiprows=header_length+1) - if np.any(np.mod(microstructure.flatten(),1)!=0.0): - pass - else: - microstructure = microstructure.astype('int') - except: # has 'to' and 'of' compression - if isinstance(fname,str): - with open(fname) as f: - raw = f.readlines()[header_length+1:] - else: - fname.seek(0) - raw = fname.readlines()[header_length+1:] + if isinstance(fname,str): + with open(fname) as f: + raw = f.readlines()[header_length+1:] + else: + raw = fname.readlines() - microstructure = np.empty(grid.prod()) # initialize as flat array - i = 0 + microstructure = np.empty(grid.prod()) # initialize as flat array + i = 0 - for line in raw: - items = line.split() - if len(items) == 3: - if items[1].lower() == 'of': - items = np.ones(int(items[0]))*int(items[2]) - elif items[1].lower() == 'to': - items = np.linspace(int(items[0]),int(items[2]), - abs(int(items[2])-int(items[0]))+1,dtype=int) - else: items = list(map(int,items)) - else: items = list(map(int,items)) - - microstructure[i:i+len(items)] = items - i += len(items) + for line in raw: + items = line.split() + if len(items) == 3: + if items[1].lower() == 'of': + items = np.ones(float(items[0]))*int(items[2]) + elif items[1].lower() == 'to': + items = np.linspace(int(items[0]),int(items[2]), + abs(int(items[2])-int(items[0]))+1,dtype=float) + else: items = list(map(float,items)) + else: items = list(map(float,items)) + + microstructure[i:i+len(items)] = items + i += len(items) + microstructure = microstructure.reshape(grid,order='F') - + + if np.any(np.mod(microstructure.flatten(),1)!=0.0): + pass + else: + microstructure = microstructure.astype('int') + return cls(size,microstructure.reshape(grid),homogenization,comments) def to_file(self,fname): @@ -115,13 +111,13 @@ class Geom(): header = ['{} header'.format(len(self.comments)+3)] header += self.comments header.append('grid a {} b {} c {}'.format(*grid)) - header.append('size a {} b {} c {}'.format(*self.get_size())) + header.append('size x {} y {} z {}'.format(*self.get_size())) header.append('homogenization {}'.format(self.get_homogenization())) if self.microstructure.dtype == 'int': format_string='%{}i'.format(int(math.floor(math.log10(self.microstructure.max())+1))) else: format_string='%.18e' - np.savetxt(fname, self.microstructure.reshape([np.prod(grid[1:]),grid[0]],order='F'), + np.savetxt(fname, self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T, header='\n'.join(header), fmt=format_string, comments='') def info(self): From cf374a04dc1bfa7b1a3f41f8e3c40f5924d92868 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 08:18:48 +0200 Subject: [PATCH 024/120] using new class --- processing/pre/geom_vicinityOffset.py | 76 +++++++-------------------- python/damask/geom.py | 1 - 2 files changed, 19 insertions(+), 58 deletions(-) diff --git a/processing/pre/geom_vicinityOffset.py b/processing/pre/geom_vicinityOffset.py index 733276d01..73a14520f 100755 --- a/processing/pre/geom_vicinityOffset.py +++ b/processing/pre/geom_vicinityOffset.py @@ -1,10 +1,12 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys import numpy as np from scipy import ndimage from optparse import OptionParser +from io import StringIO import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] @@ -63,35 +65,16 @@ options.trigger = np.array(options.trigger, dtype=int) if filenames == []: filenames = [None] for name in filenames: - try: - table = damask.ASCIItable(name = name, - buffered = False, labeled = False) - except: continue + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + try: # really needed? Why not simply fail if file does not exists etc. + geom = damask.Geom.from_file(name) + except: continue damask.util.report(scriptName,name) -# --- interpret header ---------------------------------------------------------------------------- - - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ------------------------------------------------------------------------------------ - - microstructure = table.microstructure_read(info['grid']).reshape(info['grid'],order='F') # read microstructure - -# --- do work ------------------------------------------------------------------------------------ - - newInfo = { - 'microstructures': 0, - } + microstructure = geom.microstructure if options.offset == 0: options.offset = microstructure.max() @@ -102,33 +85,12 @@ for name in filenames: extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}), microstructure + options.offset,microstructure) - newInfo['microstructures'] = len(np.unique(microstructure)) - -# --- report --------------------------------------------------------------------------------------- - - if (newInfo['microstructures'] != info['microstructures']): - damask.util.croak('--> microstructures: %i'%newInfo['microstructures']) - -# --- write header --------------------------------------------------------------------------------- - - table.labels_clear() - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']), - ]) - table.head_write() + geom.microstructure = microstructure + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) -# --- write microstructure information ------------------------------------------------------------ - - formatwidth = int(math.floor(math.log10(np.nanmax(microstructure))+1)) - table.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose() - table.data_writeArray('%{}i'.format(formatwidth),delimiter = ' ') - -# --- output finalization -------------------------------------------------------------------------- - - table.close() # close ASCII table + damask.util.croak('\n'.join(geom.info())) + + if name is None: + sys.stdout.write(str(geom)) + else: + geom.to_file(name) diff --git a/python/damask/geom.py b/python/damask/geom.py index 45096a520..5c34eeebb 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -1,7 +1,6 @@ import numpy as np import math from io import StringIO -import io class Geom(): """Geometry definition for grid solvers""" From 6c7f7c77dac1eaee5342bd452b621c7403000420 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 08:24:32 +0200 Subject: [PATCH 025/120] specifying non-existing or invalid files is an user error this is the standard behavior for common unix tools, no need to make an exception here --- processing/pre/geom_rotate.py | 5 ++--- processing/pre/geom_vicinityOffset.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 57f4eacbf..c343e2752 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -72,9 +72,8 @@ for name in filenames: virt_file = StringIO(''.join(sys.stdin.read())) geom = damask.Geom.from_file(virt_file) else: - try: # really needed? Why not simply fail if file does not exists etc. - geom = damask.Geom.from_file(name) - except: continue + geom = damask.Geom.from_file(name) + damask.util.report(scriptName,name) microstructure = geom.microstructure diff --git a/processing/pre/geom_vicinityOffset.py b/processing/pre/geom_vicinityOffset.py index 73a14520f..e23d905f9 100755 --- a/processing/pre/geom_vicinityOffset.py +++ b/processing/pre/geom_vicinityOffset.py @@ -69,9 +69,8 @@ for name in filenames: virt_file = StringIO(''.join(sys.stdin.read())) geom = damask.Geom.from_file(virt_file) else: - try: # really needed? Why not simply fail if file does not exists etc. - geom = damask.Geom.from_file(name) - except: continue + geom = damask.Geom.from_file(name) + damask.util.report(scriptName,name) microstructure = geom.microstructure From 4788fc6046f177939435b459af54d3a5e24aeadd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 08:36:00 +0200 Subject: [PATCH 026/120] making use of new class @philip: 1D arrangement needed? --- processing/pre/geom_unpack.py | 59 ++++++++++------------------------- python/damask/geom.py | 2 +- 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/processing/pre/geom_unpack.py b/processing/pre/geom_unpack.py index 4cac76c5f..fb5b58198 100755 --- a/processing/pre/geom_unpack.py +++ b/processing/pre/geom_unpack.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys +import math import numpy as np from optparse import OptionParser import damask @@ -33,48 +35,19 @@ parser.set_defaults(oneD = False, if filenames == []: filenames = [None] for name in filenames: - try: - table = damask.ASCIItable(name = name, - buffered = False, labeled = False) - except: continue + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + damask.util.report(scriptName,name) -# --- interpret header ---------------------------------------------------------------------------- - - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- write header --------------------------------------------------------------------------------- - - table.labels_clear() - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=info['microstructures']), - ]) - table.head_write() + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) -# --- write microstructure information ------------------------------------------------------------ - - microstructure = table.microstructure_read(info['grid']) # read microstructure - formatwidth = int(math.floor(math.log10(microstructure.max())+1)) # efficient number printing format - table.data = microstructure if options.oneD else \ - microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose() - table.data_writeArray('%%%ii'%(formatwidth),delimiter = ' ') - -#--- output finalization -------------------------------------------------------------------------- - - table.close() # close ASCII table + damask.util.croak('\n'.join(geom.info())) + + if name is None: + sys.stdout.write(str(geom)) + else: + geom.to_file(name) diff --git a/python/damask/geom.py b/python/damask/geom.py index 5c34eeebb..def9e9f0c 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -86,7 +86,7 @@ class Geom(): items = line.split() if len(items) == 3: if items[1].lower() == 'of': - items = np.ones(float(items[0]))*int(items[2]) + items = np.ones(int(items[0]))*float(items[2]) elif items[1].lower() == 'to': items = np.linspace(int(items[0]),int(items[2]), abs(int(items[2])-int(items[0]))+1,dtype=float) From 17eb0d1b20ae629bdb50bfff94bb7ea5891aa66b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 08:48:44 +0200 Subject: [PATCH 027/120] using new class --- processing/pre/geom_mirror.py | 96 +++++++++-------------------------- 1 file changed, 23 insertions(+), 73 deletions(-) diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index 853b99632..953e10e2d 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys import numpy as np import damask from optparse import OptionParser @@ -23,13 +24,6 @@ parser.add_option('-d','--direction', dest = 'directions', action = 'extend', metavar = '', help = "directions in which to mirror {'x','y','z'}") -parser.add_option('--float', - dest = 'float', - action = 'store_true', - help = 'use float input') - -parser.set_defaults(float = False, - ) (options, filenames) = parser.parse_args() @@ -38,83 +32,39 @@ if options.directions is None: if not set(options.directions).issubset(validDirections): invalidDirections = [str(e) for e in set(options.directions).difference(validDirections)] parser.error('invalid directions {}. '.format(*invalidDirections)) - -datatype = 'f' if options.float else 'i' + # --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: - try: - table = damask.ASCIItable(name = name, - buffered = False, - labeled = False) - except: continue + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + damask.util.report(scriptName,name) -# --- interpret header ---------------------------------------------------------------------------- - - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ------------------------------------------------------------------------------------ - - microstructure = table.microstructure_read(info['grid'],datatype).reshape(info['grid'],order='F') # read microstructure + microstructure = geom.microstructure if 'z' in options.directions: microstructure = np.concatenate([microstructure,microstructure[:,:,::-1]],2) + geom.set_size(geom.get_size()*np.array([1,1,2])) if 'y' in options.directions: microstructure = np.concatenate([microstructure,microstructure[:,::-1,:]],1) + geom.set_size(geom.get_size()*np.array([1,2,1])) if 'x' in options.directions: microstructure = np.concatenate([microstructure,microstructure[::-1,:,:]],0) - -# --- do work ------------------------------------------------------------------------------------ - - newInfo = { - 'size': microstructure.shape*info['size']/info['grid'], - 'grid': microstructure.shape, - } - - -# --- report --------------------------------------------------------------------------------------- - - remarks = [] - if (any(newInfo['grid'] != info['grid'])): - remarks.append('--> grid a b c: %s'%(' x '.join(map(str,newInfo['grid'])))) - if (any(newInfo['size'] != info['size'])): - remarks.append('--> size x y z: %s'%(' x '.join(map(str,newInfo['size'])))) - if remarks != []: damask.util.croak(remarks) - -# --- write header --------------------------------------------------------------------------------- - - table.labels_clear() - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=newInfo['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=newInfo['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=info['microstructures']), - ]) - table.head_write() - -# --- write microstructure information ------------------------------------------------------------ - - formatwidth = int(math.floor(math.log10(np.nanmax(microstructure))+1)) - table.data = microstructure.reshape((newInfo['grid'][0],np.prod(newInfo['grid'][1:])),order='F').transpose() - table.data_writeArray('%{}i'.format(formatwidth),delimiter = ' ') - -# --- output finalization -------------------------------------------------------------------------- - - table.close() # close ASCII table + geom.set_size(geom.get_size()*np.array([2,1,1])) + + geom.microstructure = microstructure + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + + damask.util.croak('\n'.join(geom.info())) + + if name is None: + sys.stdout.write(str(geom)) + else: + geom.to_file(name) From 875643c363a251fbc5ca6e9585e26329ac2a76d7 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 10:14:53 +0200 Subject: [PATCH 028/120] same style --- processing/pre/geom_fromMinimalSurface.py | 6 +- processing/pre/geom_mirror.py | 3 +- processing/pre/geom_renumber.py | 82 ++++------------ processing/pre/geom_rotate.py | 15 ++- processing/pre/geom_translate.py | 109 ++++++---------------- processing/pre/geom_unpack.py | 12 +-- processing/pre/geom_vicinityOffset.py | 10 +- python/damask/geom.py | 26 +++--- 8 files changed, 82 insertions(+), 181 deletions(-) diff --git a/processing/pre/geom_fromMinimalSurface.py b/processing/pre/geom_fromMinimalSurface.py index 66e26c8e2..37610edd0 100755 --- a/processing/pre/geom_fromMinimalSurface.py +++ b/processing/pre/geom_fromMinimalSurface.py @@ -73,7 +73,6 @@ parser.set_defaults(type = minimal_surfaces[0], if filenames == []: filenames = [None] for name in filenames: - damask.util.report(scriptName,name) X = options.periods*2.0*math.pi*(np.arange(options.grid[0])+0.5)/options.grid[0] @@ -89,9 +88,8 @@ for name in filenames: geom=damask.Geom(options.size,microstructure,options.homogenization, comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) - damask.util.croak('\n'.join(geom.info())) - + damask.util.croak(geom) if name is None: - sys.stdout.write(str(geom)) + sys.stdout.write(str(geom.show())) else: geom.to_file(name) diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index 953e10e2d..ded9b373b 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -4,8 +4,9 @@ import os import sys import numpy as np -import damask from optparse import OptionParser +from io import StringIO +import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) diff --git a/processing/pre/geom_renumber.py b/processing/pre/geom_renumber.py index 3faa7f449..f4570d08c 100755 --- a/processing/pre/geom_renumber.py +++ b/processing/pre/geom_renumber.py @@ -1,10 +1,12 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys import numpy as np -import damask from optparse import OptionParser +from io import StringIO +import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) @@ -25,36 +27,14 @@ renumber sorted microstructure indices to 1,...,N. if filenames == []: filenames = [None] for name in filenames: - try: table = damask.ASCIItable(name = name, - buffered = False, - labeled = False) - except: continue damask.util.report(scriptName,name) - -# --- interpret header --------------------------------------------------------------------------- - - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ---------------------------------------------------------------------------------- - - microstructure = table.microstructure_read(info['grid']) # read microstructure - -# --- do work ------------------------------------------------------------------------------------ - - newInfo = { - 'origin': np.zeros(3,'d'), - 'microstructures': 0, - } + + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + microstructure = geom.microstructure grainIDs = np.unique(microstructure) renumbered = np.copy(microstructure) @@ -62,35 +42,11 @@ for name in filenames: for i, oldID in enumerate(grainIDs): renumbered = np.where(microstructure == oldID, i+1, renumbered) - newInfo['microstructures'] = len(grainIDs) - -# --- report ------------------------------------------------------------------------------------- - - remarks = [] - if ( newInfo['microstructures'] != info['microstructures']): - remarks.append('--> microstructures: %i'%newInfo['microstructures']) - if remarks != []: damask.util.croak(remarks) - -# --- write header ------------------------------------------------------------------------------- - - table.labels_clear() - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']), - ]) - table.head_write() - -# --- write microstructure information ----------------------------------------------------------- - - format = '%{}i'.format(int(math.floor(math.log10(np.nanmax(renumbered))+1))) - table.data = renumbered.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose() - table.data_writeArray(format,delimiter = ' ') - -# --- output finalization ------------------------------------------------------------------------ - - table.close() # close ASCII table + geom.microstructure = renumbered + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + + damask.util.croak(geom) + if name is None: + sys.stdout.write(str(geom.show())) + else: + geom.to_file(name) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index c343e2752..98faf1e6b 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -57,26 +57,26 @@ if sum(x is not None for x in [options.rotation,options.eulers,options.matrix,op if options.quaternion is not None: eulers = damask.Rotation.fromQuaternion(np.array(options.quaternion)).asEulers(degrees=True) if options.rotation is not None: - eulers = damask.Rotation.fromAxisAngle(np.array(options.rotation,degrees=True)).asEulers(degrees=True) + eulers = damask.Rotation.fromAxisAngle(np.array(options.rotation,degrees=options.degrees)).asEulers(degrees=True) if options.matrix is not None: eulers = damask.Rotation.fromMatrix(np.array(options.Matrix)).asEulers(degrees=True) if options.eulers is not None: - eulers = damask.Rotation.fromEulers(np.array(options.eulers),degrees=True).asEulers(degrees=True) + eulers = damask.Rotation.fromEulers(np.array(options.eulers),degrees=options.degrees).asEulers(degrees=True) # --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: + damask.util.report(scriptName,name) + if name is None: virt_file = StringIO(''.join(sys.stdin.read())) geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - - damask.util.report(scriptName,name) - microstructure = geom.microstructure + spacing = geom.get_size()/geom.get_grid() newGrainID = options.fill if options.fill is not None else np.nanmax(microstructure)+1 @@ -91,9 +91,8 @@ for name in filenames: geom.set_size(microstructure.shape*spacing) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak('\n'.join(geom.info())) - + damask.util.croak(geom) if name is None: - sys.stdout.write(str(geom)) + sys.stdout.write(str(geom.show())) else: geom.to_file(name) diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index 072c270ea..aa05166f7 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -1,10 +1,12 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys import numpy as np -import damask from optparse import OptionParser +from io import StringIO +import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) @@ -30,98 +32,47 @@ parser.add_option('-s', '--substitute', dest = 'substitute', action = 'extend', metavar = '', help = 'substitutions of microstructure indices from,to,from,to,...') -parser.add_option('--float', - dest = 'float', - action = 'store_true', - help = 'use float input') parser.set_defaults(origin = (0.0,0.0,0.0), microstructure = 0, - substitute = [], - float = False, + substitute = [] ) (options, filenames) = parser.parse_args() -datatype = 'f' if options.float else 'i' - sub = {} for i in range(len(options.substitute)//2): # split substitution list into "from" -> "to" sub[int(options.substitute[i*2])] = int(options.substitute[i*2+1]) -# --- loop over input files ---------------------------------------------------------------------- +# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: - try: table = damask.ASCIItable(name = name, - buffered = False, - labeled = False) - except: continue damask.util.report(scriptName,name) + + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + microstructure = geom.microstructure + + for k, v in sub.items(): microstructure[geom.microstructure==k] = v # substitute microstructure indices -# --- interpret header --------------------------------------------------------------------------- + microstructure += options.microstructure # shift microstructure indices - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ---------------------------------------------------------------------------------- - - microstructure = table.microstructure_read(info['grid'],datatype) # read microstructure - -# --- do work ------------------------------------------------------------------------------------ - - newInfo = { - 'origin': np.zeros(3,'d'), - 'microstructures': 0, - } - - substituted = np.copy(microstructure) - for k, v in sub.items(): substituted[microstructure==k] = v # substitute microstructure indices - - substituted += options.microstructure # shift microstructure indices - - newInfo['origin'] = info['origin'] + options.origin - newInfo['microstructures'] = len(np.unique(substituted)) - -# --- report ------------------------------------------------------------------------------------- - - remarks = [] - if (any(newInfo['origin'] != info['origin'])): - remarks.append('--> origin x y z: {}'.format(' : '.join(map(str,newInfo['origin'])))) - if ( newInfo['microstructures'] != info['microstructures']): - remarks.append('--> microstructures: {}'.format(newInfo['microstructures'])) - if remarks != []: damask.util.croak(remarks) - -# --- write header ------------------------------------------------------------------------------- - - table.labels_clear() - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=newInfo['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']), - ]) - table.head_write() - -# --- write microstructure information ----------------------------------------------------------- - - format = '%g' if options.float else '%{}i'.format(int(math.floor(math.log10(np.nanmax(substituted))+1))) - table.data = substituted.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose() - table.data_writeArray(format,delimiter = ' ') - -# --- output finalization ------------------------------------------------------------------------ - - table.close() # close ASCII table + for i,line in enumerate(geom.comments): + if line.lower().strip().startswith('origin'): + origin= np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) + origin += np.array(origin) + geom.comments[i] = 'origin x {} y {} z {}'.format(*origin) + + geom.microstructure = microstructure + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + + damask.util.croak(geom) + if name is None: + sys.stdout.write(str(geom.show())) + else: + geom.to_file(name) diff --git a/processing/pre/geom_unpack.py b/processing/pre/geom_unpack.py index fb5b58198..40b6c0e64 100755 --- a/processing/pre/geom_unpack.py +++ b/processing/pre/geom_unpack.py @@ -3,9 +3,8 @@ import os import sys -import math -import numpy as np from optparse import OptionParser +from io import StringIO import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] @@ -35,19 +34,18 @@ parser.set_defaults(oneD = False, if filenames == []: filenames = [None] for name in filenames: + damask.util.report(scriptName,name) + if name is None: virt_file = StringIO(''.join(sys.stdin.read())) geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.report(scriptName,name) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak('\n'.join(geom.info())) - + damask.util.croak(geom) if name is None: - sys.stdout.write(str(geom)) + sys.stdout.write(str(geom.show())) else: geom.to_file(name) diff --git a/processing/pre/geom_vicinityOffset.py b/processing/pre/geom_vicinityOffset.py index e23d905f9..535650244 100755 --- a/processing/pre/geom_vicinityOffset.py +++ b/processing/pre/geom_vicinityOffset.py @@ -65,14 +65,13 @@ options.trigger = np.array(options.trigger, dtype=int) if filenames == []: filenames = [None] for name in filenames: + damask.util.report(scriptName,name) + if name is None: virt_file = StringIO(''.join(sys.stdin.read())) geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - - damask.util.report(scriptName,name) - microstructure = geom.microstructure if options.offset == 0: options.offset = microstructure.max() @@ -87,9 +86,8 @@ for name in filenames: geom.microstructure = microstructure geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak('\n'.join(geom.info())) - + damask.util.croak(geom) if name is None: - sys.stdout.write(str(geom)) + sys.stdout.write(str(geom.show())) else: geom.to_file(name) diff --git a/python/damask/geom.py b/python/damask/geom.py index def9e9f0c..ee924f8c0 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -6,6 +6,7 @@ class Geom(): """Geometry definition for grid solvers""" def __init__(self,size,microstructure,homogenization=1,comments=[]): + """New geometry definition from array of microstructures and size""" if len(size) != 3 or any(np.array(size)<=0): raise ValueError('invalid size') else: @@ -26,12 +27,13 @@ class Geom(): else: self.comments = [str(comment) for comment in comments] - def __repr__(self): - """Readable string""" - f=StringIO() - self.to_file(f) - f.seek(0) - return ''.join(f.readlines()) + def __repr__(self): + """Basic information on geometry definition""" + return 'grid a b c: {}\n'.format(' x '.join(map(str,self.get_grid()))) + \ + 'size x y z: {}\n'.format(' x '.join(map(str,self.get_size()))) + \ + 'homogenization: {}\n'.format(self.get_homogenization()) + \ + '# microstructures: {}\n'.format(len(np.unique(self.microstructure))) + \ + 'max microstructures: {}\n'.format(np.max(self.microstructure)) def add_comment(self,comment): if not isinstance(comment,list): @@ -119,10 +121,8 @@ class Geom(): np.savetxt(fname, self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T, header='\n'.join(header), fmt=format_string, comments='') - def info(self): - return ['grid a b c: {}'.format(' x '.join(map(str,self.get_grid()))), - 'size x y z: {}'.format(' x '.join(map(str,self.get_size()))), - 'homogenization: {}'.format(self.get_homogenization()), - '# microstructures: {}'.format(len(np.unique(self.microstructure))), - 'max microstructures: {}'.format(np.max(self.microstructure)), - ] + def show(self): + f=StringIO() + self.to_file(f) + f.seek(0) + return ''.join(f.readlines()) From fc1f65c34ec4c41969ecdf383eee551c98830a07 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 10:36:46 +0200 Subject: [PATCH 029/120] works for dtype='float' --- processing/pre/geom_clean.py | 76 +++++----------- processing/pre/geom_rescale.py | 157 +++++++-------------------------- 2 files changed, 56 insertions(+), 177 deletions(-) diff --git a/processing/pre/geom_clean.py b/processing/pre/geom_clean.py index 1d0769ab3..a4027efa0 100755 --- a/processing/pre/geom_clean.py +++ b/processing/pre/geom_clean.py @@ -1,9 +1,11 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys import numpy as np import damask +from io import StringIO from scipy import ndimage from optparse import OptionParser @@ -11,7 +13,8 @@ scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) def mostFrequent(arr): - return np.argmax(np.bincount(arr.astype('int'))) + unique, inverse = np.unique(arr, return_inverse=True) + return unique[np.argmax(np.bincount(inverse))] #-------------------------------------------------------------------------------------------------- @@ -29,8 +32,7 @@ parser.add_option('-s','--stencil', type = 'int', metavar = 'int', help = 'size of smoothing stencil [%default]') -parser.set_defaults(stencil = 3, - ) +parser.set_defaults(stencil = 3) (options, filenames) = parser.parse_args() @@ -40,55 +42,23 @@ parser.set_defaults(stencil = 3, if filenames == []: filenames = [None] for name in filenames: - try: table = damask.ASCIItable(name = name, - buffered = False, - labeled = False) - except: continue damask.util.report(scriptName,name) + + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + microstructure = geom.microstructure -# --- interpret header ---------------------------------------------------------------------------- + microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent, + size=(options.stencil,)*3).astype(microstructure.dtype) - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ------------------------------------------------------------------------------------ - - microstructure = table.microstructure_read(info['grid']).reshape(info['grid'],order='F') # read microstructure - -# --- do work ------------------------------------------------------------------------------------ - - microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent,size=(options.stencil,)*3).astype('int_') - newInfo = {'microstructures': len(np.unique(microstructure))} - -# --- report --------------------------------------------------------------------------------------- - if ( newInfo['microstructures'] != info['microstructures']): - damask.util.croak('--> microstructures: %i'%newInfo['microstructures']) - info['microstructures'] == newInfo['microstructures'] - -# --- write header --------------------------------------------------------------------------------- - - table.info_clear() - table.info_append([scriptID + ' ' + ' '.join(sys.argv[1:]),]) - table.head_putGeom(info) - table.info_append([extra_header]) - table.labels_clear() - table.head_write() - -# --- write microstructure information ------------------------------------------------------------ - - formatwidth = int(math.floor(math.log10(np.nanmax(microstructure))+1)) - table.data = microstructure.reshape((info['grid'][0],np.prod(info['grid'][1:])),order='F').transpose() - table.data_writeArray('%{}i'.format(formatwidth),delimiter = ' ') - -# --- output finalization -------------------------------------------------------------------------- - - table.close() # close ASCII table + geom.microstructure = microstructure + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + + damask.util.croak(geom) + if name is None: + sys.stdout.write(str(geom.show())) + else: + geom.to_file(name) diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index 4a14c0050..48d26e8f5 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -1,9 +1,11 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys import numpy as np from optparse import OptionParser +from scipy import ndimage import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] @@ -27,137 +29,44 @@ parser.add_option('-s', '--size', dest = 'size', type = 'string', nargs = 3, metavar = 'string string string', help = 'x,y,z size of hexahedral box [unchanged]') -parser.add_option('-r', '--renumber', - dest = 'renumber', - action = 'store_true', - help = 'renumber microstructure indices from 1..N [%default]') -parser.add_option('--float', - dest = 'float', - action = 'store_true', - help = 'use float input') - -parser.set_defaults(renumber = False, - grid = ['0','0','0'], - size = ['0.0','0.0','0.0'], - float = False, - ) (options, filenames) = parser.parse_args() -datatype = 'f' if options.float else 'i' - # --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: - try: - table = damask.ASCIItable(name = name, - buffered = False, - labeled = False) - except: continue damask.util.report(scriptName,name) - -# --- interpret header ---------------------------------------------------------------------------- - - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ------------------------------------------------------------------------------------ - - microstructure = table.microstructure_read(info['grid'],datatype) # read microstructure - -# --- do work ------------------------------------------------------------------------------------ - - newInfo = { - 'grid': np.zeros(3,'i'), - 'origin': np.zeros(3,'d'), - 'microstructures': 0, - } - - newInfo['grid'] = np.array([{True: round(o*float(n.lower().replace('x',''))), - False: round(float(n.lower().replace('x','')))}[n[-1].lower() == 'x'] - for o,n in zip(info['grid'],options.grid)],'i') - newInfo['size'] = np.array([{True: o*float(n.lower().replace('x','')), - False: float(n.lower().replace('x',''))}[n[-1].lower() == 'x'] - for o,n in zip(info['size'],options.size)],'d') - newInfo['grid'] = np.where(newInfo['grid'] <= 0 , info['grid'],newInfo['grid']) - newInfo['size'] = np.where(newInfo['size'] <= 0.0, info['size'],newInfo['size']) - - multiplicity = [] - for j in range(3): - multiplicity.append([]) - last = 0 - for i in range(info['grid'][j]): - this = int((i+1)*float(newInfo['grid'][j])/info['grid'][j]) - multiplicity[j].append(this-last) - last = this - - microstructure = microstructure.reshape(info['grid'],order='F') - microstructure = np.repeat(np.repeat(np.repeat(microstructure, - multiplicity[0], axis=0),multiplicity[1], axis=1),multiplicity[2], axis=2) -# --- renumber to sequence 1...Ngrains if requested ------------------------------------------------ -# http://stackoverflow.com/questions/10741346/np-frequency-counts-for-unique-values-in-an-array - - if options.renumber: - newID = 0 - for microstructureID,count in enumerate(np.bincount(microstructure.reshape(newInfo['grid'].prod()))): - if count != 0: - newID += 1 - microstructure = np.where(microstructure == microstructureID, newID,microstructure).reshape(microstructure.shape) - - newInfo['microstructures'] = len(np.unique(microstructure)) - -# --- report --------------------------------------------------------------------------------------- - - remarks = [] - errors = [] - - if (any(newInfo['grid'] != info['grid'])): - remarks.append('--> grid a b c: %s'%(' x '.join(map(str,newInfo['grid'])))) - if (any(newInfo['size'] != info['size'])): - remarks.append('--> size x y z: %s'%(' x '.join(map(str,newInfo['size'])))) - if ( newInfo['microstructures'] != info['microstructures']): - remarks.append('--> microstructures: %i'%newInfo['microstructures']) - - if np.any(newInfo['grid'] < 1): errors.append('invalid new grid a b c.') - if np.any(newInfo['size'] <= 0.0): errors.append('invalid new size x y z.') - - if remarks != []: damask.util.croak(remarks) - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- write header --------------------------------------------------------------------------------- - - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=newInfo['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=newInfo['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']), - ]) - table.labels_clear() - table.head_write() - -# --- write microstructure information ------------------------------------------------------------ - - format = '%g' if options.float else '%{}i'.format(int(math.floor(math.log10(np.nanmax(microstructure))+1))) - table.data = microstructure.reshape((newInfo['grid'][0],newInfo['grid'][1]*newInfo['grid'][2]),order='F').transpose() - table.data_writeArray(format,delimiter=' ') -# --- output finalization -------------------------------------------------------------------------- + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + microstructure = geom.microstructure - table.close() # close ASCII table + scale = geom.get_grid().astype('float') + if options.grid is not None: + for i,g in enumerate(options.grid): + scale[i] = scale[i]*float(g.lower().replace('x','')) if g.lower().startswith('x') \ + else float(options.grid[i])/scale[i] + + size = geom.get_size() + if options.size is not None: + for i,s in enumerate(options.size): + size[i] = size[i]*float(s.lower().replace('x','')) if s.lower().startswith('x') \ + else options.size[i] + + microstructure = ndimage.interpolation.zoom(microstructure, scale, output=microstructure.dtype, + order=0, mode='nearest', prefilter=False) + + geom.microstructure = microstructure + geom.set_size(size) + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + + damask.util.croak(geom) + if name is None: + sys.stdout.write(str(geom.show())) + else: + geom.to_file(name) From 94f85b7f3379e464d206d589c4e440b194756bc2 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 10:45:58 +0200 Subject: [PATCH 030/120] better readable --- processing/pre/geom_addPrimitive.py | 107 ++++++++-------------------- 1 file changed, 30 insertions(+), 77 deletions(-) diff --git a/processing/pre/geom_addPrimitive.py b/processing/pre/geom_addPrimitive.py index 0dfd06732..ec7a84ec6 100755 --- a/processing/pre/geom_addPrimitive.py +++ b/processing/pre/geom_addPrimitive.py @@ -1,10 +1,12 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 no BOM -*- -import os,sys,math +import os +import sys import numpy as np -from optparse import OptionParser import damask +from io import StringIO +from optparse import OptionParser scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) @@ -12,18 +14,6 @@ scriptID = ' '.join([scriptName,damask.version]) #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- -identifiers = { - 'grid': ['a','b','c'], - 'size': ['x','y','z'], - 'origin': ['x','y','z'], - } -mappings = { - 'grid': lambda x: int(x), - 'size': lambda x: float(x), - 'origin': lambda x: float(x), - 'homogenization': lambda x: int(x), - 'microstructures': lambda x: int(x), - } parser = OptionParser(option_class=damask.extendableOption, usage='%prog option [geomfile(s)]', description = """ Positions a geometric object within the (three-dimensional) canvas of a spectral geometry description. @@ -63,9 +53,6 @@ parser.add_option( '--realspace', dest='realspace', parser.add_option( '--invert', dest='inside', action='store_false', help = 'invert the volume filled by the primitive (inside/outside)') -parser.add_option('--float', dest = 'float', - action = 'store_true', - help = 'use float input') parser.set_defaults(center = (.0,.0,.0), fill = 0.0, degrees = False, @@ -73,7 +60,6 @@ parser.set_defaults(center = (.0,.0,.0), periodic = True, realspace = False, inside = True, - float = False, ) (options, filenames) = parser.parse_args() @@ -87,8 +73,6 @@ elif options.quaternion is not None: else: rotation = damask.Rotation() -datatype = 'f' if options.float else 'i' - options.center = np.array(options.center) options.dimension = np.array(options.dimension) # undo logarithmic sense of exponent and generate ellipsoids for negative dimensions (backward compatibility) @@ -104,39 +88,32 @@ for name in filenames: except: continue damask.util.report(scriptName,name) -# --- interpret header ---------------------------------------------------------------------------- +# --- loop over input files ------------------------------------------------------------------------- - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) +if filenames == []: filenames = [None] - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -#--- read data ------------------------------------------------------------------------------------ - - microstructure = table.microstructure_read(info['grid'],datatype) # read microstructure - -# --- do work ------------------------------------------------------------------------------------ - - newInfo = { - 'microstructures': 0, - } +for name in filenames: + damask.util.report(scriptName,name) + + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + microstructure = geom.microstructure options.fill = np.nanmax(microstructure)+1 if options.fill == 0 else options.fill - microstructure = microstructure.reshape(info['grid'],order='F') + origin = np.zeros(3) + for i,line in enumerate(geom.comments): + if line.lower().strip().startswith('origin'): + origin= np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) # coordinates given in real space (default) vs voxel space if options.realspace: - options.center -= info['origin'] - options.center *= np.array(info['grid']) / np.array(info['size']) - options.dimension *= np.array(info['grid']) / np.array(info['size']) + options.center -= origin + options.center *= geom.get_grid() / geom.get_size() + options.dimension *= geom.get_grid() / geom.get_size() grid = microstructure.shape @@ -209,35 +186,11 @@ for name in filenames: options.fill if options.inside else microstructure, microstructure if options.inside else options.fill) - np.seterr(**old_settings) # Reset warnings to old state - newInfo['microstructures'] = len(np.unique(microstructure)) - -# --- report --------------------------------------------------------------------------------------- - if (newInfo['microstructures'] != info['microstructures']): - damask.util.croak('--> microstructures: {}'.format(newInfo['microstructures'])) - - -#--- write header --------------------------------------------------------------------------------- - - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {}\tb {}\tc {}".format(*info['grid']), - "size\tx {}\ty {}\tz {}".format(*info['size']), - "origin\tx {}\ty {}\tz {}".format(*info['origin']), - "homogenization\t{}".format(info['homogenization']), - "microstructures\t{}".format(newInfo['microstructures']), - ]) - table.labels_clear() - table.head_write() - table.output_flush() - -# --- write microstructure information ------------------------------------------------------------ - - format = '%g' if options.float else '%{}i'.format(int(math.floor(math.log10(np.nanmax(microstructure))+1))) - table.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose() - table.data_writeArray(format,delimiter = ' ') - -#--- output finalization -------------------------------------------------------------------------- - - table.close() + geom.microstructure = microstructure + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + + damask.util.croak(geom) + if name is None: + sys.stdout.write(str(geom.show())) + else: + geom.to_file(name) From c92969787ac39d32d0665ed083dfe32cdbe46a86 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 11:56:06 +0200 Subject: [PATCH 031/120] geom Class was updated --- processing/pre/geom_mirror.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index ded9b373b..469d48183 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -40,32 +40,30 @@ if not set(options.directions).issubset(validDirections): if filenames == []: filenames = [None] for name in filenames: + damask.util.report(scriptName,name) + if name is None: virt_file = StringIO(''.join(sys.stdin.read())) geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - - damask.util.report(scriptName,name) - microstructure = geom.microstructure if 'z' in options.directions: - microstructure = np.concatenate([microstructure,microstructure[:,:,::-1]],2) + microstructure = np.concatenate([microstructure,microstructure[:,:,::-1]],2) # better not double edges geom.set_size(geom.get_size()*np.array([1,1,2])) if 'y' in options.directions: - microstructure = np.concatenate([microstructure,microstructure[:,::-1,:]],1) + microstructure = np.concatenate([microstructure,microstructure[:,::-1,:]],1) # better not double edges geom.set_size(geom.get_size()*np.array([1,2,1])) if 'x' in options.directions: - microstructure = np.concatenate([microstructure,microstructure[::-1,:,:]],0) + microstructure = np.concatenate([microstructure,microstructure[::-1,:,:]],0) # better not double edges geom.set_size(geom.get_size()*np.array([2,1,1])) geom.microstructure = microstructure geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak('\n'.join(geom.info())) - + damask.util.croak(geom) if name is None: - sys.stdout.write(str(geom)) + sys.stdout.write(str(geom.show())) else: geom.to_file(name) From 2b7d95f800ff99e33aecb437fb6b05c1b24b7600 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 12:09:09 +0200 Subject: [PATCH 032/120] was accidently commited gives different results due to interpolation from scipy --- processing/pre/geom_rescale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index 48d26e8f5..2e4dfa2d9 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -3,7 +3,7 @@ import os import sys -import numpy as np +from io import StringIO from optparse import OptionParser from scipy import ndimage import damask From 9f63d768decc8c1d7f42e6fa2e95e454a812ab8d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 13:48:38 +0200 Subject: [PATCH 033/120] do not keep whitespaces --- python/damask/geom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index ee924f8c0..254d0fb04 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -73,7 +73,7 @@ class Geom(): elif line.lower().strip().startswith('homogenization'): homogenization = int(line.split()[1]) else: - comments.append(line[:-1]) + comments.append(line.rstrip().strip()) if isinstance(fname,str): with open(fname) as f: @@ -114,6 +114,7 @@ class Geom(): header.append('grid a {} b {} c {}'.format(*grid)) header.append('size x {} y {} z {}'.format(*self.get_size())) header.append('homogenization {}'.format(self.get_homogenization())) + if self.microstructure.dtype == 'int': format_string='%{}i'.format(int(math.floor(math.log10(self.microstructure.max())+1))) else: From 094d4d06138ab5ac4212e873532025323f428315 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 13:49:21 +0200 Subject: [PATCH 034/120] test adjusted for new geom_rescale --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index d96bfb329..d326605a4 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit d96bfb32920c96a8a43958f76a209d34c6bd841a +Subproject commit d326605a49b90dfdf3352f1a6a4ae8dd36507a13 From c89d3442369c16f7a5e350d0306388a3d2c16cc8 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 25 May 2019 13:51:05 +0200 Subject: [PATCH 035/120] polishing --- processing/pre/geom_rotate.py | 2 +- processing/pre/geom_translate.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 98faf1e6b..bda176f46 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -4,10 +4,10 @@ import os import sys import numpy as np -import damask from io import StringIO from scipy import ndimage from optparse import OptionParser +import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index aa05166f7..63fa1d421 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -58,7 +58,7 @@ for name in filenames: geom = damask.Geom.from_file(name) microstructure = geom.microstructure - for k, v in sub.items(): microstructure[geom.microstructure==k] = v # substitute microstructure indices + for k, v in sub.items(): microstructure[geom.microstructure==k] = v # substitute microstructure indices microstructure += options.microstructure # shift microstructure indices From b13aa799c3abf680b6943bbe046310a7725f407c Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Sat, 25 May 2019 17:00:41 +0200 Subject: [PATCH 036/120] updated error message --- processing/pre/geom_rotate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 98faf1e6b..1209e6162 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -52,7 +52,7 @@ parser.set_defaults(degrees = False, (options, filenames) = parser.parse_args() if sum(x is not None for x in [options.rotation,options.eulers,options.matrix,options.quaternion]) != 1: - parser.error('not exactly one rotation specified...') + parser.error('more than one rotation specified.') if options.quaternion is not None: eulers = damask.Rotation.fromQuaternion(np.array(options.quaternion)).asEulers(degrees=True) From be3513d1e0c73a2eb23e04939920ba2683494457 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 09:49:56 +0200 Subject: [PATCH 037/120] polishing. python imports follow PEP8 --- processing/pre/geom_rotate.py | 37 ++++++++++++++++++++--------------- python/damask/geom.py | 6 ++++++ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 178a87e00..c3308b8f8 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -1,12 +1,13 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np from io import StringIO -from scipy import ndimage from optparse import OptionParser + +from scipy import ndimage +import numpy as np + import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] @@ -51,8 +52,10 @@ parser.set_defaults(degrees = False, (options, filenames) = parser.parse_args() -if sum(x is not None for x in [options.rotation,options.eulers,options.matrix,options.quaternion]) != 1: +if [options.rotation,options.eulers,options.matrix,options.quaternion].count(None) < 3: parser.error('more than one rotation specified.') +if [options.rotation,options.eulers,options.matrix,options.quaternion].count(None) > 3: + parser.error('no rotation specified.') if options.quaternion is not None: eulers = damask.Rotation.fromQuaternion(np.array(options.quaternion)).asEulers(degrees=True) @@ -63,7 +66,6 @@ if options.matrix is not None: if options.eulers is not None: eulers = damask.Rotation.fromEulers(np.array(options.eulers),degrees=options.degrees).asEulers(degrees=True) -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] @@ -75,20 +77,23 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - microstructure = geom.microstructure + microstructure = geom.get_microstructure() + + + fill = options.fill if options.fill is not None else np.nanmax(microstructure)+1 + + # These rotations are always applied in the reference coordinate system, i.e. (z,x,z) not (z,x',z'') + # this seems to be ok, see https://www.cs.utexas.edu/~theshark/courses/cs354/lectures/cs354-14.pdf + microstructure = ndimage.rotate(microstructure,eulers[2],(0,1),order=0, + prefilter=False,output=microstructure.dtype,cval=fill) # rotation around z + microstructure = ndimage.rotate(microstructure,eulers[1],(1,2),order=0, + prefilter=False,output=microstructure.dtype,cval=fill) # rotation around x + microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0, + prefilter=False,output=microstructure.dtype,cval=fill) # rotation around z spacing = geom.get_size()/geom.get_grid() - - newGrainID = options.fill if options.fill is not None else np.nanmax(microstructure)+1 - microstructure = ndimage.rotate(microstructure,eulers[2],(0,1),order=0, - prefilter=False,output=microstructure.dtype,cval=newGrainID) # rotation around Z - microstructure = ndimage.rotate(microstructure,eulers[1],(1,2),order=0, - prefilter=False,output=microstructure.dtype,cval=newGrainID) # rotation around X - microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0, - prefilter=False,output=microstructure.dtype,cval=newGrainID) # rotation around Z - - geom.microstructure = microstructure geom.set_size(microstructure.shape*spacing) + geom.set_microstructure(microstructure) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) damask.util.croak(geom) diff --git a/python/damask/geom.py b/python/damask/geom.py index 254d0fb04..7a154e516 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -41,9 +41,15 @@ class Geom(): else: self.comments += [str(c) for c in comment] + def set_microstructure(self,microstructure): + self.microstructure = microstructure + def set_size(self,size): self.size = np.array(size) + def get_microstructure(self): + return self.microstructure + def get_size(self): return self.size From dcb79afc84f8305a02f743e90f24c3c7fdc0032d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 12:03:21 +0200 Subject: [PATCH 038/120] more user friendly errors --- python/damask/geom.py | 45 ++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 7a154e516..1c10c4652 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -1,24 +1,28 @@ -import numpy as np import math from io import StringIO +import numpy as np + + class Geom(): """Geometry definition for grid solvers""" def __init__(self,size,microstructure,homogenization=1,comments=[]): """New geometry definition from array of microstructures and size""" if len(size) != 3 or any(np.array(size)<=0): - raise ValueError('invalid size') + raise ValueError('Invalid size {}'.format(*size)) else: self.size = np.array(size) if len(microstructure.shape) != 3: - raise ValueError('invalid microstructure') + raise ValueError('Invalid microstructure shape {}'.format(*microstructure.shape)) + elif microstructure.dtype not in ['int','float']: + raise TypeError('Invalid data type {} for microstructure'.format(microstructure.dtype)) else: self.microstructure = microstructure if not isinstance(homogenization,int) or homogenization < 1: - raise ValueError('invalid homogenization') + raise TypeError('Invalid homogenization {}'.format(homogenization)) else: self.homogenization = homogenization @@ -47,6 +51,7 @@ class Geom(): def set_size(self,size): self.size = np.array(size) + def get_microstructure(self): return self.microstructure @@ -59,37 +64,42 @@ class Geom(): def get_homogenization(self): return self.homogenization + @classmethod def from_file(cls,fname): + """Reads from *.geom file""" if isinstance(fname,str): - with open(fname) as f: - header_length = int(f.readline().split()[0]) - comments_old = [f.readline() for i in range(header_length)] + f = open(fname) + header_length,keyword = f.readline().split() + if not keyword.startswith('head') or int(header_length) < 3: + raise TypeError('Header length information missing or invalid') + comments_old = [f.readline() for i in range(int(header_length))] else: fname.seek(0) - header_length = int(fname.readline().split()[0]) - comments_old = [fname.readline() for i in range(header_length)] + header_length,keyword = f.readline().split() + if not keyword.startswith('head') or int(header_length) < 3: + raise TypeError('Header length information missing or invalid') + comments_old = [fname.readline() for i in range(int(header_length))] comments = [] for i,line in enumerate(comments_old): if line.lower().strip().startswith('grid'): - grid = np.array([int(line.split()[j]) for j in [2,4,6]]) # assume correct order (a,b,c) + grid = np.array([int(line.split()[j]) for j in [2,4,6]]) # assume correct order (a,b,c) elif line.lower().strip().startswith('size'): - size = np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) + size = np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) elif line.lower().strip().startswith('homogenization'): homogenization = int(line.split()[1]) else: comments.append(line.rstrip().strip()) if isinstance(fname,str): - with open(fname) as f: - raw = f.readlines()[header_length+1:] + raw = f.readlines() + f.close() else: raw = fname.readlines() - microstructure = np.empty(grid.prod()) # initialize as flat array + microstructure = np.empty(grid.prod()) # initialize as flat array i = 0 - for line in raw: items = line.split() if len(items) == 3: @@ -104,6 +114,9 @@ class Geom(): microstructure[i:i+len(items)] = items i += len(items) + if i != grid.prod(): + raise TypeError('Invalid file: expected {} entries,found {}'.format(grid.prod(),i)) + microstructure = microstructure.reshape(grid,order='F') if np.any(np.mod(microstructure.flatten(),1)!=0.0): @@ -114,6 +127,7 @@ class Geom(): return cls(size,microstructure.reshape(grid),homogenization,comments) def to_file(self,fname): + """Saves to file""" grid = self.get_grid() header = ['{} header'.format(len(self.comments)+3)] header += self.comments @@ -129,6 +143,7 @@ class Geom(): header='\n'.join(header), fmt=format_string, comments='') def show(self): + """Show raw content (as in file)""" f=StringIO() self.to_file(f) f.seek(0) From 974f67ffdc70eaa17955115b93610b960c0e6cbd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 12:06:51 +0200 Subject: [PATCH 039/120] no frills --- processing/pre/geom_unpack.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/processing/pre/geom_unpack.py b/processing/pre/geom_unpack.py index 40b6c0e64..b8efa49c2 100755 --- a/processing/pre/geom_unpack.py +++ b/processing/pre/geom_unpack.py @@ -1,35 +1,28 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys from optparse import OptionParser from io import StringIO + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ -Unpack geometry files containing ranges "a to b" and/or "n of x" multiples (exclusively in one line). +parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile(s)]', description = """ +Unpack ranges "a to b" and/or "n of x" multiples (exclusively in one line). """, version = scriptID) -parser.add_option('-1', '--onedimensional', - dest = 'oneD', - action = 'store_true', - help = 'output geom file with one-dimensional data arrangement') - -parser.set_defaults(oneD = False, - ) - (options, filenames) = parser.parse_args() -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] From e7b8ae08d0e5f95680d902aef8069adbeece9fe1 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 12:11:30 +0200 Subject: [PATCH 040/120] polishing --- processing/pre/geom_clean.py | 20 ++++++++++---------- processing/pre/geom_renumber.py | 24 ++++++++++++------------ processing/pre/geom_rotate.py | 9 +++++---- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/processing/pre/geom_clean.py b/processing/pre/geom_clean.py index a4027efa0..4d7b0a0e5 100755 --- a/processing/pre/geom_clean.py +++ b/processing/pre/geom_clean.py @@ -1,17 +1,20 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np -import damask from io import StringIO -from scipy import ndimage from optparse import OptionParser +from scipy import ndimage +import numpy as np + +import damask + + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + def mostFrequent(arr): unique, inverse = np.unique(arr, return_inverse=True) return unique[np.argmax(np.bincount(inverse))] @@ -22,11 +25,10 @@ def mostFrequent(arr): #-------------------------------------------------------------------------------------------------- parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ -Smooth geometry by selecting most frequent microstructure index within given stencil at each location. +Smooth microstructure by selecting most frequent index within given stencil at each location. """, version=scriptID) - parser.add_option('-s','--stencil', dest = 'stencil', type = 'int', metavar = 'int', @@ -37,8 +39,6 @@ parser.set_defaults(stencil = 3) (options, filenames) = parser.parse_args() -# --- loop over input files ------------------------------------------------------------------------- - if filenames == []: filenames = [None] for name in filenames: @@ -49,12 +49,12 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - microstructure = geom.microstructure + microstructure = geom.get_microstructure() microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent, size=(options.stencil,)*3).astype(microstructure.dtype) - geom.microstructure = microstructure + geom.set_microstructure(microstructure) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) damask.util.croak(geom) diff --git a/processing/pre/geom_renumber.py b/processing/pre/geom_renumber.py index f4570d08c..e46296555 100755 --- a/processing/pre/geom_renumber.py +++ b/processing/pre/geom_renumber.py @@ -1,28 +1,30 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np -from optparse import OptionParser from io import StringIO +from optparse import OptionParser + +import numpy as np + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog [file[s]]', description = """ -renumber sorted microstructure indices to 1,...,N. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ +Renumber sorted microstructure indices to 1,...,N. """, version=scriptID) (options, filenames) = parser.parse_args() -# --- loop over input files ---------------------------------------------------------------------- if filenames == []: filenames = [None] @@ -34,15 +36,13 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - microstructure = geom.microstructure - - grainIDs = np.unique(microstructure) - renumbered = np.copy(microstructure) + microstructure = geom.get_microstructure() - for i, oldID in enumerate(grainIDs): + renumbered = np.copy(microstructure) + for i, oldID in enumerate(np.unique(microstructure)): renumbered = np.where(microstructure == oldID, i+1, renumbered) - geom.microstructure = renumbered + geom.set_microstructure(renumbered) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) damask.util.croak(geom) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index c3308b8f8..eae36a842 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -10,15 +10,17 @@ import numpy as np import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ -Rotates spectral geometry description. +Rotates and embeddeds. """, version=scriptID) @@ -33,7 +35,7 @@ parser.add_option('-e', '--eulers', parser.add_option('-d', '--degrees', dest = 'degrees', action = 'store_true', - help = 'Euler angles are given in degrees [%default]') + help = 'Angles (Euler angles/axis angle) are given in degrees [%default]') parser.add_option('-m', '--matrix', dest = 'matrix', type = 'float', nargs = 9, metavar = ' '.join(['float']*9), @@ -47,8 +49,7 @@ parser.add_option('-f', '--fill', type = 'int', metavar = 'int', help = 'background grain index, defaults to max + 1') -parser.set_defaults(degrees = False, - ) +parser.set_defaults(degrees = False) (options, filenames) = parser.parse_args() From 34f7bbe2a0823bd1b49a3a3b35bf4687860b489d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 13:06:22 +0200 Subject: [PATCH 041/120] 'blank' option does not fit to flow of script seeds_fromRandom -N 1 | geom_fromVoronoiTessellation -g 30 30 30 -s 1 1 1 > file.geom or a few lines of python code give the same results --- processing/pre/geom_canvas.py | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index 01682deb8..a3f1b7f3b 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -32,30 +32,17 @@ parser.add_option('-o', parser.add_option('-f', '--fill', dest = 'fill', - type = 'float', metavar = 'float', + type = 'int', metavar = 'int', help = '(background) canvas grain index. "0" selects maximum microstructure index + 1 [%default]') -parser.add_option('--float', - dest = 'float', - action = 'store_true', - help = 'use float input') -parser.add_option('--blank', - dest = 'blank', - action = 'store_true', - help = 'blank out (optional) input canvas content') -parser.set_defaults(grid = ['0','0','0'], +parser.set_defaults(grid = ('0','0','0'), offset = (0,0,0), - fill = 0.0, - float = False, ) (options, filenames) = parser.parse_args() -datatype = 'f' if options.float else 'i' -options.grid = ['1','1','1'] if options.blank and options.grid == ['0','0','0'] else options.grid -options.fill = 1 if options.blank and options.fill == 0 else options.fill +datatype = 'i' -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] @@ -66,15 +53,7 @@ for name in filenames: except: continue damask.util.report(scriptName,name) - if options.blank: - extra_header = [] - info = {} - info['grid'] = np.zeros(3,dtype=int) - info['size'] = np.zeros(3,dtype=float) - info['origin'] = np.zeros(3,dtype=float) - info['microstructures'] = 0 - info['homogenization'] = 1 - else: + if True: # --- interpret header ---------------------------------------------------------------------------- @@ -107,9 +86,9 @@ for name in filenames: newInfo['grid'] = np.where(newInfo['grid'] > 0, newInfo['grid'],info['grid']) microstructure_cropped = np.zeros(newInfo['grid'],datatype) - microstructure_cropped.fill(options.fill if options.float or options.fill > 0 else np.nanmax(microstructure)+1) + microstructure_cropped.fill(options.fill if options.fill is not None else np.nanmax(microstructure)+1) - if not options.blank: + if True: xindex = np.arange(max(options.offset[0],0),min(options.offset[0]+newInfo['grid'][0],info['grid'][0])) yindex = np.arange(max(options.offset[1],0),min(options.offset[1]+newInfo['grid'][1],info['grid'][1])) zindex = np.arange(max(options.offset[2],0),min(options.offset[2]+newInfo['grid'][2],info['grid'][2])) @@ -172,7 +151,7 @@ for name in filenames: # --- write microstructure information ------------------------------------------------------------ - format = '%g' if options.float else '%{}i'.format(int(math.floor(math.log10(np.nanmax(microstructure_cropped))+1))) + format = '%{}i'.format(int(math.floor(math.log10(np.nanmax(microstructure_cropped))+1))) table.data = microstructure_cropped.reshape((newInfo['grid'][0],newInfo['grid'][1]*newInfo['grid'][2]),order='F').transpose() table.data_writeArray(format,delimiter=' ') From feb23409356853d1ee1f0669b1a3ec9558d5663c Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 17:48:59 +0200 Subject: [PATCH 042/120] self-reporting functionality for updating --- processing/pre/geom_rescale.py | 25 +++++++------- python/damask/geom.py | 62 ++++++++++++++++++++++++++++------ python/damask/util.py | 3 +- 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index 2e4dfa2d9..e39a9d0d6 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -1,22 +1,25 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys from io import StringIO from optparse import OptionParser + from scipy import ndimage + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ -Scales a geometry description independently in x, y, and z direction in terms of grid and/or size. +Scales independently in x, y, and z direction in terms of grid and/or size. Either absolute values or relative factors (like "0.25x") can be used. """, version = scriptID) @@ -24,15 +27,14 @@ Either absolute values or relative factors (like "0.25x") can be used. parser.add_option('-g', '--grid', dest = 'grid', type = 'string', nargs = 3, metavar = 'string string string', - help = 'a,b,c grid of hexahedral box [unchanged]') + help = 'a,b,c grid of hexahedral box') parser.add_option('-s', '--size', dest = 'size', type = 'string', nargs = 3, metavar = 'string string string', - help = 'x,y,z size of hexahedral box [unchanged]') + help = 'x,y,z size of hexahedral box') (options, filenames) = parser.parse_args() -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] @@ -44,28 +46,27 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - microstructure = geom.microstructure + damask.util.croak(geom) + microstructure = geom.get_microstructure() scale = geom.get_grid().astype('float') if options.grid is not None: for i,g in enumerate(options.grid): - scale[i] = scale[i]*float(g.lower().replace('x','')) if g.lower().startswith('x') \ + scale[i] = scale[i]*float(g.lower().replace('x','')) if g.lower().endswith('x') \ else float(options.grid[i])/scale[i] size = geom.get_size() if options.size is not None: for i,s in enumerate(options.size): - size[i] = size[i]*float(s.lower().replace('x','')) if s.lower().startswith('x') \ + size[i] = size[i]*float(s.lower().replace('x','')) if s.lower().endswith('x') \ else options.size[i] microstructure = ndimage.interpolation.zoom(microstructure, scale, output=microstructure.dtype, order=0, mode='nearest', prefilter=False) - geom.microstructure = microstructure - geom.set_size(size) + damask.util.croak(geom.update(microstructure,size)) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - - damask.util.croak(geom) + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/python/damask/geom.py b/python/damask/geom.py index 1c10c4652..389665320 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -7,12 +7,8 @@ import numpy as np class Geom(): """Geometry definition for grid solvers""" - def __init__(self,size,microstructure,homogenization=1,comments=[]): + def __init__(self,microstructure,size,homogenization=1,comments=[]): """New geometry definition from array of microstructures and size""" - if len(size) != 3 or any(np.array(size)<=0): - raise ValueError('Invalid size {}'.format(*size)) - else: - self.size = np.array(size) if len(microstructure.shape) != 3: raise ValueError('Invalid microstructure shape {}'.format(*microstructure.shape)) @@ -20,7 +16,12 @@ class Geom(): raise TypeError('Invalid data type {} for microstructure'.format(microstructure.dtype)) else: self.microstructure = microstructure - + + if len(size) != 3 or any(np.array(size)<=0): + raise ValueError('Invalid size {}'.format(*size)) + else: + self.size = np.array(size) + if not isinstance(homogenization,int) or homogenization < 1: raise TypeError('Invalid homogenization {}'.format(homogenization)) else: @@ -34,11 +35,52 @@ class Geom(): def __repr__(self): """Basic information on geometry definition""" return 'grid a b c: {}\n'.format(' x '.join(map(str,self.get_grid()))) + \ - 'size x y z: {}\n'.format(' x '.join(map(str,self.get_size()))) + \ - 'homogenization: {}\n'.format(self.get_homogenization()) + \ + 'size x y z: {}\n'.format(' x '.join(map(str,self.size))) + \ + 'homogenization: {}\n'.format(self.homogenization) + \ '# microstructures: {}\n'.format(len(np.unique(self.microstructure))) + \ 'max microstructures: {}\n'.format(np.max(self.microstructure)) + + + def update(self,microstructure=None,size=None,rescale=False): + """Updates microstructure and size""" + grid_old = self.get_grid() + size_old = self.size + unique_old = len(np.unique(self.microstructure)) + max_old = np.max(self.microstructure) + if size is not None and rescale: + raise ValueError('Either set size explicitly or rescale automatically') + + if microstructure is not None: + if len(microstructure.shape) != 3: + raise ValueError('Invalid microstructure shape {}'.format(*microstructure.shape)) + elif microstructure.dtype not in ['int','float']: + raise TypeError('Invalid data type {} for microstructure'.format(microstructure.dtype)) + else: + self.microstructure = microstructure + + if size is not None: + if len(size) != 3 or any(np.array(size)<=0): + raise ValueError('Invalid size {}'.format(*size)) + else: + self.size = np.array(size) + + if rescale: + self.size = self.size * self.get_grid()/grid_old + + message = '' + if np.any(grid_old != self.get_grid()): + message += 'grid a b c: {}\n'.format(' x '.join(map(str,self.get_grid()))) + if np.any(size_old != self.get_size()): + message += 'size x y z: {}\n'.format(' x '.join(map(str,self.size))) + if unique_old != len(np.unique(self.microstructure)): + message += '# microstructures: {}\n'.format(len(np.unique(self.microstructure))) + if max_old != np.max(self.microstructure): + message += 'max microstructures: {}\n'.format(np.max(self.microstructure)) + + if message != '': return message + + def add_comment(self,comment): if not isinstance(comment,list): self.comments += [str(comment)] @@ -124,7 +166,7 @@ class Geom(): else: microstructure = microstructure.astype('int') - return cls(size,microstructure.reshape(grid),homogenization,comments) + return cls(microstructure.reshape(grid),size,homogenization,comments) def to_file(self,fname): """Saves to file""" @@ -132,7 +174,7 @@ class Geom(): header = ['{} header'.format(len(self.comments)+3)] header += self.comments header.append('grid a {} b {} c {}'.format(*grid)) - header.append('size x {} y {} z {}'.format(*self.get_size())) + header.append('size x {} y {} z {}'.format(*self.size)) header.append('homogenization {}'.format(self.get_homogenization())) if self.microstructure.dtype == 'int': diff --git a/python/damask/util.py b/python/damask/util.py index 02cb4a2c6..d282963cd 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -44,7 +44,8 @@ def srepr(arg,glue = '\n'): # ----------------------------- def croak(what, newline = True): """Writes formated to stderr""" - sys.stderr.write(srepr(what,glue = '\n') + ('\n' if newline else '')) + if what is not None: + sys.stderr.write(srepr(what,glue = '\n') + ('\n' if newline else '')) sys.stderr.flush() # ----------------------------- From 657a30c2f52520997ab5a89bfb16f2f7aff76006 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 18:09:34 +0200 Subject: [PATCH 043/120] using new functionality --- processing/pre/geom_mirror.py | 35 ++++++++++++++++++++--------------- processing/pre/geom_rotate.py | 14 ++++++-------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index 469d48183..7974bde82 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -1,23 +1,25 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np -from optparse import OptionParser from io import StringIO +from optparse import OptionParser + +import numpy as np + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- -validDirections = ['x','y','z'] parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ -Mirrors spectral geometry description along given directions. +Mirror along given directions. """, version=scriptID) @@ -25,17 +27,23 @@ parser.add_option('-d','--direction', dest = 'directions', action = 'extend', metavar = '', help = "directions in which to mirror {'x','y','z'}") +parser.add_option( '--double', + dest = 'double', + action = 'store_true', + help = 'double the outer layers in mirror direction') (options, filenames) = parser.parse_args() if options.directions is None: parser.error('no direction given.') + +validDirections = ['x','y','z'] if not set(options.directions).issubset(validDirections): invalidDirections = [str(e) for e in set(options.directions).difference(validDirections)] parser.error('invalid directions {}. '.format(*invalidDirections)) - -# --- loop over input files ------------------------------------------------------------------------- +limits = [-2,0] if not options.double else [None,None] + if filenames == []: filenames = [None] @@ -47,22 +55,19 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) + damask.util.croak(geom) microstructure = geom.microstructure if 'z' in options.directions: - microstructure = np.concatenate([microstructure,microstructure[:,:,::-1]],2) # better not double edges - geom.set_size(geom.get_size()*np.array([1,1,2])) + microstructure = np.concatenate([microstructure,microstructure[:,:,limits[0]:limits[1]:-1]],2) if 'y' in options.directions: - microstructure = np.concatenate([microstructure,microstructure[:,::-1,:]],1) # better not double edges - geom.set_size(geom.get_size()*np.array([1,2,1])) + microstructure = np.concatenate([microstructure,microstructure[:,limits[0]:limits[1]:-1,:]],1) if 'x' in options.directions: - microstructure = np.concatenate([microstructure,microstructure[::-1,:,:]],0) # better not double edges - geom.set_size(geom.get_size()*np.array([2,1,1])) + microstructure = np.concatenate([microstructure,microstructure[limits[0]:limits[1]:-1,:,:]],0) - geom.microstructure = microstructure + damask.util.croak(geom.update(microstructure,rescale=True)) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak(geom) if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index eae36a842..4a24b338b 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -20,7 +20,7 @@ scriptID = ' '.join([scriptName,damask.version]) #-------------------------------------------------------------------------------------------------- parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ -Rotates and embeddeds. +Rotates original microstructure and embeddeds it into buffer material. """, version=scriptID) @@ -46,8 +46,8 @@ parser.add_option('-q', '--quaternion', help = 'rotation given as quaternion') parser.add_option('-f', '--fill', dest = 'fill', - type = 'int', metavar = 'int', - help = 'background grain index, defaults to max + 1') + type = 'float', metavar = 'int', + help = 'background microstructure index, defaults to max microstructure index + 1') parser.set_defaults(degrees = False) @@ -78,9 +78,9 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) + damask.util.croak(geom) microstructure = geom.get_microstructure() - fill = options.fill if options.fill is not None else np.nanmax(microstructure)+1 # These rotations are always applied in the reference coordinate system, i.e. (z,x,z) not (z,x',z'') @@ -92,12 +92,10 @@ for name in filenames: microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0, prefilter=False,output=microstructure.dtype,cval=fill) # rotation around z - spacing = geom.get_size()/geom.get_grid() - geom.set_size(microstructure.shape*spacing) - geom.set_microstructure(microstructure) + + damask.util.croak(geom.update(microstructure,rescale=True)) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak(geom) if name is None: sys.stdout.write(str(geom.show())) else: From 07c9b8b8f029d37686deeadcea1bd268d90a8b9d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 20:28:19 +0200 Subject: [PATCH 044/120] avoiding unwanted changes --- python/damask/geom.py | 10 +++++----- python/damask/util.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 389665320..540ed1bd9 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -44,7 +44,7 @@ class Geom(): def update(self,microstructure=None,size=None,rescale=False): """Updates microstructure and size""" grid_old = self.get_grid() - size_old = self.size + size_old = self.get_size() unique_old = len(np.unique(self.microstructure)) max_old = np.max(self.microstructure) @@ -71,7 +71,7 @@ class Geom(): message = '' if np.any(grid_old != self.get_grid()): message += 'grid a b c: {}\n'.format(' x '.join(map(str,self.get_grid()))) - if np.any(size_old != self.get_size()): + if np.any(size_old != self.size): message += 'size x y z: {}\n'.format(' x '.join(map(str,self.size))) if unique_old != len(np.unique(self.microstructure)): message += '# microstructures: {}\n'.format(len(np.unique(self.microstructure))) @@ -88,17 +88,17 @@ class Geom(): self.comments += [str(c) for c in comment] def set_microstructure(self,microstructure): - self.microstructure = microstructure + self.microstructure = np.copy(microstructure) def set_size(self,size): self.size = np.array(size) def get_microstructure(self): - return self.microstructure + return np.copy(self.microstructure) def get_size(self): - return self.size + return np.copy(self.size) def get_grid(self): return np.array(self.microstructure.shape) diff --git a/python/damask/util.py b/python/damask/util.py index d282963cd..1b990bea8 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -52,7 +52,7 @@ def croak(what, newline = True): def report(who = None, what = None): """Reports script and file name""" - croak( (emph(who)+': ' if who is not None else '') + (what if what is not None else '') ) + croak( (emph(who)+': ' if who is not None else '') + (what if what is not None else '') + '\n' ) # ----------------------------- From 99da46fda8137a5e031265b4941599ead04742a4 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 20:36:41 +0200 Subject: [PATCH 045/120] polished --- PRIVATE | 2 +- processing/pre/geom_addPrimitive.py | 94 +++++++------- processing/pre/geom_canvas.py | 173 +++++++------------------- processing/pre/geom_clean.py | 6 +- processing/pre/geom_grainGrowth.py | 118 +++++------------- processing/pre/geom_renumber.py | 6 +- processing/pre/geom_rescale.py | 4 +- processing/pre/geom_translate.py | 29 +++-- processing/pre/geom_vicinityOffset.py | 34 ++--- 9 files changed, 172 insertions(+), 294 deletions(-) diff --git a/PRIVATE b/PRIVATE index d326605a4..d59698231 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit d326605a49b90dfdf3352f1a6a4ae8dd36507a13 +Subproject commit d596982319b5e8bbded6c14a5724df6c9de2a0fd diff --git a/processing/pre/geom_addPrimitive.py b/processing/pre/geom_addPrimitive.py index ec7a84ec6..72f5019e6 100755 --- a/processing/pre/geom_addPrimitive.py +++ b/processing/pre/geom_addPrimitive.py @@ -1,60 +1,72 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np -import damask from io import StringIO from optparse import OptionParser +import numpy as np + +import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog option [geomfile(s)]', description = """ -Positions a geometric object within the (three-dimensional) canvas of a spectral geometry description. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ +Inserts a primitive geometric object at a given position. Depending on the sign of the dimension parameters, these objects can be boxes, cylinders, or ellipsoids. """, version = scriptID) -parser.add_option('-c', '--center', dest='center', +parser.add_option('-c', '--center', + dest='center', type='float', nargs = 3, metavar=' '.join(['float']*3), help='a,b,c origin of primitive %default') -parser.add_option('-d', '--dimension', dest='dimension', +parser.add_option('-d', '--dimension', + dest='dimension', type='float', nargs = 3, metavar=' '.join(['float']*3), - help='a,b,c extension of hexahedral box; negative values are diameters') -parser.add_option('-e', '--exponent', dest='exponent', + help='a,b,c extension of hexahedral box') +parser.add_option('-e', '--exponent', + dest='exponent', type='float', nargs = 3, metavar=' '.join(['float']*3), help='i,j,k exponents for axes - 0 gives octahedron (|x|^(2^0) + |y|^(2^0) + |z|^(2^0) < 1), \ 1 gives a sphere (|x|^(2^1) + |y|^(2^1) + |z|^(2^1) < 1), \ - large values produce boxes, negative turns concave.') -parser.add_option('-f', '--fill', dest='fill', - type='float', metavar = 'float', - help='grain index to fill primitive. "0" selects maximum microstructure index + 1 [%default]') -parser.add_option('-q', '--quaternion', dest='quaternion', + large values produce boxes, negative turn concave.') +parser.add_option('-f', '--fill', + dest='fill', + type='float', metavar = 'int', + help='microstructure index to fill primitive, defaults to max microstructure index + 1') +parser.add_option('-q', '--quaternion', + dest='quaternion', type='float', nargs = 4, metavar=' '.join(['float']*4), help = 'rotation of primitive as quaternion') -parser.add_option('-a', '--angleaxis', dest='angleaxis', type=float, - nargs = 4, metavar=' '.join(['float']*4), +parser.add_option('-a', '--angleaxis', + dest='angleaxis', + type=float, nargs = 4, metavar=' '.join(['float']*4), help = 'axis and angle to rotate primitive') -parser.add_option( '--degrees', dest='degrees', +parser.add_option( '--degrees', + dest='degrees', action='store_true', - help = 'angle is given in degrees [%default]') -parser.add_option( '--nonperiodic', dest='periodic', + help = 'angle is given in degrees') +parser.add_option( '--nonperiodic', + dest='periodic', action='store_false', - help = 'wrap around edges [%default]') -parser.add_option( '--realspace', dest='realspace', + help = 'wrap around edges') +parser.add_option( '--realspace', + dest='realspace', action='store_true', help = '-c and -d span [origin,origin+size] instead of [0,grid] coordinates') -parser.add_option( '--invert', dest='inside', +parser.add_option( '--invert', + dest='inside', action='store_false', help = 'invert the volume filled by the primitive (inside/outside)') + parser.set_defaults(center = (.0,.0,.0), - fill = 0.0, degrees = False, exponent = (20,20,20), # box shape by default periodic = True, @@ -65,7 +77,10 @@ parser.set_defaults(center = (.0,.0,.0), (options, filenames) = parser.parse_args() if options.dimension is None: - parser.error('no dimension specified.') + parser.error('no dimension specified.') +if [options.angleaxis,options.quaternion].count(None) == 2: + parser.error('more than one rotation specified.') + if options.angleaxis is not None: rotation = damask.Rotation.fromAxisAngle(np.array(options.angleaxis),options.degrees,normalise=True) elif options.quaternion is not None: @@ -73,22 +88,11 @@ elif options.quaternion is not None: else: rotation = damask.Rotation() -options.center = np.array(options.center) +options.center = np.array(options.center) options.dimension = np.array(options.dimension) # undo logarithmic sense of exponent and generate ellipsoids for negative dimensions (backward compatibility) -options.exponent = np.where(np.array(options.dimension) > 0, np.power(2,options.exponent), 2) +options.exponent = np.where(np.array(options.dimension) > 0, np.power(2,options.exponent), 2) -# --- loop over input files ------------------------------------------------------------------------- -if filenames == []: filenames = [None] - -for name in filenames: - try: table = damask.ASCIItable(name = name, - buffered = False, - labeled = False) - except: continue - damask.util.report(scriptName,name) - -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] @@ -100,9 +104,10 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - microstructure = geom.microstructure + damask.util.croak(geom) + microstructure = geom.get_microstructure() - options.fill = np.nanmax(microstructure)+1 if options.fill == 0 else options.fill + fill = options.fill if options.fill is not None else np.nanmax(microstructure)+1 origin = np.zeros(3) for i,line in enumerate(geom.comments): @@ -176,20 +181,19 @@ for name in filenames: grid[2] * k : grid[2] * (k+1)])**options.exponent[2] <= 1.0) microstructure = np.where(inside, - options.fill if options.inside else microstructure, - microstructure if options.inside else options.fill) + fill if options.inside else microstructure, + microstructure if options.inside else fill) else: # nonperiodic, much lighter on resources microstructure = np.where(np.abs(X)**options.exponent[0] + np.abs(Y)**options.exponent[1] + np.abs(Z)**options.exponent[2] <= 1.0, - options.fill if options.inside else microstructure, - microstructure if options.inside else options.fill) + fill if options.inside else microstructure, + microstructure if options.inside else fill) - geom.microstructure = microstructure + damask.util.croak(geom.update(microstructure)) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak(geom) if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index a3f1b7f3b..7998c42c5 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -1,160 +1,83 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- -import os,sys,math -import numpy as np +import os +import sys +from io import StringIO from optparse import OptionParser + +import numpy as np + import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [geomfile(s)]', description = """ -Changes the (three-dimensional) canvas of a spectral geometry description. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ +Increases or decreases the (three-dimensional) canvas. Grid can be given as absolute or relative values, e.g. 16 16 16 or 2x 0.5x 32. """, version = scriptID) -parser.add_option('-g', - '--grid', +parser.add_option('-g','--grid', dest = 'grid', type = 'string', nargs = 3, metavar = ' '.join(['string']*3), - help = 'a,b,c grid of hexahedral box. [auto]') -parser.add_option('-o', - '--offset', + help = 'a,b,c grid of hexahedral box') +parser.add_option('-o','--offset', dest = 'offset', type = 'int', nargs = 3, metavar = ' '.join(['int']*3), help = 'a,b,c offset from old to new origin of grid [%default]') -parser.add_option('-f', - '--fill', +parser.add_option('-f','--fill', dest = 'fill', - type = 'int', metavar = 'int', - help = '(background) canvas grain index. "0" selects maximum microstructure index + 1 [%default]') + type = 'float', metavar = 'int', + help = 'background microstructure index, defaults to max microstructure index + 1') -parser.set_defaults(grid = ('0','0','0'), - offset = (0,0,0), - ) +parser.set_defaults(offset = (0,0,0)) (options, filenames) = parser.parse_args() -datatype = 'i' - if filenames == []: filenames = [None] for name in filenames: - try: table = damask.ASCIItable(name = name, - buffered = False, - labeled = False) - except: continue damask.util.report(scriptName,name) - - if True: - -# --- interpret header ---------------------------------------------------------------------------- - - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ------------------------------------------------------------------------------------ - - microstructure = table.microstructure_read(info['grid'],datatype).reshape(info['grid'],order='F') # read microstructure - -# --- do work ------------------------------------------------------------------------------------ - - newInfo = { - 'grid': np.zeros(3,'i'), - 'origin': np.zeros(3,'d'), - 'microstructures': 0, - } - - newInfo['grid'] = np.array([int(o*float(n.translate(None,'xX'))) if n[-1].lower() == 'x'\ - else int(n) for o,n in zip(info['grid'],options.grid)],'i') - newInfo['grid'] = np.where(newInfo['grid'] > 0, newInfo['grid'],info['grid']) - - microstructure_cropped = np.zeros(newInfo['grid'],datatype) - microstructure_cropped.fill(options.fill if options.fill is not None else np.nanmax(microstructure)+1) - if True: - xindex = np.arange(max(options.offset[0],0),min(options.offset[0]+newInfo['grid'][0],info['grid'][0])) - yindex = np.arange(max(options.offset[1],0),min(options.offset[1]+newInfo['grid'][1],info['grid'][1])) - zindex = np.arange(max(options.offset[2],0),min(options.offset[2]+newInfo['grid'][2],info['grid'][2])) - translate_x = [i - options.offset[0] for i in xindex] - translate_y = [i - options.offset[1] for i in yindex] - translate_z = [i - options.offset[2] for i in zindex] - if 0 in map(len,[xindex,yindex,zindex,translate_x,translate_y,translate_z]): - damask.util.croak('invaldid combination of grid and offset.') - table.close(dismiss = True) - continue - microstructure_cropped[min(translate_x):max(translate_x)+1, - min(translate_y):max(translate_y)+1, - min(translate_z):max(translate_z)+1] \ - = microstructure[min(xindex):max(xindex)+1, - min(yindex):max(yindex)+1, - min(zindex):max(zindex)+1] + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + damask.util.croak(geom) + microstructure = geom.get_microstructure() + + grid = geom.get_grid() + if options.grid is not None: + for i,g in enumerate(options.grid): + grid[i] = int(round(grid[i]*float(g.lower().replace('x','')))) if g.lower().endswith('x') \ + else int(options.grid[i]) - newInfo['size'] = info['size']/info['grid']*newInfo['grid'] if np.all(info['grid'] > 0) else newInfo['grid'] - newInfo['origin'] = info['origin']+(info['size']/info['grid'] if np.all(info['grid'] > 0) \ - else newInfo['size']/newInfo['grid'])*options.offset - newInfo['microstructures'] = len(np.unique(microstructure_cropped)) + new = np.full(grid,options.fill if options.fill is not None else np.nanmax(microstructure)+1, + microstructure.dtype) + + for x in range(microstructure.shape[0]): + X = x + options.offset[0] + if not 0 <= X < new.shape[0]: continue + for y in range(microstructure.shape[1]): + Y = y + options.offset[1] + if not 0 <= Y < new.shape[1]: continue + for z in range(microstructure.shape[2]): + Z = z + options.offset[2] + if not 0 <= Z < new.shape[2]: continue + new[X,Y,Z] = microstructure[x,y,z] -# --- report --------------------------------------------------------------------------------------- + damask.util.croak(geom.update(new,rescale=True)) + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - remarks = [] - errors = [] - - if (any(newInfo['grid'] != info['grid'])): - remarks.append('--> grid a b c: {}'.format(' x '.join(map(str,newInfo['grid'])))) - if (any(newInfo['size'] != info['size'])): - remarks.append('--> size x y z: {}'.format(' x '.join(map(str,newInfo['size'])))) - if (any(newInfo['origin'] != info['origin'])): - remarks.append('--> origin x y z: {}'.format(' : '.join(map(str,newInfo['origin'])))) - if ( newInfo['microstructures'] != info['microstructures']): - remarks.append('--> microstructures: {}'.format(newInfo['microstructures'])) - - if np.any(newInfo['grid'] < 1): errors.append('invalid new grid a b c.') - if np.any(newInfo['size'] <= 0.0): errors.append('invalid new size x y z.') - - if remarks != []: damask.util.croak(remarks) - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- write header --------------------------------------------------------------------------------- - - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {}\tb {}\tc {}".format(*newInfo['grid']), - "size\tx {}\ty {}\tz {}".format(*newInfo['size']), - "origin\tx {}\ty {}\tz {}".format(*newInfo['origin']), - "homogenization\t{}".format(info['homogenization']), - "microstructures\t{}".format(newInfo['microstructures']), - ]) - table.labels_clear() - table.head_write() - table.output_flush() - -# --- write microstructure information ------------------------------------------------------------ - - format = '%{}i'.format(int(math.floor(math.log10(np.nanmax(microstructure_cropped))+1))) - table.data = microstructure_cropped.reshape((newInfo['grid'][0],newInfo['grid'][1]*newInfo['grid'][2]),order='F').transpose() - table.data_writeArray(format,delimiter=' ') - -# --- output finalization -------------------------------------------------------------------------- - - table.close() # close ASCII table + if name is None: + sys.stdout.write(str(geom.show())) + else: + geom.to_file(name) diff --git a/processing/pre/geom_clean.py b/processing/pre/geom_clean.py index 4d7b0a0e5..9ed8e88b4 100755 --- a/processing/pre/geom_clean.py +++ b/processing/pre/geom_clean.py @@ -49,15 +49,15 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) + damask.util.croak(geom) microstructure = geom.get_microstructure() microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent, size=(options.stencil,)*3).astype(microstructure.dtype) - geom.set_microstructure(microstructure) + damask.util.croak(geom.update(microstructure)) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - - damask.util.croak(geom) + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_grainGrowth.py b/processing/pre/geom_grainGrowth.py index f7c50c2e5..2403fd410 100755 --- a/processing/pre/geom_grainGrowth.py +++ b/processing/pre/geom_grainGrowth.py @@ -1,21 +1,28 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- -import os,sys,math -import numpy as np +import os +import sys from optparse import OptionParser + +import numpy as np from scipy import ndimage + import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + +getInterfaceEnergy = lambda A,B: np.float32((A*B != 0)*(A != B)*1.0) # 1.0 if A & B are distinct & nonzero, 0.0 otherwise +struc = ndimage.generate_binary_structure(3,1) # 3D von Neumann neighborhood + + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog [option(s)] [geomfile(s)]', description = """ -Smoothens out interface roughness by simulated curvature flow. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [geomfile(s)]', description = """ +Smoothen interface roughness by simulated curvature flow. This is achieved by the diffusion of each initially sharply bounded grain volume within the periodic domain up to a given distance 'd' voxels. The final geometry is assembled by selecting at each voxel that grain index for which the concentration remains largest. @@ -33,55 +40,33 @@ parser.add_option('-N', '--iterations', parser.add_option('-i', '--immutable', action = 'extend', dest = 'immutable', metavar = '', help = 'list of immutable microstructure indices') -parser.add_option('-r', '--renumber', - dest = 'renumber', action='store_true', - help = 'output consecutive microstructure indices') parser.add_option('--ndimage', dest = 'ndimage', action='store_true', help = 'use ndimage.gaussian_filter in lieu of explicit FFT') parser.set_defaults(d = 1, N = 1, - immutable = [], - renumber = False, - ndimage = False, + immutable = [], + ndimage = False, ) (options, filenames) = parser.parse_args() options.immutable = list(map(int,options.immutable)) -getInterfaceEnergy = lambda A,B: np.float32((A*B != 0)*(A != B)*1.0) # 1.0 if A & B are distinct & nonzero, 0.0 otherwise -struc = ndimage.generate_binary_structure(3,1) # 3D von Neumann neighborhood - -# --- loop over input files ----------------------------------------------------------------------- - -if filenames == []: filenames = [None] for name in filenames: - try: table = damask.ASCIItable(name = name, - buffered = False, - labeled = False) - except: continue damask.util.report(scriptName,name) - -# --- interpret header ---------------------------------------------------------------------------- - - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ----------------------------------------------------------------------------------- - microstructure = np.tile(table.microstructure_read(info['grid']).reshape(info['grid'],order='F'), - np.where(info['grid'] == 1, 2,1)) # make one copy along dimensions with grid == 1 + + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + damask.util.croak(geom) + + grid_original = geom.get_grid() + microstructure = np.tile(geom.get_microstructure(),np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1 grid = np.array(microstructure.shape) # --- initialize support data --------------------------------------------------------------------- @@ -94,7 +79,7 @@ for name in filenames: # Calculates gaussian weights for simulating 3d diffusion gauss = np.exp(-(X*X + Y*Y + Z*Z)/(2.0*options.d*options.d),dtype=np.float32) \ - /np.power(2.0*np.pi*options.d*options.d,(3.0 - np.count_nonzero(info['grid'] == 1))/2.,dtype=np.float32) + /np.power(2.0*np.pi*options.d*options.d,(3.0 - np.count_nonzero(grid_original == 1))/2.,dtype=np.float32) gauss[:,:,:grid[2]//2:-1] = gauss[:,:,1:(grid[2]+1)//2] # trying to cope with uneven (odd) grid size gauss[:,:grid[1]//2:-1,:] = gauss[:,1:(grid[1]+1)//2,:] @@ -156,7 +141,7 @@ for name in filenames: # transform voxels close to interface region index = ndimage.morphology.distance_transform_edt(periodic_diffusedEnergy >= 0.95*np.amax(periodic_diffusedEnergy), return_distances = False, - return_indices = True) # want index of closest bulk grain + return_indices = True) # want index of closest bulk grain periodic_microstructure = np.tile(microstructure,(3,3,3))[grid[0]//2:-grid[0]//2, grid[1]//2:-grid[1]//2, @@ -184,49 +169,10 @@ for name in filenames: # undo any changes involving immutable microstructures microstructure = np.where(immutable, microstructure_original,microstructure) -# --- renumber to sequence 1...Ngrains if requested ----------------------------------------------- -# http://stackoverflow.com/questions/10741346/np-frequency-counts-for-unique-values-in-an-array + damask.util.croak(geom.update(microstructure[0:grid_original[0],0:grid_original[1],0:grid_original[2]])) + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - if options.renumber: - newID = 0 - for microstructureID,count in enumerate(np.bincount(microstructure.flatten())): - if count != 0: - newID += 1 - microstructure = np.where(microstructure == microstructureID, newID, microstructure) - - newInfo = {'microstructures': len(np.unique(microstructure)),} - -# --- report -------------------------------------------------------------------------------------- - - remarks = [] - if newInfo['microstructures'] != info['microstructures']: - remarks.append('--> microstructures: {}'.format(newInfo['microstructures'])) - if remarks != []: damask.util.croak(remarks) - -# --- write header -------------------------------------------------------------------------------- - - table.labels_clear() - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']), - ]) - table.head_write() - -# --- write microstructure information ------------------------------------------------------------ - - formatwidth = int(math.floor(math.log10(np.nanmax(microstructure))+1)) - table.data = microstructure[::1 if info['grid'][0]>1 else 2, - ::1 if info['grid'][1]>1 else 2, - ::1 if info['grid'][2]>1 else 2,].\ - reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose() - table.data_writeArray('%{}i'.format(formatwidth),delimiter = ' ') - -# --- output finalization -------------------------------------------------------------------------- - - table.close() - \ No newline at end of file + if name is None: + sys.stdout.write(str(geom.show())) + else: + geom.to_file(name) diff --git a/processing/pre/geom_renumber.py b/processing/pre/geom_renumber.py index e46296555..25f67bd50 100755 --- a/processing/pre/geom_renumber.py +++ b/processing/pre/geom_renumber.py @@ -18,7 +18,7 @@ scriptID = ' '.join([scriptName,damask.version]) # MAIN #-------------------------------------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile(s)]', description = """ Renumber sorted microstructure indices to 1,...,N. """, version=scriptID) @@ -36,16 +36,16 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) + damask.util.croak(geom) microstructure = geom.get_microstructure() renumbered = np.copy(microstructure) for i, oldID in enumerate(np.unique(microstructure)): renumbered = np.where(microstructure == oldID, i+1, renumbered) - geom.set_microstructure(renumbered) + damask.util.croak(geom.update(renumbered)) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak(geom) if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index e39a9d0d6..c1ca091a4 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -53,13 +53,13 @@ for name in filenames: if options.grid is not None: for i,g in enumerate(options.grid): scale[i] = scale[i]*float(g.lower().replace('x','')) if g.lower().endswith('x') \ - else float(options.grid[i])/scale[i] + else float(options.grid[i])/scale[i] size = geom.get_size() if options.size is not None: for i,s in enumerate(options.size): size[i] = size[i]*float(s.lower().replace('x','')) if s.lower().endswith('x') \ - else options.size[i] + else options.size[i] microstructure = ndimage.interpolation.zoom(microstructure, scale, output=microstructure.dtype, order=0, mode='nearest', prefilter=False) diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index 63fa1d421..cffde28a7 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -1,22 +1,25 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np from optparse import OptionParser from io import StringIO + +import numpy as np + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ -translate microstructure indices (shift or substitute) and/or geometry origin. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ +Translate microstructure indices (shift or substitute) and/or geometry origin. """, version=scriptID) @@ -27,7 +30,7 @@ parser.add_option('-o', '--origin', parser.add_option('-m', '--microstructure', dest = 'microstructure', type = 'int', metavar = 'int', - help = 'offset from old to new microstructure indices') + help = 'offset from old to new microstructure indices (after substitution)') parser.add_option('-s', '--substitute', dest = 'substitute', action = 'extend', metavar = '', @@ -44,7 +47,6 @@ sub = {} for i in range(len(options.substitute)//2): # split substitution list into "from" -> "to" sub[int(options.substitute[i*2])] = int(options.substitute[i*2+1]) -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] @@ -56,11 +58,13 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - microstructure = geom.microstructure + damask.util.croak(geom) + microstructure = geom.get_microstructure() + new = np.copy(microstructure) - for k, v in sub.items(): microstructure[geom.microstructure==k] = v # substitute microstructure indices - - microstructure += options.microstructure # shift microstructure indices + for k, v in sub.items(): new[microstructure==k] = v # substitute microstructure indices and shift + + microstructure += options.microstructure # constant shift for i,line in enumerate(geom.comments): if line.lower().strip().startswith('origin'): @@ -68,10 +72,9 @@ for name in filenames: origin += np.array(origin) geom.comments[i] = 'origin x {} y {} z {}'.format(*origin) - geom.microstructure = microstructure + damask.util.croak(geom.update(microstructure)) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - - damask.util.croak(geom) + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_vicinityOffset.py b/processing/pre/geom_vicinityOffset.py index 535650244..f058e9424 100755 --- a/processing/pre/geom_vicinityOffset.py +++ b/processing/pre/geom_vicinityOffset.py @@ -1,17 +1,20 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np -from scipy import ndimage -from optparse import OptionParser from io import StringIO +from optparse import OptionParser + +from scipy import ndimage +import numpy as np + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + def taintedNeighborhood(stencil,trigger=[],size=1): me = stencil[stencil.shape[0]//2] @@ -23,11 +26,12 @@ def taintedNeighborhood(stencil,trigger=[],size=1): trigger = list(trigger) return np.any(np.in1d(stencil,np.array(trigger))) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ Offset microstructure index for points which see a microstructure different from themselves (or listed as triggers) within a given (cubic) vicinity, i.e. within the region close to a grain/phase boundary. @@ -40,10 +44,10 @@ parser.add_option('-v', '--vicinity', parser.add_option('-m', '--microstructureoffset', dest='offset', type = 'int', metavar = 'int', - help = 'offset (positive or negative) for tagged microstructure indices. '+ - '"0" selects maximum microstructure index [%default]') + help='offset (positive or negative) to tag microstructure indices, defaults to max microstructure index + 1') parser.add_option('-t', '--trigger', - action = 'extend', dest = 'trigger', metavar = '', + dest = 'trigger', + action = 'extend', metavar = '', help = 'list of microstructure indices triggering a change') parser.add_option('-n', '--nonperiodic', dest = 'mode', @@ -51,17 +55,15 @@ parser.add_option('-n', '--nonperiodic', help = 'assume geometry to be non-periodic') parser.set_defaults(vicinity = 1, - offset = 0, trigger = [], mode = 'wrap', ) (options, filenames) = parser.parse_args() + options.trigger = np.array(options.trigger, dtype=int) -# --- loop over input files ------------------------------------------------------------------------- - if filenames == []: filenames = [None] for name in filenames: @@ -72,21 +74,21 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - microstructure = geom.microstructure + damask.util.croak(geom) + microstructure = geom.get_microstructure() - if options.offset == 0: options.offset = microstructure.max() + offset = options.offset if options.offset is not None else np.nanmax(microstructure) microstructure = np.where(ndimage.filters.generic_filter(microstructure, taintedNeighborhood, size=1+2*options.vicinity,mode=options.mode, extra_arguments=(), extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}), - microstructure + options.offset,microstructure) + microstructure + offset,microstructure) - geom.microstructure = microstructure + damask.util.croak(geom.update(microstructure)) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak(geom) if name is None: sys.stdout.write(str(geom.show())) else: From 7a500e77b1b3b49a6b224d885e353da57bc691bd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 20:53:59 +0200 Subject: [PATCH 046/120] not needed (DADF5 is the modern alternative) --- python/damask/__init__.py | 1 - python/damask/result.py | 41 --------------------------------------- 2 files changed, 42 deletions(-) delete mode 100644 python/damask/result.py diff --git a/python/damask/__init__.py b/python/damask/__init__.py index c5677aaf5..8741b6f27 100644 --- a/python/damask/__init__.py +++ b/python/damask/__init__.py @@ -17,7 +17,6 @@ from .orientation import Symmetry, Lattice, Rotation, Orientation # noqa from .dadf5 import DADF5 # noqa #from .block import Block # only one class -from .result import Result # noqa from .geom import Geom # noqa from .solver import Solver # noqa from .test import Test # noqa diff --git a/python/damask/result.py b/python/damask/result.py deleted file mode 100644 index 234e317db..000000000 --- a/python/damask/result.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: UTF-8 no BOM -*- - -import numpy as np - -try: - import h5py -except (ImportError) as e: - pass # sys.stderr.write('\nREMARK: h5py module not available \n\n') - -class Result(): - """ - General class for result parsing. - - Needs h5py to be installed - """ - - def __init__(self,resultsFile): - self.data=h5py.File(resultsFile,"r") - self.Npoints=self.data.attrs['Number of Materialpoints'] - print("Opened {} with {} points".format(resultsFile,self.Npoints)) - - def getCrystallite(self,labels,inc,constituent=1,points=None): - if points is None: points = np.array(np.array(range(self.Npoints))) - results = {} - mapping=self.data['mapping/crystallite'] - for instance in self.data['increments/%s/crystallite/'%inc]: - dsets = list(self.data['increments/%s/crystallite/%s'%(inc,instance)].keys()) - for label in labels: - if label in dsets and label not in results: - shape = np.shape(self.data['increments/%s/crystallite/%s/%s'%(inc,instance,label)])[1:] - results[label] = np.nan*np.ones(np.array((self.Npoints,)+shape)) - for myPoint in range(len(points)): - matPoint = points[myPoint] - pos = mapping[matPoint,constituent-1] - if pos[0] != 0: - try: - for label in labels: - results[label][matPoint,...] = self.data['increments/%s/crystallite/%s/%s'%(inc,pos[0],label)][pos[1],...] - except: - pass - return results From af493cf9fd94ad89c0aff47d7e069c1394d1f346 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 21:30:38 +0200 Subject: [PATCH 047/120] using class needs more memory, but should be faster and is better readable --- processing/post/addGradient.py | 2 +- processing/pre/geom_pack.py | 132 +++++++++++++-------------------- processing/pre/geom_unpack.py | 4 +- 3 files changed, 54 insertions(+), 84 deletions(-) diff --git a/processing/post/addGradient.py b/processing/post/addGradient.py index d3910d2ad..080ec0bcd 100755 --- a/processing/post/addGradient.py +++ b/processing/post/addGradient.py @@ -52,7 +52,7 @@ def gradFFT(geomdim,field): # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog option [ASCIItable(s)]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """ Add column(s) containing gradient of requested column(s). Operates on periodic ordered three-dimensional data sets of vector and scalar fields. diff --git a/processing/pre/geom_pack.py b/processing/pre/geom_pack.py index 2e6080a6b..0700a16f5 100755 --- a/processing/pre/geom_pack.py +++ b/processing/pre/geom_pack.py @@ -1,112 +1,82 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- -import os,sys -import numpy as np +import os +import sys from optparse import OptionParser + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile(s)]', description = """ -compress geometry files with ranges "a to b" and/or multiples "n of x". +Pack ranges to "a to b" and/or multiples to "n of x". """, version = scriptID) (options, filenames) = parser.parse_args() -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: - try: - table = damask.ASCIItable(name = name, - buffered = False, labeled = False) - except: continue damask.util.report(scriptName,name) -# --- interpret header ---------------------------------------------------------------------------- + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + damask.util.croak(geom) + microstructure = geom.get_microstructure().flatten('F') - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- write header --------------------------------------------------------------------------------- - - table.labels_clear() - table.info_clear() - table.info_append(extra_header+[ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=info['microstructures']), - ]) - table.head_write() -# --- write packed microstructure information ----------------------------------------------------- - - compressType = '' + compressType = None former = start = -1 reps = 0 - outputAlive = True - while outputAlive and table.data_read(): # read next data line of ASCII table - items = table.data - if len(items) > 2: - if items[1].lower() == 'of': items = [int(items[2])]*int(items[0]) - elif items[1].lower() == 'to': items = range(int(items[0]),1+int(items[2])) - else: items = map(int,items) - else: items = map(int,items) + for current in microstructure: + if abs(current - former) == 1 and (start - current) == reps*(former - current): + compressType = 'to' + reps += 1 + elif current == former and start == former: + compressType = 'of' + reps += 1 + else: + if compressType == None: + out = [] + elif compressType == '.': + out.append('{}\n'.format(former)) + elif compressType == 'to': + out.append('{} to {}\n'.format(start,former)) + elif compressType == 'of': + out.append('{} of {}\n'.format(reps,former)) - for current in items: - if abs(current - former) == 1 and (start - current) == reps*(former - current): - compressType = 'to' - reps += 1 - elif current == former and start == former: - compressType = 'of' - reps += 1 - else: - if compressType == '': - table.data = [] - elif compressType == '.': - table.data = [former] - elif compressType == 'to': - table.data = [start,'to',former] - elif compressType == 'of': - table.data = [reps,'of',former] + compressType = '.' + start = current + reps = 1 - outputAlive = table.data_write(delimiter = ' ') # output processed line - - compressType = '.' - start = current - reps = 1 - - former = current - - table.data = { - '.' : [former], - 'to': [start,'to',former], - 'of': [reps,'of',former], - }[compressType] - - outputAlive = table.data_write(delimiter = ' ') # output processed line - -# --- output finalization -------------------------------------------------------------------------- - - table.close() # close ASCII table + former = current + + if compressType == '.': + out.append('{}\n'.format(former)) + elif compressType == 'to': + out.append('{} to {}\n'.format(start,former)) + elif compressType == 'of': + out.append('{} of {}\n'.format(reps,former)) + + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + comments = geom.get_comments() + with open(name,'w') as f: + f.write('{} header\n'.format(3+len(comments))) + f.writelines(["{}\n".format(comment) for comment in comments]) + f.write('grid a {} b {} c {}\n'.format(*geom.get_grid())) + f.write('size x {} y {} z {}\n'.format(*geom.get_size())) + f.write('homogenization {}\n'.format(geom.get_homogenization())) + f.writelines(out) diff --git a/processing/pre/geom_unpack.py b/processing/pre/geom_unpack.py index b8efa49c2..028fc2e25 100755 --- a/processing/pre/geom_unpack.py +++ b/processing/pre/geom_unpack.py @@ -34,10 +34,10 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - + damask.util.croak(geom) + geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak(geom) if name is None: sys.stdout.write(str(geom.show())) else: From 0039ac95511e8b4a2fd74faf1186de9b2bf046b7 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 21:32:48 +0200 Subject: [PATCH 048/120] always add comment at beginning usually, comments are related to the file history --- python/damask/geom.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 540ed1bd9..029f20651 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -83,9 +83,9 @@ class Geom(): def add_comment(self,comment): if not isinstance(comment,list): - self.comments += [str(comment)] + self.comments = [str(comment)] + self.comments else: - self.comments += [str(c) for c in comment] + self.comments = [str(c) for c in comment] + self.comments def set_microstructure(self,microstructure): self.microstructure = np.copy(microstructure) @@ -106,6 +106,8 @@ class Geom(): def get_homogenization(self): return self.homogenization + def get_comments(self): + return self.comments[:] @classmethod def from_file(cls,fname): From f251cdb746561782738be197580d0365c2d21364 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 22:07:50 +0200 Subject: [PATCH 049/120] simplified --- processing/pre/geom_toTable.py | 90 +++++++++++++--------------------- 1 file changed, 34 insertions(+), 56 deletions(-) diff --git a/processing/pre/geom_toTable.py b/processing/pre/geom_toTable.py index 0a71b335e..f2e475c1c 100755 --- a/processing/pre/geom_toTable.py +++ b/processing/pre/geom_toTable.py @@ -1,11 +1,15 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- -import os,sys -import numpy as np +import os +import sys from optparse import OptionParser +from io import StringIO + +import numpy as np + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) @@ -19,70 +23,44 @@ Translate geom description into ASCIItable containing position and microstructur """, version = scriptID) -parser.add_option('--float', - dest = 'float', - action = 'store_true', - help = 'use float input') -parser.set_defaults(float = False, - ) (options, filenames) = parser.parse_args() -datatype = 'f' if options.float else 'i' - -# --- loop over input files ------------------------------------------------------------------------- - if filenames == []: filenames = [None] for name in filenames: - try: table = damask.ASCIItable(name = name, - outname = os.path.splitext(name)[0]+'.txt' if name else name, - buffered = False, - labeled = False, - ) - except: continue damask.util.report(scriptName,name) - -# --- interpret header ---------------------------------------------------------------------------- - - table.head_read() - info,extra_header = table.head_getGeom() - damask.util.report_geom(info) - - errors = [] - if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') - if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue - -# --- read data ------------------------------------------------------------------------------------ - - microstructure = table.microstructure_read(info['grid'],datatype) - -# ------------------------------------------ assemble header --------------------------------------- - - table.info_clear() - table.info_append(extra_header + [scriptID + '\t' + ' '.join(sys.argv[1:])]) - table.labels_clear() - table.labels_append(['{}_{}'.format(1+i,'pos') for i in range(3)]+['microstructure']) - table.head_write() - table.output_flush() + + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) + else: + geom = damask.Geom.from_file(name) + damask.util.croak(geom) + microstructure = geom.get_microstructure().flatten('F') + grid = geom.get_grid() + size = geom.get_size() + + for i,line in enumerate(geom.get_comments()): + if line.lower().strip().startswith('origin'): + origin= np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) #--- generate grid -------------------------------------------------------------------------------- - x = (0.5 + np.arange(info['grid'][0],dtype=float))/info['grid'][0]*info['size'][0]+info['origin'][0] - y = (0.5 + np.arange(info['grid'][1],dtype=float))/info['grid'][1]*info['size'][1]+info['origin'][1] - z = (0.5 + np.arange(info['grid'][2],dtype=float))/info['grid'][2]*info['size'][2]+info['origin'][2] + x = (0.5 + np.arange(grid[0],dtype=float))/grid[0]*size[0]+origin[0] + y = (0.5 + np.arange(grid[1],dtype=float))/grid[1]*size[1]+origin[1] + z = (0.5 + np.arange(grid[2],dtype=float))/grid[2]*size[2]+origin[2] - xx = np.tile( x, info['grid'][1]* info['grid'][2]) - yy = np.tile(np.repeat(y,info['grid'][0] ),info['grid'][2]) - zz = np.repeat(z,info['grid'][0]*info['grid'][1]) - - table.data = np.squeeze(np.dstack((xx,yy,zz,microstructure)),axis=0) - table.data_writeArray() + xx = np.tile( x, grid[1]* grid[2]) + yy = np.tile(np.repeat(y,grid[0] ),grid[2]) + zz = np.repeat(z,grid[0]*grid[1]) # ------------------------------------------ finalize output --------------------------------------- - + table = damask.ASCIItable(outname = os.path.splitext(name)[0]+'.txt' if name else name) + table.info_append([scriptID + '\t' + ' '.join(sys.argv[1:])] + geom.get_comments()) + table.labels_append(['{}_{}'.format(1+i,'pos') for i in range(3)]+['microstructure']) + table.head_write() + table.output_flush() + table.data = np.squeeze(np.dstack((xx,yy,zz,microstructure)),axis=0) + table.data_writeArray() table.close() From 15d5a7ae28546bcca43e3e4385040127f0309aee Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 22:08:14 +0200 Subject: [PATCH 050/120] don't access attributes directly --- processing/pre/geom_translate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index cffde28a7..01f34f547 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -66,7 +66,7 @@ for name in filenames: microstructure += options.microstructure # constant shift - for i,line in enumerate(geom.comments): + for i,line in enumerate(geom.get_comments()): if line.lower().strip().startswith('origin'): origin= np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) origin += np.array(origin) From 0da39b0c69acfdd491d051880da3a9a89db84e31 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 22:08:42 +0200 Subject: [PATCH 051/120] copy and paste error --- python/damask/geom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 029f20651..585034ab7 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -120,7 +120,7 @@ class Geom(): comments_old = [f.readline() for i in range(int(header_length))] else: fname.seek(0) - header_length,keyword = f.readline().split() + header_length,keyword = fname.readline().split() if not keyword.startswith('head') or int(header_length) < 3: raise TypeError('Header length information missing or invalid') comments_old = [fname.readline() for i in range(int(header_length))] From c8dfba89e590b466e5aa62ebd680d546e697e4b0 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 22:49:05 +0200 Subject: [PATCH 052/120] using class still a very complex script --- .../pre/geom_fromVoronoiTessellation.py | 176 ++++++++---------- python/damask/geom.py | 2 +- 2 files changed, 76 insertions(+), 102 deletions(-) diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 5610c939a..695ac1488 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -1,11 +1,14 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- -import os,sys,math -import numpy as np +import os +import sys import multiprocessing +from io import StringIO from optparse import OptionParser,OptionGroup -from scipy import spatial + +import numpy as np +from scipy import spatial + import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] @@ -29,74 +32,74 @@ def meshgrid2(*arrs): ans.insert(0,arr2) return tuple(ans) -def findClosestSeed(fargs): + +def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, cpus = 2): + + def findClosestSeed(fargs): point, seeds, myWeights = fargs tmp = np.repeat(point.reshape(3,1), len(seeds), axis=1).T dist = np.sum((tmp - seeds)**2,axis=1) -myWeights return np.argmin(dist) # seed point closest to point + + copies = \ + np.array([ + [ -1,-1,-1 ], + [ 0,-1,-1 ], + [ 1,-1,-1 ], + [ -1, 0,-1 ], + [ 0, 0,-1 ], + [ 1, 0,-1 ], + [ -1, 1,-1 ], + [ 0, 1,-1 ], + [ 1, 1,-1 ], + [ -1,-1, 0 ], + [ 0,-1, 0 ], + [ 1,-1, 0 ], + [ -1, 0, 0 ], + [ 0, 0, 0 ], + [ 1, 0, 0 ], + [ -1, 1, 0 ], + [ 0, 1, 0 ], + [ 1, 1, 0 ], + [ -1,-1, 1 ], + [ 0,-1, 1 ], + [ 1,-1, 1 ], + [ -1, 0, 1 ], + [ 0, 0, 1 ], + [ 1, 0, 1 ], + [ -1, 1, 1 ], + [ 0, 1, 1 ], + [ 1, 1, 1 ], + ]).astype(float)*info['size'] if periodic else \ + np.array([ + [ 0, 0, 0 ], + ]).astype(float) + repeatweights = np.tile(weights,len(copies)).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3) + for i,vec in enumerate(copies): # periodic copies of seed points ... + try: seeds = np.append(seeds, coords+vec, axis=0) # ... (1+a,2+a,3+a,...,1+z,2+z,3+z) + except NameError: seeds = coords+vec -def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, cpus = 2): + if (repeatweights == 0.0).all(): # standard Voronoi (no weights, KD tree) + myKDTree = spatial.cKDTree(seeds) + devNull,closestSeeds = myKDTree.query(undeformed) + else: + damask.util.croak('...using {} cpu{}'.format(options.cpus, 's' if options.cpus > 1 else '')) + arguments = [[arg,seeds,repeatweights] for arg in list(undeformed)] - copies = \ - np.array([ - [ -1,-1,-1 ], - [ 0,-1,-1 ], - [ 1,-1,-1 ], - [ -1, 0,-1 ], - [ 0, 0,-1 ], - [ 1, 0,-1 ], - [ -1, 1,-1 ], - [ 0, 1,-1 ], - [ 1, 1,-1 ], - [ -1,-1, 0 ], - [ 0,-1, 0 ], - [ 1,-1, 0 ], - [ -1, 0, 0 ], - [ 0, 0, 0 ], - [ 1, 0, 0 ], - [ -1, 1, 0 ], - [ 0, 1, 0 ], - [ 1, 1, 0 ], - [ -1,-1, 1 ], - [ 0,-1, 1 ], - [ 1,-1, 1 ], - [ -1, 0, 1 ], - [ 0, 0, 1 ], - [ 1, 0, 1 ], - [ -1, 1, 1 ], - [ 0, 1, 1 ], - [ 1, 1, 1 ], - ]).astype(float)*info['size'] if periodic else \ - np.array([ - [ 0, 0, 0 ], - ]).astype(float) - - repeatweights = np.tile(weights,len(copies)).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3) - for i,vec in enumerate(copies): # periodic copies of seed points ... - try: seeds = np.append(seeds, coords+vec, axis=0) # ... (1+a,2+a,3+a,...,1+z,2+z,3+z) - except NameError: seeds = coords+vec - - if (repeatweights == 0.0).all(): # standard Voronoi (no weights, KD tree) - myKDTree = spatial.cKDTree(seeds) - devNull,closestSeeds = myKDTree.query(undeformed) + if cpus > 1: # use multithreading + pool = multiprocessing.Pool(processes = cpus) # initialize workers + result = pool.map_async(findClosestSeed, arguments) # evaluate function in parallel + pool.close() + pool.join() + closestSeeds = np.array(result.get()).flatten() else: - damask.util.croak('...using {} cpu{}'.format(options.cpus, 's' if options.cpus > 1 else '')) - arguments = [[arg,seeds,repeatweights] for arg in list(undeformed)] - - if cpus > 1: # use multithreading - pool = multiprocessing.Pool(processes = cpus) # initialize workers - result = pool.map_async(findClosestSeed, arguments) # evaluate function in parallel - pool.close() - pool.join() - closestSeeds = np.array(result.get()).flatten() - else: - closestSeeds = np.zeros(len(arguments),dtype='i') - for i,arg in enumerate(arguments): - closestSeeds[i] = findClosestSeed(arg) + closestSeeds = np.zeros(len(arguments),dtype='i') + for i,arg in enumerate(arguments): + closestSeeds[i] = findClosestSeed(arg) # closestSeed is modulo number of original seed points (i.e. excluding periodic copies) - return grains[closestSeeds%coords.shape[0]] + return grains[closestSeeds%coords.shape[0]] # -------------------------------------------------------------------- # MAIN @@ -220,10 +223,7 @@ parser.set_defaults(pos = 'pos', if filenames == []: filenames = [None] for name in filenames: - try: table = damask.ASCIItable(name = name, - outname = os.path.splitext(name)[0]+'.geom' if name else name, - buffered = False) - except: continue + table = damask.ASCIItable(name = name, readonly = True) damask.util.report(scriptName,name) # --- read header ---------------------------------------------------------------------------- @@ -281,7 +281,7 @@ for name in filenames: else table.data[:,table.label_indexrange(options.pos)] - info['origin'] eulers = table.data[:,table.label_indexrange(options.eulers)] if hasEulers \ else np.zeros(3*len(coords)) - grains = table.data[:,table.label_indexrange(options.microstructure)].astype('i') if hasGrains \ + grains = table.data[:,table.label_indexrange(options.microstructure)].astype(int) if hasGrains \ else 1+np.arange(len(coords)) weights = table.data[:,table.label_indexrange(options.weight)] if hasWeights \ else np.zeros(len(coords)) @@ -299,20 +299,8 @@ for name in filenames: grid = np.vstack(meshgrid2(x, y, z)).reshape(3,-1).T indices = laguerreTessellation(grid, coords, weights, grains, options.periodic, options.cpus) -# --- write header ------------------------------------------------------------------------ - - usedGrainIDs = np.intersect1d(grainIDs,indices) - info['microstructures'] = len(usedGrainIDs) - - if info['homogenization'] == 0: info['homogenization'] = options.homogenization - - damask.util.report_geom(info,['grid','size','origin','homogenization',]) - damask.util.croak(['microstructures: {}{}'.format(info['microstructures'], - (' out of {}'.format(NgrainIDs) if NgrainIDs != info['microstructures'] else '')), - ]) - config_header = [] - formatwidth = 1+int(math.log10(NgrainIDs)) + formatwidth = 1+int(np.log10(NgrainIDs)) if options.config: config_header += [''] @@ -331,24 +319,10 @@ for name in filenames: ] + theAxes config_header += [''] - table.labels_clear() - table.info_clear() - table.info_append([ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {}\tb {}\tc {}".format(*info['grid']), - "size\tx {}\ty {}\tz {}".format(*info['size']), - "origin\tx {}\ty {}\tz {}".format(*info['origin']), - "homogenization\t{}".format(info['homogenization']), - "microstructures\t{}".format(info['microstructures']), - config_header, - ]) - table.head_write() - -# --- write microstructure information ------------------------------------------------------------ - - table.data = indices.reshape(info['grid'][1]*info['grid'][2],info['grid'][0]) - table.data_writeArray('%%%ii'%(formatwidth),delimiter=' ') - -#--- output finalization -------------------------------------------------------------------------- - - table.close() + geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'],options.homogenization,comments=config_header) + damask.util.croak(geom) + + if name is None: + sys.stdout.write(str(geom.show())) + else: + geom.to_file(os.path.splitext(name)[0]+'.geom') diff --git a/python/damask/geom.py b/python/damask/geom.py index 585034ab7..9260d70d3 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -12,7 +12,7 @@ class Geom(): if len(microstructure.shape) != 3: raise ValueError('Invalid microstructure shape {}'.format(*microstructure.shape)) - elif microstructure.dtype not in ['int','float']: + elif microstructure.dtype not in [int,float]: raise TypeError('Invalid data type {} for microstructure'.format(microstructure.dtype)) else: self.microstructure = microstructure From b5cec797c02806a11c5c333ec021fc1b7eb7507b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 22:52:23 +0200 Subject: [PATCH 053/120] cleaned --- processing/pre/geom_fromMinimalSurface.py | 43 ++++++++++--------- .../pre/geom_fromVoronoiTessellation.py | 2 +- processing/pre/geom_grainGrowth.py | 1 + processing/pre/geom_pack.py | 3 +- python/damask/geom.py | 1 - 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/processing/pre/geom_fromMinimalSurface.py b/processing/pre/geom_fromMinimalSurface.py index 37610edd0..d001b57d2 100755 --- a/processing/pre/geom_fromMinimalSurface.py +++ b/processing/pre/geom_fromMinimalSurface.py @@ -1,30 +1,33 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import math -import numpy as np from optparse import OptionParser + +import numpy as np + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + +minimal_surfaces = ['primitive','gyroid','diamond'] + +surface = { + 'primitive': lambda x,y,z: np.cos(x)+np.cos(y)+np.cos(z), + 'gyroid': lambda x,y,z: np.sin(x)*np.cos(y)+np.sin(y)*np.cos(z)+np.cos(x)*np.sin(z), + 'diamond': lambda x,y,z: np.cos(x-y)*np.cos(z)+np.sin(x+y)*np.sin(z), + } + + # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -minimal_surfaces = ['primitive','gyroid','diamond',] - -surface = { - 'primitive': lambda x,y,z: math.cos(x)+math.cos(y)+math.cos(z), - 'gyroid': lambda x,y,z: math.sin(x)*math.cos(y)+math.sin(y)*math.cos(z)+math.cos(x)*math.sin(z), - 'diamond': lambda x,y,z: math.cos(x-y)*math.cos(z)+math.sin(x+y)*math.sin(z), - } - -parser = OptionParser(option_class=damask.extendableOption, usage='%prog [option(s)] [geomfile]', description = """ -Generate a geometry file of a bicontinuous structure of given type. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile]', description = """ +Generate a bicontinuous structure of given type. """, version = scriptID) @@ -57,6 +60,7 @@ parser.add_option('--m', dest = 'microstructure', type = 'int', nargs = 2, metavar = 'int int', help = 'two microstructure indices to be used [%default]') + parser.set_defaults(type = minimal_surfaces[0], threshold = 0.0, periods = 1, @@ -68,24 +72,23 @@ parser.set_defaults(type = minimal_surfaces[0], (options,filenames) = parser.parse_args() -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - X = options.periods*2.0*math.pi*(np.arange(options.grid[0])+0.5)/options.grid[0] - Y = options.periods*2.0*math.pi*(np.arange(options.grid[1])+0.5)/options.grid[1] - Z = options.periods*2.0*math.pi*(np.arange(options.grid[2])+0.5)/options.grid[2] + X = options.periods*2.0*np.pi*(np.arange(options.grid[0])+0.5)/options.grid[0] + Y = options.periods*2.0*np.pi*(np.arange(options.grid[1])+0.5)/options.grid[1] + Z = options.periods*2.0*np.pi*(np.arange(options.grid[2])+0.5)/options.grid[2] microstructure = np.empty(options.grid,dtype='int') - for z in range(options.grid[2]): + for x in range(options.grid[0]): for y in range(options.grid[1]): - for x in range(options.grid[0]): + for z in range(options.grid[2]): microstructure[x,y,z]=options.microstructure[options.threshold < surface[options.type](X[x],Y[y],Z[z])] - geom=damask.Geom(options.size,microstructure,options.homogenization, + geom=damask.Geom(microstructure,options.size,options.homogenization, comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) damask.util.croak(geom) diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 695ac1488..29d8a0faf 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -3,7 +3,6 @@ import os import sys import multiprocessing -from io import StringIO from optparse import OptionParser,OptionGroup import numpy as np @@ -101,6 +100,7 @@ def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, c # closestSeed is modulo number of original seed points (i.e. excluding periodic copies) return grains[closestSeeds%coords.shape[0]] + # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- diff --git a/processing/pre/geom_grainGrowth.py b/processing/pre/geom_grainGrowth.py index 2403fd410..af044879e 100755 --- a/processing/pre/geom_grainGrowth.py +++ b/processing/pre/geom_grainGrowth.py @@ -2,6 +2,7 @@ import os import sys +from io import StringIO from optparse import OptionParser import numpy as np diff --git a/processing/pre/geom_pack.py b/processing/pre/geom_pack.py index 0700a16f5..9816551b0 100755 --- a/processing/pre/geom_pack.py +++ b/processing/pre/geom_pack.py @@ -2,6 +2,7 @@ import os import sys +from io import StringIO from optparse import OptionParser import damask @@ -49,7 +50,7 @@ for name in filenames: compressType = 'of' reps += 1 else: - if compressType == None: + if compressType is None: out = [] elif compressType == '.': out.append('{}\n'.format(former)) diff --git a/python/damask/geom.py b/python/damask/geom.py index 9260d70d3..5702c1950 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -9,7 +9,6 @@ class Geom(): def __init__(self,microstructure,size,homogenization=1,comments=[]): """New geometry definition from array of microstructures and size""" - if len(microstructure.shape) != 3: raise ValueError('Invalid microstructure shape {}'.format(*microstructure.shape)) elif microstructure.dtype not in [int,float]: From 5cf63bbbc3636d98f0f260158fc2a46b5ab23917 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 27 May 2019 08:34:36 +0200 Subject: [PATCH 054/120] vtk 7 is out for more than 3 years --- processing/post/vtk_pointCloud.py | 2 +- processing/post/vtk_rectilinearGrid.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processing/post/vtk_pointCloud.py b/processing/post/vtk_pointCloud.py index 2aad22479..93b4f61bf 100755 --- a/processing/post/vtk_pointCloud.py +++ b/processing/post/vtk_pointCloud.py @@ -98,6 +98,6 @@ for name in filenames: writer.Write() - if name is None: sys.stdout.write(writer.GetOutputString()[:writer.GetOutputStringLength()]) # limiting of outputString is fix for vtk <7.0 + if name is None: sys.stdout.write(writer.GetOutputString()) table.close() diff --git a/processing/post/vtk_rectilinearGrid.py b/processing/post/vtk_rectilinearGrid.py index 2e7c66ad5..295df2714 100755 --- a/processing/post/vtk_rectilinearGrid.py +++ b/processing/post/vtk_rectilinearGrid.py @@ -129,6 +129,6 @@ for name in filenames: writer.Write() - if name is None: sys.stdout.write(writer.GetOutputString()[:writer.GetOutputStringLength()]) # limiting of outputString is fix for vtk <7.0 + if name is None: sys.stdout.write(writer.GetOutputString()) table.close() From d9ab87cfde7a53ddf11221c41cc4fc46edf09f86 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 27 May 2019 08:35:24 +0200 Subject: [PATCH 055/120] crystallite will be removed soon, error handling is done by geom class --- .../pre/geom_fromVoronoiTessellation.py | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 29d8a0faf..43c1a7987 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -192,10 +192,6 @@ group.add_option('--homogenization', dest = 'homogenization', type = 'int', metavar = 'int', help = 'homogenization index to be used [%default]') -group.add_option('--crystallite', - dest = 'crystallite', - type = 'int', metavar = 'int', - help = 'crystallite index to be used [%default]') group.add_option('--phase', dest = 'phase', type = 'int', metavar = 'int', @@ -208,7 +204,6 @@ parser.set_defaults(pos = 'pos', microstructure = 'microstructure', eulers = 'euler', homogenization = 1, - crystallite = 1, phase = 1, cpus = 2, laguerre = False, @@ -245,14 +240,10 @@ for name in filenames: hasEulers = table.label_dimension(options.eulers) == 3 hasWeights = table.label_dimension(options.weight) == 1 and options.laguerre - if np.any(np.array(info['grid']) < 1): errors.append('invalid grid a b c.') - if np.any(np.array(info['size']) <= 0.0) \ - and np.all(np.array(info['grid']) < 1): errors.append('invalid size x y z.') - else: - for i in range(3): - if info['size'][i] <= 0.0: # any invalid size? - info['size'][i] = float(info['grid'][i])/max(info['grid']) # normalize to grid - remarks.append('rescaling size {} to {}...'.format(['x','y','z'][i],info['size'][i])) + for i in range(3): + if info['size'][i] <= 0.0: # any invalid size? + info['size'][i] = float(info['grid'][i])/max(info['grid']) # normalize to grid + remarks.append('rescaling size {} to {}...'.format(['x','y','z'][i],info['size'][i])) if table.label_dimension(options.pos) != 3: errors.append('seed positions "{}" have dimension {}.'.format(options.pos, @@ -306,7 +297,7 @@ for name in filenames: config_header += [''] for i,ID in enumerate(grainIDs): config_header += ['[Grain{}]'.format(str(ID).zfill(formatwidth)), - 'crystallite {}'.format(options.crystallite), + 'crystallite 1', '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(options.phase,str(ID).rjust(formatwidth)), ] if hasEulers: @@ -319,7 +310,8 @@ for name in filenames: ] + theAxes config_header += [''] - geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'],options.homogenization,comments=config_header) + header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header + ['origin x {} y {} z {}'.format(*info['origin'])] + geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'],options.homogenization,comments=header) damask.util.croak(geom) if name is None: From 6e06764e2d94c531c1f703547ed5b29fd7227a3e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 27 May 2019 08:38:02 +0200 Subject: [PATCH 056/120] using (enhanced) central functionality --- processing/pre/geom_fromTable.py | 96 ++++++++------------------------ python/damask/util.py | 13 +++++ 2 files changed, 35 insertions(+), 74 deletions(-) diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py index 7a905cd26..22429ab4e 100755 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -1,21 +1,23 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- -import os,sys,math -import numpy as np +import os +import sys from optparse import OptionParser + +import numpy as np + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) - # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [ASCIItable(s)]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """ Generate geometry description and material configuration from position, phase, and orientation (or microstructure) data. """, version = scriptID) @@ -40,19 +42,13 @@ parser.add_option('--axes', dest = 'axes', type = 'string', nargs = 3, metavar = ' '.join(['string']*3), help = 'orientation coordinate frame in terms of position coordinate frame [+x +y +z]') - parser.add_option('--homogenization', dest = 'homogenization', type = 'int', metavar = 'int', help = 'homogenization index to be used [%default]') -parser.add_option('--crystallite', - dest = 'crystallite', - type = 'int', metavar = 'int', - help = 'crystallite index to be used [%default]') parser.set_defaults(homogenization = 1, - crystallite = 1, pos = 'pos', ) @@ -71,20 +67,12 @@ if options.axes is not None and not set(options.axes).issubset(set(['x','+x','-x (options.microstructure,1,'microstructure'), ][np.where(input)[0][0]] # select input label that was requested -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: - try: - table = damask.ASCIItable(name = name, - outname = os.path.splitext(name)[-2]+'.geom' if name else name, - buffered = False) - except: continue damask.util.report(scriptName,name) - -# ------------------------------------------ read head --------------------------------------- - + table = damask.ASCIItable(name = name,readonly=True) table.head_read() # read ASCII header info # ------------------------------------------ sanity checks --------------------------------------- @@ -101,7 +89,6 @@ for name in filenames: if errors != []: damask.util.croak(errors) - table.close(dismiss = True) continue table.data_readArray([options.pos] \ @@ -113,30 +100,11 @@ for name in filenames: if options.phase is None: table.data = np.column_stack((table.data,np.ones(len(table.data)))) # add single phase if no phase column given -# --------------- figure out size and grid --------------------------------------------------------- - + grid,size = damask.util.coordGridAndSize(table.data[:,0:3]) coords = [np.unique(table.data[:,i]) for i in range(3)] mincorner = np.array(list(map(min,coords))) - maxcorner = np.array(list(map(max,coords))) - grid = np.array(list(map(len,coords)),'i') - size = grid/np.maximum(np.ones(3,'d'), grid-1.0) * (maxcorner-mincorner) # size from edge to edge = dim * n/(n-1) - size = np.where(grid > 1, size, min(size[grid > 1]/grid[grid > 1])) # spacing for grid==1 set to smallest among other spacings - delta = size/np.maximum(np.ones(3,'d'), grid) - origin = mincorner - 0.5*delta # shift from cell center to corner + origin = mincorner - 0.5*size/grid # shift from cell center to corner - N = grid.prod() - - if N != len(table.data): - errors.append('data count {} does not match grid {}.'.format(len(table.data),' x '.join(map(repr,grid)))) - if np.any(np.abs(np.log10((coords[0][1:]-coords[0][:-1])/delta[0])) > 0.01) \ - or np.any(np.abs(np.log10((coords[1][1:]-coords[1][:-1])/delta[1])) > 0.01) \ - or np.any(np.abs(np.log10((coords[2][1:]-coords[2][:-1])/delta[2])) > 0.01): - errors.append('regular grid spacing {} violated.'.format(' x '.join(map(repr,delta)))) - - if errors != []: - damask.util.croak(errors) - table.close(dismiss = True) - continue # ------------------------------------------ process data ------------------------------------------ @@ -151,7 +119,7 @@ for name in filenames: colPhase = -1 # column of phase data comes last index = np.lexsort((table.data[:,0],table.data[:,1],table.data[:,2])) # index of position when sorting x fast, z slow - grain = -np.ones(N,dtype = 'int32') # initialize empty microstructure + grain = -np.ones(grid.prod(),dtype = int) # initialize empty microstructure orientations = [] # orientations multiplicity = [] # orientation multiplicity (number of group members) phases = [] # phase info @@ -180,23 +148,10 @@ for name in filenames: myPos += 1 - grain += 1 # offset from starting index 0 to 1 - -# --- generate header ---------------------------------------------------------------------------- - - info = { - 'grid': grid, - 'size': size, - 'origin': origin, - 'microstructures': nGrains, - 'homogenization': options.homogenization, - } - - damask.util.report_geom(info) + grain += 1 # offset from starting index 0 to 1 -# --- write header --------------------------------------------------------------------------------- - formatwidth = 1+int(math.log10(info['microstructures'])) + formatwidth = 1+int(np.log10(nGrains)) if inputtype == 'microstructure': config_header = [] @@ -204,29 +159,22 @@ for name in filenames: config_header = [''] for i,phase in enumerate(phases): config_header += ['[Grain%s]'%(str(i+1).zfill(formatwidth)), - 'crystallite %i'%options.crystallite, + 'crystallite 1', '(constituent)\tphase %i\ttexture %s\tfraction 1.0'%(phase,str(i+1).rjust(formatwidth)), ] config_header += [''] for i,orientation in enumerate(orientations): config_header += ['[Grain%s]'%(str(i+1).zfill(formatwidth)), - 'axes\t%s %s %s'%tuple(options.axes) if options.axes is not None else '', '(gauss)\tphi1 %g\tPhi %g\tphi2 %g\tscatter 0.0\tfraction 1.0'%tuple(orientation.asEulers(degrees = True)), ] + if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] - table.labels_clear() - table.info_clear() - table.info_append([scriptID + ' ' + ' '.join(sys.argv[1:])]) - table.head_putGeom(info) - table.info_append(config_header) - table.head_write() + header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header + ['origin x {} y {} z {}'.format(*origin)] + geom = damask.Geom(grain.reshape(grid,order='F'),size,options.homogenization,comments=header) + damask.util.croak(geom) -# --- write microstructure information ------------------------------------------------------------ - - table.data = grain.reshape(info['grid'][1]*info['grid'][2],info['grid'][0]) - table.data_writeArray('%{}i'.format(formatwidth),delimiter=' ') - -#--- output finalization -------------------------------------------------------------------------- - - table.close() + if name is None: + sys.stdout.write(str(geom.show())) + else: + geom.to_file(os.path.splitext(name)[0]+'.geom') diff --git a/python/damask/util.py b/python/damask/util.py index 1b990bea8..c078f57bf 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -111,6 +111,19 @@ def coordGridAndSize(coordinates): grid = np.array(list(map(len,coords)),'i') size = grid/np.maximum(np.ones(dim,'d'), grid-1.0) * (maxcorner-mincorner) # size from edge to edge = dim * n/(n-1) size = np.where(grid > 1, size, min(size[grid > 1]/grid[grid > 1])) # spacing for grid==1 equal to smallest among other ones + delta = size/grid + + N = grid.prod() + + if N != len(coordinates): + raise ValueError('Data count {} does not match grid {}.'.format(len(coordinates),' x '.join(map(repr,grid)))) + + if np.any(np.abs(np.log10((coords[0][1:]-coords[0][:-1])/delta[0])) > 0.01) \ + or np.any(np.abs(np.log10((coords[1][1:]-coords[1][:-1])/delta[1])) > 0.01): + raise ValueError('regular grid spacing {} violated.'.format(' x '.join(map(repr,delta)))) + if dim==3 and np.any(np.abs(np.log10((coords[2][1:]-coords[2][:-1])/delta[2])) > 0.01): + raise ValueError('regular grid spacing {} violated.'.format(' x '.join(map(repr,delta)))) + return grid,size # ----------------------------- From 615a4ab40fed01db7a11394ab2105f266e759c9d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 27 May 2019 09:56:15 +0200 Subject: [PATCH 057/120] keep float datatype based on the assumption, that no mixed float/int data is stored --- python/damask/geom.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 5702c1950..bbe36595b 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -162,9 +162,9 @@ class Geom(): microstructure = microstructure.reshape(grid,order='F') - if np.any(np.mod(microstructure.flatten(),1)!=0.0): + if '.' in raw[0]: # contains float values pass - else: + else: # assume int values microstructure = microstructure.astype('int') return cls(microstructure.reshape(grid),size,homogenization,comments) From 59c6c5cfe44ff7572a8d27c6d0617accb79fb8b7 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 27 May 2019 10:49:50 +0200 Subject: [PATCH 058/120] not needed anymore essentially, (gauss) is an Euler angle triplet --- processing/pre/geom_fromTable.py | 2 +- processing/pre/geom_fromVoronoiTessellation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py index 22429ab4e..43bfe338e 100755 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -166,7 +166,7 @@ for name in filenames: config_header += [''] for i,orientation in enumerate(orientations): config_header += ['[Grain%s]'%(str(i+1).zfill(formatwidth)), - '(gauss)\tphi1 %g\tPhi %g\tphi2 %g\tscatter 0.0\tfraction 1.0'%tuple(orientation.asEulers(degrees = True)), + '(gauss)\tphi1 %g\tPhi %g\tphi2 %g'%tuple(orientation.asEulers(degrees = True)), ] if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 43c1a7987..1b0f5432f 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -306,7 +306,7 @@ for name in filenames: for ID in grainIDs: eulerID = np.nonzero(grains == ID)[0][0] # find first occurrence of this grain id config_header += ['[Grain{}]'.format(str(ID).zfill(formatwidth)), - '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}\tscatter 0.0\tfraction 1.0'.format(*eulers[eulerID]) + '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}'.format(*eulers[eulerID]) ] + theAxes config_header += [''] From b69f0efbbc5826b8c2ef975ddb4507f58cd120af Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 27 May 2019 22:00:26 +0200 Subject: [PATCH 059/120] improved and simplified reporting --- processing/pre/geom_addPrimitive.py | 1 - processing/pre/geom_canvas.py | 1 - processing/pre/geom_clean.py | 1 - processing/pre/geom_mirror.py | 1 - processing/pre/geom_renumber.py | 1 - processing/pre/geom_rescale.py | 1 - processing/pre/geom_rotate.py | 1 - processing/pre/geom_toTable.py | 1 + processing/pre/geom_translate.py | 1 - processing/pre/geom_vicinityOffset.py | 1 - python/damask/geom.py | 26 ++++++++++++++++++++------ python/damask/util.py | 18 ++++++++++-------- 12 files changed, 31 insertions(+), 23 deletions(-) diff --git a/processing/pre/geom_addPrimitive.py b/processing/pre/geom_addPrimitive.py index 72f5019e6..65f13a2da 100755 --- a/processing/pre/geom_addPrimitive.py +++ b/processing/pre/geom_addPrimitive.py @@ -104,7 +104,6 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.croak(geom) microstructure = geom.get_microstructure() fill = options.fill if options.fill is not None else np.nanmax(microstructure)+1 diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index 7998c42c5..0951ab1a5 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -51,7 +51,6 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.croak(geom) microstructure = geom.get_microstructure() grid = geom.get_grid() diff --git a/processing/pre/geom_clean.py b/processing/pre/geom_clean.py index 9ed8e88b4..66a205571 100755 --- a/processing/pre/geom_clean.py +++ b/processing/pre/geom_clean.py @@ -49,7 +49,6 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.croak(geom) microstructure = geom.get_microstructure() microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent, diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index 7974bde82..e2bf5f6dd 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -55,7 +55,6 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.croak(geom) microstructure = geom.microstructure if 'z' in options.directions: diff --git a/processing/pre/geom_renumber.py b/processing/pre/geom_renumber.py index 25f67bd50..93c0ffebe 100755 --- a/processing/pre/geom_renumber.py +++ b/processing/pre/geom_renumber.py @@ -36,7 +36,6 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.croak(geom) microstructure = geom.get_microstructure() renumbered = np.copy(microstructure) diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index c1ca091a4..61f41f621 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -46,7 +46,6 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.croak(geom) microstructure = geom.get_microstructure() scale = geom.get_grid().astype('float') diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 4a24b338b..6a058f547 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -78,7 +78,6 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.croak(geom) microstructure = geom.get_microstructure() fill = options.fill if options.fill is not None else np.nanmax(microstructure)+1 diff --git a/processing/pre/geom_toTable.py b/processing/pre/geom_toTable.py index f2e475c1c..e21d081eb 100755 --- a/processing/pre/geom_toTable.py +++ b/processing/pre/geom_toTable.py @@ -56,6 +56,7 @@ for name in filenames: zz = np.repeat(z,grid[0]*grid[1]) # ------------------------------------------ finalize output --------------------------------------- + table = damask.ASCIItable(outname = os.path.splitext(name)[0]+'.txt' if name else name) table.info_append([scriptID + '\t' + ' '.join(sys.argv[1:])] + geom.get_comments()) table.labels_append(['{}_{}'.format(1+i,'pos') for i in range(3)]+['microstructure']) diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index 01f34f547..62cef3a2a 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -58,7 +58,6 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.croak(geom) microstructure = geom.get_microstructure() new = np.copy(microstructure) diff --git a/processing/pre/geom_vicinityOffset.py b/processing/pre/geom_vicinityOffset.py index f058e9424..49e419a65 100755 --- a/processing/pre/geom_vicinityOffset.py +++ b/processing/pre/geom_vicinityOffset.py @@ -74,7 +74,6 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - damask.util.croak(geom) microstructure = geom.get_microstructure() offset = options.offset if options.offset is not None else np.nanmax(microstructure) diff --git a/python/damask/geom.py b/python/damask/geom.py index bbe36595b..46c378240 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -3,6 +3,8 @@ from io import StringIO import numpy as np +from . import util + class Geom(): """Geometry definition for grid solvers""" @@ -67,17 +69,29 @@ class Geom(): if rescale: self.size = self.size * self.get_grid()/grid_old - message = '' + message = ['grid a b c: {}'.format(' x '.join(map(str,grid_old)))] if np.any(grid_old != self.get_grid()): - message += 'grid a b c: {}\n'.format(' x '.join(map(str,self.get_grid()))) + message[-1] = util.bcolors.CROSSOUT+message[-1]+util.bcolors.ENDC + message.append('grid a b c: {}'.format(' x '.join(map(str,self.get_grid())))) + + message.append('size x y z: {}'.format(' x '.join(map(str,size_old)))) if np.any(size_old != self.size): - message += 'size x y z: {}\n'.format(' x '.join(map(str,self.size))) + message[-1] = util.bcolors.CROSSOUT+message[-1]+util.bcolors.ENDC + message.append('size x y z: {}'.format(' x '.join(map(str,self.size)))) + + message.append('homogenization: {}'.format(self.homogenization)) + + message.append('# microstructures: {}'.format(unique_old)) if unique_old != len(np.unique(self.microstructure)): - message += '# microstructures: {}\n'.format(len(np.unique(self.microstructure))) + message[-1] = util.bcolors.CROSSOUT+message[-1]+util.bcolors.ENDC + message.append('# microstructures: {}'.format(len(np.unique(self.microstructure)))) + + message.append('max microstructures: {}'.format(max_old)) if max_old != np.max(self.microstructure): - message += 'max microstructures: {}\n'.format(np.max(self.microstructure)) + message[-1] = util.bcolors.CROSSOUT+message[-1]+util.bcolors.ENDC + message.append('max microstructures: {}'.format(np.max(self.microstructure))) - if message != '': return message + return '\n'.join(message) def add_comment(self,comment): diff --git a/python/damask/util.py b/python/damask/util.py index c078f57bf..7f0f3ab56 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -11,15 +11,16 @@ class bcolors: http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python """ - HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - FAIL = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - DIM = '\033[2m' + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + DIM = '\033[2m' UNDERLINE = '\033[4m' + CROSSOUT = '\033[9m' def disable(self): self.HEADER = '' @@ -30,6 +31,7 @@ class bcolors: self.ENDC = '' self.BOLD = '' self.UNDERLINE = '' + self.CROSSOUT = '' # ----------------------------- From 1f56ac6a4ae8e25499880177f34b4667ce0d6984 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 27 May 2019 19:14:09 -0600 Subject: [PATCH 060/120] streamlining and bugfixing of geom-class --- processing/pre/geom_addPrimitive.py | 30 +-- processing/pre/geom_canvas.py | 107 ++++++--- processing/pre/geom_clean.py | 8 +- processing/pre/geom_fromMinimalSurface.py | 7 +- processing/pre/geom_fromTable.py | 3 +- .../pre/geom_fromVoronoiTessellation.py | 3 +- processing/pre/geom_grainGrowth.py | 9 +- processing/pre/geom_mirror.py | 10 +- processing/pre/geom_pack.py | 42 ++-- processing/pre/geom_renumber.py | 8 +- processing/pre/geom_rescale.py | 38 ++- processing/pre/geom_rotate.py | 33 ++- processing/pre/geom_toTable.py | 13 +- processing/pre/geom_translate.py | 28 +-- processing/pre/geom_unpack.py | 8 +- processing/pre/geom_vicinityOffset.py | 14 +- python/damask/geom.py | 227 +++++++++--------- python/damask/util.py | 5 + test.log | 211 ++++++++++++++++ 19 files changed, 495 insertions(+), 309 deletions(-) create mode 100644 test.log diff --git a/processing/pre/geom_addPrimitive.py b/processing/pre/geom_addPrimitive.py index 65f13a2da..632019118 100755 --- a/processing/pre/geom_addPrimitive.py +++ b/processing/pre/geom_addPrimitive.py @@ -78,7 +78,7 @@ parser.set_defaults(center = (.0,.0,.0), if options.dimension is None: parser.error('no dimension specified.') -if [options.angleaxis,options.quaternion].count(None) == 2: +if [options.angleaxis,options.quaternion].count(None) == 0: parser.error('more than one rotation specified.') if options.angleaxis is not None: @@ -99,27 +99,18 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + grid = geom.get_grid() + size = geom.get_size() + origin = geom.get_origin() microstructure = geom.get_microstructure() - fill = options.fill if options.fill is not None else np.nanmax(microstructure)+1 - - origin = np.zeros(3) - for i,line in enumerate(geom.comments): - if line.lower().strip().startswith('origin'): - origin= np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) - - # coordinates given in real space (default) vs voxel space + # coordinates given in real space, not (default) voxel space if options.realspace: options.center -= origin - options.center *= geom.get_grid() / geom.get_size() - options.dimension *= geom.get_grid() / geom.get_size() - - grid = microstructure.shape + options.center *= grid / size + options.dimension *= grid / size + # change to coordinate space where the primitive is the unit sphere/cube/etc if options.periodic: # use padding to achieve periodicity @@ -158,6 +149,7 @@ for name in filenames: Y /= options.dimension[1] * 0.5 Z /= options.dimension[2] * 0.5 + fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill # High exponents can cause underflow & overflow - loss of precision is okay here, we just compare it to 1, so +infinity and 0 are fine old_settings = np.seterr() @@ -191,7 +183,7 @@ for name in filenames: microstructure if options.inside else fill) damask.util.croak(geom.update(microstructure)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index 0951ab1a5..3b7071968 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -1,80 +1,111 @@ #!/usr/bin/env python3 +# -*- coding: UTF-8 no BOM -*- import os import sys +import numpy as np +import damask + from io import StringIO from optparse import OptionParser -import numpy as np - -import damask - scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) - # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ -Increases or decreases the (three-dimensional) canvas. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [geomfile(s)]', description = """ +Changes the (three-dimensional) canvas of a spectral geometry description. Grid can be given as absolute or relative values, e.g. 16 16 16 or 2x 0.5x 32. """, version = scriptID) -parser.add_option('-g','--grid', +parser.add_option('-g', + '--grid', dest = 'grid', type = 'string', nargs = 3, metavar = ' '.join(['string']*3), - help = 'a,b,c grid of hexahedral box') -parser.add_option('-o','--offset', + help = 'a,b,c grid of hexahedral box. [auto]') +parser.add_option('-o', + '--offset', dest = 'offset', type = 'int', nargs = 3, metavar = ' '.join(['int']*3), help = 'a,b,c offset from old to new origin of grid [%default]') -parser.add_option('-f','--fill', +parser.add_option('-f', + '--fill', dest = 'fill', - type = 'float', metavar = 'int', - help = 'background microstructure index, defaults to max microstructure index + 1') + type = 'float', metavar = 'float', + help = '(background) canvas grain index. "0" selects maximum microstructure index + 1 [%default]') +parser.add_option('--blank', + dest = 'blank', + action = 'store_true', + help = 'blank out (optional) input canvas content') -parser.set_defaults(offset = (0,0,0)) +parser.set_defaults(grid = ['0','0','0'], + offset = (0,0,0), + ) (options, filenames) = parser.parse_args() +options.grid = ['1','1','1'] if options.blank and options.grid == ['0','0','0'] else options.grid +options.fill = 1 if options.blank and options.fill is None else options.fill + +# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) + if name is None and options.blank: + grid = np.array(list(map(int,options.grid))) + geom = damask.Geom(size=grid,microstructure=options.fill*np.ones(grid)) else: - geom = damask.Geom.from_file(name) - microstructure = geom.get_microstructure() - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + grid = geom.get_grid() - if options.grid is not None: - for i,g in enumerate(options.grid): - grid[i] = int(round(grid[i]*float(g.lower().replace('x','')))) if g.lower().endswith('x') \ - else int(options.grid[i]) + size = geom.get_size() + origin = geom.get_origin() + microstructure = geom.get_microstructure() + fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill + dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int - new = np.full(grid,options.fill if options.fill is not None else np.nanmax(microstructure)+1, - microstructure.dtype) + damask.util.croak(geom) - for x in range(microstructure.shape[0]): - X = x + options.offset[0] - if not 0 <= X < new.shape[0]: continue - for y in range(microstructure.shape[1]): - Y = y + options.offset[1] - if not 0 <= Y < new.shape[1]: continue - for z in range(microstructure.shape[2]): - Z = z + options.offset[2] - if not 0 <= Z < new.shape[2]: continue - new[X,Y,Z] = microstructure[x,y,z] +# --- do work ------------------------------------------------------------------------------------ + + new_grid = np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ + else int(n) for o,n in zip(grid,options.grid)],dtype=int) + new_grid = np.where(new_grid > 0, new_grid,grid) - damask.util.croak(geom.update(new,rescale=True)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + microstructure_cropped = np.zeros(new_grid,dtype=dtype) + microstructure_cropped.fill(fill) + + if not options.blank: + xindex = np.arange(max(options.offset[0],0),min(options.offset[0]+new_grid[0],grid[0])) + yindex = np.arange(max(options.offset[1],0),min(options.offset[1]+new_grid[1],grid[1])) + zindex = np.arange(max(options.offset[2],0),min(options.offset[2]+new_grid[2],grid[2])) + translate_x = [i - options.offset[0] for i in xindex] + translate_y = [i - options.offset[1] for i in yindex] + translate_z = [i - options.offset[2] for i in zindex] + if 0 in map(len,[xindex,yindex,zindex,translate_x,translate_y,translate_z]): + damask.util.croak('invaldid combination of grid and offset.') + continue + microstructure_cropped[min(translate_x):max(translate_x)+1, + min(translate_y):max(translate_y)+1, + min(translate_z):max(translate_z)+1] \ + = microstructure[min(xindex):max(xindex)+1, + min(yindex):max(yindex)+1, + min(zindex):max(zindex)+1] + + new_size = size/grid*new_grid if np.all(grid > 0) else new_grid + new_origin = origin + (size/grid if np.all(grid > 0) else new_size/new_grid) * options.offset + + geom.set_microstructure(microstructure_cropped) + geom.set_size(new_size) + geom.set_origin(new_origin) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_clean.py b/processing/pre/geom_clean.py index 66a205571..8fa7f5953 100755 --- a/processing/pre/geom_clean.py +++ b/processing/pre/geom_clean.py @@ -44,18 +44,14 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) microstructure = geom.get_microstructure() microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent, size=(options.stencil,)*3).astype(microstructure.dtype) damask.util.croak(geom.update(microstructure)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_fromMinimalSurface.py b/processing/pre/geom_fromMinimalSurface.py index d001b57d2..787b0628b 100755 --- a/processing/pre/geom_fromMinimalSurface.py +++ b/processing/pre/geom_fromMinimalSurface.py @@ -82,13 +82,14 @@ for name in filenames: Y = options.periods*2.0*np.pi*(np.arange(options.grid[1])+0.5)/options.grid[1] Z = options.periods*2.0*np.pi*(np.arange(options.grid[2])+0.5)/options.grid[2] - microstructure = np.empty(options.grid,dtype='int') + microstructure = np.empty(options.grid,dtype=int) for x in range(options.grid[0]): for y in range(options.grid[1]): for z in range(options.grid[2]): - microstructure[x,y,z]=options.microstructure[options.threshold < surface[options.type](X[x],Y[y],Z[z])] + microstructure[x,y,z]=options.microstructure[int(options.threshold < surface[options.type](X[x],Y[y],Z[z]))] - geom=damask.Geom(microstructure,options.size,options.homogenization, + geom=damask.Geom(microstructure,options.size, + homogenization=options.homogenization, comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) damask.util.croak(geom) diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py index 43bfe338e..b5d5c220c 100755 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -171,7 +171,8 @@ for name in filenames: if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header + ['origin x {} y {} z {}'.format(*origin)] - geom = damask.Geom(grain.reshape(grid,order='F'),size,options.homogenization,comments=header) + geom = damask.Geom(grain.reshape(grid,order='F'),size, + homogenization=options.homogenization,comments=header) damask.util.croak(geom) if name is None: diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 1b0f5432f..46533fdc5 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -311,7 +311,8 @@ for name in filenames: config_header += [''] header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header + ['origin x {} y {} z {}'.format(*info['origin'])] - geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'],options.homogenization,comments=header) + geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'], + homogenization=options.homogenization,comments=header) damask.util.croak(geom) if name is None: diff --git a/processing/pre/geom_grainGrowth.py b/processing/pre/geom_grainGrowth.py index af044879e..952c15c13 100755 --- a/processing/pre/geom_grainGrowth.py +++ b/processing/pre/geom_grainGrowth.py @@ -59,11 +59,8 @@ options.immutable = list(map(int,options.immutable)) for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + microstructure = geom.get_microstructure() damask.util.croak(geom) grid_original = geom.get_grid() @@ -171,7 +168,7 @@ for name in filenames: microstructure = np.where(immutable, microstructure_original,microstructure) damask.util.croak(geom.update(microstructure[0:grid_original[0],0:grid_original[1],0:grid_original[2]])) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index e2bf5f6dd..7933e416c 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -50,12 +50,8 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) - microstructure = geom.microstructure + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + microstructure = geom.get_microstructure() if 'z' in options.directions: microstructure = np.concatenate([microstructure,microstructure[:,:,limits[0]:limits[1]:-1]],2) @@ -65,7 +61,7 @@ for name in filenames: microstructure = np.concatenate([microstructure,microstructure[limits[0]:limits[1]:-1,:,:]],0) damask.util.croak(geom.update(microstructure,rescale=True)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_pack.py b/processing/pre/geom_pack.py index 9816551b0..cc655c06d 100755 --- a/processing/pre/geom_pack.py +++ b/processing/pre/geom_pack.py @@ -29,14 +29,10 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) - damask.util.croak(geom) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) microstructure = geom.get_microstructure().flatten('F') - + damask.util.croak(geom) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) compressType = None former = start = -1 @@ -51,13 +47,13 @@ for name in filenames: reps += 1 else: if compressType is None: - out = [] + out = geom.get_header() elif compressType == '.': - out.append('{}\n'.format(former)) + out.append('{}'.format(former)) elif compressType == 'to': - out.append('{} to {}\n'.format(start,former)) + out.append('{} to {}'.format(start,former)) elif compressType == 'of': - out.append('{} of {}\n'.format(reps,former)) + out.append('{} of {}'.format(reps,former)) compressType = '.' start = current @@ -66,18 +62,18 @@ for name in filenames: former = current if compressType == '.': - out.append('{}\n'.format(former)) + out.append('{}'.format(former)) elif compressType == 'to': - out.append('{} to {}\n'.format(start,former)) + out.append('{} to {}'.format(start,former)) elif compressType == 'of': - out.append('{} of {}\n'.format(reps,former)) + out.append('{} of {}'.format(reps,former)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) - comments = geom.get_comments() - with open(name,'w') as f: - f.write('{} header\n'.format(3+len(comments))) - f.writelines(["{}\n".format(comment) for comment in comments]) - f.write('grid a {} b {} c {}\n'.format(*geom.get_grid())) - f.write('size x {} y {} z {}\n'.format(*geom.get_size())) - f.write('homogenization {}\n'.format(geom.get_homogenization())) - f.writelines(out) + + if name is None: + sys.stdout.write('\n'.join(out)+'\n') + else: + with open(name,'w') as f: + f.write('\n'.join(out)+'\n') + + + diff --git a/processing/pre/geom_renumber.py b/processing/pre/geom_renumber.py index 93c0ffebe..ef21cd1ab 100755 --- a/processing/pre/geom_renumber.py +++ b/processing/pre/geom_renumber.py @@ -31,11 +31,7 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) microstructure = geom.get_microstructure() renumbered = np.copy(microstructure) @@ -43,7 +39,7 @@ for name in filenames: renumbered = np.where(microstructure == oldID, i+1, renumbered) damask.util.croak(geom.update(renumbered)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index 61f41f621..1a94f327e 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -2,9 +2,10 @@ import os import sys +import numpy as np + from io import StringIO from optparse import OptionParser - from scipy import ndimage import damask @@ -41,30 +42,25 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) microstructure = geom.get_microstructure() - - scale = geom.get_grid().astype('float') - if options.grid is not None: - for i,g in enumerate(options.grid): - scale[i] = scale[i]*float(g.lower().replace('x','')) if g.lower().endswith('x') \ - else float(options.grid[i])/scale[i] - + grid = geom.get_grid() size = geom.get_size() - if options.size is not None: - for i,s in enumerate(options.size): - size[i] = size[i]*float(s.lower().replace('x','')) if s.lower().endswith('x') \ - else options.size[i] - microstructure = ndimage.interpolation.zoom(microstructure, scale, output=microstructure.dtype, - order=0, mode='nearest', prefilter=False) + new_grid = grid if options.grid is None else \ + np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ + else int(n) for o,n in zip(grid,options.grid)],dtype=int) - damask.util.croak(geom.update(microstructure,size)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + new_size = size if options.size is None else \ + np.array([o*float(n.lower().replace('x','')) if n.lower().endswith('x') \ + else float(n) for o,n in zip(size,options.size)],dtype=float) + + if np.any(new_grid != grid): + microstructure = ndimage.interpolation.zoom(microstructure, new_grid/grid,output=microstructure.dtype, + order=0,mode='nearest', prefilter=False) + + damask.util.croak(geom.update(microstructure,new_size)) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 6a058f547..4189fefea 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -27,7 +27,7 @@ Rotates original microstructure and embeddeds it into buffer material. parser.add_option('-r', '--rotation', dest='rotation', type = 'float', nargs = 4, metavar = ' '.join(['float']*4), - help = 'rotation given as angle and axis') + help = 'rotation given as axis and angle') parser.add_option('-e', '--eulers', dest = 'eulers', type = 'float', nargs = 3, metavar = ' '.join(['float']*3), @@ -59,41 +59,38 @@ if [options.rotation,options.eulers,options.matrix,options.quaternion].count(Non parser.error('no rotation specified.') if options.quaternion is not None: - eulers = damask.Rotation.fromQuaternion(np.array(options.quaternion)).asEulers(degrees=True) + rot = damask.Rotation.fromQuaternion(np.array(options.quaternion)) # we might need P=+1 here, too... if options.rotation is not None: - eulers = damask.Rotation.fromAxisAngle(np.array(options.rotation,degrees=options.degrees)).asEulers(degrees=True) + rot = damask.Rotation.fromAxisAngle(np.array(options.rotation),degrees=options.degrees,P=+1) if options.matrix is not None: - eulers = damask.Rotation.fromMatrix(np.array(options.Matrix)).asEulers(degrees=True) + rot = damask.Rotation.fromMatrix(np.array(options.Matrix)) if options.eulers is not None: - eulers = damask.Rotation.fromEulers(np.array(options.eulers),degrees=options.degrees).asEulers(degrees=True) + rot = damask.Rotation.fromEulers(np.array(options.eulers),degrees=options.degrees) +eulers = rot.asEulers(degrees=True) if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) microstructure = geom.get_microstructure() - - fill = options.fill if options.fill is not None else np.nanmax(microstructure)+1 - + fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill + dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int + # These rotations are always applied in the reference coordinate system, i.e. (z,x,z) not (z,x',z'') # this seems to be ok, see https://www.cs.utexas.edu/~theshark/courses/cs354/lectures/cs354-14.pdf microstructure = ndimage.rotate(microstructure,eulers[2],(0,1),order=0, - prefilter=False,output=microstructure.dtype,cval=fill) # rotation around z + prefilter=False,output=dtype,cval=fill) # rotation around z microstructure = ndimage.rotate(microstructure,eulers[1],(1,2),order=0, - prefilter=False,output=microstructure.dtype,cval=fill) # rotation around x + prefilter=False,output=dtype,cval=fill) # rotation around x microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0, - prefilter=False,output=microstructure.dtype,cval=fill) # rotation around z + prefilter=False,output=dtype,cval=fill) # rotation around z damask.util.croak(geom.update(microstructure,rescale=True)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_toTable.py b/processing/pre/geom_toTable.py index e21d081eb..352238524 100755 --- a/processing/pre/geom_toTable.py +++ b/processing/pre/geom_toTable.py @@ -31,20 +31,13 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) damask.util.croak(geom) microstructure = geom.get_microstructure().flatten('F') grid = geom.get_grid() size = geom.get_size() + origin = geom.get_origin() - for i,line in enumerate(geom.get_comments()): - if line.lower().strip().startswith('origin'): - origin= np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) - #--- generate grid -------------------------------------------------------------------------------- x = (0.5 + np.arange(grid[0],dtype=float))/grid[0]*size[0]+origin[0] @@ -58,7 +51,7 @@ for name in filenames: # ------------------------------------------ finalize output --------------------------------------- table = damask.ASCIItable(outname = os.path.splitext(name)[0]+'.txt' if name else name) - table.info_append([scriptID + '\t' + ' '.join(sys.argv[1:])] + geom.get_comments()) + table.info_append(geom.get_comments() + [scriptID + '\t' + ' '.join(sys.argv[1:])]) table.labels_append(['{}_{}'.format(1+i,'pos') for i in range(3)]+['microstructure']) table.head_write() table.output_flush() diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index 62cef3a2a..488da5103 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -43,36 +43,22 @@ parser.set_defaults(origin = (0.0,0.0,0.0), (options, filenames) = parser.parse_args() -sub = {} -for i in range(len(options.substitute)//2): # split substitution list into "from" -> "to" - sub[int(options.substitute[i*2])] = int(options.substitute[i*2+1]) - +sub = list(map(int,options.substitute)) if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) microstructure = geom.get_microstructure() - new = np.copy(microstructure) + substituted = np.copy(microstructure) - for k, v in sub.items(): new[microstructure==k] = v # substitute microstructure indices and shift + for old,new in zip(sub[0::2],sub[1::2]): substituted[microstructure==old] = new # substitute microstructure indices + substituted += options.microstructure # constant shift - microstructure += options.microstructure # constant shift - - for i,line in enumerate(geom.get_comments()): - if line.lower().strip().startswith('origin'): - origin= np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) - origin += np.array(origin) - geom.comments[i] = 'origin x {} y {} z {}'.format(*origin) - - damask.util.croak(geom.update(microstructure)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + damask.util.croak(geom.update(substituted,origin=geom.get_origin()+options.origin)) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_unpack.py b/processing/pre/geom_unpack.py index 028fc2e25..1c9b591be 100755 --- a/processing/pre/geom_unpack.py +++ b/processing/pre/geom_unpack.py @@ -29,14 +29,10 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) damask.util.croak(geom) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/processing/pre/geom_vicinityOffset.py b/processing/pre/geom_vicinityOffset.py index 49e419a65..e36aac301 100755 --- a/processing/pre/geom_vicinityOffset.py +++ b/processing/pre/geom_vicinityOffset.py @@ -41,10 +41,10 @@ parser.add_option('-v', '--vicinity', dest = 'vicinity', type = 'int', metavar = 'int', help = 'voxel distance checked for presence of other microstructure [%default]') -parser.add_option('-m', '--microstructureoffset', +parser.add_option('-o', '--offset', dest='offset', type = 'int', metavar = 'int', - help='offset (positive or negative) to tag microstructure indices, defaults to max microstructure index + 1') + help='offset (positive or negative) to tag microstructure indices, defaults to max microstructure index') parser.add_option('-t', '--trigger', dest = 'trigger', action = 'extend', metavar = '', @@ -69,14 +69,10 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) microstructure = geom.get_microstructure() - offset = options.offset if options.offset is not None else np.nanmax(microstructure) + offset = np.nanmax(microstructure) if options.offset is None else options.offset microstructure = np.where(ndimage.filters.generic_filter(microstructure, taintedNeighborhood, @@ -86,7 +82,7 @@ for name in filenames: microstructure + offset,microstructure) damask.util.croak(geom.update(microstructure)) - geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) + geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: sys.stdout.write(str(geom.show())) diff --git a/python/damask/geom.py b/python/damask/geom.py index 46c378240..49dbacff8 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -9,110 +9,116 @@ from . import util class Geom(): """Geometry definition for grid solvers""" - def __init__(self,microstructure,size,homogenization=1,comments=[]): + def __init__(self,microstructure,size,origin=[0.0,0.0,0.0],homogenization=1,comments=[]): """New geometry definition from array of microstructures and size""" - if len(microstructure.shape) != 3: - raise ValueError('Invalid microstructure shape {}'.format(*microstructure.shape)) - elif microstructure.dtype not in [int,float]: - raise TypeError('Invalid data type {} for microstructure'.format(microstructure.dtype)) - else: - self.microstructure = microstructure + self.set_size(size) + self.set_origin(origin) + self.set_microstructure(microstructure) + self.set_homogenization(homogenization) + self.set_comments(comments) - if len(size) != 3 or any(np.array(size)<=0): - raise ValueError('Invalid size {}'.format(*size)) - else: - self.size = np.array(size) - - if not isinstance(homogenization,int) or homogenization < 1: - raise TypeError('Invalid homogenization {}'.format(homogenization)) - else: - self.homogenization = homogenization - - if not isinstance(comments,list): - self.comments = [str(comments)] - else: - self.comments = [str(comment) for comment in comments] def __repr__(self): """Basic information on geometry definition""" - return 'grid a b c: {}\n'.format(' x '.join(map(str,self.get_grid()))) + \ - 'size x y z: {}\n'.format(' x '.join(map(str,self.size))) + \ - 'homogenization: {}\n'.format(self.homogenization) + \ + return 'grid a b c: {}\n'.format(' x '.join(map(str,self.get_grid ()))) + \ + 'size x y z: {}\n'.format(' x '.join(map(str,self.get_size ()))) + \ + 'origin x y z: {}\n'.format(' x '.join(map(str,self.get_origin()))) + \ + 'homogenization: {}\n'.format(self.get_homogenization()) + \ '# microstructures: {}\n'.format(len(np.unique(self.microstructure))) + \ - 'max microstructures: {}\n'.format(np.max(self.microstructure)) + 'max microstructures: {}\n'.format(np.nanmax(self.microstructure)) - def update(self,microstructure=None,size=None,rescale=False): + def update(self,microstructure=None,size=None,origin=None,rescale=False): """Updates microstructure and size""" grid_old = self.get_grid() size_old = self.get_size() + origin_old = self.get_origin() unique_old = len(np.unique(self.microstructure)) - max_old = np.max(self.microstructure) + max_old = np.nanmax(self.microstructure) if size is not None and rescale: raise ValueError('Either set size explicitly or rescale automatically') + self.set_microstructure(microstructure) + self.set_size(self.get_grid()/grid_old if rescale else size) + self.set_origin(origin) + + message = ['grid a b c: {}'.format(' x '.join(map(str,grid_old)))] + if np.any(grid_old != self.get_grid()): + message[-1] = util.delete(message[-1]) + message.append('grid a b c: {}'.format(' x '.join(map(str,self.get_grid())))) + + message.append('size x y z: {}'.format(' x '.join(map(str,size_old)))) + if np.any(size_old != self.get_size()): + message[-1] = util.delete(message[-1]) + message.append('size x y z: {}'.format(' x '.join(map(str,self.get_size())))) + + message.append('origin x y z: {}'.format(' x '.join(map(str,origin_old)))) + if np.any(origin_old != self.get_origin()): + message[-1] = util.delete(message[-1]) + message.append('origin x y z: {}'.format(' x '.join(map(str,self.get_origin())))) + + message.append('homogenization: {}'.format(self.get_homogenization())) + + message.append('# microstructures: {}'.format(unique_old)) + if unique_old != len(np.unique(self.microstructure)): + message[-1] = util.delete(message[-1]) + message.append('# microstructures: {}'.format(len(np.unique(self.microstructure)))) + + message.append('max microstructure: {}'.format(max_old)) + if max_old != np.nanmax(self.microstructure): + message[-1] = util.delete(message[-1]) + message.append('max microstructure: {}'.format(np.nanmax(self.microstructure))) + + return util.srepr(message) + + def set_comments(self,comments): + self.comments = [] + self.add_comments(comments) + + def add_comments(self,comments): + self.comments += [str(c) for c in comments] if isinstance(comments,list) else [str(comments)] + + def set_microstructure(self,microstructure): if microstructure is not None: if len(microstructure.shape) != 3: raise ValueError('Invalid microstructure shape {}'.format(*microstructure.shape)) - elif microstructure.dtype not in ['int','float']: + elif microstructure.dtype not in [int,float]: raise TypeError('Invalid data type {} for microstructure'.format(microstructure.dtype)) else: - self.microstructure = microstructure - + self.microstructure = np.copy(microstructure) + + def set_size(self,size): if size is not None: if len(size) != 3 or any(np.array(size)<=0): raise ValueError('Invalid size {}'.format(*size)) else: self.size = np.array(size) - - if rescale: - self.size = self.size * self.get_grid()/grid_old - - message = ['grid a b c: {}'.format(' x '.join(map(str,grid_old)))] - if np.any(grid_old != self.get_grid()): - message[-1] = util.bcolors.CROSSOUT+message[-1]+util.bcolors.ENDC - message.append('grid a b c: {}'.format(' x '.join(map(str,self.get_grid())))) - message.append('size x y z: {}'.format(' x '.join(map(str,size_old)))) - if np.any(size_old != self.size): - message[-1] = util.bcolors.CROSSOUT+message[-1]+util.bcolors.ENDC - message.append('size x y z: {}'.format(' x '.join(map(str,self.size)))) + def set_origin(self,origin): + if origin is not None: + if len(origin) != 3: + raise ValueError('Invalid origin {}'.format(*origin)) + else: + self.origin = np.array(origin) - message.append('homogenization: {}'.format(self.homogenization)) - - message.append('# microstructures: {}'.format(unique_old)) - if unique_old != len(np.unique(self.microstructure)): - message[-1] = util.bcolors.CROSSOUT+message[-1]+util.bcolors.ENDC - message.append('# microstructures: {}'.format(len(np.unique(self.microstructure)))) - - message.append('max microstructures: {}'.format(max_old)) - if max_old != np.max(self.microstructure): - message[-1] = util.bcolors.CROSSOUT+message[-1]+util.bcolors.ENDC - message.append('max microstructures: {}'.format(np.max(self.microstructure))) - - return '\n'.join(message) + def set_homogenization(self,homogenization): + if homogenization is not None: + if not isinstance(homogenization,int) or homogenization < 1: + raise TypeError('Invalid homogenization {}'.format(homogenization)) + else: + self.homogenization = homogenization - def add_comment(self,comment): - if not isinstance(comment,list): - self.comments = [str(comment)] + self.comments - else: - self.comments = [str(c) for c in comment] + self.comments - - def set_microstructure(self,microstructure): - self.microstructure = np.copy(microstructure) - - def set_size(self,size): - self.size = np.array(size) - - def get_microstructure(self): return np.copy(self.microstructure) def get_size(self): return np.copy(self.size) + def get_origin(self): + return np.copy(self.origin) + def get_grid(self): return np.array(self.microstructure.shape) @@ -122,42 +128,44 @@ class Geom(): def get_comments(self): return self.comments[:] + def get_header(self): + header = ['{} header'.format(len(self.comments)+4)] + self.comments + header.append('grid a {} b {} c {}'.format(*self.get_grid())) + header.append('size x {} y {} z {}'.format(*self.get_size())) + header.append('origin x {} y {} z {}'.format(*self.get_origin())) + header.append('homogenization {}'.format(self.get_homogenization())) + return header + @classmethod def from_file(cls,fname): - """Reads from *.geom file""" - if isinstance(fname,str): - f = open(fname) - header_length,keyword = f.readline().split() - if not keyword.startswith('head') or int(header_length) < 3: - raise TypeError('Header length information missing or invalid') - comments_old = [f.readline() for i in range(int(header_length))] - else: - fname.seek(0) - header_length,keyword = fname.readline().split() - if not keyword.startswith('head') or int(header_length) < 3: - raise TypeError('Header length information missing or invalid') - comments_old = [fname.readline() for i in range(int(header_length))] + """Reads a geom file""" + with (open(fname) if isinstance(fname,str) else fname) as f: + f.seek(0) + header_length,keyword = f.readline().split()[:2] + header_length = int(header_length) + content = f.readlines() + + if not keyword.startswith('head') or header_length < 3: + raise TypeError('Header length information missing or invalid') comments = [] - for i,line in enumerate(comments_old): - if line.lower().strip().startswith('grid'): - grid = np.array([int(line.split()[j]) for j in [2,4,6]]) # assume correct order (a,b,c) - elif line.lower().strip().startswith('size'): - size = np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z) - elif line.lower().strip().startswith('homogenization'): - homogenization = int(line.split()[1]) + for i,line in enumerate(content[:header_length]): + items = line.lower().strip().split() + key = items[0] if len(items) > 0 else '' + if key == 'grid': + grid = np.array([ int(dict(zip(items[1::2],items[2::2]))[i]) for i in ['a','b','c']]) + elif key == 'size': + size = np.array([float(dict(zip(items[1::2],items[2::2]))[i]) for i in ['x','y','z']]) + elif key == 'origin': + origin = np.array([float(dict(zip(items[1::2],items[2::2]))[i]) for i in ['x','y','z']]) + elif key == 'homogenization': + homogenization = int(items[1]) else: - comments.append(line.rstrip().strip()) - - if isinstance(fname,str): - raw = f.readlines() - f.close() - else: - raw = fname.readlines() + comments.append(line.strip()) microstructure = np.empty(grid.prod()) # initialize as flat array i = 0 - for line in raw: + for line in content[header_length:]: items = line.split() if len(items) == 3: if items[1].lower() == 'of': @@ -175,28 +183,19 @@ class Geom(): raise TypeError('Invalid file: expected {} entries,found {}'.format(grid.prod(),i)) microstructure = microstructure.reshape(grid,order='F') - - if '.' in raw[0]: # contains float values - pass - else: # assume int values + if not np.any(np.mod(microstructure.flatten(),1) != 0.0): # no float present microstructure = microstructure.astype('int') - return cls(microstructure.reshape(grid),size,homogenization,comments) + return cls(microstructure.reshape(grid),size,origin,homogenization,comments) def to_file(self,fname): - """Saves to file""" - grid = self.get_grid() - header = ['{} header'.format(len(self.comments)+3)] - header += self.comments - header.append('grid a {} b {} c {}'.format(*grid)) - header.append('size x {} y {} z {}'.format(*self.size)) - header.append('homogenization {}'.format(self.get_homogenization())) - - if self.microstructure.dtype == 'int': - format_string='%{}i'.format(int(math.floor(math.log10(self.microstructure.max())+1))) - else: - format_string='%.18e' - np.savetxt(fname, self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T, + """Writes to file""" + header = self.get_header() + grid = self.get_grid() + format_string = '%{}i'.format(int(math.floor(math.log10(self.microstructure.max())+1))) if self.microstructure.dtype == int \ + else '%g' + np.savetxt(fname, + self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T, header='\n'.join(header), fmt=format_string, comments='') def show(self): diff --git a/python/damask/util.py b/python/damask/util.py index 7f0f3ab56..d11b74a7b 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -85,6 +85,11 @@ def delete(what): """Dims string""" return bcolors.DIM+srepr(what)+bcolors.ENDC +# ----------------------------- +def strikeout(what): + """Dims string""" + return bcolors.CROSSOUT+srepr(what)+bcolors.ENDC + # ----------------------------- def execute(cmd, streamIn = None, diff --git a/test.log b/test.log new file mode 100644 index 000000000..a9dbb8c45 --- /dev/null +++ b/test.log @@ -0,0 +1,211 @@ +2019-05-27 22:44:00,700 - INFO: +++++++++++++++++++++++++++++++++++++++++ +---------------------------------------- +| Check geom-modifying scripts +---------------------------------------- +2019-05-27 22:44:00,707 - INFO: +geom_addPrimitive -c 0.3 0.5 0.2 -a 1.0 0.8 0.9 0.4 -d 0.10 0.13 0.08 geom_addPrimitive.geom +2019-05-27 22:44:00,899 - INFO: +geom_addPrimitive: geom_addPrimitive.geom + +grid a b c: 32 x 35 x 12 +size x y z: 0.914285714286 x 1.0 x 0.342857142857 +origin x y z: 0.0 x 1.0 x 2.0 +homogenization: 1 +# microstructures: 20 +max microstructure: 26 + +2019-05-27 22:44:00,899 - DEBUG: + +2019-05-27 22:44:00,899 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_addPrimitive_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_addPrimitive.geom +2019-05-27 22:44:00,920 - INFO: +geom_canvas -g 40 35 20 -f 90 geom_canvas.geom +2019-05-27 22:44:01,103 - INFO: +geom_canvas: geom_canvas.geom + +grid a b c: 32 x 35 x 12 +size x y z: 0.914285714286 x 1.0 x 0.342857142857 +origin x y z: 0.0 x 0.0 x 0.0 +homogenization: 1 +# microstructures: 20 +max microstructures: 20 + + +2019-05-27 22:44:01,103 - DEBUG: + +2019-05-27 22:44:01,104 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_canvas_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_canvas.geom +2019-05-27 22:44:01,135 - INFO: +geom_clean -s 2 geom_clean.geom +2019-05-27 22:44:03,219 - INFO: +geom_clean: geom_clean.geom + +grid a b c: 53 x 52 x 52 +size x y z: 1.0 x 0.981132075472 x 0.981132075472 +origin x y z: 0.0 x 0.0 x 0.0 +homogenization: 1 +# microstructures: 23 +max microstructure: 23 + +2019-05-27 22:44:03,219 - DEBUG: + +2019-05-27 22:44:03,219 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_clean_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_clean.geom +2019-05-27 22:44:03,378 - INFO: +geom_grainGrowth -N2 -i 4 -d 2 geom_grainGrowth.geom +2019-05-27 22:44:04,065 - INFO: +geom_grainGrowth: geom_grainGrowth.geom + +grid a b c: 40 x 40 x 40 +size x y z: 1.0 x 1.0 x 1.0 +origin x y z: 0.0 x 0.0 x 0.0 +homogenization: 1 +# microstructures: 15 +max microstructures: 15 + +grid a b c: 40 x 40 x 40 +size x y z: 1.0 x 1.0 x 1.0 +origin x y z: 0.0 x 0.0 x 0.0 +homogenization: 1 +# microstructures: 15 +max microstructure: 15 + +2019-05-27 22:44:04,065 - DEBUG: + +2019-05-27 22:44:04,065 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_grainGrowth_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_grainGrowth.geom +2019-05-27 22:44:04,131 - INFO: +geom_mirror -d x,y,z --double geom_mirror.geom +2019-05-27 22:44:04,330 - INFO: +geom_mirror: geom_mirror.geom + +grid a b c: 32 x 35 x 12 +grid a b c: 64 x 70 x 24 +size x y z: 0.914285714286 x 1.0 x 0.342857142857 +size x y z: 2.0 x 2.0 x 2.0 +origin x y z: 0.0 x 0.0 x 0.0 +homogenization: 1 +# microstructures: 20 +max microstructure: 20 + +2019-05-27 22:44:04,331 - DEBUG: + +2019-05-27 22:44:04,331 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_mirror_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_mirror.geom +2019-05-27 22:44:04,447 - INFO: +geom_renumber geom_renumber.geom +2019-05-27 22:44:04,688 - INFO: +geom_renumber: geom_renumber.geom + +grid a b c: 53 x 52 x 52 +size x y z: 1.0 x 0.981132075472 x 0.981132075472 +origin x y z: 0.0 x 0.0 x 0.0 +homogenization: 1 +# microstructures: 23 +max microstructure: 42 +max microstructure: 23 + +2019-05-27 22:44:04,688 - DEBUG: + +2019-05-27 22:44:04,688 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_renumber_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_renumber.geom +2019-05-27 22:44:04,864 - INFO: +geom_rescale -g 20 22 20 -s 0.1 0.2 0.3 geom_rescale.geom +2019-05-27 22:44:05,109 - INFO: +geom_rescale: geom_rescale.geom + +grid a b c: 32 x 35 x 12 +grid a b c: 20 x 22 x 20 +size x y z: 0.914285714286 x 1.0 x 0.342857142857 +size x y z: 0.1 x 0.2 x 0.3 +origin x y z: 0.0 x 0.0 x 0.0 +homogenization: 1 +# microstructures: 20 +max microstructure: 20 + +2019-05-27 22:44:05,109 - DEBUG: + +2019-05-27 22:44:05,109 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_rescale_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_rescale.geom +2019-05-27 22:44:05,122 - INFO: +geom_rotate -d -e 45 45 0 geom_rotate.geom +2019-05-27 22:44:05,529 - INFO: +geom_rotate: geom_rotate.geom + +grid a b c: 53 x 52 x 52 +grid a b c: 90 x 90 x 74 +size x y z: 1.0 x 0.981132075472 x 0.981132075472 +size x y z: 1.6981132075471699 x 1.7307692307692308 x 1.4230769230769231 +origin x y z: 0.0 x 0.0 x 0.0 +homogenization: 1 +# microstructures: 23 +# microstructures: 24 +max microstructure: 23 +max microstructure: 24 + +2019-05-27 22:44:05,530 - DEBUG: + +2019-05-27 22:44:05,530 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_rotate_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_rotate.geom +2019-05-27 22:44:06,282 - INFO: +geom_translate -o 0 1 2 -m 6 geom_translate.geom +2019-05-27 22:44:06,469 - INFO: +geom_translate: geom_translate.geom + +grid a b c: 32 x 35 x 12 +size x y z: 0.914285714286 x 1.0 x 0.342857142857 +origin x y z: 0.0 x 0.0 x 0.0 +origin x y z: 0.0 x 1.0 x 2.0 +homogenization: 1 +# microstructures: 20 +max microstructure: 20 +max microstructure: 26 + +2019-05-27 22:44:06,469 - DEBUG: + +2019-05-27 22:44:06,469 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_translate_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_translate.geom +2019-05-27 22:44:06,486 - INFO: +geom_vicinityOffset -v 2 geom_vicinityOffset.geom +2019-05-27 22:44:07,005 - INFO: +geom_vicinityOffset: geom_vicinityOffset.geom + +grid a b c: 40 x 40 x 40 +size x y z: 1.0 x 1.0 x 1.0 +origin x y z: 0.0 x 0.0 x 0.0 +homogenization: 1 +# microstructures: 5 +# microstructures: 10 +max microstructure: 5 +max microstructure: 10 + +2019-05-27 22:44:07,005 - DEBUG: + +2019-05-27 22:44:07,005 - INFO: +comparing + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_vicinityOffset_reference.geom + /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_vicinityOffset.geom +2019-05-27 22:44:07,076 - CRITICAL: +**************************************** +All 10 tests passed. +**************************************** + From 100a2031d3fc27a78897696257c14f2083360720 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 28 May 2019 07:55:24 +0200 Subject: [PATCH 061/120] [skip ci] no white space needed --- processing/pre/geom_pack.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/processing/pre/geom_pack.py b/processing/pre/geom_pack.py index cc655c06d..1a002830e 100755 --- a/processing/pre/geom_pack.py +++ b/processing/pre/geom_pack.py @@ -74,6 +74,3 @@ for name in filenames: else: with open(name,'w') as f: f.write('\n'.join(out)+'\n') - - - From 669ca82ce1979b561c190d3a5ea958999e6d5fc6 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 28 May 2019 09:02:29 +0200 Subject: [PATCH 062/120] formatted return message also on interactive shells --- python/damask/geom.py | 2 +- python/damask/util.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 49dbacff8..4428a2f6b 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -70,7 +70,7 @@ class Geom(): message[-1] = util.delete(message[-1]) message.append('max microstructure: {}'.format(np.nanmax(self.microstructure))) - return util.srepr(message) + return util.return_message(message) def set_comments(self,comments): self.comments = [] diff --git a/python/damask/util.py b/python/damask/util.py index d11b74a7b..7e7bae3bc 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -189,6 +189,17 @@ def progressBar(iteration, total, prefix='', bar_length=50): if iteration == total: sys.stderr.write('\n') sys.stderr.flush() + + +class return_message(): + """Object with formatted return message""" + + def __init__(self,message): + self.message = message + + def __repr__(self): + """Return message suitable for interactive shells""" + return srepr(self.message) def leastsqBound(func, x0, args=(), bounds=None, Dfun=None, full_output=0, From 0db42642652fc047895aa6fa4d9c71e7560634b6 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 28 May 2019 09:27:52 +0200 Subject: [PATCH 063/120] cleaning --- src/config.f90 | 2 +- src/quaternions.f90 | 334 ++++++++++++++++++++++---------------------- 2 files changed, 168 insertions(+), 168 deletions(-) diff --git a/src/config.f90 b/src/config.f90 index 8729014ce..cd67c4641 100644 --- a/src/config.f90 +++ b/src/config.f90 @@ -15,7 +15,7 @@ module config implicit none private - type(tPartitionedStringList), public, protected, allocatable, dimension(:) :: & + type(tPartitionedStringList), public, protected, allocatable, dimension(:) :: & config_phase, & config_microstructure, & config_homogenization, & diff --git a/src/quaternions.f90 b/src/quaternions.f90 index 47490daba..dc894bdfa 100644 --- a/src/quaternions.f90 +++ b/src/quaternions.f90 @@ -3,27 +3,27 @@ ! Modified 2017-2019, Martin Diehl/Max-Planck-Institut für Eisenforschung GmbH ! All rights reserved. ! -! Redistribution and use in source and binary forms, with or without modification, are +! Redistribution and use in source and binary forms, with or without modification, are ! permitted provided that the following conditions are met: ! -! - Redistributions of source code must retain the above copyright notice, this list +! - Redistributions of source code must retain the above copyright notice, this list ! of conditions and the following disclaimer. -! - Redistributions in binary form must reproduce the above copyright notice, this -! list of conditions and the following disclaimer in the documentation and/or +! - Redistributions in binary form must reproduce the above copyright notice, this +! list of conditions and the following disclaimer in the documentation and/or ! other materials provided with the distribution. -! - Neither the names of Marc De Graef, Carnegie Mellon University nor the names -! of its contributors may be used to endorse or promote products derived from +! - Neither the names of Marc De Graef, Carnegie Mellon University nor the names +! of its contributors may be used to endorse or promote products derived from ! this software without specific prior written permission. ! -! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE ! USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! ################################################################### @@ -34,57 +34,57 @@ !> @details w is the real part, (x, y, z) are the imaginary parts. !--------------------------------------------------------------------------------------------------- module quaternions - use prec - use future + use prec + use future - implicit none - public - - real(pReal), parameter, public :: P = -1.0_pReal !< parameter for orientation conversion. - - type, public :: quaternion - real(pReal) :: w = 0.0_pReal - real(pReal) :: x = 0.0_pReal - real(pReal) :: y = 0.0_pReal - real(pReal) :: z = 0.0_pReal - + implicit none + public - contains - procedure, private :: add__ - procedure, private :: pos__ - generic, public :: operator(+) => add__,pos__ + real(pReal), parameter, public :: P = -1.0_pReal !< parameter for orientation conversion. - procedure, private :: sub__ - procedure, private :: neg__ - generic, public :: operator(-) => sub__,neg__ + type, public :: quaternion + real(pReal) :: w = 0.0_pReal + real(pReal) :: x = 0.0_pReal + real(pReal) :: y = 0.0_pReal + real(pReal) :: z = 0.0_pReal - procedure, private :: mul_quat__ - procedure, private :: mul_scal__ - generic, public :: operator(*) => mul_quat__, mul_scal__ - procedure, private :: div_quat__ - procedure, private :: div_scal__ - generic, public :: operator(/) => div_quat__, div_scal__ + contains + procedure, private :: add__ + procedure, private :: pos__ + generic, public :: operator(+) => add__,pos__ - procedure, private :: eq__ - generic, public :: operator(==) => eq__ + procedure, private :: sub__ + procedure, private :: neg__ + generic, public :: operator(-) => sub__,neg__ - procedure, private :: neq__ - generic, public :: operator(/=) => neq__ + procedure, private :: mul_quat__ + procedure, private :: mul_scal__ + generic, public :: operator(*) => mul_quat__, mul_scal__ - procedure, private :: pow_quat__ - procedure, private :: pow_scal__ - generic, public :: operator(**) => pow_quat__, pow_scal__ + procedure, private :: div_quat__ + procedure, private :: div_scal__ + generic, public :: operator(/) => div_quat__, div_scal__ - procedure, public :: abs__ - procedure, public :: dot_product__ - procedure, public :: conjg__ - procedure, public :: exp__ - procedure, public :: log__ + procedure, private :: eq__ + generic, public :: operator(==) => eq__ - procedure, public :: homomorphed => quat_homomorphed + procedure, private :: neq__ + generic, public :: operator(/=) => neq__ - end type + procedure, private :: pow_quat__ + procedure, private :: pow_scal__ + generic, public :: operator(**) => pow_quat__, pow_scal__ + + procedure, public :: abs__ + procedure, public :: dot_product__ + procedure, public :: conjg__ + procedure, public :: exp__ + procedure, public :: log__ + + procedure, public :: homomorphed => quat_homomorphed + + end type interface assignment (=) module procedure assign_quat__ @@ -123,12 +123,12 @@ contains !--------------------------------------------------------------------------------------------------- type(quaternion) pure function init__(array) - real(pReal), intent(in), dimension(4) :: array - - init__%w=array(1) - init__%x=array(2) - init__%y=array(3) - init__%z=array(4) + real(pReal), intent(in), dimension(4) :: array + + init__%w=array(1) + init__%x=array(2) + init__%y=array(3) + init__%z=array(4) end function init__ @@ -138,14 +138,14 @@ end function init__ !--------------------------------------------------------------------------------------------------- elemental subroutine assign_quat__(self,other) - type(quaternion), intent(out) :: self - type(quaternion), intent(in) :: other - - self%w = other%w - self%x = other%x - self%y = other%y - self%z = other%z - + type(quaternion), intent(out) :: self + type(quaternion), intent(in) :: other + + self%w = other%w + self%x = other%x + self%y = other%y + self%z = other%z + end subroutine assign_quat__ @@ -154,14 +154,14 @@ end subroutine assign_quat__ !--------------------------------------------------------------------------------------------------- pure subroutine assign_vec__(self,other) - type(quaternion), intent(out) :: self - real(pReal), intent(in), dimension(4) :: other - - self%w = other(1) - self%x = other(2) - self%y = other(3) - self%z = other(4) - + type(quaternion), intent(out) :: self + real(pReal), intent(in), dimension(4) :: other + + self%w = other(1) + self%x = other(2) + self%y = other(3) + self%z = other(4) + end subroutine assign_vec__ @@ -170,13 +170,13 @@ end subroutine assign_vec__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function add__(self,other) - class(quaternion), intent(in) :: self,other - - add__%w = self%w + other%w - add__%x = self%x + other%x - add__%y = self%y + other%y - add__%z = self%z + other%z - + class(quaternion), intent(in) :: self,other + + add__%w = self%w + other%w + add__%x = self%x + other%x + add__%y = self%y + other%y + add__%z = self%z + other%z + end function add__ @@ -185,13 +185,13 @@ end function add__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function pos__(self) - class(quaternion), intent(in) :: self - - pos__%w = self%w - pos__%x = self%x - pos__%y = self%y - pos__%z = self%z - + class(quaternion), intent(in) :: self + + pos__%w = self%w + pos__%x = self%x + pos__%y = self%y + pos__%z = self%z + end function pos__ @@ -200,13 +200,13 @@ end function pos__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function sub__(self,other) - class(quaternion), intent(in) :: self,other - - sub__%w = self%w - other%w - sub__%x = self%x - other%x - sub__%y = self%y - other%y - sub__%z = self%z - other%z - + class(quaternion), intent(in) :: self,other + + sub__%w = self%w - other%w + sub__%x = self%x - other%x + sub__%y = self%y - other%y + sub__%z = self%z - other%z + end function sub__ @@ -215,13 +215,13 @@ end function sub__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function neg__(self) - class(quaternion), intent(in) :: self - - neg__%w = -self%w - neg__%x = -self%x - neg__%y = -self%y - neg__%z = -self%z - + class(quaternion), intent(in) :: self + + neg__%w = -self%w + neg__%x = -self%x + neg__%y = -self%y + neg__%z = -self%z + end function neg__ @@ -230,13 +230,13 @@ end function neg__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function mul_quat__(self,other) - class(quaternion), intent(in) :: self, other + class(quaternion), intent(in) :: self, other + + mul_quat__%w = self%w*other%w - self%x*other%x - self%y*other%y - self%z*other%z + mul_quat__%x = self%w*other%x + self%x*other%w + P * (self%y*other%z - self%z*other%y) + mul_quat__%y = self%w*other%y + self%y*other%w + P * (self%z*other%x - self%x*other%z) + mul_quat__%z = self%w*other%z + self%z*other%w + P * (self%x*other%y - self%y*other%x) - mul_quat__%w = self%w*other%w - self%x*other%x - self%y*other%y - self%z*other%z - mul_quat__%x = self%w*other%x + self%x*other%w + P * (self%y*other%z - self%z*other%y) - mul_quat__%y = self%w*other%y + self%y*other%w + P * (self%z*other%x - self%x*other%z) - mul_quat__%z = self%w*other%z + self%z*other%w + P * (self%x*other%y - self%y*other%x) - end function mul_quat__ @@ -245,14 +245,14 @@ end function mul_quat__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function mul_scal__(self,scal) - class(quaternion), intent(in) :: self - real(pReal), intent(in) :: scal + class(quaternion), intent(in) :: self + real(pReal), intent(in) :: scal + + mul_scal__%w = self%w*scal + mul_scal__%x = self%x*scal + mul_scal__%y = self%y*scal + mul_scal__%z = self%z*scal - mul_scal__%w = self%w*scal - mul_scal__%x = self%x*scal - mul_scal__%y = self%y*scal - mul_scal__%z = self%z*scal - end function mul_scal__ @@ -261,9 +261,9 @@ end function mul_scal__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function div_quat__(self,other) - class(quaternion), intent(in) :: self, other + class(quaternion), intent(in) :: self, other - div_quat__ = self * (conjg(other)/(abs(other)**2.0_pReal)) + div_quat__ = self * (conjg(other)/(abs(other)**2.0_pReal)) end function div_quat__ @@ -273,10 +273,10 @@ end function div_quat__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function div_scal__(self,scal) - class(quaternion), intent(in) :: self - real(pReal), intent(in) :: scal + class(quaternion), intent(in) :: self + real(pReal), intent(in) :: scal - div_scal__ = [self%w,self%x,self%y,self%z]/scal + div_scal__ = [self%w,self%x,self%y,self%z]/scal end function div_scal__ @@ -286,11 +286,11 @@ end function div_scal__ !--------------------------------------------------------------------------------------------------- logical elemental function eq__(self,other) - class(quaternion), intent(in) :: self,other + class(quaternion), intent(in) :: self,other + + eq__ = all(dEq([ self%w, self%x, self%y, self%z], & + [other%w,other%x,other%y,other%z])) - eq__ = all(dEq([ self%w, self%x, self%y, self%z], & - [other%w,other%x,other%y,other%z])) - end function eq__ @@ -299,10 +299,10 @@ end function eq__ !--------------------------------------------------------------------------------------------------- logical elemental function neq__(self,other) - class(quaternion), intent(in) :: self,other + class(quaternion), intent(in) :: self,other + + neq__ = .not. self%eq__(other) - neq__ = .not. self%eq__(other) - end function neq__ @@ -311,11 +311,11 @@ end function neq__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function pow_scal__(self,expon) - class(quaternion), intent(in) :: self - real(pReal), intent(in) :: expon - - pow_scal__ = exp(log(self)*expon) - + class(quaternion), intent(in) :: self + real(pReal), intent(in) :: expon + + pow_scal__ = exp(log(self)*expon) + end function pow_scal__ @@ -324,11 +324,11 @@ end function pow_scal__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function pow_quat__(self,expon) - class(quaternion), intent(in) :: self - type(quaternion), intent(in) :: expon - - pow_quat__ = exp(log(self)*expon) - + class(quaternion), intent(in) :: self + type(quaternion), intent(in) :: expon + + pow_quat__ = exp(log(self)*expon) + end function pow_quat__ @@ -338,15 +338,15 @@ end function pow_quat__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function exp__(self) - class(quaternion), intent(in) :: self - real(pReal) :: absImag + class(quaternion), intent(in) :: self + real(pReal) :: absImag - absImag = norm2([self%x, self%y, self%z]) + absImag = norm2([self%x, self%y, self%z]) - exp__ = exp(self%w) * [ cos(absImag), & - self%x/absImag * sin(absImag), & - self%y/absImag * sin(absImag), & - self%z/absImag * sin(absImag)] + exp__ = exp(self%w) * [ cos(absImag), & + self%x/absImag * sin(absImag), & + self%y/absImag * sin(absImag), & + self%z/absImag * sin(absImag)] end function exp__ @@ -357,16 +357,16 @@ end function exp__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function log__(self) - class(quaternion), intent(in) :: self - real(pReal) :: absImag + class(quaternion), intent(in) :: self + real(pReal) :: absImag - absImag = norm2([self%x, self%y, self%z]) + absImag = norm2([self%x, self%y, self%z]) + + log__ = [log(abs(self)), & + self%x/absImag * acos(self%w/abs(self)), & + self%y/absImag * acos(self%w/abs(self)), & + self%z/absImag * acos(self%w/abs(self))] - log__ = [log(abs(self)), & - self%x/absImag * acos(self%w/abs(self)), & - self%y/absImag * acos(self%w/abs(self)), & - self%z/absImag * acos(self%w/abs(self))] - end function log__ @@ -375,10 +375,10 @@ end function log__ !--------------------------------------------------------------------------------------------------- real(pReal) elemental function abs__(a) - class(quaternion), intent(in) :: a + class(quaternion), intent(in) :: a + + abs__ = norm2([a%w,a%x,a%y,a%z]) - abs__ = norm2([a%w,a%x,a%y,a%z]) - end function abs__ @@ -387,10 +387,10 @@ end function abs__ !--------------------------------------------------------------------------------------------------- real(pReal) elemental function dot_product__(a,b) - class(quaternion), intent(in) :: a,b + class(quaternion), intent(in) :: a,b + + dot_product__ = a%w*b%w + a%x*b%x + a%y*b%y + a%z*b%z - dot_product__ = a%w*b%w + a%x*b%x + a%y*b%y + a%z*b%z - end function dot_product__ @@ -399,10 +399,10 @@ end function dot_product__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function conjg__(a) - class(quaternion), intent(in) :: a + class(quaternion), intent(in) :: a + + conjg__ = quaternion([a%w, -a%x, -a%y, -a%z]) - conjg__ = quaternion([a%w, -a%x, -a%y, -a%z]) - end function conjg__ @@ -411,10 +411,10 @@ end function conjg__ !--------------------------------------------------------------------------------------------------- type(quaternion) elemental function quat_homomorphed(a) - class(quaternion), intent(in) :: a + class(quaternion), intent(in) :: a + + quat_homomorphed = quaternion(-[a%w,a%x,a%y,a%z]) - quat_homomorphed = quaternion(-[a%w,a%x,a%y,a%z]) - end function quat_homomorphed end module quaternions From a5c6e4b17c21337dde6966ecf4dc2e1d5d176bc0 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 28 May 2019 12:06:21 +0200 Subject: [PATCH 064/120] do not clutter the code with use statements --- src/DAMASK_interface.f90 | 7 +- src/HDF5_utilities.f90 | 10 +- src/damage_nonlocal.f90 | 399 ++++++++++++------------ src/homogenization.f90 | 24 +- src/kinematics_cleavage_opening.f90 | 298 +++++++++--------- src/list.f90 | 34 +- src/results.f90 | 16 +- src/source_damage_anisoBrittle.f90 | 465 +++++++++++++--------------- src/source_thermal_dissipation.f90 | 34 +- src/source_thermal_externalheat.f90 | 31 +- src/thermal_adiabatic.f90 | 77 +---- 11 files changed, 614 insertions(+), 781 deletions(-) diff --git a/src/DAMASK_interface.f90 b/src/DAMASK_interface.f90 index b76813fe6..cb13bfaea 100644 --- a/src/DAMASK_interface.f90 +++ b/src/DAMASK_interface.f90 @@ -14,7 +14,11 @@ #define PETSC_MAJOR 3 #define PETSC_MINOR_MIN 10 #define PETSC_MINOR_MAX 11 + module DAMASK_interface + use, intrinsic :: iso_fortran_env + use PETScSys + use prec use system_routines @@ -50,9 +54,6 @@ contains !! information on computation to screen !-------------------------------------------------------------------------------------------------- subroutine DAMASK_interface_init - use, intrinsic :: iso_fortran_env - use PETScSys - #include #if defined(__GFORTRAN__) && __GNUC__ @details to be done !-------------------------------------------------------------------------------------------------- module damage_nonlocal - use prec - use material - use numerics - use config - use crystallite - use lattice - use mesh + use prec + use material + use numerics + use config + use crystallite + use lattice + use mesh + use source_damage_isoBrittle + use source_damage_isoDuctile + use source_damage_anisoBrittle + use source_damage_anisoDuctile - implicit none - private - - integer, dimension(:,:), allocatable, target, public :: & - damage_nonlocal_sizePostResult !< size of each post result output + implicit none + private + + integer, dimension(:,:), allocatable, target, public :: & + damage_nonlocal_sizePostResult !< size of each post result output - character(len=64), dimension(:,:), allocatable, target, public :: & - damage_nonlocal_output !< name of each post result output - - integer, dimension(:), allocatable, target, public :: & - damage_nonlocal_Noutput !< number of outputs per instance of this damage + character(len=64), dimension(:,:), allocatable, target, public :: & + damage_nonlocal_output !< name of each post result output + + integer, dimension(:), allocatable, target, public :: & + damage_nonlocal_Noutput !< number of outputs per instance of this damage - enum, bind(c) - enumerator :: undefined_ID, & - damage_ID - end enum + enum, bind(c) + enumerator :: undefined_ID, & + damage_ID + end enum - type :: tParameters - integer(kind(undefined_ID)), dimension(:), allocatable :: & - outputID - end type tParameters - - type(tparameters), dimension(:), allocatable :: & - param + type :: tParameters + integer(kind(undefined_ID)), dimension(:), allocatable :: & + outputID + end type tParameters + + type(tparameters), dimension(:), allocatable :: & + param - public :: & - damage_nonlocal_init, & - damage_nonlocal_getSourceAndItsTangent, & - damage_nonlocal_getDiffusion33, & - damage_nonlocal_getMobility, & - damage_nonlocal_putNonLocalDamage, & - damage_nonlocal_postResults + public :: & + damage_nonlocal_init, & + damage_nonlocal_getSourceAndItsTangent, & + damage_nonlocal_getDiffusion33, & + damage_nonlocal_getMobility, & + damage_nonlocal_putNonLocalDamage, & + damage_nonlocal_postResults contains @@ -53,129 +57,122 @@ contains !-------------------------------------------------------------------------------------------------- subroutine damage_nonlocal_init - integer :: maxNinstance,homog,instance,o,i - integer :: sizeState - integer :: NofMyHomog, h - integer(kind(undefined_ID)) :: & - outputID - character(len=65536), dimension(0), parameter :: emptyStringArray = [character(len=65536)::] - character(len=65536), dimension(:), allocatable :: & - outputs + integer :: maxNinstance,homog,instance,o,i + integer :: sizeState + integer :: NofMyHomog, h + integer(kind(undefined_ID)) :: & + outputID + character(len=65536), dimension(0), parameter :: emptyStringArray = [character(len=65536)::] + character(len=65536), dimension(:), allocatable :: & + outputs - write(6,'(/,a)') ' <<<+- damage_'//DAMAGE_nonlocal_label//' init -+>>>' - - maxNinstance = count(damage_type == DAMAGE_nonlocal_ID) - if (maxNinstance == 0) return - - allocate(damage_nonlocal_sizePostResult (maxval(homogenization_Noutput),maxNinstance),source=0) - allocate(damage_nonlocal_output (maxval(homogenization_Noutput),maxNinstance)) - damage_nonlocal_output = '' - allocate(damage_nonlocal_Noutput (maxNinstance), source=0) - - allocate(param(maxNinstance)) + write(6,'(/,a)') ' <<<+- damage_'//DAMAGE_nonlocal_label//' init -+>>>' - do h = 1, size(damage_type) - if (damage_type(h) /= DAMAGE_NONLOCAL_ID) cycle - associate(prm => param(damage_typeInstance(h)), & - config => config_homogenization(h)) - - instance = damage_typeInstance(h) - outputs = config%getStrings('(output)',defaultVal=emptyStringArray) - allocate(prm%outputID(0)) + maxNinstance = count(damage_type == DAMAGE_nonlocal_ID) + if (maxNinstance == 0) return + + allocate(damage_nonlocal_sizePostResult (maxval(homogenization_Noutput),maxNinstance),source=0) + allocate(damage_nonlocal_output (maxval(homogenization_Noutput),maxNinstance)) + damage_nonlocal_output = '' + allocate(damage_nonlocal_Noutput (maxNinstance), source=0) + + allocate(param(maxNinstance)) - do i=1, size(outputs) - outputID = undefined_ID - select case(outputs(i)) - - case ('damage') - damage_nonlocal_output(i,damage_typeInstance(h)) = outputs(i) - damage_nonlocal_Noutput(instance) = damage_nonlocal_Noutput(instance) + 1 - damage_nonlocal_sizePostResult(i,damage_typeInstance(h)) = 1 - prm%outputID = [prm%outputID , damage_ID] - end select - - enddo + do h = 1, size(damage_type) + if (damage_type(h) /= DAMAGE_NONLOCAL_ID) cycle + associate(prm => param(damage_typeInstance(h)), & + config => config_homogenization(h)) + + instance = damage_typeInstance(h) + outputs = config%getStrings('(output)',defaultVal=emptyStringArray) + allocate(prm%outputID(0)) + + do i=1, size(outputs) + outputID = undefined_ID + select case(outputs(i)) + + case ('damage') + damage_nonlocal_output(i,damage_typeInstance(h)) = outputs(i) + damage_nonlocal_Noutput(instance) = damage_nonlocal_Noutput(instance) + 1 + damage_nonlocal_sizePostResult(i,damage_typeInstance(h)) = 1 + prm%outputID = [prm%outputID , damage_ID] + end select + + enddo - homog = h + homog = h - NofMyHomog = count(material_homogenizationAt == homog) - instance = damage_typeInstance(homog) + NofMyHomog = count(material_homogenizationAt == homog) + instance = damage_typeInstance(homog) -! allocate state arrays - sizeState = 1 - damageState(homog)%sizeState = sizeState - damageState(homog)%sizePostResults = sum(damage_nonlocal_sizePostResult(:,instance)) - allocate(damageState(homog)%state0 (sizeState,NofMyHomog), source=damage_initialPhi(homog)) - allocate(damageState(homog)%subState0(sizeState,NofMyHomog), source=damage_initialPhi(homog)) - allocate(damageState(homog)%state (sizeState,NofMyHomog), source=damage_initialPhi(homog)) +! allocate state arrays + sizeState = 1 + damageState(homog)%sizeState = sizeState + damageState(homog)%sizePostResults = sum(damage_nonlocal_sizePostResult(:,instance)) + allocate(damageState(homog)%state0 (sizeState,NofMyHomog), source=damage_initialPhi(homog)) + allocate(damageState(homog)%subState0(sizeState,NofMyHomog), source=damage_initialPhi(homog)) + allocate(damageState(homog)%state (sizeState,NofMyHomog), source=damage_initialPhi(homog)) - nullify(damageMapping(homog)%p) - damageMapping(homog)%p => mappingHomogenization(1,:,:) - deallocate(damage(homog)%p) - damage(homog)%p => damageState(homog)%state(1,:) - - end associate - enddo + nullify(damageMapping(homog)%p) + damageMapping(homog)%p => mappingHomogenization(1,:,:) + deallocate(damage(homog)%p) + damage(homog)%p => damageState(homog)%state(1,:) + + end associate + enddo end subroutine damage_nonlocal_init + !-------------------------------------------------------------------------------------------------- !> @brief calculates homogenized damage driving forces !-------------------------------------------------------------------------------------------------- subroutine damage_nonlocal_getSourceAndItsTangent(phiDot, dPhiDot_dPhi, phi, ip, el) - use source_damage_isoBrittle, only: & - source_damage_isobrittle_getRateAndItsTangent - use source_damage_isoDuctile, only: & - source_damage_isoductile_getRateAndItsTangent - use source_damage_anisoBrittle, only: & - source_damage_anisobrittle_getRateAndItsTangent - use source_damage_anisoDuctile, only: & - source_damage_anisoductile_getRateAndItsTangent - integer, intent(in) :: & - ip, & !< integration point number - el !< element number - real(pReal), intent(in) :: & - phi - integer :: & - phase, & - grain, & - source, & - constituent - real(pReal) :: & - phiDot, dPhiDot_dPhi, localphiDot, dLocalphiDot_dPhi + integer, intent(in) :: & + ip, & !< integration point number + el !< element number + real(pReal), intent(in) :: & + phi + integer :: & + phase, & + grain, & + source, & + constituent + real(pReal) :: & + phiDot, dPhiDot_dPhi, localphiDot, dLocalphiDot_dPhi - phiDot = 0.0_pReal - dPhiDot_dPhi = 0.0_pReal - do grain = 1, homogenization_Ngrains(material_homogenizationAt(el)) - phase = phaseAt(grain,ip,el) - constituent = phasememberAt(grain,ip,el) - do source = 1, phase_Nsources(phase) - select case(phase_source(source,phase)) - case (SOURCE_damage_isoBrittle_ID) - call source_damage_isobrittle_getRateAndItsTangent (localphiDot, dLocalphiDot_dPhi, phi, phase, constituent) + phiDot = 0.0_pReal + dPhiDot_dPhi = 0.0_pReal + do grain = 1, homogenization_Ngrains(material_homogenizationAt(el)) + phase = phaseAt(grain,ip,el) + constituent = phasememberAt(grain,ip,el) + do source = 1, phase_Nsources(phase) + select case(phase_source(source,phase)) + case (SOURCE_damage_isoBrittle_ID) + call source_damage_isobrittle_getRateAndItsTangent (localphiDot, dLocalphiDot_dPhi, phi, phase, constituent) - case (SOURCE_damage_isoDuctile_ID) - call source_damage_isoductile_getRateAndItsTangent (localphiDot, dLocalphiDot_dPhi, phi, phase, constituent) + case (SOURCE_damage_isoDuctile_ID) + call source_damage_isoductile_getRateAndItsTangent (localphiDot, dLocalphiDot_dPhi, phi, phase, constituent) - case (SOURCE_damage_anisoBrittle_ID) - call source_damage_anisobrittle_getRateAndItsTangent(localphiDot, dLocalphiDot_dPhi, phi, phase, constituent) + case (SOURCE_damage_anisoBrittle_ID) + call source_damage_anisobrittle_getRateAndItsTangent(localphiDot, dLocalphiDot_dPhi, phi, phase, constituent) - case (SOURCE_damage_anisoDuctile_ID) - call source_damage_anisoductile_getRateAndItsTangent(localphiDot, dLocalphiDot_dPhi, phi, phase, constituent) + case (SOURCE_damage_anisoDuctile_ID) + call source_damage_anisoductile_getRateAndItsTangent(localphiDot, dLocalphiDot_dPhi, phi, phase, constituent) - case default - localphiDot = 0.0_pReal - dLocalphiDot_dPhi = 0.0_pReal + case default + localphiDot = 0.0_pReal + dLocalphiDot_dPhi = 0.0_pReal - end select - phiDot = phiDot + localphiDot - dPhiDot_dPhi = dPhiDot_dPhi + dLocalphiDot_dPhi - enddo - enddo - - phiDot = phiDot/real(homogenization_Ngrains(material_homogenizationAt(el)),pReal) - dPhiDot_dPhi = dPhiDot_dPhi/real(homogenization_Ngrains(material_homogenizationAt(el)),pReal) + end select + phiDot = phiDot + localphiDot + dPhiDot_dPhi = dPhiDot_dPhi + dLocalphiDot_dPhi + enddo + enddo + + phiDot = phiDot/real(homogenization_Ngrains(material_homogenizationAt(el)),pReal) + dPhiDot_dPhi = dPhiDot_dPhi/real(homogenization_Ngrains(material_homogenizationAt(el)),pReal) end subroutine damage_nonlocal_getSourceAndItsTangent @@ -185,24 +182,24 @@ end subroutine damage_nonlocal_getSourceAndItsTangent !-------------------------------------------------------------------------------------------------- function damage_nonlocal_getDiffusion33(ip,el) - integer, intent(in) :: & - ip, & !< integration point number - el !< element number - real(pReal), dimension(3,3) :: & - damage_nonlocal_getDiffusion33 - integer :: & - homog, & - grain - - homog = material_homogenizationAt(el) - damage_nonlocal_getDiffusion33 = 0.0_pReal - do grain = 1, homogenization_Ngrains(homog) - damage_nonlocal_getDiffusion33 = damage_nonlocal_getDiffusion33 + & - crystallite_push33ToRef(grain,ip,el,lattice_DamageDiffusion33(1:3,1:3,material_phase(grain,ip,el))) - enddo + integer, intent(in) :: & + ip, & !< integration point number + el !< element number + real(pReal), dimension(3,3) :: & + damage_nonlocal_getDiffusion33 + integer :: & + homog, & + grain + + homog = material_homogenizationAt(el) + damage_nonlocal_getDiffusion33 = 0.0_pReal + do grain = 1, homogenization_Ngrains(homog) + damage_nonlocal_getDiffusion33 = damage_nonlocal_getDiffusion33 + & + crystallite_push33ToRef(grain,ip,el,lattice_DamageDiffusion33(1:3,1:3,material_phase(grain,ip,el))) + enddo - damage_nonlocal_getDiffusion33 = & - charLength**2*damage_nonlocal_getDiffusion33/real(homogenization_Ngrains(homog),pReal) + damage_nonlocal_getDiffusion33 = & + charLength**2*damage_nonlocal_getDiffusion33/real(homogenization_Ngrains(homog),pReal) end function damage_nonlocal_getDiffusion33 @@ -212,20 +209,20 @@ end function damage_nonlocal_getDiffusion33 !-------------------------------------------------------------------------------------------------- real(pReal) function damage_nonlocal_getMobility(ip,el) - integer, intent(in) :: & - ip, & !< integration point number - el !< element number - integer :: & - ipc - - damage_nonlocal_getMobility = 0.0_pReal - - do ipc = 1, homogenization_Ngrains(mesh_element(3,el)) - damage_nonlocal_getMobility = damage_nonlocal_getMobility + lattice_DamageMobility(material_phase(ipc,ip,el)) - enddo + integer, intent(in) :: & + ip, & !< integration point number + el !< element number + integer :: & + ipc + + damage_nonlocal_getMobility = 0.0_pReal + + do ipc = 1, homogenization_Ngrains(mesh_element(3,el)) + damage_nonlocal_getMobility = damage_nonlocal_getMobility + lattice_DamageMobility(material_phase(ipc,ip,el)) + enddo - damage_nonlocal_getMobility = damage_nonlocal_getMobility/& - real(homogenization_Ngrains(mesh_element(3,el)),pReal) + damage_nonlocal_getMobility = damage_nonlocal_getMobility/& + real(homogenization_Ngrains(mesh_element(3,el)),pReal) end function damage_nonlocal_getMobility @@ -235,18 +232,18 @@ end function damage_nonlocal_getMobility !-------------------------------------------------------------------------------------------------- subroutine damage_nonlocal_putNonLocalDamage(phi,ip,el) - integer, intent(in) :: & - ip, & !< integration point number - el !< element number - real(pReal), intent(in) :: & - phi - integer :: & - homog, & - offset - - homog = material_homogenizationAt(el) - offset = damageMapping(homog)%p(ip,el) - damage(homog)%p(offset) = phi + integer, intent(in) :: & + ip, & !< integration point number + el !< element number + real(pReal), intent(in) :: & + phi + integer :: & + homog, & + offset + + homog = material_homogenizationAt(el) + offset = damageMapping(homog)%p(ip,el) + damage(homog)%p(offset) = phi end subroutine damage_nonlocal_putNonLocalDamage @@ -256,31 +253,31 @@ end subroutine damage_nonlocal_putNonLocalDamage !-------------------------------------------------------------------------------------------------- function damage_nonlocal_postResults(ip,el) - integer, intent(in) :: & - ip, & !< integration point - el !< element - real(pReal), dimension(sum(damage_nonlocal_sizePostResult(:,damage_typeInstance(material_homogenizationAt(el))))) :: & - damage_nonlocal_postResults + integer, intent(in) :: & + ip, & !< integration point + el !< element + real(pReal), dimension(sum(damage_nonlocal_sizePostResult(:,damage_typeInstance(material_homogenizationAt(el))))) :: & + damage_nonlocal_postResults - integer :: & - instance, homog, offset, o, c - - homog = material_homogenizationAt(el) - offset = damageMapping(homog)%p(ip,el) - instance = damage_typeInstance(homog) - associate(prm => param(instance)) - c = 0 + integer :: & + instance, homog, offset, o, c + + homog = material_homogenizationAt(el) + offset = damageMapping(homog)%p(ip,el) + instance = damage_typeInstance(homog) + associate(prm => param(instance)) + c = 0 - outputsLoop: do o = 1,size(prm%outputID) - select case(prm%outputID(o)) - - case (damage_ID) - damage_nonlocal_postResults(c+1) = damage(homog)%p(offset) - c = c + 1 - end select - enddo outputsLoop + outputsLoop: do o = 1,size(prm%outputID) + select case(prm%outputID(o)) + + case (damage_ID) + damage_nonlocal_postResults(c+1) = damage(homog)%p(offset) + c = c + 1 + end select + enddo outputsLoop - end associate + end associate end function damage_nonlocal_postResults end module damage_nonlocal diff --git a/src/homogenization.f90 b/src/homogenization.f90 index 3210f02d4..9287cc4bf 100644 --- a/src/homogenization.f90 +++ b/src/homogenization.f90 @@ -16,6 +16,12 @@ module homogenization use crystallite use mesh use FEsolving + use thermal_isothermal + use thermal_adiabatic + use thermal_conduction + use damage_none + use damage_local + use damage_nonlocal #if defined(PETSc) || defined(DAMASK_HDF5) use results use HDF5_utilities @@ -131,12 +137,6 @@ contains !> @brief module initialization !-------------------------------------------------------------------------------------------------- subroutine homogenization_init - use thermal_isothermal - use thermal_adiabatic - use thermal_conduction - use damage_none - use damage_local - use damage_nonlocal integer, parameter :: FILEUNIT = 200 integer :: e,i,p @@ -668,10 +668,6 @@ end subroutine partitionDeformation !> "happy" with result !-------------------------------------------------------------------------------------------------- function updateState(ip,el) - use thermal_adiabatic, only: & - thermal_adiabatic_updateState - use damage_local, only: & - damage_local_updateState integer, intent(in) :: & ip, & !< integration point @@ -753,14 +749,6 @@ end subroutine averageStressAndItsTangent !> if homogenization_sizePostResults(i,e) > 0 !! !-------------------------------------------------------------------------------------------------- function postResults(ip,el) - use thermal_adiabatic, only: & - thermal_adiabatic_postResults - use thermal_conduction, only: & - thermal_conduction_postResults - use damage_local, only: & - damage_local_postResults - use damage_nonlocal, only: & - damage_nonlocal_postResults integer, intent(in) :: & ip, & !< integration point diff --git a/src/kinematics_cleavage_opening.f90 b/src/kinematics_cleavage_opening.f90 index 60d9cb500..39bfbf340 100644 --- a/src/kinematics_cleavage_opening.f90 +++ b/src/kinematics_cleavage_opening.f90 @@ -13,43 +13,43 @@ module kinematics_cleavage_opening use lattice use material - implicit none - private + implicit none + private - integer, dimension(:), allocatable :: kinematics_cleavage_opening_instance + integer, dimension(:), allocatable :: kinematics_cleavage_opening_instance - type :: tParameters !< container type for internal constitutive parameters - integer :: & - totalNcleavage - integer, dimension(:), allocatable :: & - Ncleavage !< active number of cleavage systems per family - real(pReal) :: & - sdot0, & - n - real(pReal), dimension(:), allocatable :: & - critDisp, & - critLoad - end type + type :: tParameters !< container type for internal constitutive parameters + integer :: & + totalNcleavage + integer, dimension(:), allocatable :: & + Ncleavage !< active number of cleavage systems per family + real(pReal) :: & + sdot0, & + n + real(pReal), dimension(:), allocatable :: & + critDisp, & + critLoad + end type ! Begin Deprecated - integer, dimension(:), allocatable :: & - kinematics_cleavage_opening_totalNcleavage !< total number of cleavage systems - - integer, dimension(:,:), allocatable :: & - kinematics_cleavage_opening_Ncleavage !< number of cleavage systems per family - - real(pReal), dimension(:), allocatable :: & - kinematics_cleavage_opening_sdot_0, & - kinematics_cleavage_opening_N + integer, dimension(:), allocatable :: & + kinematics_cleavage_opening_totalNcleavage !< total number of cleavage systems + + integer, dimension(:,:), allocatable :: & + kinematics_cleavage_opening_Ncleavage !< number of cleavage systems per family + + real(pReal), dimension(:), allocatable :: & + kinematics_cleavage_opening_sdot_0, & + kinematics_cleavage_opening_N - real(pReal), dimension(:,:), allocatable :: & - kinematics_cleavage_opening_critDisp, & - kinematics_cleavage_opening_critLoad + real(pReal), dimension(:,:), allocatable :: & + kinematics_cleavage_opening_critDisp, & + kinematics_cleavage_opening_critLoad ! End Deprecated - public :: & - kinematics_cleavage_opening_init, & - kinematics_cleavage_opening_LiAndItsTangent + public :: & + kinematics_cleavage_opening_init, & + kinematics_cleavage_opening_LiAndItsTangent contains @@ -60,142 +60,142 @@ contains !-------------------------------------------------------------------------------------------------- subroutine kinematics_cleavage_opening_init - integer, allocatable, dimension(:) :: tempInt - real(pReal), allocatable, dimension(:) :: tempFloat + integer, allocatable, dimension(:) :: tempInt + real(pReal), allocatable, dimension(:) :: tempFloat - integer :: maxNinstance,p,instance + integer :: maxNinstance,p,instance - write(6,'(/,a)') ' <<<+- kinematics_'//KINEMATICS_cleavage_opening_LABEL//' init -+>>>' + write(6,'(/,a)') ' <<<+- kinematics_'//KINEMATICS_cleavage_opening_LABEL//' init -+>>>' - maxNinstance = count(phase_kinematics == KINEMATICS_cleavage_opening_ID) - if (maxNinstance == 0) return - - if (iand(debug_level(debug_constitutive),debug_levelBasic) /= 0) & - write(6,'(a16,1x,i5,/)') '# instances:',maxNinstance - - allocate(kinematics_cleavage_opening_instance(size(config_phase)), source=0) - do p = 1, size(config_phase) - kinematics_cleavage_opening_instance(p) = count(phase_kinematics(:,1:p) == kinematics_cleavage_opening_ID) ! ToDo: count correct? - enddo - - allocate(kinematics_cleavage_opening_critDisp(lattice_maxNcleavageFamily,maxNinstance), source=0.0_pReal) - allocate(kinematics_cleavage_opening_critLoad(lattice_maxNcleavageFamily,maxNinstance), source=0.0_pReal) - allocate(kinematics_cleavage_opening_Ncleavage(lattice_maxNcleavageFamily,maxNinstance), source=0) - allocate(kinematics_cleavage_opening_totalNcleavage(maxNinstance), source=0) - allocate(kinematics_cleavage_opening_sdot_0(maxNinstance), source=0.0_pReal) - allocate(kinematics_cleavage_opening_N(maxNinstance), source=0.0_pReal) + maxNinstance = count(phase_kinematics == KINEMATICS_cleavage_opening_ID) + if (maxNinstance == 0) return + + if (iand(debug_level(debug_constitutive),debug_levelBasic) /= 0) & + write(6,'(a16,1x,i5,/)') '# instances:',maxNinstance + + allocate(kinematics_cleavage_opening_instance(size(config_phase)), source=0) + do p = 1, size(config_phase) + kinematics_cleavage_opening_instance(p) = count(phase_kinematics(:,1:p) == kinematics_cleavage_opening_ID) ! ToDo: count correct? + enddo + + allocate(kinematics_cleavage_opening_critDisp(lattice_maxNcleavageFamily,maxNinstance), source=0.0_pReal) + allocate(kinematics_cleavage_opening_critLoad(lattice_maxNcleavageFamily,maxNinstance), source=0.0_pReal) + allocate(kinematics_cleavage_opening_Ncleavage(lattice_maxNcleavageFamily,maxNinstance), source=0) + allocate(kinematics_cleavage_opening_totalNcleavage(maxNinstance), source=0) + allocate(kinematics_cleavage_opening_sdot_0(maxNinstance), source=0.0_pReal) + allocate(kinematics_cleavage_opening_N(maxNinstance), source=0.0_pReal) - do p = 1, size(config_phase) - if (all(phase_kinematics(:,p) /= KINEMATICS_cleavage_opening_ID)) cycle - instance = kinematics_cleavage_opening_instance(p) - kinematics_cleavage_opening_sdot_0(instance) = config_phase(p)%getFloat('anisobrittle_sdot0') - kinematics_cleavage_opening_N(instance) = config_phase(p)%getFloat('anisobrittle_ratesensitivity') - tempInt = config_phase(p)%getInts('ncleavage') - kinematics_cleavage_opening_Ncleavage(1:size(tempInt),instance) = tempInt + do p = 1, size(config_phase) + if (all(phase_kinematics(:,p) /= KINEMATICS_cleavage_opening_ID)) cycle + instance = kinematics_cleavage_opening_instance(p) + kinematics_cleavage_opening_sdot_0(instance) = config_phase(p)%getFloat('anisobrittle_sdot0') + kinematics_cleavage_opening_N(instance) = config_phase(p)%getFloat('anisobrittle_ratesensitivity') + tempInt = config_phase(p)%getInts('ncleavage') + kinematics_cleavage_opening_Ncleavage(1:size(tempInt),instance) = tempInt - tempFloat = config_phase(p)%getFloats('anisobrittle_criticaldisplacement',requiredSize=size(tempInt)) - kinematics_cleavage_opening_critDisp(1:size(tempInt),instance) = tempFloat + tempFloat = config_phase(p)%getFloats('anisobrittle_criticaldisplacement',requiredSize=size(tempInt)) + kinematics_cleavage_opening_critDisp(1:size(tempInt),instance) = tempFloat - tempFloat = config_phase(p)%getFloats('anisobrittle_criticalload',requiredSize=size(tempInt)) - kinematics_cleavage_opening_critLoad(1:size(tempInt),instance) = tempFloat + tempFloat = config_phase(p)%getFloats('anisobrittle_criticalload',requiredSize=size(tempInt)) + kinematics_cleavage_opening_critLoad(1:size(tempInt),instance) = tempFloat - kinematics_cleavage_opening_Ncleavage(1:lattice_maxNcleavageFamily,instance) = & - min(lattice_NcleavageSystem(1:lattice_maxNcleavageFamily,p),& ! limit active cleavage systems per family to min of available and requested - kinematics_cleavage_opening_Ncleavage(1:lattice_maxNcleavageFamily,instance)) - kinematics_cleavage_opening_totalNcleavage(instance) = sum(kinematics_cleavage_opening_Ncleavage(:,instance)) ! how many cleavage systems altogether - if (kinematics_cleavage_opening_sdot_0(instance) <= 0.0_pReal) & - call IO_error(211,el=instance,ext_msg='sdot_0 ('//KINEMATICS_cleavage_opening_LABEL//')') - if (any(kinematics_cleavage_opening_critDisp(1:size(tempInt),instance) < 0.0_pReal)) & - call IO_error(211,el=instance,ext_msg='critical_displacement ('//KINEMATICS_cleavage_opening_LABEL//')') - if (any(kinematics_cleavage_opening_critLoad(1:size(tempInt),instance) < 0.0_pReal)) & - call IO_error(211,el=instance,ext_msg='critical_load ('//KINEMATICS_cleavage_opening_LABEL//')') - if (kinematics_cleavage_opening_N(instance) <= 0.0_pReal) & - call IO_error(211,el=instance,ext_msg='rate_sensitivity ('//KINEMATICS_cleavage_opening_LABEL//')') - enddo + kinematics_cleavage_opening_Ncleavage(1:lattice_maxNcleavageFamily,instance) = & + min(lattice_NcleavageSystem(1:lattice_maxNcleavageFamily,p),& ! limit active cleavage systems per family to min of available and requested + kinematics_cleavage_opening_Ncleavage(1:lattice_maxNcleavageFamily,instance)) + kinematics_cleavage_opening_totalNcleavage(instance) = sum(kinematics_cleavage_opening_Ncleavage(:,instance)) ! how many cleavage systems altogether + if (kinematics_cleavage_opening_sdot_0(instance) <= 0.0_pReal) & + call IO_error(211,el=instance,ext_msg='sdot_0 ('//KINEMATICS_cleavage_opening_LABEL//')') + if (any(kinematics_cleavage_opening_critDisp(1:size(tempInt),instance) < 0.0_pReal)) & + call IO_error(211,el=instance,ext_msg='critical_displacement ('//KINEMATICS_cleavage_opening_LABEL//')') + if (any(kinematics_cleavage_opening_critLoad(1:size(tempInt),instance) < 0.0_pReal)) & + call IO_error(211,el=instance,ext_msg='critical_load ('//KINEMATICS_cleavage_opening_LABEL//')') + if (kinematics_cleavage_opening_N(instance) <= 0.0_pReal) & + call IO_error(211,el=instance,ext_msg='rate_sensitivity ('//KINEMATICS_cleavage_opening_LABEL//')') + enddo end subroutine kinematics_cleavage_opening_init - + !-------------------------------------------------------------------------------------------------- !> @brief contains the constitutive equation for calculating the velocity gradient !-------------------------------------------------------------------------------------------------- subroutine kinematics_cleavage_opening_LiAndItsTangent(Ld, dLd_dTstar, S, ipc, ip, el) - integer, intent(in) :: & - ipc, & !< grain number - ip, & !< integration point number - el !< element number - real(pReal), intent(in), dimension(3,3) :: & - S - real(pReal), intent(out), dimension(3,3) :: & - Ld !< damage velocity gradient - real(pReal), intent(out), dimension(3,3,3,3) :: & - dLd_dTstar !< derivative of Ld with respect to Tstar (4th-order tensor) - integer :: & - instance, phase, & - homog, damageOffset, & - f, i, index_myFamily, k, l, m, n - real(pReal) :: & - traction_d, traction_t, traction_n, traction_crit, & - udotd, dudotd_dt, udott, dudott_dt, udotn, dudotn_dt + integer, intent(in) :: & + ipc, & !< grain number + ip, & !< integration point number + el !< element number + real(pReal), intent(in), dimension(3,3) :: & + S + real(pReal), intent(out), dimension(3,3) :: & + Ld !< damage velocity gradient + real(pReal), intent(out), dimension(3,3,3,3) :: & + dLd_dTstar !< derivative of Ld with respect to Tstar (4th-order tensor) + integer :: & + instance, phase, & + homog, damageOffset, & + f, i, index_myFamily, k, l, m, n + real(pReal) :: & + traction_d, traction_t, traction_n, traction_crit, & + udotd, dudotd_dt, udott, dudott_dt, udotn, dudotn_dt - phase = material_phase(ipc,ip,el) - instance = kinematics_cleavage_opening_instance(phase) - homog = material_homogenizationAt(el) - damageOffset = damageMapping(homog)%p(ip,el) - - Ld = 0.0_pReal - dLd_dTstar = 0.0_pReal - do f = 1,lattice_maxNcleavageFamily - index_myFamily = sum(lattice_NcleavageSystem(1:f-1,phase)) ! at which index starts my family - do i = 1,kinematics_cleavage_opening_Ncleavage(f,instance) ! process each (active) cleavage system in family - traction_d = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,1,index_myFamily+i,phase)) - traction_t = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,2,index_myFamily+i,phase)) - traction_n = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,3,index_myFamily+i,phase)) - traction_crit = kinematics_cleavage_opening_critLoad(f,instance)* & - damage(homog)%p(damageOffset)*damage(homog)%p(damageOffset) - udotd = & - sign(1.0_pReal,traction_d)* & - kinematics_cleavage_opening_sdot_0(instance)* & - (max(0.0_pReal, abs(traction_d) - traction_crit)/traction_crit)**kinematics_cleavage_opening_N(instance) - if (abs(udotd) > tol_math_check) then - Ld = Ld + udotd*lattice_Scleavage(1:3,1:3,1,index_myFamily+i,phase) - dudotd_dt = sign(1.0_pReal,traction_d)*udotd*kinematics_cleavage_opening_N(instance)/ & - max(0.0_pReal, abs(traction_d) - traction_crit) - forall (k=1:3,l=1:3,m=1:3,n=1:3) & - dLd_dTstar(k,l,m,n) = dLd_dTstar(k,l,m,n) + & - dudotd_dt*lattice_Scleavage(k,l,1,index_myFamily+i,phase)* & - lattice_Scleavage(m,n,1,index_myFamily+i,phase) - endif + phase = material_phase(ipc,ip,el) + instance = kinematics_cleavage_opening_instance(phase) + homog = material_homogenizationAt(el) + damageOffset = damageMapping(homog)%p(ip,el) + + Ld = 0.0_pReal + dLd_dTstar = 0.0_pReal + do f = 1,lattice_maxNcleavageFamily + index_myFamily = sum(lattice_NcleavageSystem(1:f-1,phase)) ! at which index starts my family + do i = 1,kinematics_cleavage_opening_Ncleavage(f,instance) ! process each (active) cleavage system in family + traction_d = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,1,index_myFamily+i,phase)) + traction_t = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,2,index_myFamily+i,phase)) + traction_n = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,3,index_myFamily+i,phase)) + traction_crit = kinematics_cleavage_opening_critLoad(f,instance)* & + damage(homog)%p(damageOffset)*damage(homog)%p(damageOffset) + udotd = & + sign(1.0_pReal,traction_d)* & + kinematics_cleavage_opening_sdot_0(instance)* & + (max(0.0_pReal, abs(traction_d) - traction_crit)/traction_crit)**kinematics_cleavage_opening_N(instance) + if (abs(udotd) > tol_math_check) then + Ld = Ld + udotd*lattice_Scleavage(1:3,1:3,1,index_myFamily+i,phase) + dudotd_dt = sign(1.0_pReal,traction_d)*udotd*kinematics_cleavage_opening_N(instance)/ & + max(0.0_pReal, abs(traction_d) - traction_crit) + forall (k=1:3,l=1:3,m=1:3,n=1:3) & + dLd_dTstar(k,l,m,n) = dLd_dTstar(k,l,m,n) + & + dudotd_dt*lattice_Scleavage(k,l,1,index_myFamily+i,phase)* & + lattice_Scleavage(m,n,1,index_myFamily+i,phase) + endif - udott = & - sign(1.0_pReal,traction_t)* & - kinematics_cleavage_opening_sdot_0(instance)* & - (max(0.0_pReal, abs(traction_t) - traction_crit)/traction_crit)**kinematics_cleavage_opening_N(instance) - if (abs(udott) > tol_math_check) then - Ld = Ld + udott*lattice_Scleavage(1:3,1:3,2,index_myFamily+i,phase) - dudott_dt = sign(1.0_pReal,traction_t)*udott*kinematics_cleavage_opening_N(instance)/ & - max(0.0_pReal, abs(traction_t) - traction_crit) - forall (k=1:3,l=1:3,m=1:3,n=1:3) & - dLd_dTstar(k,l,m,n) = dLd_dTstar(k,l,m,n) + & - dudott_dt*lattice_Scleavage(k,l,2,index_myFamily+i,phase)* & - lattice_Scleavage(m,n,2,index_myFamily+i,phase) - endif + udott = & + sign(1.0_pReal,traction_t)* & + kinematics_cleavage_opening_sdot_0(instance)* & + (max(0.0_pReal, abs(traction_t) - traction_crit)/traction_crit)**kinematics_cleavage_opening_N(instance) + if (abs(udott) > tol_math_check) then + Ld = Ld + udott*lattice_Scleavage(1:3,1:3,2,index_myFamily+i,phase) + dudott_dt = sign(1.0_pReal,traction_t)*udott*kinematics_cleavage_opening_N(instance)/ & + max(0.0_pReal, abs(traction_t) - traction_crit) + forall (k=1:3,l=1:3,m=1:3,n=1:3) & + dLd_dTstar(k,l,m,n) = dLd_dTstar(k,l,m,n) + & + dudott_dt*lattice_Scleavage(k,l,2,index_myFamily+i,phase)* & + lattice_Scleavage(m,n,2,index_myFamily+i,phase) + endif - udotn = & - sign(1.0_pReal,traction_n)* & - kinematics_cleavage_opening_sdot_0(instance)* & - (max(0.0_pReal, abs(traction_n) - traction_crit)/traction_crit)**kinematics_cleavage_opening_N(instance) - if (abs(udotn) > tol_math_check) then - Ld = Ld + udotn*lattice_Scleavage(1:3,1:3,3,index_myFamily+i,phase) - dudotn_dt = sign(1.0_pReal,traction_n)*udotn*kinematics_cleavage_opening_N(instance)/ & - max(0.0_pReal, abs(traction_n) - traction_crit) - forall (k=1:3,l=1:3,m=1:3,n=1:3) & - dLd_dTstar(k,l,m,n) = dLd_dTstar(k,l,m,n) + & - dudotn_dt*lattice_Scleavage(k,l,3,index_myFamily+i,phase)* & - lattice_Scleavage(m,n,3,index_myFamily+i,phase) - endif - enddo - enddo + udotn = & + sign(1.0_pReal,traction_n)* & + kinematics_cleavage_opening_sdot_0(instance)* & + (max(0.0_pReal, abs(traction_n) - traction_crit)/traction_crit)**kinematics_cleavage_opening_N(instance) + if (abs(udotn) > tol_math_check) then + Ld = Ld + udotn*lattice_Scleavage(1:3,1:3,3,index_myFamily+i,phase) + dudotn_dt = sign(1.0_pReal,traction_n)*udotn*kinematics_cleavage_opening_N(instance)/ & + max(0.0_pReal, abs(traction_n) - traction_crit) + forall (k=1:3,l=1:3,m=1:3,n=1:3) & + dLd_dTstar(k,l,m,n) = dLd_dTstar(k,l,m,n) + & + dudotn_dt*lattice_Scleavage(k,l,3,index_myFamily+i,phase)* & + lattice_Scleavage(m,n,3,index_myFamily+i,phase) + endif + enddo + enddo end subroutine kinematics_cleavage_opening_LiAndItsTangent diff --git a/src/list.f90 b/src/list.f90 index be80b151d..79eafc964 100644 --- a/src/list.f90 +++ b/src/list.f90 @@ -3,8 +3,8 @@ !> @brief linked list !-------------------------------------------------------------------------------------------------- module list - use prec, only: & - pReal + use prec + use IO implicit none private @@ -65,10 +65,6 @@ contains !! to lower case. The data is not stored in the new element but in the current. !-------------------------------------------------------------------------------------------------- subroutine add(this,string) - use IO, only: & - IO_isBlank, & - IO_lc, & - IO_stringPos class(tPartitionedStringList), target, intent(in) :: this character(len=*), intent(in) :: string @@ -157,8 +153,6 @@ end subroutine finalizeArray !> @brief reports wether a given key (string value at first position) exists in the list !-------------------------------------------------------------------------------------------------- logical function keyExists(this,key) - use IO, only: & - IO_stringValue class(tPartitionedStringList), target, intent(in) :: this character(len=*), intent(in) :: key @@ -180,8 +174,6 @@ end function keyExists !> @details traverses list and counts each occurrence of specified key !-------------------------------------------------------------------------------------------------- integer function countKeys(this,key) - use IO, only: & - IO_stringValue class(tPartitionedStringList), target, intent(in) :: this character(len=*), intent(in) :: key @@ -205,10 +197,6 @@ end function countKeys !! error unless default is given !-------------------------------------------------------------------------------------------------- real(pReal) function getFloat(this,key,defaultVal) - use IO, only : & - IO_error, & - IO_stringValue, & - IO_FloatValue class(tPartitionedStringList), target, intent(in) :: this character(len=*), intent(in) :: key @@ -241,10 +229,6 @@ end function getFloat !! error unless default is given !-------------------------------------------------------------------------------------------------- integer function getInt(this,key,defaultVal) - use IO, only: & - IO_error, & - IO_stringValue, & - IO_IntValue class(tPartitionedStringList), target, intent(in) :: this character(len=*), intent(in) :: key @@ -278,9 +262,6 @@ end function getInt !! the individual chunks are returned !-------------------------------------------------------------------------------------------------- character(len=65536) function getString(this,key,defaultVal,raw) - use IO, only: & - IO_error, & - IO_stringValue class(tPartitionedStringList), target, intent(in) :: this character(len=*), intent(in) :: key @@ -327,10 +308,6 @@ end function getString !! values from the last occurrence. If key is not found exits with error unless default is given. !-------------------------------------------------------------------------------------------------- function getFloats(this,key,defaultVal,requiredSize) - use IO, only: & - IO_error, & - IO_stringValue, & - IO_FloatValue real(pReal), dimension(:), allocatable :: getFloats class(tPartitionedStringList), target, intent(in) :: this @@ -376,10 +353,6 @@ end function getFloats !! values from the last occurrence. If key is not found exits with error unless default is given. !-------------------------------------------------------------------------------------------------- function getInts(this,key,defaultVal,requiredSize) - use IO, only: & - IO_error, & - IO_stringValue, & - IO_IntValue integer, dimension(:), allocatable :: getInts class(tPartitionedStringList), target, intent(in) :: this @@ -426,9 +399,6 @@ end function getInts !! If raw is true, the the complete string is returned, otherwise the individual chunks are returned !-------------------------------------------------------------------------------------------------- function getStrings(this,key,defaultVal,raw) - use IO, only: & - IO_error, & - IO_StringValue character(len=65536),dimension(:), allocatable :: getStrings class(tPartitionedStringList),target, intent(in) :: this diff --git a/src/results.f90 b/src/results.f90 index 05db831f7..cee86c7da 100644 --- a/src/results.f90 +++ b/src/results.f90 @@ -5,6 +5,9 @@ !> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH !-------------------------------------------------------------------------------------------------- module results + use DAMASK_interface + use rotations + use numerics use HDF5_utilities #ifdef PETSc use PETSC @@ -55,8 +58,6 @@ module results contains subroutine results_init - use DAMASK_interface, only: & - getSolverJobName character(len=pStringLen) :: commandLine @@ -83,9 +84,6 @@ end subroutine results_init !> @brief opens the results file to append data !-------------------------------------------------------------------------------------------------- subroutine results_openJobFile - use DAMASK_interface, only: & - getSolverJobName - resultsFile = HDF5_openFile(trim(getSolverJobName())//'.hdf5','a',.true.) @@ -396,8 +394,6 @@ end subroutine results_writeTensorDataset_int !> @brief stores a scalar dataset in a group !-------------------------------------------------------------------------------------------------- subroutine results_writeScalarDataset_rotation(group,dataset,label,description,lattice_structure) - use rotations, only: & - rotation character(len=*), intent(in) :: label,group,description character(len=*), intent(in), optional :: lattice_structure @@ -428,9 +424,6 @@ end subroutine results_writeScalarDataset_rotation !> @brief adds the unique mapping from spatial position and constituent ID to results !-------------------------------------------------------------------------------------------------- subroutine results_mapping_constituent(phaseAt,memberAt,label) - use numerics, only: & - worldrank, & - worldsize integer, dimension(:,:), intent(in) :: phaseAt !< phase section at (constituent,element) integer, dimension(:,:,:), intent(in) :: memberAt !< phase member at (constituent,IP,element) @@ -566,9 +559,6 @@ end subroutine results_mapping_constituent !> @brief adds the unique mapping from spatial position and constituent ID to results !-------------------------------------------------------------------------------------------------- subroutine results_mapping_materialpoint(homogenizationAt,memberAt,label) - use numerics, only: & - worldrank, & - worldsize integer, dimension(:), intent(in) :: homogenizationAt !< homogenization section at (element) integer, dimension(:,:), intent(in) :: memberAt !< homogenization member at (IP,element) diff --git a/src/source_damage_anisoBrittle.f90 b/src/source_damage_anisoBrittle.f90 index 2f5fc119f..ccad7c6b0 100644 --- a/src/source_damage_anisoBrittle.f90 +++ b/src/source_damage_anisoBrittle.f90 @@ -5,55 +5,62 @@ !> @details to be done !-------------------------------------------------------------------------------------------------- module source_damage_anisoBrittle - use prec + use prec + use debug + use IO + use math + use material + use config + use lattice - implicit none - private - integer, dimension(:), allocatable, public, protected :: & - source_damage_anisoBrittle_offset, & !< which source is my current source mechanism? - source_damage_anisoBrittle_instance !< instance of source mechanism + implicit none + private - integer, dimension(:,:), allocatable, target, public :: & - source_damage_anisoBrittle_sizePostResult !< size of each post result output + integer, dimension(:), allocatable, public, protected :: & + source_damage_anisoBrittle_offset, & !< which source is my current source mechanism? + source_damage_anisoBrittle_instance !< instance of source mechanism - character(len=64), dimension(:,:), allocatable, target, public :: & - source_damage_anisoBrittle_output !< name of each post result output - - integer, dimension(:,:), allocatable, private :: & - source_damage_anisoBrittle_Ncleavage !< number of cleavage systems per family + integer, dimension(:,:), allocatable, target, public :: & + source_damage_anisoBrittle_sizePostResult !< size of each post result output - enum, bind(c) - enumerator :: undefined_ID, & - damage_drivingforce_ID - end enum + character(len=64), dimension(:,:), allocatable, target, public :: & + source_damage_anisoBrittle_output !< name of each post result output + + integer, dimension(:,:), allocatable :: & + source_damage_anisoBrittle_Ncleavage !< number of cleavage systems per family + + enum, bind(c) + enumerator :: undefined_ID, & + damage_drivingforce_ID + end enum - type, private :: tParameters !< container type for internal constitutive parameters - real(pReal) :: & - aTol, & - sdot_0, & - N - real(pReal), dimension(:), allocatable :: & - critDisp, & - critLoad - real(pReal), dimension(:,:,:,:), allocatable :: & - cleavage_systems - integer :: & - totalNcleavage - integer, dimension(:), allocatable :: & - Ncleavage - integer(kind(undefined_ID)), allocatable, dimension(:) :: & - outputID !< ID of each post result output - end type tParameters + type :: tParameters !< container type for internal constitutive parameters + real(pReal) :: & + aTol, & + sdot_0, & + N + real(pReal), dimension(:), allocatable :: & + critDisp, & + critLoad + real(pReal), dimension(:,:,:,:), allocatable :: & + cleavage_systems + integer :: & + totalNcleavage + integer, dimension(:), allocatable :: & + Ncleavage + integer(kind(undefined_ID)), allocatable, dimension(:) :: & + outputID !< ID of each post result output + end type tParameters - type(tParameters), dimension(:), allocatable, private :: param !< containers of constitutive parameters (len Ninstance) + type(tParameters), dimension(:), allocatable :: param !< containers of constitutive parameters (len Ninstance) - public :: & - source_damage_anisoBrittle_init, & - source_damage_anisoBrittle_dotState, & - source_damage_anisobrittle_getRateAndItsTangent, & - source_damage_anisoBrittle_postResults + public :: & + source_damage_anisoBrittle_init, & + source_damage_anisoBrittle_dotState, & + source_damage_anisobrittle_getRateAndItsTangent, & + source_damage_anisoBrittle_postResults contains @@ -63,266 +70,230 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine source_damage_anisoBrittle_init - use debug, only: & - debug_level,& - debug_constitutive,& - debug_levelBasic - use IO, only: & - IO_error - use math, only: & - math_expand - use material, only: & - material_allocateSourceState, & - phase_source, & - phase_Nsources, & - phase_Noutput, & - SOURCE_damage_anisoBrittle_label, & - SOURCE_damage_anisoBrittle_ID, & - material_phase, & - sourceState - use config, only: & - config_phase, & - material_Nphase - use lattice, only: & - lattice_SchmidMatrix_cleavage, & - lattice_maxNcleavageFamily - integer :: Ninstance,phase,instance,source,sourceOffset - integer :: NofMyPhase,p ,i - integer, dimension(0), parameter :: emptyIntArray = [integer::] - character(len=65536), dimension(0), parameter :: emptyStringArray = [character(len=65536)::] - integer(kind(undefined_ID)) :: & - outputID + integer :: Ninstance,phase,instance,source,sourceOffset + integer :: NofMyPhase,p ,i + integer, dimension(0), parameter :: emptyIntArray = [integer::] + character(len=65536), dimension(0), parameter :: emptyStringArray = [character(len=65536)::] + integer(kind(undefined_ID)) :: & + outputID - character(len=pStringLen) :: & - extmsg = '' - character(len=65536), dimension(:), allocatable :: & - outputs + character(len=pStringLen) :: & + extmsg = '' + character(len=65536), dimension(:), allocatable :: & + outputs - write(6,'(/,a)') ' <<<+- source_'//SOURCE_DAMAGE_ANISOBRITTLE_LABEL//' init -+>>>' + write(6,'(/,a)') ' <<<+- source_'//SOURCE_DAMAGE_ANISOBRITTLE_LABEL//' init -+>>>' - Ninstance = count(phase_source == SOURCE_damage_anisoBrittle_ID) - if (Ninstance == 0) return - - if (iand(debug_level(debug_constitutive),debug_levelBasic) /= 0) & - write(6,'(a16,1x,i5,/)') '# instances:',Ninstance - - allocate(source_damage_anisoBrittle_offset(material_Nphase), source=0) - allocate(source_damage_anisoBrittle_instance(material_Nphase), source=0) - do phase = 1, material_Nphase - source_damage_anisoBrittle_instance(phase) = count(phase_source(:,1:phase) == source_damage_anisoBrittle_ID) - do source = 1, phase_Nsources(phase) - if (phase_source(source,phase) == source_damage_anisoBrittle_ID) & - source_damage_anisoBrittle_offset(phase) = source - enddo - enddo - - allocate(source_damage_anisoBrittle_sizePostResult(maxval(phase_Noutput),Ninstance), source=0) - allocate(source_damage_anisoBrittle_output(maxval(phase_Noutput),Ninstance)) - source_damage_anisoBrittle_output = '' + Ninstance = count(phase_source == SOURCE_damage_anisoBrittle_ID) + if (Ninstance == 0) return + + if (iand(debug_level(debug_constitutive),debug_levelBasic) /= 0) & + write(6,'(a16,1x,i5,/)') '# instances:',Ninstance + + allocate(source_damage_anisoBrittle_offset(material_Nphase), source=0) + allocate(source_damage_anisoBrittle_instance(material_Nphase), source=0) + do phase = 1, material_Nphase + source_damage_anisoBrittle_instance(phase) = count(phase_source(:,1:phase) == source_damage_anisoBrittle_ID) + do source = 1, phase_Nsources(phase) + if (phase_source(source,phase) == source_damage_anisoBrittle_ID) & + source_damage_anisoBrittle_offset(phase) = source + enddo + enddo + + allocate(source_damage_anisoBrittle_sizePostResult(maxval(phase_Noutput),Ninstance), source=0) + allocate(source_damage_anisoBrittle_output(maxval(phase_Noutput),Ninstance)) + source_damage_anisoBrittle_output = '' - allocate(source_damage_anisoBrittle_Ncleavage(lattice_maxNcleavageFamily,Ninstance), source=0) + allocate(source_damage_anisoBrittle_Ncleavage(lattice_maxNcleavageFamily,Ninstance), source=0) - allocate(param(Ninstance)) - - do p=1, size(config_phase) - if (all(phase_source(:,p) /= SOURCE_DAMAGE_ANISOBRITTLE_ID)) cycle - associate(prm => param(source_damage_anisoBrittle_instance(p)), & - config => config_phase(p)) - - prm%aTol = config%getFloat('anisobrittle_atol',defaultVal = 1.0e-3_pReal) + allocate(param(Ninstance)) + + do p=1, size(config_phase) + if (all(phase_source(:,p) /= SOURCE_DAMAGE_ANISOBRITTLE_ID)) cycle + associate(prm => param(source_damage_anisoBrittle_instance(p)), & + config => config_phase(p)) + + prm%aTol = config%getFloat('anisobrittle_atol',defaultVal = 1.0e-3_pReal) - prm%N = config%getFloat('anisobrittle_ratesensitivity') - prm%sdot_0 = config%getFloat('anisobrittle_sdot0') - - ! sanity checks - if (prm%aTol < 0.0_pReal) extmsg = trim(extmsg)//' anisobrittle_atol' - - if (prm%N <= 0.0_pReal) extmsg = trim(extmsg)//' anisobrittle_ratesensitivity' - if (prm%sdot_0 <= 0.0_pReal) extmsg = trim(extmsg)//' anisobrittle_sdot0' - - prm%Ncleavage = config%getInts('ncleavage',defaultVal=emptyIntArray) + prm%N = config%getFloat('anisobrittle_ratesensitivity') + prm%sdot_0 = config%getFloat('anisobrittle_sdot0') + + ! sanity checks + if (prm%aTol < 0.0_pReal) extmsg = trim(extmsg)//' anisobrittle_atol' + + if (prm%N <= 0.0_pReal) extmsg = trim(extmsg)//' anisobrittle_ratesensitivity' + if (prm%sdot_0 <= 0.0_pReal) extmsg = trim(extmsg)//' anisobrittle_sdot0' + + prm%Ncleavage = config%getInts('ncleavage',defaultVal=emptyIntArray) - prm%critDisp = config%getFloats('anisobrittle_criticaldisplacement',requiredSize=size(prm%Ncleavage)) - prm%critLoad = config%getFloats('anisobrittle_criticalload', requiredSize=size(prm%Ncleavage)) - - prm%cleavage_systems = lattice_SchmidMatrix_cleavage (prm%Ncleavage,config%getString('lattice_structure'),& - config%getFloat('c/a',defaultVal=0.0_pReal)) + prm%critDisp = config%getFloats('anisobrittle_criticaldisplacement',requiredSize=size(prm%Ncleavage)) + prm%critLoad = config%getFloats('anisobrittle_criticalload', requiredSize=size(prm%Ncleavage)) + + prm%cleavage_systems = lattice_SchmidMatrix_cleavage (prm%Ncleavage,config%getString('lattice_structure'),& + config%getFloat('c/a',defaultVal=0.0_pReal)) - ! expand: family => system - prm%critDisp = math_expand(prm%critDisp, prm%Ncleavage) - prm%critLoad = math_expand(prm%critLoad, prm%Ncleavage) - - if (any(prm%critLoad < 0.0_pReal)) extmsg = trim(extmsg)//' anisobrittle_criticalload' - if (any(prm%critDisp < 0.0_pReal)) extmsg = trim(extmsg)//' anisobrittle_criticaldisplacement' + ! expand: family => system + prm%critDisp = math_expand(prm%critDisp, prm%Ncleavage) + prm%critLoad = math_expand(prm%critLoad, prm%Ncleavage) + + if (any(prm%critLoad < 0.0_pReal)) extmsg = trim(extmsg)//' anisobrittle_criticalload' + if (any(prm%critDisp < 0.0_pReal)) extmsg = trim(extmsg)//' anisobrittle_criticaldisplacement' !-------------------------------------------------------------------------------------------------- ! exit if any parameter is out of range - if (extmsg /= '') & - call IO_error(211,ext_msg=trim(extmsg)//'('//SOURCE_DAMAGE_ANISOBRITTLE_LABEL//')') + if (extmsg /= '') & + call IO_error(211,ext_msg=trim(extmsg)//'('//SOURCE_DAMAGE_ANISOBRITTLE_LABEL//')') !-------------------------------------------------------------------------------------------------- ! output pararameters - outputs = config%getStrings('(output)',defaultVal=emptyStringArray) - allocate(prm%outputID(0)) - do i=1, size(outputs) - outputID = undefined_ID - select case(outputs(i)) - - case ('anisobrittle_drivingforce') - source_damage_anisoBrittle_sizePostResult(i,source_damage_anisoBrittle_instance(p)) = 1 - source_damage_anisoBrittle_output(i,source_damage_anisoBrittle_instance(p)) = outputs(i) - prm%outputID = [prm%outputID, damage_drivingforce_ID] + outputs = config%getStrings('(output)',defaultVal=emptyStringArray) + allocate(prm%outputID(0)) + do i=1, size(outputs) + outputID = undefined_ID + select case(outputs(i)) + + case ('anisobrittle_drivingforce') + source_damage_anisoBrittle_sizePostResult(i,source_damage_anisoBrittle_instance(p)) = 1 + source_damage_anisoBrittle_output(i,source_damage_anisoBrittle_instance(p)) = outputs(i) + prm%outputID = [prm%outputID, damage_drivingforce_ID] - end select + end select - enddo + enddo - end associate - - phase = p - NofMyPhase=count(material_phase==phase) - instance = source_damage_anisoBrittle_instance(phase) - sourceOffset = source_damage_anisoBrittle_offset(phase) + end associate + + phase = p + NofMyPhase=count(material_phase==phase) + instance = source_damage_anisoBrittle_instance(phase) + sourceOffset = source_damage_anisoBrittle_offset(phase) - call material_allocateSourceState(phase,sourceOffset,NofMyPhase,1,1,0) - sourceState(phase)%p(sourceOffset)%sizePostResults = sum(source_damage_anisoBrittle_sizePostResult(:,instance)) - sourceState(phase)%p(sourceOffset)%aTolState=param(instance)%aTol + call material_allocateSourceState(phase,sourceOffset,NofMyPhase,1,1,0) + sourceState(phase)%p(sourceOffset)%sizePostResults = sum(source_damage_anisoBrittle_sizePostResult(:,instance)) + sourceState(phase)%p(sourceOffset)%aTolState=param(instance)%aTol - source_damage_anisoBrittle_Ncleavage(1:size(param(instance)%Ncleavage),instance) = param(instance)%Ncleavage - enddo + source_damage_anisoBrittle_Ncleavage(1:size(param(instance)%Ncleavage),instance) = param(instance)%Ncleavage + enddo - end subroutine source_damage_anisoBrittle_init + !-------------------------------------------------------------------------------------------------- !> @brief calculates derived quantities from state !-------------------------------------------------------------------------------------------------- subroutine source_damage_anisoBrittle_dotState(S, ipc, ip, el) - use math, only: & - math_mul33xx33 - use material, only: & - phaseAt, phasememberAt, & - sourceState, & - material_homogenizationAt, & - damage, & - damageMapping - use lattice, only: & - lattice_Scleavage, & - lattice_maxNcleavageFamily, & - lattice_NcleavageSystem - integer, intent(in) :: & - ipc, & !< component-ID of integration point - ip, & !< integration point - el !< element - real(pReal), intent(in), dimension(3,3) :: & - S - integer :: & - phase, & - constituent, & - instance, & - sourceOffset, & - damageOffset, & - homog, & - f, i, index_myFamily, index - real(pReal) :: & - traction_d, traction_t, traction_n, traction_crit + integer, intent(in) :: & + ipc, & !< component-ID of integration point + ip, & !< integration point + el !< element + real(pReal), intent(in), dimension(3,3) :: & + S + integer :: & + phase, & + constituent, & + instance, & + sourceOffset, & + damageOffset, & + homog, & + f, i, index_myFamily, index + real(pReal) :: & + traction_d, traction_t, traction_n, traction_crit - phase = phaseAt(ipc,ip,el) - constituent = phasememberAt(ipc,ip,el) - instance = source_damage_anisoBrittle_instance(phase) - sourceOffset = source_damage_anisoBrittle_offset(phase) - homog = material_homogenizationAt(el) - damageOffset = damageMapping(homog)%p(ip,el) - - sourceState(phase)%p(sourceOffset)%dotState(1,constituent) = 0.0_pReal - - index = 1 - do f = 1,lattice_maxNcleavageFamily - index_myFamily = sum(lattice_NcleavageSystem(1:f-1,phase)) ! at which index starts my family - do i = 1,source_damage_anisoBrittle_Ncleavage(f,instance) ! process each (active) cleavage system in family + phase = phaseAt(ipc,ip,el) + constituent = phasememberAt(ipc,ip,el) + instance = source_damage_anisoBrittle_instance(phase) + sourceOffset = source_damage_anisoBrittle_offset(phase) + homog = material_homogenizationAt(el) + damageOffset = damageMapping(homog)%p(ip,el) + + sourceState(phase)%p(sourceOffset)%dotState(1,constituent) = 0.0_pReal + + index = 1 + do f = 1,lattice_maxNcleavageFamily + index_myFamily = sum(lattice_NcleavageSystem(1:f-1,phase)) ! at which index starts my family + do i = 1,source_damage_anisoBrittle_Ncleavage(f,instance) ! process each (active) cleavage system in family - traction_d = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,1,index_myFamily+i,phase)) - traction_t = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,2,index_myFamily+i,phase)) - traction_n = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,3,index_myFamily+i,phase)) - - traction_crit = param(instance)%critLoad(index)* & - damage(homog)%p(damageOffset)*damage(homog)%p(damageOffset) + traction_d = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,1,index_myFamily+i,phase)) + traction_t = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,2,index_myFamily+i,phase)) + traction_n = math_mul33xx33(S,lattice_Scleavage(1:3,1:3,3,index_myFamily+i,phase)) + + traction_crit = param(instance)%critLoad(index)* & + damage(homog)%p(damageOffset)*damage(homog)%p(damageOffset) - sourceState(phase)%p(sourceOffset)%dotState(1,constituent) = & - sourceState(phase)%p(sourceOffset)%dotState(1,constituent) + & - param(instance)%sdot_0* & - ((max(0.0_pReal, abs(traction_d) - traction_crit)/traction_crit)**param(instance)%N + & - (max(0.0_pReal, abs(traction_t) - traction_crit)/traction_crit)**param(instance)%N + & - (max(0.0_pReal, abs(traction_n) - traction_crit)/traction_crit)**param(instance)%N)/ & - param(instance)%critDisp(index) + sourceState(phase)%p(sourceOffset)%dotState(1,constituent) = & + sourceState(phase)%p(sourceOffset)%dotState(1,constituent) + & + param(instance)%sdot_0* & + ((max(0.0_pReal, abs(traction_d) - traction_crit)/traction_crit)**param(instance)%N + & + (max(0.0_pReal, abs(traction_t) - traction_crit)/traction_crit)**param(instance)%N + & + (max(0.0_pReal, abs(traction_n) - traction_crit)/traction_crit)**param(instance)%N)/ & + param(instance)%critDisp(index) - index = index + 1 - enddo - enddo + index = index + 1 + enddo + enddo end subroutine source_damage_anisoBrittle_dotState + !-------------------------------------------------------------------------------------------------- !> @brief returns local part of nonlocal damage driving force !-------------------------------------------------------------------------------------------------- subroutine source_damage_anisobrittle_getRateAndItsTangent(localphiDot, dLocalphiDot_dPhi, phi, phase, constituent) - use material, only: & - sourceState - integer, intent(in) :: & - phase, & - constituent - real(pReal), intent(in) :: & - phi - real(pReal), intent(out) :: & - localphiDot, & - dLocalphiDot_dPhi - integer :: & - sourceOffset + integer, intent(in) :: & + phase, & + constituent + real(pReal), intent(in) :: & + phi + real(pReal), intent(out) :: & + localphiDot, & + dLocalphiDot_dPhi + integer :: & + sourceOffset - sourceOffset = source_damage_anisoBrittle_offset(phase) - - localphiDot = 1.0_pReal & - - sourceState(phase)%p(sourceOffset)%state(1,constituent)*phi - - dLocalphiDot_dPhi = -sourceState(phase)%p(sourceOffset)%state(1,constituent) + sourceOffset = source_damage_anisoBrittle_offset(phase) + + localphiDot = 1.0_pReal & + - sourceState(phase)%p(sourceOffset)%state(1,constituent)*phi + + dLocalphiDot_dPhi = -sourceState(phase)%p(sourceOffset)%state(1,constituent) end subroutine source_damage_anisobrittle_getRateAndItsTangent - + + !-------------------------------------------------------------------------------------------------- !> @brief return array of local damage results !-------------------------------------------------------------------------------------------------- function source_damage_anisoBrittle_postResults(phase, constituent) - use material, only: & - sourceState - integer, intent(in) :: & - phase, & - constituent - real(pReal), dimension(sum(source_damage_anisoBrittle_sizePostResult(:, & - source_damage_anisoBrittle_instance(phase)))) :: & - source_damage_anisoBrittle_postResults + integer, intent(in) :: & + phase, & + constituent - integer :: & - instance, sourceOffset, o, c - - instance = source_damage_anisoBrittle_instance(phase) - sourceOffset = source_damage_anisoBrittle_offset(phase) + real(pReal), dimension(sum(source_damage_anisoBrittle_sizePostResult(:, & + source_damage_anisoBrittle_instance(phase)))) :: & + source_damage_anisoBrittle_postResults - c = 0 + integer :: & + instance, sourceOffset, o, c + + instance = source_damage_anisoBrittle_instance(phase) + sourceOffset = source_damage_anisoBrittle_offset(phase) - do o = 1,size(param(instance)%outputID) - select case(param(instance)%outputID(o)) - case (damage_drivingforce_ID) - source_damage_anisoBrittle_postResults(c+1) = & - sourceState(phase)%p(sourceOffset)%state(1,constituent) - c = c + 1 + c = 0 - end select - enddo + do o = 1,size(param(instance)%outputID) + select case(param(instance)%outputID(o)) + case (damage_drivingforce_ID) + source_damage_anisoBrittle_postResults(c+1) = & + sourceState(phase)%p(sourceOffset)%state(1,constituent) + c = c + 1 + + end select + enddo end function source_damage_anisoBrittle_postResults end module source_damage_anisoBrittle diff --git a/src/source_thermal_dissipation.f90 b/src/source_thermal_dissipation.f90 index 94452eb47..e8464edd0 100644 --- a/src/source_thermal_dissipation.f90 +++ b/src/source_thermal_dissipation.f90 @@ -5,27 +5,30 @@ !> @details to be done !-------------------------------------------------------------------------------------------------- module source_thermal_dissipation - use prec, only: & - pReal + use prec + use debug + use material + use config implicit none private + integer, dimension(:), allocatable, public, protected :: & - source_thermal_dissipation_offset, & !< which source is my current thermal dissipation mechanism? - source_thermal_dissipation_instance !< instance of thermal dissipation source mechanism + source_thermal_dissipation_offset, & !< which source is my current thermal dissipation mechanism? + source_thermal_dissipation_instance !< instance of thermal dissipation source mechanism integer, dimension(:,:), allocatable, target, public :: & - source_thermal_dissipation_sizePostResult !< size of each post result output + source_thermal_dissipation_sizePostResult !< size of each post result output character(len=64), dimension(:,:), allocatable, target, public :: & - source_thermal_dissipation_output !< name of each post result output + source_thermal_dissipation_output !< name of each post result output - type, private :: tParameters !< container type for internal constitutive parameters + type :: tParameters !< container type for internal constitutive parameters real(pReal) :: & kappa end type tParameters - type(tParameters), dimension(:), allocatable, private :: param !< containers of constitutive parameters (len Ninstance) + type(tParameters), dimension(:), allocatable :: param !< containers of constitutive parameters (len Ninstance) public :: & @@ -40,21 +43,6 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine source_thermal_dissipation_init - use debug, only: & - debug_level,& - debug_constitutive,& - debug_levelBasic - use material, only: & - material_allocateSourceState, & - phase_source, & - phase_Nsources, & - phase_Noutput, & - SOURCE_thermal_dissipation_label, & - SOURCE_thermal_dissipation_ID, & - material_phase - use config, only: & - config_phase, & - material_Nphase integer :: Ninstance,instance,source,sourceOffset integer :: NofMyPhase,p diff --git a/src/source_thermal_externalheat.f90 b/src/source_thermal_externalheat.f90 index 699902ad3..99d9a6f1f 100644 --- a/src/source_thermal_externalheat.f90 +++ b/src/source_thermal_externalheat.f90 @@ -5,11 +5,14 @@ !> @brief material subroutine for variable heat source !-------------------------------------------------------------------------------------------------- module source_thermal_externalheat - use prec, only: & - pReal + use prec + use debug + use material + use config implicit none private + integer, dimension(:), allocatable, public, protected :: & source_thermal_externalheat_offset, & !< which source is my current thermal dissipation mechanism? source_thermal_externalheat_instance !< instance of thermal dissipation source mechanism @@ -23,7 +26,7 @@ module source_thermal_externalheat integer, dimension(:), allocatable, target, public :: & source_thermal_externalheat_Noutput !< number of outputs per instance of this source - type, private :: tParameters !< container type for internal constitutive parameters + type :: tParameters !< container type for internal constitutive parameters real(pReal), dimension(:), allocatable :: & time, & heat_rate @@ -31,7 +34,7 @@ module source_thermal_externalheat nIntervals end type tParameters - type(tParameters), dimension(:), allocatable, private :: param !< containers of constitutive parameters (len Ninstance) + type(tParameters), dimension(:), allocatable :: param !< containers of constitutive parameters (len Ninstance) public :: & @@ -47,22 +50,6 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine source_thermal_externalheat_init - use debug, only: & - debug_level,& - debug_constitutive,& - debug_levelBasic - use material, only: & - material_allocateSourceState, & - material_phase, & - phase_source, & - phase_Nsources, & - phase_Noutput, & - SOURCE_thermal_externalheat_label, & - SOURCE_thermal_externalheat_ID - use config, only: & - config_phase, & - material_Nphase - integer :: maxNinstance,instance,source,sourceOffset,NofMyPhase,p @@ -116,8 +103,6 @@ end subroutine source_thermal_externalheat_init !> @details state only contains current time to linearly interpolate given heat powers !-------------------------------------------------------------------------------------------------- subroutine source_thermal_externalheat_dotState(phase, of) - use material, only: & - sourceState integer, intent(in) :: & phase, & @@ -135,8 +120,6 @@ end subroutine source_thermal_externalheat_dotState !> @brief returns local heat generation rate !-------------------------------------------------------------------------------------------------- subroutine source_thermal_externalheat_getRateAndItsTangent(TDot, dTDot_dT, phase, of) - use material, only: & - sourceState integer, intent(in) :: & phase, & diff --git a/src/thermal_adiabatic.f90 b/src/thermal_adiabatic.f90 index bfd5633d1..3c9fd0c6e 100644 --- a/src/thermal_adiabatic.f90 +++ b/src/thermal_adiabatic.f90 @@ -3,9 +3,16 @@ !> @brief material subroutine for adiabatic temperature evolution !-------------------------------------------------------------------------------------------------- module thermal_adiabatic - use prec, only: & - pReal - + use prec + use config + use numerics + use material + use source_thermal_dissipation + use source_thermal_externalheat + use crystallite + use lattice + use mesh + implicit none private @@ -21,7 +28,7 @@ module thermal_adiabatic enumerator :: undefined_ID, & temperature_ID end enum - integer(kind(undefined_ID)), dimension(:,:), allocatable, private :: & + integer(kind(undefined_ID)), dimension(:,:), allocatable :: & thermal_adiabatic_outputID !< ID of each post result output @@ -41,21 +48,6 @@ contains !> @details reads in material parameters, allocates arrays, and does sanity checks !-------------------------------------------------------------------------------------------------- subroutine thermal_adiabatic_init - use material, only: & - thermal_type, & - thermal_typeInstance, & - homogenization_Noutput, & - THERMAL_ADIABATIC_label, & - THERMAL_adiabatic_ID, & - material_homogenizationAt, & - mappingHomogenization, & - thermalState, & - thermalMapping, & - thermal_initialT, & - temperature, & - temperatureRate - use config, only: & - config_homogenization integer :: maxNinstance,section,instance,i,sizeState,NofMyHomog character(len=65536), dimension(0), parameter :: emptyStringArray = [character(len=65536)::] @@ -112,16 +104,6 @@ end subroutine thermal_adiabatic_init !> @brief calculates adiabatic change in temperature based on local heat generation model !-------------------------------------------------------------------------------------------------- function thermal_adiabatic_updateState(subdt, ip, el) - use numerics, only: & - err_thermal_tolAbs, & - err_thermal_tolRel - use material, only: & - material_homogenizationAt, & - mappingHomogenization, & - thermalState, & - temperature, & - temperatureRate, & - thermalMapping integer, intent(in) :: & ip, & !< integration point number @@ -156,27 +138,11 @@ function thermal_adiabatic_updateState(subdt, ip, el) end function thermal_adiabatic_updateState + !-------------------------------------------------------------------------------------------------- !> @brief returns heat generation rate !-------------------------------------------------------------------------------------------------- subroutine thermal_adiabatic_getSourceAndItsTangent(Tdot, dTdot_dT, T, ip, el) - use material, only: & - homogenization_Ngrains, & - material_homogenizationAt, & - phaseAt, & - phasememberAt, & - thermal_typeInstance, & - phase_Nsources, & - phase_source, & - SOURCE_thermal_dissipation_ID, & - SOURCE_thermal_externalheat_ID - use source_thermal_dissipation, only: & - source_thermal_dissipation_getRateAndItsTangent - use source_thermal_externalheat, only: & - source_thermal_externalheat_getRateAndItsTangent - use crystallite, only: & - crystallite_S, & - crystallite_Lp integer, intent(in) :: & ip, & !< integration point number @@ -229,18 +195,12 @@ subroutine thermal_adiabatic_getSourceAndItsTangent(Tdot, dTdot_dT, T, ip, el) dTdot_dT = dTdot_dT/real(homogenization_Ngrains(homog),pReal) end subroutine thermal_adiabatic_getSourceAndItsTangent - + + !-------------------------------------------------------------------------------------------------- !> @brief returns homogenized specific heat capacity !-------------------------------------------------------------------------------------------------- function thermal_adiabatic_getSpecificHeat(ip,el) - use lattice, only: & - lattice_specificHeat - use material, only: & - homogenization_Ngrains, & - material_phase - use mesh, only: & - mesh_element integer, intent(in) :: & ip, & !< integration point number @@ -269,13 +229,6 @@ end function thermal_adiabatic_getSpecificHeat !> @brief returns homogenized mass density !-------------------------------------------------------------------------------------------------- function thermal_adiabatic_getMassDensity(ip,el) - use lattice, only: & - lattice_massDensity - use material, only: & - homogenization_Ngrains, & - material_phase - use mesh, only: & - mesh_element integer, intent(in) :: & ip, & !< integration point number @@ -303,8 +256,6 @@ end function thermal_adiabatic_getMassDensity !> @brief return array of thermal results !-------------------------------------------------------------------------------------------------- function thermal_adiabatic_postResults(homog,instance,of) result(postResults) - use material, only: & - temperature integer, intent(in) :: & homog, & From 358272eb2ede29437b1371e76c6fcc822267e37f Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 28 May 2019 12:29:46 +0200 Subject: [PATCH 065/120] not needed, better readable without --- src/debug.f90 | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/debug.f90 b/src/debug.f90 index 4f9566c05..ff084b133 100644 --- a/src/debug.f90 +++ b/src/debug.f90 @@ -6,12 +6,12 @@ !> @brief Reading in and interpretating the debugging settings for the various modules !-------------------------------------------------------------------------------------------------- module debug - use prec, only: & - pInt, & - pReal + use prec + use IO implicit none private + integer(pInt), parameter, public :: & debug_LEVELSELECTIVE = 2_pInt**0_pInt, & debug_LEVELBASIC = 2_pInt**1_pInt, & @@ -78,19 +78,7 @@ contains !> @brief reads in parameters from debug.config and allocates arrays !-------------------------------------------------------------------------------------------------- subroutine debug_init - use prec, only: & - pStringLen - use IO, only: & - IO_read_ASCII, & - IO_error, & - IO_isBlank, & - IO_stringPos, & - IO_stringValue, & - IO_lc, & - IO_floatValue, & - IO_intValue - implicit none character(len=pStringLen), dimension(:), allocatable :: fileContent integer :: i, what, j @@ -253,8 +241,6 @@ end subroutine debug_init !-------------------------------------------------------------------------------------------------- subroutine debug_reset - implicit none - debug_stressMaxLocation = 0_pInt debug_stressMinLocation = 0_pInt debug_jacobianMaxLocation = 0_pInt @@ -272,8 +258,6 @@ end subroutine debug_reset !-------------------------------------------------------------------------------------------------- subroutine debug_info - implicit none - !$OMP CRITICAL (write2out) debugOutputCPFEM: if (iand(debug_level(debug_CPFEM),debug_LEVELBASIC) /= 0 & .and. any(debug_stressMinLocation /= 0_pInt) & From 2eb964b1eacbb39e54293254f889054814137f11 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 28 May 2019 23:45:17 +0200 Subject: [PATCH 066/120] simplified needs some manual checking and proper test --- processing/pre/geom_addPrimitive.py | 104 +++++++--------------------- 1 file changed, 26 insertions(+), 78 deletions(-) diff --git a/processing/pre/geom_addPrimitive.py b/processing/pre/geom_addPrimitive.py index 632019118..38cce2d65 100755 --- a/processing/pre/geom_addPrimitive.py +++ b/processing/pre/geom_addPrimitive.py @@ -19,7 +19,7 @@ scriptID = ' '.join([scriptName,damask.version]) parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ Inserts a primitive geometric object at a given position. -Depending on the sign of the dimension parameters, these objects can be boxes, cylinders, or ellipsoids. +These objects can be boxes, cylinders, or ellipsoids. """, version = scriptID) @@ -88,11 +88,6 @@ elif options.quaternion is not None: else: rotation = damask.Rotation() -options.center = np.array(options.center) -options.dimension = np.array(options.dimension) -# undo logarithmic sense of exponent and generate ellipsoids for negative dimensions (backward compatibility) -options.exponent = np.where(np.array(options.dimension) > 0, np.power(2,options.exponent), 2) - if filenames == []: filenames = [None] @@ -102,85 +97,38 @@ for name in filenames: geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) grid = geom.get_grid() size = geom.get_size() - origin = geom.get_origin() microstructure = geom.get_microstructure() - # coordinates given in real space, not (default) voxel space + # scale to box of size [1.0,1.0,1.0] if options.realspace: - options.center -= origin - options.center *= grid / size - options.dimension *= grid / size - - - # change to coordinate space where the primitive is the unit sphere/cube/etc - if options.periodic: # use padding to achieve periodicity - (X, Y, Z) = np.meshgrid(np.arange(-grid[0]/2, (3*grid[0])/2, dtype=np.float32), # 50% padding on each side - np.arange(-grid[1]/2, (3*grid[1])/2, dtype=np.float32), - np.arange(-grid[2]/2, (3*grid[2])/2, dtype=np.float32), - indexing='ij') - # Padding handling - X = np.roll(np.roll(np.roll(X, - -grid[0]//2, axis=0), - -grid[1]//2, axis=1), - -grid[2]//2, axis=2) - Y = np.roll(np.roll(np.roll(Y, - -grid[0]//2, axis=0), - -grid[1]//2, axis=1), - -grid[2]//2, axis=2) - Z = np.roll(np.roll(np.roll(Z, - -grid[0]//2, axis=0), - -grid[1]//2, axis=1), - -grid[2]//2, axis=2) - else: # nonperiodic, much lighter on resources - # change to coordinate space where the primitive is the unit sphere/cube/etc - (X, Y, Z) = np.meshgrid(np.arange(0, grid[0], dtype=np.float32), - np.arange(0, grid[1], dtype=np.float32), - np.arange(0, grid[2], dtype=np.float32), - indexing='ij') + center = (np.array(options.center) - geom.get_origin())/size + r = np.array(options.dimension)/size/2.0 + else: + center = (np.array(options.center) + 0.5)/grid + r = np.array(options.dimension)/grid/2.0 - # first by translating the center onto 0, 0.5 shifts the voxel origin onto the center of the voxel - X -= options.center[0] - 0.5 - Y -= options.center[1] - 0.5 - Z -= options.center[2] - 0.5 - # and then by applying the rotation - (X, Y, Z) = rotation * (X, Y, Z) - # and finally by scaling (we don't worry about options.dimension being negative, np.abs occurs on the microstructure = np.where... line) - X /= options.dimension[0] * 0.5 - Y /= options.dimension[1] * 0.5 - Z /= options.dimension[2] * 0.5 - - fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill + if np.any(center<0.0) or np.any(center>=1.0): print('error') - # High exponents can cause underflow & overflow - loss of precision is okay here, we just compare it to 1, so +infinity and 0 are fine - old_settings = np.seterr() + offset = np.ones(3)*0.5 if options.periodic else center + mask = np.full(grid,False) + # High exponents can cause underflow & overflow - okay here, just compare to 1, so +infinity and 0 are fine np.seterr(over='ignore', under='ignore') - - if options.periodic: # use padding to achieve periodicity - inside = np.zeros(grid, dtype=bool) - for i in range(2): - for j in range(2): - for k in range(2): - inside = inside | ( # Most of this is handling the padding - np.abs(X[grid[0] * i : grid[0] * (i+1), - grid[1] * j : grid[1] * (j+1), - grid[2] * k : grid[2] * (k+1)])**options.exponent[0] + - np.abs(Y[grid[0] * i : grid[0] * (i+1), - grid[1] * j : grid[1] * (j+1), - grid[2] * k : grid[2] * (k+1)])**options.exponent[1] + - np.abs(Z[grid[0] * i : grid[0] * (i+1), - grid[1] * j : grid[1] * (j+1), - grid[2] * k : grid[2] * (k+1)])**options.exponent[2] <= 1.0) - - microstructure = np.where(inside, - fill if options.inside else microstructure, - microstructure if options.inside else fill) - else: # nonperiodic, much lighter on resources - microstructure = np.where(np.abs(X)**options.exponent[0] + - np.abs(Y)**options.exponent[1] + - np.abs(Z)**options.exponent[2] <= 1.0, - fill if options.inside else microstructure, - microstructure if options.inside else fill) + e = np.array(options.exponent) + for x in range(grid[0]): + for y in range(grid[1]): + for z in range(grid[2]): + coords = np.array([x+0.5,y+0.5,z+0.5])/grid + mask[x,y,z] = np.sum(np.abs((rotation*(coords-offset))/r)**e) < 1 + + if options.periodic: + shift = ((offset-center)*grid).astype(int) + mask = np.roll(mask,shift,(0,1,2)) + + + if options.inside: mask = np.logical_not(mask) + fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill + microstructure = np.where(mask,microstructure,fill) damask.util.croak(geom.update(microstructure)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) From 9f6892303862a19d6c07267e93529e538610f0c5 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 07:38:11 +0200 Subject: [PATCH 067/120] restored old behavior save some ressources by avoiding copies. much slower than old version, better cast formula into meshgrid again --- processing/pre/geom_addPrimitive.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/processing/pre/geom_addPrimitive.py b/processing/pre/geom_addPrimitive.py index 38cce2d65..b8b1ddf6e 100755 --- a/processing/pre/geom_addPrimitive.py +++ b/processing/pre/geom_addPrimitive.py @@ -34,9 +34,10 @@ parser.add_option('-d', '--dimension', parser.add_option('-e', '--exponent', dest='exponent', type='float', nargs = 3, metavar=' '.join(['float']*3), - help='i,j,k exponents for axes - 0 gives octahedron (|x|^(2^0) + |y|^(2^0) + |z|^(2^0) < 1), \ - 1 gives a sphere (|x|^(2^1) + |y|^(2^1) + |z|^(2^1) < 1), \ - large values produce boxes, negative turn concave.') + help='i,j,k exponents for axes: '+ + '0 gives octahedron (|x|^(2^0) + |y|^(2^0) + |z|^(2^0) < 1), '+ + '1 gives a sphere (|x|^(2^1) + |y|^(2^1) + |z|^(2^1) < 1), '+ + 'large values produce boxes, negative turn concave.') parser.add_option('-f', '--fill', dest='fill', type='float', metavar = 'int', @@ -97,7 +98,6 @@ for name in filenames: geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) grid = geom.get_grid() size = geom.get_size() - microstructure = geom.get_microstructure() # scale to box of size [1.0,1.0,1.0] if options.realspace: @@ -114,7 +114,7 @@ for name in filenames: # High exponents can cause underflow & overflow - okay here, just compare to 1, so +infinity and 0 are fine np.seterr(over='ignore', under='ignore') - e = np.array(options.exponent) + e = 2.0**np.array(options.exponent) for x in range(grid[0]): for y in range(grid[1]): for z in range(grid[2]): @@ -124,13 +124,11 @@ for name in filenames: if options.periodic: shift = ((offset-center)*grid).astype(int) mask = np.roll(mask,shift,(0,1,2)) - - + if options.inside: mask = np.logical_not(mask) - fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill - microstructure = np.where(mask,microstructure,fill) + fill = np.nanmax(geom.microstructure)+1 if options.fill is None else options.fill - damask.util.croak(geom.update(microstructure)) + damask.util.croak(geom.update(np.where(mask,geom.microstructure,fill))) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: From bb6f54963a397d84bf3558cabdfb687d98efaed4 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 07:49:43 +0200 Subject: [PATCH 068/120] save some memory (avoid copies if not needed) --- processing/pre/geom_clean.py | 8 +++----- processing/pre/geom_grainGrowth.py | 5 ++--- processing/pre/geom_pack.py | 29 ++++++++++++--------------- processing/pre/geom_renumber.py | 7 +++---- processing/pre/geom_rescale.py | 14 +++++++------ processing/pre/geom_rotate.py | 1 - processing/pre/geom_toTable.py | 5 ++--- processing/pre/geom_translate.py | 5 ++--- processing/pre/geom_vicinityOffset.py | 18 ++++++++--------- 9 files changed, 41 insertions(+), 51 deletions(-) diff --git a/processing/pre/geom_clean.py b/processing/pre/geom_clean.py index 8fa7f5953..8e477c1c1 100755 --- a/processing/pre/geom_clean.py +++ b/processing/pre/geom_clean.py @@ -45,12 +45,10 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - microstructure = geom.get_microstructure() - microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent, - size=(options.stencil,)*3).astype(microstructure.dtype) - - damask.util.croak(geom.update(microstructure)) + damask.util.croak(geom.update(ndimage.filters.generic_filter( + geom.microstructure,mostFrequent, + size=(options.stencil,)*3).astype(geom.microstructure.dtype))) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: diff --git a/processing/pre/geom_grainGrowth.py b/processing/pre/geom_grainGrowth.py index 952c15c13..4c8b6c8bc 100755 --- a/processing/pre/geom_grainGrowth.py +++ b/processing/pre/geom_grainGrowth.py @@ -60,11 +60,10 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - microstructure = geom.get_microstructure() + grid_original = geom.get_grid() damask.util.croak(geom) - grid_original = geom.get_grid() - microstructure = np.tile(geom.get_microstructure(),np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1 + microstructure = np.tile(geom.microstructure,np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1 grid = np.array(microstructure.shape) # --- initialize support data --------------------------------------------------------------------- diff --git a/processing/pre/geom_pack.py b/processing/pre/geom_pack.py index 1a002830e..68045defa 100755 --- a/processing/pre/geom_pack.py +++ b/processing/pre/geom_pack.py @@ -30,7 +30,6 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - microstructure = geom.get_microstructure().flatten('F') damask.util.croak(geom) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) @@ -38,7 +37,12 @@ for name in filenames: former = start = -1 reps = 0 - for current in microstructure: + if name is None: + f = sys.stdout + else: + f= open(name,'w') + + for current in geom.microstructure.flatten('F'): if abs(current - former) == 1 and (start - current) == reps*(former - current): compressType = 'to' reps += 1 @@ -47,13 +51,13 @@ for name in filenames: reps += 1 else: if compressType is None: - out = geom.get_header() + f.write('\n'.join(geom.get_header())+'\n') elif compressType == '.': - out.append('{}'.format(former)) + f.write('{}\n'.format(former)) elif compressType == 'to': - out.append('{} to {}'.format(start,former)) + f.write('{} to {}\n'.format(start,former)) elif compressType == 'of': - out.append('{} of {}'.format(reps,former)) + f.write('{} of {}\n'.format(reps,former)) compressType = '.' start = current @@ -62,15 +66,8 @@ for name in filenames: former = current if compressType == '.': - out.append('{}'.format(former)) + f.write('{}\n'.format(former)) elif compressType == 'to': - out.append('{} to {}'.format(start,former)) + f.write('{} to {}\n'.format(start,former)) elif compressType == 'of': - out.append('{} of {}'.format(reps,former)) - - - if name is None: - sys.stdout.write('\n'.join(out)+'\n') - else: - with open(name,'w') as f: - f.write('\n'.join(out)+'\n') + f.write('{} of {}\n'.format(reps,former)) diff --git a/processing/pre/geom_renumber.py b/processing/pre/geom_renumber.py index ef21cd1ab..403aeaf5b 100755 --- a/processing/pre/geom_renumber.py +++ b/processing/pre/geom_renumber.py @@ -32,11 +32,10 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - microstructure = geom.get_microstructure() - renumbered = np.copy(microstructure) - for i, oldID in enumerate(np.unique(microstructure)): - renumbered = np.where(microstructure == oldID, i+1, renumbered) + renumbered = np.empty(geom.get_grid(),dtype=geom.microstructure.dtype) + for i, oldID in enumerate(np.unique(geom.microstructure)): + renumbered = np.where(geom.microstructure == oldID, i+1, renumbered) damask.util.croak(geom.update(renumbered)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index 1a94f327e..aa639a146 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -43,7 +43,6 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - microstructure = geom.get_microstructure() grid = geom.get_grid() size = geom.get_size() @@ -55,11 +54,14 @@ for name in filenames: np.array([o*float(n.lower().replace('x','')) if n.lower().endswith('x') \ else float(n) for o,n in zip(size,options.size)],dtype=float) - if np.any(new_grid != grid): - microstructure = ndimage.interpolation.zoom(microstructure, new_grid/grid,output=microstructure.dtype, - order=0,mode='nearest', prefilter=False) - - damask.util.croak(geom.update(microstructure,new_size)) + damask.util.croak(geom.update(microstructure = + ndimage.interpolation.zoom( + geom.microstructure, + new_grid/grid,output=geom.microstructure.dtype, + order=0,mode='nearest', prefilter=False\ + ) \ + if np.any(new_grid != grid) else None, + size = new_size)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 4189fefea..476e26c29 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -88,7 +88,6 @@ for name in filenames: microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0, prefilter=False,output=dtype,cval=fill) # rotation around z - damask.util.croak(geom.update(microstructure,rescale=True)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) diff --git a/processing/pre/geom_toTable.py b/processing/pre/geom_toTable.py index 352238524..7db7f8430 100755 --- a/processing/pre/geom_toTable.py +++ b/processing/pre/geom_toTable.py @@ -32,8 +32,7 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - damask.util.croak(geom) - microstructure = geom.get_microstructure().flatten('F') + damask.util.croak(geom) grid = geom.get_grid() size = geom.get_size() origin = geom.get_origin() @@ -55,6 +54,6 @@ for name in filenames: table.labels_append(['{}_{}'.format(1+i,'pos') for i in range(3)]+['microstructure']) table.head_write() table.output_flush() - table.data = np.squeeze(np.dstack((xx,yy,zz,microstructure)),axis=0) + table.data = np.squeeze(np.dstack((xx,yy,zz,geom.microstructure.flatten('F'))),axis=0) table.data_writeArray() table.close() diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index 488da5103..a63774b22 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -51,10 +51,9 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - microstructure = geom.get_microstructure() - substituted = np.copy(microstructure) + substituted = geom.get_microstructure() - for old,new in zip(sub[0::2],sub[1::2]): substituted[microstructure==old] = new # substitute microstructure indices + for old,new in zip(sub[0::2],sub[1::2]): substituted[substituted==old] = new # substitute microstructure indices substituted += options.microstructure # constant shift damask.util.croak(geom.update(substituted,origin=geom.get_origin()+options.origin)) diff --git a/processing/pre/geom_vicinityOffset.py b/processing/pre/geom_vicinityOffset.py index e36aac301..bda6b6c5f 100755 --- a/processing/pre/geom_vicinityOffset.py +++ b/processing/pre/geom_vicinityOffset.py @@ -70,18 +70,16 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - microstructure = geom.get_microstructure() - offset = np.nanmax(microstructure) if options.offset is None else options.offset + offset = np.nanmax(geom.microstructure) if options.offset is None else options.offset - microstructure = np.where(ndimage.filters.generic_filter(microstructure, - taintedNeighborhood, - size=1+2*options.vicinity,mode=options.mode, - extra_arguments=(), - extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}), - microstructure + offset,microstructure) - - damask.util.croak(geom.update(microstructure)) + damask.util.croak(geom.update(np.where(ndimage.filters.generic_filter( + geom.microstructure, + taintedNeighborhood, + size=1+2*options.vicinity,mode=options.mode, + extra_arguments=(), + extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}), + geom.microstructure + offset,geom.microstructure))) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: From 8ee23b37b204c9a18a5814abfe434117d826d6bf Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 07:50:37 +0200 Subject: [PATCH 069/120] should not be part of the repo --- processing/pre/geom_translate.py | 2 - test.log | 211 ------------------------------- 2 files changed, 213 deletions(-) delete mode 100644 test.log diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index a63774b22..59c431474 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -5,8 +5,6 @@ import sys from optparse import OptionParser from io import StringIO -import numpy as np - import damask diff --git a/test.log b/test.log deleted file mode 100644 index a9dbb8c45..000000000 --- a/test.log +++ /dev/null @@ -1,211 +0,0 @@ -2019-05-27 22:44:00,700 - INFO: -++++++++++++++++++++++++++++++++++++++++ ----------------------------------------- -| Check geom-modifying scripts ----------------------------------------- -2019-05-27 22:44:00,707 - INFO: -geom_addPrimitive -c 0.3 0.5 0.2 -a 1.0 0.8 0.9 0.4 -d 0.10 0.13 0.08 geom_addPrimitive.geom -2019-05-27 22:44:00,899 - INFO: -geom_addPrimitive: geom_addPrimitive.geom - -grid a b c: 32 x 35 x 12 -size x y z: 0.914285714286 x 1.0 x 0.342857142857 -origin x y z: 0.0 x 1.0 x 2.0 -homogenization: 1 -# microstructures: 20 -max microstructure: 26 - -2019-05-27 22:44:00,899 - DEBUG: - -2019-05-27 22:44:00,899 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_addPrimitive_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_addPrimitive.geom -2019-05-27 22:44:00,920 - INFO: -geom_canvas -g 40 35 20 -f 90 geom_canvas.geom -2019-05-27 22:44:01,103 - INFO: -geom_canvas: geom_canvas.geom - -grid a b c: 32 x 35 x 12 -size x y z: 0.914285714286 x 1.0 x 0.342857142857 -origin x y z: 0.0 x 0.0 x 0.0 -homogenization: 1 -# microstructures: 20 -max microstructures: 20 - - -2019-05-27 22:44:01,103 - DEBUG: - -2019-05-27 22:44:01,104 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_canvas_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_canvas.geom -2019-05-27 22:44:01,135 - INFO: -geom_clean -s 2 geom_clean.geom -2019-05-27 22:44:03,219 - INFO: -geom_clean: geom_clean.geom - -grid a b c: 53 x 52 x 52 -size x y z: 1.0 x 0.981132075472 x 0.981132075472 -origin x y z: 0.0 x 0.0 x 0.0 -homogenization: 1 -# microstructures: 23 -max microstructure: 23 - -2019-05-27 22:44:03,219 - DEBUG: - -2019-05-27 22:44:03,219 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_clean_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_clean.geom -2019-05-27 22:44:03,378 - INFO: -geom_grainGrowth -N2 -i 4 -d 2 geom_grainGrowth.geom -2019-05-27 22:44:04,065 - INFO: -geom_grainGrowth: geom_grainGrowth.geom - -grid a b c: 40 x 40 x 40 -size x y z: 1.0 x 1.0 x 1.0 -origin x y z: 0.0 x 0.0 x 0.0 -homogenization: 1 -# microstructures: 15 -max microstructures: 15 - -grid a b c: 40 x 40 x 40 -size x y z: 1.0 x 1.0 x 1.0 -origin x y z: 0.0 x 0.0 x 0.0 -homogenization: 1 -# microstructures: 15 -max microstructure: 15 - -2019-05-27 22:44:04,065 - DEBUG: - -2019-05-27 22:44:04,065 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_grainGrowth_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_grainGrowth.geom -2019-05-27 22:44:04,131 - INFO: -geom_mirror -d x,y,z --double geom_mirror.geom -2019-05-27 22:44:04,330 - INFO: -geom_mirror: geom_mirror.geom - -grid a b c: 32 x 35 x 12 -grid a b c: 64 x 70 x 24 -size x y z: 0.914285714286 x 1.0 x 0.342857142857 -size x y z: 2.0 x 2.0 x 2.0 -origin x y z: 0.0 x 0.0 x 0.0 -homogenization: 1 -# microstructures: 20 -max microstructure: 20 - -2019-05-27 22:44:04,331 - DEBUG: - -2019-05-27 22:44:04,331 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_mirror_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_mirror.geom -2019-05-27 22:44:04,447 - INFO: -geom_renumber geom_renumber.geom -2019-05-27 22:44:04,688 - INFO: -geom_renumber: geom_renumber.geom - -grid a b c: 53 x 52 x 52 -size x y z: 1.0 x 0.981132075472 x 0.981132075472 -origin x y z: 0.0 x 0.0 x 0.0 -homogenization: 1 -# microstructures: 23 -max microstructure: 42 -max microstructure: 23 - -2019-05-27 22:44:04,688 - DEBUG: - -2019-05-27 22:44:04,688 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_renumber_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_renumber.geom -2019-05-27 22:44:04,864 - INFO: -geom_rescale -g 20 22 20 -s 0.1 0.2 0.3 geom_rescale.geom -2019-05-27 22:44:05,109 - INFO: -geom_rescale: geom_rescale.geom - -grid a b c: 32 x 35 x 12 -grid a b c: 20 x 22 x 20 -size x y z: 0.914285714286 x 1.0 x 0.342857142857 -size x y z: 0.1 x 0.2 x 0.3 -origin x y z: 0.0 x 0.0 x 0.0 -homogenization: 1 -# microstructures: 20 -max microstructure: 20 - -2019-05-27 22:44:05,109 - DEBUG: - -2019-05-27 22:44:05,109 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_rescale_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_rescale.geom -2019-05-27 22:44:05,122 - INFO: -geom_rotate -d -e 45 45 0 geom_rotate.geom -2019-05-27 22:44:05,529 - INFO: -geom_rotate: geom_rotate.geom - -grid a b c: 53 x 52 x 52 -grid a b c: 90 x 90 x 74 -size x y z: 1.0 x 0.981132075472 x 0.981132075472 -size x y z: 1.6981132075471699 x 1.7307692307692308 x 1.4230769230769231 -origin x y z: 0.0 x 0.0 x 0.0 -homogenization: 1 -# microstructures: 23 -# microstructures: 24 -max microstructure: 23 -max microstructure: 24 - -2019-05-27 22:44:05,530 - DEBUG: - -2019-05-27 22:44:05,530 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_rotate_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_rotate.geom -2019-05-27 22:44:06,282 - INFO: -geom_translate -o 0 1 2 -m 6 geom_translate.geom -2019-05-27 22:44:06,469 - INFO: -geom_translate: geom_translate.geom - -grid a b c: 32 x 35 x 12 -size x y z: 0.914285714286 x 1.0 x 0.342857142857 -origin x y z: 0.0 x 0.0 x 0.0 -origin x y z: 0.0 x 1.0 x 2.0 -homogenization: 1 -# microstructures: 20 -max microstructure: 20 -max microstructure: 26 - -2019-05-27 22:44:06,469 - DEBUG: - -2019-05-27 22:44:06,469 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_translate_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_translate.geom -2019-05-27 22:44:06,486 - INFO: -geom_vicinityOffset -v 2 geom_vicinityOffset.geom -2019-05-27 22:44:07,005 - INFO: -geom_vicinityOffset: geom_vicinityOffset.geom - -grid a b c: 40 x 40 x 40 -size x y z: 1.0 x 1.0 x 1.0 -origin x y z: 0.0 x 0.0 x 0.0 -homogenization: 1 -# microstructures: 5 -# microstructures: 10 -max microstructure: 5 -max microstructure: 10 - -2019-05-27 22:44:07,005 - DEBUG: - -2019-05-27 22:44:07,005 - INFO: -comparing - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/reference/geom_vicinityOffset_reference.geom - /Users/philip/Documents/DAMASK/PRIVATE/testing/PreProcessing_GeomModification/current/geom_vicinityOffset.geom -2019-05-27 22:44:07,076 - CRITICAL: -**************************************** -All 10 tests passed. -**************************************** - From dfc2b47abc2a731ffd14bae2f5d16cf6eab5920d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 07:59:17 +0200 Subject: [PATCH 070/120] better readable --- processing/pre/geom_canvas.py | 102 ++++++++++++---------------------- 1 file changed, 35 insertions(+), 67 deletions(-) diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index 3b7071968..281555cef 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -1,110 +1,78 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np -import damask - from io import StringIO from optparse import OptionParser +import numpy as np + +import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [geomfile(s)]', description = """ -Changes the (three-dimensional) canvas of a spectral geometry description. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ +Increases or decreases the (three-dimensional) canvas. Grid can be given as absolute or relative values, e.g. 16 16 16 or 2x 0.5x 32. """, version = scriptID) -parser.add_option('-g', - '--grid', +parser.add_option('-g','--grid', dest = 'grid', type = 'string', nargs = 3, metavar = ' '.join(['string']*3), - help = 'a,b,c grid of hexahedral box. [auto]') -parser.add_option('-o', - '--offset', + help = 'a,b,c grid of hexahedral box') +parser.add_option('-o','--offset', dest = 'offset', type = 'int', nargs = 3, metavar = ' '.join(['int']*3), help = 'a,b,c offset from old to new origin of grid [%default]') -parser.add_option('-f', - '--fill', +parser.add_option('-f','--fill', dest = 'fill', - type = 'float', metavar = 'float', - help = '(background) canvas grain index. "0" selects maximum microstructure index + 1 [%default]') -parser.add_option('--blank', - dest = 'blank', - action = 'store_true', - help = 'blank out (optional) input canvas content') + type = 'float', metavar = 'int', + help = 'background microstructure index, defaults to max microstructure index + 1') -parser.set_defaults(grid = ['0','0','0'], - offset = (0,0,0), - ) +parser.set_defaults(offset = (0,0,0)) (options, filenames) = parser.parse_args() -options.grid = ['1','1','1'] if options.blank and options.grid == ['0','0','0'] else options.grid -options.fill = 1 if options.blank and options.fill is None else options.fill - -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None and options.blank: - grid = np.array(list(map(int,options.grid))) - geom = damask.Geom(size=grid,microstructure=options.fill*np.ones(grid)) + if name is None: + virt_file = StringIO(''.join(sys.stdin.read())) + geom = damask.Geom.from_file(virt_file) else: - geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - + geom = damask.Geom.from_file(name) grid = geom.get_grid() - size = geom.get_size() - origin = geom.get_origin() - microstructure = geom.get_microstructure() - fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill - dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int - - damask.util.croak(geom) -# --- do work ------------------------------------------------------------------------------------ - - new_grid = np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ - else int(n) for o,n in zip(grid,options.grid)],dtype=int) - new_grid = np.where(new_grid > 0, new_grid,grid) + if options.grid is not None: + for i,g in enumerate(options.grid): + grid[i] = int(round(grid[i]*float(g.lower().replace('x','')))) if g.lower().endswith('x') \ + else int(options.grid[i]) - microstructure_cropped = np.zeros(new_grid,dtype=dtype) - microstructure_cropped.fill(fill) + new = np.full(grid,options.fill if options.fill is not None else np.nanmax(geom.microstructure)+1, + geom.microstructure.dtype) - if not options.blank: - xindex = np.arange(max(options.offset[0],0),min(options.offset[0]+new_grid[0],grid[0])) - yindex = np.arange(max(options.offset[1],0),min(options.offset[1]+new_grid[1],grid[1])) - zindex = np.arange(max(options.offset[2],0),min(options.offset[2]+new_grid[2],grid[2])) - translate_x = [i - options.offset[0] for i in xindex] - translate_y = [i - options.offset[1] for i in yindex] - translate_z = [i - options.offset[2] for i in zindex] - if 0 in map(len,[xindex,yindex,zindex,translate_x,translate_y,translate_z]): - damask.util.croak('invaldid combination of grid and offset.') - continue - microstructure_cropped[min(translate_x):max(translate_x)+1, - min(translate_y):max(translate_y)+1, - min(translate_z):max(translate_z)+1] \ - = microstructure[min(xindex):max(xindex)+1, - min(yindex):max(yindex)+1, - min(zindex):max(zindex)+1] + for x in range(geom.microstructure.shape[0]): + X = x + options.offset[0] + if not 0 <= X < new.shape[0]: continue + for y in range(geom.microstructure.shape[1]): + Y = y + options.offset[1] + if not 0 <= Y < new.shape[1]: continue + for z in range(geom.microstructure.shape[2]): + Z = z + options.offset[2] + if not 0 <= Z < new.shape[2]: continue + new[X,Y,Z] = geom.microstructure[x,y,z] - new_size = size/grid*new_grid if np.all(grid > 0) else new_grid - new_origin = origin + (size/grid if np.all(grid > 0) else new_size/new_grid) * options.offset - - geom.set_microstructure(microstructure_cropped) - geom.set_size(new_size) - geom.set_origin(new_origin) + damask.util.croak(geom.update(new,rescale=True)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: From 6836a2eae875da33d134bb02b1c5d3b2e43e8943 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 08:04:01 +0200 Subject: [PATCH 071/120] better readable --- processing/pre/geom_canvas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index 281555cef..dd0a7eb86 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -58,8 +58,8 @@ for name in filenames: grid[i] = int(round(grid[i]*float(g.lower().replace('x','')))) if g.lower().endswith('x') \ else int(options.grid[i]) - new = np.full(grid,options.fill if options.fill is not None else np.nanmax(geom.microstructure)+1, - geom.microstructure.dtype) + new = np.full(grid,options.fill if options.fill is not None + else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) for x in range(geom.microstructure.shape[0]): X = x + options.offset[0] From 78f30684f83ae4cb09c1ddc39a5c01ad6782c50f Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 09:40:56 +0200 Subject: [PATCH 072/120] moderized needs some polishing with respect to array orders --- processing/pre/geom_fromOsteonGeometry.py | 194 +++++++++++----------- 1 file changed, 95 insertions(+), 99 deletions(-) diff --git a/processing/pre/geom_fromOsteonGeometry.py b/processing/pre/geom_fromOsteonGeometry.py index 4caffb25f..6b1ea3252 100755 --- a/processing/pre/geom_fromOsteonGeometry.py +++ b/processing/pre/geom_fromOsteonGeometry.py @@ -1,46 +1,66 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- -import os,sys,math -import numpy as np +import os +import sys +from io import StringIO from optparse import OptionParser + +import numpy as np + import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog [option(s)] [geomfile]', description = """ -Generate a geometry file of an osteon enclosing the Harvesian canal and separated by interstitial tissue. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile]', description = """ +Generate description of an osteon enclosing the Harvesian canal and separated by interstitial tissue. The osteon phase is lamellar with a twisted plywood structure. Its fiber orientation is oscillating by +/- amplitude within one period. """, version = scriptID) -parser.add_option('-g', '--grid', dest='grid', type='int', nargs=2, metavar = 'int int', +parser.add_option('-g', '--grid', + dest='grid', type='int', + nargs=2, metavar = 'int int', help='a,b grid of hexahedral box [%default]') -parser.add_option('-s', '--size', dest='size', type='float', nargs=2, metavar = 'float float', +parser.add_option('-s', '--size', + dest='size', + type='float', nargs=2, metavar = 'float float', help='x,y size of hexahedral box [%default]') -parser.add_option('-c', '--canal', dest='canal', type='float', metavar = 'float', +parser.add_option('-c', '--canal', + dest='canal', + type='float', metavar = 'float', help='Haversian canal radius [%default]') -parser.add_option('-o', '--osteon', dest='osteon', type='float', metavar = 'float', +parser.add_option('-o', '--osteon', + dest='osteon', + type='float', metavar = 'float', help='horizontal osteon radius [%default]') -parser.add_option('-l', '--lamella', dest='period', type='float', metavar = 'float', +parser.add_option('-l', '--lamella', + dest='period', + type='float', metavar = 'float', help='lamella width [%default]') -parser.add_option('-a', '--amplitude', dest='amplitude', type='float', metavar = 'float', +parser.add_option('-a', '--amplitude', + dest='amplitude', + type='float', metavar = 'float', help='amplitude of twisted plywood wiggle in deg [%default]') -parser.add_option( '--aspect', dest='aspect', type='float', metavar = 'float', +parser.add_option( '--aspect', + dest='aspect', + type='float', metavar = 'float', help='vertical/horizontal osteon aspect ratio [%default]') -parser.add_option('-w', '--omega', dest='omega', type='float', metavar = 'float', +parser.add_option('-w', '--omega', + dest='omega', + type='float', metavar = 'float', help='rotation angle around normal of osteon [%default]') -parser.add_option('--homogenization', dest='homogenization', type='int', metavar = 'int', +parser.add_option( '--homogenization', + dest='homogenization', + type='int', metavar = 'int', help='homogenization index to be used [%default]') -parser.add_option('--crystallite', dest='crystallite', type='int', metavar = 'int', - help='crystallite index to be used [%default]') parser.set_defaults(canal = 25e-6, osteon = 100e-6, @@ -50,107 +70,83 @@ parser.set_defaults(canal = 25e-6, amplitude = 60, size = (300e-6,300e-6), grid = (512,512), - homogenization = 1, - crystallite = 1) + homogenization = 1) (options,filename) = parser.parse_args() -if np.any(np.array(options.grid) < 2): - parser('invalid grid a b c.') -if np.any(np.array(options.size) <= 0.0): - parser('invalid size x y z.') -# --- open input files ---------------------------------------------------------------------------- +name = None if filename == [] else filename[0] +damask.util.report(scriptName,name) -if filename == []: filename = [None] - -table = damask.ASCIItable(outname = filename[0], - buffered = False, labeled=False) - -damask.util.report(scriptName,filename[0]) - -options.omega *= math.pi/180.0 # rescale ro radians -rotation = np.array([[ math.cos(options.omega),math.sin(options.omega),], - [-math.sin(options.omega),math.cos(options.omega),]],'d') +options.omega *= np.pi/180.0 # rescale ro radians +rotation = np.array([[ np.cos(options.omega),np.sin(options.omega),], + [-np.sin(options.omega),np.cos(options.omega),]],'d') box = np.dot(np.array([[options.canal,0.],[0.,options.aspect*options.canal]]).transpose(),rotation) +grid = np.array(options.grid,'i') +size = np.array(options.size,'d') -info = { - 'grid': np.ones(3,'i'), - 'size': np.ones(3,'d'), - 'origin': np.zeros(3,'d'), - 'microstructures': 3, - 'homogenization': options.homogenization, - } - -info['grid'][:2] = np.array(options.grid,'i') -info['size'][:2] = np.array(options.size,'d') -info['size'][2] = min(info['size'][0]/info['grid'][0],info['size'][1]/info['grid'][1]) -info['origin'] = -info['size']/2.0 - -X0 = info['size'][0]/info['grid'][0]*\ - (np.tile(np.arange(info['grid'][0]),(info['grid'][1],1)) - info['grid'][0]/2 + 0.5) -Y0 = info['size'][1]/info['grid'][1]*\ - (np.tile(np.arange(info['grid'][1]),(info['grid'][0],1)).transpose() - info['grid'][1]/2 + 0.5) +X0 = size[0]/grid[0]*\ + (np.tile(np.arange(grid[0]),(grid[1],1)) - grid[0]/2 + 0.5) +Y0 = size[1]/grid[1]*\ + (np.tile(np.arange(grid[1]),(grid[0],1)).transpose() - grid[1]/2 + 0.5) X = X0*rotation[0,0] + Y0*rotation[0,1] # rotate by omega Y = X0*rotation[1,0] + Y0*rotation[1,1] # rotate by omega radius = np.sqrt(X*X + Y*Y/options.aspect/options.aspect) alpha = np.degrees(np.arctan2(Y/options.aspect,X)) -beta = options.amplitude*np.sin(2.0*math.pi*(radius-options.canal)/options.period) +beta = options.amplitude*np.sin(2.0*np.pi*(radius-options.canal)/options.period) -microstructure = np.where(radius < float(options.canal),1,0) + np.where(radius > float(options.osteon),2,0) +microstructure = np.where(radius < float(options.canal), 1,0)\ + + np.where(radius > float(options.osteon),2,0) -alphaOfGrain = np.zeros(info['grid'][0]*info['grid'][1],'d') -betaOfGrain = np.zeros(info['grid'][0]*info['grid'][1],'d') -for y in range(info['grid'][1]): - for x in range(info['grid'][0]): - if microstructure[y,x] == 0: - microstructure[y,x] = info['microstructures'] - alphaOfGrain[info['microstructures']] = alpha[y,x] - betaOfGrain[ info['microstructures']] = beta[y,x] - info['microstructures'] += 1 +# extend to 3D +size = np.append(size,np.min(size/grid)) +grid = np.append(grid,1) +microstructure = microstructure.reshape(microstructure.shape+(1,)) -#--- report --------------------------------------------------------------------------------------- -damask.util.report_geom(info,['grid','size','origin','homogenization','microstructures']) +alphaOfGrain = np.zeros(grid[0]*grid[1],'d') +betaOfGrain = np.zeros(grid[0]*grid[1],'d') -formatwidth = 1+int(math.floor(math.log10(info['microstructures']-1))) -header = [scriptID + ' ' + ' '.join(sys.argv[1:])] -header.append('') -header.append('[canal]') -header.append('crystallite %i'%options.crystallite) -header.append('(constituent)\tphase 1\ttexture 1\tfraction 1.0') -header.append('[interstitial]') -header.append('crystallite %i'%options.crystallite) -header.append('(constituent)\tphase 2\ttexture 2\tfraction 1.0') -for i in range(3,info['microstructures']): - header.append('[Grain%s]'%(str(i).zfill(formatwidth))) - header.append('crystallite %i'%options.crystallite) - header.append('(constituent)\tphase 3\ttexture %s\tfraction 1.0'%(str(i).rjust(formatwidth))) +i = 3 +for x in range(grid[0]): + for y in range(grid[1]): + if microstructure[y,x] == 0: #ToDo: Wrong order (y and x are flipped) + microstructure[y,x] = i #ToDo: Wrong order (y and x are flipped) + alphaOfGrain[i] = alpha[y,x] + betaOfGrain[ i] = beta[y,x] + i+=1 -header.append('') -header.append('[canal]') -header.append('[interstitial]') -for i in range(3,info['microstructures']): - header.append('[Grain%s]'%(str(i).zfill(formatwidth))) - header.append('(gauss)\tphi1 %g\tPhi %g\tphi2 0\tscatter 0.0\tfraction 1.0'\ - %(alphaOfGrain[i],betaOfGrain[i])) -header.append([ - "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), - "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), - "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), - "homogenization\t{homog}".format(homog=info['homogenization']), - "microstructures\t{microstructures}".format(microstructures=info['microstructures'])]) +formatwidth = 1+int(np.floor(np.log10(np.nanmax(microstructure)-1))) +config_header = [] +config_header.append('') +config_header.append('[canal]') +config_header.append('crystallite 1') +config_header.append('(constituent)\tphase 1\ttexture 1\tfraction 1.0') +config_header.append('[interstitial]') +config_header.append('crystallite 1') +config_header.append('(constituent)\tphase 2\ttexture 2\tfraction 1.0') +for i in range(3,np.max(microstructure)): + config_header.append('[Grain%s]'%(str(i).zfill(formatwidth))) + config_header.append('crystallite 1') + config_header.append('(constituent)\tphase 3\ttexture %s\tfraction 1.0'%(str(i).rjust(formatwidth))) + +config_header.append('') +config_header.append('[canal]') +config_header.append('[interstitial]') +for i in range(3,np.max(microstructure)): + config_header.append('[Grain%s]'%(str(i).zfill(formatwidth))) + config_header.append('(gauss)\tphi1 %g\tPhi %g\tphi2 0'%(alphaOfGrain[i],betaOfGrain[i])) + +header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header +geom = damask.Geom(microstructure.reshape(grid), + size,-size/2, + homogenization=options.homogenization,comments=header) +damask.util.croak(geom) -table.info_append(header) -table.head_write() - -# --- write microstructure information ------------------------------------------------------------ - -table.data = microstructure.reshape(info['grid'][1]*info['grid'][2],info['grid'][0]) -table.data_writeArray('%%%ii'%(formatwidth),delimiter=' ') - -#--- output finalization -------------------------------------------------------------------------- -table.close() +if name is None: + sys.stdout.write(str(geom.show())) +else: + geom.to_file(name) From 16bd5294aae33646d0cb669d37ec92393e242372 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 14:06:39 +0200 Subject: [PATCH 073/120] loop order as intented --- processing/pre/geom_fromOsteonGeometry.py | 30 ++++++++++------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/processing/pre/geom_fromOsteonGeometry.py b/processing/pre/geom_fromOsteonGeometry.py index 6b1ea3252..e7f8414a6 100755 --- a/processing/pre/geom_fromOsteonGeometry.py +++ b/processing/pre/geom_fromOsteonGeometry.py @@ -78,24 +78,20 @@ parser.set_defaults(canal = 25e-6, name = None if filename == [] else filename[0] damask.util.report(scriptName,name) -options.omega *= np.pi/180.0 # rescale ro radians -rotation = np.array([[ np.cos(options.omega),np.sin(options.omega),], - [-np.sin(options.omega),np.cos(options.omega),]],'d') - -box = np.dot(np.array([[options.canal,0.],[0.,options.aspect*options.canal]]).transpose(),rotation) +omega = np.deg2rad(options.omega) +rotation = np.array([[ np.cos(omega),np.sin(omega),], + [-np.sin(omega),np.cos(omega),]]) grid = np.array(options.grid,'i') size = np.array(options.size,'d') -X0 = size[0]/grid[0]*\ - (np.tile(np.arange(grid[0]),(grid[1],1)) - grid[0]/2 + 0.5) -Y0 = size[1]/grid[1]*\ - (np.tile(np.arange(grid[1]),(grid[0],1)).transpose() - grid[1]/2 + 0.5) +X0,Y0 = np.meshgrid(size[0]/grid[0] * (np.arange(grid[0]) - grid[0]/2 + 0.5), + size[1]/grid[0] * (np.arange(grid[1]) - grid[1]/2 + 0.5), indexing='ij') X = X0*rotation[0,0] + Y0*rotation[0,1] # rotate by omega Y = X0*rotation[1,0] + Y0*rotation[1,1] # rotate by omega -radius = np.sqrt(X*X + Y*Y/options.aspect/options.aspect) +radius = np.sqrt(X*X + Y*Y/options.aspect**2.0) alpha = np.degrees(np.arctan2(Y/options.aspect,X)) beta = options.amplitude*np.sin(2.0*np.pi*(radius-options.canal)/options.period) @@ -111,12 +107,12 @@ alphaOfGrain = np.zeros(grid[0]*grid[1],'d') betaOfGrain = np.zeros(grid[0]*grid[1],'d') i = 3 -for x in range(grid[0]): - for y in range(grid[1]): - if microstructure[y,x] == 0: #ToDo: Wrong order (y and x are flipped) - microstructure[y,x] = i #ToDo: Wrong order (y and x are flipped) - alphaOfGrain[i] = alpha[y,x] - betaOfGrain[ i] = beta[y,x] +for y in range(grid[1]): + for x in range(grid[0]): + if microstructure[x,y] == 0: + microstructure[x,y] = i + alphaOfGrain[i] = alpha[x,y] + betaOfGrain[ i] = beta[x,y] i+=1 formatwidth = 1+int(np.floor(np.log10(np.nanmax(microstructure)-1))) @@ -137,7 +133,7 @@ config_header.append('') config_header.append('[canal]') config_header.append('[interstitial]') for i in range(3,np.max(microstructure)): - config_header.append('[Grain%s]'%(str(i).zfill(formatwidth))) + config_header.append('[Point%s]'%(str(i-2).zfill(formatwidth))) config_header.append('(gauss)\tphi1 %g\tPhi %g\tphi2 0'%(alphaOfGrain[i],betaOfGrain[i])) header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header From d7e8a66746c627fb5ece927a526bbe0e89f153c0 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 14:18:11 +0200 Subject: [PATCH 074/120] polishing --- processing/pre/geom_fromOsteonGeometry.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/processing/pre/geom_fromOsteonGeometry.py b/processing/pre/geom_fromOsteonGeometry.py index e7f8414a6..9281eb95b 100755 --- a/processing/pre/geom_fromOsteonGeometry.py +++ b/processing/pre/geom_fromOsteonGeometry.py @@ -95,7 +95,7 @@ radius = np.sqrt(X*X + Y*Y/options.aspect**2.0) alpha = np.degrees(np.arctan2(Y/options.aspect,X)) beta = options.amplitude*np.sin(2.0*np.pi*(radius-options.canal)/options.period) -microstructure = np.where(radius < float(options.canal), 1,0)\ +microstructure = np.where(radius < float(options.canal), 1,0) \ + np.where(radius > float(options.osteon),2,0) # extend to 3D @@ -103,16 +103,16 @@ size = np.append(size,np.min(size/grid)) grid = np.append(grid,1) microstructure = microstructure.reshape(microstructure.shape+(1,)) -alphaOfGrain = np.zeros(grid[0]*grid[1],'d') -betaOfGrain = np.zeros(grid[0]*grid[1],'d') +Alpha = np.zeros(grid[0]*grid[1],'d') +Beta = np.zeros(grid[0]*grid[1],'d') i = 3 for y in range(grid[1]): for x in range(grid[0]): if microstructure[x,y] == 0: microstructure[x,y] = i - alphaOfGrain[i] = alpha[x,y] - betaOfGrain[ i] = beta[x,y] + Alpha[i] = alpha[x,y] + Beta[ i] = beta[x,y] i+=1 formatwidth = 1+int(np.floor(np.log10(np.nanmax(microstructure)-1))) @@ -125,7 +125,7 @@ config_header.append('[interstitial]') config_header.append('crystallite 1') config_header.append('(constituent)\tphase 2\ttexture 2\tfraction 1.0') for i in range(3,np.max(microstructure)): - config_header.append('[Grain%s]'%(str(i).zfill(formatwidth))) + config_header.append('[Point%s]'%(str(i-2).zfill(formatwidth))) config_header.append('crystallite 1') config_header.append('(constituent)\tphase 3\ttexture %s\tfraction 1.0'%(str(i).rjust(formatwidth))) @@ -134,7 +134,7 @@ config_header.append('[canal]') config_header.append('[interstitial]') for i in range(3,np.max(microstructure)): config_header.append('[Point%s]'%(str(i-2).zfill(formatwidth))) - config_header.append('(gauss)\tphi1 %g\tPhi %g\tphi2 0'%(alphaOfGrain[i],betaOfGrain[i])) + config_header.append('(gauss)\tphi1 %g\tPhi %g\tphi2 0'%(Alpha[i],Beta[i])) header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header geom = damask.Geom(microstructure.reshape(grid), From 6e790e845a4c3b3bc0ff56c7b4c1474caea35f7e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 19:36:02 +0200 Subject: [PATCH 075/120] correct rescaling --- python/damask/geom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 4428a2f6b..13ff5232f 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -40,7 +40,7 @@ class Geom(): raise ValueError('Either set size explicitly or rescale automatically') self.set_microstructure(microstructure) - self.set_size(self.get_grid()/grid_old if rescale else size) + self.set_size(self.get_grid()/grid_old*self.size if rescale else size) self.set_origin(origin) message = ['grid a b c: {}'.format(' x '.join(map(str,grid_old)))] From fd9801ba09522ec350b3b370230dcdc19a52569e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 29 May 2019 19:43:36 +0200 Subject: [PATCH 076/120] StringIO not needed --- processing/pre/geom_fromOsteonGeometry.py | 1 - 1 file changed, 1 deletion(-) diff --git a/processing/pre/geom_fromOsteonGeometry.py b/processing/pre/geom_fromOsteonGeometry.py index 9281eb95b..02cbd0be5 100755 --- a/processing/pre/geom_fromOsteonGeometry.py +++ b/processing/pre/geom_fromOsteonGeometry.py @@ -2,7 +2,6 @@ import os import sys -from io import StringIO from optparse import OptionParser import numpy as np From 17168525b6430fd0c9b3f3cbbc226e70f2d6f75f Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 29 May 2019 17:43:51 -0600 Subject: [PATCH 077/120] use srepr in __repr__ --- python/damask/geom.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 13ff5232f..8ea31643a 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -20,13 +20,14 @@ class Geom(): def __repr__(self): """Basic information on geometry definition""" - return 'grid a b c: {}\n'.format(' x '.join(map(str,self.get_grid ()))) + \ - 'size x y z: {}\n'.format(' x '.join(map(str,self.get_size ()))) + \ - 'origin x y z: {}\n'.format(' x '.join(map(str,self.get_origin()))) + \ - 'homogenization: {}\n'.format(self.get_homogenization()) + \ - '# microstructures: {}\n'.format(len(np.unique(self.microstructure))) + \ - 'max microstructures: {}\n'.format(np.nanmax(self.microstructure)) - + return util.srepr([ + 'grid a b c: {}'.format(' x '.join(map(str,self.get_grid ()))), + 'size x y z: {}'.format(' x '.join(map(str,self.get_size ()))), + 'origin x y z: {}'.format(' x '.join(map(str,self.get_origin()))), + 'homogenization: {}'.format(self.get_homogenization()), + '# microstructures: {}'.format(len(np.unique(self.microstructure))), + 'max microstructure: {}'.format(np.nanmax(self.microstructure)), + ]) def update(self,microstructure=None,size=None,origin=None,rescale=False): """Updates microstructure and size""" From d79f0c6290db7be672081181133a837dee6e155a Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 29 May 2019 17:53:45 -0600 Subject: [PATCH 078/120] replace geom_canvas --blank with geom_fromScratch --- PRIVATE | 2 +- processing/pre/geom_canvas.py | 92 ++++++++++++++++++------------ processing/pre/geom_fromScratch.py | 74 ++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 37 deletions(-) create mode 100755 processing/pre/geom_fromScratch.py diff --git a/PRIVATE b/PRIVATE index d59698231..36b3a1b44 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit d596982319b5e8bbded6c14a5724df6c9de2a0fd +Subproject commit 36b3a1b44a71574e2b5dce93ed25963e9fe3e74a diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index dd0a7eb86..0b5675d75 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -1,78 +1,98 @@ #!/usr/bin/env python3 +# -*- coding: UTF-8 no BOM -*- import os import sys +import numpy as np +import damask + from io import StringIO from optparse import OptionParser -import numpy as np - -import damask - scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) - # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ -Increases or decreases the (three-dimensional) canvas. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [geomfile(s)]', description = """ +Changes the (three-dimensional) canvas of a spectral geometry description. Grid can be given as absolute or relative values, e.g. 16 16 16 or 2x 0.5x 32. """, version = scriptID) -parser.add_option('-g','--grid', +parser.add_option('-g', + '--grid', dest = 'grid', type = 'string', nargs = 3, metavar = ' '.join(['string']*3), - help = 'a,b,c grid of hexahedral box') -parser.add_option('-o','--offset', + help = 'a,b,c grid of hexahedral box. [auto]') +parser.add_option('-o', + '--offset', dest = 'offset', type = 'int', nargs = 3, metavar = ' '.join(['int']*3), help = 'a,b,c offset from old to new origin of grid [%default]') -parser.add_option('-f','--fill', +parser.add_option('-f', + '--fill', dest = 'fill', - type = 'float', metavar = 'int', - help = 'background microstructure index, defaults to max microstructure index + 1') + type = 'float', metavar = 'float', + help = '(background) canvas grain index. "0" selects maximum microstructure index + 1 [%default]') -parser.set_defaults(offset = (0,0,0)) +parser.set_defaults(grid = ['0','0','0'], + offset = (0,0,0), + ) (options, filenames) = parser.parse_args() +# --- loop over input files ------------------------------------------------------------------------- + if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - if name is None: - virt_file = StringIO(''.join(sys.stdin.read())) - geom = damask.Geom.from_file(virt_file) - else: - geom = damask.Geom.from_file(name) + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + grid = geom.get_grid() + size = geom.get_size() + origin = geom.get_origin() + microstructure = geom.get_microstructure() + fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill + dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int - if options.grid is not None: - for i,g in enumerate(options.grid): - grid[i] = int(round(grid[i]*float(g.lower().replace('x','')))) if g.lower().endswith('x') \ - else int(options.grid[i]) +# --- do work ------------------------------------------------------------------------------------ + + new_grid = np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ + else int(n) for o,n in zip(grid,options.grid)],dtype=int) + new_grid = np.where(new_grid > 0, new_grid,grid) - new = np.full(grid,options.fill if options.fill is not None - else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) + microstructure_cropped = np.zeros(new_grid,dtype=dtype) + microstructure_cropped.fill(fill) - for x in range(geom.microstructure.shape[0]): - X = x + options.offset[0] - if not 0 <= X < new.shape[0]: continue - for y in range(geom.microstructure.shape[1]): - Y = y + options.offset[1] - if not 0 <= Y < new.shape[1]: continue - for z in range(geom.microstructure.shape[2]): - Z = z + options.offset[2] - if not 0 <= Z < new.shape[2]: continue - new[X,Y,Z] = geom.microstructure[x,y,z] + xindex = np.arange(max(options.offset[0],0),min(options.offset[0]+new_grid[0],grid[0])) + yindex = np.arange(max(options.offset[1],0),min(options.offset[1]+new_grid[1],grid[1])) + zindex = np.arange(max(options.offset[2],0),min(options.offset[2]+new_grid[2],grid[2])) + translate_x = [i - options.offset[0] for i in xindex] + translate_y = [i - options.offset[1] for i in yindex] + translate_z = [i - options.offset[2] for i in zindex] + if 0 in map(len,[xindex,yindex,zindex,translate_x,translate_y,translate_z]): + damask.util.croak('invaldid combination of grid and offset.') + continue + microstructure_cropped[min(translate_x):max(translate_x)+1, + min(translate_y):max(translate_y)+1, + min(translate_z):max(translate_z)+1] \ + = microstructure[min(xindex):max(xindex)+1, + min(yindex):max(yindex)+1, + min(zindex):max(zindex)+1] - damask.util.croak(geom.update(new,rescale=True)) + new_size = size/grid*new_grid if np.all(grid > 0) else new_grid + new_origin = origin + (size/grid if np.all(grid > 0) else new_size/new_grid) * options.offset + + damask.util.croak(geom.update(microstructure=microstructure_cropped, + size=new_size, + origin=new_origin, + )) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: diff --git a/processing/pre/geom_fromScratch.py b/processing/pre/geom_fromScratch.py new file mode 100755 index 000000000..822a7f5f2 --- /dev/null +++ b/processing/pre/geom_fromScratch.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# -*- coding: UTF-8 no BOM -*- + +import os +import sys +import numpy as np +import damask + +from optparse import OptionParser + +scriptName = os.path.splitext(os.path.basename(__file__))[0] +scriptID = ' '.join([scriptName,damask.version]) + +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- + +parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [geomfile(s)]', description = """ +Generate homogeneous geometry. + +""", version = scriptID) + +parser.add_option('-g', + '--grid', + dest = 'grid', + type = 'string', nargs = 3, metavar = ' '.join(['string']*3), + help = 'a,b,c grid of hexahedral box %default') +parser.add_option('-s', + '--size', + dest = 'size', + type = 'float', nargs = 3, metavar = ' '.join(['float']*3), + help = 'x,y,z of geometry size %default') +parser.add_option('-o', + '--origin', + dest = 'origin', + type = 'float', nargs = 3, metavar = ' '.join(['float']*3), + help = 'x,y,z of geometry origin %default') +parser.add_option('--homogenization', + dest = 'homogenization', + type = 'int', metavar = 'int', + help = 'homogenization index [%default]') +parser.add_option('-f', + '--fill', + dest = 'fill', + type = 'float', metavar = 'float', + help = 'microstructure index [%default]') + +parser.set_defaults(grid = [16,16,16], + size = [1.,1.,1.], + origin = [0.,0.,0.], + homogenization = 1, + fill = 1, + ) + +(options, filenames) = parser.parse_args() + +dtype = float if np.isnan(options.fill) or int(options.fill) != options.fill else int +grid = list(map( int,options.grid)) +size = list(map(float,options.size)) +origin = list(map(float,options.origin)) +homogenization = int(options.homogenization) +fill = float(options.fill) + +damask.util.report(scriptName,'') + +geom = damask.Geom(microstructure=(fill * np.ones(grid)).astype(dtype), + size=size, + origin=origin, + homogenization=homogenization, + comments=scriptID + ' ' + ' '.join(sys.argv[1:])) + +damask.util.croak(geom) + +sys.stdout.write(str(geom.show())) From cdc8338347ff0fa5cfde1590e981da64bb6c2061 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 29 May 2019 20:22:29 -0600 Subject: [PATCH 079/120] full (not periodic) mirroring is geom_mirror default behavior --- processing/pre/geom_mirror.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index 7933e416c..1266cd29b 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -23,27 +23,29 @@ Mirror along given directions. """, version=scriptID) +validDirections = ['x','y','z'] + parser.add_option('-d','--direction', dest = 'directions', action = 'extend', metavar = '', - help = "directions in which to mirror {'x','y','z'}") -parser.add_option( '--double', - dest = 'double', + help = "directions in which to mirror {{{}}}".format(','.join(validDirections))) +parser.add_option( '--periodic', + dest = 'periodic', action = 'store_true', - help = 'double the outer layers in mirror direction') + help = 'omit periodic copies of outermost layers in mirror direction') + +parser.set_defaults(periodic = False) (options, filenames) = parser.parse_args() if options.directions is None: parser.error('no direction given.') -validDirections = ['x','y','z'] if not set(options.directions).issubset(validDirections): invalidDirections = [str(e) for e in set(options.directions).difference(validDirections)] parser.error('invalid directions {}. '.format(*invalidDirections)) -limits = [-2,0] if not options.double else [None,None] - +limits = [-2,0] if options.periodic else [None,None] if filenames == []: filenames = [None] From c5daa7e577b6c67b861da5948eab18b9ae8d6782 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 09:19:16 +0200 Subject: [PATCH 080/120] update tests -using separte PRIVATE branch geometry-class, not master --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index 36b3a1b44..78641eab9 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 36b3a1b44a71574e2b5dce93ed25963e9fe3e74a +Subproject commit 78641eab9dd03d2b11c4d2a2ecb222822fbbb2a9 From f30eda0267e84d8545362ab35372b7ef95db6550 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 09:31:14 +0200 Subject: [PATCH 081/120] no need to loop over files will procude the same file over and over again --- processing/pre/geom_fromMinimalSurface.py | 40 +++++++++++------------ processing/pre/geom_mirror.py | 2 +- python/damask/geom.py | 3 +- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/processing/pre/geom_fromMinimalSurface.py b/processing/pre/geom_fromMinimalSurface.py index 787b0628b..db3592739 100755 --- a/processing/pre/geom_fromMinimalSurface.py +++ b/processing/pre/geom_fromMinimalSurface.py @@ -70,30 +70,28 @@ parser.set_defaults(type = minimal_surfaces[0], microstructure = (1,2), ) -(options,filenames) = parser.parse_args() +(options,filename) = parser.parse_args() -if filenames == []: filenames = [None] +name = None if filename == [] else filename[0] +damask.util.report(scriptName,name) -for name in filenames: - damask.util.report(scriptName,name) +X = options.periods*2.0*np.pi*(np.arange(options.grid[0])+0.5)/options.grid[0] +Y = options.periods*2.0*np.pi*(np.arange(options.grid[1])+0.5)/options.grid[1] +Z = options.periods*2.0*np.pi*(np.arange(options.grid[2])+0.5)/options.grid[2] - X = options.periods*2.0*np.pi*(np.arange(options.grid[0])+0.5)/options.grid[0] - Y = options.periods*2.0*np.pi*(np.arange(options.grid[1])+0.5)/options.grid[1] - Z = options.periods*2.0*np.pi*(np.arange(options.grid[2])+0.5)/options.grid[2] - - microstructure = np.empty(options.grid,dtype=int) - for x in range(options.grid[0]): - for y in range(options.grid[1]): - for z in range(options.grid[2]): - microstructure[x,y,z]=options.microstructure[int(options.threshold < surface[options.type](X[x],Y[y],Z[z]))] +microstructure = np.empty(options.grid,dtype=int) +for x in range(options.grid[0]): + for y in range(options.grid[1]): + for z in range(options.grid[2]): + microstructure[x,y,z]=options.microstructure[int(options.threshold < surface[options.type](X[x],Y[y],Z[z]))] - geom=damask.Geom(microstructure,options.size, - homogenization=options.homogenization, - comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) +geom=damask.Geom(microstructure,options.size, + homogenization=options.homogenization, + comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) - damask.util.croak(geom) - if name is None: - sys.stdout.write(str(geom.show())) - else: - geom.to_file(name) +damask.util.croak(geom) +if name is None: + sys.stdout.write(str(geom.show())) +else: + geom.to_file(name) diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index 1266cd29b..e6b29ae5c 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -23,7 +23,7 @@ Mirror along given directions. """, version=scriptID) -validDirections = ['x','y','z'] +validDirections = ['x','y','z'] parser.add_option('-d','--direction', dest = 'directions', diff --git a/python/damask/geom.py b/python/damask/geom.py index 8ea31643a..1d0161ebb 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -1,4 +1,3 @@ -import math from io import StringIO import numpy as np @@ -193,7 +192,7 @@ class Geom(): """Writes to file""" header = self.get_header() grid = self.get_grid() - format_string = '%{}i'.format(int(math.floor(math.log10(self.microstructure.max())+1))) if self.microstructure.dtype == int \ + format_string = '%{}i'.format(1+int(np.floor(np.log10(np.nanmax(self.microstructure)-1)))) if self.microstructure.dtype == int \ else '%g' np.savetxt(fname, self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T, From 4e0e5a23299ef9f5c8be78266fe2c9ecef50edd6 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 09:41:22 +0200 Subject: [PATCH 082/120] new python formatting style --- processing/pre/geom_fromOsteonGeometry.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/processing/pre/geom_fromOsteonGeometry.py b/processing/pre/geom_fromOsteonGeometry.py index 02cbd0be5..af778020f 100755 --- a/processing/pre/geom_fromOsteonGeometry.py +++ b/processing/pre/geom_fromOsteonGeometry.py @@ -111,10 +111,9 @@ for y in range(grid[1]): if microstructure[x,y] == 0: microstructure[x,y] = i Alpha[i] = alpha[x,y] - Beta[ i] = beta[x,y] + Beta [i] = beta [x,y] i+=1 -formatwidth = 1+int(np.floor(np.log10(np.nanmax(microstructure)-1))) config_header = [] config_header.append('') config_header.append('[canal]') @@ -124,16 +123,16 @@ config_header.append('[interstitial]') config_header.append('crystallite 1') config_header.append('(constituent)\tphase 2\ttexture 2\tfraction 1.0') for i in range(3,np.max(microstructure)): - config_header.append('[Point%s]'%(str(i-2).zfill(formatwidth))) + config_header.append('[Point{}]'.format(i-2)) config_header.append('crystallite 1') - config_header.append('(constituent)\tphase 3\ttexture %s\tfraction 1.0'%(str(i).rjust(formatwidth))) + config_header.append('(constituent)\tphase 3\ttexture {}\tfraction 1.0'.format(i)) config_header.append('') config_header.append('[canal]') config_header.append('[interstitial]') for i in range(3,np.max(microstructure)): - config_header.append('[Point%s]'%(str(i-2).zfill(formatwidth))) - config_header.append('(gauss)\tphi1 %g\tPhi %g\tphi2 0'%(Alpha[i],Beta[i])) + config_header.append('[Point{}]'.format(i-2)) + config_header.append('(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 0'.format(Alpha[i],Beta[i])) header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header geom = damask.Geom(microstructure.reshape(grid), From 73df615ff34b77e3822eb395aa46e240d91c25df Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 09:44:40 +0200 Subject: [PATCH 083/120] numpy meshgrid can do this now --- .../pre/geom_fromVoronoiTessellation.py | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 46533fdc5..6ab8651bd 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -10,28 +10,11 @@ from scipy import spatial import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) -def meshgrid2(*arrs): - """Code inspired by http://stackoverflow.com/questions/1827489/numpy-meshgrid-in-3d""" - arrs = tuple(reversed(arrs)) - lens = np.array(list(map(len, arrs))) - dim = len(arrs) - ans = [] - for i, arr in enumerate(arrs): - slc = np.ones(dim,'i') - slc[i] = lens[i] - arr2 = np.asarray(arr).reshape(slc) - for j, sz in enumerate(lens): - if j != i: - arr2 = arr2.repeat(sz, axis=j) - - ans.insert(0,arr2) - return tuple(ans) - - def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, cpus = 2): def findClosestSeed(fargs): @@ -284,14 +267,14 @@ for name in filenames: x = (np.arange(info['grid'][0])+0.5)*info['size'][0]/info['grid'][0] y = (np.arange(info['grid'][1])+0.5)*info['size'][1]/info['grid'][1] z = (np.arange(info['grid'][2])+0.5)*info['size'][2]/info['grid'][2] + X,Y,Z = np.meshgrid(x, y, z,indexing='ij') + grid = np.stack((X,Y,Z),axis=-1).reshape((info['grid'].prod(),3),order='F') damask.util.croak('tessellating...') - - grid = np.vstack(meshgrid2(x, y, z)).reshape(3,-1).T indices = laguerreTessellation(grid, coords, weights, grains, options.periodic, options.cpus) config_header = [] - formatwidth = 1+int(np.log10(NgrainIDs)) + formatwidth = 1+int(np.floor(np.log10(np.nanmax(NgrainIDs)-1))) if options.config: config_header += [''] @@ -302,16 +285,17 @@ for name in filenames: ] if hasEulers: config_header += [''] - theAxes = [] if options.axes is None else ['axes\t{} {} {}'.format(*options.axes)] for ID in grainIDs: eulerID = np.nonzero(grains == ID)[0][0] # find first occurrence of this grain id config_header += ['[Grain{}]'.format(str(ID).zfill(formatwidth)), '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}'.format(*eulers[eulerID]) - ] + theAxes + ] + if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] config_header += [''] - header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header + ['origin x {} y {} z {}'.format(*info['origin'])] - geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'], + header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ + + config_header + geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'],info['origin'], homogenization=options.homogenization,comments=header) damask.util.croak(geom) From 07276d511cceca86950ef5662162a8ddf726ce0b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 10:03:55 +0200 Subject: [PATCH 084/120] modern python formatting - 2 digits should be precise enough for euler angles - no need to pad grain ID with leading zeros --- processing/pre/geom_fromVoronoiTessellation.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 6ab8651bd..03880267f 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -274,21 +274,19 @@ for name in filenames: indices = laguerreTessellation(grid, coords, weights, grains, options.periodic, options.cpus) config_header = [] - formatwidth = 1+int(np.floor(np.log10(np.nanmax(NgrainIDs)-1))) - if options.config: config_header += [''] - for i,ID in enumerate(grainIDs): - config_header += ['[Grain{}]'.format(str(ID).zfill(formatwidth)), + for ID in grainIDs: + config_header += ['[Grain{}]'.format(ID), 'crystallite 1', - '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(options.phase,str(ID).rjust(formatwidth)), + '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(options.phase,ID) ] if hasEulers: config_header += [''] for ID in grainIDs: eulerID = np.nonzero(grains == ID)[0][0] # find first occurrence of this grain id - config_header += ['[Grain{}]'.format(str(ID).zfill(formatwidth)), - '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}'.format(*eulers[eulerID]) + config_header += ['[Grain{}]'.format(ID), + '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*eulers[eulerID]) ] if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] config_header += [''] From 931fa9d36a855149daef6e0e3507f9b73e1cecdd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 10:20:07 +0200 Subject: [PATCH 085/120] standardized and cleaned -write to file if given -type casting is done in the geom class --- processing/pre/geom_fromScratch.py | 58 ++++++++++++++---------------- python/damask/geom.py | 2 +- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/processing/pre/geom_fromScratch.py b/processing/pre/geom_fromScratch.py index 822a7f5f2..b76e0012a 100755 --- a/processing/pre/geom_fromScratch.py +++ b/processing/pre/geom_fromScratch.py @@ -1,37 +1,36 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys +from optparse import OptionParser + import numpy as np + import damask -from optparse import OptionParser scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [geomfile(s)]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ Generate homogeneous geometry. """, version = scriptID) -parser.add_option('-g', - '--grid', +parser.add_option('-g','--grid', dest = 'grid', - type = 'string', nargs = 3, metavar = ' '.join(['string']*3), + type = 'int', nargs = 3, metavar = ' '.join(['int']*3), help = 'a,b,c grid of hexahedral box %default') -parser.add_option('-s', - '--size', +parser.add_option('-s', '--size', dest = 'size', type = 'float', nargs = 3, metavar = ' '.join(['float']*3), help = 'x,y,z of geometry size %default') -parser.add_option('-o', - '--origin', +parser.add_option('-o','--origin', dest = 'origin', type = 'float', nargs = 3, metavar = ' '.join(['float']*3), help = 'x,y,z of geometry origin %default') @@ -39,36 +38,33 @@ parser.add_option('--homogenization', dest = 'homogenization', type = 'int', metavar = 'int', help = 'homogenization index [%default]') -parser.add_option('-f', - '--fill', +parser.add_option('-f','--fill', dest = 'fill', - type = 'float', metavar = 'float', + type = 'float', metavar = 'int', help = 'microstructure index [%default]') -parser.set_defaults(grid = [16,16,16], - size = [1.,1.,1.], - origin = [0.,0.,0.], +parser.set_defaults(grid = (16,16,16), + size = (1.,1.,1.), + origin = (0.,0.,0.), homogenization = 1, fill = 1, ) -(options, filenames) = parser.parse_args() +(options, filename) = parser.parse_args() + + +name = None if filename == [] else filename[0] +damask.util.report(scriptName,name) dtype = float if np.isnan(options.fill) or int(options.fill) != options.fill else int -grid = list(map( int,options.grid)) -size = list(map(float,options.size)) -origin = list(map(float,options.origin)) -homogenization = int(options.homogenization) -fill = float(options.fill) - -damask.util.report(scriptName,'') - -geom = damask.Geom(microstructure=(fill * np.ones(grid)).astype(dtype), - size=size, - origin=origin, - homogenization=homogenization, +geom = damask.Geom(microstructure=np.full(options.grid,options.fill,dtype=dtype), + size=options.size, + origin=options.origin, + homogenization=options.homogenization, comments=scriptID + ' ' + ' '.join(sys.argv[1:])) - damask.util.croak(geom) -sys.stdout.write(str(geom.show())) +if name is None: + sys.stdout.write(str(geom.show())) +else: + geom.to_file(name) diff --git a/python/damask/geom.py b/python/damask/geom.py index 1d0161ebb..397684fe1 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -192,7 +192,7 @@ class Geom(): """Writes to file""" header = self.get_header() grid = self.get_grid() - format_string = '%{}i'.format(1+int(np.floor(np.log10(np.nanmax(self.microstructure)-1)))) if self.microstructure.dtype == int \ + format_string = '%{}i'.format(1+int(np.floor(np.log10(np.nanmax(self.microstructure))))) if self.microstructure.dtype == int \ else '%g' np.savetxt(fname, self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T, From 510b55df504c4c4935d17a2c8e848e6b97ee2f7c Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 10:31:27 +0200 Subject: [PATCH 086/120] several improvements - more error checking - order of points can be arbitrary also for microstructure input - grouping of same orientation/phase combinations --- processing/pre/geom_fromTable.py | 86 ++++++++++++-------------------- 1 file changed, 31 insertions(+), 55 deletions(-) mode change 100755 => 100644 processing/pre/geom_fromTable.py diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py old mode 100755 new mode 100644 index b5d5c220c..0a32836c2 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -54,12 +54,14 @@ parser.set_defaults(homogenization = 1, (options,filenames) = parser.parse_args() -input = [ options.quaternion is not None, +input = [options.quaternion is not None, options.microstructure is not None, ] if np.sum(input) != 1: - parser.error('need either microstructure label or exactly one orientation input format.') + parser.error('need either microstructure or quaternion (and optionally phase) as input.') +if options.microstructure is not None and options.phase is not None: + parser.error('need either microstructure or phase (and mandatory quaternion) as input.') if options.axes is not None and not set(options.axes).issubset(set(['x','+x','-x','y','+y','-y','z','+z','-z'])): parser.error('invalid axes {} {} {}.'.format(*options.axes)) @@ -105,73 +107,47 @@ for name in filenames: mincorner = np.array(list(map(min,coords))) origin = mincorner - 0.5*size/grid # shift from cell center to corner - -# ------------------------------------------ process data ------------------------------------------ - - colOri = table.label_index(label)+(3-coordDim) # column(s) of orientation data followed by 3 coordinates + indices = np.lexsort((table.data[:,0],table.data[:,1],table.data[:,2])) # indices of position when sorting x fast, z slow + microstructure = np.empty(grid,dtype = int) # initialize empty microstructure + i = 0 + if inputtype == 'microstructure': - - grain = table.data[:,colOri] - nGrains = len(np.unique(grain)) - - elif inputtype == 'quaternion': - - colPhase = -1 # column of phase data comes last - index = np.lexsort((table.data[:,0],table.data[:,1],table.data[:,2])) # index of position when sorting x fast, z slow - grain = -np.ones(grid.prod(),dtype = int) # initialize empty microstructure - orientations = [] # orientations - multiplicity = [] # orientation multiplicity (number of group members) - phases = [] # phase info - nGrains = 0 # counter for detected grains - existingGrains = np.arange(nGrains) - myPos = 0 # position (in list) of current grid point - - for z in range(grid[2]): for y in range(grid[1]): for x in range(grid[0]): + microstructure[x,y,z] = table.data[indices[i],3] + i+=1 - - myData = table.data[index[myPos]] # read data for current grid point - myPhase = int(myData[colPhase]) - - o = damask.Rotation(myData[colOri:colOri+4]) - - grain[myPos] = nGrains # assign new grain to me ... - nGrains += 1 # ... and update counter - orientations.append(o) # store new orientation for future comparison - multiplicity.append(1) # having single occurrence so far - phases.append(myPhase) # store phase info for future reporting - existingGrains = np.arange(nGrains) # update list of existing grains - - myPos += 1 - - - grain += 1 # offset from starting index 0 to 1 - - - formatwidth = 1+int(np.log10(nGrains)) - - if inputtype == 'microstructure': config_header = [] - else: + + elif inputtype == 'quaternion': + unique,unique_inverse = np.unique(table.data[:,3:8],return_inverse=True,axis=0) + + for z in range(grid[2]): + for y in range(grid[1]): + for x in range(grid[0]): + microstructure[x,y,z] = unique_inverse[indices[i]]+1 + i+=1 + config_header = [''] - for i,phase in enumerate(phases): - config_header += ['[Grain%s]'%(str(i+1).zfill(formatwidth)), + for i,data in enumerate(unique): + config_header += ['[Grain{}]'.format(i+1), 'crystallite 1', - '(constituent)\tphase %i\ttexture %s\tfraction 1.0'%(phase,str(i+1).rjust(formatwidth)), + '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(int(data[4]),i+1), ] config_header += [''] - for i,orientation in enumerate(orientations): - config_header += ['[Grain%s]'%(str(i+1).zfill(formatwidth)), - '(gauss)\tphi1 %g\tPhi %g\tphi2 %g'%tuple(orientation.asEulers(degrees = True)), + for i,data in enumerate(unique): + ori = damask.Rotation(data[0:4]) + config_header += ['[Grain{}]'.format(i+1), + '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}'.format(*ori.asEulers(degrees = True)), ] if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] - - header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header + ['origin x {} y {} z {}'.format(*origin)] - geom = damask.Geom(grain.reshape(grid,order='F'),size, + + header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ + + config_header + geom = damask.Geom(microstructure,size,origin, homogenization=options.homogenization,comments=header) damask.util.croak(geom) From e974bb9c437491f85e4a424e619bc3a59976eb49 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 10:45:17 +0200 Subject: [PATCH 087/120] similar structure for building blocks --- processing/pre/geom_fromMinimalSurface.py | 2 +- processing/pre/geom_fromOsteonGeometry.py | 3 ++- processing/pre/geom_fromTable.py | 0 processing/pre/geom_fromVoronoiTessellation.py | 6 ++++-- 4 files changed, 7 insertions(+), 4 deletions(-) mode change 100644 => 100755 processing/pre/geom_fromTable.py diff --git a/processing/pre/geom_fromMinimalSurface.py b/processing/pre/geom_fromMinimalSurface.py index db3592739..2b2887ada 100755 --- a/processing/pre/geom_fromMinimalSurface.py +++ b/processing/pre/geom_fromMinimalSurface.py @@ -89,8 +89,8 @@ for x in range(options.grid[0]): geom=damask.Geom(microstructure,options.size, homogenization=options.homogenization, comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) - damask.util.croak(geom) + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_fromOsteonGeometry.py b/processing/pre/geom_fromOsteonGeometry.py index af778020f..ebfde38fa 100755 --- a/processing/pre/geom_fromOsteonGeometry.py +++ b/processing/pre/geom_fromOsteonGeometry.py @@ -134,7 +134,8 @@ for i in range(3,np.max(microstructure)): config_header.append('[Point{}]'.format(i-2)) config_header.append('(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 0'.format(Alpha[i],Beta[i])) -header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header +header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ + + config_header geom = damask.Geom(microstructure.reshape(grid), size,-size/2, homogenization=options.homogenization,comments=header) diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py old mode 100644 new mode 100755 diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 03880267f..18b9b8b7f 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -194,15 +194,17 @@ parser.set_defaults(pos = 'pos', normalized = True, config = True, ) + (options,filenames) = parser.parse_args() -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: filenames = [None] for name in filenames: - table = damask.ASCIItable(name = name, readonly = True) damask.util.report(scriptName,name) + + table = damask.ASCIItable(name = name, readonly = True) + # --- read header ---------------------------------------------------------------------------- From 43a50713b0c1cc981457b269f316983584f155e4 Mon Sep 17 00:00:00 2001 From: Test User Date: Thu, 30 May 2019 11:00:01 +0200 Subject: [PATCH 088/120] [skip ci] updated version information after successful test of v2.0.3-344-gb25c64d1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index d961b0f73..40e72919d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.3-332-g5abcca50 +v2.0.3-344-gb25c64d1 From 49c3903cc7f3d96183f21670a55b3bd5bf32fc8d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 10:54:33 +0200 Subject: [PATCH 089/120] explicit loop for simpler code - no invalid combintations any more (allow to move the original microstructure out of the new canvas) - handling of origin needs discussion. When we want to recover the old behavior, the origin might be located outside of the new geometry --- processing/pre/geom_canvas.py | 88 +++++++++++++---------------------- 1 file changed, 32 insertions(+), 56 deletions(-) diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index 0b5675d75..fe8e69981 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -1,52 +1,46 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np -import damask - from io import StringIO from optparse import OptionParser +import numpy as np + +import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [geomfile(s)]', description = """ -Changes the (three-dimensional) canvas of a spectral geometry description. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ +Increases or decreases the (three-dimensional) canvas. Grid can be given as absolute or relative values, e.g. 16 16 16 or 2x 0.5x 32. """, version = scriptID) -parser.add_option('-g', - '--grid', +parser.add_option('-g','--grid', dest = 'grid', type = 'string', nargs = 3, metavar = ' '.join(['string']*3), - help = 'a,b,c grid of hexahedral box. [auto]') -parser.add_option('-o', - '--offset', + help = 'a,b,c grid of hexahedral box') +parser.add_option('-o','--offset', dest = 'offset', type = 'int', nargs = 3, metavar = ' '.join(['int']*3), help = 'a,b,c offset from old to new origin of grid [%default]') -parser.add_option('-f', - '--fill', +parser.add_option('-f','--fill', dest = 'fill', - type = 'float', metavar = 'float', - help = '(background) canvas grain index. "0" selects maximum microstructure index + 1 [%default]') + type = 'float', metavar = 'int', + help = 'background microstructure index, defaults to max microstructure index + 1') -parser.set_defaults(grid = ['0','0','0'], - offset = (0,0,0), - ) +parser.set_defaults(offset = (0,0,0)) (options, filenames) = parser.parse_args() -# --- loop over input files ------------------------------------------------------------------------- - if filenames == []: filenames = [None] for name in filenames: @@ -55,44 +49,26 @@ for name in filenames: geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) grid = geom.get_grid() - size = geom.get_size() - origin = geom.get_origin() - microstructure = geom.get_microstructure() - fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill - dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int + if options.grid is not None: + grid = np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ + else int(n) for o,n in zip(grid,options.grid)],dtype=int) + grid = np.maximum(grid,1) + + new = np.full(grid,options.fill if options.fill is not None + else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) -# --- do work ------------------------------------------------------------------------------------ - - new_grid = np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ - else int(n) for o,n in zip(grid,options.grid)],dtype=int) - new_grid = np.where(new_grid > 0, new_grid,grid) + for x in range(geom.microstructure.shape[0]): + X = x + options.offset[0] + if not 0 <= X < new.shape[0]: continue + for y in range(geom.microstructure.shape[1]): + Y = y + options.offset[1] + if not 0 <= Y < new.shape[1]: continue + for z in range(geom.microstructure.shape[2]): + Z = z + options.offset[2] + if not 0 <= Z < new.shape[2]: continue + new[X,Y,Z] = geom.microstructure[x,y,z] - microstructure_cropped = np.zeros(new_grid,dtype=dtype) - microstructure_cropped.fill(fill) - - xindex = np.arange(max(options.offset[0],0),min(options.offset[0]+new_grid[0],grid[0])) - yindex = np.arange(max(options.offset[1],0),min(options.offset[1]+new_grid[1],grid[1])) - zindex = np.arange(max(options.offset[2],0),min(options.offset[2]+new_grid[2],grid[2])) - translate_x = [i - options.offset[0] for i in xindex] - translate_y = [i - options.offset[1] for i in yindex] - translate_z = [i - options.offset[2] for i in zindex] - if 0 in map(len,[xindex,yindex,zindex,translate_x,translate_y,translate_z]): - damask.util.croak('invaldid combination of grid and offset.') - continue - microstructure_cropped[min(translate_x):max(translate_x)+1, - min(translate_y):max(translate_y)+1, - min(translate_z):max(translate_z)+1] \ - = microstructure[min(xindex):max(xindex)+1, - min(yindex):max(yindex)+1, - min(zindex):max(zindex)+1] - - new_size = size/grid*new_grid if np.all(grid > 0) else new_grid - new_origin = origin + (size/grid if np.all(grid > 0) else new_size/new_grid) * options.offset - - damask.util.croak(geom.update(microstructure=microstructure_cropped, - size=new_size, - origin=new_origin, - )) + damask.util.croak(geom.update(new,origin=(0,0,0),rescale=True)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: From 461611cde75da94db5d3ca95069645c8eec5dde3 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 11:26:47 +0200 Subject: [PATCH 090/120] polishing --- processing/pre/geom_grainGrowth.py | 6 ++++-- processing/pre/geom_mirror.py | 3 ++- processing/pre/geom_pack.py | 1 + processing/pre/geom_rotate.py | 2 ++ processing/pre/geom_toTable.py | 16 +++++++++------- processing/pre/geom_translate.py | 3 ++- processing/pre/geom_unpack.py | 2 +- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/processing/pre/geom_grainGrowth.py b/processing/pre/geom_grainGrowth.py index 4c8b6c8bc..479f6f6fc 100755 --- a/processing/pre/geom_grainGrowth.py +++ b/processing/pre/geom_grainGrowth.py @@ -56,14 +56,16 @@ parser.set_defaults(d = 1, options.immutable = list(map(int,options.immutable)) +if filenames == []: filenames = [None] + for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + grid_original = geom.get_grid() damask.util.croak(geom) - - microstructure = np.tile(geom.microstructure,np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1 + microstructure = np.tile(geom.microstructure,np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1 grid = np.array(microstructure.shape) # --- initialize support data --------------------------------------------------------------------- diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index e6b29ae5c..408eb15a8 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -47,14 +47,15 @@ if not set(options.directions).issubset(validDirections): limits = [-2,0] if options.periodic else [None,None] + if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + microstructure = geom.get_microstructure() - if 'z' in options.directions: microstructure = np.concatenate([microstructure,microstructure[:,:,limits[0]:limits[1]:-1]],2) if 'y' in options.directions: diff --git a/processing/pre/geom_pack.py b/processing/pre/geom_pack.py index 68045defa..2bd993770 100755 --- a/processing/pre/geom_pack.py +++ b/processing/pre/geom_pack.py @@ -30,6 +30,7 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + damask.util.croak(geom) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 476e26c29..852693304 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -69,12 +69,14 @@ if options.eulers is not None: eulers = rot.asEulers(degrees=True) + if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + microstructure = geom.get_microstructure() fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int diff --git a/processing/pre/geom_toTable.py b/processing/pre/geom_toTable.py index 7db7f8430..2b8257cfa 100755 --- a/processing/pre/geom_toTable.py +++ b/processing/pre/geom_toTable.py @@ -23,22 +23,24 @@ Translate geom description into ASCIItable containing position and microstructur """, version = scriptID) - (options, filenames) = parser.parse_args() + if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - damask.util.croak(geom) - grid = geom.get_grid() - size = geom.get_size() - origin = geom.get_origin() -#--- generate grid -------------------------------------------------------------------------------- + damask.util.croak(geom) + +# --- generate grid -------------------------------------------------------------------------------- + grid = geom.get_grid() + size = geom.get_size() + origin = geom.get_origin() + x = (0.5 + np.arange(grid[0],dtype=float))/grid[0]*size[0]+origin[0] y = (0.5 + np.arange(grid[1],dtype=float))/grid[1]*size[1]+origin[1] z = (0.5 + np.arange(grid[2],dtype=float))/grid[2]*size[2]+origin[2] @@ -47,7 +49,7 @@ for name in filenames: yy = np.tile(np.repeat(y,grid[0] ),grid[2]) zz = np.repeat(z,grid[0]*grid[1]) -# ------------------------------------------ finalize output --------------------------------------- +# --- create ASCII table -------------------------------------------------------------------------- table = damask.ASCIItable(outname = os.path.splitext(name)[0]+'.txt' if name else name) table.info_append(geom.get_comments() + [scriptID + '\t' + ' '.join(sys.argv[1:])]) diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index 59c431474..127c63bc6 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -43,14 +43,15 @@ parser.set_defaults(origin = (0.0,0.0,0.0), sub = list(map(int,options.substitute)) + if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - substituted = geom.get_microstructure() + substituted = geom.get_microstructure() for old,new in zip(sub[0::2],sub[1::2]): substituted[substituted==old] = new # substitute microstructure indices substituted += options.microstructure # constant shift diff --git a/processing/pre/geom_unpack.py b/processing/pre/geom_unpack.py index 1c9b591be..b1b12d2cc 100755 --- a/processing/pre/geom_unpack.py +++ b/processing/pre/geom_unpack.py @@ -30,8 +30,8 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + damask.util.croak(geom) - geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: From b00581f1be8b03fb2377e7f5f8784c7e1a31dd9e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 13:29:29 +0200 Subject: [PATCH 091/120] less picky on allowed datatypes --- python/damask/geom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 397684fe1..e422516a7 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -83,7 +83,7 @@ class Geom(): if microstructure is not None: if len(microstructure.shape) != 3: raise ValueError('Invalid microstructure shape {}'.format(*microstructure.shape)) - elif microstructure.dtype not in [int,float]: + elif microstructure.dtype not in np.sctypes['float'] + np.sctypes['int']: raise TypeError('Invalid data type {} for microstructure'.format(microstructure.dtype)) else: self.microstructure = np.copy(microstructure) From 7d07a3752f31c8336ac39c09bfc967b0cce5337e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 13:30:18 +0200 Subject: [PATCH 092/120] polishing --- processing/pre/geom_fromTable.py | 3 ++- processing/pre/geom_rescale.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py index 0a32836c2..53eb06316 100755 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -18,7 +18,8 @@ scriptID = ' '.join([scriptName,damask.version]) # -------------------------------------------------------------------- parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """ -Generate geometry description and material configuration from position, phase, and orientation (or microstructure) data. +Converts ASCII table. Input can be microstructure or orientation (as quaternion). For the latter, +phase information can be given additionally. """, version = scriptID) diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index aa639a146..57b43c165 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -43,6 +43,7 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + grid = geom.get_grid() size = geom.get_size() From 83800715641f50b529161e613af25e3b10dcd78e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 13:30:38 +0200 Subject: [PATCH 093/120] using geom class - dropped the use of the material class as it does not allow to have empty phase and crystallite. The material.config class needs a severe refurbishing (no crystallite, use orderedDict instead of hand written solution, drop of texture components). Probably best solution is to postpone this until we have a yaml/json reader for Fortran. --- processing/pre/geom_fromDREAM3D.py | 147 ++++++++++++----------------- 1 file changed, 59 insertions(+), 88 deletions(-) diff --git a/processing/pre/geom_fromDREAM3D.py b/processing/pre/geom_fromDREAM3D.py index 9bb8b2fcc..97ee2f84b 100755 --- a/processing/pre/geom_fromDREAM3D.py +++ b/processing/pre/geom_fromDREAM3D.py @@ -1,11 +1,15 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- -import os,sys,h5py -import numpy as np +import os +import sys from optparse import OptionParser + +import h5py +import numpy as np + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) @@ -14,40 +18,50 @@ scriptID = ' '.join([scriptName,damask.version]) # MAIN #-------------------------------------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog [dream3dfile[s]]', description = """ -Convert DREAM3D file to geometry file. This can be done from cell data (direct pointwise takeover) or -from grain data (individual grains are segmented). Requires orientation data as quaternion. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [DREAM.3Dfile(s)]', description = """ +Converts DREAM.3D file. Input can be cell data (direct pointwise takeover) or grain data (individual +grains are segmented). Requires orientation data as quaternion. """, version = scriptID) parser.add_option('-b','--basegroup', - dest = 'basegroup', metavar = 'string', + dest = 'basegroup', + metavar = 'string', help = 'name of the group in "DataContainers" containing the pointwise (and, if applicable grain average) data') parser.add_option('-p','--pointwise', - dest = 'pointwise', metavar = 'string', + dest = 'pointwise', + metavar = 'string', help = 'name of the group in "DataContainers/" containing pointwise data [%default]') parser.add_option('-a','--average', - dest = 'average', metavar = 'string', + dest = 'average', + metavar = 'string', help = 'name of the group in "DataContainers" containing grain average data. '\ + 'Leave empty for pointwise data') parser.add_option('--phase', dest = 'phase', - type = 'string', metavar = 'string', + type = 'string', + metavar = 'string', help = 'name of the dataset containing pointwise/average phase IDs [%default]') parser.add_option('--microstructure', dest = 'microstructure', - type = 'string', metavar = 'string', + type = 'string', + metavar = 'string', help = 'name of the dataset connecting pointwise and average data [%default]') parser.add_option('-q', '--quaternion', dest = 'quaternion', - type = 'string', metavar='string', + type = 'string', + metavar='string', help = 'name of the dataset containing pointwise/average orientation as quaternion [%default]') +parser.add_option('--homogenization', + dest = 'homogenization', + type = 'int', metavar = 'int', + help = 'homogenization index to be used [%default]') parser.set_defaults(pointwise = 'CellData', quaternion = 'Quats', phase = 'Phases', microstructure = 'FeatureIds', - crystallite = 1, + homogenization = 1, ) (options, filenames) = parser.parse_args() @@ -57,67 +71,59 @@ if options.basegroup is None: rootDir ='DataContainers' -# --- loop over input files ------------------------------------------------------------------------- if filenames == []: parser.error('no input file specified.') for name in filenames: - try: - table = damask.ASCIItable(outname = os.path.splitext(name)[0]+'.geom', - buffered = False, labeled=False, - ) - except: continue damask.util.report(scriptName,name) errors = [] - info = {} - ori = [] inFile = h5py.File(name, 'r') group_geom = os.path.join(rootDir,options.basegroup,'_SIMPL_GEOMETRY') try: - info['size'] = inFile[os.path.join(group_geom,'DIMENSIONS')][...] \ - * inFile[os.path.join(group_geom,'SPACING')][...] - info['grid'] = inFile[os.path.join(group_geom,'DIMENSIONS')][...] - info['origin'] = inFile[os.path.join(group_geom,'ORIGIN')][...] + size = inFile[os.path.join(group_geom,'DIMENSIONS')][...] \ + * inFile[os.path.join(group_geom,'SPACING')][...] + grid = inFile[os.path.join(group_geom,'DIMENSIONS')][...] + origin = inFile[os.path.join(group_geom,'ORIGIN')][...] except: errors.append('Geometry data ({}) not found'.format(group_geom)) group_pointwise = os.path.join(rootDir,options.basegroup,options.pointwise) if options.average is None: - label = 'point' - N_microstructure = np.product(info['grid']) + label = 'Point' dataset = os.path.join(group_pointwise,options.quaternion) try: - quats = np.reshape(inFile[dataset][...],(N_microstructure,4)) - texture = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in quats] + quats = np.reshape(inFile[dataset][...],(np.product(grid),4)) + rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in quats] except: errors.append('Pointwise orientation (quaternion) data ({}) not readable'.format(dataset)) dataset = os.path.join(group_pointwise,options.phase) try: - phase = np.reshape(inFile[dataset][...],(N_microstructure)) + phase = np.reshape(inFile[dataset][...],(np.product(grid))) except: errors.append('Pointwise phase data ({}) not readable'.format(dataset)) + + microstructure = np.arange(1,np.product(grid)+1,dtype=int).reshape(grid,order='F') else: - label = 'grain' + label = 'Grain' dataset = os.path.join(group_pointwise,options.microstructure) try: - microstructure = np.reshape(inFile[dataset][...],(np.product(info['grid']))) - N_microstructure = np.max(microstructure) + microstructure = np.transpose(inFile[dataset][...].reshape(grid[::-1]),(2,1,0)) # convert from C ordering except: errors.append('Link between pointwise and grain average data ({}) not readable'.format(dataset)) - + group_average = os.path.join(rootDir,options.basegroup,options.average) dataset = os.path.join(group_average,options.quaternion) try: - texture = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed) + rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed) except: errors.append('Average orientation data ({}) not readable'.format(dataset)) @@ -129,60 +135,25 @@ for name in filenames: if errors != []: damask.util.croak(errors) - table.close(dismiss = True) continue + config_header = [''] + for i in range(np.nanmax(microstructure)): + config_header += ['[{}{}]'.format(label,i+1), + 'crystallite 1', + '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(phase[i],i+1), + ] + + config_header += [''] + for i in range(np.nanmax(microstructure)): + config_header += ['[{}{}]'.format(label,i+1), + '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*rot[i].asEulers(degrees = True)), + ] - mat = damask.Material() - mat.verbose = False + header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ + + config_header + geom = damask.Geom(microstructure,size,origin, + homogenization=options.homogenization,comments=header) + damask.util.croak(geom) - # dummy - h = damask.config.material.Homogenization() - mat.add_section('Homogenization','none',h) - info['homogenization'] = 1 - - # placeholder (same for all microstructures at the moment) - c = damask.config.material.Crystallite() - mat.add_section('Crystallite','tbd',c) - - # placeholders - for i in range(np.max(phase)): - p = damask.config.material.Phase() - mat.add_section('phase','phase{}-tbd'.format(i+1),p) - - # - for i,o in enumerate(texture): - t = damask.config.material.Texture() - t.add_component('gauss',{'eulers':o.asEulers(degrees=True)}) - mat.add_section(part='texture', section='{}{}'.format(label,i+1),initialData=t) - - # - for i in range(N_microstructure): - m = damask.config.material.Microstructure() - mat.add_section('microstructure','{}{}'.format(label,i+1),m) - mat.add_microstructure('{}{}'.format(label,i+1), - {'phase': 'phase{}-tbd'.format(phase[i]), - 'texture':'{}{}'.format(label,i+1), - 'crystallite':'tbd', - 'fraction':1 - }) - - table.info_append([ - scriptID + ' ' + ' '.join(sys.argv[1:]), - "grid\ta {}\tb {}\tc {}".format(*info['grid']), - "size\tx {}\ty {}\tz {}".format(*info['size']), - "origin\tx {}\ty {}\tz {}".format(*info['origin']), - "homogenization\t{}".format(info['homogenization']), - str(mat).split('\n') - ]) - table.head_write() - - if options.average is None: - table.data = [1, 'to', format(N_microstructure)] - table.data_write() - else: - table.data = microstructure.reshape(info['grid'][1]*info['grid'][2],info['grid'][0]) - table.data_writeArray() - - - table.close() + geom.to_file(os.path.splitext(name)[0]+'.geom') From d0c7f8b934eee15106857be33ff5b3c6b9caa6c6 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 14:05:45 +0200 Subject: [PATCH 094/120] texture is typically the more interesting information therefore, but it to the top --- processing/pre/geom_fromDREAM3D.py | 17 ++++----- processing/pre/geom_fromOsteonGeometry.py | 37 ++++++++++--------- processing/pre/geom_fromTable.py | 18 ++++----- .../pre/geom_fromVoronoiTessellation.py | 15 +++++--- 4 files changed, 46 insertions(+), 41 deletions(-) diff --git a/processing/pre/geom_fromDREAM3D.py b/processing/pre/geom_fromDREAM3D.py index 97ee2f84b..02a2fe0da 100755 --- a/processing/pre/geom_fromDREAM3D.py +++ b/processing/pre/geom_fromDREAM3D.py @@ -136,20 +136,19 @@ for name in filenames: if errors != []: damask.util.croak(errors) continue - - config_header = [''] + + config_header = [''] + for i in range(np.nanmax(microstructure)): + config_header += ['[{}{}]'.format(label,i+1), + '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*rot[i].asEulers(degrees = True)), + ] + config_header += [''] for i in range(np.nanmax(microstructure)): config_header += ['[{}{}]'.format(label,i+1), 'crystallite 1', '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(phase[i],i+1), ] - - config_header += [''] - for i in range(np.nanmax(microstructure)): - config_header += ['[{}{}]'.format(label,i+1), - '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*rot[i].asEulers(degrees = True)), - ] - + header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ + config_header geom = damask.Geom(microstructure,size,origin, diff --git a/processing/pre/geom_fromOsteonGeometry.py b/processing/pre/geom_fromOsteonGeometry.py index ebfde38fa..d312220a7 100755 --- a/processing/pre/geom_fromOsteonGeometry.py +++ b/processing/pre/geom_fromOsteonGeometry.py @@ -114,25 +114,28 @@ for y in range(grid[1]): Beta [i] = beta [x,y] i+=1 -config_header = [] -config_header.append('') -config_header.append('[canal]') -config_header.append('crystallite 1') -config_header.append('(constituent)\tphase 1\ttexture 1\tfraction 1.0') -config_header.append('[interstitial]') -config_header.append('crystallite 1') -config_header.append('(constituent)\tphase 2\ttexture 2\tfraction 1.0') +config_header = ['', + '[canal]', + '[interstitial]' + ] for i in range(3,np.max(microstructure)): - config_header.append('[Point{}]'.format(i-2)) - config_header.append('crystallite 1') - config_header.append('(constituent)\tphase 3\ttexture {}\tfraction 1.0'.format(i)) - -config_header.append('') -config_header.append('[canal]') -config_header.append('[interstitial]') + config_header += ['[Point{}]'.format(i-2), + '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 0'.format(Alpha[i],Beta[i]) + ] + +config_header = ['', + '[canal]', + 'crystallite 1', + '(constituent)\tphase 1\ttexture 1\tfraction 1.0', + '[interstitial]', + 'crystallite 1', + '(constituent)\tphase 2\ttexture 2\tfraction 1.0' + ] for i in range(3,np.max(microstructure)): - config_header.append('[Point{}]'.format(i-2)) - config_header.append('(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 0'.format(Alpha[i],Beta[i])) + config_header += ['[Point{}]'.format(i-2), + 'crystallite 1', + '(constituent)\tphase 3\ttexture {}\tfraction 1.0'.format(i) + ] header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ + config_header diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py index 53eb06316..1ef9822a4 100755 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -131,20 +131,20 @@ for name in filenames: microstructure[x,y,z] = unique_inverse[indices[i]]+1 i+=1 - config_header = [''] - for i,data in enumerate(unique): - config_header += ['[Grain{}]'.format(i+1), - 'crystallite 1', - '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(int(data[4]),i+1), - ] - - config_header += [''] + config_header = [''] for i,data in enumerate(unique): ori = damask.Rotation(data[0:4]) config_header += ['[Grain{}]'.format(i+1), '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}'.format(*ori.asEulers(degrees = True)), ] - if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] + if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] + + config_header += [''] + for i,data in enumerate(unique): + config_header += ['[Grain{}]'.format(i+1), + 'crystallite 1', + '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(int(data[4]),i+1), + ] header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ + config_header diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 18b9b8b7f..08b069410 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -277,12 +277,7 @@ for name in filenames: config_header = [] if options.config: - config_header += [''] - for ID in grainIDs: - config_header += ['[Grain{}]'.format(ID), - 'crystallite 1', - '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(options.phase,ID) - ] + if hasEulers: config_header += [''] for ID in grainIDs: @@ -291,6 +286,14 @@ for name in filenames: '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*eulers[eulerID]) ] if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] + + config_header += [''] + for ID in grainIDs: + config_header += ['[Grain{}]'.format(ID), + 'crystallite 1', + '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(options.phase,ID) + ] + config_header += [''] header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ From bf60cffab5510fda2598c6d20308b30f3514ddb2 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 14:07:49 +0200 Subject: [PATCH 095/120] cleaning --- processing/pre/geom_addPrimitive.py | 14 ++++---- processing/pre/geom_canvas.py | 8 ++--- processing/pre/geom_check.sh | 2 +- processing/pre/geom_clean.py | 2 +- processing/pre/geom_fromDREAM3D.py | 22 ++++++------ processing/pre/geom_fromMinimalSurface.py | 2 +- processing/pre/geom_fromOsteonGeometry.py | 8 ++--- processing/pre/geom_fromScratch.py | 2 +- processing/pre/geom_fromTable.py | 20 +++++------ .../pre/geom_fromVoronoiTessellation.py | 34 +++++++++---------- processing/pre/geom_grainGrowth.py | 12 +++---- processing/pre/geom_mirror.py | 10 +++--- processing/pre/geom_pack.py | 4 +-- processing/pre/geom_renumber.py | 6 ++-- processing/pre/geom_rescale.py | 4 +-- processing/pre/geom_rotate.py | 6 ++-- processing/pre/geom_toTable.py | 8 ++--- processing/pre/geom_translate.py | 6 ++-- processing/pre/geom_unpack.py | 4 +-- processing/pre/geom_vicinityOffset.py | 4 +-- 20 files changed, 89 insertions(+), 89 deletions(-) diff --git a/processing/pre/geom_addPrimitive.py b/processing/pre/geom_addPrimitive.py index b8b1ddf6e..99035c8fe 100755 --- a/processing/pre/geom_addPrimitive.py +++ b/processing/pre/geom_addPrimitive.py @@ -24,7 +24,7 @@ These objects can be boxes, cylinders, or ellipsoids. """, version = scriptID) parser.add_option('-c', '--center', - dest='center', + dest='center', type='float', nargs = 3, metavar=' '.join(['float']*3), help='a,b,c origin of primitive %default') parser.add_option('-d', '--dimension', @@ -78,7 +78,7 @@ parser.set_defaults(center = (.0,.0,.0), (options, filenames) = parser.parse_args() if options.dimension is None: - parser.error('no dimension specified.') + parser.error('no dimension specified.') if [options.angleaxis,options.quaternion].count(None) == 0: parser.error('more than one rotation specified.') @@ -94,7 +94,7 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) grid = geom.get_grid() size = geom.get_size() @@ -106,7 +106,7 @@ for name in filenames: else: center = (np.array(options.center) + 0.5)/grid r = np.array(options.dimension)/grid/2.0 - + if np.any(center<0.0) or np.any(center>=1.0): print('error') offset = np.ones(3)*0.5 if options.periodic else center @@ -120,17 +120,17 @@ for name in filenames: for z in range(grid[2]): coords = np.array([x+0.5,y+0.5,z+0.5])/grid mask[x,y,z] = np.sum(np.abs((rotation*(coords-offset))/r)**e) < 1 - + if options.periodic: shift = ((offset-center)*grid).astype(int) mask = np.roll(mask,shift,(0,1,2)) - + if options.inside: mask = np.logical_not(mask) fill = np.nanmax(geom.microstructure)+1 if options.fill is None else options.fill damask.util.croak(geom.update(np.where(mask,geom.microstructure,fill))) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) - + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index fe8e69981..b0748dcf3 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -45,7 +45,7 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) grid = geom.get_grid() @@ -56,13 +56,13 @@ for name in filenames: new = np.full(grid,options.fill if options.fill is not None else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) - + for x in range(geom.microstructure.shape[0]): X = x + options.offset[0] - if not 0 <= X < new.shape[0]: continue + if not 0 <= X < new.shape[0]: continue for y in range(geom.microstructure.shape[1]): Y = y + options.offset[1] - if not 0 <= Y < new.shape[1]: continue + if not 0 <= Y < new.shape[1]: continue for z in range(geom.microstructure.shape[2]): Z = z + options.offset[2] if not 0 <= Z < new.shape[2]: continue diff --git a/processing/pre/geom_check.sh b/processing/pre/geom_check.sh index 2a690918e..fbae91043 100755 --- a/processing/pre/geom_check.sh +++ b/processing/pre/geom_check.sh @@ -5,7 +5,7 @@ if [[ "$1" == "-f" || "$1" == "--float" ]]; then arg='--float' else arg='' -fi +fi for geom in "$@" do diff --git a/processing/pre/geom_clean.py b/processing/pre/geom_clean.py index 8e477c1c1..aeafe4f09 100755 --- a/processing/pre/geom_clean.py +++ b/processing/pre/geom_clean.py @@ -43,7 +43,7 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) damask.util.croak(geom.update(ndimage.filters.generic_filter( diff --git a/processing/pre/geom_fromDREAM3D.py b/processing/pre/geom_fromDREAM3D.py index 02a2fe0da..5d41e05b9 100755 --- a/processing/pre/geom_fromDREAM3D.py +++ b/processing/pre/geom_fromDREAM3D.py @@ -78,7 +78,7 @@ for name in filenames: damask.util.report(scriptName,name) errors = [] - + inFile = h5py.File(name, 'r') group_geom = os.path.join(rootDir,options.basegroup,'_SIMPL_GEOMETRY') try: @@ -88,8 +88,8 @@ for name in filenames: origin = inFile[os.path.join(group_geom,'ORIGIN')][...] except: errors.append('Geometry data ({}) not found'.format(group_geom)) - - + + group_pointwise = os.path.join(rootDir,options.basegroup,options.pointwise) if options.average is None: label = 'Point' @@ -100,33 +100,33 @@ for name in filenames: rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in quats] except: errors.append('Pointwise orientation (quaternion) data ({}) not readable'.format(dataset)) - + dataset = os.path.join(group_pointwise,options.phase) try: phase = np.reshape(inFile[dataset][...],(np.product(grid))) except: errors.append('Pointwise phase data ({}) not readable'.format(dataset)) - + microstructure = np.arange(1,np.product(grid)+1,dtype=int).reshape(grid,order='F') - + else: label = 'Grain' - + dataset = os.path.join(group_pointwise,options.microstructure) try: microstructure = np.transpose(inFile[dataset][...].reshape(grid[::-1]),(2,1,0)) # convert from C ordering except: errors.append('Link between pointwise and grain average data ({}) not readable'.format(dataset)) - + group_average = os.path.join(rootDir,options.basegroup,options.average) - + dataset = os.path.join(group_average,options.quaternion) try: rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed) except: errors.append('Average orientation data ({}) not readable'.format(dataset)) - + dataset = os.path.join(group_average,options.phase) try: phase = [i[0] for i in inFile[dataset][...]][1:] # skip first entry (unindexed) @@ -148,7 +148,7 @@ for name in filenames: 'crystallite 1', '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(phase[i],i+1), ] - + header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ + config_header geom = damask.Geom(microstructure,size,origin, diff --git a/processing/pre/geom_fromMinimalSurface.py b/processing/pre/geom_fromMinimalSurface.py index 2b2887ada..19686f763 100755 --- a/processing/pre/geom_fromMinimalSurface.py +++ b/processing/pre/geom_fromMinimalSurface.py @@ -85,7 +85,7 @@ for x in range(options.grid[0]): for y in range(options.grid[1]): for z in range(options.grid[2]): microstructure[x,y,z]=options.microstructure[int(options.threshold < surface[options.type](X[x],Y[y],Z[z]))] - + geom=damask.Geom(microstructure,options.size, homogenization=options.homogenization, comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) diff --git a/processing/pre/geom_fromOsteonGeometry.py b/processing/pre/geom_fromOsteonGeometry.py index d312220a7..98d2cf9ea 100755 --- a/processing/pre/geom_fromOsteonGeometry.py +++ b/processing/pre/geom_fromOsteonGeometry.py @@ -52,7 +52,7 @@ parser.add_option( '--aspect', dest='aspect', type='float', metavar = 'float', help='vertical/horizontal osteon aspect ratio [%default]') -parser.add_option('-w', '--omega', +parser.add_option('-w', '--omega', dest='omega', type='float', metavar = 'float', help='rotation angle around normal of osteon [%default]') @@ -112,7 +112,7 @@ for y in range(grid[1]): microstructure[x,y] = i Alpha[i] = alpha[x,y] Beta [i] = beta [x,y] - i+=1 + i+=1 config_header = ['', '[canal]', @@ -122,7 +122,7 @@ for i in range(3,np.max(microstructure)): config_header += ['[Point{}]'.format(i-2), '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 0'.format(Alpha[i],Beta[i]) ] - + config_header = ['', '[canal]', 'crystallite 1', @@ -143,7 +143,7 @@ geom = damask.Geom(microstructure.reshape(grid), size,-size/2, homogenization=options.homogenization,comments=header) damask.util.croak(geom) - + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_fromScratch.py b/processing/pre/geom_fromScratch.py index b76e0012a..e943f7e3e 100755 --- a/processing/pre/geom_fromScratch.py +++ b/processing/pre/geom_fromScratch.py @@ -63,7 +63,7 @@ geom = damask.Geom(microstructure=np.full(options.grid,options.fill,dtype=dtype) homogenization=options.homogenization, comments=scriptID + ' ' + ' '.join(sys.argv[1:])) damask.util.croak(geom) - + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py index 1ef9822a4..c0b327d7d 100755 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -18,7 +18,7 @@ scriptID = ' '.join([scriptName,damask.version]) # -------------------------------------------------------------------- parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """ -Converts ASCII table. Input can be microstructure or orientation (as quaternion). For the latter, +Converts ASCII table. Input can be microstructure or orientation (as quaternion). For the latter, phase information can be given additionally. """, version = scriptID) @@ -78,7 +78,7 @@ for name in filenames: table = damask.ASCIItable(name = name,readonly=True) table.head_read() # read ASCII header info -# ------------------------------------------ sanity checks --------------------------------------- +# ------------------------------------------ sanity checks --------------------------------------- coordDim = table.label_dimension(options.pos) @@ -89,7 +89,7 @@ for name in filenames: errors.append('input "{}" needs to have dimension {}.'.format(label,dim)) if options.phase and table.label_dimension(options.phase) != 1: errors.append('phase column "{}" is not scalar.'.format(options.phase)) - + if errors != []: damask.util.croak(errors) continue @@ -97,7 +97,7 @@ for name in filenames: table.data_readArray([options.pos] \ + (label if isinstance(label, list) else [label]) \ + ([options.phase] if options.phase else [])) - + if coordDim == 2: table.data = np.insert(table.data,2,np.zeros(len(table.data)),axis=1) # add zero z coordinate for two-dimensional input if options.phase is None: @@ -112,7 +112,7 @@ for name in filenames: indices = np.lexsort((table.data[:,0],table.data[:,1],table.data[:,2])) # indices of position when sorting x fast, z slow microstructure = np.empty(grid,dtype = int) # initialize empty microstructure i = 0 - + if inputtype == 'microstructure': for z in range(grid[2]): for y in range(grid[1]): @@ -124,21 +124,21 @@ for name in filenames: elif inputtype == 'quaternion': unique,unique_inverse = np.unique(table.data[:,3:8],return_inverse=True,axis=0) - + for z in range(grid[2]): for y in range(grid[1]): for x in range(grid[0]): microstructure[x,y,z] = unique_inverse[indices[i]]+1 i+=1 - + config_header = [''] for i,data in enumerate(unique): ori = damask.Rotation(data[0:4]) config_header += ['[Grain{}]'.format(i+1), '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}'.format(*ori.asEulers(degrees = True)), ] - if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] - + if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] + config_header += [''] for i,data in enumerate(unique): config_header += ['[Grain{}]'.format(i+1), @@ -151,7 +151,7 @@ for name in filenames: geom = damask.Geom(microstructure,size,origin, homogenization=options.homogenization,comments=header) damask.util.croak(geom) - + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index 08b069410..dd2e5e8ea 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import os -import sys +import sys import multiprocessing from optparse import OptionParser,OptionGroup @@ -22,7 +22,7 @@ def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, c tmp = np.repeat(point.reshape(3,1), len(seeds), axis=1).T dist = np.sum((tmp - seeds)**2,axis=1) -myWeights return np.argmin(dist) # seed point closest to point - + copies = \ np.array([ [ -1,-1,-1 ], @@ -60,7 +60,7 @@ def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, c repeatweights = np.tile(weights,len(copies)).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3) for i,vec in enumerate(copies): # periodic copies of seed points ... try: seeds = np.append(seeds, coords+vec, axis=0) # ... (1+a,2+a,3+a,...,1+z,2+z,3+z) - except NameError: seeds = coords+vec + except NameError: seeds = coords+vec if (repeatweights == 0.0).all(): # standard Voronoi (no weights, KD tree) myKDTree = spatial.cKDTree(seeds) @@ -81,7 +81,7 @@ def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, c closestSeeds[i] = findClosestSeed(arg) # closestSeed is modulo number of original seed points (i.e. excluding periodic copies) - return grains[closestSeeds%coords.shape[0]] + return grains[closestSeeds%coords.shape[0]] # -------------------------------------------------------------------- @@ -202,7 +202,7 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + table = damask.ASCIItable(name = name, readonly = True) @@ -210,17 +210,17 @@ for name in filenames: table.head_read() info,extra_header = table.head_getGeom() - + if options.grid is not None: info['grid'] = options.grid if options.size is not None: info['size'] = options.size if options.origin is not None: info['origin'] = options.origin - -# ------------------------------------------ sanity checks --------------------------------------- + +# ------------------------------------------ sanity checks --------------------------------------- remarks = [] errors = [] labels = [] - + hasGrains = table.label_dimension(options.microstructure) == 1 hasEulers = table.label_dimension(options.eulers) == 3 hasWeights = table.label_dimension(options.weight) == 1 and options.laguerre @@ -250,8 +250,8 @@ for name in filenames: table.close(dismiss=True) continue -# ------------------------------------------ read seeds --------------------------------------- - +# ------------------------------------------ read seeds --------------------------------------- + table.data_readArray(labels) coords = table.data[:,table.label_indexrange(options.pos)] * info['size'] if options.normalized \ else table.data[:,table.label_indexrange(options.pos)] - info['origin'] @@ -271,13 +271,13 @@ for name in filenames: z = (np.arange(info['grid'][2])+0.5)*info['size'][2]/info['grid'][2] X,Y,Z = np.meshgrid(x, y, z,indexing='ij') grid = np.stack((X,Y,Z),axis=-1).reshape((info['grid'].prod(),3),order='F') - + damask.util.croak('tessellating...') indices = laguerreTessellation(grid, coords, weights, grains, options.periodic, options.cpus) - + config_header = [] if options.config: - + if hasEulers: config_header += [''] for ID in grainIDs: @@ -286,7 +286,7 @@ for name in filenames: '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*eulers[eulerID]) ] if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] - + config_header += [''] for ID in grainIDs: config_header += ['[Grain{}]'.format(ID), @@ -295,13 +295,13 @@ for name in filenames: ] config_header += [''] - + header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ + config_header geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'],info['origin'], homogenization=options.homogenization,comments=header) damask.util.croak(geom) - + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_grainGrowth.py b/processing/pre/geom_grainGrowth.py index 479f6f6fc..93f43d3b3 100755 --- a/processing/pre/geom_grainGrowth.py +++ b/processing/pre/geom_grainGrowth.py @@ -60,9 +60,9 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - + grid_original = geom.get_grid() damask.util.croak(geom) microstructure = np.tile(geom.microstructure,np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1 @@ -71,15 +71,15 @@ for name in filenames: # --- initialize support data --------------------------------------------------------------------- # store a copy the initial microstructure to find locations of immutable indices - microstructure_original = np.copy(microstructure) + microstructure_original = np.copy(microstructure) if not options.ndimage: X,Y,Z = np.mgrid[0:grid[0],0:grid[1],0:grid[2]] - + # Calculates gaussian weights for simulating 3d diffusion gauss = np.exp(-(X*X + Y*Y + Z*Z)/(2.0*options.d*options.d),dtype=np.float32) \ /np.power(2.0*np.pi*options.d*options.d,(3.0 - np.count_nonzero(grid_original == 1))/2.,dtype=np.float32) - + gauss[:,:,:grid[2]//2:-1] = gauss[:,:,1:(grid[2]+1)//2] # trying to cope with uneven (odd) grid size gauss[:,:grid[1]//2:-1,:] = gauss[:,1:(grid[1]+1)//2,:] gauss[:grid[0]//2:-1,:,:] = gauss[1:(grid[0]+1)//2,:,:] @@ -102,7 +102,7 @@ for name in filenames: grid[2]//2:-grid[2]//2] # transform bulk volume (i.e. where interfacial energy remained zero), store index of closest boundary voxel - index = ndimage.morphology.distance_transform_edt(periodic_interfaceEnergy == 0., + index = ndimage.morphology.distance_transform_edt(periodic_interfaceEnergy == 0., return_distances = False, return_indices = True) diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index 408eb15a8..8d3f3d798 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -32,7 +32,7 @@ parser.add_option('-d','--direction', parser.add_option( '--periodic', dest = 'periodic', action = 'store_true', - help = 'omit periodic copies of outermost layers in mirror direction') + help = 'omit periodic copies of outermost layers in mirror direction') parser.set_defaults(periodic = False) @@ -52,9 +52,9 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - + microstructure = geom.get_microstructure() if 'z' in options.directions: microstructure = np.concatenate([microstructure,microstructure[:,:,limits[0]:limits[1]:-1]],2) @@ -62,10 +62,10 @@ for name in filenames: microstructure = np.concatenate([microstructure,microstructure[:,limits[0]:limits[1]:-1,:]],1) if 'x' in options.directions: microstructure = np.concatenate([microstructure,microstructure[limits[0]:limits[1]:-1,:,:]],0) - + damask.util.croak(geom.update(microstructure,rescale=True)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) - + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_pack.py b/processing/pre/geom_pack.py index 2bd993770..786a40b95 100755 --- a/processing/pre/geom_pack.py +++ b/processing/pre/geom_pack.py @@ -33,7 +33,7 @@ for name in filenames: damask.util.croak(geom) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) - + compressType = None former = start = -1 reps = 0 @@ -65,7 +65,7 @@ for name in filenames: reps = 1 former = current - + if compressType == '.': f.write('{}\n'.format(former)) elif compressType == 'to': diff --git a/processing/pre/geom_renumber.py b/processing/pre/geom_renumber.py index 403aeaf5b..2eee189e1 100755 --- a/processing/pre/geom_renumber.py +++ b/processing/pre/geom_renumber.py @@ -30,16 +30,16 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - + renumbered = np.empty(geom.get_grid(),dtype=geom.microstructure.dtype) for i, oldID in enumerate(np.unique(geom.microstructure)): renumbered = np.where(geom.microstructure == oldID, i+1, renumbered) damask.util.croak(geom.update(renumbered)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) - + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index 57b43c165..5acdf87d6 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -41,7 +41,7 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) grid = geom.get_grid() @@ -55,7 +55,7 @@ for name in filenames: np.array([o*float(n.lower().replace('x','')) if n.lower().endswith('x') \ else float(n) for o,n in zip(size,options.size)],dtype=float) - damask.util.croak(geom.update(microstructure = + damask.util.croak(geom.update(microstructure = ndimage.interpolation.zoom( geom.microstructure, new_grid/grid,output=geom.microstructure.dtype, diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 852693304..09da7b044 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -76,7 +76,7 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - + microstructure = geom.get_microstructure() fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int @@ -89,10 +89,10 @@ for name in filenames: prefilter=False,output=dtype,cval=fill) # rotation around x microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0, prefilter=False,output=dtype,cval=fill) # rotation around z - + damask.util.croak(geom.update(microstructure,rescale=True)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) - + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_toTable.py b/processing/pre/geom_toTable.py index 2b8257cfa..ed33d9c85 100755 --- a/processing/pre/geom_toTable.py +++ b/processing/pre/geom_toTable.py @@ -30,17 +30,17 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - + damask.util.croak(geom) - + # --- generate grid -------------------------------------------------------------------------------- grid = geom.get_grid() size = geom.get_size() origin = geom.get_origin() - + x = (0.5 + np.arange(grid[0],dtype=float))/grid[0]*size[0]+origin[0] y = (0.5 + np.arange(grid[1],dtype=float))/grid[1]*size[1]+origin[1] z = (0.5 + np.arange(grid[2],dtype=float))/grid[2]*size[2]+origin[2] diff --git a/processing/pre/geom_translate.py b/processing/pre/geom_translate.py index 127c63bc6..4b91920ae 100755 --- a/processing/pre/geom_translate.py +++ b/processing/pre/geom_translate.py @@ -48,13 +48,13 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - + substituted = geom.get_microstructure() for old,new in zip(sub[0::2],sub[1::2]): substituted[substituted==old] = new # substitute microstructure indices substituted += options.microstructure # constant shift - + damask.util.croak(geom.update(substituted,origin=geom.get_origin()+options.origin)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) diff --git a/processing/pre/geom_unpack.py b/processing/pre/geom_unpack.py index b1b12d2cc..2a2d54130 100755 --- a/processing/pre/geom_unpack.py +++ b/processing/pre/geom_unpack.py @@ -30,10 +30,10 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - + damask.util.croak(geom) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) - + if name is None: sys.stdout.write(str(geom.show())) else: diff --git a/processing/pre/geom_vicinityOffset.py b/processing/pre/geom_vicinityOffset.py index bda6b6c5f..3a4853121 100755 --- a/processing/pre/geom_vicinityOffset.py +++ b/processing/pre/geom_vicinityOffset.py @@ -68,7 +68,7 @@ if filenames == []: filenames = [None] for name in filenames: damask.util.report(scriptName,name) - + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) offset = np.nanmax(geom.microstructure) if options.offset is None else options.offset @@ -81,7 +81,7 @@ for name in filenames: extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}), geom.microstructure + offset,geom.microstructure))) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) - + if name is None: sys.stdout.write(str(geom.show())) else: From c2a5f37818c77786b5cb21673888bb770fd7dc2f Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 14:11:54 +0200 Subject: [PATCH 096/120] round to reasonable precision without symmetry, there are 36000**3 = 46656000000000 orientations --- PRIVATE | 2 +- processing/pre/geom_fromTable.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PRIVATE b/PRIVATE index 78641eab9..85a39db96 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 78641eab9dd03d2b11c4d2a2ecb222822fbbb2a9 +Subproject commit 85a39db96387330e2509650558fddc31e048e6ea diff --git a/processing/pre/geom_fromTable.py b/processing/pre/geom_fromTable.py index c0b327d7d..aa37451c7 100755 --- a/processing/pre/geom_fromTable.py +++ b/processing/pre/geom_fromTable.py @@ -135,7 +135,7 @@ for name in filenames: for i,data in enumerate(unique): ori = damask.Rotation(data[0:4]) config_header += ['[Grain{}]'.format(i+1), - '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}'.format(*ori.asEulers(degrees = True)), + '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*ori.asEulers(degrees = True)), ] if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] From 08052737cf0ea4e1186c9fbec7a41475d02af31b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 14:28:31 +0200 Subject: [PATCH 097/120] if grid is an option, it is a tuple tuples do not have the prod() function --- PRIVATE | 2 +- processing/pre/geom_fromVoronoiTessellation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PRIVATE b/PRIVATE index 85a39db96..c93e2b1d7 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 85a39db96387330e2509650558fddc31e048e6ea +Subproject commit c93e2b1d7c39167fff9f1484857c58d34090d3f6 diff --git a/processing/pre/geom_fromVoronoiTessellation.py b/processing/pre/geom_fromVoronoiTessellation.py index dd2e5e8ea..9d4573c2c 100755 --- a/processing/pre/geom_fromVoronoiTessellation.py +++ b/processing/pre/geom_fromVoronoiTessellation.py @@ -270,7 +270,7 @@ for name in filenames: y = (np.arange(info['grid'][1])+0.5)*info['size'][1]/info['grid'][1] z = (np.arange(info['grid'][2])+0.5)*info['size'][2]/info['grid'][2] X,Y,Z = np.meshgrid(x, y, z,indexing='ij') - grid = np.stack((X,Y,Z),axis=-1).reshape((info['grid'].prod(),3),order='F') + grid = np.stack((X,Y,Z),axis=-1).reshape((np.prod(info['grid']),3),order='F') damask.util.croak('tessellating...') indices = laguerreTessellation(grid, coords, weights, grains, options.periodic, options.cpus) From 46f0ad052e717ad016ce2a52d30742e054c94b91 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 15:35:45 +0200 Subject: [PATCH 098/120] direct support for vtk output - geom_check can now handle multiple files - microstructure index is stored as integer in vtk file --- processing/pre/geom_check.py | 39 ++++++++++++++++++++++++ processing/pre/geom_check.sh | 25 --------------- python/damask/geom.py | 59 ++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 25 deletions(-) create mode 100755 processing/pre/geom_check.py delete mode 100755 processing/pre/geom_check.sh diff --git a/processing/pre/geom_check.py b/processing/pre/geom_check.py new file mode 100755 index 000000000..a79c7e1a4 --- /dev/null +++ b/processing/pre/geom_check.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import os +import sys +from io import StringIO +from optparse import OptionParser + +import damask + + +scriptName = os.path.splitext(os.path.basename(__file__))[0] +scriptID = ' '.join([scriptName,damask.version]) + + +#-------------------------------------------------------------------------------------------------- +# MAIN +#-------------------------------------------------------------------------------------------------- + +parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile(s)]', description = """ +Writes vtk file for visualization. + +""", version = scriptID) + +(options, filenames) = parser.parse_args() + + +if filenames == []: filenames = [None] + +for name in filenames: + damask.util.report(scriptName,name) + + geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) + + damask.util.croak(geom) + + if name is None: + sys.stdout.write(geom.to_vtk()) + else: + geom.to_vtk(os.path.splitext(name)[0]) diff --git a/processing/pre/geom_check.sh b/processing/pre/geom_check.sh deleted file mode 100755 index fbae91043..000000000 --- a/processing/pre/geom_check.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -if [[ "$1" == "-f" || "$1" == "--float" ]]; then - shift - arg='--float' -else - arg='' -fi - -for geom in "$@" -do - geom_toTable $arg \ - < $geom \ - | \ - vtk_rectilinearGrid > ${geom%.*}.vtk - - geom_toTable $arg \ - < $geom \ - | \ - vtk_addRectilinearGridData \ - --vtk ${geom%.*}.vtk \ - --data microstructure \ - - rm ${geom%.*}.vtk -done diff --git a/python/damask/geom.py b/python/damask/geom.py index e422516a7..365e54ade 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -1,8 +1,12 @@ +import os from io import StringIO import numpy as np +import vtk +from vtk.util import numpy_support from . import util +from . import version class Geom(): @@ -197,6 +201,61 @@ class Geom(): np.savetxt(fname, self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T, header='\n'.join(header), fmt=format_string, comments='') + + + + def to_vtk(self,fname=None): + """Generates vtk file. If file name is given, stored in file otherwise returned as string""" + grid = self.get_grid() + np.ones(3,dtype=int) + size = self.get_size() + origin = self.get_origin() + + coords = [ + np.linspace(0,size[0],grid[0]) - origin[0], + np.linspace(0,size[1],grid[1]) - origin[1], + np.linspace(0,size[2],grid[2]) - origin[2] + ] + + rGrid = vtk.vtkRectilinearGrid() + coordArray = [vtk.vtkDoubleArray(),vtk.vtkDoubleArray(),vtk.vtkDoubleArray()] + + rGrid.SetDimensions(*grid) + for d,coord in enumerate(coords): + for c in coord: + coordArray[d].InsertNextValue(c) + + rGrid.SetXCoordinates(coordArray[0]) + rGrid.SetYCoordinates(coordArray[1]) + rGrid.SetZCoordinates(coordArray[2]) + + ms = numpy_support.numpy_to_vtk(num_array=self.microstructure.flatten(order='F'),array_type=vtk.VTK_INT) + ms.SetName('microstructure') + rGrid.GetCellData().AddArray(ms) + + + if fname is not None: + writer = vtk.vtkXMLRectilinearGridWriter() + writer.SetCompressorTypeToZLib() + writer.SetDataModeToBinary() + + ext = os.path.splitext(fname)[1] + if ext == '': + name = fname + '.' + writer.GetDefaultFileExtension() + elif ext == writer.GetDefaultFileExtension(): + name = fname + else: + raise ValueError("unknown extension {}".format(ext)) + writer.SetFileName(name) + else: + writer = vtk.vtkDataSetWriter() + writer.SetHeader('damask.Geom '+version) + writer.WriteToOutputStringOn() + + writer.SetInputData(rGrid) + writer.Write() + + if fname is None: return writer.GetOutputString() + def show(self): """Show raw content (as in file)""" From 8c38a2e56f1ec77c6f7b0f8d2e576393591e55d1 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 17:39:49 +0200 Subject: [PATCH 099/120] include relaxation to nonlocal tests --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index 3a2f89547..d31da38cf 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 3a2f89547c264044a7bfab9d33aee78eec495a76 +Subproject commit d31da38cf25734a91e994a3d5d33bb048eb2f44f From 4cb0ba380362695da28dce99eaa6db136845ed22 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 19:26:41 +0200 Subject: [PATCH 100/120] not needed anymore --- python/damask/asciitable.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/python/damask/asciitable.py b/python/damask/asciitable.py index 448587db0..8dd0a549d 100644 --- a/python/damask/asciitable.py +++ b/python/damask/asciitable.py @@ -244,17 +244,6 @@ class ASCIItable(): return info,extra_header -# ------------------------------------------------------------------ - def head_putGeom(self,info): - """Translate geometry description to header""" - self.info_append([ - "grid\ta {}\tb {}\tc {}".format(*info['grid']), - "size\tx {}\ty {}\tz {}".format(*info['size']), - "origin\tx {}\ty {}\tz {}".format(*info['origin']), - "homogenization\t{}".format(info['homogenization']), - "microstructures\t{}".format(info['microstructures']), - ]) - # ------------------------------------------------------------------ def labels_append(self, what, From 37de73535d1ab541c69030cbb3b64ac39bfc584e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 20:02:55 +0200 Subject: [PATCH 101/120] following PEP style guide --- python/damask/Lambert.py | 2 -- python/damask/asciitable.py | 23 +++++------------------ python/damask/colormaps.py | 6 ++---- python/damask/environment.py | 5 ++--- python/damask/orientation.py | 4 ++-- python/damask/quaternion.py | 2 -- python/damask/util.py | 10 +++++++--- 7 files changed, 18 insertions(+), 34 deletions(-) diff --git a/python/damask/Lambert.py b/python/damask/Lambert.py index 5d07f73f4..73909f963 100644 --- a/python/damask/Lambert.py +++ b/python/damask/Lambert.py @@ -1,5 +1,3 @@ -# -*- coding: UTF-8 no BOM -*- - #################################################################################################### # Code below available according to the followin conditions on https://github.com/MarDiehl/3Drotations #################################################################################################### diff --git a/python/damask/asciitable.py b/python/damask/asciitable.py index 8dd0a549d..59e285d6a 100644 --- a/python/damask/asciitable.py +++ b/python/damask/asciitable.py @@ -1,6 +1,9 @@ -# -*- coding: UTF-8 no BOM -*- +import os +import sys +import re +import shlex +from collections import Iterable -import os, sys import numpy as np # ------------------------------------------------------------------ @@ -80,8 +83,6 @@ class ASCIItable(): def _quote(self, what): """Quote empty or white space-containing output""" - import re - return '{quote}{content}{quote}'.format( quote = ('"' if str(what)=='' or re.search(r"\s",str(what)) else ''), content = what) @@ -147,8 +148,6 @@ class ASCIItable(): by either reading the first row or, if keyword "head[*]" is present, the last line of the header """ - import re,shlex - try: self.__IO__['in'].seek(0) except IOError: @@ -276,8 +275,6 @@ class ASCIItable(): "x" for "1_x","2_x",... unless raw output is requested. operates on object tags or given list. """ - from collections import Iterable - if tags is None: tags = self.tags if isinstance(tags, Iterable) and not raw: # check whether list of tags is requested @@ -313,8 +310,6 @@ class ASCIItable(): return numpy array if asked for list of labels. transparently deals with label positions implicitly given as numbers or their headings given as strings. """ - from collections import Iterable - if isinstance(labels, Iterable) and not isinstance(labels, str): # check whether list of labels is requested idx = [] for label in labels: @@ -354,8 +349,6 @@ class ASCIItable(): return numpy array if asked for list of labels. transparently deals with label positions implicitly given as numbers or their headings given as strings. """ - from collections import Iterable - listOfLabels = isinstance(labels, Iterable) and not isinstance(labels, str) # check whether list of labels is requested if not listOfLabels: labels = [labels] @@ -389,8 +382,6 @@ class ASCIItable(): return numpy array if asked for list of labels. transparently deals with label positions implicitly given as numbers or their headings given as strings. """ - from collections import Iterable - start = self.label_index(labels) dim = self.label_dimension(labels) @@ -436,8 +427,6 @@ class ASCIItable(): advance = True, respectLabels = True): """Read next line (possibly buffered) and parse it into data array""" - import shlex - self.line = self.__IO__['readBuffer'].pop(0) if len(self.__IO__['readBuffer']) > 0 \ else self.__IO__['in'].readline().strip() # take buffered content or get next data row from file @@ -458,8 +447,6 @@ class ASCIItable(): def data_readArray(self, labels = []): """Read whole data of all (given) labels as numpy array""" - from collections import Iterable - try: self.data_rewind() # try to wind back to start of data except: pass # assume/hope we are at data start already... diff --git a/python/damask/colormaps.py b/python/damask/colormaps.py index 17c2e508d..496b76b4f 100644 --- a/python/damask/colormaps.py +++ b/python/damask/colormaps.py @@ -1,8 +1,6 @@ -# -*- coding: UTF-8 no BOM -*- +import math -import math,numpy as np - -### --- COLOR CLASS -------------------------------------------------- +import numpy as np class Color(): """ diff --git a/python/damask/environment.py b/python/damask/environment.py index 21eb24694..ef07cd264 100644 --- a/python/damask/environment.py +++ b/python/damask/environment.py @@ -1,6 +1,5 @@ -# -*- coding: UTF-8 no BOM -*- - -import os,re +import os +import re class Environment(): __slots__ = [ \ diff --git a/python/damask/orientation.py b/python/damask/orientation.py index aae96c8d6..116333e81 100644 --- a/python/damask/orientation.py +++ b/python/damask/orientation.py @@ -1,7 +1,7 @@ -# -*- coding: UTF-8 no BOM -*- - import math + import numpy as np + from . import Lambert from .quaternion import Quaternion from .quaternion import P diff --git a/python/damask/quaternion.py b/python/damask/quaternion.py index fd681fe9b..203a398ef 100644 --- a/python/damask/quaternion.py +++ b/python/damask/quaternion.py @@ -1,5 +1,3 @@ -# -*- coding: UTF-8 no BOM -*- - import numpy as np P = -1 # convention (see DOI:10.1088/0965-0393/23/8/083501) diff --git a/python/damask/util.py b/python/damask/util.py index 7e7bae3bc..189f08a98 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -1,8 +1,12 @@ -# -*- coding: UTF-8 no BOM -*- -import sys,time,os,subprocess,shlex -import numpy as np +import sys +import time +import os +import subprocess +import shlex from optparse import Option +import numpy as np + class bcolors: """ ASCII Colors (Blender code) From d4392dc1bdb875cdd50b77af8bcc7d000841af36 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 30 May 2019 23:58:59 +0200 Subject: [PATCH 102/120] one implicit none is enough --- src/grid/spectral_utilities.f90 | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/grid/spectral_utilities.f90 b/src/grid/spectral_utilities.f90 index 1d5e42070..f545eab4e 100644 --- a/src/grid/spectral_utilities.f90 +++ b/src/grid/spectral_utilities.f90 @@ -196,7 +196,6 @@ subroutine utilities_init grid3Offset, & geomSize - implicit none PetscErrorCode :: ierr integer :: i, j, k, & FFTW_planner_flag @@ -425,7 +424,6 @@ subroutine utilities_updateGamma(C,saveReference) math_det33, & math_invert2 - implicit none real(pReal), intent(in), dimension(3,3,3,3) :: C !< input stiffness to store as reference stiffness logical , intent(in) :: saveReference !< save reference stiffness to file for restart complex(pReal), dimension(3,3) :: temp33_complex, xiDyad_cmplx @@ -473,7 +471,6 @@ end subroutine utilities_updateGamma !> @details Does an unweighted filtered FFT transform from real to complex !-------------------------------------------------------------------------------------------------- subroutine utilities_FFTtensorForward - implicit none call fftw_mpi_execute_dft_r2c(planTensorForth,tensorField_real,tensorField_fourier) @@ -485,7 +482,6 @@ end subroutine utilities_FFTtensorForward !> @details Does an weighted inverse FFT transform from complex to real !-------------------------------------------------------------------------------------------------- subroutine utilities_FFTtensorBackward - implicit none call fftw_mpi_execute_dft_c2r(planTensorBack,tensorField_fourier,tensorField_real) tensorField_real = tensorField_real * wgt ! normalize the result by number of elements @@ -497,7 +493,6 @@ end subroutine utilities_FFTtensorBackward !> @details Does an unweighted filtered FFT transform from real to complex !-------------------------------------------------------------------------------------------------- subroutine utilities_FFTscalarForward - implicit none call fftw_mpi_execute_dft_r2c(planScalarForth,scalarField_real,scalarField_fourier) @@ -509,7 +504,6 @@ end subroutine utilities_FFTscalarForward !> @details Does an weighted inverse FFT transform from complex to real !-------------------------------------------------------------------------------------------------- subroutine utilities_FFTscalarBackward - implicit none call fftw_mpi_execute_dft_c2r(planScalarBack,scalarField_fourier,scalarField_real) scalarField_real = scalarField_real * wgt ! normalize the result by number of elements @@ -522,7 +516,6 @@ end subroutine utilities_FFTscalarBackward !> @details Does an unweighted filtered FFT transform from real to complex. !-------------------------------------------------------------------------------------------------- subroutine utilities_FFTvectorForward - implicit none call fftw_mpi_execute_dft_r2c(planVectorForth,vectorField_real,vectorField_fourier) @@ -534,7 +527,6 @@ end subroutine utilities_FFTvectorForward !> @details Does an weighted inverse FFT transform from complex to real !-------------------------------------------------------------------------------------------------- subroutine utilities_FFTvectorBackward - implicit none call fftw_mpi_execute_dft_c2r(planVectorBack,vectorField_fourier,vectorField_real) vectorField_real = vectorField_real * wgt ! normalize the result by number of elements @@ -554,7 +546,6 @@ subroutine utilities_fourierGammaConvolution(fieldAim) grid, & grid3Offset - implicit none real(pReal), intent(in), dimension(3,3) :: fieldAim !< desired average value of the field after convolution complex(pReal), dimension(3,3) :: temp33_complex, xiDyad_cmplx real(pReal), dimension(6,6) :: A, A_inv @@ -615,7 +606,6 @@ subroutine utilities_fourierGreenConvolution(D_ref, mobility_ref, deltaT) grid, & grid3 - implicit none real(pReal), dimension(3,3), intent(in) :: D_ref real(pReal), intent(in) :: mobility_ref, deltaT complex(pReal) :: GreenOp_hat @@ -644,7 +634,6 @@ real(pReal) function utilities_divergenceRMS() grid, & grid3 - implicit none integer :: i, j, k, ierr complex(pReal), dimension(3) :: rescaledGeom @@ -694,7 +683,6 @@ real(pReal) function utilities_curlRMS() grid, & grid3 - implicit none integer :: i, j, k, l, ierr complex(pReal), dimension(3,3) :: curl_fourier complex(pReal), dimension(3) :: rescaledGeom @@ -766,7 +754,6 @@ function utilities_maskedCompliance(rot_BC,mask_stress,C) math_rotate_forward33, & math_invert2 - implicit none real(pReal), dimension(3,3,3,3) :: utilities_maskedCompliance !< masked compliance real(pReal), intent(in) , dimension(3,3,3,3) :: C !< current average stiffness real(pReal), intent(in) , dimension(3,3) :: rot_BC !< rotation of load frame @@ -861,7 +848,6 @@ subroutine utilities_fourierScalarGradient() grid3, & grid - implicit none integer :: i, j, k vectorField_fourier = cmplx(0.0_pReal,0.0_pReal,pReal) @@ -879,7 +865,6 @@ subroutine utilities_fourierVectorDivergence() grid3, & grid - implicit none integer :: i, j, k scalarField_fourier = cmplx(0.0_pReal,0.0_pReal,pReal) @@ -898,7 +883,6 @@ subroutine utilities_fourierVectorGradient() grid3, & grid - implicit none integer :: i, j, k, m, n tensorField_fourier = cmplx(0.0_pReal,0.0_pReal,pReal) @@ -919,7 +903,6 @@ subroutine utilities_fourierTensorDivergence() grid3, & grid - implicit none integer :: i, j, k, m, n vectorField_fourier = cmplx(0.0_pReal,0.0_pReal,pReal) @@ -954,7 +937,6 @@ subroutine utilities_constitutiveResponse(P,P_av,C_volAvg,C_minmaxAvg,& materialpoint_dPdF, & materialpoint_stressAndItsTangent - implicit none real(pReal),intent(out), dimension(3,3,3,3) :: C_volAvg, C_minmaxAvg !< average stiffness real(pReal),intent(out), dimension(3,3) :: P_av !< average PK stress real(pReal),intent(out), dimension(3,3,grid(1),grid(2),grid3) :: P !< PK stress @@ -1032,7 +1014,6 @@ pure function utilities_calculateRate(heterogeneous,field0,field,dt,avRate) grid3, & grid - implicit none real(pReal), intent(in), dimension(3,3) :: & avRate !< homogeneous addon real(pReal), intent(in) :: & @@ -1063,7 +1044,6 @@ function utilities_forwardField(timeinc,field_lastInc,rate,aim) grid3, & grid - implicit none real(pReal), intent(in) :: & timeinc !< timeinc of current step real(pReal), intent(in), dimension(3,3,grid(1),grid(2),grid3) :: & @@ -1100,7 +1080,6 @@ pure function utilities_getFreqDerivative(k_s) geomSize, & grid - implicit none integer, intent(in), dimension(3) :: k_s !< indices of frequency complex(pReal), dimension(3) :: utilities_getFreqDerivative @@ -1158,7 +1137,6 @@ subroutine utilities_updateIPcoords(F) grid3Offset, & geomSize, & mesh_ipCoordinates - implicit none real(pReal), dimension(3,3,grid(1),grid(2),grid3), intent(in) :: F integer :: i, j, k, m, ierr From 45efa9cc91c65926394a0724aa2872820b45a362 Mon Sep 17 00:00:00 2001 From: Test User Date: Fri, 31 May 2019 05:47:53 +0200 Subject: [PATCH 103/120] [skip ci] updated version information after successful test of v2.0.3-350-g8c38a2e5 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 40e72919d..483423ba0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.3-344-gb25c64d1 +v2.0.3-350-g8c38a2e5 From 30826c5c8666d5c50d1e42d1304a51c64b1ef258 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 31 May 2019 09:05:58 +0200 Subject: [PATCH 104/120] not supported anymore is part of the geometry --- examples/SpectralMethod/Polycrystal/material.config | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/SpectralMethod/Polycrystal/material.config b/examples/SpectralMethod/Polycrystal/material.config index 71d7e07d7..8103e7128 100644 --- a/examples/SpectralMethod/Polycrystal/material.config +++ b/examples/SpectralMethod/Polycrystal/material.config @@ -11,7 +11,6 @@ mech none [almostAll] (output) phase (output) texture -(output) volume (output) orientation # quaternion (output) grainrotation # deviation from initial orientation as axis (1-3) and angle in degree (4) (output) f # deformation gradient tensor; synonyms: "defgrad" From 979145f023cc80e8786b49272a5d09993b44a756 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 31 May 2019 10:27:26 +0200 Subject: [PATCH 105/120] vectorized --- processing/pre/geom_addPrimitive.py | 1 + processing/pre/geom_canvas.py | 20 ++++++++++---------- processing/pre/geom_fromOsteonGeometry.py | 1 + processing/pre/geom_grainGrowth.py | 1 + 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/processing/pre/geom_addPrimitive.py b/processing/pre/geom_addPrimitive.py index 99035c8fe..3e147e24d 100755 --- a/processing/pre/geom_addPrimitive.py +++ b/processing/pre/geom_addPrimitive.py @@ -9,6 +9,7 @@ import numpy as np import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index b0748dcf3..12379e5ea 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -9,6 +9,7 @@ import numpy as np import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) @@ -49,6 +50,7 @@ for name in filenames: geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) grid = geom.get_grid() + offset = np.array(options.offset) if options.grid is not None: grid = np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ else int(n) for o,n in zip(grid,options.grid)],dtype=int) @@ -56,17 +58,15 @@ for name in filenames: new = np.full(grid,options.fill if options.fill is not None else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) + + l = np.clip( offset,0,geom.microstructure.shape) + r = np.clip(new.shape+offset,0,geom.microstructure.shape) + + L = np.clip( -offset,0,new.shape) + R = np.clip(geom.microstructure.shape-offset,0,new.shape) + + new[l[0]:r[0],l[1]:r[1],l[2]:r[2]] = geom.microstructure[L[0]:R[0],L[1]:R[1],L[2]:R[2]] - for x in range(geom.microstructure.shape[0]): - X = x + options.offset[0] - if not 0 <= X < new.shape[0]: continue - for y in range(geom.microstructure.shape[1]): - Y = y + options.offset[1] - if not 0 <= Y < new.shape[1]: continue - for z in range(geom.microstructure.shape[2]): - Z = z + options.offset[2] - if not 0 <= Z < new.shape[2]: continue - new[X,Y,Z] = geom.microstructure[x,y,z] damask.util.croak(geom.update(new,origin=(0,0,0),rescale=True)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) diff --git a/processing/pre/geom_fromOsteonGeometry.py b/processing/pre/geom_fromOsteonGeometry.py index 98d2cf9ea..146bf216c 100755 --- a/processing/pre/geom_fromOsteonGeometry.py +++ b/processing/pre/geom_fromOsteonGeometry.py @@ -8,6 +8,7 @@ import numpy as np import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) diff --git a/processing/pre/geom_grainGrowth.py b/processing/pre/geom_grainGrowth.py index 93f43d3b3..b31fc13f2 100755 --- a/processing/pre/geom_grainGrowth.py +++ b/processing/pre/geom_grainGrowth.py @@ -10,6 +10,7 @@ from scipy import ndimage import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) From 236b5c8bde2aa7a7e34ca4da592ac527b6050c92 Mon Sep 17 00:00:00 2001 From: Test User Date: Fri, 31 May 2019 15:40:17 +0200 Subject: [PATCH 106/120] [skip ci] updated version information after successful test of v2.0.3-367-g70428155 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 483423ba0..4e8921669 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.3-350-g8c38a2e5 +v2.0.3-367-g70428155 From 02671c5c03a634f0f123d089db21322b2fdcc4e8 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 31 May 2019 15:58:47 +0200 Subject: [PATCH 107/120] bugfix shoud now work for any possible combination of new and old grid and offset --- processing/pre/geom_canvas.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index 12379e5ea..992932030 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -50,7 +50,7 @@ for name in filenames: geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) grid = geom.get_grid() - offset = np.array(options.offset) + offset = np.asarray(options.offset) if options.grid is not None: grid = np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ else int(n) for o,n in zip(grid,options.grid)],dtype=int) @@ -58,13 +58,16 @@ for name in filenames: new = np.full(grid,options.fill if options.fill is not None else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) - - l = np.clip( offset,0,geom.microstructure.shape) - r = np.clip(new.shape+offset,0,geom.microstructure.shape) - - L = np.clip( -offset,0,new.shape) - R = np.clip(geom.microstructure.shape-offset,0,new.shape) - + + n = np.asarray(new.shape) + o = np.asarray(geom.microstructure.shape) + + l = np.clip( offset, 0,np.minimum(o +offset,n)) + r = np.clip( offset+o,0,np.minimum(o*2+offset,n)) + + L = np.clip(-offset, 0,np.minimum(n -offset,o)) + R = np.clip(-offset+n,0,np.minimum(n*2-offset,o)) + new[l[0]:r[0],l[1]:r[1],l[2]:r[2]] = geom.microstructure[L[0]:R[0],L[1]:R[1],L[2]:R[2]] From 615ff4ed06544f698ba7001fbaa8f8c327b06dac Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 31 May 2019 23:26:32 +0200 Subject: [PATCH 108/120] [skip ci] vectorized --- processing/pre/geom_fromMinimalSurface.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/processing/pre/geom_fromMinimalSurface.py b/processing/pre/geom_fromMinimalSurface.py index 19686f763..ab42ce5af 100755 --- a/processing/pre/geom_fromMinimalSurface.py +++ b/processing/pre/geom_fromMinimalSurface.py @@ -76,15 +76,13 @@ parser.set_defaults(type = minimal_surfaces[0], name = None if filename == [] else filename[0] damask.util.report(scriptName,name) -X = options.periods*2.0*np.pi*(np.arange(options.grid[0])+0.5)/options.grid[0] -Y = options.periods*2.0*np.pi*(np.arange(options.grid[1])+0.5)/options.grid[1] -Z = options.periods*2.0*np.pi*(np.arange(options.grid[2])+0.5)/options.grid[2] +x,y,z = np.meshgrid(options.periods*2.0*np.pi*(np.arange(options.grid[0])+0.5)/options.grid[0], + options.periods*2.0*np.pi*(np.arange(options.grid[1])+0.5)/options.grid[1], + options.periods*2.0*np.pi*(np.arange(options.grid[2])+0.5)/options.grid[2], + indexing='xy',sparse=True) -microstructure = np.empty(options.grid,dtype=int) -for x in range(options.grid[0]): - for y in range(options.grid[1]): - for z in range(options.grid[2]): - microstructure[x,y,z]=options.microstructure[int(options.threshold < surface[options.type](X[x],Y[y],Z[z]))] +microstructure = np.where(options.threshold < surface[options.type](x,y,z), + options.microstructure[1],options.microstructure[0]) geom=damask.Geom(microstructure,options.size, homogenization=options.homogenization, From dff690611ea2ca4f168cd819d452bab3ea410fab Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 3 Jun 2019 13:29:30 -0400 Subject: [PATCH 109/120] fixed origin bug in VTK; VTK can be float; size defaults to 1 as longest dimension --- python/damask/geom.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/python/damask/geom.py b/python/damask/geom.py index 365e54ade..7f9a9d33a 100644 --- a/python/damask/geom.py +++ b/python/damask/geom.py @@ -14,9 +14,9 @@ class Geom(): def __init__(self,microstructure,size,origin=[0.0,0.0,0.0],homogenization=1,comments=[]): """New geometry definition from array of microstructures and size""" + self.set_microstructure(microstructure) self.set_size(size) self.set_origin(origin) - self.set_microstructure(microstructure) self.set_homogenization(homogenization) self.set_comments(comments) @@ -26,7 +26,7 @@ class Geom(): return util.srepr([ 'grid a b c: {}'.format(' x '.join(map(str,self.get_grid ()))), 'size x y z: {}'.format(' x '.join(map(str,self.get_size ()))), - 'origin x y z: {}'.format(' x '.join(map(str,self.get_origin()))), + 'origin x y z: {}'.format(' '.join(map(str,self.get_origin()))), 'homogenization: {}'.format(self.get_homogenization()), '# microstructures: {}'.format(len(np.unique(self.microstructure))), 'max microstructure: {}'.format(np.nanmax(self.microstructure)), @@ -57,10 +57,10 @@ class Geom(): message[-1] = util.delete(message[-1]) message.append('size x y z: {}'.format(' x '.join(map(str,self.get_size())))) - message.append('origin x y z: {}'.format(' x '.join(map(str,origin_old)))) + message.append('origin x y z: {}'.format(' '.join(map(str,origin_old)))) if np.any(origin_old != self.get_origin()): message[-1] = util.delete(message[-1]) - message.append('origin x y z: {}'.format(' x '.join(map(str,self.get_origin())))) + message.append('origin x y z: {}'.format(' '.join(map(str,self.get_origin())))) message.append('homogenization: {}'.format(self.get_homogenization())) @@ -93,7 +93,10 @@ class Geom(): self.microstructure = np.copy(microstructure) def set_size(self,size): - if size is not None: + if size is None: + grid = np.asarray(self.microstructure.shape) + self.size = grid/np.max(grid) + else: if len(size) != 3 or any(np.array(size)<=0): raise ValueError('Invalid size {}'.format(*size)) else: @@ -211,9 +214,9 @@ class Geom(): origin = self.get_origin() coords = [ - np.linspace(0,size[0],grid[0]) - origin[0], - np.linspace(0,size[1],grid[1]) - origin[1], - np.linspace(0,size[2],grid[2]) - origin[2] + np.linspace(0,size[0],grid[0]) + origin[0], + np.linspace(0,size[1],grid[1]) + origin[1], + np.linspace(0,size[2],grid[2]) + origin[2] ] rGrid = vtk.vtkRectilinearGrid() @@ -228,12 +231,17 @@ class Geom(): rGrid.SetYCoordinates(coordArray[1]) rGrid.SetZCoordinates(coordArray[2]) - ms = numpy_support.numpy_to_vtk(num_array=self.microstructure.flatten(order='F'),array_type=vtk.VTK_INT) + ms = numpy_support.numpy_to_vtk(num_array=self.microstructure.flatten(order='F'), + array_type=vtk.VTK_INT if self.microstructure.dtype == int else vtk.VTK_FLOAT) ms.SetName('microstructure') rGrid.GetCellData().AddArray(ms) - if fname is not None: + if fname is None: + writer = vtk.vtkDataSetWriter() + writer.SetHeader('damask.Geom '+version) + writer.WriteToOutputStringOn() + else: writer = vtk.vtkXMLRectilinearGridWriter() writer.SetCompressorTypeToZLib() writer.SetDataModeToBinary() @@ -246,10 +254,6 @@ class Geom(): else: raise ValueError("unknown extension {}".format(ext)) writer.SetFileName(name) - else: - writer = vtk.vtkDataSetWriter() - writer.SetHeader('damask.Geom '+version) - writer.WriteToOutputStringOn() writer.SetInputData(rGrid) writer.Write() From 7ea417d5855230114d158b2fbf84f19222b543de Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 3 Jun 2019 13:30:14 -0400 Subject: [PATCH 110/120] rotated geometry maintains center of gravity --- processing/pre/geom_rotate.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index 09da7b044..c2a4af04b 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -35,7 +35,7 @@ parser.add_option('-e', '--eulers', parser.add_option('-d', '--degrees', dest = 'degrees', action = 'store_true', - help = 'Angles (Euler angles/axis angle) are given in degrees [%default]') + help = 'Euler angles/axis angle are given in degrees') parser.add_option('-m', '--matrix', dest = 'matrix', type = 'float', nargs = 9, metavar = ' '.join(['float']*9), @@ -61,7 +61,7 @@ if [options.rotation,options.eulers,options.matrix,options.quaternion].count(Non if options.quaternion is not None: rot = damask.Rotation.fromQuaternion(np.array(options.quaternion)) # we might need P=+1 here, too... if options.rotation is not None: - rot = damask.Rotation.fromAxisAngle(np.array(options.rotation),degrees=options.degrees,P=+1) + rot = damask.Rotation.fromAxisAngle(np.array(options.rotation),degrees=options.degrees,normalise=True,P=+1) if options.matrix is not None: rot = damask.Rotation.fromMatrix(np.array(options.Matrix)) if options.eulers is not None: @@ -76,7 +76,9 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - + size = geom.get_size() + grid = geom.get_grid() + origin = geom.get_origin() microstructure = geom.get_microstructure() fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int @@ -90,7 +92,7 @@ for name in filenames: microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0, prefilter=False,output=dtype,cval=fill) # rotation around z - damask.util.croak(geom.update(microstructure,rescale=True)) + damask.util.croak(geom.update(microstructure,origin=origin-(np.asarray(microstructure.shape)-grid)/2*size/grid,rescale=True)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: From 60031cc8060dd12d115d452d455cb2c6b69d6e79 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 3 Jun 2019 13:30:58 -0400 Subject: [PATCH 111/120] changed periodic option to reflect to better reflect what happens --- processing/pre/geom_mirror.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/processing/pre/geom_mirror.py b/processing/pre/geom_mirror.py index 8d3f3d798..67bd2366f 100755 --- a/processing/pre/geom_mirror.py +++ b/processing/pre/geom_mirror.py @@ -29,12 +29,12 @@ parser.add_option('-d','--direction', dest = 'directions', action = 'extend', metavar = '', help = "directions in which to mirror {{{}}}".format(','.join(validDirections))) -parser.add_option( '--periodic', - dest = 'periodic', +parser.add_option( '--reflect', + dest = 'reflect', action = 'store_true', - help = 'omit periodic copies of outermost layers in mirror direction') + help = 'reflect (include) outermost layers') -parser.set_defaults(periodic = False) +parser.set_defaults(reflect = False) (options, filenames) = parser.parse_args() @@ -45,7 +45,7 @@ if not set(options.directions).issubset(validDirections): invalidDirections = [str(e) for e in set(options.directions).difference(validDirections)] parser.error('invalid directions {}. '.format(*invalidDirections)) -limits = [-2,0] if options.periodic else [None,None] +limits = [None,None] if options.reflect else [-2,0] if filenames == []: filenames = [None] From 89e4bc800c0ffd68fe9588e04cb88c92fc233f01 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 3 Jun 2019 13:38:48 -0400 Subject: [PATCH 112/120] removed default size to adjust to changes in geom-class --- processing/pre/geom_fromScratch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/processing/pre/geom_fromScratch.py b/processing/pre/geom_fromScratch.py index e943f7e3e..bfb294080 100755 --- a/processing/pre/geom_fromScratch.py +++ b/processing/pre/geom_fromScratch.py @@ -29,7 +29,7 @@ parser.add_option('-g','--grid', parser.add_option('-s', '--size', dest = 'size', type = 'float', nargs = 3, metavar = ' '.join(['float']*3), - help = 'x,y,z of geometry size %default') + help = 'x,y,z of geometry size') parser.add_option('-o','--origin', dest = 'origin', type = 'float', nargs = 3, metavar = ' '.join(['float']*3), @@ -44,7 +44,6 @@ parser.add_option('-f','--fill', help = 'microstructure index [%default]') parser.set_defaults(grid = (16,16,16), - size = (1.,1.,1.), origin = (0.,0.,0.), homogenization = 1, fill = 1, From 2870fdb25bf9c5ac39d765e84364c81c2efc3ad2 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 3 Jun 2019 13:39:45 -0400 Subject: [PATCH 113/120] fixed buggy version --- processing/pre/geom_canvas.py | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index 992932030..e444aaaf3 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -48,30 +48,29 @@ for name in filenames: damask.util.report(scriptName,name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) - - grid = geom.get_grid() + origin = geom.get_origin() + size = geom.get_size() + grid = canvasgrid = geom.get_grid() offset = np.asarray(options.offset) + if options.grid is not None: - grid = np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ - else int(n) for o,n in zip(grid,options.grid)],dtype=int) - grid = np.maximum(grid,1) + canvasgrid = np.maximum(1, + np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ + else int(n) for o,n in zip(grid,options.grid)],dtype=int)) - new = np.full(grid,options.fill if options.fill is not None - else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) - - n = np.asarray(new.shape) - o = np.asarray(geom.microstructure.shape) - - l = np.clip( offset, 0,np.minimum(o +offset,n)) - r = np.clip( offset+o,0,np.minimum(o*2+offset,n)) - - L = np.clip(-offset, 0,np.minimum(n -offset,o)) - R = np.clip(-offset+n,0,np.minimum(n*2-offset,o)) - - new[l[0]:r[0],l[1]:r[1],l[2]:r[2]] = geom.microstructure[L[0]:R[0],L[1]:R[1],L[2]:R[2]] + canvas = np.full(canvasgrid,options.fill if options.fill is not None + else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) - damask.util.croak(geom.update(new,origin=(0,0,0),rescale=True)) + l = np.maximum( 0, offset) + r = np.minimum(grid,canvasgrid+offset) + L = l - offset + R = r - offset + + canvas [L[0]:R[0],L[1]:R[1],L[2]:R[2]] \ + = geom.microstructure[l[0]:r[0],l[1]:r[1],l[2]:r[2]] + + damask.util.croak(geom.update(canvas,origin=origin+offset*size/grid,rescale=True)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: From 8e023a1f5775ad6b8716e54013a067491528987c Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 3 Jun 2019 13:56:05 -0400 Subject: [PATCH 114/120] modified geom_mirror test to include --reflect option consistent with (former) reference output --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index c1760887b..87a70882e 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit c1760887ba01630c0c4383817567e14efc5279e2 +Subproject commit 87a70882eabd333b390ea2bd96d9ebcf65c62c32 From 8d52a3d52ad6edae93e736d16a3aad3c5061ac1c Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 3 Jun 2019 14:15:23 -0400 Subject: [PATCH 115/120] polishing of geom_rescale; adopted modified testing reference --- PRIVATE | 2 +- processing/pre/geom_rescale.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/PRIVATE b/PRIVATE index 87a70882e..6dc31fe5c 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 87a70882eabd333b390ea2bd96d9ebcf65c62c32 +Subproject commit 6dc31fe5ce138aa76edec7b8d61a0d2b41863f53 diff --git a/processing/pre/geom_rescale.py b/processing/pre/geom_rescale.py index 5acdf87d6..e84c7597b 100755 --- a/processing/pre/geom_rescale.py +++ b/processing/pre/geom_rescale.py @@ -56,12 +56,15 @@ for name in filenames: else float(n) for o,n in zip(size,options.size)],dtype=float) damask.util.croak(geom.update(microstructure = - ndimage.interpolation.zoom( + ndimage.interpolation.zoom( geom.microstructure, - new_grid/grid,output=geom.microstructure.dtype, - order=0,mode='nearest', prefilter=False\ - ) \ - if np.any(new_grid != grid) else None, + new_grid/grid, + output=geom.microstructure.dtype, + order=0, + mode='nearest', + prefilter=False, + ) if np.any(new_grid != grid) \ + else None, size = new_size)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) From 962883d0dca41adfdaa915e7a7817cf91fb8c60d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 3 Jun 2019 20:38:22 +0200 Subject: [PATCH 116/120] using other branch --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index 6dc31fe5c..7424e0624 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 6dc31fe5ce138aa76edec7b8d61a0d2b41863f53 +Subproject commit 7424e0624ecc2ca0db6a83ae4db0a8759ce7fc67 From bffeaa980dea7251b045b0e834e74a163dc32861 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 3 Jun 2019 14:42:35 -0400 Subject: [PATCH 117/120] restored Martin's logic, not clear why seemed to be broken with PE's former tests... --- processing/pre/geom_canvas.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/processing/pre/geom_canvas.py b/processing/pre/geom_canvas.py index e444aaaf3..a44065dd2 100755 --- a/processing/pre/geom_canvas.py +++ b/processing/pre/geom_canvas.py @@ -50,27 +50,25 @@ for name in filenames: geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) origin = geom.get_origin() size = geom.get_size() - grid = canvasgrid = geom.get_grid() + old = new = geom.get_grid() offset = np.asarray(options.offset) if options.grid is not None: - canvasgrid = np.maximum(1, - np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ - else int(n) for o,n in zip(grid,options.grid)],dtype=int)) + new = np.maximum(1, + np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \ + else int(n) for o,n in zip(old,options.grid)],dtype=int)) - canvas = np.full(canvasgrid,options.fill if options.fill is not None - else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) + canvas = np.full(new,options.fill if options.fill is not None + else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) + + l = np.clip( offset, 0,np.minimum(old +offset,new)) + r = np.clip( offset+old,0,np.minimum(old*2+offset,new)) + L = np.clip(-offset, 0,np.minimum(new -offset,old)) + R = np.clip(-offset+new,0,np.minimum(new*2-offset,old)) + canvas[l[0]:r[0],l[1]:r[1],l[2]:r[2]] = geom.microstructure[L[0]:R[0],L[1]:R[1],L[2]:R[2]] - l = np.maximum( 0, offset) - r = np.minimum(grid,canvasgrid+offset) - L = l - offset - R = r - offset - - canvas [L[0]:R[0],L[1]:R[1],L[2]:R[2]] \ - = geom.microstructure[l[0]:r[0],l[1]:r[1],l[2]:r[2]] - - damask.util.croak(geom.update(canvas,origin=origin+offset*size/grid,rescale=True)) + damask.util.croak(geom.update(canvas,origin=origin+offset*size/old,rescale=True)) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) if name is None: From ba99b763c92f05381c1d65d90ba6a6e003aedc6d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 4 Jun 2019 07:21:12 +0200 Subject: [PATCH 118/120] use more verbose test to track MPI restart error --- PRIVATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRIVATE b/PRIVATE index 7424e0624..64cda1c01 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit 7424e0624ecc2ca0db6a83ae4db0a8759ce7fc67 +Subproject commit 64cda1c010d500f662cd9a298c7b7ad10ab91c3c From 951134d13fe46bc9786d1489be1047e4d0818786 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 4 Jun 2019 12:06:16 +0200 Subject: [PATCH 119/120] not needed --- src/lattice.f90 | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/lattice.f90 b/src/lattice.f90 index 43fc25530..126d76d4d 100644 --- a/src/lattice.f90 +++ b/src/lattice.f90 @@ -491,7 +491,7 @@ module lattice end enum integer(kind(LATTICE_undefined_ID)), dimension(:), allocatable, public, protected :: & - lattice_structure, trans_lattice_structure + lattice_structure interface lattice_forestProjection ! DEPRECATED, use lattice_forestProjection_edge @@ -557,7 +557,6 @@ subroutine lattice_init Nphases = size(config_phase) allocate(lattice_structure(Nphases),source = LATTICE_undefined_ID) - allocate(trans_lattice_structure(Nphases),source = LATTICE_undefined_ID) allocate(lattice_C66(6,6,Nphases), source=0.0_pReal) allocate(lattice_C3333(3,3,3,3,Nphases), source=0.0_pReal) @@ -595,14 +594,6 @@ subroutine lattice_init lattice_structure(p) = LATTICE_ort_ID end select - tag = 'undefined' - tag = config_phase(p)%getString('trans_lattice_structure',defaultVal=tag) - select case(trim(tag)) - case('bcc') - trans_lattice_structure(p) = LATTICE_bcc_ID - case('hex','hexagonal') - trans_lattice_structure(p) = LATTICE_hex_ID - end select lattice_C66(1,1,p) = config_phase(p)%getFloat('c11',defaultVal=0.0_pReal) lattice_C66(1,2,p) = config_phase(p)%getFloat('c12',defaultVal=0.0_pReal) From c6db3b4a10c94277cc4751896027a66099206c74 Mon Sep 17 00:00:00 2001 From: Test User Date: Tue, 4 Jun 2019 14:16:45 +0200 Subject: [PATCH 120/120] [skip ci] updated version information after successful test of v2.0.3-369-g951134d1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 4e8921669..4630a890c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.3-367-g70428155 +v2.0.3-369-g951134d1