-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.f
248 lines (212 loc) · 8.08 KB
/
test.f
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c *** A program driver to demonstrate the use of the Fortran wrapper of the
c *** Fluent case-file reader library. This code invokes the library to read
c *** a case file. Then, it makes cells by invoking a subroutine to construct
c *** each cell by returning the element's nodes in an array; the node ordering
c *** is specific to my own conventions outlined in my notes.
c ***
c *** Created: IN <nompelis@nobelware.com> 20171006
c *** Last modified: IN <nompelis@nobelware.com> 20191216
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Program main
Implicit None
Character*100 :: fname
Integer(kind=8) :: nno,nel,nfa
Integer(kind=8),allocatable,dimension(:,:) :: ifn,ife,izone
Real*8,allocatable,dimension(:,:) :: x
Integer(kind=4) :: ierr,nz,k
Integer(kind=8) :: n,ifnt(0:4),it
c--- read a Fluent case-file and transfer it to arrays
fname = 'grid.cas'
call inFluent_FortranWrapperInit( trim( fname ), nz, nno, nel, nfa, ierr )
PRINT*,'Result of Init() ierr=',ierr,' nz=',nz
allocate( ifn(0:4,nfa), ife(2,nfa), izone(5,nz),
& x(3,nno), STAT=ierr )
PRINT*,'Result of arrays allocation ierr=',ierr
call inFluent_FortranWrapperFill( izone, ifn, ife, x, ierr )
PRINT*,'Result of Fill() ierr=',ierr
do n = 1,nz
write(*,101) 'ZONE',n,'->',izone(:,n)
enddo
101 Format(a4,1x,i5,1x,a2,1x,4(1x,i9))
call inFluent_FortranWrapperTerm( ierr )
PRINT*,'Result of Term() ierr=',ierr
c--- write a tecplot file with all _faces_ (using "nfa" for no. of elements)
open(unit=10,file='ALL_FACES.dat',status='unknown',form='formatted')
write(10,*) 'variables = x y z'
write(10,*) 'zone T="faces"'
write(10,*) 'NODES=',nno,', ELEMENTS=',nfa
write(10,*) 'ET=QUADRILATERAL'
write(10,*) 'F=FEPOINT'
do n = 1,nno
write(10,*) x(:,n)
enddo
do n = 1,nfa
ifnt(:) = ifn(:,n)
if( ifnt(4) .le. 0 ) ifnt(4) = ifnt(3)
write(10,100) ifnt(1:4)
enddo
100 Format(4(1x,i10))
close(10)
c--- write a tecplot file with all _faces_ (using "nfa" for no. of elements)
open(unit=10,file='FACES.dat',status='unknown',form='formatted')
write(10,*) 'variables = x y z'
do k = 1,nz
if( izone(4,k) .eq. 13 ) then
write(10,*) 'zone T="face group ',k,'"'
write(10,*) 'NODES=',nno,', ELEMENTS=',izone(3,k)
write(10,*) 'ET=QUADRILATERAL'
write(10,*) 'F=FEPOINT'
do n = 1,nno
write(10,*) x(:,n)
enddo
do n = izone(1,k),izone(2,k)
ifnt(:) = ifn(:,n)
if( ifnt(4) .le. 0 ) ifnt(4) = ifnt(3)
write(10,100) ifnt(1:4)
enddo
endif
enddo
close(10)
c--- swap Fluent's convention of cr,cl to mine of left,right (in array "ife")
do n = 1,nfa
it = ife(1,n)
ife(1,n) = ife(2,n)
ife(2,n) = it
enddo
c--- call a subroutine to create cells
call make_cells(nz,nno,nel,nfa,ifn,ife,izone,x)
c--- drop arrays
deallocate( x, ifn, ife, izone )
End
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c *** A subroutine to create cells from arrays adhering to a Fluent case file
c *** format. The routine simply loops over cells and invokes special cell
c *** construction functions but does nothing with the cells formed.
c *** NOTE: At this point in the development process I am testing for tets and
c *** I have a _hardwired_ tet-cell output testing code block.
c ***
c *** Created: IN <nompelis@nobelware.com> 20171006
c *** Last modified: IN <nompelis@nobelware.com> 20191216
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Subroutine make_cells(nz,nno,nel,nfa,ifn,ife,izone,x)
Use inMesh_Elements
Implicit None
Integer(kind=8) :: nno,nel,nfa
Integer(kind=4) :: nz
Integer(kind=8),dimension(0:4,nfa) :: ifn
Integer(kind=8),dimension(2,nfa) :: ife
Integer(kind=8),dimension(5,nz) :: izone
Real*8,dimension(3,nno) :: x
Integer(kind=4) :: ierr
Integer(kind=8),allocatable,dimension(:,:) :: ief,ien
Integer(kind=8) :: i,j,k
Integer(kind=8) :: ntri,nqua
Integer(kind=8) :: ieno(0:8),iefo(0:6)
Logical, parameter :: itest = .TRUE.
PRINT*,'Number of cells:',nel
allocate(ief(0:6,nel), ien(0:8,nel), STAT=ierr)
IF( itest ) THEN
c--- write a tecplot file with all cells; first put the nodes
c--- THIS IS FOR DEVELOPMENT TESTING PURPOSES
open(unit=10,file='CELLS.dat',status='unknown',form='formatted')
write(10,*) 'variables = x y z'
write(10,*) 'zone T="Tetrahedra"'
write(10,*) 'NODES=',nno,', ELEMENTS=',nel
write(10,*) 'ET=BRICK'
write(10,*) 'F=FEPOINT'
do i = 1,nno
write(10,*) x(:,i)
enddo
ENDIF
c--- initialize (face-neighbours / nodes) arrays
do i = 1,nel
ief(:,i) = 0
ien(:,i) = 0
enddo
c--- form list of surfaces bounding each element
do j = 1,nfa
i = ife(1,j)
if( i .gt. 0 ) then
ief(0,i) = ief(0,i) + 1
ief( ief(0,i) ,i) = j
endif
i = ife(2,j)
if( i .gt. 0 ) then
ief(0,i) = ief(0,i) + 1
ief( ief(0,i) ,i) = j
endif
enddo
c do i = 1,nel
c write(*,100) ief(:,i)
c enddo
c100 Format(7(1x,i6))
c--- form individual volume elements (cells) from surface elements
do i = 1,nel
ntri = 0
nqua = 0
do k = 1,ief(0,i)
if( ifn(0, ief(k,i) ) .eq. 3 ) ntri = ntri + 1
if( ifn(0, ief(k,i) ) .eq. 4 ) nqua = nqua + 1
enddo
if( ntri+nqua .lt. 4 .OR. ntri+nqua .gt. 6 ) then
PRINT*,'Problematic element! (one) i=',i
PRINT*,'ntri=',ntri,'nqua=',nqua
STOP
endif
iefo(:) = 0
if( ntri .eq. 4 .AND. nqua .eq. 0 ) then
call inMesh_Elements_FormTetrahedronFromFaces(
& nfa, ifn, ife, i, ief(0,i),
& ieno, iefo, ierr )
c--- modify faces-of-element and nodes-of-element array
ien(:,i) = ieno(:)
ief(:,i) = iefo(:)
c--- modify nodes to plot as a "brick" element
ieno(5:8) = ieno(4)
ieno(4) = ieno(3)
else if( ntri .eq. 4 .AND. nqua .eq. 1 ) then
call inMesh_Elements_FormPyramidFromFaces(
& nfa, ifn, ife, i, ief(0,i),
& ieno, iefo, ierr )
c--- modify faces-of-element and nodes-of-element array
ien(:,i) = ieno(:)
ief(:,i) = iefo(:)
c--- modify nodes to plot as a "brick" element
ieno(6:8) = ieno(5)
else if( ntri .eq. 2 .AND. nqua .eq. 3 ) then
call inMesh_Elements_FormWedgeFromFaces(
& nfa, ifn, ife, i, ief(0,i),
& ieno, iefo, ierr )
c--- modify faces-of-element and nodes-of-element array
ien(:,i) = ieno(:)
ief(:,i) = iefo(:)
c--- modify nodes to plot as a "brick" element
ieno(7:8) = ieno(6)
ieno(6) = ieno(5)
ieno(5) = ieno(4)
ieno(4) = ieno(3)
else if( ntri .eq. 0 .AND. nqua .eq. 6 ) then
call inMesh_Elements_FormBrickFromFaces(
& nfa, ifn, ife, i, ief(0,i),
& ieno, iefo, ierr )
c--- modify faces-of-element and nodes-of-element array
ien(:,i) = ieno(:)
ief(:,i) = iefo(:)
else
PRINT*,'Problematic element! (two) i=',i
PRINT*,'ntri=',ntri,'nqua=',nqua
STOP
endif
IF( itest ) THEN
c--- dump element node-connectivity to the file; this is not generic...
c--- THIS IS FOR DEVELOPMENT TESTING PURPOSES
write(10,*) ieno(1:8)
ENDIF
enddo
IF( itest ) THEN
c--- close the file; THIS IS FOR DEVELOPMENT TESTING PURPOSES
close(10)
ENDIF
deallocate( ien, ief )
End subroutine