445,820 Members | 1,189 Online
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

Gas Z-factor code problems

 P: 5 Hey there people, i'm having some serious problems in my assignment. (C++ programming) I have to calculate the gas z-factor using the Hall-Yarborough Method, and I can't seem to know how to start. It would be deeply appreciated, if someone could help. Thanks!! Mar 21 '07 #1
10 Replies

 Expert 5K+ P: 5,000 Here this gives you some information about the math involved. http://www.peteng.com/jmm/zfc02.html Mar 21 '07 #2

 P: 5 Here this gives you some information about the math involved. http://www.peteng.com/jmm/zfc02.html Thanks for the info but, know about the formula involved. It's just that i don't know how to write the code. Please help me!! Mar 23 '07 #3

 Expert 5K+ P: 5,000 Why dont you start by writing down the steps involved in the formula. What are the inputs and outputs at each stage? What do you have to do to the numbers at each stage of the process to come up with the right answer. Mar 23 '07 #4

 P: 5 Why dont you start by writing down the steps involved in the formula. What are the inputs and outputs at each stage? What do you have to do to the numbers at each stage of the process to come up with the right answer. Okay. Well, i know that in order to find Z, i will first have to find Ppr, t and y. In order to do this, i propose we use functions. But according to the y formula (from the website given above) we have to apply the Newton-Raphson method. Now to me, this is very difficult to do. I know how to write a typical code for the N-R method but this one is crazy. Maybe, i'm overseeing things to much. To calculate t, i take as input the pseudo-reduced temperature (since t is the reciprocal of this temperature) and return t. Actually, it is also calculated by Tpc/T. Therefore, INPUT: T and Tpc. Return t. But, i believe in this case we have to call the Tpc function, because we have not yet calculated Tpc. To calculate Ppr, it is the pressure (P) the user inputs divided by the pseudo-critical pressure (Ppc). Return ppr You see, i have to calculate Ppc (pseudo-critical pressure) by summing the product of the critical pressure (Pc) of each component and their mole fraction. This is the same for calculating Tpc (pseudo-critical temperature) which is the sum of the product of the critical temp (Tc) of each component and their mole fraction. So i guess, we ask the user for these critical values and their respective mole fraction. This is not too hard. But still, could u see what u could do? The major problem lies within the Newton-Raphson Method to find y from the given formula. Does this help? Mar 24 '07 #5

 P: 99 i dont know, does it? i think the point is to use some algebra to break down the equations into more manageably codable chunks . . . dont try to code the whole solution at once, code small sections of it first, one term at a time, and then cut and paste them all together. you wont be able to read what you have in the end, but the compiler will. you will know youve got it right, because you are using basic algebraic operations to get the final product. (specifically - substitution) you will know youve got it right also after running some test data. Mar 24 '07 #6

 P: 5 Well, i started to work on it piece by piece rather than the whole thing one time. So, thanks anyway for your help RedSon and Roonie. I'll see what i can do. Any problems that I encounter i'll post it. Again, thanks!!!! Mar 25 '07 #7

 P: 99 or, i guess thats a bad way to leave things for the next programmer . . . probably youd want to do the substitutions with functions and give them useful names. ideas the same though: let the algebra shape your solution. come again whenever. Mar 25 '07 #8

 P: 5 I've made some progress, but i'm not too sure the functions are accurate. Please double check it.The only thing I have to do now is to calulate y via the Newton-Raphson method. If it's possible, cud u help me with it. Here' s the CODE: Please respond soon, thank you. Expand|Select|Wrap|Line Numbers #include  #include  #include  //List prototypes   double calculate Pr (double P); double calculate t (double T); double calculate y (double Pr, double T); double calculate Ppc (int n, double Pc); double calculate Tpc (int n, double Tc); double calculate Tpc-corr (double Tpc, double E); double calculate Ppc-corr (double Tpc-corr, double Ppc,double Tpc, double E); double calculate Ppr (double Ppc-corr, double P);   using namespace std; int main (){     double Z, t, y, Ppr;          y = calculate y (Pr, T);        Ppr =  calculate Ppr(Ppc-corr,P);        t = calculate t (T);           Z = 0.06125 * Ppr * t * exp (-1.2(pow(1-t),2))/ y;                cout<<"The Gas Z-Factor is: "<>n;               cout<<"Enter the critical pressure for that component: ";               cin>>Pc;                sum = n* Pc;                count++;              sum = sum + count;         } while (n!=0);         return sum;   double calculate Tpc (int n, double Tc){        double sum;        int count;          count = 0;        sum = 0;           do {               cout<<"Enter the mole fraction of the component:";               cin>>n;               cout<<"Enter the critical temperature for that component: ";               cin>>Tc;                 sum = n* Tc;                count++;              sum = sum + count;         } while (n!=0);         return sum;   double calculate Pr (double P){             double Ppc;         cout<<"Enter P: ";        cin>>P;        Ppc = calculate Ppc (n, Pc);        Pr = P/ Ppc;          return Pr;   double calculate t (double T){                  double Tpc;        cout<<"Enter T: ";        cin>>T;        Tpc = calculate Tpc (n, Tc);        t = Tpc/T;          return t;   double calculate Tpc-corr (double Tpc, double E);                  double n1, n2, Tpc-corr;                  cout<<"Enter mole fractions for carbon dioxide and                       << "hydrogen sulphide respectively: ";                  cin>>n1>>n2;                    E = 66.667* ((pow(n1+n2),0.9) - (pow(n1+n2),1.6)) +                       8.333((pow(n2),0.5)- pow(n2),4));                  Tpc = calculate Tpc (n, Tc);                    Tpc-corr = Tpc - E;                    return Tpc-corr;   double calculate Ppc-corr (double Tpc-corr, double Ppc,double Tpc, double E){                           double n2;                           double Ppc-corr;        Tpc-corr = calculate Tpc-corr (Tpc, E);          Ppc =  calculate Ppc (n, Pc);          Ppc-corr = (Ppc*Tpc-corr)/(Tpc+n2*(1-n2)*E);                   return Ppc-corr;   double calculate Ppr (double Ppc-corr, double P){                  double Ppr;          Ppc-corr = calculate Ppc-corr (Tpc-corr, Ppc, Tpc, E);            Ppr = P/Ppc-corr;            return Ppr;   Mar 27 '07 #9

 Expert 5K+ P: 5,000 I've made some progress, but i'm not too sure the functions are accurate. Please double check it.The only thing I have to do now is to calulate y via the Newton-Raphson method. If it's possible, cud u help me with it. I'm not a petroleum engineer so I have no idea if the functions and hence the arithmetic in your application is correct. Does your program calculate the correct answer the same as you would manually? That is one way to check that the functions are right. Your code looks fine, does it compile? I expect that when you copied and pasted your code some under scores went missing but that should be no problem. Mar 27 '07 #10

 Expert 5K+ P: 5,000 I also recommend changing the names of your variables away from the names used in the formula to names that are more readable. Mar 27 '07 #11