Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dxgrow, dygrow to facilitate variable spaced grid. Modified rec… #746

Merged
merged 14 commits into from
Aug 22, 2022

Conversation

daveh150
Copy link
Contributor

@daveh150 daveh150 commented Aug 2, 2022

…tgrid to generate grid from center outward using growth factor

For detailed information about submitting Pull Requests (PRs) to the CICE-Consortium,
please refer to: https://github.com/CICE-Consortium/About-Us/wiki/Resource-Index#information-for-developers

PR checklist

  • [ x] Short (1 sentence) summary of your PR:
    Add growth factors in x and y direction to facilitate variable spaced grid
  • [ x] Developer(s):
    David Hebert
  • [ x] Suggest PR reviewers from list in the column to the right.
  • Please copy the PR test results link or provide a summary of testing completed below.
    ENTER INFORMATION HERE
  • How much do the PR code changes differ from the unmodified code?
    • bit for bit
    • different at roundoff level
    • more substantial
  • Does this PR create or have dependencies on Icepack or any other models?
    • Yes
    • [x ] No
  • Does this PR add any new test cases?
    • [x ] Yes
    • No
  • Is the documentation being updated? ("Documentation" includes information on the wiki or in the .rst files from doc/source/, which are used to create the online technical docs at https://readthedocs.org/projects/cice-consortium-cice/. A test build of the technical docs will be performed as part of the PR testing.)
    • Yes
    • [ x] No, does the documentation need to be updated at a later time?
      • Yes
      • [ x] No
  • [x ] Please provide any additional information or relevant details below:

Added x and y growth factors to test variable spaced grid. The intent is to grow the grid spacing from center of grid outward. I added a few tests to the gridsys_suite that passed, but can use help with deciding what other tests to setup.

Here is what the HTN and HTE look like for the boxsyme, kmtslands test:
HTE

image

HTN

image

Copy link
Contributor

@apcraig apcraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several thoughts.

I think we also want a flag to turn this on. Setting dxgrow and dygrow = "1.0" and it actually being 1.0_real8 is a little risky. I know 1.0 is likely to turn into 1.0_real8, but I still don't like to think about a regular grid spacing case being roundoff non-regular.

I'm not sure I love setting all work_g1 values to the "center" and then adjusting outwards. I also wonder if there is a way to write a cleaner single loop that doesn't require two identical loops (center out x 2) to initialize things. The loops also impose things on the loop ordering (i/j) that seems complicated.

I also think it would be good to more tightly tie the lon/lat and the dx/dy calculations. For instance, rather than independently computing lon/lat then dx/dy from the namelist parameters, why not compute lon/lat then set dx=lon(i+1)-lon(i), etc. Or compute dx and dy then compute lon/lat from dx and dy. That way we're sure the grid values are self-consistent. With constant spacing, it's not as risky.

Maybe there should be a simple computation of dxrect and dyrect first then lon/lat should be derived from those? Maybe consistency and loops get cleaner?

The definition of dxgrow, dygrow ("growth factor") should be spelled out a little more clearly somewhere. The documentation also needs to be updated, at least to add the new namelist variables to the appropriate sections in the user guide.

@daveh150
Copy link
Contributor Author

daveh150 commented Aug 2, 2022

Thanks @apcraig! I was trying to avoid extra flags and if statements, but good point about roundoff issues. I can add a flag to the namelist to enable grid expansion/telescoping and only do math if the expansion is desired.

For variable dx/dy it probably make sense to define the dx spacing first, then convert from centimeters to radians for the lat/lon arrays. Maybe rearranging that operation in the code will help.

If it is preferred to grow from the bottom left corner, or if growing out from the center really doesn't matter, I can just apply the multiplication from the index (1,1) and not worry about expanding from the center. I'll work on all this next.

@apcraig
Copy link
Contributor

apcraig commented Aug 2, 2022

Thanks @daveh150. I don't have a strong feeling about whether to start in the corner or center. I assumed there was a reason center was chosen, namely to change the gradient over the domain. If you start in a corner, you will probably end up with increasing/decreasing dx/dy over the entire domain. In the center, you have decreasing to increasing (or vv). Think about it a bit, not sure what the best setup is.

@eclare108213
Copy link
Contributor

eclare108213 commented Aug 2, 2022 via email

@apcraig
Copy link
Contributor

apcraig commented Aug 2, 2022

@eclare108213, good point.

@eclare108213
Copy link
Contributor

Simplifying the loops and/or logic would be good, and I agree that multiplying by a factor that might change the results in standard cases should be avoided, if possible. I think it's better to start the calculation from the center so that there's not a big jump in grid size in cyclic configurations (in case someone tries such a test). But if that makes the logic/loops more complicated, then start in the corner and we can add a warning not to run rectgrid tests with cyclic boundaries and variable grid spacing.

Just a hint re the template above: removing the space from between the brackets fixes the check-box formatting, e.g.

  • [x ] versus
  • correct

Alternatively, you can submit the PR with out editing the check-boxes, then click on the ones you want to check off, afterwards in the open PR.

…le_dxdy flag to check of want grid spacing scaled. Renamed dxgrow/dygrow to dxscale/dyscale.
@daveh150
Copy link
Contributor Author

daveh150 commented Aug 3, 2022

Thanks for the feedback and reviews! I added flag scale_dxdy to apply the grid expansion scaling. I also renamed dxgrow/dygrow to dxscale,dyscale.

I reworked the looping so it only loops over half the nx_global/ny_global - 1, then multiplies the scaling factor accordingly. I know it is still a relative complicated loop, but with multiplying by the cell next to it I'm not sure if there is a more elegant way. Any other thoughts are appreciated. I tried to explain what is happening in the comments.

I added a method to check for even/odd in nx_global/ny_global. That affects the center of the domain. But I'm not sure if we would ever use an odd number for a domain size in these tests? If not I can remove that to avoid confusion.

I did a cursory update to the documentation to add the new scaling variables. and a vargrid_test suite, but that needs to be updated to add more cases (I think).

Copy link
Contributor

@apcraig apcraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple comments.

I propose we not include vargrid_suite.ts. It looks like this was for quick testing and debugging, but probably should not be included formally. Those tests already exist in gridsys_suite.

I'm wondering about the hardcoded lonref and latref. Should these be namelists?

@daveh150
Copy link
Contributor Author

I agree making the lonref/latref namelist seems to make sense. They probably should be renamed something like grid_lonref/grid_latref to signify it is for grid generation and not diagnostics or something else.

Also fine to remove the vargrid_suite.ts. I wasn't sure if we wanted the variable spaced test it's own suite or lumped in with the gridsys_suite.ts. I can add a vargrid option to all the the boxsym tests for starters.

@apcraig
Copy link
Contributor

apcraig commented Aug 11, 2022

@daveh150, I think it's fine to add a few more vargrid tests to the existing test suites, but we probably don't need more than a handful of tests total to provide reasonable test coverage. We just want to test the feature, not necessarily all uses. I also think we should get rid of vargrid_suite.ts. That kind of suite is what I often create for development, as needed. But we don't need to check all those in.

Lets also add lon/lat rect grid reference point to the namelist. The default should be whatever is hardwired into the code right now (Barrow?). I would call the variables lonrefrect, latrefrect which is sort of consistent with dxrect and dyrect. But open to other ideas. Thanks!

@daveh150
Copy link
Contributor Author

I just ran a full gridsys_test and have 3 test fails. remarkably, they are not the ones with a variable grid test, but they are gridcd tests. Do these normally fail?

[hebert@boulder:daveh150/testsuite.lonlatref]$ more fails.ts

Test Grid PEs Sets

smoke gbox80 2x2 boxwallblock,gridcd
smoke gbox80 4x1 boxsyme,gridcd,kmtislands,run1day
smoke gbox80 4x2 boxislandse,gridcd,run1day

…te.ts. Updated the box nml to specify the default grid_lonref and grid_latref for future reference.
@daveh150
Copy link
Contributor Author

@apcraig All sounds good. I removed the vargrid_suite.ts and made grid_lonref, grid_latref namelist variables. I just pushed that for review. This had those three gridcd failures I don't understand. Depending on the test they are failing with

(abort_ice) error = (ice_write_hist)ERROR: writing variable vvelE
(abort_ice) error = (ice_write_hist)ERROR: writing variable uvelE

@apcraig
Copy link
Contributor

apcraig commented Aug 11, 2022

Thanks @daveh150 for the most recent changes. Could we change grid_lonref and grid_latref to lonrefrect and latrefrect. I think it's important to have "rect" in the name. Also, I don't think we need so many vargrid tests. I would have 2 or 3 for each grid type (B, C, CD). Please pick a subset of the tests you've added and remove the rest.

Some of the gridcd tests do fail on some machines. I have not looked closely at that right now. It may also depend what values uninitialized arrays are taking on. I actually think we need to reduce our gridcd testing at this point. I can also run the gridsys_suite on cheyenne once your branch is ready to make sure nothing new is broken. Did you run a baseline suite prior to your changes to check that you're not changing answers and to check that no new tests are failing? You might want to create a sandbox with the unmodified code and create baseline results, then use --bcmp to make sure answers are the same and nothing new is failing.

@daveh150
Copy link
Contributor Author

Done, Renamed grid_lonref/grid_latref to lonrefrect/latrefrect. Also kept only the 3 directional tests without islands in the gridsys_suite.ts. The others are commented out.

@daveh150
Copy link
Contributor Author

P.S. Sorry I forgot to change my calendar and missed the meeting today. :-(

@apcraig
Copy link
Contributor

apcraig commented Aug 12, 2022

Thanks @daveh150, this looks good. Just for sanity, I'll run a test suite on cheyenne with these changes. If all OK, we can merge today.

@apcraig
Copy link
Contributor

apcraig commented Aug 12, 2022

The test suite indicates that a number of test fail regression. Looks like answers changed for all these cases,

FAIL cheyenne_intel_restart_gbox128_4x2_short complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_restart_gbox128_4x2_short compare cice.5a1701c005.220806-085010 27.71 9.67 13.20 different-data
FAIL cheyenne_intel_restart_gbox128_2x2_boxadv_short complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_restart_gbox128_2x2_boxadv_short compare cice.5a1701c005.220806-085010 88.19 70.45 13.14 different-data
FAIL cheyenne_intel_smoke_gbox128_2x2_boxadv_debug_short complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_2x2_boxadv_debug_short compare cice.5a1701c005.220806-085010 197.27 169.86 15.83 different-data
FAIL cheyenne_intel_restart_gbox128_4x4_boxrestore_short complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_restart_gbox128_4x4_boxrestore_short compare cice.5a1701c005.220806-085010 19.73 12.16 4.05 different-data
FAIL cheyenne_intel_smoke_gbox128_4x4_boxrestore_debug_short complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_4x4_boxrestore_debug_short compare cice.5a1701c005.220806-085010 80.07 67.37 5.20 different-data
FAIL cheyenne_intel_restart_gbox180_16x1x6x6x60_debugblocks_dspacecurve complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_restart_gbox180_16x1x6x6x60_debugblocks_dspacecurve compare cice.5a1701c005.220806-085010 35.87 12.82 13.61 different-data
FAIL cheyenne_intel_smoke_gbox180_16x1x6x6x60_debug_debugblocks_dspacecurve_run2day complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox180_16x1x6x6x60_debug_debugblocks_dspacecurve_run2day compare cice.5a1701c005.220806-085010 207.30 133.57 45.49 different-data
FAIL cheyenne_intel_smoke_gbox128_8x2_reprosum_run10day complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x2_reprosum_run10day compare cice.5a1701c005.220806-085010 31.28 11.10 13.64 different-data
FAIL cheyenne_intel_smoke_gbox128_9x2_boxadv_reprosum_run10day complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_9x2_boxadv_reprosum_run10day compare cice.5a1701c005.220806-085010 51.63 41.15 6.99 different-data
FAIL cheyenne_intel_smoke_gbox128_14x2_boxrestore_reprosum_run10day complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_14x2_boxrestore_reprosum_run10day compare cice.5a1701c005.220806-085010 25.85 16.40 5.32 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_cmplogrest_reprosum_run10day_thread complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_cmplogrest_reprosum_run10day_thread compare cice.5a1701c005.220806-085010 53.09 18.36 25.79 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_boxadv_cmplogrest_reprosum_run10day_thread complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_boxadv_cmplogrest_reprosum_run10day_thread compare cice.5a1701c005.220806-085010 81.01 62.78 13.56 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_boxrestore_cmplogrest_reprosum_run10day_thread complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_boxrestore_cmplogrest_reprosum_run10day_thread compare cice.5a1701c005.220806-085010 59.75 36.52 14.34 different-data
FAIL cheyenne_intel_smoke_gbox128_8x2_gridc_reprosum_run10day complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x2_gridc_reprosum_run10day compare cice.5a1701c005.220806-085010 36.22 16.04 13.60 different-data
FAIL cheyenne_intel_smoke_gbox128_14x2_boxrestore_gridc_reprosum_run10day complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_14x2_boxrestore_gridc_reprosum_run10day compare cice.5a1701c005.220806-085010 36.32 26.74 5.37 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_cmplogrest_gridc_reprosum_run10day_thread complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_cmplogrest_gridc_reprosum_run10day_thread compare cice.5a1701c005.220806-085010 53.98 18.98 25.99 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_boxrestore_cmplogrest_gridc_reprosum_run10day_thread complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_boxrestore_cmplogrest_gridc_reprosum_run10day_thread compare cice.5a1701c005.220806-085010 61.16 37.78 14.38 different-data
FAIL cheyenne_intel_smoke_gbox128_8x2_gridcd_reprosum_run10day complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x2_gridcd_reprosum_run10day compare cice.5a1701c005.220806-085010 43.08 23.37 13.48 different-data
FAIL cheyenne_intel_smoke_gbox128_14x2_boxrestore_gridcd_reprosum_run10day complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_14x2_boxrestore_gridcd_reprosum_run10day compare cice.5a1701c005.220806-085010 46.36 36.93 5.35 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_cmplogrest_gridcd_reprosum_run10day_thread complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_cmplogrest_gridcd_reprosum_run10day_thread compare cice.5a1701c005.220806-085010 65.26 30.14 26.10 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_boxrestore_cmplogrest_gridcd_reprosum_run10day_thread complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_smoke_gbox128_8x1_boxrestore_cmplogrest_gridcd_reprosum_run10day_thread compare cice.5a1701c005.220806-085010 83.37 60.26 14.24 different-data
FAIL cheyenne_intel_restart_gbox128_8x1_diag1 complog cice.5a1701c005.220806-085010 different-data
FAIL cheyenne_intel_restart_gbox128_8x1_diag1 compare cice.5a1701c005.220806-085010 26.29 8.93 12.70 different-data

I think a goal was to make sure the answers did not change. Looking at diff from output, the first changes are in the lon/lat diagnostics,

<  min/max ULON:  -156.500000000000       -122.230467826556     
---
>  min/max ULON:  -156.500000000000       -122.230467826554     
547c547
<  min/max TLON:  -156.365080581994        57.6346127554386     
---
>  min/max TLON:  -156.365080581994        57.6346127554403     
550c550
<  min/max NLON:  -156.365080581994        57.6346127554386     
---
>  min/max NLON:  -156.365080581994        57.6346127554403     
552c552
<  min/max ELON:  -156.500000000000        57.4996933374329     
---
>  min/max ELON:  -156.500000000000        57.4996933374346     

My guess is that this is an issue of setting

    lonrefrect    = -156.5
    latrefrect    = 71.35

in the namelist. We should probably either remove this and leave it as default (set to double precision in the code) or change it to double precision in the namelist. Let me test this theory and I'll propose some further modifications.

@apcraig
Copy link
Contributor

apcraig commented Aug 12, 2022

Fixing the double precision of the lon/lat refrect did not fix the problem. I still think we need to change to double precision in the ice_in by adding d0 to lon/lat refrect. We should also remove setting lon/lat refrect in the set_nml options where it is the same as the base ice_in, which I think is everywhere.

I think the problem comes down to the numerics of computing the lons/lats in subroutine rectgrid. The old implementation was numerically different in terms of computing dx,dy,lon,lat. At this point, I would have two sections of code. If scale_dxdy is false, do it the old way. If scale_dxdy is true, do it the new way. One could also argue that we should have a requirement that scale_dxdy=true and dxscale=dyscale=1.0d0 should reproduce bit-for-bit the old implementation. And maybe that is a reasonable requirement. The new implementation would probably not meet that requirement.

Anyway, I think we need to do some refactoring after we decide what the requirements are. I like the requirements I propose above, old implementation is bit-for-bit. New var grid is bit-for-bit with old implementation if dxscale=dyscale=1.0d0. I'm open to discussing that second requirement, but we could add a test for it in our test suite quite easily. Happy to discuss these issues. @daveh150, please do regression testing as you move forward if you can. I'm happy to do another set of tests on cheyenne once things are updated too.

@daveh150
Copy link
Contributor Author

Thanks Tony. I can add d0 to the ice_in and remove them from the set_nml. It seems we have a convention of listing EVERY namelist option in ice_in, so adding d0 to those seems to be clearest.

I'll rework the recgrid to keep what was there originally and do something different if scale_dxdy = true.

I'll also see about setting up regression test on our local machines here.

…move explicit latrefrec/lonrefrect from set_nml. Make dxscale,dyscale,latrefrec,lonrefrec double precition in ice_in
@daveh150
Copy link
Contributor Author

Modified ice_in to be double precision for the scale factors. I added a separate subroutine rectgrid_scale_dxdy to apply the scaling if scale_dxdy=true. This is called from within rectgrid if scale_dxdy = true. If scale_dxdy=false it will run the original rectgrid method.

If I did this correctly, I ran a regression by first checking out the main branch then running gridsys_suite.ts with --bgen cice.main option. I then checked out the box_vres branch and ran the same gridys_suite.ts and compared with the --bcmp cice.main.

results are as follows:
#totl = 300 total
#chkd = 300 checked
#pass = 276
#pend = 0
#miss = 18
#fail = 6

Both branches have the same 6 failures due to the gridcd tests

more fail.ts

Test Grid PEs Sets

smoke gbox80 2x2 boxwallblock,gridcd
smoke gbox80 4x1 boxsyme,gridcd,kmtislands,run1day
smoke gbox80 4x2 boxislandse,gridcd,run1day

The 18 missing are the vargrid tests that do not exists in the main branch.

I also added a set_nml.scale1 to apply dxscale,dyscale = 1.d0. But I'm not sure how to apply a regression test if this is applied, since it will be a separate directory. I probably just don't know now to tell the test suite which directories to compare. Is the --bdir is for a testsuite output? Thank you!

@apcraig
Copy link
Contributor

apcraig commented Aug 15, 2022

There are conflicts in this branch. A couple PRs were merged recently, one did a bunch of cleanup. There is a short section in one file that needs to be addressed. I suggest a rebase. Or you can do it on the "Resolve conflicts" button above. If you need help, let me know. Once that's resolved, I'll retest on cheyenne. thanks!

@daveh150
Copy link
Contributor Author

I merged in the updates from main into the box_vres branch. Thanks.

@apcraig
Copy link
Contributor

apcraig commented Aug 17, 2022

I ran a full test suite on cheyenne with 3 compilers and everything looks good. https://github.com/CICE-Consortium/Test-Results/wiki/cice_by_hash_forks#d0d777e03ded31a19e3aea531095a90b0d6697e0

Copy link
Contributor

@apcraig apcraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check documentation. I think some new namelist are missing (lonrefrect, ...?).

@apcraig apcraig self-requested a review August 17, 2022 21:20
@daveh150
Copy link
Contributor Author

Thank you Tony! I added lonrefrec and latrefrect to the documentation. Looks like the other namelist additions are there too.

@apcraig
Copy link
Contributor

apcraig commented Aug 18, 2022

@daveh150, one more thing. The namelist documentation is alphabetical in the tables, could you update the order of the new namelist in ug_case_settings.rst. Otherwise, documentation looks fine. Sorry I didn't notice that before. I think we can then merge. Thanks!

@daveh150
Copy link
Contributor Author

Thank you, I did not notice they were alphabetical order. I put them in alphabetical order and pushed the update. Thanks!

@apcraig apcraig merged commit c87dcd3 into CICE-Consortium:main Aug 22, 2022
dabail10 pushed a commit to ESCOMP/CICE that referenced this pull request Oct 4, 2022
CICE-Consortium#746)

* Added dxgrow, dygrow to facilitate variable spaced grid. Modified rectgrid to generate grid from center outward using growth factor

* Adding vargrid namelist options.

* Refactored rectgrid to compute dx/dy first. Then ULON/ULAT. Added scale_dxdy flag to check of want grid spacing scaled. Renamed dxgrow/dygrow to dxscale/dyscale.

* Added method to check for odd nx_global/ny_global when applying grid spacing scale factors

* Update comments before computing dx/dy

* Update comments when checking for even/odd

* made grid_lonref, grid_latref namelist varaibles. Removed vargrid_suite.ts. Updated the box nml to specify the default grid_lonref and grid_latref for future reference.

* Change grid_lonref/grid_latref to lonrefrect,latrefrect. Reduce default vargrid tests to 3 per B,C,CD grid.

* Make new subroutine rectgrid_scale_dxdy to implemnet grid scaling. Remove explicit latrefrec/lonrefrect from set_nml. Make dxscale,dyscale,latrefrec,lonrefrec double precition in ice_in

* Add set_nml.scale1 to test vargrid with dxscale/dyscale = 1.d0

* Remove lonrefrec/latrefrec from boxnodyn

* Add lonrefrect, latrafrect to documentation

* Inserted new scaled grid varibles in alphabetical order in documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants