EnviroSim is pleased to announce the latest issue of “**The BioWin Advantage**” e-tech newsletter. This release discusses Using BioWin’s Model Builder Functionality

DOWNLOAD RELATED FILES |

**Using BioWin’s Model Builder Functionality**

In this issue we will explore the use of BioWin’s Model Builder functionality. This powerful feature can be used to write extensions to BioWin’s core model (on a global or local basis), or to write standalone models to replace those of BioWin if so desired.

**BioWin Files : **

- Full plant with Sidestream N removal – Black Box Model
- SS – Global – ASM1 Example
- SS – Model unit – ASM1 Example

**Model Builder** The BioWin Model Builder provides the user with the ability to build a new model using existing state variables (including BioWin’s four **User Defined Variable**s), or to enhance/modify/extend the BioWin ASDM model. The model builder may be invoked and applied on a local basis by clicking the **Specify local model…** button (if the **Local Builder model** option is selected) on the **Model** tab of the **Model builder element**. Alternatively, the model builder may be invoked and applied on a global basis by selecting the **Model builder…** command from the **Project** menu.

BioWin’s Model Builder editor interface is shown in Figure 1. It is used to enter stoichiometry and kinetic rate equations (along with stoichiometry and rate constants) for user-defined models.

*Figure 1. Model Builder editor interface.*

The user can input the name and notes relating to the user-defined model in the **Model Name** and **Notes** fields, respectively. As the **# of processes** field is changed, the number of rows of the model matrix will expand to allow the user to enter processes which act on the BioWin state variables and the corresponding stoichiometric and kinetic relationships. A powerful equation editor is available for editing stoichiometric and rate equations by double-clicking in either a stoichiometry or rate equation field. All the stoichiometry constants utilized in the stoichiometric relationship between state variables in each process and the rate constants utilized in the rate equations should be defined. These are input using the **Name** and **Value** fields under **Enter constant name and value** heading. After inputting the Name and Value of each constant, the user needs to click either the **Add to rate constants** or **Add to stoich. constants** buttons to categorize the constant.

**Managing models**

The user-defined models that you create can be either project-specific (i.e. they are available only within the project where they were created), or you may save them in “.mod” files to be used in other BioWin projects.

If you create a model using the **Project | Model Builder…** command, then that model will be used by all:

- Model builder elements that you place in your configuration, provided those models do not override this by using a
**Local Builder model**. You can also have individual models that are local to a particular model builder element (select the**Local Builder model**option on the**Model**tab). - Elements that include reactions if you select
**Use project Model Builder model**from the**Project | Current Project Options | Model**tab (Figure2).

If you create a model using the **Specify local model…** button on the **Model** tab of a model builder element, then that model will only be used by that model builder element (Figure 3).

*Figure 2. Model options list in BioWin*

*Figure 3. Model Builder unit in BioWin (top) and Specify local model in the Model Builder unit on the tab of “Model” (bottom)*

Once you have created a model, either in the **Project | Model Builder… **or through **Specify local model…** you can save it using the **Save** or **Save as** buttons as appropriate. Saving a model allows you to **Open** a model in any project, or model builder element.

A number of Builder models are shipped with BioWin. You can access these by opening the **Model Builder** (by selecting **Project | Model** builder… from the main BioWin window). Within the model builder interface there is a **Cabinet models** drop down list; to load a model click the arrow to reveal the list and then click the model you want to use. A model loaded from the **Cabinet models** list can be edited and saved in the normal fashion; this does not impact the underlying template model file (unless you specifically overwrite the template model).

**Example 1: Set up and use ASM 1 in BioWin**

**Set up AMS1 in Model Builder – a step-by-step procedure**

Activated Sludge Model No. 1 (ASM 1) was developed and published by a Task Group of the International Association on Water Pollution Research and Control (IAWPRC), the predecessor of the International Water Association (IWA) (Henze *et al.*, 1987). It is a simple model and is used for teaching and in some cases for model development. The ASM1 matrix is shown in Figure 4.

*Figure 4. ASM 1 Matrix (Henze et al., 1987)*

** Tip:** It can be very helpful for the user to organize the developed model in a matrix such as Figure 4 in a spreadsheet before input to the

**Model Builder**. This approach facilitates checking of model mass balances for each process, etc.

**Step 1: Define BioWin’s corresponding state variables**

ASM 1 includes 13 state variables and 8 processes. 12 of the 13 state variables are also used by BioWin’s ASDM model, although they are named differently. The user only needs to find the corresponding state variables in BioWin and directly use them. The 12 state variables that are used in BioWin ASDM and ASM 1 are listed in Table 1.

