A simple model of a pH process. More...
#include <ph_process.h>
Public Member Functions | |
ph_process (dsim_model_setup *setup) | |
void | initialize_data () |
void | initialization_complete () |
Finish initialization. | |
void | initialize_timestep () |
Computation done prior to numerical integration. | |
void | rhs (double t, double jd) |
void | complete_timestep () |
Computation done after numerical integration. | |
Protected Attributes | |
dsim_variable | wA1_dsim |
Acid stream 1. | |
dsim_variable | wA2_dsim |
Acid stream 2. | |
dsim_variable | wA3_dsim |
Acid stream 3. | |
dsim_variable | wB1_dsim |
Base stream 1. | |
dsim_variable | wB2_dsim |
Base stream 2. | |
dsim_variable | wB3_dsim |
Base stream 3. | |
dsim_variable | a_dsim |
Crossectional area of the mixing tank. | |
dsim_variable | cV_dsim |
Valve coefficient. | |
dsim_variable | n_dsim |
Valve exponent. | |
dsim_variable | z_dsim |
Vertical distance between bottom of tank and outlet. | |
dsim_variable | q1_dsim |
Volumetric flow of HNO3. | |
dsim_variable | q2_dsim |
Volumetric flow of NaHCO3. | |
dsim_variable | q3_dsim |
Volumetric flow of NaOH. | |
dsim_variable | wA4_dsim |
Acid stream 4. | |
dsim_variable | wB4_dsim |
Base stream 4. | |
dsim_variable | h_dsim |
Height (fluid level) |
A simple model of a pH process.
The process consists of an acid (HNO3) stream, buffer (NaHCO3) stream, and base (NaOH) stream thar are mixed in a stirred tank. The chemical equilibria is modeled by introducing two reaction invariants for each inlet stream. + - - = wAi = [H ]i - [OH ]i - [HCO3]i - 2[CO3]i
Reference: Henson, M. A. and D. E. Seborg. (1997.) Nonlinear Process Control Prentice-Hall. pp. 207-210.
Definition at line 33 of file ph_process.h.
void ph_process::initialize_data | ( | ) |
Create the parameters and states.
Definition at line 27 of file ph_process.cc.
{ // Parameters double wA1 = 0.003; // Mole double wA2 = -0.03; // Mole double wA3 = -3.05e-3; // Mole double wB1 = 0.0; // Mole double wB2 = 0.03; // Mole double wB3 = 5.0e-5; // Mole double a = 207; // cm^2 double cV = 1; // Valve coefficient double n = 0.607; double z = 11.5; // cm double q1 = 16.6; // ml/s double q2 = 15.6; // ml/s double q3 = 0.55; // ml/s This is used as the control // Integrated states double wA4 = -4.32e-4; // Mole double wB4 = 5.28e-4; // Mole double h = 14.0; // cm wA1_dsim = create_parameter("wA1", sd_type_double, &wA1, 1,1, "Mole", "Acid stream 1"); wA1_dsim.mark_telemetry(); wA2_dsim = create_parameter("wA2", sd_type_double, &wA2, 1,1, "Mole", "Acid stream 2"); wA2_dsim.mark_telemetry(); wA3_dsim = create_parameter("wA3", sd_type_double, &wA3, 1,1, "Mole", "Acid stream 3"); wA3_dsim.mark_telemetry(); wA1_dsim = create_parameter("wB1", sd_type_double, &wB1, 1,1, "Mole", "Base stream 1"); wB1_dsim.mark_telemetry(); wB1_dsim = create_parameter("wB2", sd_type_double, &wB2, 1,1, "Mole", "Base stream 2"); wB2_dsim.mark_telemetry(); wB2_dsim = create_parameter("wB3", sd_type_double, &wB3, 1,1, "Mole", "Base stream 3"); wB3_dsim.mark_telemetry(); a_dsim = create_parameter("a", sd_type_double, &a, 1,1, "cm^2", "Crossectional area of the mixing tank"); a_dsim.mark_telemetry(); cV_dsim = create_parameter("cV", sd_type_double, &cV, 1,1, "", "Valve coefficient"); cV_dsim.mark_telemetry(); n_dsim = create_parameter("n", sd_type_double, &n, 1,1, "", "Valve exponent"); n_dsim.mark_telemetry(); z_dsim = create_parameter("z", sd_type_double, &z, 1,1, "cm", "Vertical distance between bottom of tank and outlet"); z_dsim.mark_telemetry(); q1_dsim = create_parameter("q1", sd_type_double, &q1, 1,1, "M", "Volumetric flow of HNO3"); q1_dsim.mark_telemetry(); q2_dsim = create_parameter("q2", sd_type_double, &q2, 1,1, "M", "Volumetric flow of NaHCO3"); q2_dsim.mark_telemetry(); q3_dsim = create_parameter("a3", sd_type_double, &q3, 1,1, "M", "Volumetric flow of NaOH"); q3_dsim.mark_telemetry(); wA4_dsim = create_integrated_state("wA4", sd_type_double, &wA4, 1,1, "Mole", "Acid stream 4"); wA4_dsim.mark_telemetry(); wB4_dsim = create_integrated_state("wB4", sd_type_double, &wB4, 1,1, "Mole", "Base stream 4"); wB4_dsim.mark_telemetry(); h_dsim = create_integrated_state("h", sd_type_double, &h, 1,1, "cm", "Fluid level"); h_dsim.mark_telemetry(); configure_timestep(false,true,false); }
void ph_process::rhs | ( | double | t, |
double | jd | ||
) |
Computation done during numerical integration. Model the process PH and set the derivatives of the acid and base streams.
Definition at line 84 of file ph_process.cc.
{ double wA1 = wA1_dsim.value_as_double(); double wA2 = wA2_dsim.value_as_double(); double wA3 = wA3_dsim.value_as_double(); double wB1 = wB1_dsim.value_as_double(); double wB2 = wB2_dsim.value_as_double(); double wB3 = wB3_dsim.value_as_double(); double a = a_dsim.value_as_double(); double cV = cV_dsim.value_as_double(); double n = n_dsim.value_as_double(); double z = z_dsim.value_as_double(); double q1 = q1_dsim.value_as_double(); double q2 = q2_dsim.value_as_double(); double q3 = q3_dsim.value_as_double(); double wA4 = wA4_dsim.value_as_double(); double wB4 = wB4_dsim.value_as_double(); double h = h_dsim.value_as_double(); double hA = 1/(h*a); double wA4_dot = hA*( (wA1 - wA4)*q1 + (wA2 - wA4)*q2 + (wA3 - wA4)*q3 ); double wB4_dot = hA*( (wB1 - wB4)*q1 + (wB2 - wB4)*q2 + (wB3 - wB4)*q3 ); double h_dot = q1 + q2 + q3 - cV*pow(h - z,n); wA4_dsim.set_derivative(wA4_dot); wB4_dsim.set_derivative(wB4_dot); h_dsim.set_derivative(h_dot); }