473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Gas Z-factor code problems

chimmy48
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 2844
RedSon
5,000 Expert 4TB
Here this gives you some information about the math involved.

http://www.peteng.com/jmm/zfc02.html
Mar 21 '07 #2
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
RedSon
5,000 Expert 4TB
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
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
Roonie
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
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
Roonie
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
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
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <cmath>
  4. //List prototypes
  5.  
  6. double calculate Pr (double P);
  7. double calculate t (double T);
  8. double calculate y (double Pr, double T);
  9. double calculate Ppc (int n, double Pc);
  10. double calculate Tpc (int n, double Tc);
  11. double calculate Tpc-corr (double Tpc, double E);
  12. double calculate Ppc-corr (double Tpc-corr, double Ppc,double Tpc, double E);
  13. double calculate Ppr (double Ppc-corr, double P);
  14.  
  15. using namespace std;
  16. int main (){
  17.     double Z, t, y, Ppr;
  18.  
  19.        y = calculate y (Pr, T);
  20.        Ppr =  calculate Ppr(Ppc-corr,P);
  21.        t = calculate t (T); 
  22.  
  23.        Z = 0.06125 * Ppr * t * exp (-1.2(pow(1-t),2))/ y;
  24.  
  25.  
  26.            cout<<"The Gas Z-Factor is: "<<Z<<endl;
  27.  
  28.  
  29.  
  30.  
  31.     system("PAUSE");
  32.     return EXIT_SUCCESS;
  33. }
  34. double calculate Ppc (int n, double Pc){
  35.        double sum;
  36.        int count;
  37.  
  38.        count = 0;
  39.        sum = 0;
  40.  
  41.  
  42.       do {
  43.               cout<<"Enter the mole fraction of the component:";
  44.               cin>>n;
  45.               cout<<"Enter the critical pressure for that component: ";
  46.               cin>>Pc;
  47.  
  48.              sum = n* Pc;
  49.  
  50.              count++;
  51.              sum = sum + count;
  52.  
  53.       } while (n!=0);
  54.  
  55.       return sum;
  56.  
  57. double calculate Tpc (int n, double Tc){
  58.        double sum;
  59.        int count;
  60.  
  61.        count = 0;
  62.        sum = 0;
  63.  
  64.  
  65.       do {
  66.               cout<<"Enter the mole fraction of the component:";
  67.               cin>>n;
  68.               cout<<"Enter the critical temperature for that component: ";
  69.               cin>>Tc;
  70.  
  71.               sum = n* Tc;
  72.  
  73.              count++;
  74.              sum = sum + count;
  75.  
  76.       } while (n!=0);
  77.  
  78.       return sum;
  79.  
  80. double calculate Pr (double P){
  81.             double Ppc; 
  82.        cout<<"Enter P: ";
  83.        cin>>P;
  84.        Ppc = calculate Ppc (n, Pc);
  85.        Pr = P/ Ppc;
  86.  
  87.        return Pr;
  88.  
  89. double calculate t (double T){
  90.                  double Tpc;
  91.        cout<<"Enter T: ";
  92.        cin>>T;
  93.        Tpc = calculate Tpc (n, Tc);
  94.        t = Tpc/T;
  95.  
  96.        return t;
  97.  
  98. double calculate Tpc-corr (double Tpc, double E);
  99.                  double n1, n2, Tpc-corr;
  100.                  cout<<"Enter mole fractions for carbon dioxide and 
  101.                      << "hydrogen sulphide respectively: ";
  102.                  cin>>n1>>n2;
  103.  
  104.                  E = 66.667* ((pow(n1+n2),0.9) - (pow(n1+n2),1.6)) + 
  105.                      8.333((pow(n2),0.5)- pow(n2),4));
  106.                  Tpc = calculate Tpc (n, Tc);
  107.  
  108.                  Tpc-corr = Tpc - E;
  109.  
  110.                  return Tpc-corr;
  111.  
  112. double calculate Ppc-corr (double Tpc-corr, double Ppc,double Tpc, double E){
  113.                           double n2;
  114.                           double Ppc-corr;
  115.        Tpc-corr = calculate Tpc-corr (Tpc, E);
  116.  
  117.        Ppc =  calculate Ppc (n, Pc);
  118.  
  119.        Ppc-corr = (Ppc*Tpc-corr)/(Tpc+n2*(1-n2)*E);
  120.  
  121.  
  122.               return Ppc-corr;
  123.  
  124. double calculate Ppr (double Ppc-corr, double P){
  125.                  double Ppr;
  126.          Ppc-corr = calculate Ppc-corr (Tpc-corr, Ppc, Tpc, E);
  127.  
  128.          Ppr = P/Ppc-corr;
  129.  
  130.          return Ppr;
  131.  
Mar 27 '07 #9
RedSon
5,000 Expert 4TB
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
RedSon
5,000 Expert 4TB
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

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Torbjørn Pettersen | last post by:
I'm having problems validating my HTML code because of some ASP code I'm using: ---Start Code--- <% If rs("Average") = 0 Then VotingImage = "<img src="/images/0.gif" alt='No votes yet'>"...
14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
0
by: JMCN | last post by:
i have been running into some ftp problems. when i run the ftp, the log indicates that it has been ftp'd. here is my ftp log: USER XX PASS XXX CONNECT XXX.dns.com CD $1$DKB101: GET...
2
by: tzvika.visman | last post by:
I write a MC++ wrapper for our company internal SDK that wrote in C++ native code for writing application with this SDK over C# and other .NET languages and most of my SDK API function return a...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
11
by: kartheeknagasuri | last post by:
my friend gave this code to me..... it is working fine....how come? please explain me if u can understand..... #include <stdio.h> #include <conio.h> #define _(__,___)\ ___##__
7
by: P Pulkkinen | last post by:
This all below is my opinion, not any official post though... ====================================== 1) Have a debugging/error handling system. It is not so difficult to make, I have made one...
6
by: David Mathog | last post by:
Do any of you happen to have links to compendiums (or heaven forbid, an actual manual) which maps compiler warnings and errors to examples of actual code problems? In this case I'm specifically...
2
by: jwhitehouse2346 | last post by:
Having real problems Created my ASP site which connected and submitted/retrieved data happily to my database which was stored on my hard drive, within the web sites folders. No code problems at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.