Skip to content

Commit

Permalink
Polishing Nutrient Intake.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismael-lajaaiti authored and iago-lito committed Jun 27, 2023
1 parent 1163692 commit de2bbcf
Show file tree
Hide file tree
Showing 36 changed files with 1,160 additions and 1,185 deletions.
2 changes: 0 additions & 2 deletions .vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions docs/src/example/paradox_enrichment.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ df = DataFrame(;
# Run simulations: for each carrying capacity we compute the equilibrium biomass.
for K in K_values
environment = Environment(foodweb; K)
params = ModelParameters(foodweb; functional_response, environment)
producer_growth = LogisticGrowth(foodweb; K)
params = ModelParameters(foodweb; functional_response, producer_growth)
B0 = rand(2) # Inital biomass.
solution = simulate(params, B0; tmax, verbose)
extrema = biomass_extrema(solution, "10%")
Expand Down
76 changes: 51 additions & 25 deletions docs/src/man/modelparameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Once the [`FoodWeb`](@ref) is created,
you still have to attribute values to the system parameters.
To navigate easily through the parameters,
they are split in 4 different fields depending on their nature:
they are split into 4 different fields depending on their nature:

- [`BioRates`](@ref) contains species biological rates,
*e.g.* producer intrinsic growth rates
- [`Environment`](@ref) contains environmental variables,
*e.g.* temperature
- [`FunctionalResponse`](@ref) contains functional response parameters,
*e.g.* the hill exponent
- [`producer_growth`](@ref) contains producers growth model parameters,
- [`producer_growth`](@ref) contains producer growth model parameters,
*e.g.* the carrying capacity

All the fields are stored within the same object [`ModelParameters`](@ref).
Expand Down Expand Up @@ -123,34 +123,49 @@ can be given to [`BioRates`](@ref) as seen previously.
biorates = BioRates(foodweb; x = rate) # custom metabolic demand
```

## Producers growth
## Producer growth

Two models are available for producers growth:

- a logistic growth model, used by default and a
- a nutrient intake model.
- a logistic growth model, used by default, and a
- a nutrient intake model.

In both models, the producer biomasses $B_p$ grow following the general equation:

$$
growth = r_i * B_i * G_i
$$

where $r_i$ is producer's $i$ intrinsic growth rate, $B_i$ its biomass and $G_i$ its net growth term. The latter can take different forms depending on the growth model in use.
Where $r_i$ is producer $i$'s intrinsic growth rate, $B_i$ is its biomass
and $G_i$ is its net growth term.
The latter can take different forms depending on the growth model in use.

The model is controlled by the field `producer_growth` in model parameters.
The form of producer growth term is controlled by
the field `producer_growth` in model parameters.

### The logistic model

In the logistic model, $G_i$ takes the general form
In the logistic model, $G_i$ takes the general form:

$$
G_i = 1 - \frac{s}{K_i}
$$

where the numerator $s$ can take the simplest form $s = B_i$ (default) or include a matrix $\alpha$ describing the relative strength of the inter- vs intra-specific competition among producer. In this case, $s = \sum\alpha_{ij}B_j$ The matrix $\alpha$ should have as many rows and columns as there are producers in the food web. When the intra-specific competition is $1$ ($\alpha_{ii} = 1$), then species pairing with values below $1$ ($\alpha_{ij} < 1$) describe something akin to facilitation and values above $1$ ($\alpha_{ij} > 1$) describe a stronger inter-specific competition (that would lead to competitive exclusion in the absence of other processes). Note that when all non diagonal values are set to $0$, then $s = \sum\alpha_{ij}B_j = B_j$ and the two models are equivalent.
Where the numerator $s$ can take the simplest form $s = B_i$ (default),
or include a matrix $a$ describing the relative strength of the inter- vs
intra-specific competition among producers.
In this case, $s = \sum a_{ij}B_j$.

When setting up the simulations, the logistic model is controlled as followed:
The matrix $a$ should have as many rows
and columns as there are producers in the food web.
When the intra-specific competition is $1$ ($a_{ii} = 1$),
then species pairs with values below $1$ ($a_{ij} < 1$) describes something akin to
facilitation and values above $1$ ($a_{ij} > 1$) describe stronger inter-specific
competition (that would lead to competitive exclusion in the absence of other processes).
Note that when all non-diagonal values are set to $0$,
then $s = \sum\alpha_{ij}B_j = B_j$ and the two models are equivalent.

When setting up the simulations, the logistic model is controlled as followed:

```
julia> foodweb = FoodWeb([0 0 0; 0 0 0; 1 1 0])
Expand All @@ -161,10 +176,10 @@ FoodWeb of 3 species:
method: unspecified
species: [s1, s2, s3]
julia> logmod = LogisticGrowth(foodweb) #default behavior
julia> logmod = LogisticGrowth(foodweb) # Default behaviour.
LogisticGrowth:
Kᵢ - carrying capacity: [1.0, 1.0, nothing]
α - competition: (3, 3) sparse matrix
a - competition: (3, 3) sparse matrix
julia> #Note: This is equivalent to ModelParameters(foodweb):
julia> p = ModelParameters(foodweb, producer_growth = logmod)
Expand All @@ -177,34 +192,44 @@ ModelParameters{BioenergeticResponse, LogisticGrowth}:
temperature_response: NoTemperatureResponse
```

which allows to control the value of the carrying capacities and the matrix of competition:
which allows for control over the value of the carrying capacities
and the matrix of competition:

```
julia> logmod = LogisticGrowth(foodweb, K = [10, 5, nothing], αij = 0.8)
LogisticGrowth:
Kᵢ - carrying capacity: [10.0, 5.0, nothing]
α - competition: (3, 3) sparse matrix
a - competition: (3, 3) sparse matrix
```

### The nutrient intake model
### The nutrient intake model

The nutrient intake model is implemented following Brose et al., 2005. In this model, the net growth terms depends on nutrients $l$ concentration ($N_l$) and take the form:
The nutrient intake model is implemented following Brose et al., 2005.
In this model, the net growth terms depends on nutrient $l$'s concentration ($N_l$)
and take the form:

$$
G_i(N) = MIN(\frac{N_l}{K_{li} + N_l}, ...)
$$

where $K_{li}$ describes the species-specific half saturation densities for each nutrient $l$. In the absence of other factors it describes the producers hierarchy of competition (lower values means higher intake efficiency).
where $K_{li}$ describes the species-specific half saturation densities
for each nutrient $l$.
In the absence of other factors it describes the producers hierarchy of competition
(lower values means higher intake efficiency).

The nutrients concentrations are described as:
The nutrients concentrations are described as:

$$
dN_l/dt = D(S_l - N_l)-\sum^n_{i = 1}(C_{li}G_i(N)B_i)
$$

where $D$ is the system turnover (default is 0.25), $S_l$ is nutrient $l$'s supply concentration and $C_{li}$ is the concentration of the nutrients in the producers biomass (the higher it is the most needed the nutrient is for the species growth).
where $D$ is the system turnover (default is 0.25), $S_l$ is
nutrient $l$'s supply concentration and $C_{li}$ is the concentration of
the nutrients in the producers biomass
(the higher it is the more essential the nutrient is for the species growth).

As for the logistic model, the nutrient intake model's behavior is controlled through the use of the `producer_growth` field:
As with the logistic model, the nutrient intake model's behaviour is controlled
through the use of the `producer_growth` field:

```
julia> foodweb = FoodWeb([0 0 0; 0 0 0; 1 1 0])
Expand All @@ -223,7 +248,8 @@ NutrientIntake - 2 nutrients:
Kₗᵢ - half sat. densities: (S, n) matrix
```

By default, the models has 2 nutrients, but has for every other parameters, this can be changed:
By default, the models has 2 nutrients, but as for every other parameters,
this can be changed:

```
julia> ni4 = NutrientIntake(foodweb, n = 4)
Expand All @@ -234,7 +260,7 @@ NutrientIntake - 4 nutrients:
Kₗᵢ - half sat. densities: (S, n) matrix
```

It's then passed to `ModelParameter`:
This is then passed to `ModelParameter`:

```
julia> p = ModelParameters(foodweb, producer_growth = ni2)
Expand All @@ -256,13 +282,13 @@ in which case the parameters take default values.

```@example econetd
foodweb = FoodWeb([0 0 0; 0 0 0; 0 1 0]; Z = 10)
environment = Environment(foodweb)
environment = Environment()
```

By default the temperature is set to 293.15 K.

```@example econetd
environment.K
environment.T
```

However, these default values can be changed
Expand All @@ -271,7 +297,7 @@ For the temperature
you just have to provide the scalar corresponding to the wanted temperature.

```@example econetd
environment = Environment(foodweb; T = 273.15);
environment = Environment(; T = 273.15);
environment.T
```

Expand Down
22 changes: 11 additions & 11 deletions src/EcologicalNetworksDynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ by writing `?<function_name>` in a Julia REPL.
"""
module EcologicalNetworksDynamics

# Dependencies
import DifferentialEquations.Rodas4
import DifferentialEquations.SSRootfind
import DifferentialEquations.Tsit5
Expand All @@ -39,27 +38,22 @@ using Statistics
using Decimals
using SciMLBase

# Convenience aliases.
const Solution = SciMLBase.AbstractODESolution

# Include scripts
include(joinpath(".", "macros.jl"))
include(joinpath(".", "inputs/foodwebs.jl"))
include(joinpath(".", "inputs/nontrophic_interactions.jl"))
include(joinpath(".", "inputs/functional_response.jl"))
include(joinpath(".", "inputs/biological_rates.jl"))
include(joinpath(".", "inputs/environment.jl"))
include(joinpath(".", "inputs/temperature_dependent_rates.jl"))
#include(joinpath(".", "inputs/producer_competition.jl"))
include(joinpath(".", "inputs/nutrient_intake.jl"))
include(joinpath(".", "inputs/producer_growth.jl"))
include(joinpath(".", "model/model_parameters.jl"))
include(joinpath(".", "model/producer_growth.jl"))
include(joinpath(".", "model/set_temperature.jl"))
#include(joinpath(".", "model/productivity.jl"))
include(joinpath(".", "model/consumption.jl"))
include(joinpath(".", "model/metabolic_loss.jl"))
include(joinpath(".", "model/dbdt.jl"))
include(joinpath(".", "model/nutrient_dynamics.jl"))
include(joinpath(".", "model/dudt.jl"))
include(joinpath(".", "model/generate_dbdt.jl"))
include(joinpath(".", "model/simulate.jl"))
include(joinpath(".", "model/effect_nti.jl"))
Expand All @@ -70,7 +64,6 @@ include(joinpath(".", "measures/utils.jl"))
include(joinpath(".", "utils.jl"))
include(joinpath(".", "formatting.jl"))

# Export public functions
export @check_between
export @check_greater_than
export @check_in
Expand Down Expand Up @@ -100,7 +93,6 @@ export DefaultGrowthParams
export DefaultMaxConsumptionParams
export DefaultMetabolismParams
export DefaultMortalityParams
export DefaultNIntakeParams
export draw_asymmetric_links
export draw_symmetric_links
export efficiency
Expand Down Expand Up @@ -129,8 +121,12 @@ export get_parameters
export handling_time
export homogeneous_preference
export interaction_names
export is_boostable
export is_success
export is_terminated
export ispredator
export isprey
export isproducer
export Layer
export LinearResponse
export living_species
Expand All @@ -149,6 +145,8 @@ export NIntakeParams
export nontrophic_adjacency_matrix
export NonTrophicIntensity
export NoTemperatureResponse
export nutrient_indices
export nutrient_richness
export NutrientIntake
export population_stability
export potential_competition_links
Expand All @@ -167,15 +165,17 @@ export shannon_diversity
export simpson
export simulate
export species_cv
export species_indices
export species_persistence
export species_richness
export synchrony
export TemperatureResponse
export top_predators
export total_biomass
export total_richness
export trophic_classes
export trophic_levels
export trophic_structure
export weighted_mean_trophic_level

end
end
34 changes: 10 additions & 24 deletions src/inputs/environment.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
#### Type definition ####
mutable struct Environment
T::Union{Int64,Float64}
T::Float64
end
#### end ####

#### Type display ####
"""
One line Environment display.
"""
function Base.show(io::IO, environment::Environment)
T = environment.T
print(io, "Environment(" * "T=$(T)K)")
print(io, "Environment(T=$(T)K)")
end

"""
Multiline Environment display.
"""
function Base.show(io::IO, ::MIME"text/plain", environment::Environment)

# Display output
println(io, "Environment:")
print(io, " T: $(environment.T) Kelvin")
end
#### end ####

"""
Environment(foodweb, T=293.15)
Environment(; T=293.15)
Create environmental parameters of the system.
Expand All @@ -38,23 +32,15 @@ The environmental parameters are:
# Examples
```jldoctest
julia> foodweb = FoodWeb([0 0 0; 0 0 0; 1 1 0]); # species 1 & 2 producers, 3 consumer
julia> environment = Environment(foodweb) # default behaviour
Environment:
T: 293.15 Kelvin
julia> e = Environment() # Default behaviour.
e.T == 293.15 # Kelvin
true
julia> Environment(foodweb; T = 300.15).T # change temperature
Environment:
T: 300.15 Kelvin
julia> e = Environment(; T = 300.0)
e.T == 300.0
true
```
See also [`ModelParameters`](@ref).
"""
function Environment(
net::EcologicalNetwork;
T::Real = 293.15,
) where {Tp<:Real}
Environment(T)
end
Environment(; T = 293.15) = Environment(T)
Loading

0 comments on commit de2bbcf

Please sign in to comment.