hvs_ascii_dump_elem_data Subroutine

public subroutine hvs_ascii_dump_elem_data(ascii, outProc, varpos, varsys, mesh, time, subtree, nDofs)

Write single log for the right scheme into its ascii file. This routine dumps the element data

Arguments

Type IntentOptional Attributes Name
type(hvs_ascii_type), intent(inout) :: ascii

ascii file to write data to.

type(tem_comm_env_type), intent(in) :: outProc

Parallel environment to use for the output.

integer, intent(in) :: varpos(:)

Position of the variable to write

type(tem_varSys_type), intent(in) :: varsys

Description of the available variable system to get the given varnames from.

type(treelmesh_type), intent(in) :: mesh

Mesh to write the data on.

type(tem_time_type), intent(in) :: time

Point in time to use for this data.

Can be important for space-time function evaluations.

type(tem_subTree_type), intent(in), optional :: subtree

Optional restriction of the elements to output.

integer, intent(in) :: nDofs

The number of dofs for each scalar variable of the equation system


Calls

proc~~hvs_ascii_dump_elem_data~~CallsGraph proc~hvs_ascii_dump_elem_data hvs_ascii_dump_elem_data proc~tem_get_element_chunk tem_get_element_chunk proc~hvs_ascii_dump_elem_data->proc~tem_get_element_chunk proc~tem_reduction_spatial_append tem_reduction_spatial_append proc~hvs_ascii_dump_elem_data->proc~tem_reduction_spatial_append proc~tem_reduction_spatial_close tem_reduction_spatial_close proc~hvs_ascii_dump_elem_data->proc~tem_reduction_spatial_close proc~tem_reduction_spatial_open tem_reduction_spatial_open proc~hvs_ascii_dump_elem_data->proc~tem_reduction_spatial_open proc~tem_reduction_spatial_tochunk tem_reduction_spatial_toChunk proc~hvs_ascii_dump_elem_data->proc~tem_reduction_spatial_tochunk proc~tem_elemsize tem_ElemSize proc~tem_reduction_spatial_append->proc~tem_elemsize proc~tem_levelof tem_LevelOf proc~tem_reduction_spatial_append->proc~tem_levelof mpi_reduce mpi_reduce proc~tem_reduction_spatial_close->mpi_reduce proc~tem_elemsize->proc~tem_levelof proc~tem_elemsizelevel tem_ElemSizeLevel proc~tem_elemsize->proc~tem_elemsizelevel

Called by

proc~~hvs_ascii_dump_elem_data~~CalledByGraph proc~hvs_ascii_dump_elem_data hvs_ascii_dump_elem_data proc~hvs_output_write hvs_output_write proc~hvs_output_write->proc~hvs_ascii_dump_elem_data proc~tem_tracker tem_tracker proc~tem_tracker->proc~hvs_output_write

