Scripts for creating refinement-subclass nested grids using GridBuilder

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
gli353
Posts: 30
Joined: Tue May 14, 2019 1:39 pm
Location: The University of Auckland

Scripts for creating refinement-subclass nested grids using GridBuilder

#1 Unread post by gli353 »

Hi, all,
I wonder if anyone here is also struggling with creating nested grids with GridBuilder. As mentioned in this post viewtopic.php?t=5018 (Floor #22), Charles, the developer of GridBuilder mentioned that the psi points of the outputted subgrids do not align exactly with the coarser grids. At least for my project, where I only need a refinement-subclass nesting, the situation is not very difficult. I could buffer the subgrids with an external layer of cells such that when in GridBuilder the psi points are recalculated upon generating NC files the recalculated psi points will align EXACTLY with the coarser grid. The script BufferedGrids.m does this. At least for the simple refinement-subclass, this scrip can also deal with a small grid that is NOT an exact subgrid of the larger one. A description of the steps for creating these grids is given in README.txt. Pictures of the created grids are attached below.
Another issue: In the MATLAB scripts for pre/postprocessing grids, MATLAB function inpolygon is used to check if points fall on the perimeter of a grid. In the cases with ROUND-OFF errors, inpolygon will say no point falls on the perimeter when we expect otherwise. All these calls to inpolygon are replaced by the inpoly2.m written by Darren Engwirda (the zip file of this function is also provided).

I'm not sure if other people have solved this problem in a more elegant way, but I do hope it can make life easier for those who are struggling with refinement-subclass/telescoped nesting. And I hope this can form a tentative foundation for improving GridBuilder in future versions. Good luck and look forward to your feedback!

Changes to the original code:
1. Changes and Corrections to contact.m:
(1) Now we pass four arguments to the function, the last one being the refinement factors for each grid,
these numbers will be used to fill in some fields of the nc file to tell the code we need the refinement
subclass stuff;
(2) a minor bug is fixed:
In the function refinment (starting from about line 1484), at the end of it the structure R (intermediate
refienment structure) will be set to empty under certain conditions. This part of the code needs to differentiate
between "spherical" and "cartesian" coordinates, since the two require different types of fields in the R
structure. However, in the original code there were not "ifs" to tell them apart. This issue has been fixed.
(P.S. I remember that in a reply by Charles, the developer of GridBuilder, he mentioned a similar bug involving
FCr variable. I have not run into it, just a reminder)
2. grid_connections.m, contact.m etc:
All the inpolygon function calls are replaced by inpoly2 when checking if grid points of the larger grid fall ON
the bndry of smaller grids, so as to AVOID ROUND OFF ERRORS!
3. write_contact.m:
Line 151 to 170: The code checks if the parent_Imin, parent_Imax, etc. fields of the grids structure are consistent
with the variables Imin Imax etc.. However, when we build subgrids in GridBuilder, these fields are left empty.
I commented out this section and made the code fill in the parent_Imin fields etc. using the Imin Imax variables.
Actually, in my BufferedGrid.m script, these Imin Imax stuff have already been calculated, so they could be filled
in (at the start of contact.m) along with the Refinement Factors.
Attachments
NestedGrids_Refinement.zip
(465.58 KiB) Downloaded 420 times

Post Reply