SlideShare a Scribd company logo
1 of 20
Download to read offline
Bond University
Volume 12| Issue 3 | 2021
Simulation of Physical, Chemical, and
Biochemical Environmental Processes with
Spreadsheets and VBA
Selami Demir
Environmental Engineering Department
Yıldız Technical University
seldemir@yildiz.edu.tr
_______________________________________________________________________
Follow this and additional works at: https://sie.scholasticahq.com
This work is licensed under a Creative Commons Attribution-Noncommercial-No
Derivative Works 4.0 Licence.
2
Simulation of Physical, Chemical, and Biochemical
Environmental Processes with Spreadsheets and VBA
Selami Demir
Environmental Engineering Department
Yıldız Technical University
seldemir@yildiz.edu.tr
Abstract
Dynamic simulation of physical, chemical, and biochemical reactions is usually difficult for
environmental engineering students since most of water and wastewater treatment systems rely
on several combinations of these reactions. Besides, the processes are so complex most of the time
that numerical solution of differential equations by simple integration algorithms like Euler’s
method is not a viable option due to large margins of errors propagated. With more sophisticated
algorithms like Runge-Kutta methods, on the other hand, the solution of related ordinary
differential equations becomes a mathematical challenge for students. This paper presents a
simple spreadsheet and programming solution to this mathematical challenge for teaching
simulation of processes.
Keywords: Environmental processes, Modelling, Integration, Spreadsheets, Visual Basic for
Applications
1. Introduction
Spreadsheets are extremely effective tools for performing engineering calculations
and managing numerical tables. Besides, they can be effectively employed for
engineering education. In fact, a great number of papers have been dedicated to the
use of spreadsheet software packages like Microsoft Excel for teaching numerical
methods as well as several other courses in a variety of engineering sub-disciplines [1-
10]. For instance, Manav Demir and Demir [11] and Demir and Manav Demir [12]
employed spreadsheets enhanced with a Visual Basic for Applications (VBA) program
to implement activated sludge modelling tools for teaching purposes in the field of
environmental engineering. Another paper by the authors presents a methodology to
calculate fluid flow in a closed conduit running full using MS Excel and VBA [7].
Niazkar and Afzali [13, 14] offered an MS Excel-based methodology for the analysis of
water distribution networks for teaching purposes. In another study, Demir et al [15]
employed MS Excel and VBA for multivariate nonlinear regression. Other sample
papers including Demir [16] and Demir et al [17-19] show effective uses of
spreadsheets and VBA for both teaching and research purposes.
Simulation of environmental engineering systems that involve physical, chemical,
and biochemical processes is usually a challenge for environmental engineering
students due to the nature of mathematical calculations in the simulation work, which
usually require solving sets of ordinary differential equations (ODEs) in addition to
several other numerical methods. Since the solution of ODEs requires performing
many iterative steps, it is tiring and most of the time it is boring for students in both
3
classes and examinations [20]. Due to the limited classroom and examination hours,
teaching and examining in environmental modelling courses become more difficult
and tedious since the students usually employ hand calculations supported by a
scientific calculator. Further, the simulation results usually involve small to large
margins of errors due mostly to rounding and truncation errors during hand
calculations. Thus, using spreadsheets can be an effective method of delivery of
information without tiring and boring the students with a lot of calculation steps, and
can help students obtain simulation results with smaller margins of errors by
eliminating most of rounding errors.
Coto and Suarez [4] proposed that the students implement Euler’s algorithm on
their own using spreadsheets by typing necessary formulae after discretization of the
differential equations. Although this method offers great advantages for teaching the
solution of simple chemical reaction kinetics, the Euler method, which is a linear
integration method, is usually prone to large errors depending on time step. Also,
Euler’s method can only be used effectively with extremely small time steps for large
and complicated sets of ODEs such as those written for sedimentation [21] and
activated sludge modelling of wastewater treatment plants. Tay et al [20] proposed the
use of fourth-order Runge-Kutta method (RK4) for solving ODEs using spreadsheets
by implementing the integration formulae in spreadsheet cells. For the purpose of
teaching environmental modelling examples, RK4 method is more suitable in that it
provides reliable results even at larger time steps, thus reducing the total number of
steps for a given period of simulation time. Tay et al [20] offered a great method,
however, this method of implementation has its own drawbacks, too, especially in the
simulation of environmental processes, which involves the solution of very
complicated sets of ODEs with very long formulae [12]. Implementing the solution of
these complicated formulae in spreadsheet cells can be as challenging for students as
solving them by hand calculations.
The motivation of this study comes from the search for an effective method of
delivery of information in an environmental modelling course which involves the
solution of ODEs in physical, chemical, and biochemical processes employed in
environmental engineering field. The paper presents a method of teaching
environmental modelling topics using fourth-order Runge-Kutta method on
spreadsheet enhanced with user-defined VBA functions. Although the method
requires students have VBA programming background, it is only on a beginner’s level
and the students can be taught how to implement user-defined functions in VBA
within minutes of a class hour.
2. Methodology
2.1. Formulations
A set of ordinary differential equations can be defined by a set of n functions as
follows:
4
= 𝑓 𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 , 𝑦 , … 𝑦
= 𝑓 𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 , 𝑦 , … 𝑦
⋮
= 𝑓 𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 , 𝑦 , … 𝑦
(1)
where n is the number of state (dependent) variables, m is the number of process
parameters, t is simulation time, [y1, y2, …yn] is the vector of state variables, and [a1, a2,
… am] is the vector of process parameters.
The simulation process starts with known values of state variables usually at time
t = 0 as [y1(0), y2(0), … yn(0)]. The discretization of ODEs is performed, and state
variables can be integrated over a given period of simulation time (tmax) with a specific
time step (Δt) using various methods for numerical integration. The focus of this
paper, the fourth-order Runge-Kutta method, can be employed for the integration as
follows:
𝑦 𝑡 + ∆𝑡 = 𝑦 𝑡 + 𝑘 + 2𝑘 + 2𝑘 + 𝑘
𝑦 𝑡 + ∆𝑡 = 𝑦 𝑡 + 𝑘 + 2𝑘 + 2𝑘 + 𝑘
⋮
𝑦 𝑡 + ∆𝑡 = 𝑦 𝑡 + 𝑘 + 2𝑘 + 2𝑘 + 𝑘
(2)
where ki1, ki2, ki3, and ki4 for i = 1, 2, … n are the integration parameters for each state
variable and must be calculated in each time step of the simulation period. The
integration parameters are calculated as follows:
𝑘 = ∆𝑡𝑓 𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 , … 𝑦
𝑘 = ∆𝑡𝑓 𝑡 + ∆𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 + 𝑘 , … 𝑦
𝑘 = ∆𝑡𝑓 𝑡 + ∆𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 + 𝑘 , … 𝑦
𝑘 = ∆𝑡𝑓 𝑡 + ∆𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 + 𝑘 , … 𝑦
i = 1, 2, …n (3)
The integration parameters are calculated separately for each state variable. For
the ith state variable, the values of all state variables must be those calculated at time t
([y1(t), y2(t), …yn(t)]) except the ith variable, which must be taken as 𝑦 + 𝑘 , 𝑦 + 𝑘 ,
and 𝑦 + 𝑘 , respectively for calculating ki2, ki3, and ki4 in each step.
2.2. Implementation
Coto and Suarez [4] and Tay et al [20] suggested the integration formulations (Eqn.
2 & 3) be written in spreadsheet cells in separate columns for each state variable.
Although this brings negligible difficulty of implementation of the formulae if Euler’s
method of integration is employed, the method can only be used for simple sets of
ordinary differential equations such as simple chemical reaction kinetics. On the other
hand, implementation of formulae for each state variable requires typing formulae in
5
five cells in five columns if the fourth-order Runge-Kutta method of integration is
employed. Since the RK4 integration formulae are already more complicated than
those in Euler method, the students are expected to experience a higher level of
difficulty in implementation. Although it is still achievable for simple sets of ODEs
within class hours, it will be more difficult to implement more complicated sets of
ODEs. For instance, simulation of an activated sludge system even in its simplest form
as given by Gujer et al [22] requires implementation of 13 ODEs for each process
reactor. For even a very simple system configuration of a pre-denitrification system
(anoxic and aerobic reactors followed by a secondary clarifier), a total of 36 ODEs (13
for anoxic reactor, 13 for aerobic reactor, and 10 for secondary clarifier) must be
implemented, which means a total of 180 formulae in separate columns on the
spreadsheet. This can be very time-consuming and tiring for students. Besides, correct
implementation of these formulae requires much attention during the implementation
process.
The author believes that user-defined VBA functions can also be used for
spreadsheet solution of complicated sets of ODEs. These functions can be used for
implementing RK4 on spreadsheet, which will probably reduce the students’ efforts
by eliminating the need to type the same function in cells over and over again. The
author describes, in this paper, how to employ user-defined VBA functions for solving
ODEs as an enhancement to the method of Tay et al [20]. In this method, the student
needs to write a user-defined VBA function for each state variable and to use that
function to implement the solution to that ODE in spreadsheet, thus, reducing the
effort to type the same function over and over again with various values of state
variables (Eqn. 3) for each ODE.
Today, most new computers come with a licensed or open-source operating
system, and at least a demo version of MS Excel. The student, on the other hand, can
install open-source packages like Apache OpenOffice or LibreOffice, which also
support VBA. The method in this paper requires implementation of a user-defined
VBA function and using it in spreadsheet formulae for solving the respective ODE as
shown in Fig. 1. Please note that Fig. 1 shows the spreadsheet solution to a single ODE,
which can be a simple homework task for teaching how to implement an ODE solver
on spreadsheet with VBA support.
6
Figure 1: Screenshot of a) VBA and b) spreadsheet solution to ODEs
The ordinary differential equation in Fig. 1 is given as follows:
= 𝑎𝑥 𝑦 + 𝑑 (4)
where x is the independent variable, y is the dependent variable, and a, b, c, and d are
numerical parameters that can be assumed to be different for each student. Besides,
the initial value of the dependent variable is also different for each student as y(0) = e.
The method described in this paper involves following steps to implement a
spreadsheet solution to an ordinary differential equation by fourth-order Runge-Kutta
(RK4) method:
1. Open Visual Basic Editor (VBE) by pressing “ALT+F11”, or by a proper method
for the spreadsheet software.
2. Insert a new, standard module to the VBA project. Optionally name the module
with a unique name.
3. Define the parameters related with the problem as VBA constants, i.e. with the
“Const” statement. Optionally, use the “Option Explicit” statement on top of
the module (Fig. 1.b).
4. Implement the ordinary differential equation (Eqn. 4) as a user-defined VBA
function (Fig. 1.b) using the “Function – End Function” block. Optionally, the
function can be implemented with a “Public” statement as “Public Function –
End Function” or a “Private” statement as “Private Function – End Function”.
The name of the function can be any that is different from the names of intrinsic
functions of the spreadsheet and VBA (it’s dydx for the example in Fig. 1). The
implementation involves typing of the mathematical formulation inside the
function block to calculate integration parameters (k1, k2, k3, and k4 as in Eqn. 3).
Optionally, explanations can be inserted in each line of the VBA code after a
separation mark (‘).
5. Switch to spreadsheet view and prepare a calculation table as shown in Fig. 1.a.
The calculation table must include the step size as well as any global
7
parameters for the problem such as the initial values of the dependent
variables. The cell formulae in Fig. 1a are given below:
Cell C2: “=0”
Cell D2: “=B2”
Cell E2: “=dydx(C2;D2)*$B$1”
Cell F2: “=dydx(C2+0.5*$B$1;D2+0.5*E2)*$B$1”
Cell G2: “=dydx(C2+0.5*$B$1;D2+0.5*F2)*$B$1”
Cell H2: “=dydx(C2+$B$1;D2+G2)*$B$1”
Cell C3: “=C2+$B$1”
Cell D3: “=D2+(E2+2*F2+2*G2+H2)/6”
6. The cell range to calculate RK4 integration parameters (the range “E2:H2” in
Fig. 1.a) and the cell range to calculate independent/dependent variables (the
range “C3:D3” in Fig. 1.a) is extended by dragging till the maximum value of
independent variable.
7. Optionally, the columns can be formatted to show a specific number of
significant figures. Also, an optional chart showing the change of the
dependent variable with respect to the independent variable can be added and
formatted. Optionally, the columns containing the integration parameters (the
range “E:H” in Fig. 1.a) can be hidden for a clear, visible solution.
3. Example Problems
3.1. Microbial Growth Process
Environmental engineers encounter the problem of microbial growth usually in
simulation of wastewater treatment plants and watersheds. This problem involves two
ordinary differential equations for microbial concentration and substrate
concentration, which is more than enough to teach the modelling work by spreadsheet
and VBA since it is very suitable for classroom applications.
The microbial growth problem can be formulated by the following two
differentials:
= 𝜇 𝑋 − 𝑘 𝑋 (5.a)
= − 𝜇 𝑋 + 𝑓 𝑘 𝑋 (5.b)
where X is the microbial concentration (g/m³), S is the substrate concentration (g/m³),
μmax is the maximum specific growth rate of microorganisms (g/g.day), KS is the half
saturation constant for microbial growth on substrate (g/m³), kd is the specific decay
rate of microorganisms (g/g.day), yH is the yield coefficient (g/g), and fs is the fraction
of biodegradable organics (substrates) in biomass (dimensionless).
The purpose of the classroom example is to teach students how to implement
solution to a set of ODEs using spreadsheet and user-defined VBA functions within
acceptable time limit. The problem statement, with given initial values of microbial
8
and substrate concentrations in a batch reactor as well as stoichiometric and kinetic
parameters, is “calculate the maximum microbial concentration in the batch reactor”.
The solution to the problem starts with implementing the ODEs as user-defined
VBA functions in Visual Basic Editor, which completes the first four steps of the
solution procedure provided in previous section. A screenshot of the VBA module is
shown in Fig. 2a. The fifth step involves typing the cell formulae to implement a
solution with the given parameters. A screenshot of the spreadsheet solution to the
problem is shown Fig. 2.b and the cell formulae are shown in Table 1. In the sixth step,
the cell formulae need to be extended over a certain range that depends on the
maximum time of simulation. For this purpose, the extension is performed by
dragging the formula over the target range. The formula in cell C3 is extended to
“C3:C2883” by dragging to obtain simulation results until 24 hours with a time step of
30 seconds. Also, the cells D3, E4, and F4 are extended to “D3:D2883”, “E4:E2883”, and
“F4:F2883”, respectively. In order to calculate the integration parameters in each time
step, the cell range “G3:N3” must be extended until “G2882:N2882”.
Figure 2: Solution to microbial growth problem. a) VBA functions, b) spreadsheet view
Table 1: Implementation of spreadsheet solution to microbial growth problem
Cell
reference
Cell formula Remarks
C3 “=0”
D3 “=C3/3600” To calculate simulation time in hours. Extended to D2883
E3 “=B2”
F3 “=B3”
G3 “=dXdt(E3;F3)*$B$1” Extended to G2882
H3 “=dXdt(E3+0.5*G3;F3)*$B$1” Extended to H2882
I3 “=dXdt(E3+0.5*H3;F3)*$B$1” Extended to I2882
9
J3 “=dXdt(E3+I3;F3)*$B$1” Extended to J2882
K3 “=dSdt(F3;E3)*$B$1” Extended to K2882
L3 “=dSdt(F3+0.5*K3;E3)*$B$1” Extended to L2882
M3 “=dSdt(F3+0.5*L3;E3)*$B$1” Extended to M2882
N3 “=dSdt(F3+M3;E3)*$B$1” Extended to N2882
C4 “=C3+B$1” Extended to C2883
E4 “=E3+(G3+2*H3+2*I3+J3)/6” Extended to E2883
F4 “=F3+(K3+2*L3+2*M3+N3)/6” Extended to F2883
The solution to the microbial growth problem with user-defined VBA functions
eliminates the need for implementation of the differentials in Eqn. 5 in cells. Without
VBA functions, the student would need to type the differentials over and over again
in the cell range “G3:N3”, which would be a long and tiring process. Thus, employing
user-defined VBA functions reduces the effort and time that students have to spend
implementing a solution to any set of ODEs. In the example of microbial growth, the
solution is obtained within minutes including the implementation of both VBA
functions and spreadsheet formulae. Further, most environmental processes involve
much more complicated formulations that combine physical, chemical, and
biochemical process equations as in the case of activated sludge modelling. In
addition, most activated sludge systems operate in continuous mode and the
differential equations, therefore, include several other terms for the transport of
pollutants with the bulk flow of liquid. As a result, this approach of spreadsheet
solution enhanced with VBA functions could provide an easy-to-implement method
of solution and could be used in a classroom setting.
For the case of microbial growth example, the students can optionally apply the
last step of the procedure for formatting the cells (as in Fig. 2.b) and preparing charts
on the spreadsheet. Fig. 3 shows the change of microbial and substrate concentrations
in the batch reactor with the initial values and parameters provided in Fig. 2. As
expected, the microbial concentration increases exponentially up to a certain limit
while substrate concentration decreases quickly due to microbial growth. The
maximum microbial concentration in the batch reactor is calculated at around 9.5
hours of simulation as 441 mg/L. The solution to the problem takes less than 10
minutes including both the implementation of VBA functions and spreadsheet
formulae. Without using spreadsheets, it would not be possible to complete this
classroom example within class hours at a time step of 30 seconds. Besides, it would
be extremely tiring and boring for students to take 2880 steps (24 hours at a time step
of 30 s) to perform a 24-hour-simulation. On the other hand, a time step of around 2
hours would be an appropriate value to reduce students’ efforts in hand calculations
(without spreadsheets). In this case, the maximum microbial concentration would be
calculated as 505 mg/L at 12th hour of simulation, which contains a very large margin
of error (around 15%). One can conclude that using spreadsheets enhanced with user-
defined VBA functions reduces student effort to solve the problem drastically, and
10
eliminates most of rounding errors. Besides, enhancing the spreadsheet method of
solution with user-defined VBA functions eliminates the need for typing the
differential equations as cell formulae over and over again, further reducing the time
required for solution.
Figure 3: Calculated concentrations for microbial growth problem a) microbial concentration, b)
substrate concentration
3.2. Activated Sludge Process
This example employs a simplified version of Activated Sludge Model No. 3
(ASM3) by Gujer et al [22] for the purpose of simulating the aerobic phase of a
sequencing batch reactor for biological carbon and nitrogen removal from residential
wastewater. Seven components were included in the simulations along with seven
processes. The components of interest are readily biodegradable substrates (SS, g
COD/m³), ammonia plus ammonium nitrogen (SNH, g N/m³), alkalinity (SNO, mol
HCO₃/m³), slowly biodegradable substrate (XS, g COD/m³), organic material stored by
heterotrophs (XSTO, g COD/m³), heterotrophic biomass (XH, g COD/m³), and
autotrophic biomass (XA, g COD/m³). The processes were hydrolysis of slowly
biodegradable substrates, storage of readily biodegradable substrates by heterotrophs,
use of stored organics for heterotrophic growth, growth and endogenous respiration
of heterotrophs and autotrophs. The dissolved oxygen concentration in the batch
reactor was assumed to be constant at 2 g O2/m³.
Mass balance equations for the model are given as follows:
= 1 − 𝑓 𝑟 − 𝑟 (6.a)
= 𝑖 , − 𝑖 , + 𝑓 𝑖 , 𝑟 + 𝑖 , 𝑟 − 𝑖 , 𝑟 − 𝑟 − 𝑖 , + 𝑟 + 𝑖 , 𝑟 (6.b)
=
, , ,
𝑟 −
,
𝑟 + ,
𝑟 − 𝑟 − ,
+ 𝑟 + ,
𝑟 (6.c)
= −𝑟 (6.d)
= 𝑌 𝑟 − 𝑟 − 𝑟 (6.e)
11
= 𝑟 − 𝑟 (6.f)
= 𝑟 − 𝑟 (6.g)
where 𝑓 is the fraction of inert soluble organic matter from biomass decay
(dimensionless), 𝑖 , , 𝑖 , , and 𝑖 , are nitrogen content of readily biodegradable
substrate, slowly biodegradable substrate and biomass, respectively (g N/g COD), 𝑌
is autotrophic yield (g COD/g N), 𝑌 is heterotrophic yield (g COD/g COD), and 𝑌
is yield of XSTO (g COD/g COD). The rate functions (r1 through r7) are given as follows:
𝑟 = 𝑘
⁄
⁄
𝑋 (7.a)
𝑟 = 𝑘
, ,
𝑋 (7.b)
𝑟 = 𝜇
, , ,
⁄
, ⁄
𝑋 (7.c)
𝑟 = 𝑏
,
𝑋 (7.d)
𝑟 = 𝑏
,
𝑋 (7.e)
𝑟 = 𝜇
, , ,
𝑋 (7.f)
𝑟 = 𝑏
,
𝑋 (7.g)
where kHYD is hydrolysis rate constant (g COD/g COD.sec), KX is hydrolysis saturation
constant (g COD/g COD), kSTOR is storage rate constant (g COD/g COD.sec), KH,O is
heterotrophic saturation constant for SO (g O2/m³), KH,S is heterotrophic saturation
constant for SS (g COD/m³), KH,NH is heterotrophic saturation constant for SNH (g N/m³),
KH,ALK is heterotrophic saturation constant for alkalinity (mol HCO₃/m³), KH,STO is
heterotrophic saturation constant for XSTO (g COD/m³), μH is maximum specific growth
rate of heterotrophs (g COD/g COD.sec), bH is endogenous respiration rate of
heterotrophs (g COD/g COD.sec), bSTO is respiration rate for XSTO (g COD/g COD.sec),
KA,O is autotrophic saturation constant for SO (g O2/m³), KA,NH is autotrophic saturation
constant for SNH (g N/m³), KA,ALK is autotrophic saturation constant for alkalinity (mol
HCO₃-
/m³), μA is maximum specific growth rate of autotrophs (g COD/g COD.sec), and
bA is endogenous respiration rate of autotrophs (g COD/g COD.sec).
The solution to the activated sludge process problem involves the calculation of
component concentrations (SS, SNH, SALK, XA, XH, XS, and XSTO) at a given time step with
the given initial concentrations of the components. The solution starts with
implementing Eqn. 6 and 7 in VBE (Fig. 4.a). The students need to declare the
stoichiometric and kinetic parameters as well as the dissolved oxygen concentration
in the sequencing batch reactor as constants. Then, the mass balance equations (Eqn.
5) are implemented as public VBA functions and the rate expressions (Eqn. 6) are
implemented as private VBA functions. Private VBA functions are not available in MS
Excel spreadsheet, however, mass balance equations are available and they employ
private rate expressions.
12
In step 5 of the solution procedure, the student switches to spreadsheet view and
prepares a calculation table as shown in Fig. 4.b. The initial values of component
concentrations and the time step must be given here. For the solution of the current
example, the time step was 30 seconds with the initial component concentrations as
shown in Fig. 4.b. The simulation time was 4 hours.
Figure 4: Solution to activated sludge process. a) VBA functions, b) spreadsheet view
The first cells to implement on the spreadsheet are those that hold the time data.
These cells are located in D and E columns and have the following formulae:
Cell D2: “=0”
Cell D3: “=D2+$B$1”, extended to D482
Cell E2: “=D2/3600”, extended to E482
Option Explicit
Const S_O = 2 'Dissolved oxygen concentration (g / m3)
'STOICHIOMETRIC PARAMETERS
Const f_SI = 0 '(g COD) / (g COD)
Const i_N_BM = 0.07 '(g N) / (g COD)
Const i_N_XS = 0.04 '(g N) / (g COD)
Const i_N_SS = 0.03 '(g N) / (g COD)
Const Y_A = 0.24 '(g COD) / (g N)
Const Y_H = 0.63 '(g COD) / (g COD)
Const Y_STO = 0.85 '(g COD) / (g COD)
'KINETIC PARAMETERS
Const b_A = 0.00000174 '(g COD) / (g COD.sec)
Const b_H = 0.00000231 '(g COD) / (g COD.sec)
Const b_STO = 0.00000231 '(g COD) / (g COD.sec)
Const k_HYD = 0.0000347 '(g COD) / (g COD.sec)
Const k_STOR = 0.0000579 '(g COD) / (g COD.sec)
Const MHU_A = 0.0000116 '(g COD) / (g COD.sec)
Const MHU_H = 0.0000231 '(g COD) / (g COD.sec)
Const K_A_ALK = 0.5 '(mol HCO3) / m3
Const K_A_NH = 1 '(g N) / m3
Const K_A_O = 0.5 '(g O2) / m3
Const K_H_ALK = 0.1 '(mol HCO3) / m3
Const K_H_NH = 0.01 '(g N) / m3
Const K_H_O = 0.2 '(g O2) / m3
Const K_H_S = 2 '(g COD) / m3
Const K_H_STO = 1 '(g COD) / (g COD)
Const K_X = 1 '(g COD) / (g COD)
'PROCESS RATE EQUATIONS
Private Function R1(X_S, X_H)
R1 = k_HYD * (X_S / X_H) / (K_X + (X_S / X_H)) * X_H
End Function
Private Function R2(S_S, X_H)
R2 = k_STOR * S_O / (K_H_O + S_O) * S_S / (K_H_S + S_S) * X_H
End Function
Private Function R3(S_NH, S_ALK, X_STO, X_H)
R3 = MHU_H * S_O / (K_H_O + S_O) * S_NH / (K_H_NH + S_NH) * _
S_ALK / (K_H_ALK + S_ALK) * (X_STO / X_H) / (K_H_STO + (X_STO / X_H)) * X_H
End Function
Private Function R4(X_H)
R4 = b_H * S_O / (K_H_O + S_O) * X_H
End Function
Private Function R5(X_STO)
R5 = b_STO * S_O / (K_H_O + S_O) * X_STO
End Function
Private Function R6(S_NH, S_ALK, X_A)
R6 = MHU_A * S_O / (K_A_O + S_O) * S_NH / (K_A_NH + S_NH) * _
S_ALK / (K_A_ALK + S_ALK) * X_A
End Function
Private Function R7(X_A)
R7 = b_A * S_O / (K_A_O + S_O) * X_A
End Function
'MASS BALANCE EQUATIONS
Public Function dS_Sdt(S_S, X_S, X_H)
dS_Sdt = (1 - f_SI) * R1(X_S, X_H) - R2(S_S, X_H)
End Function
Public Function dS_NHdt(S_NH, S_S, S_ALK, X_S, X_STO, X_H, X_A)
dS_NHdt = (i_N_XS + (f_SI - 1) * i_N_SS) * R1(X_S, X_H) - _
i_N_SS * R2(S_S, X_H) + i_N_BM * (R4(X_H) - R3(S_NH, S_ALK, X_STO, X_H)) - _
(i_N_BM + 1 / Y_A) * R6(S_NH, S_ALK, X_A) + i_N_BM * R7(X_A)
End Function
Public Function dS_ALKdt(S_ALK, S_S, S_NH, X_S, X_STO, X_H, X_A)
dS_ALKdt = ((i_N_XS + (f_SI - 1) * i_N_SS) / 14) * R1(X_S, X_H) - _
(i_N_SS / 14) * R2(S_S, X_H) + (i_N_BM / 14) * _
(R4(X_H) - R3(S_NH, S_ALK, X_STO, X_H)) - ((i_N_BM + 1 / Y_A) / 14) * _
R6(S_NH, S_ALK, X_A) + (i_N_BM / 14) * R7(X_A)
End Function
Public Function dX_Sdt(X_S, X_H)
dX_Sdt = -R1(X_S, X_H)
End Function
Public Function dX_STOdt(X_STO, S_S, S_NH, S_ALK, X_H)
dX_STOdt = Y_STO * R2(S_S, X_H) - (1 / Y_H) * _
R3(S_NH, S_ALK, X_STO, X_H) - R5(X_STO)
End Function
Public Function dX_Hdt(X_H, S_NH, S_ALK, X_STO)
dX_Hdt = R3(S_NH, S_ALK, X_STO, X_H) - R4(X_H)
End Function
Public Function dX_Adt(X_A, S_NH, S_ALK)
dX_Adt = R6(S_NH, S_ALK, X_A) - R7(X_A)
End Function
a
13
Fourth-order Runge-Kutta formulations as given in Eqn. 2 must be implemented
for each of the component concentrations. For readily biodegradable substrates (SS),
following cell formulae are implemented:
Cell M2: “=dS_Sdt(F2;I2;K2)*$B$1”, extended to M481
Cell N2: “=dS_Sdt(F2+0.5*M2;I2;K2)*$B$1”, extended to N481
Cell O2: “=dS_Sdt(F2+0.5*N2;I2;K2)*$B$1”, extended to O481
Cell P2: “=dS_Sdt(F2+O2;I2;K2)*$B$1”, extended to P481
Cell F2: “=B3”
Cell F3: “=F2+(M2+2*N2+2*O2+P2)/6”, extended to F482
Following cell formulae are implemented to calculate concentration of ammonia
plus ammonium nitrogen (SNH):
Cell Q2: “=dS_NHdt(G2;F2;H2;I2;J2;K2;L2)*$B$1”, extended to Q481
Cell R2: “=dS_NHdt(G2+0.5*Q2; F2;H2;I2;J2;K2;L2)*$B$1”, extended to R481
Cell S2: “=dS_NHdt(G2+0.5*R2;F2;H2;I2;J2;K2;L2)*$B$1”, extended to S481
Cell T2: “=dS_NHdt(G2+S2;F2;H2;I2;J2;K2;L2)*$B$1”, extended to T481
Cell G2: “=B4”
Cell G3: “=G2+(Q2+2*R2+2*S2+T2)/6”, extended to G482
Following cell formulae are implemented to calculate alkalinity (SALK):
Cell U2: “=dS_ALKdt(H2;F2;G2;I2;J2;K2;L2)*$B$1”, extended to U481
Cell V2: “=dS_ALKdt(H2+0.5*U2;F2;G2;I2;J2;K2;L2)*$B$1”, extended to V481
Cell W2: “=dS_ALKdt(H2+0.5*V2;F2;G2;I2;J2;K2;L2)*$B$1”, extended to W481
Cell X2: “=dS_ALKdt(H2+W2;F2;G2;I2;J2;K2;L2)*$B$1”, extended to X481
Cell H2: “=B5”
Cell H3: “=H2+(U2+2*V2+2*W2+X2)/6”, extended to H482
Following cell formulae are implemented to calculate concentration of slowly
biodegradable substrate (XS):
Cell Y2: “=dX_Sdt(I2;K2)*$B$1”, extended to Y481
Cell Z2: “=dX_Sdt(I2+0.5*Y2;K2)*$B$1”, extended to Z481
Cell AA2: “=dX_Sdt(I2+0.5*Z2;K2)*$B$1”, extended to AA481
Cell AB2: “=dX_Sdt(I2+AA2;K2)*$B$1”, extended to AB481
Cell I2: “=B6”
Cell I3: “=I2+(Y2+2*Z2+2*AA2+AB2)/6”, extended to I482
Following cell formulae are implemented to calculate concentration of organic
material stored by heterotrophs (XSTO):
Cell AC2: “=dX_STOdt(J2;F2;G2;H2;K2)*$B$1”, extended to AC481
Cell AD2: “=dX_STOdt(J2+0.5*AC2;F2;G2;H2;K2)*$B$1”, extended to AD481
Cell AE2: “=dX_STOdt(J2+0.5*AD2;F2;G2;H2;K2)*$B$1”, extended to AE481
Cell AF2: “=dX_STOdt(J2+AE2;F2;G2;H2;K2)*$B$1”, extended to AF481
Cell J2: “=B7”
Cell J3: “=J2+(AC2+2*AD2+2*AE2+AF2)/6”, extended to J482
14
Following cell formulae are implemented to calculate concentration of
heterotrophic biomass (XH):
Cell AG2: “=dX_Hdt(K2;G2;H2;J2)*$B$1”, extended to AC481
Cell AH2: “=dX_Hdt(K2+0.5*AG2;G2;H2;J2)*$B$1”, extended to AD481
Cell AI2: “=dX_Hdt(K2+0.5*AH2;G2;H2;J2)*$B$1”, extended to AE481
Cell AJ2: “=dX_Hdt(K2+AI2;G2;H2;J2)*$B$1”, extended to AF481
Cell K2: “=B8”
Cell K3: “=K2+(AG2+2*AH2+2*AI2+AJ2)/6”, extended to K482
Following cell formulae are implemented to calculate concentration of autotrophic
biomass (XA):
Cell AK2: “=dX_Adt(L2;G2;H2)*$B$1”, extended to AK481
Cell AL2: “=dX_Adt(L2+0.5*AK2;G2;H2)*$B$1”, extended to AL481
Cell AM2: “=dX_Adt(L2+0.5*AL2;G2;H2)*$B$1”, extended to AM481
Cell AN2: “=dX_Adt(L2+AM2;G2;H2)*$B$1”, extended to AN481
Cell L2: “=B9”
Cell L3: “=L2+(AK2+2*AL2+2*AM2+AN2)/6”, extended to L482
The spreadsheet solution to the activated sludge problem takes only a few seconds
depending on the computational power. In the final step of spreadsheet
implementation of the solution, the columns M through AN are hidden for a clear look
of the sheet. Finally, several charts are added to monitor the change of component
concentrations with simulation time.
The component concentrations in the sequencing batch reactor are shown in Fig.
5. As expected, readily biodegradable substrates (SS) are stored or metabolized quickly
by heterotrophic bacteria and the concentration diminishes quickly within the first 2
hours of simulation (Fig. 5.a). Since growth rates of autotrophic bacteria are very small
compared to that of heterotrophs, it is also an expected result that ammonia plus
ammonium nitrogen (SNH) decreases at a slower speed (Fig. 5.b). Alkalinity (SALK) of
wastewater decreases slowly as a result of the consumption of ammonia by
autotrophic metabolism and generation of carbon dioxide by heterotrophic
metabolism. Also, results shows that an initial alkalinity of 5 mol HCO₃/m³ during the
aerobic phase of the sequencing batch reactor is more than enough for the process to
continue. The concentration of organic materials stored by heterotrophs (XSTO)
increases rapidly (Fig. 5.c) as the heterotrophic bacteria stores the readily
biodegradable substrate in their cells before metabolizing (Eqn. 6.e). After the readily
biodegradable substrates are depleted (around the second hour), the rate of storage
slows down and the hydrolysis process becomes a limiting factor of the storage of
organic material. The concentration of slowly biodegradable substrates (XS) changes
only under the effect of hydrolysis process (Eqn. 6.a), which is a result of heterotrophic
activity, and the concentration decreases slowly, as expected (Fig. 5.d). Concentrations
of heterotrophic and autotrophic bacteria increases with time (Fig. 5.e and 5.f) under
aerobic conditions with plenty of organic carbon and ammonia within the reactor for
microbial growth. As expected based on their maximum specific growth rates, the rate
15
of change of heterotrophic biomass concentration was much higher than that of
autotrophic biomass.
Figure 5: Calculated component concentrations in activated sludge process. a) Readily biodegradable
substrates, b) ammonia plus ammonium nitrogen, c) organic materials stored by heterotrophs, d) slowly
biodegradable substrates, e) heterotrophic biomass, and f) autotrophic biomass
4. Discussion
Solution for the simulation of environmental processes, which usually involve
complex sets of ordinary differential equations, by spreadsheet and Visual Basic for
Applications was presented in this paper. A simplified procedure was proposed for
the implementation, and the procedure was applied to solve two example problems
that involve biochemical processes with complex formulations. The first example was
16
a simple one with two differentials and relatively short process rate expressions. The
solution to this example problem takes less than 10 minutes including implementation
of user-defined VBA functions and spreadsheet formulae. Compared to the time
required for and the accuracy with hand calculations, the proposed method is
extremely fast and accurate. Without the use of VBA functions, the students would
need to implement Eqn. 5 separately in four cells with modifications (Eqn. 2 and 3) to
calculate RK4 integration parameters, which probably takes much more than 10
minutes and require much attention for correct implementation.
The second example problem was a simplified version of Activated Sludge Model
No. 3 by Gujer et al [22]. The implementation of this problem was challenging while
solution by hand calculations would take days. This example can be solved in a few
hours by implementing user-defined VBA functions and using them in spreadsheet
formulae. The main advantage of the proposed method can be seen in this example.
Without user-defined VBA functions, the students would need to implement all of the
model equations (Eqn. 6 and 7) over and over again with small modifications with
regard to RK4 parameter calculations (Eqn. 2 and 3). For instance, the concentration of
ammonia+ammonium nitrogen (SNH) is calculated in the column G using the RK4
parameters in columns Q through T. Without user-defined VBA functions, the
students would need to implement following cell formulae to calculate SNH:
Cell Q2: “=((i_N_XS–i_N_SS+f_SI*i_N_SS)*k_HYD*(K2/J2)/(K_X+(K2/J2))*J2+
i_N_SS*k_STOR*S_O/(K_H_O+S_O)*F2/(K_H_S+F2)*J2–
i_N_BM*(b_H*S_O/(K_H_O+S_O)*J2–b_STO*S_O/(K_H_O+S_O)*J2)–(
i_N_BM+1/Y_A)*MHU_A*S_O/(K_A_O+S_O)*G2/(K_A_NH+G2)*I2+i_N_BM*b_A*S
_O/(K_A_O+S_O)*I2)*$B$1, extended to Q481
Cell R2: “=((i_N_XS–i_N_SS+f_SI*i_N_SS)*k_HYD*(K2/J2)/(K_X+(K2/J2))*J2+
i_N_SS*k_STOR*S_O/(K_H_O+S_O)*F2/(K_H_S+F2)*J2–
i_N_BM*(b_H*S_O/(K_H_O+S_O)*J2–b_STO*S_O/(K_H_O+S_O)*J2)–(
i_N_BM+1/Y_A)*MHU_A*S_O/(K_A_O+S_O)*(G2+Q2/2)/(K_A_NH+(G2+Q2/2))*I2+i
_N_BM*b_A*S_O/(K_A_O+S_O)*I2)*$B$1, extended to R481
Cell S2: “=((i_N_XS–i_N_SS+f_SI*i_N_SS)*k_HYD*(K2/J2)/(K_X+(K2/J2))*J2+
i_N_SS*k_STOR*S_O/(K_H_O+S_O)*F2/(K_H_S+F2)*J2–
i_N_BM*(b_H*S_O/(K_H_O+S_O)*J2–b_STO*S_O/(K_H_O+S_O)*J2)–(
i_N_BM+1/Y_A)*MHU_A*S_O/(K_A_O+S_O)*(G2+R2/2)/(K_A_NH+(G2+R2/2))*I2+i_
N_BM*b_A*S_O/(K_A_O+S_O)*I2)*$B$1, extended to S481
Cell T2: “=((i_N_XS–i_N_SS+f_SI*i_N_SS)*k_HYD*(K2/J2)/(K_X+(K2/J2))*J2+
i_N_SS*k_STOR*S_O/(K_H_O+S_O)*F2/(K_H_S+F2)*J2–
i_N_BM*(b_H*S_O/(K_H_O+S_O)*J2–b_STO*S_O/(K_H_O+S_O)*J2)–(
i_N_BM+1/Y_A)*MHU_A*S_O/(K_A_O+S_O)*(G2+S2)/(K_A_NH+(G2+S2))*I2+i_N_B
M*b_A*S_O/(K_A_O+S_O)*I2)*$B$1, extended to T481
Cell G2: “=B4”
Cell G3: “=G2+(Q2+2*R2+2*S2+T2)/6”, extended to G482
where values of all stoichiometric and kinetic parameters need to be written in related
named cell ranges, which brings an extra workload to create named ranges on
spreadsheet. The above cell formulae are just for calculating SNH concentrations in the
17
reactor. The calculation of alkalinity requires implementing more complicated cell
formulae. Considering the difficulty of implementing these formulae on spreadsheet
alone, it would not be wise to expect students to complete the task within allowed time
limits. Besides, correct implementation of these formulae would need much more
attention and can take as much time as would by hand calculations. In the case of
employing user-defined VBA functions, the cell formulae are simpler and the
differential equations need to be implemented only once in VBE, reducing student
efforts and solution time.
In order to test the effectiveness of the proposed method, several students were
selected from those who already completed first year courses, i.e. Computer
Programming and Numerical Methods. On the other hand, the students did not
complete the Environmental Modeling course. All of the students were already
familiar with spreadsheet software (Excel) and they had moderate experience with
Excel’s spreadsheet functions as well as implementing formulae in cells. In terms of
programming platform, 33% of all were familiar with Matlab programming with no
experience in VBA programming. The students’ programming experience were 2.83
out of 5, with 1 being no programming background and 5 being an experienced
computer programmer.
All students were given an online seminar on the solution of the example problem
given in Section 2.2 of this paper, including a minor chapter on how to implement
functions in VBA and how to use those custom VBA functions in Excel. They were also
given the formulations pertaining to the microbial growth problem and the activated
sludge process given in Section 3 of this paper. All students were given a day to solve
the problems using Excel and VBA. At the end, they were asked to answer a few
questions. Students reported that they had completed both problems within 3 to 5
hours using Excel and VBA, which was very fast considering their VBA and
environmental modeling experience and that this was the first time the students
encountered problems as complex as the activated sludge process. All of the students
are then asked to score the methodology by comparing the ease of solutions with hand
calculations and Excel spreadsheet calculations in Numerical Methods course. The
score was 5 out of 5 from all students, which show that the students find it very easy
to solve complex sets of ODEs with Excel and VBA.
5. Conclusions
A simple procedure for solving complicated differential equations encountered in
environmental processes, which may involve physical, chemical and biochemical
reactions, is proposed in this study. The procedure involves implementing the
differential equations as user-defined Visual Basic for Applications (VBA) functions
and using these functions for implementing a spreadsheet solution of the problem. The
procedure is applicable in MS Excel and other spreadsheet applications with VBA
support.
The advantage of the proposed method is that it reduces the student effort and
solution time drastically by simplifying the cell formulae that need to be implemented
18
in a great number of spreadsheet columns. Besides, employing user-defined VBA
functions is simpler than implementing the whole formulae in cells with regard to
fourth-order Runge-Kutta (RK4) integration parameters. In light of the discussion
presented, the proposed method can be used confidently for delivering the
information in environmental modelling courses within very short periods of time.
19
References
[1] Rivas, A., Gomez-Acebo, T., and Ramos, J.C. (2006). The application of
spreadsheets to the analysis and optimization of systems and processes in the
teaching of hydraulic and thermal engineering. Computer Applications in
Engineering Education, 14(4), 256-268.
[2] Hosseini, S.M. (2009). Application of spreadsheets in developing flexible
multiple-reach and multiple-branch methods of Muskingum flood routing.
Computer Applications in Engineering Education, 17(4), 448-454.
[3] Fernandez, S., Orosa, J.A., Galan, J.J. (2012). A new methodology to teach
numerical methods with MS Excel. Journal of Maritime Research, 9(2), 29-32.
[4] Coto, B., and Suarez, I. (2017). Euler algorithm to solve reaction kinetic
equations: Mathematical formulation, programming, and applications. Computer
Applications in Engineering Education, 26(1), 29-36.
[5] Sana, A. (2017). Teaching fundamental concepts of coastal engineering using
excel spreadsheet. Computer applications in Engineering Education, 25(2), 304-310.
[6] Demir, S., Duman, S., Manav Demir, N., and Karadeniz, A. (2018). An MS Excel
add-in for calculating Darcy friction factor. Spreadsheets in Education, 10(3), 3.
[7] Demir, S., Karadeniz, A., Manav Demir, N., and Duman, S. (2018). Excel VBA-
based solution to pipe flow measurement problem. Spreadsheets in Education,
10(3), 4.
[8] Demir, S., Manav Demir, N., and Karadeniz, A. (2018). An MS Excel tool for
water distribution network design in environmental engineering education.
Computer Applications in Engineering Education, 26(2), 203-214.
[9] Demir, S., Duman, S., Manav Demir, N., Karadeniz, A., and Lubura E. (2018). An
MS Excel add-in for teaching hydraulics of pipe flow in engineering curricula.
Computer Applications in Engineering Education, 26(3), 449-459.
[10] Rabi, J.A., and Caneppele, F.L. (2018). Numerical methods to Biosystems and
food engineering students: Hands-on practices and cross-disciplinary
integration. Computer Applications in Engineering Education, 26(5), 1120-1133.
[11] Manav Demir, N., and Demir, S. (2017). An MS Excel tool for wastewater
treatment modeling in undergraduate education: Activated Sludge Model No. 1.
Fresenius Environmental Bulletin, 26(12), 7008-7017.
[12] Demir, S., and Manav Demir, N. (2020). Implementation of activated sludge
model no. 3 (ASM3) as an educational tool: bioXL3. Computer Applications in
Engineering Education, DOI: 10.1002/cae.22292.
[13] Niazkar, M., and Afzali S.H. (2017). Analysis of water distribution networks
using MATLAB and Excel spreadsheet: H-based methods. Computer Applications
in Engineering Education, 25(1), 129-141.
20
[14] Niazkar, M., and Afzali, S.H. (2017). Analysis of water distribution networks
using MATLAB and Excel spreadsheet: Q-based methods. Computer Applications
in Engineering Education, 25(2), 277-289.
[15] Demir, S., Karadeniz, A., Civelek Yörüklü, H., and Manav Demir, N. (2017). An
MS Excel tool for parameter estimation by multivariate nonlinear regression in
environmental engineering education. Sigma Journal of Engineering and Natural
Sciences, 35(2), 265-273.
[16] Demir, S. (2018). Evaluation of the suitability of global gradient algorithm and
inverse matrix method for steady-state analysis of water distribution networks
in engineering education. Ömer Halisdemir Üniversitesi Mühendislik Bilimleri
Dergisi, 7(1), 23-33.
[17] Demir, S, Karadeniz, A., and Manav Demir, N. (2016a). Using steepness
coefficient to improve artificial neural network performance for environmental
modelling. Polish Journal of Environmental Studies, 25(4), 1467-1477.
[18] Demir, S, Karadeniz, A., and Manav Demir, N. (2016b). Artificial neural network
simulation of cyclone pressure drop: Selection of the best activation function.
Polish Journal of Environmental Studies, 25(5), 1891-1899.
[19] Demir, S, Manav Demir, N., Karadeniz, A., and Civelek Yörüklü, H. (2018e).
Implementation of an MS Excel tool for backpropagation neural network
algorithm in environmental engineering education. Sigma Journal of Engineering
and Natural Sciences, 36(1) 251-260.
[20] Tay, G.T., Kek, S.L., and Abdul-Kadar, R. (2012). A spreadsheet solution of a
system of ordinary differential equations using the fourth-order Runge-Kutta
method. Spreadsheets in Education, 5(2), 5.
[21] Demir, S. (2020). Solution to secondary sedimentation problem by spreadsheet
and VBA. Spreadsheets in Education, 12(2), 3.
[22] Gujer, W., Henze, M., Mino, T., and van Loosdrecht, M.C.M. (1999). Activated
sludge model no. 3. Water Science and Technology 39(1), 183-193.

