read file only once

This commit is contained in:
Martin Diehl 2020-01-25 10:58:04 +01:00
parent ddeebc189a
commit a2e4160e61
1 changed files with 14 additions and 19 deletions

View File

@ -40,7 +40,6 @@ module mesh
mesh_init, & mesh_init, &
mesh_FEasCP mesh_FEasCP
contains contains
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
@ -207,10 +206,9 @@ subroutine inputRead(elem,node0_elem,connectivity_elem,microstructureAt,homogeni
call inputRead_NnodesAndElements(nNodes,nElems,& call inputRead_NnodesAndElements(nNodes,nElems,&
inputFile) inputFile)
call IO_open_inputFile(FILEUNIT) ! ToDo: It would be better to use fileContent
call inputRead_mapElemSets(nameElemSet,mapElemSet,& call inputRead_mapElemSets(nameElemSet,mapElemSet,&
FILEUNIT,inputFile) inputFile)
call inputRead_elemType(elem, & call inputRead_elemType(elem, &
nElems,inputFile) nElems,inputFile)
@ -227,6 +225,7 @@ subroutine inputRead(elem,node0_elem,connectivity_elem,microstructureAt,homogeni
connectivity_elem = inputRead_connectivityElem(nElems,elem%nNodes,inputFile) connectivity_elem = inputRead_connectivityElem(nElems,elem%nNodes,inputFile)
call IO_open_inputFile(FILEUNIT) ! ToDo: It would be better to use fileContent
call inputRead_microstructureAndHomogenization(microstructureAt,homogenizationAt, & call inputRead_microstructureAndHomogenization(microstructureAt,homogenizationAt, &
nElems,elem%nNodes,nameElemSet,mapElemSet,& nElems,elem%nNodes,nameElemSet,mapElemSet,&
initialcondTableStyle,FILEUNIT) initialcondTableStyle,FILEUNIT)
@ -395,16 +394,15 @@ end subroutine inputRead_NelemSets
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief map element sets !> @brief map element sets
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
subroutine inputRead_mapElemSets(nameElemSet,mapElemSet,fileUnit,fileContent) subroutine inputRead_mapElemSets(nameElemSet,mapElemSet,&
fileContent)
character(len=64), dimension(:), allocatable, intent(out) :: nameElemSet character(len=64), dimension(:), allocatable, intent(out) :: nameElemSet
integer, dimension(:,:), allocatable, intent(out) :: mapElemSet integer, dimension(:,:), allocatable, intent(out) :: mapElemSet
integer, intent(in) :: fileUnit character(len=*), dimension(:), intent(in) :: fileContent !< file content, separated per lines
character(len=*), dimension(:), intent(in) :: fileContent !< file content, separated per lines
integer, allocatable, dimension(:) :: chunkPos integer, allocatable, dimension(:) :: chunkPos
character(len=300) :: line integer :: elemSet, NelemSets, maxNelemInSet,l
integer :: elemSet, NelemSets, maxNelemInSet
call inputRead_NelemSets(NelemSets,maxNelemInSet,fileContent) call inputRead_NelemSets(NelemSets,maxNelemInSet,fileContent)
@ -412,19 +410,17 @@ subroutine inputRead_mapElemSets(nameElemSet,mapElemSet,fileUnit,fileContent)
allocate(mapElemSet(1+maxNelemInSet,NelemSets),source=0) allocate(mapElemSet(1+maxNelemInSet,NelemSets),source=0)
elemSet = 0 elemSet = 0
rewind(fileUnit) do l = 1, size(fileContent)
do chunkPos = IO_stringPos(fileContent(l))
read (fileUnit,'(a)',END=620) line if( (IO_lc(IO_stringValue(fileContent(l),chunkPos,1)) == 'define' ) .and. &
chunkPos = IO_stringPos(line) (IO_lc(IO_stringValue(fileContent(l),chunkPos,2)) == 'element' ) ) then
if( (IO_lc(IO_stringValue(line,chunkPos,1)) == 'define' ) .and. &
(IO_lc(IO_stringValue(line,chunkPos,2)) == 'element' ) ) then
elemSet = elemSet+1 elemSet = elemSet+1
nameElemSet(elemSet) = trim(IO_stringValue(line,chunkPos,4)) nameElemSet(elemSet) = trim(IO_stringValue(fileContent(l),chunkPos,4))
mapElemSet(:,elemSet) = IO_continuousIntValues(fileUnit,size(mapElemSet,1)-1,nameElemSet,mapElemSet,size(nameElemSet)) mapElemSet(:,elemSet) = continuousIntValues(fileContent(l+1:),size(mapElemSet,1)-1,nameElemSet,mapElemSet,size(nameElemSet))
endif endif
enddo enddo
620 end subroutine inputRead_mapElemSets end subroutine inputRead_mapElemSets
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
@ -1095,7 +1091,6 @@ end function mesh_FEasCP
!> @brief return integer list corresponding to items in consecutive lines. !> @brief return integer list corresponding to items in consecutive lines.
!! First integer in array is counter !! First integer in array is counter
!> @details ints concatenated by "c" as last char, range of a "to" b, or named set !> @details ints concatenated by "c" as last char, range of a "to" b, or named set
! TODO: needs to report the numer of lines read
! REMARK: should replace IO_continuousIntValues ! REMARK: should replace IO_continuousIntValues
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
function continuousIntValues(fileContent,maxN,lookupName,lookupMap,lookupMaxN) function continuousIntValues(fileContent,maxN,lookupName,lookupMap,lookupMaxN)
@ -1121,7 +1116,7 @@ function continuousIntValues(fileContent,maxN,lookupName,lookupMap,lookupMaxN)
exit exit
elseif (verify(IO_stringValue(fileContent(l),chunkPos,1),'0123456789') > 0) then ! a non-int, i.e. set name elseif (verify(IO_stringValue(fileContent(l),chunkPos,1),'0123456789') > 0) then ! a non-int, i.e. set name
do i = 1, lookupMaxN ! loop over known set names do i = 1, lookupMaxN ! loop over known set names
if (IO_stringValue(fileContent(l),chunkPos,1) == lookupName(i)) then ! found matching name if (IO_stringValue(fileContent(l),chunkPos,1) == lookupName(i)) then ! found matching name
continuousIntValues = lookupMap(:,i) ! return resp. entity list continuousIntValues = lookupMap(:,i) ! return resp. entity list
exit exit
endif endif