get_volume_average_func Subroutine

public subroutine get_volume_average_func(func, f_avg, volume)

Uses

  • proc~~get_volume_average_func~~UsesGraph proc~get_volume_average_func get_volume_average_func module~mod_global_parameters mod_global_parameters proc~get_volume_average_func->module~mod_global_parameters module~mod_basic_types mod_basic_types module~mod_global_parameters->module~mod_basic_types module~mod_connectivity mod_connectivity module~mod_global_parameters->module~mod_connectivity module~mod_constants mod_constants module~mod_global_parameters->module~mod_constants module~mod_physicaldata mod_physicaldata module~mod_global_parameters->module~mod_physicaldata module~mod_variables mod_variables module~mod_global_parameters->module~mod_variables mpi mpi module~mod_global_parameters->mpi module~mod_variables->module~mod_basic_types

Compute the volume average of func(w) over the leaves of the grid.

Arguments

Type IntentOptional Attributes Name
public pure function func(w_vec, w_size) result(val)
Arguments
Type IntentOptional Attributes Name
double precision, intent(in) :: w_vec(w_size)
integer, intent(in) :: w_size
Return Value double precision
double precision, intent(out) :: f_avg

The volume average of func

double precision, intent(out) :: volume

The total grid volume


Calls

proc~~get_volume_average_func~~CallsGraph proc~get_volume_average_func get_volume_average_func mpi_allreduce mpi_allreduce proc~get_volume_average_func->mpi_allreduce

Source Code

  subroutine get_volume_average_func(func, f_avg, volume)
    use mod_global_parameters

    interface
       pure function func(w_vec, w_size) result(val)
         integer, intent(in)          :: w_size
         double precision, intent(in) :: w_vec(w_size)
         double precision             :: val
       end function func
    end interface
    double precision, intent(out) :: f_avg
    !< The volume average of func
    double precision, intent(out) :: volume
    !< The total grid volume
    integer                       :: iigrid, igrid, i1,i2,i3
    double precision              :: wsum(2)
    double precision              :: dsum_recv(2)

    wsum(:) = 0

    ! Loop over all the grids
    do iigrid = 1, igridstail
       igrid = igrids(iigrid)

       ! Store total volume in last element
       wsum(2) = wsum(2) + sum(ps(igrid)%dvolume(ixMlo1:ixMhi1,ixMlo2:ixMhi2,&
          ixMlo3:ixMhi3))

       ! Compute the modes of the cell-centered variables, weighted by volume
       do i1 = ixMlo1, ixMhi1
       do i2 = ixMlo2, ixMhi2
       do i3 = ixMlo3, ixMhi3
       wsum(1) = wsum(1) + ps(igrid)%dvolume(i1,i2,i3) * func(ps(igrid)%w(i1,&
          i2,i3, :), nw)
       end do
       end do
       end do
    end do

    ! Make the information available on all tasks
    call MPI_ALLREDUCE(wsum, dsum_recv, 2, MPI_DOUBLE_PRECISION, MPI_SUM,&
        icomm, ierrmpi)

    ! Set the volume and the average
    volume = dsum_recv(2)
    f_avg  = dsum_recv(1) / volume

  end subroutine get_volume_average_func