bugs in contact.m and grid_connections.m scripts?

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
zduvims
Posts: 5
Joined: Fri Feb 10, 2023 4:06 pm
Location: Virginia Institute of Marine Science

bugs in contact.m and grid_connections.m scripts?

#1 Unread post by zduvims »

Hi,

I downloaded the latest ROMS matlab package and tried to create a contact points file for composite grids.

1. First, I used the dogbone grids:

Code: Select all

c_contact('contact.nc', 0, 2);
Gnames = {'dogbone_grd_left.nc','dogbone_grd_right.nc'};
G = grids_structure(Gnames);
S = grid_perimeter(G);
S = grid_connections(G, S);
which got an error in grid_connections.m (Line 648): Xmin=min(X(:)-G(rg).x_rho(:));
The reason is X and G(rg).x_rho are not the same size. This is easy to debug, I changed it to: Xmin=min(X(:))-min(G(rg).x_rho(:));

Note that the dogbone_grd_left.nc and dogbone_grd_right.nc "totally overlap" at the boundary:
Screenshot 2023-07-10 at 10.51.53.png

2. I use grid_extract.m to create two grids from my parent grid, and the overlap region is not only one column:
Screenshot 2023-07-10 at 11.02.24.png
This time I got an error when running grid_connections.m

Code: Select all

Summary of Contact Regions Processed:
  
   Grid 01: left_new.nc
   Grid 02: right.nc
  
   Contact   Donor   Receiver
    Region    Grid       Grid
  
Unrecognized field name "contact".

Error in grid_connections (line 635)
  dg = S.contact(cr).donor_grid;
Looking deeper, it seems that the reason comes from the variable "connected" - this remains always false and so load_connectivity is also false.
The way I set up my two sub-grids makes it unable to run some if-end syntax (in grid_connections.m) in which "connected" is defined as true.

So I created a new left sub-grid, and this time the two sub-grids only overlap one column like the dogbone case:
Screenshot 2023-07-10 at 11.16.08.png
Now grid_connections.m worked.


3. I ran the contact.m and got this error:

Code: Select all

Summary of Contact Regions Processed:
  
   Grid 01: left.nc
   Grid 02: right.nc
  
   Contact   Donor   Receiver
    Region    Grid       Grid
  
     01        01        02
     02        02        01
  
Dot indexing is not supported for variables of this type.

Error in contact (line 345)
  Ndatum = Ndatum + length(S.contact(cr).point.Irg_rho)
I figured out that when the right sub-grid (larger one) is the donor grid, since its four corners do not lay at the edge of the left sub-grid, "coincident" was set to false. The contact.m will not run the if-end module in Lines 336-343, and "S.contact(cr).point" will not be defined.
Screenshot 2023-07-10 at 11.21.04.png
To get it run, I change line 336 to: if (S.contact(cr).coincident) || ~(S.contact(cr).coincident). I ran contact.m again and got this error:

Code: Select all

Updated global 'type' attribute to: "ROMS Hybrid Nesting Contact Regions Data".
Unable to perform assignment because the left and right
sides have a different number of elements.

Error in write_contact (line 235)
  Idg(NstrR(cr):NendR(cr)) = S.contact(cr).point.Idg_rho;

Error in contact (line 376)
write_contact(Cname, S, G);
It turned out that the left side has a size of 4372, while the right side has a size of 768. It is interesting that the Irg_rho (receiver grid) has exactly the size of 4372, but the syntax in line 235 assigns a value for the donor grid.
Screenshot 2023-07-10 at 11.30.43.png
This time I was unable to fix the problem....


4. I wondered if my subgrids had some problems, so I set up a similar subgrids case using dogbone_grd_whole.nc. I used grid_extract.m to create a new left subgrid for the dogbone test case. The new two subgrids overlap more than one column, and their boundaries do not "totally overlap":
Screenshot 2023-07-10 at 11.38.30.png
Then I can produce the same error in grid_connections.m:

Code: Select all

 Summary of Contact Regions Processed:
  
   Grid 01: dogbone_grd_left_new.nc
   Grid 02: dogbone_grd_right.nc
  
   Contact   Donor   Receiver
    Region    Grid       Grid
  
Unrecognized field name "contact".

Error in grid_connections (line 635)
  dg = S.contact(cr).donor_grid;
So It seems that to get contact.m run, I have to set up the two subgrids in this way: the two boundaries at the overlap region have to be the same size.
Does anyone have a modified contact.m script that can work for my case? I hope that the ROMS developers could revise grid_connections.m and contact.m, thank you!

Post Reply