Environmental Modelling:
############################################################## #################
## Soetaert and Meysman ## Ecological Modelling
## Exercise: Algal growth in a bucket
############################################################## ##################
require(deSolve)
#============================================================= ================
# Units used in the program:
#============================================================= ================ # Space = m # Time = day # Mass = mmolN #============================================================= ================ # Model geometry #============================================================= ================ V <- 0.01 # volume system [m3] #============================================================= ================ # Model parameters: #============================================================= ================ # Transport parameters # Not applicable here # Reaction parameters
pMax <- 1.0 # Maximal uptake rate [d-1] kN <- 1.0 # Saturation constant [mmolN m-3] pDIN <- 1
kDIN <- 1 mPHYTO <- 0.5
mBACT <- 0.3 pDET <- 2 kDET <- 1 q <- 0.25
# Assembling the 'parameters' vector parameters <- c(pMax = pMax,
kN = kN, pDIN = pDIN, kDIN = kDIN, mPHYTO=mPHYTO, mBACT= mBACT, pDET = pDET, kDET = kDET, q = q) #============================================================= ================ # Model formulation #============================================================= ================
Batch.model <- function(t, state, parameters) {
with(as.list(c(state, parameters)),{ # PROBLEM-SPECIFIC CODE STARTS HERE # Rate expressions DINuptake <- pMax*DIN/(DIN+kN)*PHYTO phytomort <- mPHYTO*PHYTO DETuptake <- pDET*DET/(DET+kDET)*BACT bactmort <- mBACT*BACT # Balance equations
dPHYTO <- DINuptake - phytomort
dDIN <- - DINuptake + (1-q)*DETuptake dBACT <- (DETuptake*q) - bactmort dDET <- phytomort+bactmort-DETuptake # output variable: total nitrogen TN <- DIN + PHYTO + DET + BACT
# return list
return(list(c(dPHYTO, dDIN, dDET, dBACT), # rate of change, a vector
TotalN = TN ) # output variable )
# PROBLEM-SPECIFIC CODE ENDS HERE })
} # end of model equations
#============================================================= ================
# Model solution: transient
#============================================================= ================ # Initial conditions: PHYTO_0 <- 1 # mmolN/m3 DIN_0 <- 10.0 # mmolN/m3 DET_0 <- 1 BACT_0 <- 1
# Initializing the state variable vector with the initial conditions:
state <- c(PHYTO = PHYTO_0, DIN = DIN_0, DET = DET_0, BACT = BACT_0) # Time sequence: t_start <- 0 # day t_stop <- 40 # day
n_output <- 101 # number of output times
time_seq <- seq(from = t_start, to = t_stop,length = n_output) # Calculation of the transient solution
# The routine 'ode' from the package deSolve is used
out <- ode(y = state, times = time_seq, func = Batch.model, parms = parameters)
head(out)
parameters["mBACT"] <- 0.6
out2 <- ode(y = state, times = time_seq, func = Batch.model, parms = parameters)
tail(out) head(out)
#============================================================= ================
# Plotting model output
#============================================================= ================
#windows()
par(oma = c(0, 0, 3, 0)) # increase outer margin size (oma) plot(out, out2, lwd=2, xlab = "time [days]", ylab =
"concentration [mmolN/m3]") # plot all variables at once mtext(outer = TRUE, side = 3, "BUCKET model", cex = 1.5) Theoretical part:
1. Definition of functional response; what are the three main types (give examples).
2. Definition of forcing function, give examples from class Exercises (paper):
1. Fill in the box of a conceptual model using a scenario. Define the state variables. Write the mass balance and rate expression.
2. Scenario wherein fish population is migrating into an enclosed bay and eaten by killer whales and seals. Write a conceptual model about the carbon transfer. Define the state variables. What are the transport and reaction processes. Write the mass balance and rate expressions.
Tip: Make sure to solve the exercises given in class and understand them, and your good to go! Although the equations are given for the computer exercise, you still have to
memorize them for the paper exercise. Exercise (computer):
Tip: Saving your work from time to time will help (in case of accidental deletion or computer shutdown).