-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvtk_plot_binary.f90
572 lines (430 loc) · 15.8 KB
/
vtk_plot_binary.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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
MODULE vtk_plot
!
! Contains three subroutines to generate .vtk output files.
!
USE start_sparse_kit ! needed for the extract subroutine
!
!==============================================================================
CONTAINS
! vtk_plot_P2 :: scalar + vector fields on P2 grid
! plots the velocity field on the P2 grid stored in 'rr'
!
! vtk_plot_scalar_P2 :: scalar field on P2 grid
! plots a scalar field on the P2 grid stored in 'rr'
!
! vtk_plot_P1 :: scalar field on P1 grid
! plots the pressure field on the P1 grid stored in 'rr_L'
!------------------------------------------------------------------------------
SUBROUTINE vtk_plot_P2 (rr, jj, jj_L, uu, pp, file_name)
!
! Author: Jacopo Canton
! E-mail: [email protected]
! Last revision: 6/10/2013
!
!++++++++ 2D/3D version +++++++++++++++++++++++++++++++++++++++++++++++++++++++
!
! - rr :: coordinates of the nodes of the P2 grid (triangle vertices plus
! midpoints)
! - jj :: connectivity matrix of the P2 grid
! - uu :: a vector field whose values are defined on the P2 nodes
! - pp :: a scalar field whose values are defined on the P1 nodes
!
! - file_name :: a string for the file name
!
IMPLICIT NONE
REAL(KIND=8), DIMENSION(:,:), INTENT(IN) :: rr
INTEGER, DIMENSION(:,:), INTENT(IN) :: jj, jj_L
REAL(KIND=8), DIMENSION(:,:), INTENT(IN) :: uu
REAL(KIND=8), DIMENSION(:), INTENT(IN) :: pp
CHARACTER(*), INTENT(IN) :: file_name
! internal variables
INTEGER :: m
INTEGER :: me, np
INTEGER :: uc
REAL(KIND=8), DIMENSION(SIZE(rr,2)) :: pp_P2
CHARACTER(LEN=128) :: s_buffer
character(1), parameter :: end_rec = char(10) ! end-character for binary-record finalize
me = SIZE(jj, 2) ! number of volume elements
np = SIZE(rr, 2) ! number of P2 nodes
uc = SIZE(uu, 1) ! number of velocity components
WRITE(*,*)
WRITE(*,*) '+++++++++++++++++++++++++++++++++++++'
WRITE(*,*) '--> Plotting ' // trim(file_name) // ' ...'
OPEN( UNIT = 20, &
FILE = file_name, &
FORM = 'unformatted', &
STATUS = 'unknown', &
access = 'SEQUENTIAL', &
action = 'WRITE', &
convert = 'BIG_ENDIAN', &
recordtype = 'STREAM', &
buffered = 'YES')
WRITE(20) '# vtk DataFile Version 3.0'//end_rec
WRITE(20) trim(file_name)//end_rec
WRITE(20) 'BINARY'//end_rec
WRITE(20) 'DATASET UNSTRUCTURED_GRID'//end_rec
WRITE(20) ! jump one line
! nodes coordinates
WRITE(s_buffer, '(a7,i7,a7)') 'POINTS ', np, ' double'
write(20) trim(s_buffer)//end_rec
DO m = 1, np
WRITE(20) rr(1, m), rr(2, m), 0.0
END DO
WRITE(20) ! jump one line
! connectivity matrix
WRITE(s_buffer, '(a6,i7,a1,i7)') 'CELLS ', me, ' ', me*7 ! 7 = number of numbers per row
write(20) trim(s_buffer)//end_rec
DO m = 1, me
WRITE(20) 6, jj(1, m)-1, jj(2, m)-1, jj(3, m)-1, &
jj(6, m)-1, jj(4, m)-1, jj(5, m)-1
END DO
WRITE(20) ! jump one line
! type of cells
WRITE(s_buffer, '(a11,i7)') 'CELL_TYPES ', me
write(20) trim(s_buffer)//end_rec
DO m = 1, me
WRITE(20) '22' ! 22 = P2 triangles
END DO
WRITE(20) ! jump one line
! point data
WRITE(s_buffer, '(a11,i7)') 'POINT_DATA ', np
write(20) trim(s_buffer)//end_rec
! scalar field
CALL plot_inject_p1_p2 (jj_L, jj, pp, pp_P2)
WRITE(s_buffer, '(a)') 'SCALARS p double'
write(20) trim(s_buffer)//end_rec
WRITE(s_buffer, '(a)') 'LOOKUP_TABLE default'
write(20) trim(s_buffer)//end_rec
DO m = 1, np
WRITE(20) pp_P2(m)
END DO
WRITE(20) ! jump one line
! vector field
WRITE(s_buffer, '(a)') 'VECTORS u double'
write(20) trim(s_buffer)//end_rec
IF ( uc == 3 ) THEN
DO m = 1, np
WRITE(20) uu(1, m), uu(2, m), uu(3,m)
END DO
ELSEIF ( uc == 2 ) THEN
DO m = 1, np
WRITE(20) uu(1, m), uu(2, m), '0.0'
END DO
ELSEIF ( uc == 1 ) THEN
DO m = 1, np
WRITE(20) uu(1, m), '0.0 0.0'
END DO
ELSE
! what kind of vectorial field would you like to plot?!?
WRITE(*,*) ' wrong vectorial field dimensions'
WRITE(*,*) ' STOP.'
CALL MPI_ABORT(MPI_COMM_WORLD, mpiErrC, mpiIerr)
END IF
CLOSE(20)
WRITE(*,*) ' Done.'
END SUBROUTINE vtk_plot_P2
!------------------------------------------------------------------------------
SUBROUTINE vtk_plot_scalar_P2 (rr, jj, psi, file_name)
!
! Author: Jacopo Canton
! E-mail: [email protected]
! Last revision: 14/3/2013
!
! - rr :: coordinates of the nodes of the P2 grid (triangle vertices plus
! midpoints)
! - jj :: connectivity matrix of the P2 grid
! - psi :: a scalar field whose values are defined on the P2 nodes
!
! - file_name :: a string for the file name
IMPLICIT NONE
REAL(KIND=8), DIMENSION(:,:), INTENT(IN) :: rr
INTEGER, DIMENSION(:,:), INTENT(IN) :: jj
REAL(KIND=8), DIMENSION(:), INTENT(IN) :: psi
CHARACTER(*), INTENT(IN) :: file_name
INTEGER :: m
INTEGER :: me, np
me = SIZE(jj, 2) ! number of volume elements
np = SIZE(rr, 2) ! number of P2 nodes
WRITE(*,*)
WRITE(*,*) '+++++++++++++++++++++++++++++++++++++'
WRITE(*,*) '--> Plotting ' // trim(file_name) // ' ...'
OPEN( UNIT = 20, FILE = file_name, FORM = 'formatted', STATUS = 'unknown')
WRITE(20, '(a)') '# vtk DataFile Version 3.0'
WRITE(20, '(a)') file_name
WRITE(20, '(a)') 'ASCII'
WRITE(20, '(a)') 'DATASET UNSTRUCTURED_GRID'
WRITE(20, *) ! jump one line
! nodes coordinates
WRITE(20, '(a7,i7,a7)') 'POINTS ', np, ' double'
DO m = 1, np
WRITE(20, '(2(g17.10,1x),g17.10)') rr(1, m), rr(2, m), 0.0
END DO
WRITE(20, *) ! jump one line
! connectivity matrix
WRITE(20, '(a6,i7,a1,i7)') 'CELLS ', me, ' ', me*7 ! 7 = number of numbers per row
DO m = 1, me
WRITE(20, '(i1,1x,5(i7,1x),i7)') 6, jj(1, m)-1, jj(2, m)-1, jj(3, m)-1, &
jj(6, m)-1, jj(4, m)-1, jj(5, m)-1
END DO
WRITE(20, *) ! jump one line
! type of cells
WRITE(20, '(a11,i7)') 'CELL_TYPES ', me
DO m = 1, me
WRITE(20, '(a)') '22' ! 22 = P2 triangles
END DO
WRITE(20, *) ! jump one line
! point data
WRITE(20, '(a11,i7)') 'POINT_DATA ', np
! scalar field
WRITE(20, '(a)') 'SCALARS psi double'
WRITE(20, '(a)') 'LOOKUP_TABLE default'
DO m = 1, np
WRITE(20, '(g17.10)') psi(m)
END DO
WRITE(20, *) ! jump one line
CLOSE(20)
WRITE(*,*) ' Done.'
END SUBROUTINE vtk_plot_scalar_P2
!------------------------------------------------------------------------------
SUBROUTINE vtk_plot_P1 (rr_L, jj_L, pp, file_name)
!
! Author: Jacopo Canton
! Last revision: 13/3/2013
!
! - rr_L :: coordinates of the nodes of the P1 grid (triangle vertices)
! - jj_L :: connectivity matrix of the P1 grid
! - pp :: a scalar field whose values are defined on the P1 nodes
!
! - file_name :: a string for the file name
IMPLICIT NONE
REAL(KIND=8), DIMENSION(:,:), INTENT(IN) :: rr_L
INTEGER, DIMENSION(:,:), INTENT(IN) :: jj_L
REAL(KIND=8), DIMENSION(:), INTENT(IN) :: pp
CHARACTER(*), INTENT(IN) :: file_name
INTEGER :: m
INTEGER :: me, np_L
me = SIZE(jj_L, 2) ! number of volume elements
np_L = SIZE(rr_L, 2) ! number of P1 nodes
WRITE(*,*)
WRITE(*,*) '+++++++++++++++++++++++++++++++++++++'
WRITE(*,*) '--> Plotting ' // trim(file_name) // ' ...'
OPEN( UNIT = 20, FILE = file_name, FORM = 'formatted', STATUS = 'unknown')
WRITE(20, '(a)') '# vtk DataFile Version 3.0'
WRITE(20, '(a)') file_name
WRITE(20, '(a)') 'ASCII'
WRITE(20, '(a)') 'DATASET UNSTRUCTURED_GRID'
WRITE(20, *) ! jump one line
! nodes coordinates
WRITE(20, '(a7,i7,a7)') 'POINTS ', np_L, ' double'
DO m = 1, np_L
WRITE(20, '(2(g17.10,1x),g17.10)') rr_L(1, m), rr_L(2, m), 0.0
END DO
WRITE(20, *) ! jump one line
! connectivity matrix
WRITE(20, '(a6,i7,a1,i7)') 'CELLS ', me, ' ', me*4 ! 4 = number of numbers per row
DO m = 1, me
WRITE(20, '(i1,1x,2(i7,1x),i7)') 3, jj_L(1, m)-1, jj_L(2, m)-1, jj_L(3, m)-1
END DO
WRITE(20, *) ! jump one line
! type of cells
WRITE(20, '(a11,i7)') 'CELL_TYPES ', me
DO m = 1, me
WRITE(20, '(a)') '5' ! 5 = P1 triangles
END DO
WRITE(20, *) ! jump one line
! point data
WRITE(20, '(a11,i7)') 'POINT_DATA ', np_L
! scalar field
WRITE(20, '(a)') 'SCALARS p double'
WRITE(20, '(a)') 'LOOKUP_TABLE default'
DO m = 1, np_L
WRITE(20, '(g17.10)') pp(m)
END DO
CLOSE(20)
WRITE(*,*) ' Done.'
END SUBROUTINE vtk_plot_P1
!------------------------------------------------------------------------------
SUBROUTINE vtk_plot_eigenvectors (rr, jj, eigvecs, file_name)
!
! Author: Jacopo Canton
! E-mail: [email protected]
! Last revision: 21/5/2013
!
!******************************************************************************
!******** 3D version ONLY: the velocity field has 3 components. **************
!******** The declaration of variable u_plot and the actual **************
!******** writing, both marked with asterisks, need to be **************
!******** changed depending on the number of velocity components **************
!******************************************************************************
!
! - rr :: coordinates of the nodes of the P2 grid (triangle vertices plus
! midpoints)
! - jj :: connectivity matrix of the P2 grid
! - eigvecs :: a matrix containing 'nev' eigenvectors, defined on the P2 nodes,
! organized by columns
!
! - file_name :: a string for the file name
!
IMPLICIT NONE
REAL(KIND=8), DIMENSION(:,:), INTENT(IN) :: rr
INTEGER, DIMENSION(:,:), INTENT(IN) :: jj
REAL(KIND=8), DIMENSION(:,:), INTENT(IN) :: eigvecs
CHARACTER(*), INTENT(IN) :: file_name
INTEGER :: m, i
INTEGER :: me, np, nev
REAL(KIND=8), DIMENSION(3,SIZE(rr,2)) :: u_plot
! ^
! |
! This value has to be changed between 2 and 3
! depending on the number of components of the
! velocity field
!******************************************************************
me = SIZE(jj, 2) ! number of volume elements
np = SIZE(rr, 2) ! number of P2 nodes
nev = SIZE(eigvecs,2) ! number of eigenvectors
WRITE(*,*)
WRITE(*,*) '+++++++++++++++++++++++++++++++++++++'
WRITE(*,*) '--> Plotting ' // trim(file_name) // ' ...'
OPEN( UNIT = 20, FILE = file_name, FORM = 'formatted', STATUS = 'unknown')
WRITE(20, '(a)') '# vtk DataFile Version 3.0'
WRITE(20, '(a)') file_name
WRITE(20, '(a)') 'ASCII'
WRITE(20, '(a)') 'DATASET UNSTRUCTURED_GRID'
WRITE(20, *) ! jump one line
! nodes coordinates
WRITE(20, '(a7,i7,a7)') 'POINTS ', np, ' double'
DO m = 1, np
WRITE(20, '(2(g17.10,1x),g17.10)') rr(1, m), rr(2, m), 0.0
END DO
WRITE(20, *) ! jump one line
! connectivity matrix
WRITE(20, '(a6,i7,a1,i7)') 'CELLS ', me, ' ', me*7 ! 7 = number of numbers per row
DO m = 1, me
WRITE(20, '(i1,1x,5(i7,1x),i7)') 6, jj(1, m)-1, jj(2, m)-1, jj(3, m)-1, &
jj(6, m)-1, jj(4, m)-1, jj(5, m)-1
END DO
WRITE(20, *) ! jump one line
! type of cells
WRITE(20, '(a11,i7)') 'CELL_TYPES ', me
DO m = 1, me
WRITE(20, '(a)') '22' ! 22 = P2 triangles
END DO
WRITE(20, *) ! jump one line
! point data
WRITE(20, '(a11,i7)') 'POINT_DATA ', np
! vector fields
DO i = 1, nev
u_plot = 0
CALL extract(eigvecs(:,i), u_plot)
IF ( i < 10 ) THEN
WRITE(20, '(a11,i1,a7)') 'VECTORS eig', i, ' double'
ELSEIF ( i < 100 ) THEN
WRITE(20, '(a11,i2,a7)') 'VECTORS eig', i, ' double'
ELSEIF ( i < 1000 ) THEN
WRITE(20, '(a11,i3,a7)') 'VECTORS eig', i, ' double'
ENDIF
DO m = 1, np
!*********************************************************************
! WRITE(20, '(2(g17.10,1x),a3)') u_plot(1, m), u_plot(2, m), '0.0' ! 2 velocity components
WRITE(20, '(2(g17.10,1x),g17.10)') u_plot(1, m), u_plot(2, m), u_plot(3, m) ! 3 velocity components
!*********************************************************************
END DO
WRITE(20, *) ! jump one line
END DO
CLOSE(20)
WRITE(*,*) ' Done.'
END SUBROUTINE vtk_plot_eigenvectors
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
SUBROUTINE plot_inject_p1_p2 (jj_L, jj_P, pp_L, pp_P)
! Injection from Linear interpolation to Parabolic interpolation
! Vertex nodes of the parabolic triangle are the first three
! nodes of the element
!****************** 2D grid only **********************************************
IMPLICIT NONE
INTEGER, DIMENSION(:,:), INTENT(IN) :: jj_L, jj_P
REAL(KIND=8), DIMENSION(:), INTENT(IN) :: pp_L
REAL(KIND=8), DIMENSION(:), INTENT(OUT) :: pp_P
pp_P(1:SIZE(pp_L)) = pp_L
pp_P(jj_P(4,:)) = (pp_L(jj_L(2,:)) + pp_L(jj_L(3,:)))*0.5
pp_P(jj_P(5,:)) = (pp_L(jj_L(3,:)) + pp_L(jj_L(1,:)))*0.5
pp_P(jj_P(6,:)) = (pp_L(jj_L(1,:)) + pp_L(jj_L(2,:)))*0.5
END SUBROUTINE plot_inject_p1_p2
!==============================================================================
SUBROUTINE vtk_read_P2 (file_name, rr, jj, jj_L, uu)
!
! Author: Jacopo Canton
! E-mail: [email protected]
! Last revision: 5/12/2013
!
!++++++++ 2D/3D version +++++++++++++++++++++++++++++++++++++++++++++++++++++++
!
! - rr :: coordinates of the nodes of the P2 grid (triangle vertices plus
! midpoints)
! - jj :: connectivity matrix of the P2 grid
! - uu :: a vector field whose values are defined on the P2 nodes
! - pp :: a scalar field whose values are defined on the P1 nodes
!
! - file_name :: a string for the file name
!
IMPLICIT NONE
CHARACTER(*), INTENT(IN) :: file_name
REAL(KIND=8), DIMENSION(:,:), INTENT(IN) :: rr
INTEGER, DIMENSION(:,:), INTENT(IN) :: jj, jj_L
REAL(KIND=8), DIMENSION(:,:) :: uu
!REAL(KIND=8), DIMENSION(:) :: pp
! internal variables
INTEGER :: m
INTEGER :: me, np
INTEGER :: uc
!REAL(KIND=8), DIMENSION(SIZE(rr,2)) :: pp_P2
me = SIZE(jj, 2) ! number of volume elements
np = SIZE(rr, 2) ! number of P2 nodes
uc = SIZE(uu, 1) ! number of velocity components
WRITE(*,*)
WRITE(*,*) '+++++++++++++++++++++++++++++++++++++'
WRITE(*,*) '--> Reading ' // trim(file_name) // ' ...'
OPEN( UNIT = 20, FILE = file_name, FORM = 'formatted', STATUS = 'unknown')
READ(20, *)
READ(20, *)
READ(20, *)
READ(20, *)
READ(20, *)
! nodes coordinates
READ(20, *) ! 'POINTS ', np, ' double'
DO m = 1, np
READ(20, *)
END DO
READ(20, *) ! jump one line
! connectivity matrix
READ(20, *) ! 'CELLS ', me, ' ', me*7 ! 7 = number of numbers per row
DO m = 1, me
READ(20, *)
END DO
READ(20, *) ! jump one line
! type of cells
READ(20, *) ! 'CELL_TYPES ', me
DO m = 1, me
READ(20, *) ! '22' ! 22 = P2 triangles
END DO
READ(20, *) ! jump one line
! point data
READ(20, *) ! 'POINT_DATA ', np
! scalar field
READ(20, *) ! 'SCALARS p double'
READ(20, *) ! 'LOOKUP_TABLE default'
DO m = 1, np
READ(20, *) ! pp_P2(m)
END DO
READ(20, *) ! jump one line
! vector field
READ(20, *) ! 'VECTORS u double'
DO m = 1, np
READ(20, *) uu(1, m), uu(2, m), uu(3,m)
END DO
CLOSE(20)
WRITE(*,*) ' Done.'
END SUBROUTINE vtk_read_P2
!------------------------------------------------------------------------------
!==============================================================================
END MODULE vtk_plot