Stoat 4.2

37
What’s New in STOAT 4.2 Introduction .................................................................................................................. 3 New Process Models ..................................................................................................... 5 Screening .............................................................................................................................. 5 Grit trap ............................................................................................................................... 6 Sand filtration ...................................................................................................................... 7 UV disinfection .................................................................................................................... 9 Chlorination ....................................................................................................................... 13 Reactive settlers ................................................................................................................. 14 Collocation biofilm models ............................................................................................... 14 Instrumentation ................................................................................................................. 15 Graphical Process Reporting ..................................................................................... 17 User-defined Models................................................................................................... 20 STOAT ASM............................................................................................................... 20 APPENDIX - User-defined Models ........................................................................... 21 File location ........................................................................................................................ 21 Program file ....................................................................................................................... 22 Menu files ........................................................................................................................... 22 Example .............................................................................................................................. 23 Contents of USER.DAT file .............................................................................................. 24 Contents of menu file (“menu.txt”) .................................................................................. 24 Fortran routines ................................................................................................................ 27

Transcript of Stoat 4.2

Page 1: Stoat 4.2

What’s New in STOAT 4.2

Introduction.................................................................................................................. 3

New Process Models..................................................................................................... 5

Screening .............................................................................................................................. 5

Grit trap ............................................................................................................................... 6

Sand filtration...................................................................................................................... 7

UV disinfection .................................................................................................................... 9

Chlorination....................................................................................................................... 13

Reactive settlers ................................................................................................................. 14

Collocation biofilm models ............................................................................................... 14

Instrumentation................................................................................................................. 15

Graphical Process Reporting ..................................................................................... 17

User-defined Models................................................................................................... 20

STOAT ASM............................................................................................................... 20

APPENDIX - User-defined Models ........................................................................... 21

File location........................................................................................................................ 21

Program file ....................................................................................................................... 22

Menu files ........................................................................................................................... 22

Example.............................................................................................................................. 23

Contents of USER.DAT file .............................................................................................. 24

Contents of menu file (“menu.txt”).................................................................................. 24

Fortran routines ................................................................................................................ 27

Page 2: Stoat 4.2
Page 3: Stoat 4.2

3

Introduction

STOAT 4.1 was released in May 1999. This version, STOA4.2, was releasedin August 2001. This release contains many small enhancements andcorrections that have been made in the intervening two years. In addition tothese there have been the following:

♦ There have been several new process models added, and extensions toexisting process models. The range of preliminary and tertiary treatmentmodels has been increased, and there is now support for reactivesecondary clarifiers. In addition, there is a new process model, NIVAPlant,available from the Norwegian Water Research Institute, NIVA. NIVAPlantencompasses the Norwegian knowledge of chemically-assistedsedimentation, both to enhance the removal of TSS and BOD/COD andalso to remove phosphorus. If you wish to add NIVAPlant to your STOATplease contact Harsha Ratnaweera of NIVA at the following e-mailaddress: [email protected]. We would be interested inknowing about your interest in NIVAPlant, or if you have models that youwould like advertised as being available through STOAT. You can e-mailus at [email protected]. This guide includes information on how youcan write your own models to work with STOAT.

♦ At the end of a simulation you can now view the results from the processmodels graphically, as well as tables of summary statistics and timeseries. Where the process has a single stage the results will be displayedas line plots, and multiple stage processes will be displayed as three-dimensional graphs. At present the biofilm models do not supportgraphical output, as this requires four-dimensional graphs – time (T),distance into the biofilm (Y), distance along the reactor (X), and the valueat this (T, Y, X) point.

♦ Support for the DHI/WRc Integrated Catchment Simulator (ICS) andimproved support for Wallingford Software’s InfoWorks system.

♦ The ICS allows you to run simulations using sewer models (MOUSE),sewage works models (STOAT) and river models (MIKE), with dataexchange between the three programs. This provides for a greatimprovement in the support for modelling the feasibility of real-timecontrol of the entire catchment. More information on the ICS can befound by e-mailing WRc at [email protected]

♦ InfoWorks allows you to carry out similar integrated modelling, usingSTOAT along with Wallingford Software’s sewer model HydroWorksand their river model ISIS. These two enhancements further positionSTOAT as the tool designed for ease of use when studying catchment-wide decision modelling.

♦ A spin-off from the DHI ICS system is that there is now a COMinterface that allows STOAT To be controlled by other programs. Thisis currently being used as part of a research project by NIVA to send

Page 4: Stoat 4.2

4

SCADA data to STOAT to examine real-time output as part of onlinecontrol investigations. If you wish to pursue this aspect of STOATplease e-mail us at [email protected]. We will be delighted to helpyou implement controlling STOAT through your own applications,extending this interface as necessary to ensure that you get the bestout of STOAT to meet your own needs.

♦ You can now write your own process models and integrate them intoSTOAT. Details are given in the section introducing user-defined models.We are willing to assist you in getting your first model to work within theSTOAT framework. One valuable feature of the STOAT approach to user-defined models is that they can be written in any computer language ofyour choice, providing that the language can produce dynamic link libraries(DLLs). This means that you can easily use C, C++, Fortran, Pascal/Delphiand some versions of Basic, and even Lisp, SmallTalk or Prolog!

♦ Finally, we will be using our web site, http://www.wrcplc.co.uk/software, toprovide ongoing support. On the web site we will post future upgrades forSTOAT 4.2 – what Microsoft refers to as Service Packs – and also laterreleases of STOAT.

Page 5: Stoat 4.2

5

New Process Models

Screening

The data entry forms are shown below. The bar spacing affects thescreenings production. The screenings production1 can also be changedunder sewage calibration, by choosing either Average or Maximum.Screenings are assumed to be gross solids that are not captured by traditionalsampling methods and therefore the screening model has no effect on thesewage quality passing through it.

1 The model is based on curves of screening production published in RL Droste,Theory and Practice of Water and Wastewater Treatment, Wiley

Page 6: Stoat 4.2

6

Grit trap

The grit trap data entry forms are shown below. At present the volume of thegrit trap has no process significance – all that is required is that be a valuegreater than zero. The grit removal is specified as g/l, and is the removal ofnonvolatile suspended solids from the influent stream.

Page 7: Stoat 4.2

7

Sand filtration

Influent

Bypass

Backwash

Effluent

There are two sand filtration models, Simple and Time varying. Both aremass-balance based models.

The Simple model is a steady-state approximation to the back-washperformance. The bypass stream is never used. You must connect an outletstream to this connector, but there is never any flow down it. For this modelperformance is defined by specifying what fraction of the incoming flow isdiverted as the backwash, and what is the efficiency of solids removal – therecovery fraction. There is a continuous flow through both the backwash andeffluent streams.

The Time varying model also uses a simple equation to calculate theefficiency of solids removal, but now that efficiency may vary over time, andyou also specify a backwash frequency and period – during the backwashperiod all flow is diverted through the bypass line, the backwash stream onlyhas a flow during the backwash period and the effluent stream only has a flowoutside the backwash period. The backwash flow is assumed to come from aclean source, and is not explicitly modelled.

Page 8: Stoat 4.2

8

Operational data entry for the simple model

Operational data entry for the time varying model

The clean efficiency is the efficiency at the start of each operating cycle. Theefficiency falls off with time, but will never fall off below the worst efficiency.The equation relating the fall-off in performance with time is given by

Efficiency = Best efficiency • exp(-fouling coefficient • time)

The phase time is used to set up an operating stagger when several sandfilters are present on the flowsheet.

Page 9: Stoat 4.2

9

UV disinfection

The UV disinfection model is based on a correlation2 from the US WaterEnvironment Research Foundation (WERF). This model uses the UVintensity, which is dependent on the number of UV tubes, their spacing, poweroutput, assumptions about fouling coefficients, etc. The model predicts thecoliform count in the final effluent, not the log removal of coliforms.

The UV intensity in a uniform lamp array can be estimated from the followingchart:

2 FJ Loge et al, 1996, Water Environment Research 68(5) 900-916. Original work inWEF, 1995, Comparison of UV irradiation to chlorination: Guidance for achievingoptimal UV performance, ISBN 95-060880, WEF # 91-WWD-1

Page 10: Stoat 4.2

10

An example of its use is given in the following figure: Start at the spacing axis.Move horizontally left to the UV density in the reactor. Move down until youintersect the appropriate UV absorbance coefficient, α. Move left until youintersect the UV intensity. The UV absorbance coefficient is calculated using

−=

100

nm 254at cm 1over ncetransmitta %UVlog303.2 10α

Page 11: Stoat 4.2

11

Page 12: Stoat 4.2

12

The model can be calibrated by adjusting the WERF parameters, but this willobviously require access to coliform count results.

A:

The WERF model uses the equation

nbaA DUFTTSSCount ⋅⋅⋅=10

where Count = coliform countTSS = total suspended solids, mg/lUFT = unfiltered UV transmissivity, %D = UV dose, mWs/cm2

Because STOAT does not predict the unfiltered UV transmittance this isapproximated by a further correlation on suspended solids, as

UFT = Atransmittance - Btransmittance TSS

Page 13: Stoat 4.2

13

Chlorination

The chlorination model is a simple representation of chlorine kill, using theequation

% Survival = 100 • exp(-kill rate • dose • time)

Page 14: Stoat 4.2

14

Reactive settlers

STOAT has added the following reactive settlers for the secondary settlingtank:

ASAL 1 This should be used with the ASAL 1/1A and OXID 1 aeration tanksASAL 2 This should be used with the ASAL 2/2A and OXID 2 aeration tanksASAL 3 This should be used with the ASAL 3/3A and OXID 3 aeration tanksASAL 5 This should be used with the ASAL 5/5A and OXID 5 aeration tanksASM 1 This should be used with the IAWQ #1 aeration tanksASM 2d This should be used with the IAWQ #2d aeration tanksASM 2w3 This should be used with the IAWQ #2w aeration tanksASM 3 This should be used with the IAWQ #3aeration tanks

When selecting a reactive settler model we recommend that you adopt thefollowing procedure:

1. Set up all the aeration tanks to use the required kinetic model (ASAL 1,IAWWQ #1, etc.)

2. Set up the secondary settlers to use the desired matching kinetic model

3. Close the settler Name and dimensions dialogue, then re-open. On thesecond page of the dialogue you are asked to enter the name of theactivated sludge tank that will be used to pick up the kinetic data. The listof allowable names will be filtered to display only those that are valid forthe chosen settling tank reaction model.

The models ASL 1, ASAL 2 and ASAL 5 are sufficiently simple on their dataneeds that this is repeated under Sewage Calibration rather than being takenfrom the corresponding aeration tank. For the models ASAL 3, ASM 1, ASM2d, ASM 2w and ASM 3 the reaction kinetic parameters are always takenfrom the associated aeration basin.

Collocation biofilm models

New biofilm models have been added, based loosely on collocation equationsfor the soluble components. These models are referred to as BOD coll (1) and

3 The ASM 2w model is a variant of ASM 2d developed by WRc. The model differsfrom the standard ASM 2d model in the handling of the switching function forheterotrophic usage of VFA and fermentable COD. Where the standard model uses

the term (for VFA) of FA

A

AK

A

SS

S

SK

S

+⋅

+, the WRc modification uses

FAFAA

A

KKSSK

S

/⋅++. This change has better mathematical consistency than

the standard ASM 2 version. The ASM 2w model will only show a differencecompared to ASM 2d when there are substantial quantities of VFA in the aerobicsection of the aeration tank.

Page 15: Stoat 4.2

15

COD coll (1). They usually give the same results as the standard finite-difference models, but with substantially reduced computation times4. Wewould recommend that the standard model be used first, and if computationspeed is an issue then you should switch to the collocation method. There willbe small differences between the two models - usually this is negligible,unless the biofilm is close to a nitrifying/non-nitrifying position, when the fullmodel will be more accurate.

Instrumentation

There are two new instrumentation models: noisy probe and delay sampler.

Noisy probe is a generalisation of the first-order probe, but allowing you tospecify that a random amount of noise should be added to the measurements.The noise is calculated from a Normal distribution, and you can use a mixtureof constant noise (independent of the magnitude of the measurement) andvariable noise (related to the size of the measurement).

Delay sampler is a representation of a wet-chemistry type of sampler, wherethere is a large delay between taking a sample and the sample results beingavailable. This model also supports noisy measurements.

4 We are developing further collocation models, where the collocationmethod will also be applied to the particulate components. Thesemodels will be made available in a later release of STOAT.

Page 16: Stoat 4.2

16

Operational data for the noisy probe

The measurement has a level of noise added to it, using two Normalfunctions. The first adds noise independent of the measured value:

For white noise the mean, µ, has the value zero.

The second noise function allows the mean and standard deviation to bedependent on the measured value:

µ = measured value x relative mean

σ = measured value x relative standard deviation

Operational data for the delay sampler

( )σµ,NNoise =

Page 17: Stoat 4.2

17

Graphical Process Reporting

At the end of a simulation you can look at process results graphically. Onselecting the results you will first be presented with a menu allowing you toselect what parameters you want displayed. (In previous versions of STOATyou were always given tabular values of all available parameters, with nochoice.)

After this you can then choose how the data should be displayed – graphicallyor in tables.

Page 18: Stoat 4.2

18

The results will then be displayed. For most processes the graphs will bedisplayed as a three-dimensional plot. For some processes, that only everhave one stage, the results will be presented as simple line graph. Stagedprocesses display one parameter per graph, with a series of tabs allowing youto quickly switch between different parameters.

By right-clicking over the graph you will get a series of menus that allow youto rotate and modify the graph.

Page 19: Stoat 4.2

19

The most useful are likely to be View 3D, which allows you to experiment withrotation and view angles, and Plot cube, which allows you to distort thedifferent axes to better view the image.

Page 20: Stoat 4.2

20

User-defined Models

You can now add your own models to STOAT. More details are given in theappendix.

STOAT ASM

STOAT .2 has a partner product, STOAT ASM – Activated Sludge Model.Many wastewater modellers focus only on activated sludge. For those peoplewe have STOAT ASM as a lower-priced entry into the STOAT world. Anymodels developed by STOAT ASM are fully compatible with the full STOATpackage, and can easily be upgraded to STOAT later. If you need to deliver acopy of your STOAT models to your clients then STOAT ASM may be a low-cost way of handing over a working version for them to use.

Page 21: Stoat 4.2

21

APPENDIX - User-defined Models

This appendix explains the procedure for adding your own models to STOAT. Thereare several steps:

♦ Create your model and compile it in a DLL. The DLL must, in its turn, be called bya DLL that has the name and entry points defined by STOAT. Details are givenbelow.

♦ Create a file that contains all the menu information needed by your model.

♦ Create a bitmap that will be used to display your model.

♦ Update a file used by STOAT that tells STOAT that you have added a newprocess model. Details are given below.

File location

STOAT looks for a file called USER.DAT in the same directory as the projectdatabase. USER.DAT should contain the following:

[USER_MODELS]NAME = <Model name>, CODE = <Model code>, FILE = <Model file>

The NAME = … line can be repeated for as many models as you wish to use.

<Model name> is the name that will be associated with the model. If the namecontains any spaces or commas then it should be enclosed in double quotes (")

<Model code> is a positive integer that will be used to identify the model in the user-written program files.

<Model file> is the location of the dialogue text for this model. If no path is given thenthe file must be in the same directory as USER.DAT. If there are spaces or commasin the filename/path then the entire name should be enclosed in double quotes (").Note that Standard Windows will treat commas in a filename/file path as an illegalcharacter.

The model is compiled and placed in a DLL, or a DLL called from a DLL. The masterDLL that STOAT looks for must be called STOAT_USER.DLL and must be on theexecutable path - this is most commonly achieved by placing the DLL either in\WINDOWS\SYSTEM or in the same place as the STOAT32.EXE file. If you havemultiple copies of this file then Windows normally locates the files in the followingorder: the same place as STOAT32.EXE; any directories specified in the PATHenvironment variable - these directories are searched in the order defined in thePATH statement; or the \WINDOS and \WINDOWS\SYSTEM directories. Werecommend not keeping multiple copies of STOAT_USER.DLL on your computer.

Page 22: Stoat 4.2

22

Program file

For an example of the contents of a program file please study the file BULK1.F90.This indicates

• What parameters are passed from STOAT to STOAT_USER.DLL

• The two entry points that STOAT is looking for: USER and USERS

• How to declare that these entry points are to be made available. Note that thesyntax is specific to Digital/Compaq Visual Fortran and would have to be modifiedif you are using a different Fortran compiler, or a compiler for another language(e.g. C or C++). Also note that the entry points USER and USERS are definedusing an ALIAS command to be exported in 'undecorated' format.

• What parameters can be adjusted, specified using the Fortran attributesintent(in) for parameters that you should not alter and intent(out) for parametersthat are undefined by STOAT and for which you must specify a value - theperformance of STOAT is undefined if you do not set values for theseparameters.

Menu files

The menu file contains information about the screen representation of your model.When no model is specified STOAT will display a question mark in a box. When youspecify a model this will change to the symbol that you have defined for the model. Ifyou add streams to a screen symbol and subsequently change the process to adifferent model with a different number of inlets or outlets then the performance ofSTOAT may be unpredictable. Always settle for the models before addingstreams.

The menu file contains the following information:

[CONNECTIONS]IMAGE = <image file name, usually an icon, but possibly a bitmap>INLETn, NAME = <Name>, X = <X>, Y = <Y>OUTLETn, NAME = <Name>, X = <X>, Y = <Y>

Where n is 1-3: up to 3 inlets and 3 outlets per process.

<Name> is a name that will be used to help users identify connections.

<X> and <Y> are the X and Y co-ordinates for the connections on your image.

[UNIT SPECIFICATION]

This must be specified, even if empty, for STOAT to automatically add an entry forthe number of stages and, optionally, an entry for the number of recycle streams.

NAME = <Name>, MAX = <Max>, MIN = <Min>, DEFUALT = <Default value>

[KINETICS CALIBRATION]

Page 23: Stoat 4.2

23

[INITIAL CONDITIONS]

These follow the same format as above

[RECYCLES]ENABLED

No [RECYCLES] entry means that there will be no user prompts for internal recyclestreams.

[DISTRIBUTION]

This has the same format as for unit specification, but with an optional SUM =<Sum> keyword if the sum of values for a stage must equal some defined number -typically 1, where the values are fractional distributions across the stages (e.g.,volume fractions).

[DERIVED PARAMETERS]NAME = <Name>

The derived parameters are defined for each stage.

Example

The following material gives an example of implementing a model for bulkingactivated sludge (See “Low F/M bulking model” of J. Kapeller and R.Brodman, 1995,Water Science and technology 31(2), 225 ff. for more details) . Sample output fromthe model is given in the following figure.

Page 24: Stoat 4.2

24

Contents of USER.DAT file;; USER.DAT -- master user model file;[USER_MODELS]NAME = "Bulking model", CODE = 100, FILE = "menu.txt"

Contents of menu file (“menu.txt”);; Dialog data for bulking model;[CONNECTIONS]IMAGE = "bulk1.ico"INLET1, NAME = "Sewage", X = 0, Y = 7INLET2, NAME = "RAS", X = 0, Y = 15OUTLET1, NAME = "Outlet", X = 31, Y = 10

[UNIT SPECIFICATION]; Nothing to add to defaults.; Must be defined (even empty) to indicate that; this menu option is wanted

[KINETICS CALIBRATION]NAME = "Mu max floc formers @ 15C", MIN = 0, MAX = 1, DEFAULT = 0.125NAME = "Temp coeff.", MIN = 0, MAX = 0, DEFAULT = 0NAME = "Mu max filaments @ 15C", MIN = 0, MAX = 1, DEFAULT = 0.08333NAME = "Temp coeff.", MIN = 0, MAX = 1, DEFAULT = 0NAME = "Mu max Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.0333NAME = "Temp coeff.", MIN = 0, MAX = 1, DEFAULT = 0NAME = "Mu max Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.05NAME = "Temp coeff.", MIN = 0, MAX = 1, DEFAULT = 0NAME = "Death rate, floc formers", MIN = 0, MAX = 10, DEFAULT = 0.021NAME = "Temp coeff.", MIN = 0, MAX = 1, DEFAULT = 0NAME = "Deat rate, filaments", MIN = 0, MAX = 1, DEFAULT = 0.0125NAME = "Temp coeff.", MIN = 0, MAX = 1, DEFAULT = 0NAME = "Death rate, Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.00417NAME = "Temp coeff.", MIN = 0, MAX = 1, DEFAULT = 0NAME = "Death rate, Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.00625NAME = "Temp coeff.", MIN = 0, MAX = 1, DEFAULT = 0NAME = "Yield, floc formers", MIN = 0, MAX = 1, DEFAULT = 0.63NAME = "Yield, filaments", MIN = 0, MAX = 1, DEFAULT = 0.63NAME = "Yield, Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.21NAME = "Yield, Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.03NAME = "O2 switch, floc formers", MIN = 0, MAX = 1, DEFAULT = 0.25NAME = "O2 switch, filaments", MIN = 0, MAX = 1, DEFAULT = 0.1NAME = "O2 switch, Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.5NAME = "O2 switch, Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.5NAME = "O2 suppression on NO2", MIN = 0, MAX = 1, DEFAULT = 0.1NAME = "O2 supression on NO", MIN = 0, MAX = 1, DEFAULT = 0.05NAME = "Switch for growth on SH", MIN = 0, MAX = 10, DEFAULT = 1NAME = "Switch for nitrite growth on SH", MIN = 0, MAX = 10, DEFAULT = 5NAME = "Switch, flocs, on SL", MIN = 0, MAX = 10, DEFAULT = 5NAME = "Switch, filaments, on SL", MIN = 0, MAX = 10, DEFAULT = 1NAME = "Switch, flocs, on SL and nitrite", MIN = 0, MAX = 10, DEFAULT = 10NAME = "Switch, flocs, on NH4", MIN = 0, MAX = 10, DEFAULT = 0.01NAME = "Switch, filaments, on NH4", MIN = 0, MAX = 10, DEFAULT = 0.01NAME = "Switch, Nitrosomonas, on NH4", MIN = 0, MAX = 10, DEFAULT = 0.01NAME = "Switch, Nitrobacter, on NH4", MIN = 0, MAX = 10, DEFAULT = 0.01NAME = "Switch on NO", MIN = 0, MAX = 10, DEFAULT = 0.5NAME = "Switch on NO3", MIN = 0, MAX = 10, DEFAULT = 0.5NAME = "Switch on NO2, flocs", MIN = 0, MAX = 10, DEFAULT = 0.5NAME = "Switch on NO2, Nitrobacter", MIN = 0, MAX = 10, DEFAULT = 0.5NAME = "beta1", MIN = 0, MAX = 10, DEFAULT = 1NAME = "beta2", MIN = 0, MAX = 10, DEFAULT = 0.8NAME = "beta3", MIN = 0, MAX = 10, DEFAULT = 0.8

Page 25: Stoat 4.2

25

NAME = "beta4", MIN = 0, MAX = 10, DEFAULT = 1NAME = "beta5", MIN = 0, MAX = 10, DEFAULT = 1NAME = "beta6", MIN = 0, MAX = 10, DEFAULT = 1.67NAME = "beta7", MIN = 0, MAX = 10, DEFAULT = 1.67NAME = "O2 consumed per NO2", MIN = 0, MAX = 10, DEFAULT = 3.22NAME = "O2 consumed per NO3", MIN = 0, MAX = 10, DEFAULT = 1.11NAME = "N/COD, floc", MIN = 0, MAX = 1, DEFAULT = 0.06NAME = "N/COD, filament", MIN = 0, MAX = 1, DEFAULT = 0.06NAME = "N/COD, Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.06NAME = "N/COD, Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.06NAME = "N/COD in lysis, floc", MIN = 0, MAX = 1, DEFAULT = 0.054NAME = "N/COD in lysis, filament", MIN = 0, MAX = 1, DEFAULT = 0.054NAME = "N/COD in lysis, Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.054NAME = "N/COD in lysis, Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.054NAME = "N/COD in XH", MIN = 0, MAX = 1, DEFAULT = 0.05NAME = "N/COD in XL", MIN = 0, MAX = 1, DEFAULT = 0.02NAME = "Release of SH by lysis, floc", MIN = 0, MAX = 1, DEFAULT = 0.8NAME = "Release of SH by lysis, filament", MIN = 0, MAX = 1, DEFAULT = 0.8NAME = "Release of SH by lysis, Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.8NAME = "Release of SH by lysis, Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.8NAME = "Release of SL by lysis, floc", MIN = 0, MAX = 1, DEFAULT = 0.1NAME = "Release of SL by lysis, filament", MIN = 0, MAX = 1, DEFAULT = 0.1NAME = "Release of SL by lysis, Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.1NAME = "Release of SL by lysis, Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.1NAME = "Release of Xsurf by lysis, floc", MIN = 0, MAX = 1, DEFAULT = 0.02NAME = "Release of Xsurf by lysis, filament", MIN = 0, MAX = 1, DEFAULT = 0.02NAME = "Release of Xsurf by lysis, Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.02NAME = "Release of Xsurf by lysis, Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.02NAME = "Release of XI by lysis, floc", MIN = 0, MAX = 1, DEFAULT = 0.08NAME = "Release of XI by lysis, filament", MIN = 0, MAX = 1, DEFAULT = 0.08NAME = "Release of XI by lysis, Nitrosomonas", MIN = 0, MAX = 1, DEFAULT = 0.08NAME = "Release of XI by lysis, Nitrobacter", MIN = 0, MAX = 1, DEFAULT = 0.08NAME = "Hydrolysis rate, XH", MIN = 0, MAX = 10, DEFAULT = 0.208NAME = "Temp. coeff", MIN = 0, MAX = 10, DEFAULT = 0, DEFAULT = 0NAME = "Hydrolysis rate, XL", MIN = 0, MAX = 10, DEFAULT = 0.208NAME = "Temp coeff.", MIN = 0, MAX = 10, DEFAULT = 0, DEFAULT = 0NAME = "Degradation rate, XSurf", MIN = 0, MAX = 10, DEFAULT = 0.208NAME = "Temp coeff.", MIN = 0, MAX = 10, DEFAULT = 0, DEFAULT = 0NAME = "betaH", MIN = 0, MAX = 10, DEFAULT = 0.4NAME = "betaL", MIN = 0, MAX = 10, DEFAULT = 0.4NAME = "beta_surf", MIN = 0, MAX = 10, DEFAULT = 0.4NAME = "KXSurf", MIN = 0, MAX = 10, DEFAULT = 0.5NAME = "TSS to COD ratio, biomass", MIN = 0, MAX = 1, DEFAULT = 0.75NAME = "XI released by hydrolysis of XH", MIN = 0, MAX = 1, DEFAULT = 0NAME = "XI released by hydrolysis of XL", MIN = 0, MAX = 1, DEFAULT = 0NAME = "KO2Hyd", MIN = 0, MAX = 10, DEFAULT = 0.25NAME = "KNO3Hyd", MIN = 0, MAX = 10, DEFAULT = 0.5NAME = "KO2Surf", MIN = 0, MAX = 10, DEFAULT = 0.25NAME = "KNO3Surf", MIN = 0, MAX = 10, DEFAULT = 0.5

[INITIAL CONDITIONS]NAME = "Temperature", MIN = 0, MAX = 30NAME = "Oxygen", MIN=0, MAX = 10NAME = "SH", MIN = 0, MAX = 1E6NAME = "SL", MIN = 0, MAX = 1E6NAME = "SI", MIN = 0, MAX = 1E6NAME = "NH4", MIN = 0, MAX = 1E6NAME = "NO3", MIN = 0, MAX = 1E6NAME = "NO2", MIN = 0, MAX = 1E6NAME = "NO", MIN = 0, MAX = 1E6NAME = "XF", MIN = 0, MAX = 1E6, DEFAULT = 100NAME = "XB", MIN = 0, MAX = 1E6, DEFAULT = 100NAME = "XNS", MIN = 0, MAX = 1E6, DEFAULT = 10NAME = "XNB", MIN = 0, MAX = 1E6, DEFAULT = 10NAME = "XH", MIN = 0, MAX = 1E6NAME = "XL", MIN = 0, MAX = 1E6NAME = "XSurf", MIN = 0, MAX = 1E6

Page 26: Stoat 4.2

26

NAME = "XI", MIN = 0, MAX = 1E6NAME = "XNVS", MIN = 0, MAX = 1E6NAME = "Integral error", MIN = 0, MAX = 1E6

[RECYCLES]ENABLED ; indicates that recycles are to be used.

[DISTRIBUTION]NAME = "Volume", MIN=0, MAX = 1E6NAME = "Sewage distribution", MIN = 0, MAX = 1, SUM = 1NAME = "RAS distribution", MIN = 0, MAX = 1, SUM = 1NAME = "Alpha value", MIN = 0.5, MAX = 1.2, DEFAULT = 1NAME = "Beta value", MIN = 0.5, MAX = 1.2, DEFAULT = 1NAME = "Theta value", MIN = 1, MAX = 2, DEFAULT = 1.024NAME = "Min KLa", MIN = 0, MAX = 20, DEFAULT = 0NAME = "Max KLa", MIN = 0, MAX = 20, DEFAULT = 10NAME = "DO setpoint", MIN = 0, MAX = 10, DEFAULT = 2NAME = "Gain", MIN = 0, MAX = 10, DEFAULT = 1NAME = "Integral time", MIN = 1, MAX = 10, DEFAULT = 1

[DERIVED PARAMETERS]NAME = "KLa"NAME = "O2 demand"NAME = "OUR"NAME = "NUR"

Page 27: Stoat 4.2

27

Fortran routines! In these two routines, USER is used to specify the values for the! differential equations DY()/dy = f(Y(), ...)! USER should NOT be used to assign values to the streams.!! USERS is used to specify values for the outlet streams.! It should not be used to specify values for any other parameters,! with the possible exception of DERIVED().!

!DEC$ ATTRIBUTES DLLEXPORT:: User!DEC$ ATTRIBUTES ALIAS: 'USER':: Usersubroutine user(in1, in2, in3, out1, out2, out3, & model, NoStages, NoRecycles, & CalibUnit, CalibSwg, Calibswitch, CalibStoic, & Recycles, Distribution, Operation, & y, dy, derived, s1, s2, t)include 'stream.fi'record /Stream/ in1, in2, in3record /Stream/ out1, out2, out3integer modelinteger NoStagesinteger NoRecyclesdouble precision CalibUnit(*)double precision CalibSwg(*)double precision CalibStoic(*)double precision CalibSwitch(*)double precision Recycles(3,*)double precision Distribution(NoStages, *)double precision Operation(*)double precision y(NoStages, *)double precision dy(NoStages, *)double precision derived(NoStages, *)double precision s1double precision s2double precision t

intent (in) :: in1, in2, in3, out1, out2, out3intent (in) :: model, NoStages, NoRecyclesintent (in) :: CalibUnit, CalibSwg, CalibStoic, CalibSwitchintent (in) :: Recycles, Distribution, Operationintent (in) :: yintent (out) :: dyintent (inout) :: derivedintent (in) :: s1, s2, t!! Up to 3 inlet streams and 3 outlet streams. If a user model does! not use a stream then the value for that stream is undefined, and! should not be accessed by that model.!! MODEL contains the user-specified ID number.! NoStages is the number of stages.! Norecycles is the number of recycles.! CalibUnit() contains the unit calibration data in the order specified! by the dialogue data file.! CalibSwg() contains the main sewage calibration data in the order! specified by the dialogue data file.! CalibStoic() contains additional stoichiometric data if specified! by the dialogue data file.! Calibswitch() contains additional switching data if specified! by the dialogue data file.! Recycles() contains the recycle data, in the form of triplets:! From stage, To stage, Stage flow.! Distribution() contains the stage distribution data.! Operation() contains operational data in the order specified by! the dialogue data file. If any operational data was listed as

Page 28: Stoat 4.2

28

! being staged, then this will be repeated NoStages times.! Y() contains the current computed values for the model.! DY() should, on exit from this routine, contain the current values! for the time derivative.! Derived() contains computed values. These may have been set in the! companion routine USERS or may be set here. Derived() is! used to pass information that is not specified by differential! equations.! s1 is the ratio of BOD removed per unit of volatile solids, excluding! biomass, removed. The BOD removed may be converted to soluble! BOD rather than being oxidised.! s2 is the ratio of BOD removed per unit of biomass removed.! t is the current integration time.!

select case (model)case (100) ! Call the appropriate routine call bulk1(in1, in2, NoStages, NoRecycles, & CalibSwg, Recycles, Distribution, & y, dy, Derived, s2)end select

end

!DEC$ ATTRIBUTES DLLEXPORT:: Users!DEC$ ATTRIBUTES ALIAS: 'USERS':: Userssubroutine users(in1, in2, in3, out1, out2, out3, & model, NoStages, NoRecycles, & CalibUnit, CalibSwg, Calibswitch, CalibStoic, & Recycles, Distribution, Operation, & y, derived, s1, s2, t)include 'stream.fi'record /Stream/ in1, in2, in3record /Stream/ out1, out2, out3integer modelinteger NoStagesinteger NoRecyclesdouble precision CalibUnit(*)double precision CalibSwg(*)double precision CalibStoic(*)double precision CalibSwitch(*)double precision Recycles(3,*)double precision Distribution(NoStages, *)double precision Operation(*)double precision y(NoStages, *)double precision derived(NoStages, *)double precision s1double precision s2double precision t

intent (in) :: in1, in2, in3intent (in ) :: out1, out2, out3intent (in) :: model, NoStages, NoRecyclesintent (in) :: CalibUnit, CalibSwg, CalibStoic, CalibSwitchintent (in) :: Recycles, Distribution, Operationintent (in) :: yintent (inout) :: derivedintent (in) :: s1, s2, t

select case (model)case (100) ! Call the appropriate routine call bulk1_output(NoStages, in1, in2, out1, CalibSwg, y, s1)end select

end

!! Low F/M bulking model of J. Kapeller and R.Brodman, 1995

Page 29: Stoat 4.2

29

! Water Science and technology 31(2), 225 ff.!! The Kapeller model has been extended by adding a term for nonvolatilesolids!! Contents of p()! Number of stages [NS]! Number of MLSS recycles [NR]! NR FROM recycle stage! NR TO recycle stage! NR recycle flow! NS stage volumes! NS feed distribution (sums to 1.0)! NS RAS distribution (sums to 1.0)! NS alpha values! NS beta values! NS theta values! NS minimum KLa values! NS maximum KLa values! NS DO setpoints! NS proportional gains! NS integral times! (Start of reaction parameters)!subroutine bulk1(in1, in2, NumberOfStages, NumberOfRecycles, & CalibSwg, Recycles, Distribution, y, dy, x, s2)implicit noneinclude 'stream.fi'

record /stream/ in1, in2integer:: NumberOfStages, NumberOfRecyclesdouble precision:: CalibSwg(*), Recycles(3, NumberOfRecycles), & Distribution(NumberOfStages, 11), & y(NumberofStages, 19), dy(NumberofStages, 19), & x(NumberOfStages, 4), s2! Internal variables double precision, dimension(NumberofStages):: KLa20 integer:: Stage

KLa20 = Distribution(:, 10) * ( (Distribution(:, 9) - y(:, 2)) & + Distribution(:, 11) * y(:, 19))

dy(:, 19) = Distribution(:, 9) - y(:, 2) do Stage = 1, NumberOfStages if ( KLa20(Stage) > Distribution(Stage, 8) & .and. dy(Stage, 19) > 0) then KLa20(Stage) = Distribution(Stage, 8) dy(Stage, 19) = 0d0 elseif ( KLa20(Stage) < Distribution(Stage, 7) & .and. dy(Stage, 19) < 0) then KLa20(Stage) = Distribution(Stage, 7) dy(Stage, 19) = 0d0 end if end do

call bulk1_hydraulics(in1, in2, y(1,1), dy(1,1), & y(:, 2:18), dy(:, 2:18), & NumberOfStages, & Distribution(:, 1), & Distribution(:, 2), & Distribution(:, 3), & s2, Recycles(1, :), & Recycles(2, :), & Recycles(3, :), & NumberOfRecycles)

x(:, 1) = KLa20 dy(:, 1) = dy(1, 1)

Page 30: Stoat 4.2

30

call bulk1_kinetics(NumberOfStages, y(1,1), y(:, 2:18), dy(:, 2:18), & Distribution(:, 1), KLa20, & Distribution(:, 6), & Distribution(:, 4), & Distribution(:, 5), & CalibSwg, & x(:, 2), x(:, 3), x(:, 4), s2)

end

subroutine bulk1_output(NumberofStages, in1, in2, out, p, y, s1)implicit noneinclude 'stream.fi'integer:: NumberofStagesrecord /stream/ in1, in2, outdouble precision:: p(*), y(NumberOfStages, 19)

double precision:: iTSSBM, s1

out.flow = in1.flow + in2.flow

iTSSBM = p(85)

out.t = y(1, 1)out.pH = 7d0

out.c.o2 = y(NumberOfStages, 2) out.c.sbod = y(NumberOfStages, 3) out.c.vfa = y(NumberOfStages, 4) out.c.scod = y(NumberOfStages, 5) out.c.nh3 = y(NumberOfStages, 6) out.c.no3 = y(NumberOfStages, 7) out.c.no2 = y(NumberOfStages, 8) out.c.son = y(NumberOfStages, 9) out.c.xvih = y(NumberOfStages, 10) * iTSSBM out.c.xnvh = y(NumberOfStages, 11) * iTSSBM out.c.xvia = y(NumberOfStages, 12) * iTSSBM out.c.xnva = y(NumberOfStages, 13) * iTSSBM out.c.xbod = Sum(y(NumberOfStages, 10:14)) out.c.phb1 = y(NumberOfStages, 15) ! 'low' MW out.c.phb2 = y(NumberOfStages, 16) ! 'surfactants' out.c.xcod = y(NumberOfStages, 17) ! 'inerts' out.c.xnvs = y(NumberOfStages, 18) out.c.xvs = out.c.xvih + out.c.xnvh + out.c.xvia + out.c.xnva & + Sum(y(NumberOfStages, 14:17)) / s1

end

subroutine bulk1_hydraulics(sin, sRAS, T, dT, y, dy, NumberOfStages, & Volume, Feed, RASFeed, s2, From, To, Q, & NumberOfRecycles)implicit noneinclude 'stream.fi'record /stream/ sin, sRASinteger:: NumberOfStagesinteger:: NumberOfRecyclesdouble precision:: T, dTdouble precision:: s2 ! biomass COD:VSS ratiodouble precision, dimension(NumberOfStages, 17):: y, dydouble precision, dimension(NumberOfStages):: Volume, Feed, RASFeed, & From, To, Q

! Local variablesdouble precision:: Qin, QRAS, QSewagedouble precision:: XBOD1, XBOD2integer:: Stage, FromStage, ToStage, idouble precision:: QMLSS, Q1, Q2

Page 31: Stoat 4.2

31

QSewage = sin.flowQRAS = sRAS.flow

dT = QSewage * sin.T + QRAS * sRAS.T - (QRAS + QSewage) * TdT = dT / sum(Volume)

dy = 0d0Qin = 0d0do Stage = 1, NumberOfStages Q1 = Qsewage * Feed(Stage) Q2 = QRAS * RASFeed(Stage)

dy(Stage, 1) = Q1 * sin.c.o2 + Q2 * sRAS.c.o2 dy(Stage, 2) = Q1 * sin.c.sbod + Q2 * sRAS.c.sbod! Volatile fatty acid term in STOAT used to hold the low molecular weightsoluble! degradable COD fraction in Kapeller's model. dy(Stage, 3) = Q1 * sin.c.vfa + Q2 * sRAS.c.vfa dy(Stage, 4) = Q1 * sin.c.scod + Q2 * sRAS.c.scod dy(Stage, 5) = Q1 * sin.c.nh3 + Q2 * sRAS.c.nh3 dy(Stage, 6) = Q1 * sin.c.no3 + Q2 * sRAS.c.no3 dy(Stage, 7) = Q1 * sin.c.no2 + Q2 * sRAS.c.no2! Soluble degradable organic nitrogen fraction in STOAT used to hold the! dissolved nitrous oxide (NO) component in Kapeller's model dy(Stage, 8) = Q1 * sin.c.son + Q2 * sRAS.c.son! Mapping STOAT components to Kapeller's model::! Viable heterotrophs (XVIH) : Floc formers! Nonviable heterotrophs (XNVH) : 'Bulking' biomass! Viable autotrophs (XVIA) : Nitrosomonas! Nonviable autotrophs (XNVA) : Nitrobacter! Degradable particulate COD (XBOD): High-molecular weight particulate cOD! Stored PHB (PHB1) : Low-molecular weight particulate COD! Stored PHB (PHB2) : Surfactant COD! Nondegradable COD (XCOD) : Nondegradable COD dy(Stage, 9) = Q1 * s2 * sin.c.XVIH + Q2 * s2 * sRAS.c.XVIH dy(Stage, 10) = Q1 * s2 * sin.c.XNVH + Q2 * s2 * sRAS.c.XNVH dy(Stage, 11) = Q1 * s2 * sin.c.XVIA + Q2 * s2 * sRAS.c.XVIA dy(Stage, 12) = Q1 * s2 * sin.c.XNVA + Q2 * s2 * sRAS.c.XNVA!! Biomass COD was added to XBOD to ensure that the COD balance is correctly! reported. In STOAT the biomass terms are reported as having units! of suspended solids, not COD. We must subtract the! biomass COD from XBOD before assigning it to the! XH fraction in kapeller's model! XBOD1 = sin.c.xbod & - s2 * (sin.c.xvih + sin.c.xnvh + sin.c.xvia + sin.c.xnva) XBOD2 = sRAS.c.xbod & - s2 * (sRAS.c.xvih + sRAS.c.xnvh + sRAS.c.xvia + sRAS.c.xnva) dy(Stage, 13) = Q1 * XBOD1 + Q2 * XBOD2 dy(Stage, 14) = Q1 * sin.c.phb1 + Q2 * sRAS.c.phb1 dy(Stage, 15) = Q1 * sin.c.phb2 + Q2 * sRAS.c.phb2 dy(Stage, 16) = Q1 * sin.c.xcod + Q2 * sRAS.c.xcod dy(Stage, 17) = Q1 * sin.c.xnvs + Q2 * sRAS.c.xnvs

if (Stage > 1) then dy(Stage, :) = dy(Stage, :) + Qin * y(Stage - 1, :) end if

! Add internal recycle flows Qin = Q1 + Q2 + Qin do i = 1, NumberOfRecycles FromStage = From(i) ToStage = To(i) QMLSS = Q(i) if (QMLSS < 0) QMLSS = abs(QMLSS) * Qsewage if (FromStage .eq. Stage) then Qin = Qin - QMLSS

Page 32: Stoat 4.2

32

dy(Stage, :) = dy(Stage, :) - QMLSS * y(Stage, :) elseif (ToStage .eq. Stage) then Qin = Qin + QMLSS dy(Stage, :) = dy(Stage, :) + QMLSS * y(FromStage, :) end if end do

dy(Stage, :) = dy(Stage, :) - Qin * y(Stage, :)

end do

! Now divide by volumesdo Stage = 1, NumberOfStages dy(Stage,:) = dy(Stage,:) / Volume(Stage)end do

end

subroutine bulk1_kinetics(NumberOfStages, T, y, dy, & Volume, KLa20, Theta, Alpha, Beta, p, & QO2, OUR, NUR, s2)implicit noneinteger, parameter:: NumberOfComponents = 17integer, parameter:: NumberOfReactions = 21

integer:: NumberOfStagesdouble precision:: Tdouble precision, dimension(NumberOfStages, NumberofComponents):: y, dydouble precision, dimension(NumberOfStages):: Volume, Alpha, Beta, & KLa20, Theta, QO2, OUR, NURdouble precision:: p(82)double precision:: s2

! Local variablesdouble precision:: Rho(NumberOfReactions) = 0d0double precision:: S(NumberOfComponents, NumberOfReactions) = 0d0double precision, dimension (NumberOfStages):: KLa

double precision:: mumaxF, mumaxB, mumaxNS, mumaxNBdouble precision:: bF, bB, bNS, bNBdouble precision:: YF, YB, YNS, YNBdouble precision:: KO2F, KO2B, KO2NS, KO2NB, KO2NO, KO2NO2double precision:: KH, KHNO2double precision:: KLF, KLB, KLFNO2double precision:: KNH4F, KNH4B, KNH4NS, KNH4NBdouble precision:: KNO, KNO3, KNO2, KNO2NBdouble precision:: beta1, beta2, beta3, beta4, beta5, beta6, beta7double precision:: betaH, betaL, beta_surfdouble precision:: iNO2, iNO3double precision:: iXBF, iXBB, iXBNS, iXBNBdouble precision:: iLysF, iLysB, iLysNS, iLysNBdouble precision:: iNHdouble precision:: iNLdouble precision:: fLHF, fLHB, fLHNS, fLHNBdouble precision:: fLLF, fLLB, fLLNS, fLLNBdouble precision:: fLSF, fLSB, fLSNS, fLSNBdouble precision:: fIF, fIB, fINS, fINBdouble precision:: kHi, kLo, kS, kXSurfdouble precision:: iTSSBMdouble precision:: fH, fLdouble precision:: KO2Hyd, KNO3Hyd, KO2Surf, KNO3Surf

integer:: Stage, Reaction, Compdouble precision:: SO2, SH, SL, SI, SNH4, SNO3, SNO2, SNOdouble precision:: XF, XB, XNS, XNB, XH, XL, XS, XI

KLa = KLa20 * Theta**(T - 20d0)

Page 33: Stoat 4.2

33

!! Assign kinetic values!mumaxF = p( 1) * exp(p( 2) * (T - 15d0))mumaxB = p( 3) * exp(p( 4) * (T - 15d0))mumaxNS = p( 5) * exp(p( 6) * (T - 15d0))mumaxNB = p( 7) * exp(p( 8) * (T - 15d0))bF = p( 9) * exp(p(10) * (T - 15d0))bB = p(11) * exp(p(12) * (T - 15d0))bNS = p(13) * exp(p(14) * (T - 15d0))bNB = p(15) * exp(p(16) * (T - 15d0))YF = p(17)YB = p(18)YNS = p(19)YNB = p(20)KO2F = p(21)KO2B = p(22)KO2NS = p(23)KO2NB = p(24)KO2NO2 = p(25)KO2NO = p(26)KH = p(27)KHNO2 = p(28)KLF = p(29)KLB = p(30)KLFNO2 = p(31)KNH4F = p(32)KNH4B = p(33)KNH4NS = p(34)KNH4NB = p(35)KNO = p(36)KNO3 = p(37)KNO2 = p(38)KNO2NB = p(39)beta1 = p(40)beta2 = p(41)beta3 = p(42)beta4 = p(43)beta5 = p(44)beta6 = p(45)beta7 = p(46)iNO2 = p(47)iNO3 = p(48)iXBF = p(49)iXBB = p(50)iXBNS = p(51)iXBNB = p(52)iLysF = p(53)iLysB = p(54)iLysNS = p(55)iLysNB = p(56)iNH = p(57)iNL = p(58)fLHF = p(59)fLHB = p(60)fLHNS = p(61)fLHNB = p(62)fLLF = p(63)fLLB = p(64)fLLNS = p(65)fLLNB = p(66)fLSF = p(67)fLSB = p(68)fLSNS = p(69)fLSNB = p(70)fIF = p(71)fIB = p(72)

Page 34: Stoat 4.2

34

fINS = p(73)fINB = p(74)kHi = p(75) * exp(p(76) * (T - 15d0))KLo = p(77) * exp(p(78) * (T - 15d0))KS = p(78) * exp(p(80) * (T - 15d0))betaH = p(81)betaL = p(82)beta_surf = p(83)KXSurf = p(84)iTSSBM = p(85)fH = p(86)fL = p(87)KO2Hyd = p(88)KNO3Hyd = p(89)KO2Surf = p(90)KNO3Surf = p(91)!! Define stoichiometry matrix!

! O2s( 1, 1) = -(1d0 - YF) / YFs( 1, 2) = -(1d0 - YF) / YFs( 1, 10) = -(1d0 - YB) / YBs( 1, 12) = -iNO2 / YNSs( 1, 14) = -iNO3 / YNB

! SH -- high molecular wieght, solubles( 2, 1) = -1d0 / YFs( 2, 3) = -1d0 / YFs( 2, 5) = -1d0 / YFs( 2, 7) = -1d0 / YFs( 2, 9) = fLHFs( 2, 11) = fLHBs( 2, 13) = fLHNSs( 2, 15) = fLHNBs( 2, 16) = 1d0 - fHs( 2, 18) = 1d0 - fH

! SL -- low molecular weight, solubles( 3, 2) = -1d0 / YFs( 3, 4) = -1d0 / YFs( 3, 6) = -1d0 / YFs( 3, 8) = -1d0 / YFs( 3, 9) = fLLFs( 3, 11) = fLLBs( 3, 13) = fLLNSs( 3, 15) = fLLNBs( 3, 17) = 1d0 - fLs( 3, 19) = 1d0 - fL

! SI -- nondegradable, solubles( 4, 16) = fHs( 4, 17) = fLs( 4, 18) = fHs( 4, 19) = fL

! SNH4s( 5, 1) = -iXBFs( 5, 2) = -iXBFs( 5, 3) = -iXBFs( 5, 4) = -iXBFs( 5, 5) = -iXBFs( 5, 6) = -iXBFs( 5, 7) = -iXBFs( 5, 8) = -iXBFs( 5, 9) = iLysFs( 5, 10) = -iXBB

Page 35: Stoat 4.2

35

s( 5, 11) = iLysBs( 5, 12) = -1d0 / YNS - iXBNSs( 5, 13) = iLysNSs( 5, 14) = -iXBNBs( 5, 15) = iLysNBs( 5, 16) = iNHs( 5, 17) = iNLs( 5, 18) = iNHs( 5, 19) = iNL

! SNO2s( 6, 3) = (1d0 - YF) / (1.14d0 * YF)s( 6, 4) = (1d0 - YF) / (1.14d0 * YF)s( 6, 5) = -(1d0 - YF) / (0.57d0 * YF)s( 6, 6) = -(1d0 - YF) / (0.57d0 * YF)s( 6, 12) = 1d0 / YNSs( 6, 14) = -1d0 / YNB

! SNO3s( 7, 3) = -(1d0 - YF) / (1.14d0 * YF)s( 7, 4) = -(1d0 - YF) / (1.14d0 * YF)s( 7, 14) = 1d0 / YNB

! SNOs( 8, 5) = (1d0 - YF) / (0.57d0 * YF)s( 8, 6) = (1d0 - YF) / (0.57d0 * YF)s( 8, 7) = -(1d0 - YF) / (1.14d0 * YF)s( 8, 8) = -(1d0 - YF) / (1.14d0 * YF)

! XF -- floc formerss( 9, 1) = 1d0s( 9, 2) = 1d0s( 9, 3) = 1d0s( 9, 4) = 1d0s( 9, 5) = 1d0s( 9, 6) = 1d0s( 9, 7) = 1d0s( 9, 8) = 1d0s( 9, 9) = -1d0

! XB -- bulking biomasss(10, 10) = 1d0s(10, 11) = -1d0

! XNS -- Nitrosomonass(11, 12) = 1d0s(11, 13) = -1d0

! XNB -- Nitrobacters(12, 14) = 1d0s(12, 15) = -1d0

! XH -- high molecular weight, particulates(13, 16) = -1d0s(13, 18) = -1d0s(13, 20) = 1d0s(13, 21) = 1d0

! XL -- low molecular weight, particulates(14, 17) = -1d0s(14, 19) = -1d0

! XS -- surfactant, particulates(15, 9) = fLSFs(15, 11) = fLSBs(15, 13) = fLSNSs(15, 15) = fLSNBs(15, 20) = -1d0

Page 36: Stoat 4.2

36

s(15, 21) = -1d0

! XI -- nondegradable, particulates(16, 9) = fIFs(16, 11) = fIBs(16, 13) = fINSs(16, 15) = fINB

! Nonvolatile solids! iTSSBM is the ratio between biomass as COD and biomass as TSS! s2 is the ratio between biomass as COD and biomass as VSS! We assume that dditions to nonvolatile solids are a result! of the difference between these two ratios only.s(17, :) = s( 9, :) * (iTSSBM - 1d0 / s2) & + s(10, :) * (iTSSBM - 1d0 / s2) & + s(11, :) * (iTSSBM - 1d0 / s2) & + s(12, :) * (iTSSBM - 1d0 / s2)

!! Evaluate kinetics!do Stage = 1, NumberOfStages SO2 = y(Stage, 1) SH = y(Stage, 2) SL = y(Stage, 3) SI = y(Stage, 4) SNH4 = y(Stage, 5) SNO3 = y(Stage, 6) SNO2 = y(Stage, 7) SNO = y(Stage, 8) XF = y(Stage, 9) XB = y(Stage, 10) XNS = y(Stage, 11) XNB = y(Stage, 12) XH = y(Stage, 13) XL = y(Stage, 14) XS = y(Stage, 15) XI = y(Stage, 16)

rho( 1) = mumaxF*ON(SO2,KO2F) *ON(SH,KH)*ON(SNH4,KNH4F)*OFF(SNO,KNO) *XF rho( 2) = beta1*mumaxF*ON(SO2,KO2F) *ON(SL,KLF)*ON(SNH4,KNH4F)*OFF(SNO,KNO) *XF rho( 3) = beta2*mumaxF*OFF(SO2,KO2F) *ON(SH,KH)*ON(SNH4,KNH4F)*ON(SNO3,KNO3)*XF rho( 4) = beta3*mumaxF*OFF(SO2,KO2F) *ON(SL,KLF)*ON(SNH4,KNH4F)*ON(SNO3,KNO3)*XF rho( 5) = beta4*mumaxF*OFF(SO2,KO2NO2)*ON(SH,KHNO2)*ON(SNH4,KNH4F)*ON(SNO2,KNO2)*XF rho( 6) =beta5*mumaxF*OFF(SO2,KO2NO2)*ON(SL,KLFNO2)*ON(SNH4,KNH4F)*ON(SNO2,KNO2)*XF rho( 7) = beta6*mumaxF*OFF(SO2,KO2NO) *ON(SH,KHNO2)*ON(SNH4,KNH4F)*ON(SNO,KNO) *XF rho( 8) = beta7*mumaxF*OFF(SO2,KO2NO)*ON(SL,KLFNO2)*ON(SNH4,KNH4F)*ON(SNO,KNO) *XF rho( 9) = bF*XF rho(10) = mumaxB*ON(SO2,KO2B)*ON(SL,KLB)*ON(SNH4,KNH4B)*XB rho(11) = bB*XB rho(12) = mumaxNS*ON(SO2,KO2NS)*ON(SNH4,KNH4NS)*XNS rho(13) = bNS*XNS rho(14) = mumaxNB*ON(SO2,KO2NB)*ON(SNH4,KNH4NB)*ON(SNO2,KNO2NB)*XNB rho(15) = bNB*XNB rho(16) = kHi*ON(SO2,KO2Hyd)*XH rho(17) = kLo*ON(SO2,KO2Hyd)*ON(XS,KXSurf*XL)*XL rho(18) = betaH*kHi*OFF(SO2,KO2Hyd)*ON(SNO3,KNO3Hyd)*XH rho(19) = betaL*kLo*OFF(SO2,KO2Hyd)*ON(SNO3,KNO3Hyd)*ON(XS,KXSurf*XL)*XL rho(20) = kS*ON(SO2,KO2Surf)*XS rho(21) = beta_surf*OFF(SO2,KO2Surf)*ON(SNO3,KNO3Surf)*XS

Page 37: Stoat 4.2

37

OUR(Stage) = 0d0 NUR(Stage) = 0d0 do Reaction = 1, NumberofReactions do Comp = 1, NumberOfComponents if (s(Comp, Reaction) <> 0) then dy(Stage, Comp) = dy(Stage, Comp) & + Rho(Reaction) * s(Comp, Reaction) end if end do OUR(Stage) = Sum(Rho * s(1, :)) NUR(Stage) = Sum(Rho * s(6, :)) + Sum(Rho * s(7, :)) + Sum(Rho * s(8,:)) end do dy(Stage, 1) = dy(Stage, 1) + KLa(Stage) * Alpha(Stage) * (Beta(Stage) *SatO2(T) - SO2) QO2(Stage) = KLa(Stage) * Alpha(Stage) * (Beta(Stage) * SatO2(T) - SO2) *Volume(Stage) * 1d-3 ! kg/hend do

contains double precision function ON(S, K) double precision:: S, K if (K == 0 .and. S == 0) then ON = 0 else ON = S / (K + abs(S)) endif end function ON

double precision function OFF(S, K) double precision:: S, K OFF = K / (abs(S) + K) end function OFF

double precision function SatO2(T) double precision:: T SatO2 = exp(1d0/(t*0.004065d0 + 0.372017d0)) end function SatO2end