More Related Content

Similar to 18964-simulation-of-physical-chemical-and-biochemical-environmental-processes-with-spreadsheets-and-vba.pdf

IRJET- Syllabus and Timetable Generation System
IRJET- Syllabus and Timetable Generation SystemIRJET- Syllabus and Timetable Generation System
IRJET- Syllabus and Timetable Generation SystemIRJET Journal
 
Animation as-the-final-step-in-the-dynamics-experience
Animation as-the-final-step-in-the-dynamics-experienceAnimation as-the-final-step-in-the-dynamics-experience
Animation as-the-final-step-in-the-dynamics-experienceVíctor Quezada
 
A low cost-feedback_control_systems_laboratory_setup_via_arduino_simulink_int...
A low cost-feedback_control_systems_laboratory_setup_via_arduino_simulink_int...A low cost-feedback_control_systems_laboratory_setup_via_arduino_simulink_int...
A low cost-feedback_control_systems_laboratory_setup_via_arduino_simulink_int...DevduttSingh3
 
Master’s theorem Derivative Analysis
Master’s theorem Derivative AnalysisMaster’s theorem Derivative Analysis
Master’s theorem Derivative AnalysisIRJET Journal
 
IRJET- Impact of using e-Textbook for the Teaching of Control Systems Enginee...
IRJET- Impact of using e-Textbook for the Teaching of Control Systems Enginee...IRJET- Impact of using e-Textbook for the Teaching of Control Systems Enginee...
IRJET- Impact of using e-Textbook for the Teaching of Control Systems Enginee...IRJET Journal
 
An Application Of An Optimization Tool To Solve Problems Of Mechanics Of Mate...
An Application Of An Optimization Tool To Solve Problems Of Mechanics Of Mate...An Application Of An Optimization Tool To Solve Problems Of Mechanics Of Mate...
An Application Of An Optimization Tool To Solve Problems Of Mechanics Of Mate...Kelly Lipiec
 
Solution of Ordinary Differential Equation with Initial Condition Using New E...
Solution of Ordinary Differential Equation with Initial Condition Using New E...Solution of Ordinary Differential Equation with Initial Condition Using New E...
Solution of Ordinary Differential Equation with Initial Condition Using New E...IRJET Journal
 
Iterative Determinant Method for Solving Eigenvalue Problems
Iterative Determinant Method for Solving Eigenvalue ProblemsIterative Determinant Method for Solving Eigenvalue Problems
Iterative Determinant Method for Solving Eigenvalue Problemsijceronline
 
Comparison Study of Assessment Results for a Course Offered During and After ...
Comparison Study of Assessment Results for a Course Offered During and After ...Comparison Study of Assessment Results for a Course Offered During and After ...
Comparison Study of Assessment Results for a Course Offered During and After ...IRJET Journal
 
PuShort Term Hydrothermal Scheduling using Evolutionary Programmingblished pa...
PuShort Term Hydrothermal Scheduling using Evolutionary Programmingblished pa...PuShort Term Hydrothermal Scheduling using Evolutionary Programmingblished pa...
PuShort Term Hydrothermal Scheduling using Evolutionary Programmingblished pa...Satyendra Singh
 
