0.18.0 - Major internal refactor of NutrientsPlanktonDetritus abstraction + adds ImplicitProductivity plankton#378
Conversation
plankton|
@johnryantaylor this PR maintains almost all existing functionality, except variable C:N detritus. I'm still thinking about the best way to abstract this and as its our only thing that has variable elemental ratios I think its worth considering how best to do it for e.g. when we implement MARBL plankton. I also think that once we have devised this interface, it would be straight forward to have one of the "elements" of the large particles be calcite (or multiple calcium carbonate species/different precipitation methods), because |
227b46b to
3aca35b
Compare
|
@johnryantaylor @nanophyto @lgloege Something I've been thinking about is where to land on the balance of code complexity vs writing out similar things for different situations. As an example I implemented I think in this case it is probably still clear enough to land on the right side of the complexity/obfuscation balance, but I've been trying to work out how to extend this for variable elemental ratio detritus and I'm not sure if it becomes too difficult to understand the code? It gets relatively confusing because if we explicitly have the default plankton element represented (e.g. nitrogen or phosphate) only, then we have to assume that the particulates contain carbon and calcite in the same ratio as the plankton (and that the zooplankton are the same as the phytoplankton), but if we explicitly represent carbon then we can associate that calcite with the POC groups so the zooplankton doesn't have to have calcite associated with it (in LOBSTER grazing leads to some dissolution and some PIC production accounting for all the calcite in the phytoplankton). But we could also have explicit calcite groups which means the POC group now only has the organic carbon. This can be even more complicated if we then want multiple DIC/Alk because we have to have different PIC groups then because they'll dissolve differently. (Having different DIC/Alk replicates could actually mean you need to have replicates of the plankton in some models, for example PISCES has the rain ratio in the phytoplankton vary depending on saturation state. MARBL doesn't do that and only varies rain ratio by other environmental conditions. Perhaps its not a first order effect but in the context of OAE it might actually be something we would want to capture, but would make the modelling significantly harder.) I was wondering what you all thought of where on the code complexity/repetition we should land and if we're going to invest in more complex code that automates model setup how we should allow for future development of new elements e.g. aggregation? Perhaps there is a better abstraction for detritus that could solve some of these problems. @glwagner do you have any thoughts on this too? |
57984bd to
b10cd0f
Compare
I think in general you have to take an empirical approach here... sometimes it can be better to error on the side of clarity (ie duplicating some code) at first, and then eliminate duplications if maintenance becomes hard, later. Would it help if you develop an interface for the "tracer name type" in Oceananigans? It seems like at least some of the difficulty comes from the fact that you need to dispatch on I noticed that you have functions like dissolved_waste(bgc.plankton, bgc, i, j, k, fields, auxiliary_fields)I recommend always using the "kernel form" |
made edible_particulate_organic_matter more generic by removing hardcoding of sPOM name.
| PN = phosphate_ratio(i, j, k, grid, bgc.plankton, bgc, fields) / nitrogen_ratio(i, j, k, grid, bgc.plankton, bgc, fields) | ||
|
|
||
| return ( | ||
| nitrate_primary_production(i, j, k, grid, bgc.plankton, bgc, clock, fields, auxiliary_fields) * (1 - PN) |
There was a problem hiding this comment.
Should there be a - sign in front of this line? uptake of nitrate should increase the alkalinity. In the nitrate_primary_production function, nutrient_uptake is negative. Hence, without a minus sign here, it looks like nitrate uptake is reducing alkalinity instead of increasing it.
There was a problem hiding this comment.
I think this is correct: #365 (comment)
There was a problem hiding this comment.
what about the minus sign here on line 17 of defaults.jl:
- nutrient_uptake(i, j, k, grid, bgc.plankton, bgc, fields, auxiliary_fields)
I was concerned that nitrate uptake is decreasing alkalinity.
There was a problem hiding this comment.
Oh I understand now, I think I've switched the nitrate and ammonia places
|
Hi @jagoosw, what are we still missing for this PR? Do you want me to work on the docs or an example? |
I'll go through and fix the docs etc in the next few days |
NutrientsPlanktonDetritus abstraction + adds ImplicitProductivity plankton
This PR has turned into a refactor of the NPD module which hopefully aids abstraction. It also adds an
ImplicitProductivityplankton(details below).I will update docs (probably the "Implementing new models page") but this refactor hopefully aids implementing new elements by specifying the basic interfaces between
nutrients,plankton,detritus,inorganic_carbon, andoxygen, but more complex models can still write their own methods up to(bgc::NutrientPlanktonDetritus{FT, <:Nutrients{<:Any, <:MyIronCycle}, <:MyNewPlankton)(i, j, k...).This means that if you want to implement a new thing, for example a plankton, you just define the nutrient usage, elemental ratios, and waste (inorganic, dissolved, solid), and if the new model is not too abnormal it should just work. If you e.g. wanted to have a phytoplankton with variable C:N you would then need to write methods for
inorganic_nitrogen_wasteandinorganic_carbon_wasteetc. but it would still work if you e.g. included phosphate growth limitation with no additional work.The implicit
planktonwhich tracks no tracers but computes a community productivity like this model from MITGCM and ClimaOceanBiogeochemistry.This might be useful as a starting point for global runs so we can see if this simple model replicates other results (vs e.g. not being able to know if biases are from LOBTER or from the circulation, since there are no global LOBSTER solutions).
To do:
Breaking changes:
gridandsurface_PARto be positional arguments of light modelscarbonate_systemtoinorganic_carbonVariableRedfieldDetritusis now calledCarbonNitrogenDissolvedParticulate