Skip to content

Conversation

@hdrake
Copy link

@hdrake hdrake commented Aug 15, 2024

For unjustified legacy reasons, these have been bundled together in the past. They are not only bundled together in SIS2 variables, but also in the ice-ocean fluxes passed to the coupler and hence to MOM6.

This commit attempts to address this Issue: #213

However, I currently am getting a SEGFAULT error stating that iobt%seaice_melt has not been allocated memory when I try to do a checksum on it.

(Edit: See compaion PRs NOAA-GFDL/MOM6#710 and NOAA-GFDL/FMScoupler#145)

For unjustified legacy reasons, these have been bundled together in the past.
They are not only bundled together in SIS2 variables, but also in the ice-ocean
fluxes passed to the coupler and hence to MOM6.

This commit attempts to address this Issue: NOAA-GFDL#213

However, I currently am getting a SEGFAULT error stating that `iobt%seaice_melt`
has not been allocated memory when I try to do a checksum on it.
@hdrake hdrake marked this pull request as draft August 15, 2024 00:01
@hdrake hdrake changed the title Attempt at separating sea ice melt/formation from liquid precipitation Separating sea ice melt/formation from liquid precipitation field Aug 15, 2024
@hdrake
Copy link
Author

hdrake commented Aug 15, 2024

This is the line that is currently giving me problems when running:

https://github.com/NOAA-GFDL/MOM6/blob/b3e65c63533bf17ae3dd70243f8827fa277ff386/config_src/drivers/FMS_cap/MOM_surface_forcing_gfdl.F90#L1799

If I remove it, the model runs (I am using the Baltic_OM4_05 configuration for testing, with a diag_table that includes fsitherm from the ocean_model) but then the fsitherm diagnostic stays full of zero and is not being currently overwritten by the coupling with SIS2.

@hdrake
Copy link
Author

hdrake commented Aug 16, 2024

@theresa-morrison pointed out that that I forgot to allocate the new seaice_melt field in the coupler!

After doing so in this PR, my Baltic sea test now works!

Screenshot 2024-08-16 at 4 58 55 PM

This fixes a bug introduced in my previous two commits, in
which I was unintentionally adding IOF%seaice_melt rate on top of the
previous timesteps result, without realizing that it never gets set
back to zero!
@theresa-cordero
Copy link

Is there any reason we would want to be able to save the old method for calculating net_melt = melt+ lprec? Or is prlq (new) + fsitherm = prlq (old) sufficient for recreating old results if needed?

@hdrake
Copy link
Author

hdrake commented Dec 13, 2024

Is there any reason we would want to be able to save the old method for calculating net_melt = melt+ lprec? Or is prlq (new) + fsitherm = prlq (old) sufficient for recreating old results if needed?

I personally think this would be undesirable, as it just propagates something that was already mislabelled and could lead to further misinterpretation.

@Hallberg-NOAA
Copy link
Member

Hallberg-NOAA commented Dec 13, 2024

We always retain the ability to use the old calculations if there is any chance at all that anyone is using them, no matter how ugly the code was.  We can wrap in a runtime BUG flag or an ANSWER_DATE flag, but we do not ever change other people's answers without warning and explicit consent.  Keeping the new method as the only option is only sufficient if it can be configured to be bitwise identical to the old one!

@hdrake
Copy link
Author

hdrake commented Dec 17, 2024

Thanks for clarifying @Hallberg-NOAA. I do think answers will not change in the sense that the sum of the two existing diagnostics, prlq + fsitherm, will be bitwise identical. But for prlq and fsitherm individually the answers will definitely change.

Is this fine or should I add a runtime BUG flag? I assume I can follow the implementation for something like this:

SIS2/src/ice_model.F90

Lines 214 to 223 in 2c49005

if (Ice%sCS%berg_windstress_bug) then
! This code is only required to reproduce an old bug.
i_off = LBOUND(Ice%flux_t,1) - sG%isc
j_off = LBOUND(Ice%flux_t,2) - sG%jsc
!$OMP parallel do default(none) shared(Ice,sG,US,i_off,j_off) private(i2,j2)
do j=sG%jsc,sG%jec ; do i=sG%isc,sG%iec
i2 = i+i_off ; j2 = j+j_off
Ice%sCS%IOF%flux_u_ocn(i,j) = US%kg_m2s_to_RZ_T*US%m_s_to_L_T*Ice%flux_u(i2,j2)
Ice%sCS%IOF%flux_v_ocn(i,j) = US%kg_m2s_to_RZ_T*US%m_s_to_L_T*Ice%flux_v(i2,j2)
enddo ; enddo

if (CS%id_net_melt>0) call post_data(CS%id_net_melt, net_melt, CS%diag)
if (CS%id_CMOR_melt>0) call post_data(CS%id_CMOR_melt, net_melt, CS%diag)
if (CS%id_net_melt>0) call post_data(CS%id_net_melt, IOF%seaice_melt, CS%diag)
if (CS%id_CMOR_melt>0) call post_data(CS%id_CMOR_melt, IOF%seaice_melt, CS%diag)

Choose a reason for hiding this comment

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

to reproduce old answers, I think this should be okay, since IOF%seaice_melt and net_melt are the same. Right?


call disable_SIS_averaging(CS%diag)

! Combine the liquid precipitation with the net melt of ice and snow for

Choose a reason for hiding this comment

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

I think a bug fix flag here will work to get the old diagnostics, but it would be ideal (in my opinion) if there was a way to save sea ice melt and sea ice melt + lprec from the same simulation.

do j=jsc,jec ; do i=isc,iec
CS%water_in_col(i,j) = CS%water_in_col(i,j) - dt * &
( ((FIA%runoff(i,j) + FIA%calving(i,j)) + &
IOF%seaice_melt(i,j) + &
Copy link
Member

@Hallberg-NOAA Hallberg-NOAA Feb 1, 2025

Choose a reason for hiding this comment

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

Please add parentheses to specify the order with which IOF%seaice_melt is added to the other fields so that this diagnostic does not capriciously change with the level of optimization.
My preference would be for IOF%seaice_melt to be added first to IOF%lprec_ocn_top so that the answers more closely resemble what was done previously, but other options could be justified as long as the order of arithmetic is specified unambiguously.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you @Hallberg-NOAA; I've started to make the necessary changes wherever fluxes%lprec shows up.

I am not sure what to do here:
https://github.com/NOAA-GFDL/MOM6/blob/37d1385b2979a453c5b2c24d91bbea7c74c6a82e/src/core/MOM_forcing_type.F90#L2275

Is there any way to separately increment these averages for fluxes%lprec and fluxes%seaice_melt while preserving the overall order of operations?

Copy link
Author

Choose a reason for hiding this comment

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

Similarly, in any if associated(fluxes%lprec) blocks, do I need to separately treat the two cases of if associated(fluxes%seaice_melt)?

Following @Hallberg-NOAA's suggestion (https://github.com/NOAA-GFDL/SIS2/pull/214/files#r1938255222),
I have added parentheses so that `IOF%seaice_melt` is added to `lprec_ocn_top` before it is added to
other contributions, preserving the original order of operations.
hdrake pushed a commit to hdrake/MOM6 that referenced this pull request Apr 1, 2025
Continues to address @Hallberg-NOAA's [concern](NOAA-GFDL/SIS2#214 (comment)) that these diagnostics could change
with the level of compiler optimization by adding parentheses to preserve the order
in which fluxes are added together.

However, there are some locations where I did not see how this was possible, as in
this comment: NOAA-GFDL/SIS2#214 (comment)
@theresa-cordero
Copy link

Henri, we are planning to merge MOM6 and SIS2 in the near future (hopefully by the end of the calendar year at the latest). Combining the two code bases would make merging both this PR and the related MOM6 PR much easier. Would you be willing to wait until the merge happens for these code changes to be accepted?

@hdrake
Copy link
Author

hdrake commented Jul 30, 2025

Oh, that's great. Yes, it would be much easier to reimplement these changes within the same code base.

I figured out how to separate these fields using the sea ice diagnostics offline in the meantime anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants