Good morning,
I am using set_depth.m Matlab script to get depth values for each level of my vertical discretization. I do not understand why the computation of U and V-points (from RHO-points) is as follows:
Considering that Lp and Mp are the RHO-points dimension, L=Lp-1 and M=Mp-1 :
zetau=0.5.*(zeta(1:L,1:Mp)+zeta(2:Lp,1:Mp)); [line 192 of set_depth.m]
zetav=0.5.*(zeta(1:Lp,1:M)+zeta(1:Lp,2:Mp)); [line 195 of set_depth.m]
U-points grid size should be [Lp,M] and V-points grid size should be [L,Mp]. However, according to the previous calculation, zetau is [L,Mp] and zetav is [Lp,M]. Is it right?
Thank you very much for your time
Josep Maria Solé Tasias
set_depth.m question
- arango
- Site Admin
- Posts: 1356
- Joined: Wed Feb 26, 2003 4:41 pm
- Location: DMCS, Rutgers University
- Contact:
Re: set_depth.m question
Nope. The script is correct. The RHO-point variables are of size [Lp,Mp], U-points are [L,Mp], V-points variables are [Lp,M], and PSI-variables are [L,M] in Matlab. Matlab does not allows array elements less than 1. Therefore, the zero lower range is rolled by one. That's what the suffix p in Lp and Mp means (plus 1) in the the context of all ROMS Matlab scripts.
Re: set_depth.m question
Good morning Arango,
Thank you very much for your reply. I would like to understand better this issue.
According to the description of Wikiroms (Horizontal Discretiztion): https://www.myroms.org/wiki/index.php/N ... _Technique
here I can see that U-points has one column less than RHO-POINTS, and V-points has one row less than RHO-POINTS, right? Then, if dimension of RHO-POINTS is [Lp,Mp] ([num rows, num columns]), I think that U-points should be of size [Lp,M] and V-points should be of size [L,Mp].
Thank you very much
Thank you very much for your reply. I would like to understand better this issue.
According to the description of Wikiroms (Horizontal Discretiztion): https://www.myroms.org/wiki/index.php/N ... _Technique
here I can see that U-points has one column less than RHO-POINTS, and V-points has one row less than RHO-POINTS, right? Then, if dimension of RHO-POINTS is [Lp,Mp] ([num rows, num columns]), I think that U-points should be of size [Lp,M] and V-points should be of size [L,Mp].
Thank you very much
Re: set_depth.m question
I think I found out my mistake! Size of matrixs is given as [columns,rows], right?. I was used to working on matrixs whose size is given as [rows,columns]. That was my confusion.
- arango
- Site Admin
- Posts: 1356
- Joined: Wed Feb 26, 2003 4:41 pm
- Location: DMCS, Rutgers University
- Contact:
Re: set_depth.m question
Yes, all the Matlab scripts in the ROMS repository are in column major order, A(x,y,z,t) or A(lon,lat,depth,time). After all, both Fortran and Matlab are in colunm major order
Then, it is more efficient to operate in column major order because of the multiple dimension linear storage of array elements in memory. Also, less confusing when dealing with square arrays. Many user have transposed the dimensions with catastrophic results in terms of physics when dealing with vector quantities and Coriolis.
Some people make the mistake that Matlab is like C-language which have a row major order.
![Exclamation :!:](./images/smilies/icon_exclaim.gif)
Some people make the mistake that Matlab is like C-language which have a row major order.