Modelling of a simple continuous neutralisation reactor

Modelling of a simple continuous
neutralisation reactor
Serge Zihlmann
ThirdWay
February 23, 2015
Modelling of a neutralisation reactor
Foreword
When I was browsing the web for a decent and intuitive model of a neutralisation reactor,
I could not nd the appropriate theorethical descripton nor model les for download. At
that time I started to develop an own model including its implementation in a Simulation
software. Quickly, this ended up in a rather extensive project.
The theory developed and the models used are described in this little script in two
dierent ways: One more intuitively and the other more academic. The models can of
course be downloaded read to use.
S. Zihlmann
February 23, 2015
Page 1 of 18
Modelling of a neutralisation reactor
1 Introduction and Modelling
Figure 1.1 illustrates a CSTR used for neutralisation of waste water. In the given
example, the waste water enters the reactor with a feedrate of V̇F = 2 000 l/h at pHF =13.
Acid and base are dosed by a PI-controller, which varies the ows of V̇A and V̇B . A pHprobe measures the current pH-value and causes feedback to the controller with a lag
time of 50 s. The reactor volume is V = 4 000 l and the maximum feed of the acid (25 %
Acid feed VA
CA[H+],CA[OH-]
Base feed VB
CB[H+],CB[OH-]
M
Wastewater
feed
Outlet
pHF, VF
pH
VF+VA+VB
pH-probe
Figure 1.1: Continuously stirred tank reactor (CSTR) with acid and base dosing for
neutralisation. pH value is equivalent to concentration of H + and OH −
ions.
HCl) is 30 l/h. As the pH setpoint (goal value) is pH10, only acid addition will be used
in the following.
1.1 Intuitive modelling of the reactor
All parameters are subject to time change, except the volume V . Especially V̇A , V̇B are
used for control of the neutralisation. A simplication is the assumption of linear mixing
volume (no miscibility gap) of acid and waste water.
S. Zihlmann
February 23, 2015
Page 2 of 18
Modelling of a neutralisation reactor
In order to model the dynamic behavior of the CSTR, usually a balance for each compound is set up. The accumulation term is then given by sum of inputs and outputs of
the respective compound.
Accumulation = Input − Output
Let us assume for simplication that we only have an acid pump available to neutralise
the alkaline waste water, thus V̇B = 0. For the both species involved, the balances read:
d
C[OH − ] = V̇F · CF [OH − ] − (V̇F + V̇A ) · C[OH − ] + V̇A · CA [OH − ]
dt
d
V · C[H + ] = V̇F · CF [H + ] − (V̇F + V̇A ) · C[H + ] + V̇A · CA [H + ]
dt
V ·
The diculty of a neutralisation reactor is that a reaction occurs, i.e. the both equations
are coupled by the autoprotolysis of water.
H + + OH − *
) H2 O
This reaction has the approximate equilibrium constant of 10−14 mol
assuming that the
l2
water concentration is constant.
2
C[H + ] · C[OH − ] = 10−14
To keep things simple let us assume that this reactions does not take place and the
H + and OH − ions remain in the solution, because for the matter of neutralisation we
only need to balance the both ions to the same level. Still, if we want to calculate the
pH, we need to nd the equilibrium of the autoprotolysis. Say, if we start from the
concentrations as calculated by the dynamic models above, then the ion prodcut is not
yet fullled. The above reaction consumes or produces a certain amount ∆H of OH −
e +]
and H + ions, until the equation is satised and we have an equilibrium level of C[H
−
e
and C[OH
].
(C[H + ] + ∆H) · (C[OH − ] + ∆H) = 10−14
e + ]. It follows:
We can eliminate the irrelevant ∆H by renaming C[H + ] + ∆H = C[H
e + ] · (C[OH − ] + C[H
e + ] − C[H + ]) = 10−14
C[H
e + ] using a root solver to nd the equilibrium
This equations must be solved for C[H
concentration. Luckily, the equation is only quadratic, thus a straight forward solution
exists. The equation in standard shape is:
e + ]2 + (C[H + ] − C[OH − ]) · C[H
e + ] + 10−14
0 = −C[H
with:
a = −1
b = C[H + ] − C[OH − ]
c = 10−14
S. Zihlmann
February 23, 2015
Page 3 of 18
Modelling of a neutralisation reactor
The solution is:
e + ]1,2 =
C[H
−b ±
√
b2 − 4ac
2a
While only one of the two solutions retrieves a positive concentration. It can further be
simplied to depend only on the input concentration of H + and OH − ions:
√
e + ] = 1 b + b2 + 4 · 10−14
C[H
2
And the pH value will read:
e + ])
pH = −log10 (C[H
We see that the dierence b of the ion concentration plays a central role to the solution
of the problem. Let's try to combine the two dierential equations by subtracting the
rst from the second.
V ·
d
(C[H + ] − C[OH − ]) =
dt
V̇F · (CF [H + ] − CF [OH − ]) − (V̇F + V̇A ) · (C[H + ] − C[OH − ]) + V̇A · (CA [H + ] − CA [OH − ])
We can identify some terms by b, bF and bA :
V ·
d
b = V̇F · bF − (V̇F + V̇A ) · b + V̇A · bA
dt
The neutralisation problem can now be solved by one simple ODE. Note: For the modelling of base addition, the term V̇B · bB must be added to the right side.
1.1.1 Dynamic behavior
The model was implemented in Simulink (see Appendix) and the dynamic behavior
in terms of step response and PI-controlled CSTR are shown in gure 1.2. The step
response when suddenly acid is fed to the reactor with otherwise constant inow, can be
interpreted as titration curve. The controlled plant is quite sensitive to oscillation due
to the lag time of the pH-electrode (here 50 s) and the high nonlinearity, for which the
PID's are not well designed.
1.2 Second approach
One might ask whether there is a more sophisticate approach to the modelling part
in contrast to the previous rather intuitive model. Of course there is a more strict,
mathemathical way but the intuitive has its advantage that the user understands the
process behind well. To proceed with the model in the academic way, I propose a
more simplied model structure (gure 1.3) which contstitutes of one lumped system
S. Zihlmann
February 23, 2015
Page 4 of 18
Modelling of a neutralisation reactor
13
12
12.5
10
12
pH
pH
8
6
11
4
10.5
2
0
11.5
0
0.5
1
1.5
2
Time / h
2.5
3
10
3.5
0
0.5
1
1.5
2
Time / h
2.5
3
3.5
(a) Step response when acid is fed continuously at (b)
Controlled neutralisation reactor to reach
full power to a batch tank with initially pH13.
pH10.5 with an initial and input of pH13.
The behavior is the same as for a titration
Feedback has a lag time of 50 s and the
curve.
PID-controller parameters are
1
P = −1.0 pH
,
1
I = −0.15 s pH
Figure 1.2: Intuitive model: Step response and controlled CSTR.
which represents the CSTR (in the lumped system all properties are averaged, thus
well stirred). The inows origin from the acid, base and the waste water. The reactor
overows to an outlet. For each arrow there is a volumetric owrate and the ow
composition vector c.
WW
A
VWW|R
CWW
VA|R
CA
R
B
VB|R
CB
VR|O
CR
O
Figure 1.3: Model of the neutralisation reactor as one lumped system (R=reactor) and
four reservoirs (A=acid, WW=waste water, B=base, O=outow).
First of all we have three species involved and we dene a species vector as follows:
[H + OH − H2 O]T
From the general conservation
Accumulation = Flows + Reaction
S. Zihlmann
February 23, 2015
Page 5 of 18
Modelling of a neutralisation reactor
There follows directly the equation in matrix notation:
ṅR = F n̂ + n̂r
Where ṅR is the total change in moles of each compound in the reactor, n̂ is the molar
ow of each compound and in each stream, F represents the direction matrix of the ows
(in or out) and is only a selector matrix, n̂r represents the production/consumption by
reaction (= index r) of each compound within the reactor. More specic, the ow vector
consists of (omitting the base ow)


n̂A|R
n̂ =  n̂W W |R 
n̂R|O
And the ow selector matrix:


1 0 0 1 0 0 −1 0
0
F =  0 1 0 0 1 0 0 −1 0  = [ 1 1 −1 ] ⊗ I
0 0 1 0 0 1 0
0 −1
The notation is very ecient using the kronecker product ⊗. The molar ow in each
stream is simply n̂x|y = V̇x|y · cx for an exemplary ow from tank x to y . The input
ows V̇A|R and V̇W W |R are well dened as well as their composition cA , cW W . The
outlet ow must be obtained from an assumption. Here it is, that the volume during
mixing of the two streams remains constant and the reactor has constant volume, thus
V̇R|O = V̇A|R + V̇W W |R . The composition of the outlet cR ow changes with time and
must be obtained from the dynamic model cR = V −1 nR where V is the volume of the
reactor.
1.2.1 Including the reaction
The reaction term n̂r mentioned in the last section is represented by the reaction stochiometry matrix N and some extent of reaction ne.
e
n̂r = N T n
For the autodissociation of the water
kf
H2 O *
) H + + OH −
kb
the reaction stochiometri matrix reads
N=
S. Zihlmann
1
1 −1
−1 −1 1
forward
backward
February 23, 2015
Page 6 of 18
Modelling of a neutralisation reactor
for the forward and backward reaction. The reaction extent is formulated by the reaction
rate law
n̂r = N T V K r g(cr )
where V is the reactor volume, K r contains the reaction rate constants and g(cr ) is the
formulation of the rate law. Joined in one equation:
ṅR = F n̂ + N T V K r g(cr )
The central assumption for the further procedure is that the autoprotolysis reaction
of the water is very fast. In other words, the reaction reaches always the equilibrium.
Therefore we will eliminate the reaction term by nding the left nullspace Ω of N T and
it is
Ω=
1 −1 0
1 0 1
Of course there exists an innite amount of possible nullspaces, it is selected in that
way that the equations used during root solving become nice. By multiplying the whole
equation with the left null space, we eliminate the reaction terms.
Ω ṅR = Ω F n̂ + Ω N T V K r g(cr )
Ω ṅR = Ω F n̂
After the nullspace transformation we can identify a new state z R = Ω nR
ż R = Ω F n̂
Now the dynamic model is nished and simply the ODE for the state z R has to be
solved. n̂ is dened by the input variables (acid ow, waste water ow) and the reactor
composition (feedback). That requires the reconstruction of the reactor composition cR
from the state z R . That involves solving the roots of the equation
0 = z R − Ω nR = z R − Ω V cR
In this case we need to solve for three dimensions in the space of cR but the above
expression returns only two equations. Thus we need another condition and it originates
from the reaction term, more precisely, the equilbrium relation:
0 = N T V K r g(cr )


1 −1
k
0
c
f
H
O
2
0 =  1 −1  V
0 kb
cH + · cOH −
−1 1


kf · cH2 O − kb · cH + · cOH −
0 = V  kf · cH2 O − kb · cH + · cOH − 
−kf · cH2 O + kb · cH + · cOH −
(1.1)
(1.2)
(1.3)
(1.4)
S. Zihlmann
February 23, 2015
Page 7 of 18
Modelling of a neutralisation reactor
The three equations are equal and result in
cH2 O
kb
=
kf
cH + · cOH −
The concentration of the water is assumed constant and the equilibrium constant equal
to 1014 as generally for the water dissoziation.
k1 =
cH +
1
= 1014
· cOH −
Thus the third required equation to reconstruct the composition cR from the state z R is
0 = k1 −
cH +
1
· cOH −
Finally we have to fulll all three equations:
"
0=
z R − Ω V cR
k1 − c + ·c1 −
H
#
OH
This can be solved for cR by a numerical root solver, but in this simple case explicit
expressions are available. In detailed formulation this reads:

z1 − V (cH + − cOH − )
0 =  z2 − V (cH + + cH2 O ) 
k1 − c + ·c1 −

H
OH
After solving this system one obtains:
cH +
1
=
2
z1
+
V
r z 2
1
V
1
k 1 cH +
z2
=
− cH +
V
4
+
k1
(1.5)
cOH − =
(1.6)
cH2 O
(1.7)
Now the modelling is complete and the structure can be implemented into a numerical
software. The concentration vector for each input ow must be obtained from the pH or
acid/base concentration. For the water always a constant concentration of 55.6 mol/L is
assumed. One central dierence of this model to the intuitive one is that also the water
is balanced.
1.2.2 Dynamic behavior
In gure 1.4 the results of the dynamic Simulink model for the academic approach are
shown. The results is equal to the intuitive approach.
S. Zihlmann
February 23, 2015
Page 8 of 18
Modelling of a neutralisation reactor
Time Series Plot:
Time Series Plot:
13
12
12.5
10
12
pH
pH
8
6
11
4
10.5
2
0
11.5
0
0.5
1
1.5
2
Time / h
2.5
3
3.5
10
0
0.5
1
1.5
2
Time / h
2.5
3
3.5
(a) Step response when acid is fed continuously at (b)
Controlled neutralisation reactor to reach
full power to a batch tank with initially pH13.
pH10.5 with an initial and input of pH13.
The behavior is the same as for a titration
curve.
Feedback has a lag time of 50 s and the
PID-controller parameters are
1
P = −1.0 pH
,
1
I = −0.15 s pH
Figure 1.4: Academic model: Step response and controlled CSTR.
1.3 Linearizing the plant
The aim is to abtain a linearized model of the plant in standard shape as depicted for
the system Σ in gure 1.5
r(t)
u(t)
Σ
ẋ = Ax + bu
y = dx + cu
x
y(t)
Figure 1.5: The model block for a linear system Σ with the input u, state x and output
y . r is a disturbance eect, e.g. noise.
We shall work here with the dierential equation from the intuitive approach, as obtained
before:
d
b = V̇F · bF − (V̇F + V̇A ) · b + V̇A · bA
dt
Identifying b as state and call it x. Also identify the acid ow V̇A as the input u(t). This
V ·
retrieves the model in standard shape:
ẋ(t) =
S. Zihlmann
V̇F · bF
V̇F
1
bA
−
· x(t) − · x(t) · u(t) +
· u(t)
V
V
V
V
February 23, 2015
Page 9 of 18
Modelling of a neutralisation reactor
The output of the plant is not b but the pH value. Therefore we needed the root solver:
√
1
+
2
−14
e
b + b + 4 · 10
C[H ] =
2
and thus
√
1
pH = −log10
b + b2 + 4 · 10−14
2
In standard form, where pH is the output y(t) and b again the state x(t):
p
1
2
−14
y(t) = −log10
x(t) + x (t) + 4 · 10
2
Thus we have the complete non linear model in standard shape:



ẋ(t) =
V̇F ·bF
V
−
V̇F
V
−log10
y(t) =
· x(t) −
1
2
1
V
· x(t) · u(t) +
bA
V
· u(t) = f (x(t), u(t))
p
x(t) + x2 (t) + 4 · 10−14
= g (x(t), u(t))



The linearization will bring the model into the shape:
ẋ(t) = A x(t) + b u(t)
y(t) = c x(t) + d u(t)
While A, b, c and d are matrices in general, but here simple constants. The linearization
is done around the equilibrium point with x = xe and u = ue. In this equilibrium point
we have:
!
0 = ẋ(t) =
V̇F
1
bA
V̇F · bF
−
· xe − · xe · ue +
· ue
V
V
V
V
Usually for this equilibrium point the plants steady state point without interactions is
chosen (this would be in our case that the reactor has the same composition as the inlet
ow). Because the model is highly non linear, this would not be a good choice since
we want to control the pH in detail around pH10. Thus we select pH10 as linearization
point and have to search for the appropriate ue. b is readily calculated from the pH:
be =
and thus
10−2pH − 10−14
C 2 [H + ] − 10−14
=
= 10−pH − 10pH−14
+
−pH
C[H ]
10
xe = be = 10−10 − 10−4 = 10−4 (10−6 − 1) ≈ −10−4
Now we have to nd the acid feed ue to reach steady pH10 (xe). Reformulation of the
equation above:
ue = V̇F
S. Zihlmann
xe − bF
bA − xe
February 23, 2015
Page 10 of 18
Modelling of a neutralisation reactor
The constants are then calculated:
∂f u=ue
∂x x=xe
=
b =
∂f u=ue
∂u x=xe
=
c =
∂g u=ue
∂x x=xe
A =
d =
=
− V̇VF
−
1
V
u=ue
· u(t)
=
− V̇FV+ue
bA u=ue
V x=xe
=
bA −xe
V
− V1 · x(t) +
x=xe
u=ue
√ 1
−
ln(10) x2 (t)+4·10−14 = − ln(10)√xe12 +4·10−14
x=xe
∂g u=ue
∂u x=xe
=
0
The factor d appears to be zero, because the acid feed has no instantaneous eect onto
the pH value.
1.3.1 Dynamic behavior and linearization error
As the model is linearized around pH11, it is not a good idea to start the control at
pH13 due to the high non-linearity. For this reason, two scenarios are compared here:
ˆ Control from pH12 to pH11 (strong disturbance)
ˆ Control from pH11.1 to pH11 (slight disturbance)
Each scenario is compared for the controlled linearized and full model (as from intuitive
approach). Th results are depicted in gure 1.6. What is obvious is that the linearized
model starts at the wrong pH due to linearization error. This error becomes much less
when the starting point is pH11.1. For the big step in control variable, the dierence
between the control characteristic of the full/linearrized model is quite large, whilst
at a small step the error is negligible (less linearization error). As a consequence, the
modeling with this linear model is only appropriate if the pH does not vary much from
the setpoint (e.g. when keeping the level constant under disturbance).s
1.4 Transfer function
The transfer function represents the dynamic input/output behavior. The transfer function in the laplace domain can not readily be calculated for the full model, as x and y
occur in a multiplication (which leads to a convolution in the laplace domain). Anyhow,
it can be obtained quickly from the linearized model:
S. Zihlmann
ẋ(t) = A x(t) + b u(t)
y(t) = c x(t) + d u(t)
February 23, 2015
Page 11 of 18
Modelling of a neutralisation reactor
12
11.1
Full model
Linearized
11.6
11.06
11.4
11.04
11.2
11.02
11
11
10.8
10.98
10.6
10.96
10.4
10.94
10.2
10.92
10
0
0.2
0.4
0.6
0.8
Full model
Linearized
11.08
pH
pH
11.8
1
10.9
0
0.2
Time / h
0.4
0.6
0.8
1
Time / h
(a) Control from pH12 to pH11.
(b) Control from pH11.1 to pH11.
Figure 1.6: Response of a controlled neutralisation CSTR for dierent starting/aim pHvalues. Each plot shows the response of the full model compared to the
linearized plant. Parameters of the controller are the same as before (feed1
1
back lag 50 s, P = −1.0 pH
, I = −0.15 s pH
After a laplace transformation one obtains
x(s) · s = A x(s) + b u(s)
y(s) = c x(s) + d u(s)
because A, b, c and d are simple constants. After algebraic operations:
x(s) =
Then
b · u(s)
s−A
c·b
+ d u(s)
y(s) =
s−A
And the transfer function:
G(s) =
y(s)
c·b
=
+d
u(s)
s−A
Although derived here, this section is more for info than practical use.
S. Zihlmann
February 23, 2015
Page 12 of 18
2 Choosing a PID controller
2.1 Back-linearization
13
13
12.5
12.5
12
12
12
11.5
pH
13
12.5
pH
pH
One might state that it is a good idea to `re-linearize' the plant, thus to take the output
pH value and calculate it back to the concentration of H + ions. Also the setpoint shall
be given as a concentration of H + . The control would then be linear, anyhow across huge
magnitudes. The problem is then, that the chosen PID constants are only valid for a
specic case and nding parameters for a wide range of application would be impossible.
E.g. switching the setpoint from pH11 to pH10 would make the control parameters
useless. Figure 2.1 contains three examples for illustration. The basic problem with this
11.5
11.5
11
11
11
10.5
10.5
10.5
10
10
0
0.5
1
1.5
2
Time / h
2.5
3
3.5
0
0.5
1
1.5
2
Time / h
2.5
3
3.5
(a) Control from pH13 to pH10.5. (b) Control from pH13 to pH10.
10
0
0.5
1
1.5
2
Time / h
2.5
3
3.5
(c) Control from pH13 to pH11.
Figure 2.1: Response of a controlled neutralisation CSTR with back-linearization for
dierent set points of pH. The starting value is always pH13. One set of PID
parameters is not appropriate for all cases (optimized for case a) ). Feedback
1
1
lag 50 s, P = 2 · 1010 pH
, I = 6 · 109 s pH
.
approach is, that the overshoot (e.g. in example b) ) appears huge in the logarithmic
domain but is not in the linear (controlled) one. Keeping this logarithmic behavior in
mind, the reverse case, when controllong from pH10, pH11 or pH12 to pH13 looks well
for all cases.
It would be good to have some anti-windup1 in the real plant.
1 The integral term gets windup very quickly (especially in this logarithmic domain), thus it accumulates an output that is larger than the maximal value for the regulation variable.
13
3 Appendix
In gures 3.1 3.2 3.3 & 3.4 the models inplemented in Simulink for the intuitive model,
its substructures and the linearized model are depicted. The last two pages contain
the Matlab code to execute the models. All complete les can also be downloaded
from http://www.thirdway.ch/En/projects/neutralisation_modeling (or thirdway.ch ->
projects -> Neutralisation modeling). The Simulink models and code for the academic
approach are not shown here, but can be downloaded from the same place.
14
Modelling of a neutralisation reactor
Step(response(of(the(neutralisation
1
Acid(pump
set(point
Acid(pump
setpoint
Reactor(pH
In1 Out1
Scope1
CSTR
neutralisation
reactor
simout1
To(Workspace2
Controlled(neutralisation(plant
10.5
PID4s3
pH(setpoint
PI(Controller
In1 Out1
Transport
Delay
Scope2
CSTR
neutralisation
reactor1
simout2
To(Workspace
Controlled(linearized(plant
pH_set
PID4s3
pH(setpoint1
PI(Controller1
In1 Out1
Scope4
Linearized(CSTR
Transport
Delay1
simout3
To(Workspace1
Figure 3.1: Overview of the Simulink block structure for the intuitive approach. Step
response, controlled plant and controlled linearized plant.
S. Zihlmann
February 23, 2015
Page 15 of 18
Modelling of a neutralisation reactor
Model1of1the1neutralisation1CSTR.1One1balance1for1each1of1H41and1OH-.
b_A
Setpoint1acid1pump
1
In1
Saturation
CA_H
Acid1feedrate
V_A
Product4
-C-
b
Product3
1/V
Acid1pump1capacity
Gain2
V_F
Feedrate
1
xo s
b
1
Out1
Get1pH
b_init
Product2
In1 Out1
integrator
b_init
b_F
b_F
Product1
Figure 3.2: Simulink structure of the intuitive model.
CalculateGpHGvalue
InputGconcentration
H+G-GOHinGmol/l
1
In1
u2
u
Square
4e-14
H+Gconc
1/2
log10
Gain3
pHGvalue
-1
Math
Function
Gain1
1
Out1
Sqrt
ConvertGH+GconcGtoGpH
IonGproduct
FulfillGH+G+GOH-G=GH2OGequilibrium
->GRootGsolver
Figure 3.3: Root solver `Get pH' of the intuitive model.
Linearized3plant
A
Acid3pump
1
In1
Setpoint
acid3pump
Saturation1
A
-K-
u(t)
B
Acid
pump3capacity
B
ue
1
xo s
x0
init
linearization
point1
x
integrator
y(t)
C
1
C
xe
ye
linearization
point2
linearization
point3
Out1
Figure 3.4: Structure of the linearized model.
S. Zihlmann
February 23, 2015
Page 16 of 18