# Online calculation of spatial derivatives

#### flaounas

##### New member
Good afternoon,

I am working on a code to calculate online the field of relative vorticity. I am quite curious about the formulation of the code and the role of mapfactors.

For instance to calculate the term "du/dy", I do the following at a given grid point (i,k,j) where jp1=j+1 and jm1=j-1:

do i=its,ite
do k=kts,kte
do j=jts,jte
ddy = (msfvy(i,j)/msfvx(i,j))*rdy/(jp1-jm1)
dudy = .5*(u(i,k,jp1) + u(i+1,k,jp1) - u(i,k,jm1) - u(i+1,k,jm1))*ddy
enddo
endo
endo

The code is supposed to use the mass centre coordinates and to calculate derivative at the central grid point respect to the previous one in the south and the next one in the north.

I am not sure about the above although the results look reasonable. So I have two questions:

1) The calculation of "ddy" was inspired by the "horizontal_pressure_gradient" subroutine. Nevertheless the use of map scale factors does not seem to me to be consistent in the advection schemes of WRF. Does the above seem correct to you? Could you also please provide a bit more information about the difference between the ones that indicate a specific direction e.g. "MAPFAC_MX" and MAPFAC_M?

2) and now a naive question . The above code makes much sense in standard lat-lon projection where an increasing "j" index always points from south to north. However, I use a polar projection where an increasing "j" index might point from north to south or even towards the zonal direction. Could you please provide information how and where the model takes care of this? Does the model assume that "i" and "j" indexes always increase at the positive zonal and meridional direction? I guess that map scale factors are not relevant to this issue right?

Many thanks and I wish you an excellent week!

Kind regards,
Manos