Scheduled Downtime
On Friday 21 April 2023 @ 5pm MT, this website will be down for maintenance and expected to return online the morning of 24 April 2023 at the latest

Calculating domain average of a variable

This post was from a previous version of the WRF&MPAS-A Support Forum. New replies have been disabled and if you have follow up questions related to this post, then please start a new thread from the forum home page.

flaounas

New member
Hello,

For a certain diagnostic, I have introduced to the registry a variable named "diag8". At every model time step, now I need to calculate the average of diag8 within the whole domain. For this reason I naively introduced the following piece of code at the beginning of "solve_em.F". Obviously this is not the correct way to do it since I am getting "meanval" equal to NaN :-|.

Could I please ask you for any tips on how to calculate the domain average of a certain variable?

Thank you in advance,
Manos

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!$OMP PiRALLEL DO &
!$OMP PRIVATE ( ij ) REDUCTION (+:meanval)
REDUCTION
DO ij = 1 , grid%num_tiles
DO i=ims,ime
DO k=kms,kme
DO j=jms,jme
meanval = meanval + abs(grid%diag8(i,k,j))/(ide*jde*kte)
END DO
END DO
END DO
END DO
!$OMP END PARALLEL DO
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
Hi,
Unfortunately I'm not a software engineer, and it looks like the only place domain-averaging is currently computed in the model is in the phys/module_diag_misc.F file. I'd recommend taking a look in the file to see how it was done for some of the other variables and try to do something similar. You may have to search the code a bit to determine how all the related variables are set-up.
 
Hi,

thank you for the answer. This was very helpful!

Looking into the file you mentioned helped me realize that wrf has a subroutine that calculates sums of variables treated by different processors (wrf_dm_sum_real).

Kind regards,
Manos
 
Top