*Table 1. State variables used in ASM 1 and the corresponding state variables in BioWin ASDM*

BioWin State Variable Name |
BioWinSymbol |
ASM 1Symbol |
ASM 1 State Variable Name |
Units |

Non-polyP heterotrophic organism mass | Z_{BH} |
X_{BH} |
Active heterotrophic biomass | mgCOD/L |

Autotrophic organism mass | Z_{BA} |
X_{BA} |
Active autotrophic biomass | mgCOD/L |

Endogenous residue from organism decay | Z_{E} |
X_{P} |
Particulate products arising from biomass decay | mgCOD/L |

Slowly biodegradable particulate COD | X_{SP} |
X_{S} |
Slowly biodegradable substrate | mgCOD/L |

Particulate unbiodegradable organic nitrogen | X_{I} |
X_{I} |
Particulate inert organic matter | mgCOD/L |

Particulate biodegradable organic nitrogen | X_{ON} |
X_{ND} |
Particulate biodegradable organic nitrogen | mgN/L |

Soluble readily biodegradable complex COD (non-VFA) | S_{BSC} |
S_{S} |
Readily biodegradable substrate | mgN/L |

Ammonia nitrogen | NH3-N | S_{NH} |
Ammonia and ammonium nitrogen | mgN/L |

Soluble biodegradable organic nitrogen | N_{OS} |
S_{ND} |
Soluble biodegradable organic nitrogen | mgN/L |

Nitrate nitrogen | NO3-N | S_{NO} |
Nitrate and nitrite nitrogen | mgN/L |

Soluble unbiodegradable COD | S_{US} |
S_{I} |
Soluble inert organic matter | mgCOD/L |

Dissolved oxygen | DO | S_{O} |
Oxygen | mgO/L |

The 13^{th} variable of ASM 1 is alkalinity, the capacity of the solution to buffer acid. BioWin does not use alkalinity as a state variable; rather, BioWin calculates pH and alkalinity based on charge and ion balances. Therefore, when the user wants to implement the ASM 1 in BioWin, a **User Defined Variable** has to be used for the alkalinity.

At present, BioWin contains 53 state variables including four **User Defined Variable**s. The definition and naming of those variables can be found in BioWin’s user manual in the **Model reference > Definition of Combined Variables** section. BioWin has four user defined variables and **UD1** and **UD2** have units of mg/L. **UD3** and **UD4** have units of mgVSS/L and mgTSS/L, respectively. In this example, **UD1** is used to represent alkalinity.

** Tip:** There’s no

**User Defined Variable**with a unit of mmol/L or meq/L in BioWin. UD1 and UD2 are variables representing soluble components. To use UD1 to represent alkalinity, the user either assumes it is the alkalinity equivalent in the unit of mmol/L (i.e. BioWin’s unit basis for reporting alkalinity) or needs to multiply the alkalinity equivalent by 50 to convert it to units of mgCaCO

_{3}/L. The original published ASM 1 uses the unit of mmol/L for alkalinity so that convention is followed by this example.

**Step 2: Define stoichiometric and rate constants**

From the ASM 1 matrix (Figure 4), the user can summarize all the stoichiometric and rate constants needed to define the model. The Model Builder editor allows the user to input the **Name** and **Value** of a pre-defined constant.

** Tip:** Remember to click the button of

**Add to rate constants**or

**Add to stoich. constants**after inputting or modifying the constant to add/update it to the corresponding categories.

**Step 3: Define and input stoichiometric relationships**

The user can name the model, for example, “BioWin Advantage Model Builder Example – ASM 1” and set up the **# of processes** (Figure 5).

*Figure 5. Expand the Stoichiometry matrix and Rate_equations.*

The first process of ASM1 is “Aerobic growth of heterotrophs”. The user can enter the process name to replace the default title “Process 1”. In this process, oxygen is the electron acceptor and the soluble readily biodegradable complex COD (S_{S}) is the substrate. Energy will be generated through oxidizing S_{S} and used for microorganism synthesis. The yield of heterotrophs is Y_OHO (mgX_{BH}/mgS_{S}), which should already be defined in Step 2. Organic material (S_{S}) and nutrient (ammonia, S_{NO}) will be consumed during the synthesis; there will also be alkalinity consumption due to the S_{NO} uptake. Every 1 mmol/L of ammonia removal from the liquid will consume 1 meq/L alkalinity; that is, every 1mgN/L S_{NO} removal will reduce 1/14 meq/L alkalinity. The overall stoichiometric relationship for the aerobic growth of heterotrophs is shown below:

