← Module 1 · Modeling Assignment M1 (OpenHydroQual)

A well-mixed tank in OpenHydroQual: filling, flushing, and mixing two streams

An illustrated, step-by-step worked example · about 45 minutes · the latest OpenHydroQual · uses Module 1, Sections 2–4 (mass balance, the well-mixed tank, the energy balance)

What you will build

A completely mixed 1000 m³ tank with one inflow and one outflow. You will fill it with a tracer, flush it clean, and then add a second inflow from a river and carry temperature as a second "constituent". Every stage is checked against the formulas of Module 1.

StageWhat changesWhat to look forSaved as
1clean tank, inflow at 50 g/m³\(C = C_{\text{in}}(1 - e^{-t/\tau})\), \(\tau = 5\) daysM1_stage1_fill.ohq
2tank starts at 50 g/m³, clean inflow\(C = C_0\,e^{-t/\tau}\)M1_stage2_flush.ohq
3+ a river inflow, + temperatureflow-weighted steady state: 26 g/m³ and 16 °C, \(\tau = 2\) daysM1_stage3_mixing_energy.ohq

The system

ItemValue
Tank\(V = 1000\) m³, completely mixed, constant volume
Inflow (Stages 1–2)\(Q = 200\) m³/day; tracer \(C_{\text{in}} = 50\) g/m³ (Stage 1) or 0 (Stage 2)
Outflowequal to the inflow, so the volume stays constant: \(\tau = V/Q = 5\) days
River inflow (Stage 3)300 m³/day at 10 g/m³ and 10 °C; the first inflow is wastewater at 50 g/m³ and 25 °C
Simulation0 to 30 days (Stage 3: 0 to 20 days)

OpenHydroQual writes the mass balance of Module 1, Section 2, for every block and every constituent: accumulation = what the links bring in − what they take out + the block's own inflow and sources. You only describe the blocks and links.

1Load the Mass Transfer plugin

Install OpenHydroQual from www.OpenHydroQual.com if you have not already, and start a new model. Open File → Preferences → Add plugin and add Mass Transfer: it provides the Reactor block (a completely mixed tank) and the Fixed flow link.

File menu: Preferences, Add plugin
1 File → 2 Preferences → 3 Add plugin.
Select Plugin: Mass Transfer
Scroll down to 1 Mass Transfer, then 2 OK. New icons appear in the Blocks and Links toolbars.

2Create the tracer (a "constituent")

A constituent is any substance whose mass balance you want. Create it before the blocks, so that every block gets concentration fields for it. Use Add Objects → Chemistry → Chemical constituent.

Add Objects, Chemistry, Chemical constituent
1 Add Objects → 2 Chemistry → 3 Chemical constituent.
Constituent properties with Name set to Tracer
Click the new constituent under Constituents in the Object Browser and 1 rename it Tracer (double-click the value, type, Enter). Leave the diffusion coefficient and dispersivity at 0: in a single well-mixed tank they do nothing.

3Add the tank: a Reactor block

Click the Reactor icon in the Blocks toolbar; a block appears on the canvas. Click it and set its properties in the panel under the Object Browser. Double-click a value to edit it, type the number, and press Enter. The unit is shown in brackets; leave it as it is.

Blocks toolbar: Reactor icon
1 The Reactor icon (hover over an icon to see its name). A Reactor is a completely mixed control volume.
Drag the divider between the Object Browser and the canvas to the right, and the divider between the Property and Value column headers, so you can read the full property names.
Tank properties
Properties of the tank.
PropertyValueMeaning
1Initial Storage1000 m³the volume of water in the tank, \(V\)
2Tracer:Concentration0 g/m³the initial concentration, \(C_0\): a clean tank
3Tracer:Constant Inflow concentration50 g/m³\(C_{\text{in}}\) of the block's own inflow
4Constant Inflow200 m³/day\(Q\), water entering the tank from outside the model
5NameTank

The block's inflow brings in mass at the rate \(QC_{\text{in}}\) (OpenHydroQual reports it as "Tracer:Inflow loading"). Remember that g/m³ = mg/L.

4Add somewhere for the water to go: the Outlet

The water leaving the tank needs a destination. Add a second Reactor and make it very large, so that what flows into it changes it very little. It acts as a sink, and its mass at the end of the run tells you how much tracer has left the tank.

Outlet properties
1 Initial Storage 1e+06 m³ (type 1000000); 2 Name Outlet. Leave its constant inflow at 0. Drag it to the right of the tank.

5Connect them with a Fixed flow link

Choose the Fixed flow icon in the Links toolbar, then drag from Tank to Outlet. A Fixed flow link moves a set flow of water, and with it mass at the rate \(Q \times C_{\text{Tank}}\), from the first block to the second. This is exactly the "out" term of the mass balance for a completely mixed tank.

Links toolbar: Fixed flow icon
1 The Fixed flow link.
Tank, link and Outlet on the canvas
1 Tank, 2 the link (drawn from Tank to Outlet, so its arrow points to the Outlet), 3 Outlet.
Link properties: flow rate 200
Click the link (or select it under Connectors) and set 1 Flow rate 200 m³/day, equal to the inflow, so the tank volume stays at 1000 m³.
Why must the outflow equal the inflow here?
OpenHydroQual also keeps a water balance for each block: \(dV/dt = Q_{\text{in}} - Q_{\text{out}}\). With 200 in and 200 out the volume is constant, which is what the formula \(C = C_{\text{in}}(1 - e^{-t/\tau})\) assumes. Try a different outflow in Explore.

6Simulation time and time step

Expand Settings in the Object Browser.

General Settings: simulation end time 30
General Settings: 1 Simulation end time 30 (days). Start time 0.
Solver Settings
Solver Settings: keep 1 the initial time-step at 0.01 and set 2 the Maximum allowable time-step increase factor to 5 (the default is larger).

Why limit the time step? OpenHydroQual solves the balance in small time steps. Over each step it treats the change as if it happened at the end of the step, so a long step makes the curve slightly wrong during the first day, when the concentration changes fastest. With the limit, the error is small; the checkpoints start at day 5.

Stage 1Fill the tank

Save the model (File → Save as, M1_stage1_fill.ohq)). Then press Run Model on the right-hand toolbar and confirm with Yes. The run takes a few seconds.

Run Model button
1 Run Model.
Running Model window: Finished
The run window. The time step rises from 0.01 to 0.05 day and stays there: the limit from Step 6. Close it when it says Finished!
Right-click Tank, Results, Tracer:Concentration
Right-click Tank → 1 Results → 2 Tracer:Concentration.
Tank tracer concentration rising to 50
The tank fills along the curve \(C = 50(1 - e^{-t/5})\): 31.6 g/m³ after one residence time (5 days, 63 %), 47.5 after three, and practically 50 by day 30.

Read the concentration at 5, 10 and 20 days (hover over the curve, or use the export button in the plot window to save the numbers) and compare with the formula. Also plot the Outlet's Tracer:Mass at 30 days: by the mass balance it should be the 300,000 g that entered (200 m³/day × 50 g/m³ × 30 days) minus the ≈ 49,900 g still in the tank.

Stage 2Flush the tank

Save a copy as M1_stage2_flush.ohq. Change only the tank: its initial concentration becomes 50 g/m³ and its inflow is clean.

Tank properties for flushing
1 Tracer:Concentration 50 g/m³ (the initial value, \(C_0\)); 2 Tracer:Constant Inflow concentration 0.
Tank tracer concentration falling from 50
The tank is flushed along \(C = 50\,e^{-t/5}\): 18.4 g/m³ after 5 days, 6.77 after 10, 0.92 after 20. It is the fill curve turned upside down: the two always add up to 50.

Stage 3Two inflows, and temperature

Start from Stage 1 and save a copy as M1_stage3_mixing_energy.ohq. Now the tank also receives water from a river, and you will follow the temperature as well as the tracer.

3a · A heat constituent: Temperature

OpenHydroQual has a constituent made for this: Heat (temperature). Add one with Add Objects → Chemistry → Heat (temperature) (or its icon in the Constituents toolbar) and name it Temperature.

Add Objects, Chemistry, Heat (temperature)
1 Add Objects → 2 Chemistry → 3 Heat (temperature).
Heat constituent properties
Its properties: 1 Volumetric heat capacity \(\rho c_p\) = 4.186 MJ/(m³·°C), the value for water (keep it); 2 Name Temperature. Leave thermal diffusivity and dispersivity at 0.
How the heat constituent works. It is the energy balance of Module 1, Section 4, written for every block. The quantity OpenHydroQual balances is the heat content \(\rho c_p V T\) (MJ); what it shows you is the temperature \(T\) in °C. A flow carries heat at the rate \(\rho c_p Q T\), so with \(\rho c_p\) constant the temperatures mix exactly like concentrations. Each block gets three new inputs: its initial Temperature, the Inflow temperature of its own inflow, and a Heat input in kW (a heater, or waste heat; negative for cooling).

The Heat (temperature) constituent is in the latest OpenHydroQual. If your Chemistry menu does not list it, install the latest version from www.OpenHydroQual.com. is constant, it gives the same temperatures.)

3b · The river and the new flows

Add a third Reactor named River, to the left of the tank. Like the Outlet it is very large, so its concentration and temperature stay at the values you give it. Draw a Fixed flow link from River to Tank.

Stage 3 model: River, Tank and Outlet, with Temperature in the constituent list
1 The second constituent, Temperature. 2 River, 3 the link River → Tank, 4 the link Tank → Outlet.
River properties
River: 1 Initial Storage 1e+06 m³, 2 Temperature:Temperature 10 °C, 3 Tracer:Concentration 10 g/m³. Constant Inflow 0, Heat input 0.
Tank properties in Stage 3
Tank: it starts full of river water: 1 Temperature:Temperature 10 °C, 3 Tracer:Concentration 0. Its own inflow (still 200 m³/day) is the wastewater: 2 Temperature:Inflow temperature 25 °C and 4 Tracer:Constant Inflow concentration 50 g/m³. Leave the Heat input at 0 for now.
Flow rates of the two links
1 River → Tank: 300 m³/day. 2 Tank → Outlet: 500 m³/day = 200 + 300, so the tank volume stays constant. Set the end time to 20 days.

Before you run, predict the answers with Module 1:

\[ \tau = \frac{1000}{500} = 2\ \text{days}, \qquad C_{\text{ss}} = \frac{200(50) + 300(10)}{500} = 26\ \text{g/m}^3, \qquad T_{\text{ss}} = \frac{200(25) + 300(10)}{500} = 16\ ^\circ\text{C}. \]
Tank tracer concentration and temperature in Stage 3
Left: tracer, from 0 to 26 g/m³. Right: temperature, from 10 to 16 °C. Both approach steady state along the same \(e^{-t/2}\) curve. The tank now passes 2.5 times as much water (500 instead of 200 m³/day), so its residence time is 2 days instead of 5 and it reaches steady state 2.5 times sooner.

Checkpoints

Read these from your own runs; small differences in the last digit are normal. The model lags the formula slightly during the first days because of the time step (Step 6).

StageQuantityModelFormula
1Tank C at 5 / 10 / 20 days (g/m³)31.52 / 43.17 / 49.0731.61 / 43.23 / 49.08
1Outlet tracer mass at 30 days (g)250,100250,100
2Tank C at 5 / 10 / 20 days (g/m³)18.49 / 6.83 / 0.9318.39 / 6.77 / 0.92
3Tank C at 2 / 10 / 20 days (g/m³)16.32 / 25.81 / 26.0016.44 / 25.82 / 26.00
3Tank T at 2 / 10 / 20 days (°C)13.77 / 15.96 / 16.0013.79 / 15.96 / 16.00
3Tank storage (m³), all times10001000

Explore

Save a copy with File → Save as and change one thing at a time.

Troubleshooting

The tank concentration stays at 0.The tank's Constant Inflow or Tracer:Constant Inflow concentration is 0, or you set Tracer:Concentration (the initial value) instead of the inflow concentration.
The tank empties or overflows.The link flow does not match the inflow (Stage 3: 500 = 200 + 300). Plot Storage to check.
The curve reaches 50 in a day or two.The tank volume (Initial Storage) is too small: check it is 1000 m³, not 1000 ft³ (the mouse wheel over a unit box changes the unit).
No Reactor or Fixed flow icons.The Mass Transfer plugin is not loaded (Step 1).
The first-day values are a little off.That is the time step (Step 6). Check the maximum time-step increase factor is 5, and compare from day 5 on.

What to submit