-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsortnodes.f90
538 lines (489 loc) · 18.6 KB
/
sortnodes.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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
! The code was developed at the Fritz Haber Institute, and
! the intellectual properties and copyright of this file
! are with the Max Planck Society. When you use it, please
! cite R. Gomez-Abal, X. Li, C. Ambrosch-Draxl, M. Scheffler,
! Extended linear tetrahedron method for the calculation of q-dependent
! dynamical response functions, to be published in Comp. Phys. Commun. (2010)
!BOP
!
! !ROUTINE: sortnodes
!
! !INTERFACE:
subroutine sortnodes
! !DESCRIPTION:
! This subroutine sort the nodes of each region so that it can be devided
! into tetrahedron in order. For the case of nnod=4, it is already done.
! For nnod=5, we devide it into two tetrahedrons with index(inod,1:2) indicates
! the order of the node in the tetrahedron. For example, if index(inod,2)=1,
! we should take this node as the first node in the second tetrahedron.
! For nnod=6, we can devide it into three tetrahedron, the nodes should be ordered
! in a way that 1,2,3,4 form a tetrahedron, 2,,3,4,5 form a tetrahedron and
! 3,4,5,6 form the other one. These three together make up the prism.
! For nnod=7, we can devide it into two penta which are ordered in the way as
! nnod=5. For nnod=8, we can devide it into two prism which are ordered in the
! way as nnod=6 case.
!
! !USES:
use polyhedron
! !LOCAL VARIABLES:
implicit none
integer(1) :: ibit, inod, ip, iind
integer(4) :: is, it, i, iq1
integer(1) :: ibt(3)
integer(1) :: it1, it2, is1
integer(1), dimension(6) :: triangle
integer(1), dimension(6) :: square
integer(1), dimension(2) :: penta
integer(4), dimension(0:5) :: spl
integer(1) :: nt, signbit, signbita,signbitb,signnod,signnodb
integer(1), dimension(6) :: sigtri
integer(1), parameter :: one=1
integer(1), parameter :: four=4
integer(1), parameter :: five=5
! !INTRINSIC ROUTINES:
intrinsic btest
! !REVISION HISTORY:
!
! Created 23rd. April 2004 by RGA, last revised by XZL on Dec 14th, 2004
!
!EOP
!BOC
spl(0:5)=0
it=0
is=0
ip=0
select case(nnod)
case(5)
allocate(index(5,1))
!--------------------------------------------------------------------
! finding how many triangles and squares to form the region
! begin
!--------------------------------------------------------------------
do ibit=0,5 ! here we use the bit to represent the six planes
do inod=1,5 ! inod means each node
nt=ntype(inod)
if(btest(nt,ibit))spl(ibit)=spl(ibit)+1
enddo
select case(spl(ibit))
case(3) ! for one plane, if there are 3 nodes on it.
it=it+1
triangle(it)=ibit
case(4) ! for one plane, if there are 4 nodes on it.
is=is+1
square(is)=ibit
signbit=ibit
end select
enddo
!--------------------------------------------------------------------
! finding how many triangles and squares to form the region
! end
!--------------------------------------------------------------------
index(1:5,1)=0
if(is.ne.0) then ! the case when there is one node
! out of one surface while the other
! four in.
!--------------------------------------------------------------------
! When the region is formed by 4 triangles and one square, begin
!--------------------------------------------------------------------
is1=1
do inod=1,5
if(btest(ntype(inod),triangle(1))) then
if(.not.(btest(ntype(inod),signbit))) then
index(inod,1)=2
else
index(inod,1)=is1
is1=is1+2
signnod=inod
endif
else
continue
endif
enddo
do i=2,4
if(btest(ntype(signnod),triangle(i)))signbit=triangle(i)
enddo
do inod=1,5
if(index(inod,1).eq.0) then
if(btest(ntype(inod),signbit)) then
index(inod,1)=5
else
index(inod,1)=4
endif
else
continue
endif
enddo
!-------------------------------------------------------------------------
! when the region is formed by 4 triangles and one square, end
!--------------------------------------------------------------------------
else ! for the case when there are 3 nodes in
! each surface.
!-------------------------------------------------------------------------
! when the region is formed by 6 triangles, begin
!--------------------------------------------------------------------------
do inod=1,5
signbit=0
do ibit=0,5
if(btest(ntype(inod),ibit))signbit=signbit+1
enddo
it1=1
it2=1
if(signbit.eq.3) then
index(inod,1)=1+(it1-1)*4
it1=it1+1
else
index(inod,1)=1+it2
it2=it2+1
endif
enddo
!-------------------------------------------------------------------------
! when the region is formed by 6 triangles, end
!--------------------------------------------------------------------------
endif
case(6)
allocate(index(6,1))
index(1:6,1)=0
!--------------------------------------------------------------------
! finding how many triangles and squares to form the region
! begin
!--------------------------------------------------------------------
do ibit=0,5
do inod=1,6
nt=ntype(inod)
if(btest(nt,ibit))spl(ibit)=spl(ibit)+1
enddo
select case(spl(ibit))
case(3)
it=it+1
triangle(it)=ibit
case(4)
is=is+1
square(is)=ibit
end select
enddo
!--------------------------------------------------------------------
! finding how many triangles and squares to form the region
! end
!--------------------------------------------------------------------
select case(is)
case(2)
!-------------------------------------------------------------------------
! when the region is formed by 4 triangles and 2 squares, begin
!-------------------------------------------------------------------------
it=1
do inod=1,6
if(btest(ntype(inod),square(1)).and. &
& btest(ntype(inod),square(2))) then
index(inod,1)=2+(it-1)*3
if(it.eq.1) signnod=inod
if(it.eq.2) signnodb=inod
it=it+1
else
continue
endif
enddo
sigtri(1:6)=0
do inod=1,6
do it=1,4
if(btest(ntype(inod),triangle(it))) then
sigtri(inod)=sigtri(inod)+1
else
continue
endif
enddo
enddo
do it=1,4
if(btest(ntype(signnod),triangle(it)))signbita=it
if(btest(ntype(signnodb),triangle(it)))signbitb=it
enddo
do inod=1,6
if(index(inod,1).eq.0) then
if((sigtri(inod).eq.3).and.btest(ntype(inod),triangle(signbita)))index(inod,1)=4
if((sigtri(inod).eq.2).and.btest(ntype(inod),triangle(signbita)))index(inod,1)=1
if((sigtri(inod).eq.3).and.btest(ntype(inod),triangle(signbitb)))index(inod,1)=3
if((sigtri(inod).eq.2).and.btest(ntype(inod),triangle(signbitb)))index(inod,1)=6
else
continue
endif
enddo
!-------------------------------------------------------------------------
! when the region is formed by 4 triangles and 2 squares, end
!-------------------------------------------------------------------------
case(3)
do inod=1,6
do it=1,2
if(btest(ntype(inod),triangle(it)))then
if(btest(ntype(inod),square(1)).and. &
& btest(ntype(inod),square(2))) then
index(inod,1)=1+3*(it-1)
else if(btest(ntype(inod),square(1))) then
index(inod,1)=2+3*(it-1)
else if(btest(ntype(inod),square(2))) then
index(inod,1)=3+3*(it-1)
else
stop 'error in sortnodes, nnod=6'
endif
else
continue
endif
enddo
enddo
end select
case(7)
allocate(index(7,2))
!-----------------------------------------------------------------------
! Finding how the region is formed, begin
!-----------------------------------------------------------------------
index(1:7,1:2)=0
do ibit=0,5
do inod=1,7
if(btest(ntype(inod),ibit))spl(ibit)=spl(ibit)+1
enddo
select case(spl(ibit))
case(3)
it=it+1
triangle(it)=ibit
case(4)
is=is+1
square(is)=ibit
case(5)
ip=ip+1
penta(ip)=ibit
end select
enddo
write(90,'(a7,3i4)')'istp = ',it,is,ip
!-----------------------------------------------------------------------
! Finding how the region is formed, end
!-----------------------------------------------------------------------
select case(it)
case(2) ! when it is formed by 2 triangles and 4 squares
!-----------------------------------------------------------------------
! When the region is formed by 2 triangles and 4 squares, begin
!-----------------------------------------------------------------------
select case(is)
case(4) ! 2 triangles and 4 squares
do inod=1,7
if(btest(ntype(inod),triangle(1)).and. &
& btest(ntype(inod),triangle(2))) then
index(inod,1:2)=2
signnod=inod
else
continue
endif
enddo
is1=0
do ibit=0,5
if(btest(ntype(signnod),ibit).and. &
& (spl(ibit).eq.4).and.(is1.eq.0)) then
signbita=ibit
is1=is1+1
else if(btest(ntype(signnod),ibit).and. &
& (spl(ibit).eq.4)) then
signbitb=ibit
else
continue
endif
enddo
do inod=1,7
if(inod.ne.signnod) then
if(btest(ntype(inod),triangle(1)).and. &
& btest(ntype(inod),signbita)) then
index(inod,1)=1
else if(btest(ntype(inod),triangle(1)).and. &
& btest(ntype(inod),signbitb)) then
index(inod,1)=3
else if(btest(ntype(inod),triangle(2)).and. &
& btest(ntype(inod),signbita)) then
index(inod,2)=1
else if(btest(ntype(inod),triangle(2)).and. &
& btest(ntype(inod),signbitb)) then
index(inod,2)=3
else if(btest(ntype(inod),signbita)) then
index(inod,1:2)=4
else
index(inod,1:2)=5
endif
else
continue
endif
enddo
case default
print*, it, is, ip
stop 'error in sortnodes.f90, inod=7 and it=2'
end select
!-----------------------------------------------------------------------
! When the region is formed by 2 triangles and 4 squares, end
!-----------------------------------------------------------------------
case(3) ! when it is made up of 3 triangles, 2 squares and 1 penta
!--------------------------------------------------------------------------
! When the region is formed by 3 triangles and 2 squares and 1 penta, begin
!--------------------------------------------------------------------------
index(1:7,1:2)=0
do inod=1,7
ibit=0
do it1=1,3
if(btest(ntype(inod),triangle(it1)))ibit=ibit+1
enddo
if(btest(ntype(inod),penta(1))) then
if(ibit.eq.2)index(inod,1)=1
else
if(ibit.eq.2) then
index(inod,1)=2
index(inod,2)=1
else
index(inod,2)=4
iind=inod
endif
endif
enddo
do it2=1,3
if(btest(ntype(iind),triangle(it2)))signbita=triangle(it2)
enddo
do inod=1,7
if((index(inod,1).eq.0).and.(index(inod,2).eq.0)) then
if(btest(ntype(inod),signbita).and. &
& btest(ntype(inod),square(1))) then
index(inod,2)=5
else if(btest(ntype(inod),signbita).and. &
& btest(ntype(inod),square(2))) then
index(inod,1)=5
index(inod,2)=2
else if(btest(ntype(inod),square(1))) then
index(inod,1)=4
index(inod,2)=3
else
index(inod,1)=3
endif
else
continue
endif
enddo
case default
print*, it, is, ip
stop 'error in sortnodes.f90, inod=7'
end select
!--------------------------------------------------------------------------
! When the region is formed by 3 triangles and 2 squares and 1 penta, begin
!--------------------------------------------------------------------------
case(8)
allocate(index(8,2))
!--------------------------------------------------------------------------
! Finding how the region is formed, begin
!--------------------------------------------------------------------------
do ibit=0,5
do inod=1,8
nt=ntype(inod)
if(btest(nt,ibit))spl(ibit)=spl(ibit)+1
enddo
select case(spl(ibit))
case(3)
it=it+1
triangle(it)=ibit
case(4)
is=is+1
square(is)=ibit
case(5)
ip=ip+1
penta(ip)=ibit
end select
enddo
!--------------------------------------------------------------------------
! Finding how the region is formed, end
!--------------------------------------------------------------------------
index(1:8,1:2)=0
! write(90,*)'itsp =',it, is,ip
select case(is)
case(2) ! then it is made up of 2 squares, 2 triangles and 2 penta
!--------------------------------------------------------------------------
! When the region is formed by 2 triangles and 2 squares and 2 penta, begin
!--------------------------------------------------------------------------
do inod=1,8
do it1=1,2
if(btest(ntype(inod),triangle(it1))) then
if(btest(ntype(inod),penta(1)).and. &
& btest(ntype(inod),penta(2))) then
index(inod,1)=1+(it1-1)*3
else if(btest(ntype(inod),penta(1))) then
index(inod,1)=2+(it1-1)*3
else if(btest(ntype(inod),penta(2))) then
index(inod,1)=3+(it1-1)*3
else
continue
endif
else
continue
endif
enddo
do iq1=1,2
if(btest(ntype(inod),penta(iq1))) then
if(btest(ntype(inod),square(1)).and. &
& btest(ntype(inod),square(2))) then
index(inod,2)=1+(iq1-1)*3
else if(btest(ntype(inod),square(1))) then
index(inod,2)=2+(iq1-1)*3
else if(btest(ntype(inod),square(2))) then
index(inod,2)=3+(iq1-1)*3
else
continue
endif
else
continue
endif
enddo
enddo
!--------------------------------------------------------------------------
! When the region is formed by 2 triangles and 2 squares and 2 penta, end
!--------------------------------------------------------------------------
case(6) ! when it is made up of 6 squares
!--------------------------------------------------------------------------
! When the region is formed by 4 squares, begin
!--------------------------------------------------------------------------
is1=0
! choose the node 1 to be 1 in the first prism and it is not in the
! second (node 1:0)
index(1,1)=1
index(1,2)=0
! set the three planes to which node 1 belongs as 1,2,3 in order of
! appearence
do ibit=0,5
if(btest(ntype(1),ibit)) then
is1=is1+1
ibt(is1)=ibit
endif
enddo
! the rest of the nodes
do inod=2,8
if(btest(ntype(inod),ibt(1)))then
if(btest(ntype(inod),ibt(2)))then
index(inod,1:2)=2 ! node 2:2= intersection of plane 1 and 2
else if(btest(ntype(inod),ibt(3)))then
index(inod,1:2)=3 ! node 3:3= intersection of plane 1 and 4
else
index(inod,1)=0 ! node 0:1= the remaining node of plane 1
index(inod,2)=1
endif
else if(btest(ntype(inod),ibt(2)))then
if(btest(ntype(inod),ibt(3)))then
index(inod,1)=4 ! node 4:0= intersection of plane 2 and 3
index(inod,2)=0
else
index(inod,1:2)=5 ! node 5:5= the remaining node of plane 2
endif
else
if(btest(ntype(inod),ibt(3)))then
index(inod,1:2)=6 ! node 6:6= the remaining node of plane 3
else
index(inod,1)=0 ! node 0:4= the node that doesn´t belong
index(inod,2)=4 ! to any of the planes 1,2 or 3
endif
endif
enddo
!--------------------------------------------------------------------------
! When the region is formed by 4 squares, end
!--------------------------------------------------------------------------
case default
stop 'error in nnod=8 of sortnodes.f90'
end select
end select
end subroutine sortnodes
!EOC