traitecoevo / plant

Trait-Driven Models of Ecology and Evolution :evergreen_tree:
https://traitecoevo.github.io/plant
53 stars 20 forks source link

Move `compute_assimilation` into FF16 Strategy as a lambda #339

Closed aornugent closed 2 years ago

aornugent commented 2 years ago

Draft of changes to modularise how assimilation is calculated. Where previously the per-leaf photosynthetic canopy was hard-coded, it now resides in FF16_Strategy::compute_assimilation which is passed to assimilation::assimilate for integration along the distribution of canopy openness during calculation of net_mass_production_dt.

I've left the leaf level approximation in assimilation for now, which can be accessed from the assimilator object -

// ff16_strategy.cpp
double FF16_Strategy::compute_assimilation(double z, double height,
                                     const FF16_Environment& environment) {
  return assimilator.assimilation_leaf(environment.get_environment_at_height(z)) * assimilator.q(z, height);
}

When FF16w comes online, we can substitute in a new method while also reusing q to access information about the distribution of leaf area -

// ff16w_strategy.cpp
double FF16w_Strategy::compute_assimilation(double z, double height,
                                     const FF16_Environment& environment) {
  // something like..
  return leaf::assimilation(environment.get_environment_at_height(z)) * assimilator.q(z, height);
}

The only requirements are to return a double and scale the result by area_leaf:

// assimilation.h
double assimilate(std::function<double(double)> f, ...) {
    ...
    return area_leaf * A;
}

We can modify this last line if additional scaling terms are needed and set them to 1 in FF16 to maintain backwards compatibility.

codecov-commenter commented 2 years ago

Codecov Report

:exclamation: No coverage uploaded for pull request base (develop@27e391c). Click here to learn what that means. The diff coverage is n/a.

@@            Coverage Diff             @@
##             develop     #339   +/-   ##
==========================================
  Coverage           ?   79.63%           
==========================================
  Files              ?       97           
  Lines              ?     8897           
  Branches           ?        0           
==========================================
  Hits               ?     7085           
  Misses             ?     1812           
  Partials           ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 27e391c...c29a177. Read the comment docs.

aornugent commented 2 years ago

Merged and extended in simple_water_model branch.