To normalize the equation for the generation of 1mgCOD of X_{BH}, the equation can be divided through by the heterotroph yield and written in the following form:

Once the stoichiometric relationship is defined, the user needs to input the stoichiometric coefficients from the above equation into the cells under the corresponding state variables. Recall that UD1 will be used to represent S_{Alk}.

** Tip:** The state variables on the left side of the equation will be consumed in the process so when the user inputs their stoichiometric coefficients into the matrix, a negative sign should be added.

The user can double-click each cell of the stoichiometric matrix to invoke the

**Equation Editor**to input the stoichiometric coefficient one-by-one. Alternatively, if the stoichiometric expression is not complex the user can click once in the cell to edit it and directly type in the equation. In this example, we will input “1”, “-1/Y_OHO”, “-i_N_Bio”, “(1-Y_OHO)/Y_OHO”, and “-i_N_Bio/14” under the state variables Zbh, Sbsc, NH3-N, DO, and UD1, respectively, for the process we have named “Aerobic growth of heterotrophs”. More details about editing in the

**Equation Editor**will be introduced in Step 4.

**Step 4: Define and input the rate equations for each model process**

To input the rate formula of a process, the user should find the row of the corresponding process in the

**Rate equations**section and double-click the cell to invoke the

**Equation Editor**. The equation editor provides you with a window into which you may your equation. You must take care to use proper mathematical syntax when you enter equations. The required syntax is similar to that used when entering mathematical equations in computer code or spreadsheet formulas. For example, say you wanted to change the equation shown above to have the term in brackets multiplied by the constant MiuMax. The following syntax would not be correct, because the multiplication operator is missing:

*Figure 6. Incorrect multiplication syntax.*

The equation shown below, with the correct multiplication syntax would be acceptable:

*Figure 7. Correct multiplication syntax.*

The equation editor also offers the functionality of a right-click popup menu that makes writing your equations much easier. If you right-click your mouse button anywhere within the equation editor window, you will be presented with a popup menu similar to the one shown below (depending on whether the editor was opened from a stoichiometry or a rate equation cell):

*Figure 8. Equation editor right-click popup menu.*

Selecting one of the popup menu choices will open a small window containing a list of variables, constants, or function/operator templates that you can place into your equation. For example, selecting the **Variable** option opens a window that lists the BioWin state variables, shown below:

*Figure 9. State variable selection window.*

To place a variable from this list into your current equation, simply locate the variable in the list and double-click it. The popup window will close, and you will return to your equation, where you will see that the variable has been placed where you had located your cursor. To close a popup window without adding an item to your equation, click the small **x** located in the upper right corner of the popup window. When the user double-clicks an item to add it to the equation, BioWin also adds the item to the Windows clipboard. Pressing **Ctrl+v** will add the item to the equation at another point if desired, until another item is added to the clipboard.

Selecting the **Rate constant** option (when opening the equation editor from a stoichiometry cell) opens a window that lists the rate constants that the user has defined for the model.

Selecting the **Function / operator** option opens a window that lists a number of function / operator templates that the user may place in the equation. To place a function or operator from this list into the current equation, simply locate the function or operator in the list and double-click it. The popup window will close, and the user will return to the equation, where the function or operator template has been placed at the cursor.

*Figure 10. Function/ operator selection window.*

For example, for the first process “Aerobic growth of heterotrophs” of ASM1, the rate of heterotrophic growth will be depending on the availability of substrate S_{S}, electron acceptor S_{O} and the nutrient SN_{O}. The maximum growth rate of heterotrophs is also dependent on temperature. If the user uses the right-click menu **Function/ operator** instead of manually writing the formula, the rate of this process will be input using the **Monod(TD(RateAt20; Theta; Temp), Substrate; Ks**) template Monod rate expression, and also two **Conc Swtich Ks **— Switching function for Conc with Ks. For example:

- Right-click the blank area of the
**Equation editor**, select**Function/ operator**, and select**Monod(TD(RateAt20; Theta; Temp), Substrate; Ks**). Type in an asterisk character for the multiplication operator, and then right-click, select**Function/ operator**, and select**Conc Swtich Ks.**Repeat to insert another**Conc Swtich Ks**.

