ESCOMP / ESCOMP/CTSM

Photosynthesis doesn't initialize all variables needed to be set for nighttime

Open
#3,620 4 comments 0 reactions 0 assignees View on GitHub
code health enhancement modernization
Dominant language
Fortran
Stars
352
Forks
361
Avg merge
2d 21h
Merged PRs (30d)
7

Description

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:

``` fortran
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

``` fortran

! -----------------------------------------------------------------
! 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 ( ) then
>
> else
>
> 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)_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.