**Hydrologic and Water Quality Model Development Using Simulink**

#### **James D. Bowen, David N. Perry and Colin D. Bell**

**Abstract:** A stormwater runoff model based on the Soil Conservation Service (SCS) method and a finite-volume based water quality model have been developed to investigate the use of Simulink for use in teaching and research. Simulink, a MATLAB extension, is a graphically based model development environment for system modeling and simulation. Widely used for mechanical and electrical systems, Simulink has had less use for modeling of hydrologic systems. The watershed model is being considered for use in teaching graduate-level courses in hydrology and/or stormwater modeling. Simulink's block (data process) and arrow (data transfer) object model, the copy and paste user interface, the large number of existing blocks, and the absence of computer code allows students to become model developers almost immediately. The visual depiction of systems, their component subsystems, and the flow of data through the systems are ideal attributes for hands-on teaching of hydrologic and mass balance processes to today's computer-savvy visual learners. Model development with Simulink for research purposes is also investigated. A finite volume, multi-layer pond model using the water quality kinetics present in CE-QUAL-W2 has been developed using Simulink. The model is one of the first uses of Simulink for modeling eutrophication dynamics in stratified natural systems. The model structure and a test case are presented. One use of the model for teaching a graduate-level water quality modeling class is also described.

Reprinted from *J. Mar. Sci. Eng.* Cite as: Bowen, J.D.; Perry, D.N.; Bell, C.D. Hydrologic and Water Quality Model Development Using Simulink. *J. Mar. Sci. Eng.* **2014**, *2*, 616-632.

#### **1. Introduction**

Mechanistic models of water quality have long been used for predicting the impact of wastewaters on natural water bodies. While the first use of models relied on analytical solutions to problems of point or distributed sources of conventional pollutants (e.g., biochemical oxygen demand (BOD), suspended solids) into rivers, most of the water quality modeling applications these days rely on very large computer codes written with a high-level programming language such as FORTRAN or C++.

Many of the most used water quality models were originally developed in the 1980s and 1990s using FORTRAN as the high-level programming language. FORTRAN is still widely used; for instance, in recent a review of fifteen lake ecosystem models [1], five were written in FORTRAN and another five were written in C++, with the remainder written in other high level languages. These models are similar in concept and execution in that they are capable of modeling the dynamics in multi-dimensional physical systems of water quality properties, nutrients, dissolved oxygen, organic matter, and biota by simultaneously solving conservation equations for heat, momentum, and constituent mass in numerous water volumes. Examples of these sorts of models include the Water Analysis Simulation Program (WASP) [2], the Environmental Fluid Dynamics Code (EFDC) [3] with the water quality formulations described in HEM-3D [4], Qual2E [5], CE-QUAL-ICM [6], and CE-QUAL-W2 [7]. These models are very commonly used in regulatory water quality management (e.g., [8,9]) or to investigate the dynamics of water quality indicators as influenced by dynamic anthropogenic pollutant loading (e.g., [10]).

All of the above referenced models are essentially very large, complex computer codes that are maintained, modified, and manipulated by only a very small group of expert model developers. Manipulation of the code for site-specific or research purposes is not practical for the vast majority of users. There are circumstances, however, when model development is warranted, either when new model state variables are needed, when a special set of water quality processes are appropriate, or when prediction accuracy could be improved by assimilating monitoring data rather than modeling it. Water quality model development is also an important part of education in the field. Making these powerful models more flexible in their formulation through user development could greatly improve their overall utility.

MATLAB/Simulink has been adopted in other fields of engineering as a means for modeling and simulating complex systems without the need to write thousands of lines of computer code during model development. Simulink systems are drawn using a graphical user interface as "block and arrow" diagrams. The Simulink block library is very large and includes math and logic functions, signal generation and processing, visualization, plus many specialized toolboxes (e.g., fuzzy logic, DSP, control systems, neural networks). Lines connecting the blocks represent data signals. Signals can be bundled into buses and selectively unbundled as input into "downstream" blocks. Simulink systems are often operated in a time stepping mode to model the dynamic behavior of the system. As an extension of the MATLAB environment, Simulink models can be easily integrated to read and write data from the workspace and to interact with scripts written with its own high-level programming language.

Simulink has been utilized previously to model the dynamics of engineered systems in a variety of disciplines. Examples of its use in non-environmental systems analysis include process modeling in the sugar industry [11] and building systems modeling [12]. In the area of environmental engineering, Simulink has been used for simulating wastewater treatment plants, either as individual unit processes [13,14], as benchmark simulations of an entire wastewater treatment plant [15,16], for simulation of stormwater systems [17,18], or for integrated models that include both engineered and natural surface water systems [19,20]. Simulink has also been used to model the hydrodynamics and water quality of a few surface water natural systems [21–23].

In this article we explore the benefits of Simulink for water quality model development in teaching and research. Of particular interest is how the graphical modeling environment of Simulink can assist new model developers without programming experience as they are introduced to mass-balanced based water quality simulation in a graduate-level course that intentionally includes both instruction and collaborative model development by students. Simulink has been frequently used in engineering education for situations where construction of powerful computational tools for system simulation is an integral part of the pedagogy. For example, Simulink has been used as a teaching aid in courses on digital and analog modulation [24], multiphase electric machines [25], river water quality [26], and wastewater treatment plant operation and control [27]. It has been recognized in the engineering education community that use of tools such as Simulink can provide a "learner-centered" environment whereby students are able to create simulation tools that allow personal experimentation of system behavior (e.g., [28]). Courses structured to include such features can positively affect student interactivity, participation, and course satisfaction [29].

As a case study of water quality modeling instruction and model development with Simulink, we present three examples that were developed either for use in the classroom and/or in research. The first model was developed as an alternative to a spreadsheet solution of conservative flushing and transport through a pond and channel. The second application is a Simulink version of a widely used stormwater runoff hydrology model. The third example describes the finite volume implementation in Simulink of the water quality model CE-QUAL-W2. This application represents one of the first uses of Simulink for modeling dynamic, spatially varying water quality in natural systems.