International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)inventionjournals
 
Scilab Finite element solver for stationary and incompressible navier-stokes ...
Scilab Finite element solver for stationary and incompressible navier-stokes ...Scilab Finite element solver for stationary and incompressible navier-stokes ...
Scilab Finite element solver for stationary and incompressible navier-stokes ...Scilab
 
A Comprehensive Introduction of the Finite Element Method for Undergraduate C...
A Comprehensive Introduction of the Finite Element Method for Undergraduate C...A Comprehensive Introduction of the Finite Element Method for Undergraduate C...
A Comprehensive Introduction of the Finite Element Method for Undergraduate C...IJERA Editor
 
A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY .docx
 A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY .docx A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY .docx
A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY .docxaryan532920
 
Proposing a scheduling algorithm to balance the time and cost using a genetic...
Proposing a scheduling algorithm to balance the time and cost using a genetic...Proposing a scheduling algorithm to balance the time and cost using a genetic...
Proposing a scheduling algorithm to balance the time and cost using a genetic...Editor IJCATR
 

Similar to 18964-simulation-of-physical-chemical-and-biochemical-environmental-processes-with-spreadsheets-and-vba.pdf (20)

IRJET- Syllabus and Timetable Generation System
IRJET- Syllabus and Timetable Generation SystemIRJET- Syllabus and Timetable Generation System
IRJET- Syllabus and Timetable Generation System
 
Animation as-the-final-step-in-the-dynamics-experience
Animation as-the-final-step-in-the-dynamics-experienceAnimation as-the-final-step-in-the-dynamics-experience
Animation as-the-final-step-in-the-dynamics-experience
 
A low cost-feedback_control_systems_laboratory_setup_via_arduino_simulink_int...
A low cost-feedback_control_systems_laboratory_setup_via_arduino_simulink_int...A low cost-feedback_control_systems_laboratory_setup_via_arduino_simulink_int...
A low cost-feedback_control_systems_laboratory_setup_via_arduino_simulink_int...
 
Master’s theorem Derivative Analysis
Master’s theorem Derivative AnalysisMaster’s theorem Derivative Analysis
Master’s theorem Derivative Analysis
 
IRJET- Impact of using e-Textbook for the Teaching of Control Systems Enginee...
IRJET- Impact of using e-Textbook for the Teaching of Control Systems Enginee...IRJET- Impact of using e-Textbook for the Teaching of Control Systems Enginee...
IRJET- Impact of using e-Textbook for the Teaching of Control Systems Enginee...
 
An Application Of An Optimization Tool To Solve Problems Of Mechanics Of Mate...
An Application Of An Optimization Tool To Solve Problems Of Mechanics Of Mate...An Application Of An Optimization Tool To Solve Problems Of Mechanics Of Mate...
An Application Of An Optimization Tool To Solve Problems Of Mechanics Of Mate...
 
Solution of Ordinary Differential Equation with Initial Condition Using New E...
Solution of Ordinary Differential Equation with Initial Condition Using New E...Solution of Ordinary Differential Equation with Initial Condition Using New E...
Solution of Ordinary Differential Equation with Initial Condition Using New E...
 
Iterative Determinant Method for Solving Eigenvalue Problems
Iterative Determinant Method for Solving Eigenvalue ProblemsIterative Determinant Method for Solving Eigenvalue Problems
Iterative Determinant Method for Solving Eigenvalue Problems
 
Some numerical methods for Schnackenberg model
Some numerical methods for Schnackenberg modelSome numerical methods for Schnackenberg model
Some numerical methods for Schnackenberg model
 
Comparison Study of Assessment Results for a Course Offered During and After ...
Comparison Study of Assessment Results for a Course Offered During and After ...Comparison Study of Assessment Results for a Course Offered During and After ...
Comparison Study of Assessment Results for a Course Offered During and After ...
 
PuShort Term Hydrothermal Scheduling using Evolutionary Programmingblished pa...
PuShort Term Hydrothermal Scheduling using Evolutionary Programmingblished pa...PuShort Term Hydrothermal Scheduling using Evolutionary Programmingblished pa...
PuShort Term Hydrothermal Scheduling using Evolutionary Programmingblished pa...
 
A02610106
A02610106A02610106
A02610106
 
International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)
 
A02610106
A02610106A02610106
A02610106
 
Scilab Finite element solver for stationary and incompressible navier-stokes ...
Scilab Finite element solver for stationary and incompressible navier-stokes ...Scilab Finite element solver for stationary and incompressible navier-stokes ...
Scilab Finite element solver for stationary and incompressible navier-stokes ...
 
Task level energy and performance assurance workload scheduling model in dis...
Task level energy and performance assurance workload  scheduling model in dis...Task level energy and performance assurance workload  scheduling model in dis...
Task level energy and performance assurance workload scheduling model in dis...
 
A Comprehensive Introduction of the Finite Element Method for Undergraduate C...
A Comprehensive Introduction of the Finite Element Method for Undergraduate C...A Comprehensive Introduction of the Finite Element Method for Undergraduate C...
A Comprehensive Introduction of the Finite Element Method for Undergraduate C...
 
C41016023
C41016023C41016023
C41016023
 
A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY .docx
 A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY .docx A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY .docx
A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY .docx
 
Proposing a scheduling algorithm to balance the time and cost using a genetic...
Proposing a scheduling algorithm to balance the time and cost using a genetic...Proposing a scheduling algorithm to balance the time and cost using a genetic...
Proposing a scheduling algorithm to balance the time and cost using a genetic...
 

Recently uploaded

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Recently uploaded (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

18964-simulation-of-physical-chemical-and-biochemical-environmental-processes-with-spreadsheets-and-vba.pdf

  • 1. Bond University Volume 12| Issue 3 | 2021 Simulation of Physical, Chemical, and Biochemical Environmental Processes with Spreadsheets and VBA Selami Demir Environmental Engineering Department Yıldız Technical University seldemir@yildiz.edu.tr _______________________________________________________________________ Follow this and additional works at: https://sie.scholasticahq.com This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 4.0 Licence.
  • 2. 2 Simulation of Physical, Chemical, and Biochemical Environmental Processes with Spreadsheets and VBA Selami Demir Environmental Engineering Department Yıldız Technical University seldemir@yildiz.edu.tr Abstract Dynamic simulation of physical, chemical, and biochemical reactions is usually difficult for environmental engineering students since most of water and wastewater treatment systems rely on several combinations of these reactions. Besides, the processes are so complex most of the time that numerical solution of differential equations by simple integration algorithms like Euler’s method is not a viable option due to large margins of errors propagated. With more sophisticated algorithms like Runge-Kutta methods, on the other hand, the solution of related ordinary differential equations becomes a mathematical challenge for students. This paper presents a simple spreadsheet and programming solution to this mathematical challenge for teaching simulation of processes. Keywords: Environmental processes, Modelling, Integration, Spreadsheets, Visual Basic for Applications 1. Introduction Spreadsheets are extremely effective tools for performing engineering calculations and managing numerical tables. Besides, they can be effectively employed for engineering education. In fact, a great number of papers have been dedicated to the use of spreadsheet software packages like Microsoft Excel for teaching numerical methods as well as several other courses in a variety of engineering sub-disciplines [1- 10]. For instance, Manav Demir and Demir [11] and Demir and Manav Demir [12] employed spreadsheets enhanced with a Visual Basic for Applications (VBA) program to implement activated sludge modelling tools for teaching purposes in the field of environmental engineering. Another paper by the authors presents a methodology to calculate fluid flow in a closed conduit running full using MS Excel and VBA [7]. Niazkar and Afzali [13, 14] offered an MS Excel-based methodology for the analysis of water distribution networks for teaching purposes. In another study, Demir et al [15] employed MS Excel and VBA for multivariate nonlinear regression. Other sample papers including Demir [16] and Demir et al [17-19] show effective uses of spreadsheets and VBA for both teaching and research purposes. Simulation of environmental engineering systems that involve physical, chemical, and biochemical processes is usually a challenge for environmental engineering students due to the nature of mathematical calculations in the simulation work, which usually require solving sets of ordinary differential equations (ODEs) in addition to several other numerical methods. Since the solution of ODEs requires performing many iterative steps, it is tiring and most of the time it is boring for students in both
  • 3. 3 classes and examinations [20]. Due to the limited classroom and examination hours, teaching and examining in environmental modelling courses become more difficult and tedious since the students usually employ hand calculations supported by a scientific calculator. Further, the simulation results usually involve small to large margins of errors due mostly to rounding and truncation errors during hand calculations. Thus, using spreadsheets can be an effective method of delivery of information without tiring and boring the students with a lot of calculation steps, and can help students obtain simulation results with smaller margins of errors by eliminating most of rounding errors. Coto and Suarez [4] proposed that the students implement Euler’s algorithm on their own using spreadsheets by typing necessary formulae after discretization of the differential equations. Although this method offers great advantages for teaching the solution of simple chemical reaction kinetics, the Euler method, which is a linear integration method, is usually prone to large errors depending on time step. Also, Euler’s method can only be used effectively with extremely small time steps for large and complicated sets of ODEs such as those written for sedimentation [21] and activated sludge modelling of wastewater treatment plants. Tay et al [20] proposed the use of fourth-order Runge-Kutta method (RK4) for solving ODEs using spreadsheets by implementing the integration formulae in spreadsheet cells. For the purpose of teaching environmental modelling examples, RK4 method is more suitable in that it provides reliable results even at larger time steps, thus reducing the total number of steps for a given period of simulation time. Tay et al [20] offered a great method, however, this method of implementation has its own drawbacks, too, especially in the simulation of environmental processes, which involves the solution of very complicated sets of ODEs with very long formulae [12]. Implementing the solution of these complicated formulae in spreadsheet cells can be as challenging for students as solving them by hand calculations. The motivation of this study comes from the search for an effective method of delivery of information in an environmental modelling course which involves the solution of ODEs in physical, chemical, and biochemical processes employed in environmental engineering field. The paper presents a method of teaching environmental modelling topics using fourth-order Runge-Kutta method on spreadsheet enhanced with user-defined VBA functions. Although the method requires students have VBA programming background, it is only on a beginner’s level and the students can be taught how to implement user-defined functions in VBA within minutes of a class hour. 2. Methodology 2.1. Formulations A set of ordinary differential equations can be defined by a set of n functions as follows:
  • 4. 4 = 𝑓 𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 , 𝑦 , … 𝑦 = 𝑓 𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 , 𝑦 , … 𝑦 ⋮ = 𝑓 𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 , 𝑦 , … 𝑦 (1) where n is the number of state (dependent) variables, m is the number of process parameters, t is simulation time, [y1, y2, …yn] is the vector of state variables, and [a1, a2, … am] is the vector of process parameters. The simulation process starts with known values of state variables usually at time t = 0 as [y1(0), y2(0), … yn(0)]. The discretization of ODEs is performed, and state variables can be integrated over a given period of simulation time (tmax) with a specific time step (Δt) using various methods for numerical integration. The focus of this paper, the fourth-order Runge-Kutta method, can be employed for the integration as follows: 𝑦 𝑡 + ∆𝑡 = 𝑦 𝑡 + 𝑘 + 2𝑘 + 2𝑘 + 𝑘 𝑦 𝑡 + ∆𝑡 = 𝑦 𝑡 + 𝑘 + 2𝑘 + 2𝑘 + 𝑘 ⋮ 𝑦 𝑡 + ∆𝑡 = 𝑦 𝑡 + 𝑘 + 2𝑘 + 2𝑘 + 𝑘 (2) where ki1, ki2, ki3, and ki4 for i = 1, 2, … n are the integration parameters for each state variable and must be calculated in each time step of the simulation period. The integration parameters are calculated as follows: 𝑘 = ∆𝑡𝑓 𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 , … 𝑦 𝑘 = ∆𝑡𝑓 𝑡 + ∆𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 + 𝑘 , … 𝑦 𝑘 = ∆𝑡𝑓 𝑡 + ∆𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 + 𝑘 , … 𝑦 𝑘 = ∆𝑡𝑓 𝑡 + ∆𝑡, 𝑎 , 𝑎 , … 𝑎 , 𝑦 + 𝑘 , … 𝑦 i = 1, 2, …n (3) The integration parameters are calculated separately for each state variable. For the ith state variable, the values of all state variables must be those calculated at time t ([y1(t), y2(t), …yn(t)]) except the ith variable, which must be taken as 𝑦 + 𝑘 , 𝑦 + 𝑘 , and 𝑦 + 𝑘 , respectively for calculating ki2, ki3, and ki4 in each step. 2.2. Implementation Coto and Suarez [4] and Tay et al [20] suggested the integration formulations (Eqn. 2 & 3) be written in spreadsheet cells in separate columns for each state variable. Although this brings negligible difficulty of implementation of the formulae if Euler’s method of integration is employed, the method can only be used for simple sets of ordinary differential equations such as simple chemical reaction kinetics. On the other hand, implementation of formulae for each state variable requires typing formulae in
  • 5. 5 five cells in five columns if the fourth-order Runge-Kutta method of integration is employed. Since the RK4 integration formulae are already more complicated than those in Euler method, the students are expected to experience a higher level of difficulty in implementation. Although it is still achievable for simple sets of ODEs within class hours, it will be more difficult to implement more complicated sets of ODEs. For instance, simulation of an activated sludge system even in its simplest form as given by Gujer et al [22] requires implementation of 13 ODEs for each process reactor. For even a very simple system configuration of a pre-denitrification system (anoxic and aerobic reactors followed by a secondary clarifier), a total of 36 ODEs (13 for anoxic reactor, 13 for aerobic reactor, and 10 for secondary clarifier) must be implemented, which means a total of 180 formulae in separate columns on the spreadsheet. This can be very time-consuming and tiring for students. Besides, correct implementation of these formulae requires much attention during the implementation process. The author believes that user-defined VBA functions can also be used for spreadsheet solution of complicated sets of ODEs. These functions can be used for implementing RK4 on spreadsheet, which will probably reduce the students’ efforts by eliminating the need to type the same function in cells over and over again. The author describes, in this paper, how to employ user-defined VBA functions for solving ODEs as an enhancement to the method of Tay et al [20]. In this method, the student needs to write a user-defined VBA function for each state variable and to use that function to implement the solution to that ODE in spreadsheet, thus, reducing the effort to type the same function over and over again with various values of state variables (Eqn. 3) for each ODE. Today, most new computers come with a licensed or open-source operating system, and at least a demo version of MS Excel. The student, on the other hand, can install open-source packages like Apache OpenOffice or LibreOffice, which also support VBA. The method in this paper requires implementation of a user-defined VBA function and using it in spreadsheet formulae for solving the respective ODE as shown in Fig. 1. Please note that Fig. 1 shows the spreadsheet solution to a single ODE, which can be a simple homework task for teaching how to implement an ODE solver on spreadsheet with VBA support.
  • 6. 6 Figure 1: Screenshot of a) VBA and b) spreadsheet solution to ODEs The ordinary differential equation in Fig. 1 is given as follows: = 𝑎𝑥 𝑦 + 𝑑 (4) where x is the independent variable, y is the dependent variable, and a, b, c, and d are numerical parameters that can be assumed to be different for each student. Besides, the initial value of the dependent variable is also different for each student as y(0) = e. The method described in this paper involves following steps to implement a spreadsheet solution to an ordinary differential equation by fourth-order Runge-Kutta (RK4) method: 1. Open Visual Basic Editor (VBE) by pressing “ALT+F11”, or by a proper method for the spreadsheet software. 2. Insert a new, standard module to the VBA project. Optionally name the module with a unique name. 3. Define the parameters related with the problem as VBA constants, i.e. with the “Const” statement. Optionally, use the “Option Explicit” statement on top of the module (Fig. 1.b). 4. Implement the ordinary differential equation (Eqn. 4) as a user-defined VBA function (Fig. 1.b) using the “Function – End Function” block. Optionally, the function can be implemented with a “Public” statement as “Public Function – End Function” or a “Private” statement as “Private Function – End Function”. The name of the function can be any that is different from the names of intrinsic functions of the spreadsheet and VBA (it’s dydx for the example in Fig. 1). The implementation involves typing of the mathematical formulation inside the function block to calculate integration parameters (k1, k2, k3, and k4 as in Eqn. 3). Optionally, explanations can be inserted in each line of the VBA code after a separation mark (‘). 5. Switch to spreadsheet view and prepare a calculation table as shown in Fig. 1.a. The calculation table must include the step size as well as any global
  • 7. 7 parameters for the problem such as the initial values of the dependent variables. The cell formulae in Fig. 1a are given below: Cell C2: “=0” Cell D2: “=B2” Cell E2: “=dydx(C2;D2)*$B$1” Cell F2: “=dydx(C2+0.5*$B$1;D2+0.5*E2)*$B$1” Cell G2: “=dydx(C2+0.5*$B$1;D2+0.5*F2)*$B$1” Cell H2: “=dydx(C2+$B$1;D2+G2)*$B$1” Cell C3: “=C2+$B$1” Cell D3: “=D2+(E2+2*F2+2*G2+H2)/6” 6. The cell range to calculate RK4 integration parameters (the range “E2:H2” in Fig. 1.a) and the cell range to calculate independent/dependent variables (the range “C3:D3” in Fig. 1.a) is extended by dragging till the maximum value of independent variable. 7. Optionally, the columns can be formatted to show a specific number of significant figures. Also, an optional chart showing the change of the dependent variable with respect to the independent variable can be added and formatted. Optionally, the columns containing the integration parameters (the range “E:H” in Fig. 1.a) can be hidden for a clear, visible solution. 3. Example Problems 3.1. Microbial Growth Process Environmental engineers encounter the problem of microbial growth usually in simulation of wastewater treatment plants and watersheds. This problem involves two ordinary differential equations for microbial concentration and substrate concentration, which is more than enough to teach the modelling work by spreadsheet and VBA since it is very suitable for classroom applications. The microbial growth problem can be formulated by the following two differentials: = 𝜇 𝑋 − 𝑘 𝑋 (5.a) = − 𝜇 𝑋 + 𝑓 𝑘 𝑋 (5.b) where X is the microbial concentration (g/m³), S is the substrate concentration (g/m³), μmax is the maximum specific growth rate of microorganisms (g/g.day), KS is the half saturation constant for microbial growth on substrate (g/m³), kd is the specific decay rate of microorganisms (g/g.day), yH is the yield coefficient (g/g), and fs is the fraction of biodegradable organics (substrates) in biomass (dimensionless). The purpose of the classroom example is to teach students how to implement solution to a set of ODEs using spreadsheet and user-defined VBA functions within acceptable time limit. The problem statement, with given initial values of microbial
  • 8. 8 and substrate concentrations in a batch reactor as well as stoichiometric and kinetic parameters, is “calculate the maximum microbial concentration in the batch reactor”. The solution to the problem starts with implementing the ODEs as user-defined VBA functions in Visual Basic Editor, which completes the first four steps of the solution procedure provided in previous section. A screenshot of the VBA module is shown in Fig. 2a. The fifth step involves typing the cell formulae to implement a solution with the given parameters. A screenshot of the spreadsheet solution to the problem is shown Fig. 2.b and the cell formulae are shown in Table 1. In the sixth step, the cell formulae need to be extended over a certain range that depends on the maximum time of simulation. For this purpose, the extension is performed by dragging the formula over the target range. The formula in cell C3 is extended to “C3:C2883” by dragging to obtain simulation results until 24 hours with a time step of 30 seconds. Also, the cells D3, E4, and F4 are extended to “D3:D2883”, “E4:E2883”, and “F4:F2883”, respectively. In order to calculate the integration parameters in each time step, the cell range “G3:N3” must be extended until “G2882:N2882”. Figure 2: Solution to microbial growth problem. a) VBA functions, b) spreadsheet view Table 1: Implementation of spreadsheet solution to microbial growth problem Cell reference Cell formula Remarks C3 “=0” D3 “=C3/3600” To calculate simulation time in hours. Extended to D2883 E3 “=B2” F3 “=B3” G3 “=dXdt(E3;F3)*$B$1” Extended to G2882 H3 “=dXdt(E3+0.5*G3;F3)*$B$1” Extended to H2882 I3 “=dXdt(E3+0.5*H3;F3)*$B$1” Extended to I2882
  • 9. 9 J3 “=dXdt(E3+I3;F3)*$B$1” Extended to J2882 K3 “=dSdt(F3;E3)*$B$1” Extended to K2882 L3 “=dSdt(F3+0.5*K3;E3)*$B$1” Extended to L2882 M3 “=dSdt(F3+0.5*L3;E3)*$B$1” Extended to M2882 N3 “=dSdt(F3+M3;E3)*$B$1” Extended to N2882 C4 “=C3+B$1” Extended to C2883 E4 “=E3+(G3+2*H3+2*I3+J3)/6” Extended to E2883 F4 “=F3+(K3+2*L3+2*M3+N3)/6” Extended to F2883 The solution to the microbial growth problem with user-defined VBA functions eliminates the need for implementation of the differentials in Eqn. 5 in cells. Without VBA functions, the student would need to type the differentials over and over again in the cell range “G3:N3”, which would be a long and tiring process. Thus, employing user-defined VBA functions reduces the effort and time that students have to spend implementing a solution to any set of ODEs. In the example of microbial growth, the solution is obtained within minutes including the implementation of both VBA functions and spreadsheet formulae. Further, most environmental processes involve much more complicated formulations that combine physical, chemical, and biochemical process equations as in the case of activated sludge modelling. In addition, most activated sludge systems operate in continuous mode and the differential equations, therefore, include several other terms for the transport of pollutants with the bulk flow of liquid. As a result, this approach of spreadsheet solution enhanced with VBA functions could provide an easy-to-implement method of solution and could be used in a classroom setting. For the case of microbial growth example, the students can optionally apply the last step of the procedure for formatting the cells (as in Fig. 2.b) and preparing charts on the spreadsheet. Fig. 3 shows the change of microbial and substrate concentrations in the batch reactor with the initial values and parameters provided in Fig. 2. As expected, the microbial concentration increases exponentially up to a certain limit while substrate concentration decreases quickly due to microbial growth. The maximum microbial concentration in the batch reactor is calculated at around 9.5 hours of simulation as 441 mg/L. The solution to the problem takes less than 10 minutes including both the implementation of VBA functions and spreadsheet formulae. Without using spreadsheets, it would not be possible to complete this classroom example within class hours at a time step of 30 seconds. Besides, it would be extremely tiring and boring for students to take 2880 steps (24 hours at a time step of 30 s) to perform a 24-hour-simulation. On the other hand, a time step of around 2 hours would be an appropriate value to reduce students’ efforts in hand calculations (without spreadsheets). In this case, the maximum microbial concentration would be calculated as 505 mg/L at 12th hour of simulation, which contains a very large margin of error (around 15%). One can conclude that using spreadsheets enhanced with user- defined VBA functions reduces student effort to solve the problem drastically, and
  • 10. 10 eliminates most of rounding errors. Besides, enhancing the spreadsheet method of solution with user-defined VBA functions eliminates the need for typing the differential equations as cell formulae over and over again, further reducing the time required for solution. Figure 3: Calculated concentrations for microbial growth problem a) microbial concentration, b) substrate concentration 3.2. Activated Sludge Process This example employs a simplified version of Activated Sludge Model No. 3 (ASM3) by Gujer et al [22] for the purpose of simulating the aerobic phase of a sequencing batch reactor for biological carbon and nitrogen removal from residential wastewater. Seven components were included in the simulations along with seven processes. The components of interest are readily biodegradable substrates (SS, g COD/m³), ammonia plus ammonium nitrogen (SNH, g N/m³), alkalinity (SNO, mol HCO₃/m³), slowly biodegradable substrate (XS, g COD/m³), organic material stored by heterotrophs (XSTO, g COD/m³), heterotrophic biomass (XH, g COD/m³), and autotrophic biomass (XA, g COD/m³). The processes were hydrolysis of slowly biodegradable substrates, storage of readily biodegradable substrates by heterotrophs, use of stored organics for heterotrophic growth, growth and endogenous respiration of heterotrophs and autotrophs. The dissolved oxygen concentration in the batch reactor was assumed to be constant at 2 g O2/m³. Mass balance equations for the model are given as follows: = 1 − 𝑓 𝑟 − 𝑟 (6.a) = 𝑖 , − 𝑖 , + 𝑓 𝑖 , 𝑟 + 𝑖 , 𝑟 − 𝑖 , 𝑟 − 𝑟 − 𝑖 , + 𝑟 + 𝑖 , 𝑟 (6.b) = , , , 𝑟 − , 𝑟 + , 𝑟 − 𝑟 − , + 𝑟 + , 𝑟 (6.c) = −𝑟 (6.d) = 𝑌 𝑟 − 𝑟 − 𝑟 (6.e)
  • 11. 11 = 𝑟 − 𝑟 (6.f) = 𝑟 − 𝑟 (6.g) where 𝑓 is the fraction of inert soluble organic matter from biomass decay (dimensionless), 𝑖 , , 𝑖 , , and 𝑖 , are nitrogen content of readily biodegradable substrate, slowly biodegradable substrate and biomass, respectively (g N/g COD), 𝑌 is autotrophic yield (g COD/g N), 𝑌 is heterotrophic yield (g COD/g COD), and 𝑌 is yield of XSTO (g COD/g COD). The rate functions (r1 through r7) are given as follows: 𝑟 = 𝑘 ⁄ ⁄ 𝑋 (7.a) 𝑟 = 𝑘 , , 𝑋 (7.b) 𝑟 = 𝜇 , , , ⁄ , ⁄ 𝑋 (7.c) 𝑟 = 𝑏 , 𝑋 (7.d) 𝑟 = 𝑏 , 𝑋 (7.e) 𝑟 = 𝜇 , , , 𝑋 (7.f) 𝑟 = 𝑏 , 𝑋 (7.g) where kHYD is hydrolysis rate constant (g COD/g COD.sec), KX is hydrolysis saturation constant (g COD/g COD), kSTOR is storage rate constant (g COD/g COD.sec), KH,O is heterotrophic saturation constant for SO (g O2/m³), KH,S is heterotrophic saturation constant for SS (g COD/m³), KH,NH is heterotrophic saturation constant for SNH (g N/m³), KH,ALK is heterotrophic saturation constant for alkalinity (mol HCO₃/m³), KH,STO is heterotrophic saturation constant for XSTO (g COD/m³), μH is maximum specific growth rate of heterotrophs (g COD/g COD.sec), bH is endogenous respiration rate of heterotrophs (g COD/g COD.sec), bSTO is respiration rate for XSTO (g COD/g COD.sec), KA,O is autotrophic saturation constant for SO (g O2/m³), KA,NH is autotrophic saturation constant for SNH (g N/m³), KA,ALK is autotrophic saturation constant for alkalinity (mol HCO₃- /m³), μA is maximum specific growth rate of autotrophs (g COD/g COD.sec), and bA is endogenous respiration rate of autotrophs (g COD/g COD.sec). The solution to the activated sludge process problem involves the calculation of component concentrations (SS, SNH, SALK, XA, XH, XS, and XSTO) at a given time step with the given initial concentrations of the components. The solution starts with implementing Eqn. 6 and 7 in VBE (Fig. 4.a). The students need to declare the stoichiometric and kinetic parameters as well as the dissolved oxygen concentration in the sequencing batch reactor as constants. Then, the mass balance equations (Eqn. 5) are implemented as public VBA functions and the rate expressions (Eqn. 6) are implemented as private VBA functions. Private VBA functions are not available in MS Excel spreadsheet, however, mass balance equations are available and they employ private rate expressions.
  • 12. 12 In step 5 of the solution procedure, the student switches to spreadsheet view and prepares a calculation table as shown in Fig. 4.b. The initial values of component concentrations and the time step must be given here. For the solution of the current example, the time step was 30 seconds with the initial component concentrations as shown in Fig. 4.b. The simulation time was 4 hours. Figure 4: Solution to activated sludge process. a) VBA functions, b) spreadsheet view The first cells to implement on the spreadsheet are those that hold the time data. These cells are located in D and E columns and have the following formulae: Cell D2: “=0” Cell D3: “=D2+$B$1”, extended to D482 Cell E2: “=D2/3600”, extended to E482 Option Explicit Const S_O = 2 'Dissolved oxygen concentration (g / m3) 'STOICHIOMETRIC PARAMETERS Const f_SI = 0 '(g COD) / (g COD) Const i_N_BM = 0.07 '(g N) / (g COD) Const i_N_XS = 0.04 '(g N) / (g COD) Const i_N_SS = 0.03 '(g N) / (g COD) Const Y_A = 0.24 '(g COD) / (g N) Const Y_H = 0.63 '(g COD) / (g COD) Const Y_STO = 0.85 '(g COD) / (g COD) 'KINETIC PARAMETERS Const b_A = 0.00000174 '(g COD) / (g COD.sec) Const b_H = 0.00000231 '(g COD) / (g COD.sec) Const b_STO = 0.00000231 '(g COD) / (g COD.sec) Const k_HYD = 0.0000347 '(g COD) / (g COD.sec) Const k_STOR = 0.0000579 '(g COD) / (g COD.sec) Const MHU_A = 0.0000116 '(g COD) / (g COD.sec) Const MHU_H = 0.0000231 '(g COD) / (g COD.sec) Const K_A_ALK = 0.5 '(mol HCO3) / m3 Const K_A_NH = 1 '(g N) / m3 Const K_A_O = 0.5 '(g O2) / m3 Const K_H_ALK = 0.1 '(mol HCO3) / m3 Const K_H_NH = 0.01 '(g N) / m3 Const K_H_O = 0.2 '(g O2) / m3 Const K_H_S = 2 '(g COD) / m3 Const K_H_STO = 1 '(g COD) / (g COD) Const K_X = 1 '(g COD) / (g COD) 'PROCESS RATE EQUATIONS Private Function R1(X_S, X_H) R1 = k_HYD * (X_S / X_H) / (K_X + (X_S / X_H)) * X_H End Function Private Function R2(S_S, X_H) R2 = k_STOR * S_O / (K_H_O + S_O) * S_S / (K_H_S + S_S) * X_H End Function Private Function R3(S_NH, S_ALK, X_STO, X_H) R3 = MHU_H * S_O / (K_H_O + S_O) * S_NH / (K_H_NH + S_NH) * _ S_ALK / (K_H_ALK + S_ALK) * (X_STO / X_H) / (K_H_STO + (X_STO / X_H)) * X_H End Function Private Function R4(X_H) R4 = b_H * S_O / (K_H_O + S_O) * X_H End Function Private Function R5(X_STO) R5 = b_STO * S_O / (K_H_O + S_O) * X_STO End Function Private Function R6(S_NH, S_ALK, X_A) R6 = MHU_A * S_O / (K_A_O + S_O) * S_NH / (K_A_NH + S_NH) * _ S_ALK / (K_A_ALK + S_ALK) * X_A End Function Private Function R7(X_A) R7 = b_A * S_O / (K_A_O + S_O) * X_A End Function 'MASS BALANCE EQUATIONS Public Function dS_Sdt(S_S, X_S, X_H) dS_Sdt = (1 - f_SI) * R1(X_S, X_H) - R2(S_S, X_H) End Function Public Function dS_NHdt(S_NH, S_S, S_ALK, X_S, X_STO, X_H, X_A) dS_NHdt = (i_N_XS + (f_SI - 1) * i_N_SS) * R1(X_S, X_H) - _ i_N_SS * R2(S_S, X_H) + i_N_BM * (R4(X_H) - R3(S_NH, S_ALK, X_STO, X_H)) - _ (i_N_BM + 1 / Y_A) * R6(S_NH, S_ALK, X_A) + i_N_BM * R7(X_A) End Function Public Function dS_ALKdt(S_ALK, S_S, S_NH, X_S, X_STO, X_H, X_A) dS_ALKdt = ((i_N_XS + (f_SI - 1) * i_N_SS) / 14) * R1(X_S, X_H) - _ (i_N_SS / 14) * R2(S_S, X_H) + (i_N_BM / 14) * _ (R4(X_H) - R3(S_NH, S_ALK, X_STO, X_H)) - ((i_N_BM + 1 / Y_A) / 14) * _ R6(S_NH, S_ALK, X_A) + (i_N_BM / 14) * R7(X_A) End Function Public Function dX_Sdt(X_S, X_H) dX_Sdt = -R1(X_S, X_H) End Function Public Function dX_STOdt(X_STO, S_S, S_NH, S_ALK, X_H) dX_STOdt = Y_STO * R2(S_S, X_H) - (1 / Y_H) * _ R3(S_NH, S_ALK, X_STO, X_H) - R5(X_STO) End Function Public Function dX_Hdt(X_H, S_NH, S_ALK, X_STO) dX_Hdt = R3(S_NH, S_ALK, X_STO, X_H) - R4(X_H) End Function Public Function dX_Adt(X_A, S_NH, S_ALK) dX_Adt = R6(S_NH, S_ALK, X_A) - R7(X_A) End Function a
  • 13. 13 Fourth-order Runge-Kutta formulations as given in Eqn. 2 must be implemented for each of the component concentrations. For readily biodegradable substrates (SS), following cell formulae are implemented: Cell M2: “=dS_Sdt(F2;I2;K2)*$B$1”, extended to M481 Cell N2: “=dS_Sdt(F2+0.5*M2;I2;K2)*$B$1”, extended to N481 Cell O2: “=dS_Sdt(F2+0.5*N2;I2;K2)*$B$1”, extended to O481 Cell P2: “=dS_Sdt(F2+O2;I2;K2)*$B$1”, extended to P481 Cell F2: “=B3” Cell F3: “=F2+(M2+2*N2+2*O2+P2)/6”, extended to F482 Following cell formulae are implemented to calculate concentration of ammonia plus ammonium nitrogen (SNH): Cell Q2: “=dS_NHdt(G2;F2;H2;I2;J2;K2;L2)*$B$1”, extended to Q481 Cell R2: “=dS_NHdt(G2+0.5*Q2; F2;H2;I2;J2;K2;L2)*$B$1”, extended to R481 Cell S2: “=dS_NHdt(G2+0.5*R2;F2;H2;I2;J2;K2;L2)*$B$1”, extended to S481 Cell T2: “=dS_NHdt(G2+S2;F2;H2;I2;J2;K2;L2)*$B$1”, extended to T481 Cell G2: “=B4” Cell G3: “=G2+(Q2+2*R2+2*S2+T2)/6”, extended to G482 Following cell formulae are implemented to calculate alkalinity (SALK): Cell U2: “=dS_ALKdt(H2;F2;G2;I2;J2;K2;L2)*$B$1”, extended to U481 Cell V2: “=dS_ALKdt(H2+0.5*U2;F2;G2;I2;J2;K2;L2)*$B$1”, extended to V481 Cell W2: “=dS_ALKdt(H2+0.5*V2;F2;G2;I2;J2;K2;L2)*$B$1”, extended to W481 Cell X2: “=dS_ALKdt(H2+W2;F2;G2;I2;J2;K2;L2)*$B$1”, extended to X481 Cell H2: “=B5” Cell H3: “=H2+(U2+2*V2+2*W2+X2)/6”, extended to H482 Following cell formulae are implemented to calculate concentration of slowly biodegradable substrate (XS): Cell Y2: “=dX_Sdt(I2;K2)*$B$1”, extended to Y481 Cell Z2: “=dX_Sdt(I2+0.5*Y2;K2)*$B$1”, extended to Z481 Cell AA2: “=dX_Sdt(I2+0.5*Z2;K2)*$B$1”, extended to AA481 Cell AB2: “=dX_Sdt(I2+AA2;K2)*$B$1”, extended to AB481 Cell I2: “=B6” Cell I3: “=I2+(Y2+2*Z2+2*AA2+AB2)/6”, extended to I482 Following cell formulae are implemented to calculate concentration of organic material stored by heterotrophs (XSTO): Cell AC2: “=dX_STOdt(J2;F2;G2;H2;K2)*$B$1”, extended to AC481 Cell AD2: “=dX_STOdt(J2+0.5*AC2;F2;G2;H2;K2)*$B$1”, extended to AD481 Cell AE2: “=dX_STOdt(J2+0.5*AD2;F2;G2;H2;K2)*$B$1”, extended to AE481 Cell AF2: “=dX_STOdt(J2+AE2;F2;G2;H2;K2)*$B$1”, extended to AF481 Cell J2: “=B7” Cell J3: “=J2+(AC2+2*AD2+2*AE2+AF2)/6”, extended to J482
  • 14. 14 Following cell formulae are implemented to calculate concentration of heterotrophic biomass (XH): Cell AG2: “=dX_Hdt(K2;G2;H2;J2)*$B$1”, extended to AC481 Cell AH2: “=dX_Hdt(K2+0.5*AG2;G2;H2;J2)*$B$1”, extended to AD481 Cell AI2: “=dX_Hdt(K2+0.5*AH2;G2;H2;J2)*$B$1”, extended to AE481 Cell AJ2: “=dX_Hdt(K2+AI2;G2;H2;J2)*$B$1”, extended to AF481 Cell K2: “=B8” Cell K3: “=K2+(AG2+2*AH2+2*AI2+AJ2)/6”, extended to K482 Following cell formulae are implemented to calculate concentration of autotrophic biomass (XA): Cell AK2: “=dX_Adt(L2;G2;H2)*$B$1”, extended to AK481 Cell AL2: “=dX_Adt(L2+0.5*AK2;G2;H2)*$B$1”, extended to AL481 Cell AM2: “=dX_Adt(L2+0.5*AL2;G2;H2)*$B$1”, extended to AM481 Cell AN2: “=dX_Adt(L2+AM2;G2;H2)*$B$1”, extended to AN481 Cell L2: “=B9” Cell L3: “=L2+(AK2+2*AL2+2*AM2+AN2)/6”, extended to L482 The spreadsheet solution to the activated sludge problem takes only a few seconds depending on the computational power. In the final step of spreadsheet implementation of the solution, the columns M through AN are hidden for a clear look of the sheet. Finally, several charts are added to monitor the change of component concentrations with simulation time. The component concentrations in the sequencing batch reactor are shown in Fig. 5. As expected, readily biodegradable substrates (SS) are stored or metabolized quickly by heterotrophic bacteria and the concentration diminishes quickly within the first 2 hours of simulation (Fig. 5.a). Since growth rates of autotrophic bacteria are very small compared to that of heterotrophs, it is also an expected result that ammonia plus ammonium nitrogen (SNH) decreases at a slower speed (Fig. 5.b). Alkalinity (SALK) of wastewater decreases slowly as a result of the consumption of ammonia by autotrophic metabolism and generation of carbon dioxide by heterotrophic metabolism. Also, results shows that an initial alkalinity of 5 mol HCO₃/m³ during the aerobic phase of the sequencing batch reactor is more than enough for the process to continue. The concentration of organic materials stored by heterotrophs (XSTO) increases rapidly (Fig. 5.c) as the heterotrophic bacteria stores the readily biodegradable substrate in their cells before metabolizing (Eqn. 6.e). After the readily biodegradable substrates are depleted (around the second hour), the rate of storage slows down and the hydrolysis process becomes a limiting factor of the storage of organic material. The concentration of slowly biodegradable substrates (XS) changes only under the effect of hydrolysis process (Eqn. 6.a), which is a result of heterotrophic activity, and the concentration decreases slowly, as expected (Fig. 5.d). Concentrations of heterotrophic and autotrophic bacteria increases with time (Fig. 5.e and 5.f) under aerobic conditions with plenty of organic carbon and ammonia within the reactor for microbial growth. As expected based on their maximum specific growth rates, the rate
  • 15. 15 of change of heterotrophic biomass concentration was much higher than that of autotrophic biomass. Figure 5: Calculated component concentrations in activated sludge process. a) Readily biodegradable substrates, b) ammonia plus ammonium nitrogen, c) organic materials stored by heterotrophs, d) slowly biodegradable substrates, e) heterotrophic biomass, and f) autotrophic biomass 4. Discussion Solution for the simulation of environmental processes, which usually involve complex sets of ordinary differential equations, by spreadsheet and Visual Basic for Applications was presented in this paper. A simplified procedure was proposed for the implementation, and the procedure was applied to solve two example problems that involve biochemical processes with complex formulations. The first example was
  • 16. 16 a simple one with two differentials and relatively short process rate expressions. The solution to this example problem takes less than 10 minutes including implementation of user-defined VBA functions and spreadsheet formulae. Compared to the time required for and the accuracy with hand calculations, the proposed method is extremely fast and accurate. Without the use of VBA functions, the students would need to implement Eqn. 5 separately in four cells with modifications (Eqn. 2 and 3) to calculate RK4 integration parameters, which probably takes much more than 10 minutes and require much attention for correct implementation. The second example problem was a simplified version of Activated Sludge Model No. 3 by Gujer et al [22]. The implementation of this problem was challenging while solution by hand calculations would take days. This example can be solved in a few hours by implementing user-defined VBA functions and using them in spreadsheet formulae. The main advantage of the proposed method can be seen in this example. Without user-defined VBA functions, the students would need to implement all of the model equations (Eqn. 6 and 7) over and over again with small modifications with regard to RK4 parameter calculations (Eqn. 2 and 3). For instance, the concentration of ammonia+ammonium nitrogen (SNH) is calculated in the column G using the RK4 parameters in columns Q through T. Without user-defined VBA functions, the students would need to implement following cell formulae to calculate SNH: Cell Q2: “=((i_N_XS–i_N_SS+f_SI*i_N_SS)*k_HYD*(K2/J2)/(K_X+(K2/J2))*J2+ i_N_SS*k_STOR*S_O/(K_H_O+S_O)*F2/(K_H_S+F2)*J2– i_N_BM*(b_H*S_O/(K_H_O+S_O)*J2–b_STO*S_O/(K_H_O+S_O)*J2)–( i_N_BM+1/Y_A)*MHU_A*S_O/(K_A_O+S_O)*G2/(K_A_NH+G2)*I2+i_N_BM*b_A*S _O/(K_A_O+S_O)*I2)*$B$1, extended to Q481 Cell R2: “=((i_N_XS–i_N_SS+f_SI*i_N_SS)*k_HYD*(K2/J2)/(K_X+(K2/J2))*J2+ i_N_SS*k_STOR*S_O/(K_H_O+S_O)*F2/(K_H_S+F2)*J2– i_N_BM*(b_H*S_O/(K_H_O+S_O)*J2–b_STO*S_O/(K_H_O+S_O)*J2)–( i_N_BM+1/Y_A)*MHU_A*S_O/(K_A_O+S_O)*(G2+Q2/2)/(K_A_NH+(G2+Q2/2))*I2+i _N_BM*b_A*S_O/(K_A_O+S_O)*I2)*$B$1, extended to R481 Cell S2: “=((i_N_XS–i_N_SS+f_SI*i_N_SS)*k_HYD*(K2/J2)/(K_X+(K2/J2))*J2+ i_N_SS*k_STOR*S_O/(K_H_O+S_O)*F2/(K_H_S+F2)*J2– i_N_BM*(b_H*S_O/(K_H_O+S_O)*J2–b_STO*S_O/(K_H_O+S_O)*J2)–( i_N_BM+1/Y_A)*MHU_A*S_O/(K_A_O+S_O)*(G2+R2/2)/(K_A_NH+(G2+R2/2))*I2+i_ N_BM*b_A*S_O/(K_A_O+S_O)*I2)*$B$1, extended to S481 Cell T2: “=((i_N_XS–i_N_SS+f_SI*i_N_SS)*k_HYD*(K2/J2)/(K_X+(K2/J2))*J2+ i_N_SS*k_STOR*S_O/(K_H_O+S_O)*F2/(K_H_S+F2)*J2– i_N_BM*(b_H*S_O/(K_H_O+S_O)*J2–b_STO*S_O/(K_H_O+S_O)*J2)–( i_N_BM+1/Y_A)*MHU_A*S_O/(K_A_O+S_O)*(G2+S2)/(K_A_NH+(G2+S2))*I2+i_N_B M*b_A*S_O/(K_A_O+S_O)*I2)*$B$1, extended to T481 Cell G2: “=B4” Cell G3: “=G2+(Q2+2*R2+2*S2+T2)/6”, extended to G482 where values of all stoichiometric and kinetic parameters need to be written in related named cell ranges, which brings an extra workload to create named ranges on spreadsheet. The above cell formulae are just for calculating SNH concentrations in the
  • 17. 17 reactor. The calculation of alkalinity requires implementing more complicated cell formulae. Considering the difficulty of implementing these formulae on spreadsheet alone, it would not be wise to expect students to complete the task within allowed time limits. Besides, correct implementation of these formulae would need much more attention and can take as much time as would by hand calculations. In the case of employing user-defined VBA functions, the cell formulae are simpler and the differential equations need to be implemented only once in VBE, reducing student efforts and solution time. In order to test the effectiveness of the proposed method, several students were selected from those who already completed first year courses, i.e. Computer Programming and Numerical Methods. On the other hand, the students did not complete the Environmental Modeling course. All of the students were already familiar with spreadsheet software (Excel) and they had moderate experience with Excel’s spreadsheet functions as well as implementing formulae in cells. In terms of programming platform, 33% of all were familiar with Matlab programming with no experience in VBA programming. The students’ programming experience were 2.83 out of 5, with 1 being no programming background and 5 being an experienced computer programmer. All students were given an online seminar on the solution of the example problem given in Section 2.2 of this paper, including a minor chapter on how to implement functions in VBA and how to use those custom VBA functions in Excel. They were also given the formulations pertaining to the microbial growth problem and the activated sludge process given in Section 3 of this paper. All students were given a day to solve the problems using Excel and VBA. At the end, they were asked to answer a few questions. Students reported that they had completed both problems within 3 to 5 hours using Excel and VBA, which was very fast considering their VBA and environmental modeling experience and that this was the first time the students encountered problems as complex as the activated sludge process. All of the students are then asked to score the methodology by comparing the ease of solutions with hand calculations and Excel spreadsheet calculations in Numerical Methods course. The score was 5 out of 5 from all students, which show that the students find it very easy to solve complex sets of ODEs with Excel and VBA. 5. Conclusions A simple procedure for solving complicated differential equations encountered in environmental processes, which may involve physical, chemical and biochemical reactions, is proposed in this study. The procedure involves implementing the differential equations as user-defined Visual Basic for Applications (VBA) functions and using these functions for implementing a spreadsheet solution of the problem. The procedure is applicable in MS Excel and other spreadsheet applications with VBA support. The advantage of the proposed method is that it reduces the student effort and solution time drastically by simplifying the cell formulae that need to be implemented
  • 18. 18 in a great number of spreadsheet columns. Besides, employing user-defined VBA functions is simpler than implementing the whole formulae in cells with regard to fourth-order Runge-Kutta (RK4) integration parameters. In light of the discussion presented, the proposed method can be used confidently for delivering the information in environmental modelling courses within very short periods of time.
  • 19. 19 References [1] Rivas, A., Gomez-Acebo, T., and Ramos, J.C. (2006). The application of spreadsheets to the analysis and optimization of systems and processes in the teaching of hydraulic and thermal engineering. Computer Applications in Engineering Education, 14(4), 256-268. [2] Hosseini, S.M. (2009). Application of spreadsheets in developing flexible multiple-reach and multiple-branch methods of Muskingum flood routing. Computer Applications in Engineering Education, 17(4), 448-454. [3] Fernandez, S., Orosa, J.A., Galan, J.J. (2012). A new methodology to teach numerical methods with MS Excel. Journal of Maritime Research, 9(2), 29-32. [4] Coto, B., and Suarez, I. (2017). Euler algorithm to solve reaction kinetic equations: Mathematical formulation, programming, and applications. Computer Applications in Engineering Education, 26(1), 29-36. [5] Sana, A. (2017). Teaching fundamental concepts of coastal engineering using excel spreadsheet. Computer applications in Engineering Education, 25(2), 304-310. [6] Demir, S., Duman, S., Manav Demir, N., and Karadeniz, A. (2018). An MS Excel add-in for calculating Darcy friction factor. Spreadsheets in Education, 10(3), 3. [7] Demir, S., Karadeniz, A., Manav Demir, N., and Duman, S. (2018). Excel VBA- based solution to pipe flow measurement problem. Spreadsheets in Education, 10(3), 4. [8] Demir, S., Manav Demir, N., and Karadeniz, A. (2018). An MS Excel tool for water distribution network design in environmental engineering education. Computer Applications in Engineering Education, 26(2), 203-214. [9] Demir, S., Duman, S., Manav Demir, N., Karadeniz, A., and Lubura E. (2018). An MS Excel add-in for teaching hydraulics of pipe flow in engineering curricula. Computer Applications in Engineering Education, 26(3), 449-459. [10] Rabi, J.A., and Caneppele, F.L. (2018). Numerical methods to Biosystems and food engineering students: Hands-on practices and cross-disciplinary integration. Computer Applications in Engineering Education, 26(5), 1120-1133. [11] Manav Demir, N., and Demir, S. (2017). An MS Excel tool for wastewater treatment modeling in undergraduate education: Activated Sludge Model No. 1. Fresenius Environmental Bulletin, 26(12), 7008-7017. [12] Demir, S., and Manav Demir, N. (2020). Implementation of activated sludge model no. 3 (ASM3) as an educational tool: bioXL3. Computer Applications in Engineering Education, DOI: 10.1002/cae.22292. [13] Niazkar, M., and Afzali S.H. (2017). Analysis of water distribution networks using MATLAB and Excel spreadsheet: H-based methods. Computer Applications in Engineering Education, 25(1), 129-141.
  • 20. 20 [14] Niazkar, M., and Afzali, S.H. (2017). Analysis of water distribution networks using MATLAB and Excel spreadsheet: Q-based methods. Computer Applications in Engineering Education, 25(2), 277-289. [15] Demir, S., Karadeniz, A., Civelek Yörüklü, H., and Manav Demir, N. (2017). An MS Excel tool for parameter estimation by multivariate nonlinear regression in environmental engineering education. Sigma Journal of Engineering and Natural Sciences, 35(2), 265-273. [16] Demir, S. (2018). Evaluation of the suitability of global gradient algorithm and inverse matrix method for steady-state analysis of water distribution networks in engineering education. Ömer Halisdemir Üniversitesi Mühendislik Bilimleri Dergisi, 7(1), 23-33. [17] Demir, S, Karadeniz, A., and Manav Demir, N. (2016a). Using steepness coefficient to improve artificial neural network performance for environmental modelling. Polish Journal of Environmental Studies, 25(4), 1467-1477. [18] Demir, S, Karadeniz, A., and Manav Demir, N. (2016b). Artificial neural network simulation of cyclone pressure drop: Selection of the best activation function. Polish Journal of Environmental Studies, 25(5), 1891-1899. [19] Demir, S, Manav Demir, N., Karadeniz, A., and Civelek Yörüklü, H. (2018e). Implementation of an MS Excel tool for backpropagation neural network algorithm in environmental engineering education. Sigma Journal of Engineering and Natural Sciences, 36(1) 251-260. [20] Tay, G.T., Kek, S.L., and Abdul-Kadar, R. (2012). A spreadsheet solution of a system of ordinary differential equations using the fourth-order Runge-Kutta method. Spreadsheets in Education, 5(2), 5. [21] Demir, S. (2020). Solution to secondary sedimentation problem by spreadsheet and VBA. Spreadsheets in Education, 12(2), 3. [22] Gujer, W., Henze, M., Mino, T., and van Loosdrecht, M.C.M. (1999). Activated sludge model no. 3. Water Science and Technology 39(1), 183-193.