CICE-Consortium / Icepack

Development repository for sea-ice column physics
Other
25 stars 131 forks source link

Update snwgrain implementation to fix bug in snow sublimation #428

Closed apcraig closed 1 year ago

apcraig commented 1 year ago

PR checklist

needed for E3SM, reported by NJ.

apcraig commented 1 year ago

I implemented the allocation checks as deallocates then reallocate. I'm not sure what is going on there. The arrays should never be allocated ahead of time if snw_aging_table='snicar' or 'test'. If snw_aging_table='file', then the user defines those arrays. So, in the former case, the arrays should not be pre allocated and then icepack will allocate and fill them. In the latter, the arrays are allocated and filled by the driver/user and there is no allocation conflict. Maybe we should abort if snw_aging_table='snicar' or 'test' and the arrays are allocated?? Looking for some additional guidance here about why this is happening in E3SM.

njeffery commented 1 year ago

@apcraig : In E3SM, the snow tables read from streams are passed to icepack in icepack_init_parameters and allocated here first (snowage_tau, snowage_kappa, snowage_drdt0). Then init_icepack_snow_tracers is called where snowage_rhos , snowage_Tgrd and snowage_T are allocated and defined. The first three should be queried if (.not.allocated) allocate, but I think you're right about the last three. They should be fine as is.

eclare108213 commented 1 year ago

I think the snow tables are now available internally in Icepack, so MPAS-SI doesn't need to read them from streams.

njeffery commented 1 year ago

It's not as flexible. Does Icepack overwrite the passed fields?

eclare108213 commented 1 year ago

Icepack and CICE have a namelist flag to choose what method to use, snw_aging_table. Icepack itself doesn't read the data (and so snw_aging_table='snicar' is not available in Icepack). CICE uses that option, and so MPAS-SI should be able to also. Maybe the conflict here is only that CICE and MPAS-SI allocate fields in different places, at different times.

@apcraig, looking at the just the documentation, I don't understand the difference between the 'file' and 'snicar' options in CICE (and I don't remember how this worked). https://cice-consortium-cice.readthedocs.io/en/main/user_guide/ug_case_settings.html#snow-nml https://cice-consortium-icepack.readthedocs.io/en/main/user_guide/ug_case_settings.html#snow-nml

apcraig commented 1 year ago

First of all, the documentation on readthedocs is for the current Consortium main. The E3SM Icepack is different. So don't look at the readthedocs for this at the moment.

I had a closer look at the implementation and now understand what is happening. I will update the allocate/deallocate thing. I think Nicole had it right/closer than I did.

This is how it's implemented on the E3SM Icepack. snw_aging_table namelist has 3 possible values, 'snicar', 'test', and 'file'. In Icepack standalone, only 'test' is supported. This fills the 6 snowage arrays with test data internally. When 'file' is set, all 6 snowage fields have to be passed into icepack_parameters. 'snicar' is the weird one. With 'snicar', Icepack expects snowage_tau, kappa, and drdt0 to be passed in, but they are expected to be the "known" snicar ones. It then sets the rhos, Tgrd, and T. I think this is because the snicar dataset doesn't define the latter 3 fields in the file, they are just "known". And so we let Icepack define those. It would be better if there were a snicar input file that included the values of rhos, Tgrd, T and then the user would specify 'file'. So the problem really is the snicar setting. And that also comes down to whether you call icepack_init_snow before or after icepack_init_parameters with the snowage data passed in. Again, all this was done based on the snicar file that we had access to.

So let me refactor that a bit more, I now understand why E3SM is having problems with that allocate, it must call icepack_init_parameters before icepack_init_snow. I'll have an update soon.

apcraig commented 1 year ago

I updated the allocation checks, think I have it OK now. I pushed the changes and am rerunning the test suites, don't expect any problems with testing but will report them when done.

apcraig commented 1 year ago

Full test suites with Icepack and CICE all still good on cheyenne with latest update. This is ready for review and merge.

apcraig commented 1 year ago

Thanks for testing @njeffery.