ocean_budgets_drain_contributors Subroutine

private subroutine ocean_budgets_drain_contributors(this)

For each contributor: integrate per_cell·mask·areaT (over k) into total_integrated, then zero per_cell for the next window.

Type Bound

ocean_budgets_t

Arguments

Type IntentOptional Attributes Name
class(ocean_budgets_t), intent(inout) :: this

Calls

proc~~ocean_budgets_drain_contributors~~CallsGraph proc~ocean_budgets_drain_contributors ocean_budgets_t%ocean_budgets_drain_contributors proc~budget_area_field budget_area_field proc~ocean_budgets_drain_contributors->proc~budget_area_field proc~diag_mask_global diag_mask_global proc~ocean_budgets_drain_contributors->proc~diag_mask_global proc~recompute_total_area recompute_total_area proc~diag_mask_global->proc~recompute_total_area

Variables

Type Visibility Attributes Name Initial
real(kind=wp), private, allocatable :: areaT(:,:)
real(kind=wp), private :: col_sum
integer, private :: i
integer, private :: ic
real(kind=wp), private :: increment
integer, private :: j
integer, private :: k
integer, private :: nx
integer, private :: ny
integer, private :: nz
real(kind=wp), private :: w_dA

Source Code

   subroutine ocean_budgets_drain_contributors(this)
      !! For each contributor: integrate `per_cell·mask·areaT` (over k) into
      !! `total_integrated`, then zero `per_cell` for the next window.
      class(ocean_budgets_t), intent(inout) :: this
      integer :: ic, i, j, k, nx, ny, nz
      real(wp) :: w_dA, col_sum, increment
      real(wp), allocatable :: areaT(:, :)

      if (.not. this%is_init) return
      if (.not. allocated(this%mask)) then
         allocate (this%mask, source=diag_mask_global(this%grid))
      end if
      call budget_area_field(this, areaT)

      do ic = 1, this%n_contributors
         associate (c => this%contributors(ic))
            if (.not. c%is_active) cycle
            if (.not. associated(c%per_cell)) cycle
            if (c%device_resident) then
               !$acc update self(c%per_cell) if_present
            end if
            nx = min(this%mask%nx, size(c%per_cell, 1))
            ny = min(this%mask%ny, size(c%per_cell, 2))
            nz = size(c%per_cell, 3)
            increment = 0.0_wp
            do j = 1, ny
               do i = 1, nx
                  w_dA = this%mask%weight(i, j)*areaT(i, j)
                  if (w_dA <= 0.0_wp) cycle
                  col_sum = 0.0_wp
                  do k = 1, nz
                     col_sum = col_sum + c%per_cell(i, j, k)
                  end do
                  increment = increment + w_dA*col_sum
               end do
            end do
            c%total_integrated = c%total_integrated + increment
            c%per_cell = 0.0_wp
            if (c%device_resident) then
               !$acc update device(c%per_cell) if_present
            end if
         end associate
      end do
   end subroutine ocean_budgets_drain_contributors