E3SM-Project / E3SM

Energy Exascale Earth System Model source code. NOTE: use "maint" branches for your work. Head of master is not validated.
https://docs.e3sm.org/E3SM
Other
345 stars 352 forks source link

Variable soil depth: Divided by zero bug #2583

Open xuchongang opened 5 years ago

xuchongang commented 5 years ago

When the variable soil depth is set so that interface depth is equal to water depth. Namely, zwtmm(c)=zimm(c,j) in the following line of code: https://github.com/E3SM-Project/E3SM/blob/master/components/clm/src/biogeophys/SoilWaterMovementMod.F90#L494, it became divided by zero.

I will propose the following fix:

delta_z_zwt= zwtmm(c)-zimm(c,j)
if(delta_z_zwt==0._r8) delta_z_zwt= 1 !make a hypothetical thin layer (1 mm)
temp0 = (((sucsat(c,j)+delta_z_zwt)/sucsat(c,j)))**(1._r8-1._r8/bsw(c,j))
vol_eq(c,j+1) = -sucsat(c,j)*watsat(c,j)/(1._r8-1._r8/bsw(c,j))/(delta_z_zwt)*(tempi-temp0)

Let me know your thoughts @bishtgautam

mabrunke commented 5 years ago

@xuchongang, I introduced variable soil thickness into the model. This didn't seem to blow up the model when variable soil thickness was turned on, because the 11th layer is not used when variable soil thickness is turned on. Still, this should be fixed for when the model is run regularly just in case you get the 1 in a million chance of getting zwtmm and zimm exactly the same.

xuchongang commented 5 years ago

@mabrunke , when I set the soil depth to 10meter manually, it gave me this error. If the variabile soil depth does not use the soil layer below, then my fix of avoiding dividing by zero should be OK. @bishtgautam , it would be great if you could confirm.

bishtgautam commented 5 years ago

@xuchongang, I propose an alternate fix:

if (abs(zwtmm(c)-zimm(c,j)) < some_small_threshold) then ! Essentially the diff is zero
   vol_eq(c,j+1) = watsat(c,j) ! The 11-th layer completely saturated
   ! Now compute zq
else
   ! Do the default code
endif

What do you think?

xuchongang commented 5 years ago

@bishtgautam, I will follow your suggestions and make the change