subtract_owned_mean_scalar Subroutine

public subroutine subtract_owned_mean_scalar(flow, scalar)

Remove the constant nullspace component from an owned-cell scalar.

Arguments

Type IntentOptional Attributes Name
type(flow_mpi_t), intent(in) :: flow
real(kind=rk), intent(inout) :: scalar(:)

Source Code

   subroutine subtract_owned_mean_scalar(flow, scalar)
      type(flow_mpi_t), intent(in) :: flow
      real(rk), intent(inout) :: scalar(:)

      integer :: c, ierr
      integer :: global_count
      real(rk) :: local_sum, global_sum, mean_value

      local_sum = zero

      do c = flow%first_cell, flow%last_cell
         local_sum = local_sum + scalar(c)
      end do

      call profiler_start('Pressure_Gauge_Allreduce')
      call MPI_Allreduce(local_sum, global_sum, 1, MPI_DOUBLE_PRECISION, MPI_SUM, flow%comm, ierr)
      call profiler_stop('Pressure_Gauge_Allreduce')
      if (ierr /= MPI_SUCCESS) call fatal_error('numerics', 'MPI failure reducing zero-mean scalar sum')

      if (allocated(flow%gather_counts)) then
         global_count = sum(flow%gather_counts)
      else
         global_count = flow%nlocal
      end if

      if (global_count <= 0) return
      mean_value = global_sum / real(global_count, rk)

      do c = flow%first_cell, flow%last_cell
         scalar(c) = scalar(c) - mean_value
      end do
   end subroutine subtract_owned_mean_scalar