473,795 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gas Z-factor code problems

chimmy48
5 New Member
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 2877
RedSon
5,000 Recognized Expert Expert
Here this gives you some information about the math involved.

http://www.peteng.com/jmm/zfc02.html
Mar 21 '07 #2
chimmy48
5 New Member
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 Recognized Expert Expert
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
chimmy48
5 New Member
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 New Member
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
chimmy48
5 New Member
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 New Member
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
chimmy48
5 New Member
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 Recognized Expert Expert
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

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

Similar topics

12
2054
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'>" ElseIf rs("Average") >= 1 And rs("Average") < 2 Then VotingImage = "<img src=/images/1.gif alt='1 out of 6 stars'>"
14
2326
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 going to use .Net......I highly recommend signing up for the free KBAlertz newsletter at http://www.kbalertz.com/default.aspx. Looking at all of the errors and quirks sometimes makes me wonder if this thing is really ready for prime time.
0
1497
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 PROD6-06-09-04-299-2 C:\TEMP\PROD.txt 0 CD $1$DKA101:
2
1824
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 status code that define as a enum type. Do I have other option then duplicate the enum from the c++ to the C# code and write a MC++ class that look something like this: public __gc class ManagedDokStatus {
2
5438
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 recommended by many for web applications. I create the instances of Excel, Workbook and the worksheet. And later on Release the references by “System.Runtime.InteropServices.Marshal.ReleaseComObject(Object)” and making the object as null finally....
11
1906
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
1323
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 myself and it really often helped us in development. 2) Test code ALL the time, after every couple of lines, not in big chunks. 3) Leave debugging features inside, even if you use simple lines like: echo "now variable i = $i";
6
2273
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 looking for one for gcc. The general problem is of course that the compiler messages must be short, and that tends to make them so cryptic that it isn't always immediately obvious what the problem is. It almost makes me long for the days when the...
2
1434
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 all. As soon as I put the database in the ODBC controller I can still see the data from the database but I can no longer add data back to it. Any ideas? Thanks
0
10438
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.