1 | include(dom.inc)
2 | ! ===============================================================
3 | ! Copyright (c) CERFACS (all rights reserved)
4 | ! ===============================================================
5 |
6 |
7 | ! ================================================================
8 | ! ================================================================
9 | module avbp_conn
10 |
11 | implicit none
12 |
13 | character*80 connfile
14 |
15 | DOM_INT, parameter :: conn_maxtype = 8
16 |
17 | DOM_INT, dimension(:),allocatable :: ielno
18 | DOM_INT, dimension(1:8) :: nclength
19 | DOM_INT, dimension(1:8) :: ncbegin
20 | DOM_INT, dimension(1:8) :: ncbeg
21 | DOM_INT, dimension(1:8) :: ncvert
22 | DOM_INT, dimension(1:2,1:8) :: ieltype
23 | DOM_INT conn_ndim, &
24 | & conn_nblock, &
25 | & conn_ntcell, &
26 | & conn_ndum, &
27 | & conn_ntvert
28 |
29 | logical :: conn_itexists = .false.
30 | logical :: conn_show = .true.
31 |
32 | data ieltype / 1,3, 2,4, 3,4, 4,5, 5,6, 6,8, &
33 | & 7,5, 8,0 /
34 |
35 | contains
36 | ! ================================================================
37 |
38 |
39 | ! ================================================================
40 | subroutine destroyconnmemory
41 |
42 | if(allocated(ielno)) deallocate(ielno)
43 |
44 | end subroutine destroyconnmemory
45 | ! ================================================================
46 |
47 |
48 | ! ================================================================
49 | subroutine getconninfo
50 |
51 | implicit none
52 | DOM_INT n
53 |
54 | inquire(file=connfile,exist=conn_itexists)
55 |
56 | if(conn_itexists) then
57 | open( unit=2, file=connfile, form='unformatted' )
58 |
59 | read(2) conn_nblock, conn_ntcell, conn_ndum
60 |
61 | close(2)
62 | else
63 | n = len_trim(connfile)
64 | write(*,*) ' could not find the file ',connfile(1:n)
65 | endif
66 |
67 | end subroutine getconninfo
68 | ! ================================================================
69 |
70 |
71 | ! ================================================================
72 | subroutine readconn
73 | !
74 | ! -----------------------------------
75 | ! Read in the connectivity
76 | ! -----------------------------------
77 | !
78 | ! Since we have no idea about the number of vertices
79 | ! per cell we read the connectivity file twice,
80 | ! once to count the number of cells and their vertices,
81 | ! and a second time to read the pointers.
82 |
83 | implicit none
84 | DOM_INT n
85 | DOM_INT ndcell,neltype,nvert,ncbegin0,nclength0
86 | DOM_INT nlen,nbeg
87 | DOM_INT iel,k,startn,endn
88 | DOM_INT dummysize
89 | DOM_INT, dimension(:),allocatable :: intdummy
90 |
91 | ! -------------------------------------------
92 | ! Read in the elements to count them
93 | ! -------------------------------------------
94 |
95 | dummysize = 10000
96 |
97 | inquire(file=connfile,exist=conn_itexists)
98 |
99 | if ((connfile.ne.'nofile').AND.conn_itexists) then
100 |
101 | n = len_trim(connfile)
102 | if (conn_show) then
103 | write(*,*) ' >>>> Reading connectivity file ',connfile(1:n)
104 | end if
105 |
106 | open( unit=2, file=connfile, form='unformatted' )
107 |
108 | if(allocated(intdummy)) then
109 | deallocate(intdummy)
110 | endif
111 |
112 | allocate(intdummy(1:dummysize))
113 |
114 | read(2) conn_nblock, conn_ntcell, conn_ndum
115 |
116 | nbeg = 0
117 | conn_ntvert = 0
118 |
119 | do iel=1,conn_maxtype
120 | nclength(iel) = 0
121 | end do
122 |
123 | do k=1,conn_ndum+2
124 | read(2) ndcell, neltype
125 |
126 | do iel=1,neltype
127 | read(2) nvert,ncbegin0,nclength0
128 | ncvert(iel) = nvert
129 | ncbegin(iel) = ncbegin0
130 | nclength(iel) = nclength0
131 | nlen = nclength0*nvert
132 | conn_ntvert = conn_ntvert+nlen
133 |
134 | if(nlen.GE.dummysize) then
135 | if(allocated(intdummy)) then
136 | deallocate(intdummy)
137 | endif
138 | dummysize = nlen + 1
139 | allocate(intdummy(1:dummysize))
140 | endif
141 |
142 | read(2) (intdummy(n),n=1,nlen)
143 |
144 | nbeg = nbeg+nlen
145 | end do
146 | end do
147 |
148 | if(allocated(intdummy)) then
149 | deallocate(intdummy)
150 | endif
151 |
152 | close(2)
153 |
154 | !
155 | ! ------------------------------------------------
156 | ! Allocate sufficient memory for the vertices
157 | ! ------------------------------------------------
158 | !
159 | if(allocated(ielno)) then
160 | deallocate(ielno)
161 | endif
162 |
163 | allocate(ielno(1:conn_ntvert))
164 | !
165 | ! ------------------------------------------------
166 | ! Read in the elements to place them into an array
167 | ! ------------------------------------------------
168 | !
169 |
170 | open( unit=2, file=connfile, form='unformatted' )
171 |
172 | read(2) conn_nblock, conn_ntcell, conn_ndum
173 |
174 | nbeg = 0
175 | conn_ntvert = 0
176 |
177 | do iel=1,conn_maxtype
178 | nclength(iel) = 0
179 | end do
180 |
181 | do k=1,conn_ndum+2
182 | read(2) ndcell, neltype
183 |
184 | do iel=1,neltype
185 | read(2) nvert,ncbegin0,nclength0
186 | nlen = nclength0*nvert
187 | conn_ntvert = conn_ntvert+nlen
188 |
189 |
190 | if ( conn_ndim.eq.2 .and. nvert.eq.3 ) then
191 | nclength(1) = nclength0
192 | ncvert(1) = nvert
193 | ncbegin(1) = ncbegin0
194 | ncbeg(1) = nbeg
195 | else if ( conn_ndim.eq.2 .and. nvert.eq.4 ) then
196 | nclength(2) = nclength0
197 | ncvert(2) = nvert
198 | ncbegin(2) = ncbegin0
199 | ncbeg(2) = nbeg
200 | else if ( conn_ndim.eq.3 .and. nvert.eq.4 ) then
201 | nclength(3) = nclength0
202 | ncvert(3) = nvert
203 | ncbegin(3) = ncbegin0
204 | ncbeg(3) = nbeg
205 | else if ( conn_ndim.eq.3 .and. nvert.eq.5 ) then
206 | nclength(4) = nclength0
207 | ncvert(4) = nvert
208 | ncbegin(4) = ncbegin0
209 | ncbeg(4) = nbeg
210 | else if ( conn_ndim.eq.3 .and. nvert.eq.6 ) then
211 | nclength(5) = nclength0
212 | ncvert(5) = nvert
213 | ncbegin(5) = ncbegin0
214 | ncbeg(5) = nbeg
215 | else if ( conn_ndim.eq.3 .and. nvert.eq.8 ) then
216 | nclength(6) = nclength0
217 | ncvert(6) = nvert
218 | ncbegin(6) = ncbegin0
219 | ncbeg(6) = nbeg
220 | endif
221 |
222 | read(2) (ielno(n),n=nbeg+1,nbeg+nlen)
223 |
224 | nbeg = nbeg+nlen
225 | end do
226 | end do
227 |
228 | close(2)
229 |
230 | else
231 | n = len_trim(connfile)
232 | write(*,*) ' could not find the file ',connfile(1:n)
233 | endif
234 |
235 | if(allocated(intdummy)) then
236 | deallocate(intdummy)
237 | endif
238 |
239 | end subroutine readconn
240 | ! ================================================================
241 |
242 |
243 | end module avbp_conn
244 | ! ================================================================
245 | ! ================================================================