geco-bern/rsofun

Side-effects (spillover) from one pmodel run to the other

Closed this issue · 2 comments

It appears, that runs of the pmodel (or phydro) model have unwanted side-effects, affecting subsequent runs in the same R session.
This might affect biomee as well. (see #204 (comment))

MWE is in:

# TODO(fabian): These here will fail:
# It appears that upon first run, dpsi and psi_leaf are all zero. However, if we rerun after running mod4, then they are now 0.3463472 and -0.3463472
# mod1_2ndTry <- run_pmodel_f_bysite(
# sitename = df_drivers$sitename[1],
# params_siml = dplyr::mutate(df_drivers$params_siml[[1]], use_phydro = FALSE, use_pml = FALSE, use_gs = FALSE),
# site_info = df_drivers$site_info[[1]],
# forcing = df_drivers$forcing[[1]],
# forcing_acclim = df_drivers$forcing[[1]],
# params_modl = params_modl,
# makecheck = TRUE
# )

Specifically, here we find dpsi and psi_leaf to be zero, when running the pmodel. If we run phydro in between (which supposedly sets dpsi and psi_leaf), and then run again pmodel, we find that dpsi and psi_leaf have constant values referring to the last time step of the phydro simulation.

I think it should now be fixed: da95557
I consider the generalized use of module variables (having a global scope) and saveed variables (implicitly or not) is dangerous (and they make the code impossible to parallelized should that be of interest). In addition, the use of flags (eg. use_phydro) will make the code unmaintainable very soon. Use of object oriented programming supported by Fortran 2003 is highly encouraged.

Thanks Mayeul. Yes this fixed it. The tests from dff710a are now passing on my local machine.