Skip to content

Commit 72430ec

Browse files
committed
adds vtk write routine
1 parent 04456d6 commit 72430ec

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

src/shared/write_VTK_file.f90

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,10 +1474,108 @@ end subroutine write_VTK_movie_data_elemental
14741474
! close(IOUT_VTK)
14751475
!
14761476
! end subroutine write_VTK_movie_data_binary
1477+
14771478
!
1479+
!-------------------------------------------------------------------------------------------------
14781480
!
1481+
1482+
subroutine write_VTK_wavefield(nspec,nglob,xstore,ystore,zstore,ibool, &
1483+
field,prname_file)
1484+
1485+
use constants, only: CUSTOM_REAL,MAX_STRING_LEN,IOUT_VTK,NDIM,NGLLX,NGLLY,NGLLZ
1486+
1487+
implicit none
1488+
1489+
integer,intent(in) :: nspec,nglob
1490+
1491+
! global coordinates
1492+
integer, dimension(NGLLX,NGLLY,NGLLZ,nspec),intent(in) :: ibool
1493+
real(kind=CUSTOM_REAL), dimension(nglob),intent(in) :: xstore,ystore,zstore
1494+
1495+
! GLL data values array
1496+
real(kind=CUSTOM_REAL), dimension(NDIM,nglob),intent(in) :: field
1497+
1498+
! file name
1499+
character(len=MAX_STRING_LEN),intent(in) :: prname_file
1500+
1501+
! local parameters
1502+
integer :: ispec,i,ier
1503+
1504+
open(IOUT_VTK,file=trim(prname_file)//'.vtk',status='unknown',iostat=ier)
1505+
if (ier /= 0 ) then
1506+
print *, 'Error opening VTK output file: ',trim(prname_file)
1507+
stop 'Error opening VTK output file'
1508+
endif
1509+
write(IOUT_VTK,'(a)') '# vtk DataFile Version 3.1'
1510+
write(IOUT_VTK,'(a)') 'material model VTK file'
1511+
write(IOUT_VTK,'(a)') 'ASCII'
1512+
write(IOUT_VTK,'(a)') 'DATASET UNSTRUCTURED_GRID'
1513+
write(IOUT_VTK, '(a,i12,a)') 'POINTS ', nglob, ' float'
1514+
do i = 1,nglob
1515+
write(IOUT_VTK,'(3e18.6)') real(xstore(i),kind=4),real(ystore(i),kind=4),real(zstore(i),kind=4)
1516+
enddo
1517+
write(IOUT_VTK,*) ""
1518+
1519+
! note: indices for vtk start at 0
1520+
write(IOUT_VTK,'(a,i12,i12)') "CELLS ",nspec,nspec*9
1521+
do ispec = 1,nspec
1522+
write(IOUT_VTK,'(9i12)') 8, &
1523+
ibool(1,1,1,ispec)-1,ibool(NGLLX,1,1,ispec)-1, &
1524+
ibool(NGLLX,NGLLY,1,ispec)-1,ibool(1,NGLLY,1,ispec)-1, &
1525+
ibool(1,1,NGLLZ,ispec)-1,ibool(NGLLX,1,NGLLZ,ispec)-1, &
1526+
ibool(NGLLX,NGLLY,NGLLZ,ispec)-1,ibool(1,NGLLY,NGLLZ,ispec)-1
1527+
enddo
1528+
write(IOUT_VTK,*) ""
1529+
1530+
! type: hexahedrons
1531+
write(IOUT_VTK,'(a,i12)') "CELL_TYPES ",nspec
1532+
write(IOUT_VTK,'(6i12)') (12,ispec=1,nspec)
1533+
write(IOUT_VTK,*) ""
1534+
1535+
write(IOUT_VTK,'(a,i12)') "POINT_DATA ",nglob
1536+
1537+
! single wavefield components
1538+
if (.true.) then
1539+
write(IOUT_VTK,'(a)') "SCALARS field_x float"
1540+
write(IOUT_VTK,'(a)') "LOOKUP_TABLE default"
1541+
do i = 1,nglob
1542+
write(IOUT_VTK,*) real(field(1,i),kind=4)
1543+
enddo
1544+
write(IOUT_VTK,*) ""
1545+
1546+
write(IOUT_VTK,'(a)') "SCALARS field_y float"
1547+
write(IOUT_VTK,'(a)') "LOOKUP_TABLE default"
1548+
do i = 1,nglob
1549+
write(IOUT_VTK,*) real(field(2,i),kind=4)
1550+
enddo
1551+
write(IOUT_VTK,*) ""
1552+
1553+
write(IOUT_VTK,'(a)') "SCALARS field_z float"
1554+
write(IOUT_VTK,'(a)') "LOOKUP_TABLE default"
1555+
do i = 1,nglob
1556+
write(IOUT_VTK,*) real(field(3,i),kind=4)
1557+
enddo
1558+
write(IOUT_VTK,*) ""
1559+
endif
1560+
1561+
! vector wavefield
1562+
if (.true.) then
1563+
write(IOUT_VTK,'(a)') "VECTORS field_vector float"
1564+
do i = 1,nglob
1565+
write(IOUT_VTK,*) real(field(1,i),kind=4),real(field(2,i),kind=4),real(field(3,i),kind=4)
1566+
enddo
1567+
write(IOUT_VTK,*) ""
1568+
endif
1569+
1570+
close(IOUT_VTK)
1571+
1572+
end subroutine write_VTK_wavefield
1573+
14791574
!-------------------------------------------------------------------------------------------------
14801575
!
1576+
! VTU binary formats
1577+
!
1578+
!-------------------------------------------------------------------------------------------------
14811579

14821580
subroutine write_VTU_movie_data(ne,np,total_dat_xyz,total_dat_con,total_dat,mesh_file,var_name)
14831581

0 commit comments

Comments
 (0)