Write the mesh information into the VTK output files.
Note: the unstructured meshes we write are consisting of voxels, this assumption is built into the code and exploited.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hvs_vtk_file_type), | intent(in) | :: | vtk_file |
File handles to the files where the mesh data should be written to. |
||
type(tem_vrtx_type), | intent(in) | :: | vrtx |
Information on the vertices of the mesh |
||
integer, | intent(in) | :: | nElems |
Number of elements in the mesh |
subroutine hvs_vtk_write_meshdata(vtk_file, vrtx, nElems)
!> File handles to the files where the mesh data should be written to.
type(hvs_vtk_file_type), intent(in) :: vtk_file
!> Information on the vertices of the mesh
type(tem_vrtx_type), intent(in) :: vrtx
!> Number of elements in the mesh
integer, intent(in) :: nElems
! ----------------------------------------------------------------------!
real(kind=c_double), target, allocatable :: indata(:)
integer(kind=c_int), target, allocatable :: indata_int(:)
integer(kind=c_int_least8_t), target, allocatable :: indata_int8(:)
character(len=PathLen) :: headerline
character :: linebreak
logical :: use_ascii
integer :: iVrtx, iElem
! ----------------------------------------------------------------------!
linebreak = new_line('x')
use_ascii = (trim(vtk_file%dataform) == 'ascii')
write(headerline,'(a,i0,a,i0,a)') ' <Piece NumberOfPoints="', &
& vrtx%nVertices, '" NumberOfCells="', &
& nElems, '">'
write(vtk_file%outunit) trim(headerline)//linebreak
write(vtk_file%outunit) linebreak
! Write the point data:
write(headerline,'(a)') ' <Points>'
write(vtk_file%outunit) trim(headerline)//linebreak
write(headerline,'(a)') ' <DataArray Name="xyz" ' &
& // 'NumberOfComponents="3" type="Float64" ' &
& // 'format="' // trim(vtk_file%dataform) // '">'
write(vtk_file%outunit) trim(headerline)//linebreak
if (use_ascii) then
do ivrtx = 1, vrtx%nvertices
write(headerline,*) real(vrtx%coord%val(:,ivrtx), kind = double_k)
write(vtk_file%outunit) trim(headerline)//linebreak
end do
else
allocate(indata(vrtx%nVertices*3))
do ivrtx = 1, vrtx%nvertices
indata(1+(ivrtx-1)*3:ivrtx*3) = vrtx%coord%val(:,ivrtx)
end do
call convert_to_base64( indata, vrtx%nVertices*3, vtk_file%outunit )
write(vtk_file%outunit) linebreak
deallocate(indata)
end if
write(headerline,'(a)') ' </DataArray>'
write(vtk_file%outunit) trim(headerline)//linebreak
write(headerline,'(a)') ' </Points>'
write(vtk_file%outunit) trim(headerline)//linebreak
write(vtk_file%outunit) linebreak
! Write the cell data:
write(headerline,'(a)') ' <Cells>'
write(vtk_file%outunit) trim(headerline)//linebreak
write(headerline,'(a)') ' <DataArray type="Int32" Name="connectivity"' &
& //' format="'//trim(vtk_file%dataform)//'">'
write(vtk_file%outunit) trim(headerline)//linebreak
if (use_ascii) then
do iElem = 1, nElems
write(headerline,*) vrtx%map2global(iElem,:) - 1
write(vtk_file%outunit) trim(headerline)//linebreak
end do
else
allocate(indata_int(vrtx%maxVertices))
do iElem = 1, nElems
indata_int( &
& (iElem-1)*vtk_file%vtx_per_Elem +1 : iElem*vtk_file%vtx_per_Elem) &
& = vrtx%map2global(iElem,:) - 1
end do
call convert_to_base64( indata_int, vrtx%maxVertices, vtk_file%outunit )
deallocate(indata_int)
write(vtk_file%outunit) linebreak
end if
write(headerline,'(a)') ' </DataArray>'
write(vtk_file%outunit) trim(headerline)//linebreak
! Write offsets:
write(headerline,'(a)') ' <DataArray type="Int32" Name="offsets"' &
& //' format="'//trim(vtk_file%dataform)//'">'
write(vtk_file%outunit) trim(headerline)//linebreak
if (use_ascii) then
do iElem = 1, nElems
write(headerline,*) iElem*vtk_file%vtx_per_Elem
write(vtk_file%outunit) trim(headerline)
end do
write(vtk_file%outunit) linebreak
else
allocate(indata_int(nElems))
do iElem = 1, nElems
indata_int(iElem) = iElem*vtk_file%vtx_per_Elem
end do
call convert_to_base64( indata_int, nElems, vtk_file%outunit )
deallocate(indata_int)
write(vtk_file%outunit) linebreak
end if
write(headerline,'(a)') ' </DataArray>'
write(vtk_file%outunit) trim(headerline)//linebreak
! Write the cell type.
write(headerline,'(a)') ' <DataArray type="UInt8" Name="types"' &
& // ' format="'//trim(vtk_file%dataform)//'">'
write(vtk_file%outunit) trim(headerline)//linebreak
if (use_ascii) then
do iElem = 1, nElems
write(headerline,*) vtk_file%CellType
write(vtk_file%outunit) trim(headerline)
end do
write(vtk_file%outunit) linebreak
else
allocate(indata_int8(nElems))
indata_int8 = int(vtk_file%CellType, c_int_least8_t)
call convert_to_base64( indata_int8, nElems, vtk_file%outunit )
deallocate(indata_int8)
write(vtk_file%outunit) linebreak
end if
write(headerline,'(a)') ' </DataArray>'
write(vtk_file%outunit) trim(headerline)//linebreak
write(headerline,'(a,i0,a)') ' </Cells>'
write(vtk_file%outunit) trim(headerline)//linebreak
write(vtk_file%outunit) linebreak
! Add mesh information to the pvtu file accordingly:
if (vtk_file%write_pvtu) then
write(headerline,'(a)') ' <PPoints>'
write(vtk_file%punit) trim(headerline)//linebreak
write(headerline,'(a)') ' <PDataArray Name="xyz" ' &
& // 'NumberOfComponents="3" type="Float64" ' &
& // 'format="' // trim(vtk_file%dataform) // '"/>'
write(vtk_file%punit) trim(headerline)//linebreak
write(headerline,'(a)') ' </PPoints>'
write(vtk_file%punit) trim(headerline)//linebreak
write(vtk_file%punit) linebreak
write(headerline,'(a)') ' <PCells>'
write(vtk_file%punit) trim(headerline)//linebreak
write(headerline,'(a)') ' <PDataArray type="Int32" ' &
& // 'Name="connectivity" format="' &
& // trim(vtk_file%dataform) // '"/>'
write(vtk_file%punit) trim(headerline)//linebreak
write(headerline,'(a)') ' <PDataArray type="Int32" ' &
& // 'Name="offsets" format="' &
& // trim(vtk_file%dataform) // '"/>'
write(vtk_file%punit) trim(headerline)//linebreak
write(headerline,'(a)') ' <PDataArray type="UInt8" ' &
& // 'Name="types" format="' &
& // trim(vtk_file%dataform) // '"/>'
write(vtk_file%punit) trim(headerline)//linebreak
write(headerline,'(a)') ' </PCells>'
write(vtk_file%punit) trim(headerline)//linebreak
write(vtk_file%punit) linebreak
end if
end subroutine hvs_vtk_write_meshdata