A Continuous Stirred-Tank Reactor (CSTR) is a type of chemical reactor that has a wealth of applications in industrial processes. The CSTR models an irreversible chemical reaction which transforms a chemical liquid \(A\) into a mix of chemicals. In this tutorial, we will investigate how to model this process in Collimator.

The CSTR can be modeled as a nonlinear system of differential equations:

$$\frac{d C_r}{dt} = \frac{F}{V}\left( C_{Ai}\left(t\right) - C_{r}\left(t\right) \right) -k_0 e^{\frac{-E}{R T_r\left(t\right)}} C_r\left(t\right)$$

$$\frac{d T_r\left(t\right)}{dt} = \frac{F}{V}\left( T_{Ai}\left(t\right) - T_{r}\left(t\right) \right)-\frac{\Delta H}{\rho C_p} k_0 e^{\frac{-E}{R T_r\left(t\right)}}-\frac{U A}{\rho C_p V}\left( T_{r}\left(t\right) - T_{c}\left(t\right) \right)$$

The CSTR variables and parameters are denoted in the following tables:

\begin{array} {|l|l|} \hline Variable & Unit & Description \\ \hline C_{Ai} & \frac{kmol}{m^3} & \text{Concentration of A in inlet flow} \\ \hline C_{r} & \frac{kmol}{m^3} & \text{Concentration of A in reactor mix} \\ \hline T_{Ai} & K & \text{Temperature of inlet flow}\\ \hline T_{r} & K & \text{Temperature of reactor mix} \\ \hline T_{c} & K & \text{Temperature of cooling medium} \\ \hline \end{array}

\begin{array} {|l|l|}\hline Parameter & Value & Unit & Description \\ \hline F & 1.2 & \frac{m^3}{h} & \text{Inlet flow rate}\\ \hline V & 1.2 & m^3 & \text{Reactor mix volume}\\ \hline R & 1.987204259 & \frac{kcal}{kmol.K} & \text{Boltzmann's constant}\\ \hline \Delta H & 6250 & \frac{kcal}{kmol} & \text{Reaction heat per mole}\\ \hline E & 12580 & \frac{kcal}{kmol} & \text{Activation energy per mole}\\ \hline k_0 & 36725500 & h^{-1} & \text{Reaction frequency factor}\\ \hline \rho & 1000 & \frac{kcal}{kmol.K} & \text{Density of reaction mix}\\ \hline C_p & 1.16 & \frac{kcal}{kg.K} & \text{Specific heat of reaction mix}\\ \hline U A & 200 & \frac{kcal}{K.h} & \displaylines{\text{Overall heat transfer coefficient}\\\text{multiplied by heat transfer area}}\\ \hline \end{array}

In our Collimator Notebook, we will begin by importing the libraries we will use.

Then we will begin modeling the CSTR by defining the system parameters

Then, we define the following lumped constants to simplify the modeling process in our Collimator Model Editor:

Now, we move to the Model Editor to build the CSTR nonlinear model as in the following diagram:

The model above is lumped in a Subsystem block:

After that, we define the lumped model parameters that we computed before:

Before extracting the model, we will install the the "slycot" library so that we can linearize multi-input multi-output systems:

Finally, we extract the CSTR linearized model:

The CSTR transfer function between the manipulated variable of the cooling medium temperature *\(T_c\)* and the concentration of the reactor mix *\(C_c\)* is:

First, we'll take a look at the step response of the linearized transfer function:

From the step response, we can see that the CSTR linearized transfer function is overdamped and can be approximated by a first-order transfer function:

$$C \left( s \right) = \frac{b}{s+a}$$

\(a\) can be approximated using the following rule:

$$\text{Rise Time} = \frac{2.2}{a}$$

Meanwhile, the gain can be computed easily from the CSTR DC gain as follows:

Consequently, we can use the following simple rules for tuning a PI controller for a first-order system:

$$C\left( s \right) = k_p+\frac{k_i}{s}$$

$$k_p=\frac{2 \zeta \omega_0 - a}{b}$$

$$k_i=\omega_0^2/b$$

Tuning the PI controller through parameters \(\omega_0\) and \(\zeta\) is much easier as they have more meaningful physical interpretation. We can increase the response speed be increasing \(\omega_0\) while we can control the shape of response with \(\zeta\). Therefore, we define the following interactive tuning function:

We can get a potential satisfactory response for values of \(\omega_0 = 0.8\) and \(\zeta = 1\). This leads to a PI controller of \(C\left(s\right)=282+\frac{202.7}{s}\)

We now evaluate the obtained PI controller with the nonlinear model in the Model Editor. The closed-loop feedback with the PI controller is implemented as in the following diagram:

Then, we update the PI values:

Finally, we run the simulation to investigate the results. The reactor mix concentration response and temperature are given in the Model Visualizer: