hvs_vtk_write_meshdata Subroutine

public subroutine hvs_vtk_write_meshdata(vtk_file, vrtx, nElems)

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.

Arguments

Type IntentOptional 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


Calls

proc~~hvs_vtk_write_meshdata~2~~CallsGraph proc~hvs_vtk_write_meshdata~2 hvs_vtk_write_meshdata interface~convert_to_base64 convert_to_Base64 proc~hvs_vtk_write_meshdata~2->interface~convert_to_base64 proc~int8_to_base64 int8_to_base64 interface~convert_to_base64->proc~int8_to_base64 proc~int64_to_base64 int64_to_base64 interface~convert_to_base64->proc~int64_to_base64 proc~real64_to_base64 real64_to_base64 interface~convert_to_base64->proc~real64_to_base64 proc~char_to_base64 char_to_base64 interface~convert_to_base64->proc~char_to_base64 proc~real32_to_base64 real32_to_base64 interface~convert_to_base64->proc~real32_to_base64 proc~int32_to_base64 int32_to_base64 interface~convert_to_base64->proc~int32_to_base64 interface~convert_to_base64_single convert_to_Base64_single proc~int8_to_base64->interface~convert_to_base64_single interface~encodeindex EncodeIndex proc~int8_to_base64->interface~encodeindex interface~encodeblock EncodeBlock proc~int8_to_base64->interface~encodeblock proc~int64_to_base64->interface~convert_to_base64_single proc~int64_to_base64->interface~encodeindex proc~int64_to_base64->interface~encodeblock proc~real64_to_base64->interface~convert_to_base64_single proc~real64_to_base64->interface~encodeindex proc~real64_to_base64->interface~encodeblock proc~char_to_base64->interface~convert_to_base64_single proc~char_to_base64->interface~encodeindex proc~char_to_base64->interface~encodeblock proc~real32_to_base64->interface~convert_to_base64_single proc~real32_to_base64->interface~encodeindex proc~real32_to_base64->interface~encodeblock proc~int32_to_base64->interface~convert_to_base64_single proc~int32_to_base64->interface~encodeindex proc~int32_to_base64->interface~encodeblock proc~real64_to_base64_single real64_to_base64_single interface~convert_to_base64_single->proc~real64_to_base64_single proc~int8_to_base64_single int8_to_base64_single interface~convert_to_base64_single->proc~int8_to_base64_single proc~int64_to_base64_single int64_to_base64_single interface~convert_to_base64_single->proc~int64_to_base64_single proc~real32_to_base64_single real32_to_base64_single interface~convert_to_base64_single->proc~real32_to_base64_single proc~char_to_base64_single char_to_base64_single interface~convert_to_base64_single->proc~char_to_base64_single proc~int32_to_base64_single int32_to_base64_single interface~convert_to_base64_single->proc~int32_to_base64_single

Called by

proc~~hvs_vtk_write_meshdata~2~~CalledByGraph proc~hvs_vtk_write_meshdata~2 hvs_vtk_write_meshdata proc~hvs_dump_debug_array hvs_dump_debug_array proc~hvs_dump_debug_array->proc~hvs_vtk_write_meshdata~2

Contents


Source Code

  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