read file only once

This commit is contained in:
Martin Diehl 2020-01-26 19:56:30 +01:00
parent 62865e779d
commit 830b05005f
3 changed files with 17 additions and 46 deletions

View File

@ -23,7 +23,6 @@ module IO
public :: &
IO_init, &
IO_read_ASCII, &
IO_open_file, & ! deprecated, use IO_read_ASCII
IO_open_jobFile_binary, &
IO_isBlank, &
IO_getTag, &
@ -125,23 +124,6 @@ function IO_read_ASCII(fileName) result(fileContent)
end function IO_read_ASCII
!--------------------------------------------------------------------------------------------------
!> @brief opens existing file for reading to given unit. Path to file is relative to working
!! directory
!--------------------------------------------------------------------------------------------------
subroutine IO_open_file(fileUnit,path)
integer, intent(in) :: fileUnit !< file unit
character(len=*), intent(in) :: path !< relative path from working directory
integer :: myStat
open(fileUnit,status='old',iostat=myStat,file=path,action='read',position='rewind')
if (myStat /= 0) call IO_error(100,el=myStat,ext_msg=path)
end subroutine IO_open_file
!--------------------------------------------------------------------------------------------------
!> @brief opens an existing file for reading or a new file for writing. Name is the job name
!> @details replaces an existing file when writing

View File

@ -1,4 +1,4 @@
!-------------------------------------------------------------------------------------------------
!--------------------------------------------------------------------------------------------------
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
!> @brief Reads in the material configuration from file
!> @details Reads the material configuration file, where solverJobName.materialConfig takes

View File

@ -39,9 +39,6 @@ module mesh
integer, dimension(:,:), allocatable :: &
mesh_element !DEPRECATED
real(pReal), dimension(:,:), allocatable :: &
mesh_node !< node x,y,z coordinates (after deformation! ONLY FOR MARC!!!)
real(pReal), dimension(:,:), allocatable :: &
mesh_ipVolume, & !< volume associated with IP (initially!)
mesh_node0 !< node x,y,z coordinates (initially!)
@ -71,20 +68,18 @@ 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
integer, parameter :: FILEUNIT = 222
integer :: j
integer :: j, l
integer, allocatable, dimension(:) :: chunkPos
integer :: dimPlex, &
mesh_Nnodes !< total number of nodes in mesh
integer, parameter :: &
mesh_ElemType=1 !< Element type of the mesh (only support homogeneous meshes)
character(len=pStringLen) :: &
line
logical :: flag
logical :: found
PetscSF :: sf
DM :: globalMesh
PetscInt :: nFaceSets
PetscInt, pointer :: pFaceSets(:)
PetscInt, pointer, dimension(:) :: pFaceSets
character(len=pStringLen), dimension(:), allocatable :: fileContent
IS :: faceSetIS
PetscErrorCode :: ierr
@ -122,31 +117,25 @@ subroutine mesh_init
endif
call MPI_Bcast(mesh_boundaries,mesh_Nboundaries,MPI_INTEGER,0,PETSC_COMM_WORLD,ierr)
! this read in function should ignore C and C++ style comments
! it is used for BC only?
if (worldrank == 0) then
fileContent = IO_read_ASCII(geometryFile)
j = 0
flag = .false.
call IO_open_file(FILEUNIT,trim(geometryFile))
l = 0
found = .false.
do
read(FILEUNIT,'(a)') line
if (trim(line) == IO_EOF) exit ! skip empty lines
if (trim(line) == '$Elements') then
read(FILEUNIT,'(A)') line ! number of elements (ignore)
read(FILEUNIT,'(A)') line
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)
l = l + 1
if (IO_isBlank(fileContent(l))) cycle ! need also to ignore C and C++ style comments?
if (trim(fileContent(l)) == '$EndElements') exit
if (trim(fileContent(l)) == '$Elements') found = .true.
if (found) then
chunkPos = IO_stringPos(fileContent(l))
if (chunkPos(1) == 3+IO_intValue(fileContent(l),chunkPos,3)+dimPlex+1) then
call DMSetLabelValue(globalMesh,'material',j,IO_intValue(fileContent(l),chunkPos,4),ierr)
CHKERRQ(ierr)
j = j + 1
endif ! count all identifiers to allocate memory and do sanity check
endif ! count all identifiers to allocate memory and do sanity check
endif
enddo
close (FILEUNIT)
call DMClone(globalMesh,geomMesh,ierr)
CHKERRQ(ierr)
else