Source Code

  subroutine hvs_ascii_dump_elem_data( ascii, outProc, varPos, varSys, mesh,  &
    &                                   time, subTree, nDofs )
    ! ---------------------------------------------------------------------------
    !> ascii file to write data to.
    type(hvs_ascii_type), intent(inout) :: ascii

    !> Parallel environment to use for  the output.
    type(tem_comm_env_type ), intent(in)    :: outProc

    !> Position of the variable to write
    integer, intent(in) :: varpos(:)

    !> Description of the available variable system to get the given varnames
    !! from.
    type(tem_varSys_type), intent(in) :: varsys

    !> Mesh to write the data on.
    type(treelmesh_type), intent(in) :: mesh

    !> Point in time to use for this data.
    !!
    !! Can be important for space-time function evaluations.
    type(tem_time_type), intent(in) :: time

    !> Optional restriction of the elements to output.
    type(tem_subtree_type), optional, intent(in) :: subtree

    !> The number of dofs for each scalar variable of the equation system
    integer, intent(in) :: nDofs
    ! ---------------------------------------------------------------------------
    integer :: nVars, nElems, nScalars, elemOff, nChunkElems
    integer :: nDofs_out
    integer :: nScalars_out
    integer :: iElem, iChunk, iScalar, iDof
    integer :: buf_start, buf_end
    real(kind=rk), allocatable :: res(:)
    integer, allocatable :: elemPos(:)
    character(len=4000) :: log_output ! output buffer
    ! ---------------------------------------------------------------------------
    allocate(res(io_buffer_size))

    ! Number of variables to dump
    nVars = size(varPos)

    ! Number of scalars in current output
    nScalars = sum(varSys%method%val(varPos(:))%nComponents)

    if (present(subTree)) then
      nElems = subTree%nElems
    else
      nElems = mesh%nElems
    end if

    if (ascii%isReduce) then
      ! open spatial reduction
      call tem_reduction_spatial_open( me     = ascii%redSpatial, &
        &                              varSys = varSys,           &
        &                              varPos = varPos(:nVars)    )
    end if

    ! allocate elemPos to size of chunkSize
    allocate(elemPos(ascii%chunkSize))

    ! Process all chunks to derive the quantities defined in the tracking object
    do iChunk = 1, ascii%nChunks
      ! Number of elements read so far in previous chunks.
      elemOff = ((iChunk-1)*ascii%chunkSize)

      ! number of elements written to THIS chunk
      nChunkElems = min(ascii%chunkSize, nElems-elemOff)

      ! Compute the element lower and upper bound for the current chunk
      buf_start = elemOff + 1
      buf_end = elemOff + nChunkElems

      if (present(subTree)) then
        elemPos(1:nChunkElems) = subTree%map2Global(buf_start:buf_end)
      else
        elemPos(1:nChunkElems) = (/ (iElem, iElem=buf_start, buf_end) /)
      end if

      ! evaluate all variables on current chunk
      call tem_get_element_chunk(varSys  = varSys,                 &
        &                        varPos  = varPos,                 &
        &                        elemPos = elemPos(1:nChunkElems), &
        &                        time    = time,                   &
        &                        tree    = mesh,                   &
        &                        nElems  = nChunkElems,            &
        &                        nDofs   = nDofs,                  &
        &                        res     = res                     )

      ! preform spatial reduction
      if (ascii%isReduce) then
        call tem_reduction_spatial_append(                                 &
          &                        me     = ascii%redSpatial,              &
          &                        chunk  = res,                           &
          &                        nElems = nChunkElems,                   &
          &                        treeID = mesh%treeID(                   &
          &                                      elemPos(1:nChunkElems) ), &
          &                        tree   = mesh,                          &
          &                        varSys = varSys,                        &
          &                        nDofs  = nDofs,                         &
          &                        varPos = varPos                         )
      end if
    end do ! iChunk

    ndofs_out = ndofs
    nscalars_out = nscalars

    ! If a reduction is present in the tracking, then the output is
    ! changed completely to only the reduced values
    ! For each variable, a reduction has to be assigned
    if( ascii%isReduce ) then

      ! Perform the global reduction on the data which was appended
      ! inside trackVariable by tem_reduction_spatial_append
      call tem_reduction_spatial_close( me   = ascii%redSpatial, &
        &                               proc = outProc           )

      ! Re-assign the chunk here to the stuff which was produced in the
      ! reduction operation
      call tem_reduction_spatial_toChunk(me          = ascii%redSpatial, &
        &                                chunk       = res,              &
        &                                nChunkElems = nChunkElems       )

      ndofs_out = 1
      nscalars_out = sum(ascii%redSpatial(:)%nComponents)
    end if

    ! If reduction is active only root of this output
    ! dumps data else all process writes their own result file
    if ( (ascii%isReduce .and. outProc%rank == 0) .or. &
      & (.not. ascii%isReduce) ) then

      ! First assemble the complete row consisting of the time ...
      write( log_output, '(e24.16e3)' ) time%sim

      ! add all the scalars entries of the variable systems for each elements

      do iElem = 1, nChunkElems
        do iDof = 1, nDofs_out
          do iScalar = 1, nScalars_out
            write( log_output, '(a,1x,e24.16e3)' ) trim(log_output),          &
              &    res( ((iElem-1)*nDofs_out+ (iDof-1))*nScalars_out + iScalar )
          end do
        end do
      end do
      ! then write into the ascii file
      write ( ascii%outunit , '(a)' ) trim(log_output)
    end if

    deallocate(elemPos)
    deallocate(res)

  end subroutine hvs_ascii_dump_elem_data