2018-08-17 14:53:24 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @author Pratheek Shanthraj, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!> @author Philip Eisenlohr, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!> @author Franz Roters, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
module mesh
|
2018-08-30 15:25:13 +05:30
|
|
|
#include <petsc/finclude/petscdmplex.h>
|
2018-08-17 14:53:24 +05:30
|
|
|
#include <petsc/finclude/petscis.h>
|
|
|
|
#include <petsc/finclude/petscdmda.h>
|
2019-06-07 03:50:35 +05:30
|
|
|
use PETScdmplex
|
|
|
|
use PETScdmda
|
|
|
|
use PETScis
|
2019-06-16 00:19:48 +05:30
|
|
|
|
2019-06-07 03:50:35 +05:30
|
|
|
use DAMASK_interface
|
|
|
|
use IO
|
|
|
|
use debug
|
|
|
|
use discretization
|
|
|
|
use numerics
|
|
|
|
use FEsolving
|
|
|
|
use FEM_Zoo
|
2019-06-16 00:19:48 +05:30
|
|
|
use prec
|
|
|
|
use mesh_base
|
2019-06-07 03:50:35 +05:30
|
|
|
|
2018-08-17 14:53:24 +05:30
|
|
|
implicit none
|
|
|
|
private
|
2019-06-07 03:50:35 +05:30
|
|
|
|
2019-06-09 20:00:30 +05:30
|
|
|
integer, public, protected :: &
|
2018-08-17 14:53:24 +05:30
|
|
|
mesh_Nboundaries, &
|
|
|
|
mesh_NcpElems, & !< total number of CP elements in mesh
|
|
|
|
mesh_NcpElemsGlobal, &
|
2019-06-09 19:57:05 +05:30
|
|
|
mesh_Nnodes !< total number of nodes in mesh
|
|
|
|
|
2018-09-23 21:36:18 +05:30
|
|
|
!!!! BEGIN DEPRECATED !!!!!
|
2019-06-09 20:00:30 +05:30
|
|
|
integer, public, protected :: &
|
2018-09-23 22:34:17 +05:30
|
|
|
mesh_maxNips !< max number of IPs in any CP element
|
2018-09-23 21:36:18 +05:30
|
|
|
!!!! BEGIN DEPRECATED !!!!!
|
2018-08-17 14:53:24 +05:30
|
|
|
|
2019-06-16 00:19:48 +05:30
|
|
|
integer, dimension(:,:), allocatable :: &
|
2018-09-23 23:28:43 +05:30
|
|
|
mesh_element !DEPRECATED
|
2018-08-17 14:53:24 +05:30
|
|
|
|
2019-06-16 00:19:48 +05:30
|
|
|
real(pReal), dimension(:,:), allocatable :: &
|
2018-08-17 14:53:24 +05:30
|
|
|
mesh_node !< node x,y,z coordinates (after deformation! ONLY FOR MARC!!!)
|
|
|
|
|
2019-06-16 00:19:48 +05:30
|
|
|
real(pReal), dimension(:,:), allocatable :: &
|
2018-08-17 14:53:24 +05:30
|
|
|
mesh_ipVolume, & !< volume associated with IP (initially!)
|
|
|
|
mesh_node0 !< node x,y,z coordinates (initially!)
|
|
|
|
|
|
|
|
real(pReal), dimension(:,:,:), allocatable, public :: &
|
|
|
|
mesh_ipCoordinates !< IP x,y,z coordinates (after deformation!)
|
|
|
|
|
|
|
|
DM, public :: geomMesh
|
|
|
|
|
2018-09-22 14:02:26 +05:30
|
|
|
PetscInt, dimension(:), allocatable, public, protected :: &
|
2018-08-17 14:53:24 +05:30
|
|
|
mesh_boundaries
|
|
|
|
|
2019-06-09 19:57:05 +05:30
|
|
|
|
2019-01-24 21:20:23 +05:30
|
|
|
type, public, extends(tMesh) :: tMesh_FEM
|
|
|
|
|
|
|
|
|
|
|
|
contains
|
2019-02-02 02:26:38 +05:30
|
|
|
procedure, pass(self) :: tMesh_FEM_init
|
|
|
|
generic, public :: init => tMesh_FEM_init
|
2019-01-24 21:20:23 +05:30
|
|
|
end type tMesh_FEM
|
|
|
|
|
|
|
|
type(tMesh_FEM), public, protected :: theMesh
|
|
|
|
|
|
|
|
|
2018-08-17 14:53:24 +05:30
|
|
|
public :: &
|
|
|
|
mesh_init, &
|
|
|
|
mesh_FEM_build_ipVolumes, &
|
|
|
|
mesh_FEM_build_ipCoordinates, &
|
|
|
|
mesh_cellCenterCoordinates
|
|
|
|
|
|
|
|
contains
|
|
|
|
|
2019-02-02 02:26:38 +05:30
|
|
|
subroutine tMesh_FEM_init(self,dimen,order,nodes)
|
2019-01-24 21:20:23 +05:30
|
|
|
|
2019-06-11 13:18:07 +05:30
|
|
|
integer, intent(in) :: dimen
|
2019-06-09 20:00:30 +05:30
|
|
|
integer, intent(in) :: order
|
2019-06-11 13:18:07 +05:30
|
|
|
real(pReal), intent(in), dimension(:,:) :: nodes
|
2019-01-24 21:20:23 +05:30
|
|
|
class(tMesh_FEM) :: self
|
|
|
|
|
2019-06-09 20:00:30 +05:30
|
|
|
if (dimen == 2) then
|
|
|
|
if (order == 1) call self%tMesh%init('mesh',1,nodes)
|
|
|
|
if (order == 2) call self%tMesh%init('mesh',2,nodes)
|
|
|
|
elseif(dimen == 3) then
|
|
|
|
if (order == 1) call self%tMesh%init('mesh',6,nodes)
|
|
|
|
if (order == 2) call self%tMesh%init('mesh',8,nodes)
|
2019-01-24 21:20:23 +05:30
|
|
|
endif
|
|
|
|
|
2019-02-02 02:26:38 +05:30
|
|
|
end subroutine tMesh_FEM_init
|
|
|
|
|
2019-01-24 21:20:23 +05:30
|
|
|
|
2018-08-17 14:53:24 +05:30
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief initializes the mesh by calling all necessary private routines the mesh module
|
|
|
|
!! Order and routines strongly depend on type of solver
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2019-06-09 19:57:05 +05:30
|
|
|
subroutine mesh_init
|
|
|
|
|
|
|
|
integer, dimension(1), parameter:: FE_geomtype = [1] !< geometry type of particular element type
|
|
|
|
|
|
|
|
integer, dimension(1) :: FE_Nips !< number of IPs in a specific type of element
|
|
|
|
|
2018-08-17 14:53:24 +05:30
|
|
|
|
2019-06-09 20:00:30 +05:30
|
|
|
integer, parameter :: FILEUNIT = 222
|
|
|
|
integer :: j
|
|
|
|
integer, allocatable, dimension(:) :: chunkPos
|
2018-08-17 14:53:24 +05:30
|
|
|
integer :: dimPlex
|
2019-06-09 20:00:30 +05:30
|
|
|
integer, parameter :: &
|
|
|
|
mesh_ElemType=1 !< Element type of the mesh (only support homogeneous meshes)
|
2018-08-17 14:53:24 +05:30
|
|
|
character(len=512) :: &
|
|
|
|
line
|
|
|
|
logical :: flag
|
|
|
|
PetscSF :: sf
|
|
|
|
DM :: globalMesh
|
|
|
|
PetscInt :: face, nFaceSets
|
|
|
|
PetscInt, pointer :: pFaceSets(:)
|
|
|
|
IS :: faceSetIS
|
|
|
|
PetscErrorCode :: ierr
|
|
|
|
|
|
|
|
|
|
|
|
write(6,'(/,a)') ' <<<+- mesh init -+>>>'
|
|
|
|
|
2018-08-30 16:07:47 +05:30
|
|
|
! read in file
|
2018-08-17 14:53:24 +05:30
|
|
|
call DMPlexCreateFromFile(PETSC_COMM_WORLD,geometryFile,PETSC_TRUE,globalMesh,ierr)
|
|
|
|
CHKERRQ(ierr)
|
2018-08-30 16:07:47 +05:30
|
|
|
! get spatial dimension (2 or 3?)
|
2018-08-17 14:53:24 +05:30
|
|
|
call DMGetDimension(globalMesh,dimPlex,ierr)
|
|
|
|
CHKERRQ(ierr)
|
2018-08-30 16:07:47 +05:30
|
|
|
write(6,*) 'dimension',dimPlex;flush(6)
|
2018-08-17 14:53:24 +05:30
|
|
|
call DMGetStratumSize(globalMesh,'depth',dimPlex,mesh_NcpElemsGlobal,ierr)
|
|
|
|
CHKERRQ(ierr)
|
2018-08-30 16:07:47 +05:30
|
|
|
! get number of IDs in face sets (for boundary conditions?)
|
2018-08-17 14:53:24 +05:30
|
|
|
call DMGetLabelSize(globalMesh,'Face Sets',mesh_Nboundaries,ierr)
|
|
|
|
CHKERRQ(ierr)
|
2018-08-30 16:07:47 +05:30
|
|
|
write(6,*) 'number of "Face Sets"',mesh_Nboundaries;flush(6)
|
2018-08-17 14:53:24 +05:30
|
|
|
call MPI_Bcast(mesh_Nboundaries,1,MPI_INTEGER,0,PETSC_COMM_WORLD,ierr)
|
|
|
|
call MPI_Bcast(mesh_NcpElemsGlobal,1,MPI_INTEGER,0,PETSC_COMM_WORLD,ierr)
|
|
|
|
call MPI_Bcast(dimPlex,1,MPI_INTEGER,0,PETSC_COMM_WORLD,ierr)
|
|
|
|
|
2019-06-09 20:00:30 +05:30
|
|
|
allocate(mesh_boundaries(mesh_Nboundaries), source = 0)
|
2018-08-17 14:53:24 +05:30
|
|
|
call DMGetLabelSize(globalMesh,'Face Sets',nFaceSets,ierr)
|
|
|
|
CHKERRQ(ierr)
|
|
|
|
call DMGetLabelIdIS(globalMesh,'Face Sets',faceSetIS,ierr)
|
|
|
|
CHKERRQ(ierr)
|
|
|
|
if (nFaceSets > 0) call ISGetIndicesF90(faceSetIS,pFaceSets,ierr)
|
|
|
|
do face = 1, nFaceSets
|
|
|
|
mesh_boundaries(face) = pFaceSets(face)
|
|
|
|
enddo
|
|
|
|
if (nFaceSets > 0) call ISRestoreIndicesF90(faceSetIS,pFaceSets,ierr)
|
|
|
|
call MPI_Bcast(mesh_boundaries,mesh_Nboundaries,MPI_INTEGER,0,PETSC_COMM_WORLD,ierr)
|
2018-08-30 16:07:47 +05:30
|
|
|
|
|
|
|
! this read in function should ignore C and C++ style comments
|
|
|
|
! it is used for BC only?
|
2018-08-17 14:53:24 +05:30
|
|
|
if (worldrank == 0) then
|
|
|
|
j = 0
|
|
|
|
flag = .false.
|
|
|
|
call IO_open_file(FILEUNIT,trim(geometryFile))
|
|
|
|
do
|
|
|
|
read(FILEUNIT,'(a512)') line
|
|
|
|
if (trim(line) == IO_EOF) exit ! skip empty lines
|
|
|
|
if (trim(line) == '$Elements') then
|
2018-08-30 16:07:47 +05:30
|
|
|
read(FILEUNIT,'(a512)') line ! number of elements (ignore)
|
|
|
|
read(FILEUNIT,'(a512)') line
|
2018-08-17 14:53:24 +05:30
|
|
|
flag = .true.
|
|
|
|
endif
|
|
|
|
if (trim(line) == '$EndElements') exit
|
|
|
|
if (flag) then
|
|
|
|
chunkPos = IO_stringPos(line)
|
|
|
|
if (chunkPos(1) == 3+IO_intValue(line,chunkPos,3)+dimPlex+1) then
|
|
|
|
call DMSetLabelValue(globalMesh,'material',j,IO_intValue(line,chunkPos,4),ierr)
|
|
|
|
CHKERRQ(ierr)
|
|
|
|
j = j + 1
|
|
|
|
endif ! count all identifiers to allocate memory and do sanity check
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
close (FILEUNIT)
|
2019-06-16 00:19:48 +05:30
|
|
|
call DMClone(globalMesh,geomMesh,ierr)
|
2018-08-17 14:53:24 +05:30
|
|
|
CHKERRQ(ierr)
|
|
|
|
else
|
2019-06-16 00:19:48 +05:30
|
|
|
call DMPlexDistribute(globalMesh,0,sf,geomMesh,ierr)
|
2018-08-17 14:53:24 +05:30
|
|
|
CHKERRQ(ierr)
|
|
|
|
endif
|
2019-06-16 00:19:48 +05:30
|
|
|
|
2018-08-17 14:53:24 +05:30
|
|
|
call DMDestroy(globalMesh,ierr); CHKERRQ(ierr)
|
|
|
|
|
2018-09-23 18:49:23 +05:30
|
|
|
call DMGetStratumSize(geomMesh,'depth',dimPlex,mesh_NcpElems,ierr)
|
2018-08-17 14:53:24 +05:30
|
|
|
CHKERRQ(ierr)
|
|
|
|
call DMGetStratumSize(geomMesh,'depth',0,mesh_Nnodes,ierr)
|
|
|
|
CHKERRQ(ierr)
|
|
|
|
|
2019-06-09 20:00:30 +05:30
|
|
|
FE_Nips(FE_geomtype(1)) = FEM_Zoo_nQuadrature(dimPlex,integrationOrder)
|
|
|
|
mesh_maxNips = FE_Nips(1)
|
2019-01-24 21:20:23 +05:30
|
|
|
|
|
|
|
write(6,*) 'mesh_maxNips',mesh_maxNips
|
2018-08-17 14:53:24 +05:30
|
|
|
call mesh_FEM_build_ipCoordinates(dimPlex,FEM_Zoo_QuadraturePoints(dimPlex,integrationOrder)%p)
|
|
|
|
call mesh_FEM_build_ipVolumes(dimPlex)
|
|
|
|
|
2019-06-09 20:00:30 +05:30
|
|
|
allocate (mesh_element (4,mesh_NcpElems)); mesh_element = 0
|
2018-08-17 14:53:24 +05:30
|
|
|
do j = 1, mesh_NcpElems
|
2019-06-09 20:00:30 +05:30
|
|
|
mesh_element( 1,j) = -1 ! DEPRECATED
|
2018-09-23 18:49:23 +05:30
|
|
|
mesh_element( 2,j) = mesh_elemType ! elem type
|
2019-06-09 20:00:30 +05:30
|
|
|
mesh_element( 3,j) = 1 ! homogenization
|
2018-08-17 14:53:24 +05:30
|
|
|
call DMGetLabelValue(geomMesh,'material',j-1,mesh_element(4,j),ierr)
|
|
|
|
CHKERRQ(ierr)
|
|
|
|
end do
|
|
|
|
|
|
|
|
if (debug_e < 1 .or. debug_e > mesh_NcpElems) &
|
2019-06-09 20:00:30 +05:30
|
|
|
call IO_error(602,ext_msg='element') ! selected element does not exist
|
|
|
|
if (debug_i < 1 .or. debug_i > FE_Nips(FE_geomtype(mesh_element(2,debug_e)))) &
|
|
|
|
call IO_error(602,ext_msg='IP') ! selected element does not have requested IP
|
2018-08-17 14:53:24 +05:30
|
|
|
|
2019-06-09 20:00:30 +05:30
|
|
|
FEsolving_execElem = [ 1,mesh_NcpElems ] ! parallel loop bounds set to comprise all DAMASK elements
|
2018-08-17 14:53:24 +05:30
|
|
|
if (allocated(FEsolving_execIP)) deallocate(FEsolving_execIP)
|
2019-06-09 20:00:30 +05:30
|
|
|
allocate(FEsolving_execIP(2,mesh_NcpElems)); FEsolving_execIP = 1 ! parallel loop bounds set to comprise from first IP...
|
|
|
|
forall (j = 1:mesh_NcpElems) FEsolving_execIP(2,j) = FE_Nips(FE_geomtype(mesh_element(2,j))) ! ...up to own IP count for each element
|
2018-08-17 14:53:24 +05:30
|
|
|
|
2019-02-02 02:26:38 +05:30
|
|
|
allocate(mesh_node0(3,mesh_Nnodes),source=0.0_pReal)
|
|
|
|
call theMesh%init(dimplex,integrationOrder,mesh_node0)
|
2019-02-02 16:16:38 +05:30
|
|
|
call theMesh%setNelems(mesh_NcpElems)
|
2019-03-10 15:06:50 +05:30
|
|
|
|
|
|
|
theMesh%homogenizationAt = mesh_element(3,:)
|
|
|
|
theMesh%microstructureAt = mesh_element(4,:)
|
2019-02-02 02:26:38 +05:30
|
|
|
|
2019-06-07 03:50:35 +05:30
|
|
|
call discretization_init(mesh_element(3,:),mesh_element(4,:),&
|
2019-06-07 09:37:00 +05:30
|
|
|
reshape(mesh_ipCoordinates,[3,mesh_maxNips*mesh_NcpElems]), &
|
|
|
|
mesh_node0)
|
2019-06-07 03:50:35 +05:30
|
|
|
|
2018-08-17 14:53:24 +05:30
|
|
|
end subroutine mesh_init
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Calculates cell center coordinates.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
pure function mesh_cellCenterCoordinates(ip,el)
|
|
|
|
|
2019-06-09 20:00:30 +05:30
|
|
|
integer, intent(in) :: el, & !< element number
|
2019-06-11 13:18:07 +05:30
|
|
|
ip !< integration point number
|
2018-08-17 14:53:24 +05:30
|
|
|
real(pReal), dimension(3) :: mesh_cellCenterCoordinates !< x,y,z coordinates of the cell center of the requested IP cell
|
|
|
|
|
2019-06-07 03:50:35 +05:30
|
|
|
end function mesh_cellCenterCoordinates
|
2018-08-17 14:53:24 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @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_FEM_build_ipVolumes(dimPlex)
|
|
|
|
|
2019-06-16 00:19:48 +05:30
|
|
|
PetscInt :: dimPlex
|
|
|
|
PetscReal :: vol
|
|
|
|
PetscReal, target :: cent(dimPlex), norm(dimPlex)
|
|
|
|
PetscReal, pointer :: pCent(:), pNorm(:)
|
|
|
|
PetscInt :: cellStart, cellEnd, cell
|
|
|
|
PetscErrorCode :: ierr
|
|
|
|
|
|
|
|
if (.not. allocated(mesh_ipVolume)) then
|
|
|
|
allocate(mesh_ipVolume(mesh_maxNips,mesh_NcpElems))
|
|
|
|
mesh_ipVolume = 0.0_pReal
|
|
|
|
endif
|
|
|
|
|
|
|
|
call DMPlexGetHeightStratum(geomMesh,0,cellStart,cellEnd,ierr); CHKERRQ(ierr)
|
|
|
|
pCent => cent
|
|
|
|
pNorm => norm
|
|
|
|
do cell = cellStart, cellEnd-1
|
|
|
|
call DMPlexComputeCellGeometryFVM(geomMesh,cell,vol,pCent,pNorm,ierr)
|
|
|
|
CHKERRQ(ierr)
|
|
|
|
mesh_ipVolume(:,cell+1) = vol/real(mesh_maxNips,pReal)
|
|
|
|
enddo
|
2018-08-17 14:53:24 +05:30
|
|
|
|
|
|
|
end subroutine mesh_FEM_build_ipVolumes
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Calculates IP Coordinates. Allocates global array 'mesh_ipCoordinates'
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
subroutine mesh_FEM_build_ipCoordinates(dimPlex,qPoints)
|
|
|
|
|
2019-06-16 00:19:48 +05:30
|
|
|
PetscInt, intent(in) :: dimPlex
|
|
|
|
PetscReal, intent(in) :: qPoints(mesh_maxNips*dimPlex)
|
|
|
|
|
|
|
|
PetscReal, target :: v0(dimPlex), cellJ(dimPlex*dimPlex), invcellJ(dimPlex*dimPlex)
|
|
|
|
PetscReal, pointer :: pV0(:), pCellJ(:), pInvcellJ(:)
|
|
|
|
PetscReal :: detJ
|
|
|
|
PetscInt :: cellStart, cellEnd, cell, qPt, dirI, dirJ, qOffset
|
|
|
|
PetscErrorCode :: ierr
|
2019-06-07 03:50:35 +05:30
|
|
|
|
2019-06-16 00:19:48 +05:30
|
|
|
|
|
|
|
allocate(mesh_ipCoordinates(3,mesh_maxNips,mesh_NcpElems),source=0.0_pReal)
|
|
|
|
|
|
|
|
pV0 => v0
|
|
|
|
pCellJ => cellJ
|
|
|
|
pInvcellJ => invcellJ
|
|
|
|
call DMPlexGetHeightStratum(geomMesh,0,cellStart,cellEnd,ierr); CHKERRQ(ierr)
|
|
|
|
do cell = cellStart, cellEnd-1 !< loop over all elements
|
|
|
|
call DMPlexComputeCellGeometryAffineFEM(geomMesh,cell,pV0,pCellJ,pInvcellJ,detJ,ierr)
|
|
|
|
CHKERRQ(ierr)
|
|
|
|
qOffset = 0
|
|
|
|
do qPt = 1, mesh_maxNips
|
|
|
|
do dirI = 1, dimPlex
|
|
|
|
mesh_ipCoordinates(dirI,qPt,cell+1) = pV0(dirI)
|
|
|
|
do dirJ = 1, dimPlex
|
|
|
|
mesh_ipCoordinates(dirI,qPt,cell+1) = mesh_ipCoordinates(dirI,qPt,cell+1) + &
|
|
|
|
pCellJ((dirI-1)*dimPlex+dirJ)*(qPoints(qOffset+dirJ) + 1.0)
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
qOffset = qOffset + dimPlex
|
|
|
|
enddo
|
|
|
|
enddo
|
2018-08-17 14:53:24 +05:30
|
|
|
|
|
|
|
end subroutine mesh_FEM_build_ipCoordinates
|
|
|
|
|
|
|
|
end module mesh
|