Skip to content

Remove or reduce duplication in Photosynthesis code for Plant Hydraulic Stress #139

@ekluzek

Description

@ekluzek

Erik Kluzek < erik > - 2016-06-24 14:09:30 -0600
Bugzilla Id: 2323
Bugzilla CC: andre, dlawren, oleson, rfisher, sacks,

clm4_5_8_r182 brings in plant hydraulic stress (PHS) as an option to the code. The older version needs to stay in place as well to support clm4_5 answers. The new option is brought in largely by duplicating the code in PhotosynthesisMod.F90 for PHS. Almost all subroutines have a PHS version and a non-PHS version. The effects of at least six namelist control items is also reproduced: lnc_opt, reduce_dayl_factor, vcmax_opt, leafresp_method, leafacc, and light_inhibit. Thus any testing for these control items must be duplicated for both PHS on and off. And the size of the file more than doubled from 2k to 2.5k.

This duplication leads to double maintenance of code where changes in the PHS section of the code has to be duplicated in the non-PHS section of the code. It also leads to bugs where a change is made on one side and not the other.

Because, there is so much code duplication this can be managed better by breaking it up into smaller segments that can be called by both PHS and non-PHS versions. The top section of Photosynthesis is almost identically duplicated in PhotosyntesisHydraulicStress until the loop through canopy layers above snow. The sections after that are also duplicated with the PHS setting both sun and shade. I think the duplication can be removed if it's broken up into three parts by three loops -- calculate_respiration loop, leaf-level-photosynthesis-and-stomotal-conductance, and canopy-photosynthesis-and-stomotal-conductance. The second section includes the call to hybrid or hybrid_PHS.

Other ways of handling the duplication are to set magic numbers in one place as parameters in the code, and to break up the namelist control items into small subroutines/functions that can be called in either branch. Thus these control items are tested whether called from the PHS branch or the non-PHS branch. At least some of these methods should be used to reduce the code duplication.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code healthimproving internal code structure to make easier to maintain (sustainability)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions