Photosynthesis doesn't initialize all variables needed to be set for nighttime
In #3617 we found that vegwp_ln and vegwp_pd wasn't being set on restart when the restart is at nighttime. There's only a few variables that explicitly get set to zero when it's nighttime in Photosynthesis and more should be added. And we probably want something to make it easy to identify that arrays should be reset to nighttime values when nighttime roles around rather than having to explicitly think about each of them.
I think adding something like a subroutine to do this in the data structures would be good to have:
module PhotosynthesisMod
type, public :: photosyns_type
.
.
.
contains
procedure SetToNighttimeValues
.
.
.
end type photosyns_type
subroutine SetToNitghtimeValues( this,bounds, fn, filterp )
! Set values to what they should be when it's nighttime
.
.
.
do f = 1, fn
p = filterp(f)
do iv = 1, nrad(p)
! When nighttime set everything to the nighttime value
if (par_z(p,iv) <= 0._r8) then
vcmax_z(p,sun,iv) = 0._r8
jmax_z(p,sun,iv) = 0._r8
tpu_z(p,sun,iv) = 0._r8
kp_z(p,sun,iv) = 0._r8
.
.
.
end if
end do
end do
end subroutine SetToNighttimeValues
and then called in CanopyFluxesMod
! -----------------------------------------------------------------
! Time step initialization of photosynthesis variables
! -----------------------------------------------------------------
call photosyns_inst%TimeStepInit(bounds)
call photosyns_inst%SetNithtimeValues(bounds, fn, filterp)
>
> The underlying problem is that the logic in Photosynthesis is complicated enough and often only done during the day, so that even if you have a
>
> ``` fortran
>
> if ( <something> ) then
> <do this>
> else
> <do thiat>
> end if
> ```
>
> Neither branch may get executed, when it's easy to think that the above would cover everything. There are places in Photosynthesis where some variables are explicitly set to zero for nighttime, and this code should have something similar for it. I assume that it should be spval for nighttime? @djk2120 what do you think these should be set to during nighttime?
_Originally posted by @ekluzek in [#3617](https://github.com/ESCOMP/CTSM/issues/3617#issuecomment-3564181852)_
Thoughts on this idea @slevis-lmwg @olyson and @djk2120 ?
temporary fix here is to set these diagnostic variables to inactive. This doesn't seem like a high priority at this point
@ekluzek will contact @djk2120 on this to confirm
A thought (unless we already did this) might be to add a comment in the code near the default "inactive" statements, to warn users that these two fields currently do not restart correctly.