VIRTUAL LAB IN MODELICA FOR AIR POLLUTION CONTROL*

Interactive is a Modelica library whose goal is to facilitate the implementation of virtual labs based on Modelica models quickly and with little effort. Modelica is a free object oriented modeling language. The implementation of a virtual lab for air pollution control developed using Interactive 2.0 is discussed in this manuscript. This virtual lab has been developed to explain the dispersion of pollutants into the atmosphere to undergraduate students of Environmental Chemistry of the Universidad Nacional de Tucum ́an (Argentina). Main aspects in the virtual lab development process are addressed in this discussion, including: 1) application of a systematic methodology to adapt any Modelica model into a description suitable for interactive simulation; 2) composition of the virtual lab view using Interactive. Additionally, the use of this virtual lab in the Environmental Chemistry course is discussed. Interactive is freely available at www.euclides.dia.uned.es.


INTRODUCTION
Modelica [1] is a free object-oriented modeling language that facilitates the description of models in terms of hybrid differential algebraic equations (i.e., hybrid DAE). The mathematical models are described using equations, algorithms, and clauses to define the hybrid behavior, such as when and if clauses. The assignment of computational causality, and the symbolic manipulation and sorting of the model equations, are not made by the model developer. The modeling environment performs automatically these tasks. This feature greatly facilitates model development and reuse, reducing the time and effort required for completing simulation projects. Besides, Modelica facilitates structuring the modeling knowledge into model libraries, and defining new models by instantiating and connecting the library components. Model connection is performed on the basis of the energy-balance principle. A list of some of the Modelica environments can be found in [1]. Two well-known Modelica environments are Dymola and OpenModelica. Dymola is a commercial environment and OpenModelica is a free environment developed by the OpenModelica Consortium.
Virtual labs facilitate user's interactive actions on the models through the interactive user-to model interface. This user-to-model interface, named virtual lab view, typically includes an animation of the model behavior and gadgets such as sliders, check-boxes and buttons to change the model variables, parameters, etc. During the virtual lab running, it is established a communication between the virtual lab view and the simulation of the mathematical model. The view changes according to the actual state of the simulation of the mathematical model, and the modifications performed by the users in the view can change the mathematical model.
Interactive [2] is a free Modelica library that facilitates the implementation of virtual labs based on Modelica models. Interactive Release 2, which can be run in both Dymola and Open-Modelica, is described in [2,3]. Using Interactive 2.0 in combination with OpenModelica, we have a free solution to develop interactive virtual lab based on complex Modelica models. The virtual lab developer only needs to use the Modelica language to describe the virtual-lab view, and to set-up the virtual lab. The Interactive library includes all the code required to generate the graphical user-to model interface (a C++ application) and to perform the communication between the model and the view (through TCP sockets).
The components of Interactive Release 2 have been programmed using Qt 4.8, Qwt 6.1, Qwt-Plot3D and VTK 6.1. The Qt library [4], programmed in C++ and free for non-commercial use, has been used to develop the C++ code corresponding to the windows and the interactive elements (i.e., sliders, check-boxes, etc.). The Qwt and QwtPlot3D libraries [5], which contain Qt widgets for technical applications, have been used to implement 2D and 3D plot widgets. The VTK library [6], written in C++ and open source, has been used for the rendering and the visualization.
We have developed a virtual lab for air pollution control using the Interactive library and the Modelica language. This virtual lab can be executed with Dymola and OpenModelica, and it is currently being used by students taking the course Environmental Chemistry of the degree in Chemistry of the Universidad Nacional de Tucumán (Argentina). It is aimed to analyze the pollutant concentration emitted from large industrial chimneys (i.e. stacks) into the landscape. The pollutant dynamics are determined by: 1) transport, 2) diffusion, 3) chemical transformation, and 4) ground deposition [7,8]. The polluted air coming from the stack is called plume. The plume shape can be influenced by the meteorological conditions and emission factors such as gas temperature at the stack top, stack height, pollutant mass flow rate, or wind velocity. This virtual lab may help students to get insight into the physics that governs the circulation of pollutants in the atmosphere and into the pollutants chemical behavior. The pollutants emitted through a stack source enter the atmosphere and can be transported or dispersed by meteorological conditions. The virtual lab model considers dilution and concentration processes. Students can analyze by using this virtual lab the relationship between the shape of the plume, shown in the virtual lab main window, and the meteorological conditions. Students can set different meteorological conditions, wind speed, emission rate, terrain complexity and stack height, and then visualize the resulting plume shape and analyze the pollutant concentrations.
There are many models of air quality that consider the processes governing the contaminants dispersion and the reactions in the atmosphere [9]. Modeling the atmospheric dispersion is essential to calculate the pollutant concentration at specific points and to analyze how this pollution moves in the atmosphere [10]. These models are used to estimate the pollutants concentration at specified ground-level receptors surrounding an emission source. There are many atmospheric dispersion simulators provided and approved by US Environmental Protection Agency [11]. These simulators typically have as input information about emissions and meteorology and predict pollution concentration at several locations using a dispersion model. Our virtual lab is based on a Gaussian dispersion model. This paper has the following structure. Firstly, the methodology to describe the virtual lab for the air pollution control using Interactive 2.0 is described. Then, the Modelica dispersion model and the steps to implement the user interface are discussed. Finally, the use of the virtual lab is explained.

METHODOLOGY
To implement the complete virtual lab in Modelica it is required to describe: (1) the Modelica model, (2) the view, and (3) the connection between the model and the view. The description of these three elements for the air pollution virtual lab is discussed below.

Description of the air pollution model
The Gaussian plume model is a standard approach for studying the transport of atmospheric pollutants [12,13]. The main assumptions taken to develop this model are the following [14]: -Steady-state conditions, which imply that the emission rate of the source is constant. Pollutant distributions are represented by concentrations on a (regular) three-dimensional grid of points. An orthogonal Cartesian reference system is assumed with its origin corresponding to the base position of the source. The x axis is parallel to the wind direction and the z axis corresponds to the height from the ground direction.
The Gaussian's method employs the Gaussian's normal distribution equation to determine the variation of the pollutant concentrations in the plume by relatively simple calculations. This model has a symmetry axis determined by wind direction, as is illustrated in Figure 1. According to the Gaussian dispersion model, there exists a region of more pollutant concentration and two symmetrical regions. The pollutant concentration in the air in the coordinate (x, y, z) is described by the following equation: where C (x, y, z) is the concentration of pollutant in the air in g/m 3 , Q is the emission rate of the pollutant from the source in g/s, σ y is the horizontal crosswind dispersion coefficient, σ z is the vertical dispersion coefficient, u is the mean speed of the wind in m/s, and H is the effective height of the plume in m. H is computed by adding the additional height to which the hot gases rise above the stack (∆h) to the physical height of the stack (h).
The following equation has to be applied to compute the concentration of a particular component in parts per million (ppm): where C component is the component concentration in ppm, C is the concentration on pollutant in the air in g/m 3 , K is a constant equal to 24.5 at 1 atm and 25 • C, and MW is the molecular weight of the component expressed in g/mol.
The value of the horizontal and vertical dispersion coefficients (σ y and σ z ) depends on the distance from the source and the atmospheric conditions. They can be calculated with different theories: Martin, Briggs, Pasquill, Taylor, etc. We have computed these coefficients using the equations shown in [15]. Pasquill defined the following seven classes of atmospheric stability conditions: A, B, C, D, E and F. The parameters correspond to "very stable" (F class) to "very unstable" (A class). The neutral atmosphere is represented by D. The Martin equations [15] to compute the dispersion coefficients are the following: where x is the distance to the source expressed in km, and a, c, d and f are stability-dependent constants, and b is a constant of value 0.894. The c, d and f constants assume different values depending on x is ≤ or > 1 km. The value of these constants are shown in Table 1.
We suppose that it is only known the wind speed at a height of 10 m (u 10 ) and we compute the mean wind from Eq. (5), where p is a coefficient that depends on the stability class and the media (see Table 2).
The Modelica model has been adapted to suit interactive simulation. A systematic methodology for transforming any Modelica model into a description suitable for interactive simulation was proposed in [16]. Basically, the interactive quantities need to be defined as state variables of the interactive model. For instance, the interactive parameters are defined as state variables with zero time derivative.

