Compute mean(w**power) over the leaves of the grid. The first mode (power=1) corresponds to the mean, the second to the mean squared values and so on.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | power |
Which mode to compute |
||
| double precision, | intent(out) | :: | mode(nw) |
The computed mode |
||
| double precision, | intent(out) | :: | volume |
The total grid volume |
subroutine get_volume_average(power, mode, volume) use mod_global_parameters integer, intent(in) :: power !< Which mode to compute double precision, intent(out) :: mode(nw) !< The computed mode double precision, intent(out) :: volume !< The total grid volume integer :: iigrid, igrid, iw integer :: ncells double precision :: wsum(nw+1) double precision :: dvol double precision :: dsum_recv(1:nw+1) wsum(:) = 0 ncells = (ixMhi1-ixMlo1+1)*(ixMhi2-ixMlo2+1)*(ixMhi3-ixMlo3+1) ! Loop over all the grids do iigrid = 1, igridstail igrid = igrids(iigrid) if (slab_uniform) then ! Every cell of the block has the same volume, and ps(igrid)%dvolume ! is not even allocated in a Cartesian build - take the one value ! from the block's spacing in rnode and factor it out of the sums. dvol = rnode(rpdx1_,igrid)*rnode(rpdx2_,igrid)*rnode(rpdx3_,igrid) wsum(nw+1) = wsum(nw+1) + dvol*dble(ncells) do iw = 1, nw wsum(iw) = wsum(iw) + dvol*sum(ps(igrid)%w(ixMlo1:ixMhi1,& ixMlo2:ixMhi2,ixMlo3:ixMhi3,iw)**power) end do else ! Read the metric out of bgeo directly rather than through the ! ps(igrid)%dvolume pointer view: bgeo is where the data actually ! lives, and the view is a bounds-remapped pointer into it. ! Store total volume in last element wsum(nw+1) = wsum(nw+1) + sum(bgeo%dvolume(ixMlo1:ixMhi1,& ixMlo2:ixMhi2,ixMlo3:ixMhi3,igrid)) ! Compute the modes of the cell-centered variables, weighted by volume do iw = 1, nw wsum(iw) = wsum(iw) + sum(bgeo%dvolume(ixMlo1:ixMhi1,& ixMlo2:ixMhi2,ixMlo3:ixMhi3,igrid)*ps(igrid)%w(ixMlo1:ixMhi1,& ixMlo2:ixMhi2,ixMlo3:ixMhi3,iw)**power) end do end if end do ! Make the information available on all tasks call MPI_ALLREDUCE(wsum, dsum_recv, nw+1, MPI_DOUBLE_PRECISION, MPI_SUM,& icomm, ierrmpi) ! Set the volume and the average volume = dsum_recv(nw+1) mode = dsum_recv(1:nw) / volume end subroutine get_volume_average