Bug in fine2coarse.m for nesting

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
jpringle
Posts: 107
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

Bug in fine2coarse.m for nesting

#1 Unread post by jpringle »

I am developing a new modeling setup with a simple nested grid configuration. Following Hernan's advice, I am starting from a full domain fine grid and extracting the coarse grid from it. However, the fine2coarse.m downloaded from the SVN repository as of this morning is completely broken (SVN revision 766, retrieved from the repository at https://www.myroms.org/svn/src/matlab). There are errors in syntax (line 145):

Code: Select all

    grd_vars = [grd_vars, 'x_rho', 'y_rho', 'x_psi', 'y_psi',               ...
                      'x_u', 'y_u', 'x_v', 'y_v'};
And undeclared variables (line 280, the grid variable should be F)

Code: Select all

     if (G.spherical),
And the logic of the grid sizes is wrong and fails for some simple use cases (Gfactor=3, Imin=3,Imax=18,Jmin=3,Jmax=18). It produces rho and psi grids that are the same size. These dimensions are (properly) incompatible with the netcdf file layout.

I am happy to pitch in and fix it. But the code is so scrambled it looks, perhaps, like a bad code merge :( . Does anyone have a minimally working copy? As I said, I am happy to dig into the code, but am loath to duplicate effort.

Cheers,
Jamie Pringle

jpringle
Posts: 107
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

Re: Bug in fine2coarse.m for nesting

#2 Unread post by jpringle »

Before anyone else spends time on this, I am working on fixing this code. I will let people know when a working version exists and has been tested.

Jamie

jpringle
Posts: 107
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

Re: Bug in fine2coarse.m for nesting

#3 Unread post by jpringle »

Attached is a corrected fine2coarse.m, a testing code, a file with grid information for it to read, and a little routine to plot grids. The testing harness expects the rest of the ROMS Matlab tools to be in the path.

Please make sure you are running the provided fine2coarse.m, and not the one that comes from the SVN server.

To test the new fine2coarse.m, run the code "test_fine2coarse.m"

I have not tested this on cartesian grids; that should not make a difference :D .

Cheers,
Jamie Pringle
Attachments
plot_grid.m
(1.1 KiB) Downloaded 265 times
test_fine2coarse.m
(2.41 KiB) Downloaded 258 times
bigTest_ocean_his.nc
(3.69 MiB) Downloaded 252 times
fine2coarse.m
(11.48 KiB) Downloaded 273 times

User avatar
kate
Posts: 4088
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: Bug in fine2coarse.m for nesting

#4 Unread post by kate »

Thanks, Jamie! I was hoping to try this stuff one of these months.

jpringle
Posts: 107
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

Re: Bug in fine2coarse.m for nesting

#5 Unread post by jpringle »

My fine2coarse code does not set either the coarse_factor or refine_factor attributes of either grid; see viewtopic.php?f=1&t=3698&p=14962#p14962 ; I am not sure fine2coarse is a good place to do so, and will not be able to do so until I have a better understanding of the roll of these attributes in contacts.m

Until contacts.m understands coarse_factor, I would add the attribute refine_factor to the fine receiver grid. HOWEVER, this advice is likely to be out of date soon as Hernan and others update the contacts.m code. Right now the codes are new, and it is easy to explore new edge cases. If you are reading this much after July 2015, discount appropriately.

User avatar
arango
Site Admin
Posts: 1347
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

Re: Bug in fine2coarse.m for nesting

#6 Unread post by arango »

There are two ways to construct refined nested grids: (1) coarse to fine grid refinement or (2) fine to coarse grid extraction. I prefer to do option (2) since all the quantities needed in the contact area are already available in the donor grid. If you don't see this, think about refinement and composite grids in estuary applications. Notice that the contact points information are created outside of ROMS to facilitate complex nesting configurations. We need to provide all the metrics (h, pm, pn, dndx, dmde, mask_rho, mask_u, mask_v) and interpolation weights instead of computing or fine tuning them inside ROMS. This is preferable than start hacking ROMS code and make a mess of the logic and the non trivial parallelzation. Therefore, it is wise to add the respective attributes in question to the generated NetCDF files. There are several new scripts that I haven't released yet and you have to take my word for it that we need those parameters. Also, it is simpler to read them than start decoding the nasty history attribute. I don't know what is the big deal about adding a global attribute into the NetCDF file that it is used by the nesting scripts, grids structure arrays, and plotting. It is even a good policy for future documentation of what you did. If you started from my version of the script, it should have the code to write those parameters.

The fine2coarse.m script was mostly overwritten to have a robust logic for extraction. I hope that I release it soon but I still need to do some testing. I am still dealing with the issues of area and volume conservation and come-up with a tolerance error for such big numbers in meters. My intuition tells me that this is important. They are other opinions to the contrary. The other issue is how to compute correctly pm, pn, dndx, and dmde for curvilinear grids that are distorted. This one is tricky and there are different opinions on how to do it. There is also the issue of quadratic conservative interpolation which preserve reversibility. This is very important when building the tangent linear and the adjoint of the nesting operators. Our final target is to have 4D-Var data assimilation on two-way nested grids. As you can see, there are a lot to consider and have delayed the releasing of the new version of the nesting scripts.

A major problem that we have with nesting now is that the two-way nesting (fine2coare in ROMS) is very expensive in MPI because of the communications in gathering the full array data for averaging fine grid solution into the coarse grid. I already know what to do to improve this. It will require recoding this subroutines (2D and 3D). It is in my to do list... My plate is very full so everybody need to be patient.

jpringle
Posts: 107
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

Re: Bug in fine2coarse.m for nesting

#7 Unread post by jpringle »

My original edits to fine2coarse.m, and the "official" version on the Subversion repository, contain an error in which the curvilinear metrics dmde and dndx are not written to the coarse grid. Since those fields are defined in c_grid(), the grid file has fill values for those metrics. The fixed code is attached below. It will be necessary to add

Code: Select all

if (F.curvilinear) 
   grd_vars= [grd_vars, 'dmde', 'dndx'];
end 
to the code on the Subversion repository where grd_vars is being defined.
Attachments
fine2coarse.m
(11.64 KiB) Downloaded 272 times

Post Reply