From 830b05005ffd6f1b2bdcf4f04618a6d6bdf89c96 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 Jan 2020 19:56:30 +0100 Subject: [PATCH] read file only once --- src/IO.f90 | 18 ------------------ src/config.f90 | 2 +- src/mesh_FEM.f90 | 43 ++++++++++++++++--------------------------- 3 files changed, 17 insertions(+), 46 deletions(-) diff --git a/src/IO.f90 b/src/IO.f90 index e3b2db305..40e32b8cd 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -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 diff --git a/src/config.f90 b/src/config.f90 index cffa9f644..18f07d4d1 100644 --- a/src/config.f90 +++ b/src/config.f90 @@ -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 diff --git a/src/mesh_FEM.f90 b/src/mesh_FEM.f90 index ce754d330..cc3d4c6eb 100644 --- a/src/mesh_FEM.f90 +++ b/src/mesh_FEM.f90 @@ -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