- Highlight the text
**RateAt20**, right-click, select**Rate constant**, and select the pre-defined rate constant for the maximum growth rate**mu_OHO**to replace**RateAt20**. Similarly, replace**Theta**with the pre-defined rate constant**theta_muOHO**and**Ks**with the pre-defined rate constant**K_SB_OHO**. Highlight**Substate**, right-click, select**Variable**, and select**Sbsc**to replace**Substrate**.

- To define the DO switch, highlight
**Conc**, right-click, select**Variable**and select**DO**. Highlight**Ks**, right-click, select**Rate constant**, and select the pre-defined rate constant for the maximum growth rate**K_O2_OHO**. The updated equation is shown below.

- To define the NH3 switch, highlight
**Conc**, right-click, select**Variable**and select**NH3N**. Highlight**Ks**, right-click, select**Rate constant**, and select the pre-defined rate constant for the maximum growth rate**K_NHx_OHO**. The updated equation is shown below.

- Add another asterisk for multiplication syntax and the variable
**Zbh**for the active heterotrophs to complete the formula

During the edition of the formula, the user can use the **Set position to** button to quickly move the cursor around within the **Equation editor**. The position refers to the number of spaces from the left (or beginning) of a line of text.

To exit the equation editor and accept the changes you have made, the user should click the **Close and update** button. To exit the equation editor without accepting the changes you have made, the user just clicks the small **x** in the upper right hand corner of the equation editor window.

**Step 5: Verifying equations**

As the user enters equations in the model, they should use the **Verify equations…** button to ensure that there are no mistakes in the equations. When the user clicks this button, BioWin checks the equations for undeclared variables and constants (rate and stoichiometric). BioWin also checks the equations for the proper syntax (e.g. missing multiplication operators). Finally, BioWin attempts to calculate the model equations. This may be useful in discovering equation formula errors such as division by zero.

**Step 6: Save the model**

After verifying the model equations, click **OK** to close the **Model Builder Editor** window and save the created model in the current BioWin file. If the user wants to load this model in different BioWin files, they can save the developed model on the computer in a “.mod” file. In this example, the developed model is saved as **ASM1Ex.mod**.

**Set up the influent element for using ASM 1 **

Using a regular BioWin influent adds unnecessary complexity for ASM 1 utilization, because it includes many state variables not recognized by ASM1. Furthermore, the alkalinity represented by UD1 is not included in a regular BioWin influent. BioWin’ State Variable Influent element is ideal for creating an ASM1-compatible influent.

For detailed information on the State Variable Influent element, readers are referred to the **Influent (State Variable)** section of the BioWin manual chapter entitled **Element Types**. The basic concept is that this element allows the user to specify an influent in terms of model state variables. This facility allows the creation of an influent that consists only of components acted upon by ASM 1. Below is an example influent file that accompanies this document.

*Table 2. Example influent*

Component |
Value Used |

Flow | 80 ML/d |

X_{SP} |
310 mgCOD/L |

X_{I} |
65 mgCOD/L |

X_{ON} |
2.79 mgN/L |

S_{BSC} |
100 mgCOD/L |

NH3-N | 30 mgN/L |

N_{OS} |
2.79 mgN/L |

S_{US} |
25 mgCOD/L |

UD1 | 6 mmol/L |

This influent was composed to mimic a typical municipal wastewater. For example, the total COD of the influent is:

tCOD = X_{SP} + X_{I} +S_{BSC} + S_{US} = 310 + 65 + 100 + 25 = 500 mgCOD/L

**Applying the Model Builder model **

**Applying the Model Builder model globally**

To apply the Model Builder model ASM 1, the user has to turn off BioWin’s default ASDM model. Click the “**Model options…**” button in the left bottom corner of the main BioWin window, check the box labelled **User project Model Builder model** and uncheck the boxes labelled **Use BioWin integrated ASDM**, **Include pH calculations** and **Apply pH limitation in activated sludge kinetic equations**. pH and alkalinity calculations in the default BioWin model are not applicable when the user-defined ASM1 model is used because the ASM1 model does not have the capability of pH calculation and alkalinity is considered as a state variable rather than a result of water chemistry. Therefore, the user should ignore pH values reported by BioWin when using the user-defined ASM1 model.

The following configuration shows a conventional activated sludge process set up in BioWin. ASM 1 was used for its simulation. The influent components listed in Table 2 were used.

*Figure 11. A single reactor system with constant input.*

The system is set up to waste at a constant rate to give a system SRT of 3.44 days. A summary view of the steady state solution is shown below.

*Figure 12. State variable values at the steady state condition for the single reactor system with constant input.*

**Applying the Model Builder model locally**

