-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
In plain text, an example in pure Fortran:
module VTUWriter
implicit none
private
type, public :: VTUFile
integer :: file_unit
char(len=500) :: filename
end type
public :: VTUOpenFile
end module
function VTUOpenFile(filename)
implicit none
type(VTUOpenFile), pointer :: vtu
character(len=500) :: filename
integer :: unit = 42
allocate(f)
vtu%unit = unit
vtu%filename = filename
open(unit = unit, file = filename, status = 'new')
VTUOpenFile => vtu
end function
function VTUCloseFile(vtu)
VTUOpenFile :: vtu
close(vtu%unit)
end function
function VTUWriteHeader(vtu)
implicit none
type(VTUFile), pointer :: vtu
write(vtu%unit, '(A)') '<VTKFile type="UnstructuredGrid" version="1.0" header_type="UInt64">'
write(vtu%unit, '(A)') '<UnstructuredGrid>'
write(vtu%unit, '(A)') '<Piece NumberOfPoints="', n_vertices, '" NumberOfCells="', n_elements, '">'
end function
function VTUWritePoints()
write(vtu%unit, '(A)') '<Points>'
write(vtu%unit, '(A)') '<DataArray type="Float32" NumberOfComponents="3" format="ascii">'
do (i=1,n_points)
write(vtu%unit, '(A)') points(i, 1), points(i, 2), points(i, 3)
end do
write(vtu%unit, '(A)') '</DataArray>'
write(vtu%unit, '(A)') '</Points>'
end function
function VTUWriteCells()
write(vtu%unit, '(A)') '<Cells>'
write(vtu%unit, '(A)') '<DataArray type="Int64" Name="connectivity" format="ascii">'
do i=1,n_cells
do j=1,size(cells(i))
write(vtu%unit, '(A)') cells(i, j)
end do
end do
write(vtu%unit, '(A)') '</DataArray>'
write(vtu%unit, '(A)') '</Cells>'
! https://github.com/polyfem/polyfem/blob/3f58d84cd0ad930b71e8c6db917fe46e8dd4e100/src/mesh/VTUWriter.cpp#L170
end function
function VTUWriteFooter()
write(vtu%unit, '(A)') '</Piece>'
write(vtu%unit, '(A)') '</UnstructuredGrid>'
write(vtu%unit, '(A)') '</VTKFile>'
end function
function VTUWriteFile()
! https://github.com/polyfem/polyfem/blob/3f58d84cd0ad930b71e8c6db917fe46e8dd4e100/src/mesh/VTUWriter.cpp#L82:21
vtu = VTUOpenFile(filename)
VTUWriteHeader(vtu)
VTUWritePoints(vtu, points)
VTUWriteFooter(vtu)
VTUCloseFile(vtu)
end functionReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels