-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathreadGrid.f90
148 lines (116 loc) · 4.3 KB
/
readGrid.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
!> @file readGrid.f90
!!
!! Input of grid coordinates, elements and boundaries.
!
! *****************************************************************************
!
! (c) J. Blazek, CFD Consulting & Analysis, www.cfd-ca.de
! Created February 25, 2014
! Last modification: May 21, 2014
!
! *****************************************************************************
!
! This program is free software; you can redistribute it and/or
! modify it under the terms of the GNU General Public License
! as published by the Free Software Foundation; either version 2
! of the License, or (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program; if not, write to the Free Software
! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
!
! *****************************************************************************
!> Reads in grid data and boundary segments.
!!
subroutine ReadGrid
use ModFiles
use ModGeometry
use ModInterfaces, only : DummyNodes, ErrorMessage
implicit none
! local variables
integer :: errFlag, i, ib, ibn, ibf, ibegf, iendf, ibegn, iendn
! *****************************************************************************
open(unit=ifGrid, file=fnGrid, status="old", action="read", iostat=errFlag)
if (errFlag /= 0) call ErrorMessage( "cannot open grid file" )
read(ifGrid,"(1X)")
read(ifGrid,"(1X)")
read(ifGrid,"(1X)")
! numbers of physical nodes, triangles and boundary segments
read(ifGrid,*) nndint,ntria,nsegs
! boundary type, no. of boundary faces & nodes, boundary name
allocate( btype(nsegs),stat=errFlag )
if (errFlag /= 0) call ErrorMessage( "cannot allocate memory for btype()" )
allocate( bname(nsegs),stat=errFlag )
if (errFlag /= 0) call ErrorMessage( "cannot allocate memory for bname()" )
allocate( ibound(2,nsegs),stat=errFlag )
if (errFlag /= 0) call ErrorMessage( "cannot allocate memory for ibound()" )
read(ifGrid,"(1X)")
do ib=1,nsegs
read(ifGrid, * ) btype(ib),ibound(1,ib),ibound(2,ib)
read(ifGrid,"(A)") bname(ib)
enddo
nbfaces = ibound(1,nsegs)
nbnodes = ibound(2,nsegs)
! definition of boundary faces / periodic nodes
allocate( bnode(3,nbnodes),stat=errFlag )
if (errFlag /= 0) call ErrorMessage( "cannot allocate memory for bnode()" )
allocate( bface(2,nbfaces),stat=errFlag )
if (errFlag /= 0) call ErrorMessage( "cannot allocate memory for bface()" )
do ibn=1,nbnodes
bnode(1,ibn) = -777
bnode(2,ibn) = -777 ! set in DummyNodes
bnode(3,ibn) = -777 ! set in EdgesFinalize
enddo
do ibf=1,nbfaces
bface(1,ibf) = -777
bface(2,ibf) = -777
enddo
read(ifGrid,"(1X)")
ibegf = 1
ibegn = 1
do ib=1,nsegs
iendf = ibound(1,ib)
iendn = ibound(2,ib)
if (btype(ib)>=700 .and. btype(ib)<800) then ! periodic nodes
do ibn=ibegn,iendn
read(ifGrid,*) bnode(1,ibn),bnode(2,ibn)
enddo
else ! boundary faces
do ibf=ibegf,iendf
read(ifGrid,*) bface(1,ibf),bface(2,ibf)
enddo
endif
ibegf = iendf + 1
ibegn = iendn + 1
enddo
! check boundary faces pointer
do ibf=1,nbfaces
if (bface(1,ibf)<0 .or. bface(2,ibf)<0) then
call ErrorMessage( "array bface() not completely defined" )
endif
enddo
! generate dummy nodes
call DummyNodes
! grid nodes
allocate( x(nnodes),stat=errFlag )
if (errFlag /= 0) call ErrorMessage( "cannot allocate memory for x()" )
allocate( y(nnodes),stat=errFlag )
if (errFlag /= 0) call ErrorMessage( "cannot allocate memory for y()" )
read(ifGrid,"(1X)")
do i=1,nndint
read(ifGrid,*) x(i),y(i)
enddo
! triangles
allocate( tria(3,ntria),stat=errFlag )
if (errFlag /= 0) call ErrorMessage( "cannot allocate memory for tria()" )
read(ifGrid,"(1X)")
do i=1,ntria
read(ifGrid,*) tria(1,i),tria(2,i),tria(3,i)
enddo
close(unit=ifGrid)
end subroutine ReadGrid