The Model Builder model can be applied locally in Model Builder units if desired, as shown in the Figure 13 below. In this way, the user does not need to check **Use project Model Builder model** under **Model options**, but rather load the ASM1Ex.mod in the Model Builder unit. The simulations results are the same as the results shown in 3.3.1.

*Figure 13. A single reactor system using Model Builder unit.*

**Example 2: Black box model for percentage removal**

In some cases, the underlying mechanics of a treatment element (say for a chemical or physical treatment process acting on specific components) are not well understood and no model has been developed to describe it. The user may still want to include this element in a whole-plant BioWin model, but is only interested in the percentage removal of the specific components. In this case, a “black box” model can be developed and applied locally for this element using the Model Builder unit.

The BioWin file “Full plant with sidestream N removal – blk box model” illustrates an example of applying a black box model to approximate a percentage removal of specific compounds. The configuration is shown below in Figure 14.

*Figure 14. Full plant simulation with a black box model unit for sidestream N removal.*

The wastewater treatment plant configuration includes an MLE (or A/O) process for mainstream nitrogen removal, anaerobic digestion for primary and secondary sludge treatment, and a sidestream treatment process for ammonia removal from the centrate of the digester. In this example, the actual sidestream treatment process has not been specified, but the user wanted to explore the impact of implementing a process that would achieve about 85% ammonia removal.

A “black box” model was developed with only one process for ammonia removal. The stoichiometric relationship is simple: -1 for NH3N. Note that there won’t be a mass balance for N since ammonia will just “disappear”. The rate equation is formed to achieve the expected percentage removal. A Monod-form rate is used so the user has two rate constants, the maximum removal rate R_NH3 and the half-saturation coefficient ks_NH3, to tune the removal rate.

*Figure 15. The “black box” model for sidestream N removal.*

The results are shown in the following Figure 16. The ammonia removal is (545.29 – 83.56)/545.29 = 84.7%, consistent with the user’s expectation. Since only one process is included in the model for ammonia removal, all the other components in the centrate are not touched. Figure 16 also shows the total COD and TSS of the centrate maintain the same values through the Model Builder unit.

*Figure 16. The results of the sidestream N removal element.*

Obviously, the “black box” model is not predictive. The model structure and parameter values are specified for the current element (influent loading, reactor size, removal percentage, *etc.*) and should be double-checked if the operation condition and percentage removal of the element are changed.

**Summary**

We trust that you found this technical topic both interesting and informative. Please feel free to contact us at info@envirosim.com **(Subject: The BioWin Advantage)** with your comments on this article or suggestions for future articles.

Thank you, and good modeling.

**The EnviroSim Team**

To subscribe to “**The BioWin Advantage**” please **click here**.

**Edition Archive**

This section contains earlier editions of BioWin Advantage

- BioWin Advantage 7.3 : Using Function Series in BioWin
- BioWin Advantage 7.2 : Introducing the Granular Sludge Sequencing Tank
- BioWin Advantage 7.1 : Illustrating pH Modeling in BioWin – Titrations of Acids and Bases
- BioWin Advantage 6.1 : Using BioWin’s Model Builder Functionality
- BioWin Advantage 5.2 : Investigating Energy and Operating Cost Implications in BioWin
- BioWin Advantage 5.1 : Simulating the Trickling Filter
- BioWin Advantage 4.1 : Simulating Air and/or Mixing Shut-Off in a Bioreactor
- BioWin Advantage 3.2 : Introducing the Thermal Hydrolysis Unit
- BioWin Advantage 3.1 : SRT Control Under Dynamic Conditions Using BW Controller
- BioWin Advantage 2.5 : VSS/TSS Ratio Across A Primary Settling Tank
- BioWin Advantage 2.4 : Impact of Primary Settling on Wastewater Characteristics
- BioWin Advantage 2.3 : Using a Model Primary Settling Tank
- BioWin Advantage 2.2 : Simulating Upflow Anaerobic Sludge Blanket Reactors
- BioWin Advantage 2.1 : Simulating Step Feed for Storm Events
- BioWin Advantage 1.6 : The Rates Window in BioWin
- BioWin Advantage 1.5 : One Dimensional Settling Models
- BioWin Advantage 1.4 : Most Popular BioWin User Questions
- BioWin Advantage 1.3 : Introducing BioWin Controller
- BioWin Advantage 1.2 : Faster SBR Simulations
- BioWin Advantage 1.1 : Sludge as Model Input

I created a new process in the model builder editor. I want to check what happened with that process after the simulation. Where can I find that option?