Compute the volume average of func(w) over the leaves of the grid.
| Type | Intent | Optional | Attributes | Name | |||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
public pure function func(w_vec, w_size) result(val)Arguments
Return Value double precision |
|||||||||||||||||||||||||||
| double precision, | intent(out) | :: | f_avg |
The volume average of func |
|||||||||||||||||||||||
| double precision, | intent(out) | :: | volume |
The total grid volume |
|||||||||||||||||||||||
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