1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
#include <iostream>
#include <math.h>
using namespace std;
class initialize {
double p,t,ant,mar,y,x,pc,tc,omega;
int i, comps, j;
char name;
public:
double pressure () {
cout << "Enter in the pressure of the system" << endl;
cin >> p;
return p;}
double temperature () {
cout << "Enter in the temperature of the system" << endl;
cin >> t;
return t;}
double crit_t (int i) {
cout << "Enter the critical temperature, in Kelvin, for component # " << i << endl;
cin >> tc;
return tc;}
double crit_p (int i) {
cout << "Enter in critical pressure, in bar, for component # " << i << endl;
cin >> pc;
return pc;}
double accentric (int i) {
cout << "Enter the accentric factor for component # " << i << endl;
cin >> omega;
return omega;}
int numcomps() {
cout << "Enter in the number of components in the system" << endl;
cin >> comps;
return comps;}
double antoine(int i, int k) {
if (i == 0)
{
name = 'A';
}
else if ( i == 1)
{
name = 'B';
}
else if (i == 2)
{
name = 'C';
}
else
{
name = 'E';
}
cout << "Enter the " << name << k + 1<< " Antoine Constant" << endl;
cin >> ant;
return ant;}
double margules(int i) {
cout << "Enter the A" << i+1 << 2-i << " Margules constant" << endl;
cin >> mar;
return mar;}
double y_frac (int i) {
cout << "Enter in the vapor mole fraction for component # " << i + 1<< endl;
cin >> y;
return y;}
double x_frac (int i) {
cout << "Enter in the liquid mole fraction for component # " << i + 1 << endl;
cin >> x;
return x;}
};
class root{
double a, b, c, d, q, r, delta, s, t, rt[3], rho, theta, rtf;
public:
double minima(double a, double b, double c, double d){
q = (3*a*c-b*b)/(9*a*a);
r = (9*a*b*c-27*a*a*d-2*pow(b,3))/(54*pow(a,3));
delta = pow(q,3)+pow(r,2);
cout << " q " << q << " r " << r << " delta " << delta << endl;
if (delta >= 0 )
{
cout << "1 root" << endl;
s = pow((r + sqrt(delta)),1.0/3.0);
s = s*(r + sqrt(delta))/abs((r + sqrt(delta)));
t = pow(abs((r - sqrt(delta))),1.0/3.0);
t = t*(r - sqrt(delta))/abs((r - sqrt(delta)));
rt[0] = s+t-b/(3*a);
rtf = rt[0];
}
else if (delta < 0)
{
cout << "3 roots" << endl;
rho = -pow(q,3);
rho = sqrt(rho);
theta = acos(r/rho);
rt[0] = 2*pow(rho,1.0/3.0)*cos(theta/3.0)-b/(3*a);
rt[1] = -pow(rho,1.0/3.0)*cos(theta/3.0)-b/(3*a)-sqrt(3.0)*pow(rho,1.0/3.0)*sin(theta/3.0);
rt[2] = -pow(rho,1.0/3.0)*cos(theta/3.0)-b/(3*a)+sqrt(3.0)*pow(rho,1.0/3.0)*sin(theta/3.0);
cout << rt[0] << "\t" << rt[1] << "\t" << rt[2] << endl;
}
cout << rt[0] << endl;
return 0;
}
};
class vle {
initialize prop;
double p, t, aant[2],bant[2], cant[2], mar[2], y[2],pc[2],tc[2],omg[2];
int i, m, j;
public:
double dew_t() {
/*Feed in system presseure for Dew T calc */
p = prop.pressure();
/*Specify number of components*/
m = prop.numcomps();
/*Supply gas phase compositions, Antoine constants, Margules' parameters, and critical property data for Dew T calc */
for (i = 0; i<= m-1; ++i)
{
y[i] = prop.y_frac(i);
mar[i] = prop.margules(i);
tc[i] = prop.crit_t(i);
pc[i] = prop.crit_p(i);
omg[i] = prop.accentric(i);
for (j = 0; j <=2; ++j)
{
if (j == 0)
{
aant[i] = prop.antoine(j,i);
}
else if ( j==1 )
{
bant[i] = prop.antoine(j,i);
}
else if ( j == 2)
{
cant[i] = prop.antoine(j,i);
}
}
}
cout << "Pressure: " << p << " Mole fractions " << y[0] << '\t' << y[1] << endl;
for (i=0; i<= m-1; ++i)
{
cout << "Antoine constants A" << i +1 << '\t' << aant[i] << " B" << i+1 << '\t' << bant[i] << '\t' << "C" << i+1 << '\t' << cant[i] << endl;
cout << "Margules constant A" << i+1 << 2-i << "\t" << mar[i] << endl;
}
return 0;
}
int return_m () {
return m;
}
}param;
class fug_coeff {
vle param;
root min;
double phi,phisat,bigphi;
public:
double big_phi_init()
{
bigphi = 1.0;
return bigphi;
}
};
class preos_params: public vle {
int n;
public:
double get_m()
{
n = param.return_m();
cout << n << endl;
return 0;
}
}prparam;
int main () {
/*cout <<"Enter cubic parameter" << endl;*/
/*cin >> a >> b >> c >> d;*/
vle param;
root min;
/*min.minima(a,b,c,d);*/
param.dew_t();
prparam.get_m();
return 0;
}
|