ph_process.cc

Go to the documentation of this file.
00001 
00011 #include "ph_process.h"
00012 #include <math.h>
00013 
00014 
00015 
00016 ph_process::ph_process(dsim_model_setup *setup) : dsim_model(setup)
00017 {
00018 }
00019 
00020 ph_process::~ph_process()
00021 {
00022 }
00023         
00027 void ph_process::initialize_data()
00028 {               
00029     // Parameters
00030     double wA1       = 0.003;                   // Mole
00031     double wA2       = -0.03;                   // Mole
00032     double wA3       = -3.05e-3;                // Mole
00033     double wB1       =  0.0;                    // Mole
00034     double wB2       =  0.03;                   // Mole
00035     double wB3       =  5.0e-5;                 // Mole
00036     double a         = 207;                     // cm^2
00037     double cV        = 1;                       // Valve coefficient
00038     double n         =  0.607;
00039     double z         = 11.5;                    // cm
00040     double q1        = 16.6;                    // ml/s
00041     double q2        = 15.6;                    // ml/s
00042     double q3        =  0.55;                   // ml/s This is used as the control
00043     
00044     // Integrated states
00045     double wA4         = -4.32e-4;              // Mole
00046     double wB4         =  5.28e-4;              // Mole
00047     double h           = 14.0;                  // cm
00048 
00049     wA1_dsim = create_parameter("wA1",  sd_type_double, &wA1,   1,1,    "Mole", "Acid stream 1");                                       wA1_dsim.mark_telemetry();
00050     wA2_dsim = create_parameter("wA2",  sd_type_double, &wA2,   1,1,    "Mole", "Acid stream 2");                                       wA2_dsim.mark_telemetry();
00051     wA3_dsim = create_parameter("wA3",  sd_type_double, &wA3,   1,1,    "Mole", "Acid stream 3");                                       wA3_dsim.mark_telemetry();
00052     wA1_dsim = create_parameter("wB1",  sd_type_double, &wB1,   1,1,    "Mole", "Base stream 1");                                       wB1_dsim.mark_telemetry();
00053     wB1_dsim = create_parameter("wB2",  sd_type_double, &wB2,   1,1,    "Mole", "Base stream 2");                                       wB2_dsim.mark_telemetry();
00054     wB2_dsim = create_parameter("wB3",  sd_type_double, &wB3,   1,1,    "Mole", "Base stream 3");                                       wB3_dsim.mark_telemetry();
00055     a_dsim   = create_parameter("a",    sd_type_double, &a,     1,1,    "cm^2", "Crossectional area of the mixing tank");               a_dsim.mark_telemetry();
00056     cV_dsim  = create_parameter("cV",   sd_type_double, &cV,    1,1,    "",     "Valve coefficient");                                   cV_dsim.mark_telemetry();
00057     n_dsim   = create_parameter("n",    sd_type_double, &n,     1,1,    "",     "Valve exponent");                                      n_dsim.mark_telemetry();
00058     z_dsim   = create_parameter("z",    sd_type_double, &z,     1,1,    "cm",   "Vertical distance between bottom of tank and outlet"); z_dsim.mark_telemetry();
00059     q1_dsim  = create_parameter("q1",   sd_type_double, &q1,    1,1,    "M",    "Volumetric flow of HNO3");                             q1_dsim.mark_telemetry();
00060     q2_dsim  = create_parameter("q2",   sd_type_double, &q2,    1,1,    "M",    "Volumetric flow of NaHCO3");                           q2_dsim.mark_telemetry();
00061     q3_dsim  = create_parameter("a3",   sd_type_double, &q3,    1,1,    "M",    "Volumetric flow of NaOH");                             q3_dsim.mark_telemetry();
00062         
00063     wA4_dsim = create_integrated_state("wA4", sd_type_double,   &wA4,   1,1,    "Mole", "Acid stream 4");                               wA4_dsim.mark_telemetry();
00064     wB4_dsim = create_integrated_state("wB4", sd_type_double,   &wB4,   1,1,    "Mole", "Base stream 4");                               wB4_dsim.mark_telemetry();
00065     h_dsim   = create_integrated_state("h",   sd_type_double,   &h,     1,1,    "cm",   "Fluid level");                                 h_dsim.mark_telemetry();
00066 
00067     configure_timestep(false,true,false);
00068 }
00069 
00071 void ph_process::initialization_complete()
00072 {
00073 }
00074 
00076 void ph_process::initialize_timestep()
00077 {
00078 }
00079 
00084 void ph_process::rhs(double t,double jd)
00085 {
00086     double wA1      = wA1_dsim.value_as_double();
00087     double wA2      = wA2_dsim.value_as_double();
00088     double wA3      = wA3_dsim.value_as_double();
00089     double wB1      = wB1_dsim.value_as_double();
00090     double wB2      = wB2_dsim.value_as_double();
00091     double wB3      = wB3_dsim.value_as_double();
00092     double a        = a_dsim.value_as_double();
00093     double cV       = cV_dsim.value_as_double();
00094     double n        = n_dsim.value_as_double();
00095     double z        = z_dsim.value_as_double();
00096     double q1       = q1_dsim.value_as_double();
00097     double q2       = q2_dsim.value_as_double();
00098     double q3       = q3_dsim.value_as_double();    
00099     double wA4      = wA4_dsim.value_as_double();
00100     double wB4      = wB4_dsim.value_as_double();
00101     double h        = h_dsim.value_as_double();
00102     
00103     double hA       = 1/(h*a);
00104     
00105     double wA4_dot  = hA*( (wA1 - wA4)*q1 + (wA2 - wA4)*q2 + (wA3 - wA4)*q3 );
00106     double wB4_dot  = hA*( (wB1 - wB4)*q1 + (wB2 - wB4)*q2 + (wB3 - wB4)*q3 );
00107     double h_dot    = q1 + q2 + q3 - cV*pow(h - z,n);
00108     
00109     wA4_dsim.set_derivative(wA4_dot);
00110     wB4_dsim.set_derivative(wB4_dot);
00111     h_dsim.set_derivative(h_dot);
00112 }
00113 
00115 void ph_process::complete_timestep()
00116 {
00117         dsim_model::complete_timestep();
00118 }
00119 
00120 extern "C"
00121 {
00122     dsim_model *PHProcess(void *setup);
00123 
00124         dsim_model *PHProcess(void *setup)
00125         {
00126                 return new ph_process((dsim_model_setup *)setup);
00127         }
00128         
00129 }
 All Classes Files Functions Variables