Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem returning arrays 1

Status
Not open for further replies.

aaadetos

Programmer
Nov 21, 2004
54
0
0
US
I have the following code, which runs w/out erroe, but fails to return the proper values...
Code:
#include <math>
#include "stdafx.h"
#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;

const double PI = 3.141592653589793238462643383279502884197;
double q = 1000;//STB/D
double pi = 5000;//psia
double rw = 0.25;//ft
double h = 100;//ft
double por = 0.2;
double k = 200;//md
double ct = 0.00003;//psi-1
double Bo = 1.2;//RB/STB
double visc = 1.3;//cp
double C = 0.5;//RB/psi
double S = 10;
double tp = 200;//hrs
double delta_t = 200;//hrs
double a0,a1,a2,a3,a4,a5,b1,b2,b3,b4,c1,c2,c3,c4;
double a[50],b[50],c[50],expint;

double t[50],qsf[50],alpha,x[50],EI[50],beta[50],pd[50],pwf[50];

double time_hr()
{
	double N=49.0;
	for (int i=0;i<50;i++)
	{
		t[i] = 0.01*exp((i/N)*log(200/0.01));
	}
	return t[i];
}

int main(int argc, char* argv[])
{
//	printf("Hello World!\n");
	ofstream outputdeck;
	outputdeck.open("output.txt", ios::out);
	
	outputdeck<<"Type A: With Wellbore Storage.\n";
	outputdeck<<"Time"<<setw(5)<<"Pwf"<<setw(5)<<endl;
	for(int i=0;i<50;i++)
	{
		outputdeck<<t[i]<<endl
	}


	return 0;
}
This code returns a value of 0 for every value of i. t is supposed to increase from 0.01 to 200 as i increases from 0 to 49.

Can anyone pls tell me what i'm doing wrong?
Thank you.
 
You don't seem to be calling time_hr() anywhere, so why would t ever be filled?

You should definitely cut down on the number of globals you are using. You should be using none in this program.

After the loop, the value of i becomes garbage, so change your time_hr() code to return the last t[49] if that's what you want it to return.
 
timmay3141, thank you so much. i'm indeed grateful...this is the solution i didn't c. many thanks again!
 
Now, i have a new dilemma..
Code:
#include <math>
#include "stdafx.h"
#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;

const double PI = 3.141592653589793238462643383279502884197;
double q = 1000;//STB/D
double pi = 5000;//psia
double rw = 0.25;//ft
double h = 100;//ft
double por = 0.2;
double k = 200;//md
double ct = 0.00003;//psi-1
double Bo = 1.2;//RB/STB
double visc = 1.3;//cp
double C = 0.5;//RB/psi
double S = 10;
double tp = 200;//hrs
double delta_t = 200;//hrs
double a0,a1,a2,a3,a4,a5,b1,b2,b3,b4,c1,c2,c3,c4;
double a[50],b[50],c[50],expint;

double t[50],qsf[50],alpha,x[50],EI[50],beta[50],pd[50],pwf[50];

double time_hr()
{
	double N=49.0;
	for (int i=0;i<50;i++)
	{
		t[i] = 0.01*exp((i/N)*log(200/0.01));
	}
	return t[i];
}

//In the Presence of Wellbore Storage
double wbs()
{
	a0 = -0.57721566;
	a1 = 0.99999193;
	a2 = -0.24991055;
	a3 = 0.05519968;
	a4 = -0.00976004;
	a5 = 0.00107857;

	b1 = 8.5733287401;
	b2 = 18.059016973;
	b3 = 8.6347608925;
	b4 = 0.2677737343;

	c1 = 9.5733223454;
	c2 = 25.6329561486;
	c3 = 21.0996530827;
	c4 = 3.9584969228;

	int N = 49;
	alpha = (4/(3*PI*C))*(k*h/visc);
	
	for (int i=0;i<50;i++)
	{
		t[i] = 0.01*exp((i/N)*log(200/0.01));
		qsf[i] = q*(1-exp(-1*alpha*t[i]));
		x[i] = (948*por*visc*ct*pow(rw,2))/(k*t[i]);

		if (x[i]<=0.01)
		{
			EI[i] = log(x[i])+0.5772;
		}
		else
		{
			a[i] = pow(x[i],4)+(b1*pow(x[i],3))+(b2*pow(x[i],2))+(b3*x[i])+b4;
			b[i] = pow(x[i],4)+(c1*pow(x[i],3))+(c2*pow(x[i],2))+(c3*x[i])+c4;
			EI[i]= (1/(x[i]*exp(x[i])))*a[i]/b[i];
		}

		beta[i] = (-0.5*EI[i])+S;
		pd[i] = (1-(1/exp(alpha*t[i])))*beta[i];
		pwf[i] = pi-((141.2*q*visc*Bo*pd[i])/(k*h));
	}
	return pwf[i];
}


int main(int argc, char* argv[])
{
//	printf("Hello World!\n");
	ofstream outputdeck;
	outputdeck.open("output.txt", ios::out);
	
	outputdeck<<"Type A: With Wellbore Storage.\n";
	outputdeck<<"Time"<<setw(5)<<"Pwf"<<setw(5)<<endl;
	time_hr();
	wbs();
	for(int i=0;i<50;i++)
	{
		outputdeck<<t[i]<<setw(10)<<pwf[i]<<endl;	}


	return 0;
}
The above code just reproduces the values of t[0] and pwf[0], over the entire loop. when i called wbs() before time_hr(), viz:
Code:
wbs();
time_hr();
i get correct values for t, but pwf is still returning pwf[0]...Please help!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top