ugly piece of code
In Snowpack.cc, L440-446 (function SnowCreep), there is an ugly piece of code:
while (EMS[e].theta[ICE] + EMS[e].theta[WATER] + EMS[e].theta[SOIL] > 0.99) { EMS[e].theta[ICE] *= 0.99; EMS[e].theta[WATER] *= 0.99; EMS[e].M = EMS[e].L0 * ((EMS[e].theta[ICE] * Constants::density_ice) + (EMS[e].theta[WATER] * Constants::density_water)); assert(EMS[e].M>=0.); //mass must be positive }
The problem of this code is:
- it causes a mass balance error
- it is an unnecessary loop (it can be determined beforehand how much mass is in excess in this layer and how much dL should be adjusted or how much mass should be thrown away)
- a much nicer solution is just to limit the maximum possible settling dL, such that there will be always enough room for WATER + ICE + SOIL + extra room when WATER refreezes.