Description of the virtual lab view
The Modelica description of the view has been composed using components from the Interactive library. The Interactive library is structured in four packages (see Fig. 2a). VLabModels, ViewElements and Examples contain the Modelica classes that a library user (i.e., the virtual lab developer) will typically employ for developing virtual labs. On the contrary, src contains partial classes and Modelica functions that are not intended to be directly used by the virtual lab developers.
The VLabModels package contains classes that need to be used in the virtual lab view definition and for setting up the complete virtual lab. We have created a new class, named Pollu-tantsView, by extending the PartialView class. The PartialView class includes the root class, a graphic component that hosts the rest of the graphic components, and the code to perform the communication between the model and the view. The required graphic components are dragged and dropped with the mouse from the ViewElements package to the PollutantsView class. Then, they are connected forming a tree structure (see Figure 3). The connections among the graphic components determine their layout in the virtual lab view.
The Modelica description of the graphical interface of this virtual lab is depicted in Figure 3. The graphical user interface generated is shown in Figure 4. The Modelica description of the view (see Figure 3) has a main window (MainWindow class) that hosts a panel of the Panel class on the top, a container of the Canvas class at the center, and another panel of the Panel class at the bottom. These classes are located inside the Container package. The graphical properties of these elements are set in the view definition and they cannot be changed during the simulation run.
The top panel includes objects of the BasicElements and InteractiveControl package that facilitate the user to interact with the model. The model variables can be linked to the state of the graphical components included in the InteractiveControl package. As a result, the value of the linked variable changes accordingly to the interactive changes that the virtual lab user performs on the control element during the simulation run. The top panel contains numerical boxes to set the wind speed (u), the emission flow rate of the stack (Q), the vertical plume rise (∆h) and the stack height (h), and the x, y and z coordinates of the trial point (i.e., a ball inside the volume whose pollutant concentration is shown). Additionally, there are radio-boxes to select the type of pollutant (sulfur dioxide or carbon monoxide), the class of stability, and the type of terrain among five different types (three of rural and two of urban type).
The object of Canvas class include objects of the Drawable package depicting the stack and the pollutant distribution. The geometric and visual properties of these objects (e.g., spatial position, rotation, size, texture and color) can be linked to the model variables, changing during the simulation according to the time evolution of these variables. The stack and the pollutant distribution are represented by an object of the Cylinder and the PlanarGrid classes, respectively. The pollutant distribution is represented as a spatial grid of equal size cuboid cells. Each cell has a different color depending on the pollutant concentration at the center of the cell. An object of the ScalarBar class indicates the relationship between the cell color and its pollutant concentration.
The bottom panel contains two check-boxes. A check-box that allows to display a dialog window with a plot of the pollution concentration at a determined height (z) in the plane (x,y). The other check-box allows to display a dialog window with the virtual lab documentation in HTML format.

Description of the connection between the model and the view
We have created a Modelica class named VLab and we have inserted in it an instance of VirtualLab class, which is included in the VLabModels package of the Interactive library. VirtualLab contains two parameterized generic classes: the classes of the virtual lab model and view. We have written inside the VLab class equations to connect the model and the view variables.
The VLab class is translated using Dymola or OpenModelica, and run. As a part of the model initialization (i.e., the calculations performed to find the initial value of the model variables), the initial sections of the interactive graphic objects and of the PartialView class are executed. These initial sections contain calls to Modelica functions, which encapsulate calls to external C-functions. These C-functions generate the C++ code of the view. As a result, during the model initialization, the C++ code of the virtual lab view is automatically generated. Also, the communication procedure between the model and the view is set up. This communication is based on client-server architecture: the C-program generated by the simulation environment is the server and the C++ program (which is automatically generated during the model initialization) is the client.
During the simulation run, there is a bi-directional flow of information between the model and the view. The communication is as follows. Every communication interval, the model simulation (i.e., the server) sends to the view (i.e., the client) the data required to refresh the view; and the view sends to the model simulation the new value of the variables modified due to the user's interactive action.

DISCUSSION
This virtual lab is aimed to determine the concentration of pollutants (such as sulfur dioxide and carbon monoxide) for particular conditions of wind speed (u), stack height (h) and stability class (A, B , C , D, E , F ) in different terrains. Additionally, students can select the stability class and calculate the pollutant maximum concentration at downwind direction. The effect of the stability class can also be analyzed for different wind speeds (u). The purpose is not the accurate prediction of the pollutants concentration from the site of generation to a site of deposition based on emissions and meteorological data, but to understand the complex relationships among them.
Students taking the Environmental Chemistry course are asked to perform the following activities using this virtual lab and a document with the maximum carbon monoxide and sulfur dioxide allowed during a certain time by the argentinian air quality legislation. 4. Get the minimum value of Q that makes the maximum concentration of CO to be higher that the maximum permitted by the Argentinian legislation.

CONCLUSIONS
This virtual lab can be used as an introduction to mass transport in environmental flows providing an introduction to the physics and chemistry of the atmosphere. Furthermore, this tool allows students to take account of the critical situation of their surrounding and to be strongly involved in sustainable development.
The implementation of this virtual lab is based on the application of a systematic methodology to transform any Modelica model into a formulation suitable for interactive simulation; the Interactive Modelica library, which allows performing the object-oriented description of the virtual lab view and the set-up of the complete virtual lab; and Dymola or OpenModelica, which translates the Modelica description of the virtual lab into an executable file. The use of Modelica reduces considerably the modeling effort, facilitating the code reuse and the development of virtual labs based on complex models. The simulation code generated by Dymola and Open-Modelica is highly efficient. Interactive Release 2 is backward compatible, can be run in both Dymola 2015 and OpenModelica, and is freely available at www.euclides.dia.uned.es.