CTSM icon indicating copy to clipboard operation
CTSM copied to clipboard

Code is repeated both inside if and in it's else statement

Open ekluzek opened this issue 3 years ago • 3 comments

The calculation of xmf in SoilTemperatureMod has an if statement where the if and else both contain the same expression. Thus the if statement should just be removed.

@mvdebolskiy noticed this.

                     if (j >= 1) then
                        xmf(c) = xmf(c) + hfus*(wice0(c,j)-h2osoi_ice(c,j))/dtime
                     else
                        xmf(c) = xmf(c) + hfus*(wice0(c,j)-h2osoi_ice(c,j))/dtime
                     endif

It looks like this goes back to this commit:

commit 248307d5bd096a23ff6f85efaf255c0254e0e348
Author: Keith Oleson <[email protected]>
Date:   Tue Feb 27 09:25:33 2018 -0700

    Bug fixes for energy imbalance associated with surface water and lakes

Previous to that there was a difference and the else statement included a bit about frac_sno_eff and looked like this...

xmf(c) = xmf(c) + frac_sno_eff(c)*hfus*(wice0(c,j)-h2osoi_ice(c,j))/dtime

From the commit log this difference was causing an energy imbalance.

ekluzek avatar Aug 02 '22 19:08 ekluzek

@olyson and @swensosc does it look correct to you that we should just remove the if and else associated with this statement?

ekluzek avatar Aug 02 '22 19:08 ekluzek

This issue was noticed @mvdebolskiy in #1787. We actually probably shouldn't change this as there does need to be a difference between the statements in #1787.

ekluzek avatar Aug 02 '22 19:08 ekluzek

I think this was associated with Sean's work to reduce our contribution to the energy imbalance in the CESM2 heat budget as shown in the coupler history logs. As is, we could remove the if/else. If you change this statement then we'll need to keep it in mind when we check coupler energy budgets during CESM3 development to make sure we don't introduce an imbalance from the perspective of the coupled system.

olyson avatar Aug 04 '22 14:08 olyson