% SIMIODE-TeacherStudent-Template.tex and simiode.cls for LaTeX2e
% Version 22 November 2016.
% 
% This template is to be used with the  class file "simiode.cls". 
%  
% The latest version of this class and template files 
% can be found at
% 
%       <http://www.SIMIODE.org> in the Author section.
%
% A "Quick Start Guide" appears below.
%
% This file must be processed with version LaTeX2e or higher.
% Appreciation to Mark Frantz, IUPUI; John Thoo, Yuba College; and Eric Sullivan, Carroll College.
%
\documentclass{simiode}
%
% With this version of the tex file and the associated SIMIODE.cls file you can produce BOTH a Student Version and a Teacher Version of your modeling scenario or technique narrative.
%
% Student Version contains the title STUDENT VERSION along with the NAME OF SCENARIO, with no abstract, no keywords, no tags, no author identifiers, and no COMMENTS section. The Student Version contains only the STATEMENT of the modeling scenario only with appropriate figures, data, instructions, and perhaps a bibliography appropriate for student resourcing, but nothing in the bibliography which would "give away" the nature of the modeling scenario, etc.
%
%The Teacher Version contains the material in the Student Version, namely the title NAME OF SCENARIO, now headed with   TEACHER VERSION, but also full author  identification, abstract, key words, tag words, and, following the STATEMENT, a section of COMMENTS which can be discussion of presentation  ideas, "solutions," techniques, etc.
%
% Authors can prepare a full Teacher Version using the notions immediately below  to create a pdf for review, but in review please eliminate all information about the author as we use a double-blind referee system. Such information will be restored when accepted and published in SIMIODE at www.simiode.org.
%
%***********   Toggle the following line to turn the teacher version on (1) or off (0). ***********
%
\def\TeacherEdition{0} % Toggle this line's value.
\newcommand{\teacher}[1]{\ifnum\TeacherEdition=1 #1 \fi}
%
% The \teacher{ } command wraps any text that will appear only in the teacher version of
% the document. See this file for examples. This has been done for you in the document below.   
% Rename the pdf after you compile each final version.
%
\usepackage{amsmath,amssymb}
\usepackage{color}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{url}
%
\renewcommand{\baselinestretch}{1.3}
%
% NOTE regarding macros %%
%
% Any macros defined for your paper should be contained in 
% the top matter. Likewise, any environment definitions such 
% as \newtheorem or \newenvironment should also go in the 
% top matter. 
% 
% Do not \input your macros as separate files within your 
% final version because more files make it harder for the 
% editors and users to keep track of and/or modify and 
% append your paper.
%
% Top matter is above and the beginning of the document below.
%
\begin{document}

\newpage
%
% You only need to change the NAME OF SCENARIO in the next line and delete the footnote. 
% See above for instructions on toggling from Teacher Version to Student Version.
%
\title{\ifnum\TeacherEdition=1 TEACHER VERSION %\footnote{DELETE THIS FOOTNOTE BEFORE SUBMISSION.  In the \TeX \, source code there is a toggle/option to produce a Teacher Version or a Student Version by ``carving'' out with  $\backslash$teacher\{\} that material which should only appear in the Teacher version. See the source code.}
 \else STUDENT VERSION \fi\\ Theoretical and numerical study of chlorine concentration dynamics in regular swimming pool maintenance cycles}



\markboth{Chlorine concentration dynamics in regular swimming pool maintenance cycles}{Chlorine concentration dynamics in regular swimming pool maintenance cycles}

\author{Barbara Zubik-Kowal\\
Boise State University\\
Boise ID 83725 USA\\
bzubik@boisestate.edu
}

\makeStitlePDFLaTex


\begin{abstract}
This project involves the dynamics of chlorine concentration during regular swimming pool maintenance cycles. Students will have the opportunity to use both analytic and numerical methods. On the analytical side, students will solve one of the model equations, describing the first stage of a two-stage mixing process, by separating variables, and the other by applying the method of integrating factors. On the numerical side, students will apply Euler's method to solve the model equations numerically, with the opportunity to examine numerical errors for various step sizes, while comparing results to the previously obtained exact solutions. 
\end{abstract}

\section*{SCENARIO DESCRIPTION}


\subsection*{Background}
The concentration of chemical agents in pool water is regulated by health and safety standards to ensure safe use of recreational facilities \cite{WHO2006}. 
Chlorine is one of the most common disinfectants added to pool water in order to suppress the growth of  pathogenic  microorganisms \cite{Aprea2010}. This project is concerned with the concentration of chlorine in a mid-sized swimming pool during a regular maintenance cycle. 

A certain swimming pool is $20$m long, $8$m wide, and $2$m deep. When filled, it contains a volume of $84,000$ gallons of water. 
Recommended levels of chlorine concentration range from $1.3\times10^{-5}$ to $2.6\times10^{-5}$ ounces per gallon of water. 
The pool's regular maintenance schedule involves filtering, cleaning, and refilling the pool at regular time intervals, while adhering to recommended health and safety standards. 

A particular incident during one of the regular maintenance cycles can be described by a two-step process as follows.  \\[1ex]

\hspace{0.05\linewidth}
\begin{minipage}[h]{0.9\linewidth}
\begin{enumerate}
\item[\bf Stage 1:] {\bf Initial refill.} As a result of a miscalculation, water of a specified concentration of $1\times10^{-7}$ ounces of chlorine per gallon of water is supplied at a rate of $5$ gallons per minute into the swimming pool, which initially had a concentration of $1.3\times10^{-5}$ ounces of chlorine per gallon of water. 
The mixture is well-stirred in the pool. A water pump is turned on to filter and heat the pool water, so that the well-stirred mixture drains at the same rate.  
\item[\bf Stage 2:] {\bf Post-quality-check refill.} After $24$ hours, chlorine levels are found to be insufficient, and water of an increased concentration of $5\times10^{-5}$ ounces of chlorine per gallon of water is now supplied at a rate of $5$ gallons per minute, with the well-stirred mixture draining from the pool at the same rate.
\end{enumerate}
\end{minipage} \\[1ex]


\noindent
This project consists of two parts. Part I is a group activity, which you should complete in groups of 2-3. Part II is an individual project which you should complete yourself. 


\section*{Group activity - Part I}

\noindent
Form a group of 2-3.  
 Group members:\\[2ex] 
\rule{0.33\linewidth}{0.16mm} \rule{0.33\linewidth}{0.15mm} \rule{0.33\linewidth}{0.15mm} \\[2ex]
Complete the following with your group. 

\begin{enumerate}
\item Model formulation -- Stage 1
\begin{enumerate}
\item Denote the total amount of chlorine in the pool at time $t$ by $Q(t)$  (in ounces). Write down an expression denoting the rate of change of amount of chlorine. 
\item Formulate a differential equation modeling the amount of chlorine, $Q(t)$, during Stage 1. Define any new constants, if necessary. 
\item Write down the initial condition(s). 
\end{enumerate}

\item Separate variables to solve the differential equation modeling Stage 1. In particular: 
\begin{enumerate}
\item Obtain a general solution to the differential equation
\item Apply the initial condition(s) to find how the amount of chlorine changes in time during Stage 1. 
\item Does your answer make sense physically? Does your solution have the properties you expect it to have?
\item Write down any thoughts you have about your work, including what you think went well, what you are unsure of, and what you'd like to have feedback on. 
\end{enumerate}

\item Model formulation -- Stage 2
\begin{enumerate}
\item Formulate a differential equation modeling the amount of chlorine during Stage 2. Define any new constants, if necessary. 
\item Write down appropriate initial condition(s) for Stage 2, in order to couple the problem to that of Stage 1. 
\end{enumerate}

\item Use the method of integrating factors to solve the differential equation modeling Stage 2. In particular: 
\begin{enumerate}
\item Identify an appropriate integrating factor. 
\item Obtain a general solution to the differential equation. 
\item Apply the initial condition(s) to find how the amount of chlorine changes in time during Stage 2. 
\item Does your answer make sense physically? Does your solution have the properties you expect it to have, in comparison to that of Stage 1? 
\item How long does it take for the concentration of chlorine to reach the recommended minimum value of $1.3\times10^{-5}$ ounces per gallon of water? 
\item Write down any thoughts you have about your work, including what you think went well, what you are unsure of, and what you'd like to have feedback on. 
\end{enumerate}


\item Swap your work with another group. Read the other group's work carefully and provide feedback on their work, taking time to respond to their questions and anything they have requested feedback for. 

\item Discuss the feedback you have received from the other group. Provide each other the opportunity to ask questions about the feedback you have given each other. 

\item Are there any areas you could improve on? Take the opportunity to implement any changes in your work, based on the feedback you have received. 

\end{enumerate}



\section*{Criteria}
Hand in your work addressing the above questions as a group, in the form of a written report. You will be graded based on mathematical correctness, accuracy, clarity, and grammar. 


\section*{Individual Project - Part II}

\noindent
This part should be completed individually. \\

\noindent
Consider the two mathematical models that you have derived with your group for Stage 1 and Stage 2. 

\begin{enumerate}
\item Apply Euler's method to create a MATLAB script that implements a numerical algorithm to solve the two model equations numerically. The script should let the user specify the step size. 

\item Write supporting documentation outlining what each part of your script does. 

\item Using the exact solution that you have obtained with your group, plot the numerical error as a function of time using the step size $h=0.1$ for $0<t<24\times60$ (minutes) for Stage 1 and $24\times60<t<48\times60$ (minutes) for Stage 2, in a single figure. 
\label{step3}

\item Plot the numerical error as a function of time using the step sizes $h=0.02$ and $h=0.01$ for both Stage 1 and Stage 2 in a single figure (overlain on top of the figure of Step \ref{step3} above).  

\item Prepare a table listing the step size $h=0.1,0.09, \dots 0.01$ in the first column and the maximal error over the time interval $0<t<48\times60$ (minutes) in the second column. What do you observe? {\it Hint: It may help to apply the command {\tt format short e}, if the errors end up being small enough to unnecessarily truncate to zero.}
\end{enumerate}


\section*{Criteria}
Hand in your work for Part II of this project individually in the form of a report. You will be graded based on mathematical correctness, accuracy, clarity, and grammar. 



\begin{thebibliography}{98}

\bibitem{Aprea2010} Aprea, Maria-Cristina;  Banchi, Bruno; Lunghini, Liana;  Pagliantini, Massimo; Peruzzi, Antonio;  Sciarra, Gianfranco. 2010. Disinfection of swimming pools with chlorine and derivatives: formation of organochlorinated and   organobrominated compounds and exposure of pool personnel and swimmers. {\it Natural Science}. 2(2):68-78. \href{https://www.scirp.org/pdf/NS20100200001\_82150606.pdf}{https://www.scirp.org/pdf/NS20100200001\_82150606.pdf}.
\bibitem{WHO2006} WHO. 2006.  {\it Guidelines for safe recreational water environments. Volume 2: Swimming pools and similar environments\/}. Geneva SWITZERLAND: World Health Organization. \href{https://www.who.int/water\_sanitation\_health/bathing/srwe2full.pdf}{https://www.who.int/water\_sanitation\_health/bathing/srwe2full.pdf}
\end{thebibliography}


\teacher{
\section*{NOTES FOR TEACHERS}



\subsection*{Prerequisites}

To complete Part I of the project, students should be familiar with solving first order differential equations by separating variables and by applying the method of integrating factors. It would be helpful for students to have seen mixing problems prior to this project, though that is not necessary as students are guided through the necessary steps in the project. 

To complete Part II of the project, students should be familiar with applying Euler's method to solve differential equations numerically. Students should also be familiar with basic programming to create a script that implements Euler's method in MATLAB or another numerical computing environment. 


\subsection*{Timelines}

Part I of the project can be completed near the beginning of a typical differential equations course, after students are taught how to solve first order differential equations by separating variables and by applying the method of integrating factors. 

Part II of the project should be completed after students are introduced to Euler's method, along with basic programming tasks. 

Parts I and II can be assigned as a single project, or split into two separate projects after the required material has been taught. 

\subsection*{Possible alterations}

There is flexibility in the type of method that can be used to solve the differential equations modeling Stages 1 and 2. Either separating variables, or integrating factors, or a combination of both, can be used to solve each differential equation.  

Part I of the project is self-contained. A possible alternative is to assign just Part I of the project, in which case no knowledge of numerical methods and no prior programming experience would be necessary. 

\subsection*{Technology use}

Although MATLAB has been chosen to formulate Part II of this project, other numerical computing environments can also be used. 

\subsection*{Possible issues}

Things to watch out for: 

\begin{itemize}
\item (Part I) Students may have trouble with basic integration, after separating variables. Make sure to refer students to their calculus text for extra practice, if necessary. 
\item (Part I) Students may forget the constant of integration when solving the differential equations by separating variables and by applying the method of integrating factors. 
\item (Part I) Students may forget to multiply both sides of the differential equation in Stage 2 by the integrating factor. 
\item (Part II) Students should be taught basic programming before attempting Part II. 
\end{itemize}



\subsection*{Outline of a model solution - Part I}

There are various possible solution techniques. Below is an example of an outline of a possible solution. 

\begin{enumerate}
\item  Model formulation -- Stage 1
\begin{enumerate}
\item The rate of change of the amount of chlorine (in ounces) is 
$$\text{rate}_{\text{in}}-\text{rate}_{\text{out}}=c_1r_1 - Q(t)r_1/V,$$ 
where 
$c_1$ is the concentration of chlorine in water flowing in during Stage 1 ($c_1=10^{-7}$ ounces per gallon), 
$r_1$ is the rate in and out during Stage 1 ($r_1=5$ gallons per minute), and 
$V$ is the volume of the pool ($V=84,000$ gallons). 
\item $Q'(t)=c_1r_1 - Q(t)r_1/V$. No new constants necessary. 
\item $Q(0) = c_0V$, where $c_0$ is the initial concentration of the pool water ($c_0=1.3\cdot 10^{-5}$ ounces per gallon of water). Explicitly, $Q(0)=1.092$ ounces. 
\end{enumerate}
\item Separating variables:
\begin{enumerate}
\item Express $Q'(t)$ as $dQ/dt$ and rewrite the model equation as 
$$\frac{dQ}{dt} = c_1r_1 - \frac{Qr_1}{V}.$$
Divide both sides:
$$\frac{1}{ c_1r_1 - \frac{Qr_1}{V}} \frac{dQ}{dt}=1.$$
Separate variables:
$$\frac{dQ}{ c_1r_1 - \frac{Qr_1}{V}}=dt.$$
Integrate both sides, so that 
$$-\frac{V}{r_1}\ln\big|c_1r_1V-r_1Q(t)\big|=t+C,$$
where $C$ is a constant of integration. Solve for $Q(t)$ explicitly:
$$Q(t)=Ae^{-{r_1t}/{V}}+V c_1,$$
where $A$ is a constant. 


\item Apply the initial condition $Q(0)=c_0 V$ so that 
$$Q(t)=V  \left(c_0-c_1\right)e^{-\frac{r_1 t}{V}}+V c_1.$$

\item The solution has the property that $Q(t)\to Vc_1$ as $t\to\infty$, that is, the concentration of pool water tends towards the concentration of the water flowing in with time, which is physically expected. Additionally, the concentration is  decreasing from its initial value of $c_0$ (since $c_0>c_1$), which is also physically expected as a less concentrated solution is flowing into the pool. 

\item Any notes about what went well, and what the students are unsure of, are helpful for the peer-review stage.
\end{enumerate}

\item Model formulation -- Stage 2
\begin{enumerate} 
\item The rate of change of the amount of chlorine is $c_2 r_2-\frac{r_2 Q(t)}{V}$, so that
$$Q'(t)=c_2 r_2-\frac{r_2 Q(t)}{V},$$
where 
$c_2$ is the concentration of chlorine in water flowing in during Stage 2 ($c_2=5\cdot10^{-5}$ ounces per gallon), 
$r_2$ is the rate in and out during Stage 2 ($r_2=5$ gallons per minute), and 
$V$ is the volume of the pool ($V=84,000$ gallons). 
\item Stage 2 begins at time $t=T$, where $T=24\times60$ minutes. Chlorine concentration should be continuous at all times. As such, the appropriate initial condition at this point in time is
$$
Q(T)=V  \left(c_0-c_1\right)e^{-\frac{r_1 T}{V}}+V c_1,
$$
where the right-hand side is the solution obtained for Stage 1, evaluated at $t=T$.  
\end{enumerate}
\item Solving the differential equation using the method of integrating factors
\begin{enumerate}
\item Rewrite the equation as 
$$Q'(t)+\frac{r_2 Q(t)}{V}=c_2 r_2,$$
from which, one can identify the integrating factor $\mu(t)=e^{r_2t/V}$. 
\item Rewrite the equation as
$$\frac{d}{dt}\left(e^{r_2t/V} Q(t)\right)=c_2 r_2e^{r_2t/V},$$
and integrate both sides to obtain
$$e^{r_2t/V} Q(t)=c_2Ve^{r_2t/V}+D,$$
where $D$ is a constant of integration. Solve for $Q(t)$ explicitly:
$$Q(t)=c_2V+De^{-r_2t/V}.$$
\item Apply the initial condition to find that 
$$
Q(t)=c_2V +\left[(c_0-c_1) e^{-{r_1 T}/{V}}+(c_1-c_2)\right]Ve^{-{r_2 (t-T)}/{V}}. 
$$
\item The concentration of pool water tends towards $c_2$ with time, which is expected physically, as this is the concentration of chlorine in water flowing in during Stage 2. Also, the solution is increasing,  
which is also physically expected as the concentration of chlorine flowing in has increased significantly in Stage 2. 
\item To find how long it takes for the concentration of chlorine to reach the recommended minimum value of $c_0=1.3\times10^{-5}$ ounces per gallon of water, we solve for $t=T+\tau$, where
$$Q(t)/V=c_0,$$
that is, 
$$c_2 +\left[(c_0-c_1) e^{-{r_1 T}/{V}}+(c_1-c_2)\right]e^{-{r_2 \tau}/{V}}=c_0. $$
Solving for $\tau$ gives
$$
\tau = \frac{V}{r_2} \ln \left(\frac{(c_1-c_2)-(c_1-c_0) e^{-{r_1 T}/{V}}}{c_0-c_2}\right).
$$
Plugging in specific values for the parameters gives
$$
\tau\approx 474 \text{ minutes}\approx 7 \text{ hours } 54 \text{ minutes}. 
$$
That is, it takes about $7$ hours and $54$ minutes (from the beginning of Stage 2) for the pool water to attain the recommended minimum concentration. 
\item Any notes about what went well, and what the students are unsure of, are helpful for the peer-review stage.
\end{enumerate}
\end{enumerate}

\subsection*{Outline of a model solution - Part II}

\begin{enumerate}
\item There are many different ways of doing this. It is recommended to create a script that invokes an auxiliary function implementing Euler's method, and to apply that auxiliary function to solve the two differential equations, rather than implementing Euler's method twice. 
The auxiliary function should take in a number of input arguments, to be specified by the user, including the right-hand side of the differential equation, the interval of integration, the initial conditions, and the step size. It should give the numerical solution, as well as the corresponding vector of grid points in $t$, as the output.  \\[-1.5ex]

\begin{minipage}[h]{0.9\linewidth}{\it A sample script ({\tt numerical.m}) is available for the teacher to see how this can be implemented. In this script, the auxiliary function is called {\tt Euler}. }
\end{minipage}
\\[-1ex]

\item It is useful for students to get in the habit of commenting on each part of their scripts. For example, when giving the step size, say $h$, a specific value, add a comment that $h$ is the step size. Students should indicate in which part of the script the model parameters are defined, in which part of the script the numerical algorithm is implemented, in which part of the script the exact solutions are being entered, and in which part of the script results are being plotted/tabulated. 
\item See Figure  1. 
\item See Figure  1. The error decreases the smaller the step size. 



\item See Table 1. The errors decrease approximately linearly. 
\end{enumerate}
\newpage



\begin{figure}
\vspace*{.5 true cm} 
\centering
\includegraphics[width=\linewidth]{numerical-error.eps}
\caption{Numerical error for various step sizes}
\end{figure}


\begin{table}
\centering
\begin{tabular}{cc}
h & Maximal error\\
\hline
   0.10  & 5.1569e-07 \\
   0.09 &  4.6412e-07\\
   0.08 &  4.1255e-07\\
   0.07  & 3.6100e-07\\
   0.06  & 3.0942e-07\\
   0.05  & 2.5785e-07\\
   0.04  & 2.0628e-07\\
   0.03 &  1.5471e-07\\
   0.02  & 1.0314e-07\\
   0.01 &  5.1569e-08\\
\hline
\end{tabular}
\caption{Table of maximal errors}
\end{table}




\subsection*{Attachments}

\begin{itemize}
\item A sample Matlab script {\tt numerical.m} for Part II of the project can be found posted in the supplemental materials for this Modeling Scenario. 
\end{itemize}


}





\end{document}
