vj said:
So perhaps now is the time to show us the code that you're struggling
with. (Actually, earlier was the time, but now will do.)
Thanks for the replies. The free disk space is at least 4 GB.
I am copying below the code. The interesting thing is that the same
code is running alright on a different machine, so this makes me think
that there seems to be problem with my machine. (Of course I have to
increase the stack size on the other machine also, and this is what I
normally do, and it works fine). As mentioned in my previous post, I
don't remember doing anything signifacant with the machine (only thing
I can remember is wiriting a songs CD using Nero). Here is the code
(I admit that the code is far from being an example of an efficient
code
, but serves my purpose well) :
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stddef.h>
#include <complex.h>
#include <fstream>
#include <time.h>
#define PI 3.14159265
#define c 3.0e8
#define dX 50.0e-9//73.170731e-9
#define dT dX/(c)
#define NX 780
#define NY 600
#define NM 4
#define double_complex complex <double>
class D2{
public:
int NT;
double **V10, **V11, **V8, **V9, **Iy, **Ix, **Vz;
double **Sez;
double **pez, **X1z, **X2z;
double ALPHA[NM], d[NM], w0[NM];
double Tp0[NM], b0, b1[NM], b2[NM], b3[NM], Tp1[NM], Te2[NM],
Te1[NM];
double *h1, *h2, *h3, *h4;
int X, Y, N;
D2( );
~D2( );
void iterate( );
};
main(){
time_t starttime,endtime;
starttime=time(NULL);
D2 A;
A.iterate();
endtime=time(NULL);
cout<<endl<<"Total Run time"<<"\t"<<endtime-starttime<<" sec
("<<(endtime-starttime)/60<<" min "<<(endtime-starttime)%60<<"
sec)"<<endl;
getchar();
}
D2 :: D2(){
int array_counter;
V10 = new double *[NX];
V11 = new double *[NX];
V8 = new double *[NX];
V9 = new double *[NX];
Iy = new double *[NX];
Ix = new double *[NX];
Vz = new double *[NX];
Sez = new double *[NX];
pez = new double *[NX];
X1z = new double *[NX];
X2z = new double *[NX];
for (array_counter = 0; array_counter < NX; array_counter++)
{
V10[array_counter] = new double [NY];
V11[array_counter] = new double [NY];
V8[array_counter] = new double [NY];
V9[array_counter] = new double [NY];
Iy[array_counter] = new double [NY];
Ix[array_counter] = new double [NY];
Vz[array_counter] = new double [NY];
//Sey[array_counter] = new double [NY];
Sez[array_counter] = new double [NY];
pez[array_counter] = new double [NY];
//pey[array_counter] = new double [NY];
X1z[array_counter] = new double [NY];
//X1y[array_counter] = new double [NY];
X2z[array_counter] = new double [NY];
//X2y[array_counter] = new double [NY];
}
cout << "Enter no. of Timesteps (NT) - ";
cin >> NT;
ofstream outfileNT("Last_NT.out");
outfileNT<<"Last NT= "<<NT<<endl;
// NT=30;
h1=new double [NT];
h2=new double [NT];
h3=new double [NT];
h4=new double [NT];
}
D2 :: ~D2(){
int array_counter;
for (array_counter = 0; array_counter < NX; array_counter++)
{
delete [] V10[array_counter];
delete [] V11[array_counter];
delete [] V8[array_counter];
delete [] V9[array_counter];
delete [] Iy[array_counter];
delete [] Ix[array_counter];
delete [] Vz[array_counter];
// delete [] Sey[array_counter];
delete [] Sez[array_counter];
delete [] pez[array_counter];
// delete [] pey[array_counter];
delete [] X1z[array_counter];
// delete [] X1y[array_counter];
delete [] X2z[array_counter];
//delete [] X2y[array_counter];
}
delete [] V10;
delete [] V11;
delete [] V8;
delete [] V9;
delete [] Iy;
delete [] Ix;
delete [] Vz;
// delete [] Sey;
delete [] Sez;
delete [] pez;
// delete [] pey;
delete [] X1z;
// delete [] X1y;
delete [] X2z;
// delete [] X2y;
delete []h1;
delete []h2;
delete []h3;
delete []h4;
}
void D2 :: iterate(){
ofstream outfile1("sp_dist_Ix_NL.out");
//ofstream outfile1_ENV("sp_dist_Vx_NL_Envelope.out");
ofstream outfile2A("FFT_Vz_NL.out");
//ofstream outfile2B("FFT_Vy_NL.out");
//ofstream outfile2C("FFT_I_NL.out");
//ofstream outfile2D("FFT_P_NL.out");
ofstream outfile3("TimeData_NL.out");
//ofstream outfile4A("sp_dist_Vy_NL_1.out");
//ofstream outfile4B("sp_dist_Vy_NL_2.out");
//ofstream outfile4C("sp_dist_Vy_NL_3.out");
ofstream outfile4("sp_dist_Iy_NL.out");
ofstream outfileMatProfile("MaterialProfile.out");
//ofstream outfile4_ENV("sp_dist_Vy_NL_Envelope.out");
ofstream outfile5("sp_dist_Vz_NL.out");
ofstream outfile5A("sp_dist_Vz_NL_NT1000.out");
ofstream outfile5B("sp_dist_Vz_NL_NT1200.out");
ofstream outfile5C("sp_dist_Vz_NL_NT1400.out");
ofstream outfile5D("sp_dist_Vz_NL_NT800.out");
//ofstream outfile5E("sp_dist_Vz_NL_NT400.out");
//ofstream outfile5_ENV("sp_dist_I_NL_Envelope.out");
ofstream outfile6("sp_dist_P_NL.out");
//ofstream outfile6_ENV("sp_dist_P_NL_Envelope.out");
ofstream StoreVoltages("AllVoltages.out");
ifstream ReadVoltages("AllVoltages_400.in");
int MaterialPresent[NX][NY];
int NLB = 220;//NX-10;
int StripStartY_LEFT = (NY/2)-30;
int StripEndY_LEFT = (NY/2)+30;
int StripStartY_RIGHT = StripStartY_LEFT;//(NY/2)-6; //=144;
int StripEndY_RIGHT = StripEndY_LEFT;//(NY/2)+6; //=156;
for (X=0; X<NX; X++)
{
for (Y=0; Y<NY; Y++)
{
if (X<=NLB)
{
if (Y>=StripStartY_LEFT && Y<=StripEndY_LEFT) MaterialPresent[X][Y]
=1;
else MaterialPresent[X][Y]=0;
}
if (X>NLB)
{
if (Y>=StripStartY_RIGHT && Y<=StripEndY_RIGHT)
MaterialPresent[X][Y] =2;
else MaterialPresent[X][Y]=3;
}
outfileMatProfile<<MaterialPresent[X][Y];
}
outfileMatProfile<<endl;
}
double CH[NM];
double T1[NM];
CH[0] = (10.487 * 10.487) - 1.0;
CH[1] = (10.491 * 10.491) - 1.0;
CH[2] = (10.491 * 10.491) - 1.0;
CH[3] = (10.487 * 10.487) - 1.0;
double n0_0=10.487, n0_1=10.491, n0_2=10.491, n0_3=10.487, n2=2.5e16;
double e0 = 8.854e-12;
double Z0=376.7;
double dCH_0 = n0_0*n0_0 + 1.0;
double dCH_1 = n0_1*n0_1 + 1.0;
double dCH_2 = n0_2*n0_2 - 1.0;
double dCH_3 = n0_3*n0_3 + 1.0;
double alpha_value_0 = 2.0 * n0_0 * n2 / (dCH_0*dCH_0*dCH_0*2.0*Z0) ;
double alpha_value_1 = 2.0 * n0_1 * n2 / (dCH_1*dCH_1*dCH_1*2.0*Z0) ;
double alpha_value_2 = 2.0 * n0_2 * n2 / (dCH_2*dCH_2*dCH_2*2.0*Z0) ;
double alpha_value_3 = 2.0 * n0_3 * n2 / (dCH_3*dCH_3*dCH_3*2.0*Z0) ;
double x=-0*1.0/2000.0;
ALPHA[0] = 0.0*alpha_value_0;
ALPHA[1] = 0.0*alpha_value_1;
ALPHA[2] = x*alpha_value_2;
ALPHA[3] = x*alpha_value_3;
w0[0] = 2.0 * M_PI * 1500e12;
w0[1] = 2.0 * M_PI * 1500e12;
w0[2] = 2.0 * M_PI * 1500e12;
w0[3] = 2.0 * M_PI * 1500e12;
d[0] = w0[0] * 1e-3;
d[1] = w0[1] * 1e-3;
d[2] = w0[2] * 1e-3;
d[3] = w0[3] * 1e-3;
w0[0] = 2.0 * M_PI * 1500e12 * 1e50;
w0[1] = 2.0 * M_PI * 1500e12 * 1e50;
w0[2] = 2.0 * M_PI * 1500e12 * 1e50;
w0[3] = 2.0 * M_PI * 1500e12 * 1e50;
w0[0] = w0[0] * (dT);
w0[1] = w0[1] * (dT);
w0[2] = w0[2] * (dT);
w0[3] = w0[3] * (dT);
d[0] = d[0] * (dT);
d[1] = d[1] * (dT);
d[2] = d[2] * (dT);
d[3] = d[3] * (dT);
double Convergence_z = 1.5e-9;
//double Convergence_y = 1.5e-9;
Tp0[0] = 1.0 / (4.0 + 4.0*d[0]);
Tp0[1] = 1.0 / (4.0 + 4.0*d[1]);
Tp0[2] = 1.0 / (4.0 + 4.0*d[2]);
Tp0[3] = 1.0 / (4.0 + 4.0*d[3]);
b0 = 8.0;
b1[0] = -2.0 * w0[0] * w0[0];
b1[1] = -2.0 * w0[1] * w0[1];
b1[2] = -2.0 * w0[2] * w0[2];
b1[3] = -2.0 * w0[3] * w0[3];
b2[0] = 2.0 * CH[0] * w0[0] * w0[0];
b2[1] = 2.0 * CH[1] * w0[1] * w0[1];
b2[2] = 2.0 * CH[2] * w0[2] * w0[2];
b2[3] = 2.0 * CH[3] * w0[3] * w0[3];
b3[0] = -(4.0 - 4.0 * d[0]);
b3[1] = -(4.0 - 4.0 * d[1]);
b3[2] = -(4.0 - 4.0 * d[2]);
b3[3] = -(4.0 - 4.0 * d[3]);
double Te = 0.5;
double Ke = -2.0;
Tp1[0] = 1.0 / (1.0 + 2.0 * CH[0] * w0[0] * w0[0] * Tp0[0] * Te);
Tp1[1] = 1.0 / (1.0 + 2.0 * CH[1] * w0[1] * w0[1] * Tp0[1] * Te);
Tp1[2] = 1.0 / (1.0 + 2.0 * CH[2] * w0[2] * w0[2] * Tp0[2] * Te);
Tp1[3] = 1.0 / (1.0 + 2.0 * CH[3] * w0[3] * w0[3] * Tp0[3] * Te);
Te2[0] = Tp0[0];
Te2[1] = Tp0[1];
Te2[2] = Tp0[2];
Te2[3] = Tp0[3];
Te1[0] = CH[0] * w0[0] * w0[0];
Te1[1] = CH[1] * w0[1] * w0[1];
Te1[2] = CH[2] * w0[2] * w0[2];
Te1[3] = CH[3] * w0[3] * w0[3];
double r_Abs_LEFT, r_Abs_RIGHT, r_Abs_TOP, r_Abs_BOTTOM;
//double r_Metal = -1.0;
int Noff=300;
for (X=0; X<NX; X++)
{
for (Y=0; Y<NY; Y++)
{
V10[X][Y] = V11[X][Y] = V8[X][Y] = V9[X][Y] =Iy[X][Y]=Ix[X][Y]=Vz[X]
[Y]/*=Sey[X][Y]*/=Sez[X][Y]=0.0;
pez[X][Y] = /*pey[X][Y] =*/ X1z[X][Y] = /*X1y[X][Y] =*/ X2z[X][Y] /
*= X2y[X][Y]*/ = 0.0;
}
}
int SignalFromSource, SignalFromFile;
SignalFromSource=1;
SignalFromFile=!SignalFromSource;
if (SignalFromSource==1){cout<<"Taking input signal from SOURCE.....
\n";}
if (SignalFromFile==1){cout<<"Taking input signal from File.....\n";}
if (SignalFromFile==1)
{
for (X=0; X<NX; X++)
{
for (Y=NY-1; Y>=0; Y--)
{
if(X>=150 && X<990)
{
int Xn = X-148;
ReadVoltages>>V8[Xn][Y]>>V9[Xn][Y]>>V10[Xn][Y]>>V11[Xn]
[Y]>>Ix[Xn][Y]>>Iy[Xn][Y]>>Vz[Xn][Y]>>/*Sex[Xn][Y]>>*/Sez[Xn]
[Y]>>X1z[Xn][Y]>>X2z[Xn][Y]>>/*X1y[Xn][Y]>>X2y[Xn][Y]>>*/pez[Xn][Y]/
*>>pey[Xn][Y]*/;
}
else {double junk;
ReadVoltages>>junk>>junk>>junk>>junk>>junk>>junk>>junk>>junk>>junk>>junk>>junk/
*>>junk>>junk>>junk>>junk*/;}
}
}
}
for (N=0; N<NT; N++)
{
/*if (N%200==0) */cout << "Time Step N= "<<N<<endl;
if (SignalFromSource==1)
{
// if (N<Noff)
{
for (Y=0; Y<NY; Y++)//Y=NY/2;//=150;
// Y=NY/2.0;
{
double MD = (1000.0/sqrt(2.0))* exp(log(0.001)*(N-double(Noff)/
2.0)*(N-double(Noff)/2.0)/((double(Noff)/2.0)*(double(Noff)/2.0)))*
cos(2.0 * PI * 196.07843e12 * double(N) * dT);
double a= (StripEndY_LEFT - StripStartY_LEFT +1.0)/2.0;
double u=/*0.9899;0.872;*/ 0.573982;
double w=/*1.508;1.038;*/ 0.371137;
if (Y>= StripStartY_LEFT && Y<=StripEndY_LEFT)
{
V10[20][Y]+= (0.5/sqrt(2.0))* MD *cos((Y-NY/2.0)*(u/a)) /
cos(a);
V11[20][Y]+= (0.5/sqrt(2.0))* MD*cos((Y-NY/2.0)*(u/a)) /
cos(a);
V8[20][Y]+=0.5/sqrt(2.0) * MD*cos((Y-NY/2.0)*(u/a)) /
cos(a);
V9[20][Y]+= 0.5/sqrt(2.0) * MD*cos((Y-NY/2.0)*(u/a)) /
cos(a);
}
else
{
V10[20][Y]+= (0.5/sqrt(2.0) )* MD *exp(-fabs(Y-NY/2.0)*w/a)/
exp(-a);
V11[20][Y]+= (0.5/sqrt(2.0) )* MD*exp(-fabs(Y-NY/2.0)*w/a)/
exp(-a);
V8[20][Y]+=0.5/sqrt(2.0) * MD*exp(-fabs(Y-NY/2.0)*w/a)/
exp(-a);
V9[20][Y]+= 0.5/sqrt(2.0) * MD*exp(-fabs(Y-NY/2.0)*w/a)/
exp(-a);
}
}
}
}
int Xout =115 ;
int Yout =(double(NY))/2.0;
h1[N] = Vz[Xout][Yout];
//h2[N] = Iy[Xout][Yout];
//h3[N] = Vz[Xout][Yout];
//h4[N] = Ix[Xout][Yout] * Ix[Xout][Yout] + Iy[Xout][Yout] * Iy[Xout]
[Yout];
outfile3<<N<<" "<<h1[N]<<endl;
for (X=0; X<NX; X++)
{
for (Y=0; Y<NY; Y++)
{
double v8 = V8[X][Y];
double v9 = V9[X][Y];
double v10 = V10[X][Y];
double v11 = V11[X][Y];
// if (N>=54) cout<<"X= "<<X<<" Y= "<<Y<<" N=
"<<N<<endl;
// I[X][Y] = 0.5 * (-V2[X][Y]+ V4[X][Y] + V3[X][Y] - V5[X][Y]);
Ix[X][Y] = (V8[X][Y] + V9[X][Y]);
Iy[X][Y] = (V10[X][Y] + V11[X][Y]);
//if (Iy[X][Y]!=0.0) {cout<<"N= "<<N<<" X= "<<X<<"
Y= "<<Y<<" Iy[X][Y]= "<<Iy[X][Y]<<endl;char fff; cin>>fff;}
// Vy[X][Y] = V4[X][Y] + V5[X][Y];
{
double Uez = (Te * (2.0 * (v9+v10) + Sez[X][Y]))/2.0;
double Wez = Te2[MaterialPresent[X][Y]] * (b2[MaterialPresent[X]
[Y]] * Uez + X1z[X][Y]);
double P0z = pez[X][Y];
// int itercount_z =0;
for ( ; ; ) {
// if (X==310 && Y==25){ cout<<"itercount_y =
"<<itercount_y<<" at timestep N = "<<N<<" (X,Y) = "<<X<<","<<Y<<endl;
char iterchecky; cin>>iterchecky;}
// itercount_z++;
double P1z = P0z - (P0z - b1[MaterialPresent[X][Y]] *
Te2[MaterialPresent[X][Y]] *exp(ALPHA[MaterialPresent[X]
[Y]]*(P0z*P0z)) * P0z - Wez) / (1.0 - 0.5*b1[MaterialPresent[X][Y]] *
Te2[MaterialPresent[X][Y]] *exp(ALPHA[MaterialPresent[X]
[Y]]*(P0z*P0z)) * (1.0 + 2.0*ALPHA[MaterialPresent[X][Y]]*P0z*P0z) );
if (fabs(P1z - P0z) < Convergence_z) {pez[X][Y] = P1z;
break;}
P0z = P1z;
}
Vz[X][Y] = Uez + 2.0 * Te * pez[X][Y];
Sez[X][Y] = (2.0 * (V10[X][Y] - V11[X][Y] + V8[X][Y] - V9[X]
[Y]) + 2.0* Ke * Vz[X][Y] + 2.0* 2.0 * pez[X][Y]);
X1z[X][Y] = b0 * pez[X][Y] + b1[MaterialPresent[X][Y]] *
exp((ALPHA[MaterialPresent[X][Y]]*(pez[X][Y]*pez[X][Y]))) *pez[X][Y] +
b2[MaterialPresent[X][Y]] *
Vz[X][Y] + X2z[X][Y];
//if (N>474 && X>400 ){ cout<<"X= "<<X<<" Y= "<<Y<<" N= "<<N<<"
X1z[X][Y]= "<<X1z[X][Y]<<endl; char zz; cin>>zz;}
X2z[X][Y] = b3[MaterialPresent[X][Y]] * pez[X][Y] +
0.5*b1[MaterialPresent[X][Y]] * exp((ALPHA[MaterialPresent[X]
[Y]]*(pez[X][Y]*pez[X][Y] ))) * pez[X][Y] + 0.5*b2[MaterialPresent[X]
[Y]] *
Vz[X][Y];
}
//Vx[X][Y] = V2[X][Y] + V3[X][Y];
V10[X][Y] = Vz[X][Y] + Iy[X][Y] - v11;
V11[X][Y] = Vz[X][Y] + Iy[X][Y] - v10;
V8[X][Y] = Vz[X][Y] - Ix[X][Y] - v9;
V9[X][Y] = Vz[X][Y] + Ix[X][Y] - v8;
}
}
double tempref89=20.0;
double tempref1011=20.0;
for (Y=0; Y<NY; Y++)
{
if (Y>=StripStartY_LEFT && Y<=StripEndY_LEFT) r_Abs_LEFT =
(sqrt(tempref1011) - sqrt(CH[1] + 1.0)) / (sqrt(tempref1011) +
sqrt(CH[1] + 1.0));
else r_Abs_LEFT = (sqrt(tempref1011) - sqrt(CH[0] + 1.0)) /
(sqrt(tempref1011) + sqrt(CH[0] + 1.0));
if (Y>=StripStartY_RIGHT && Y<=StripEndY_RIGHT) r_Abs_RIGHT =
(sqrt(tempref1011) - sqrt(CH[2] + 1.0)) / (sqrt(tempref1011) +
sqrt(CH[2] + 1.0));
else r_Abs_RIGHT = (sqrt(tempref1011) - sqrt(CH[3] + 1.0)) /
(sqrt(tempref1011) + sqrt(CH[3] + 1.0));
//r_Abs_RIGHT = (sqrt(2.0) - sqrt(CH[2] + 1.0)) / (sqrt(2.0) +
sqrt(CH[2] + 1.0));
//r_Abs_RIGHT = r_Abs_LEFT;
//r_Abs_RIGHT = (sqrt(2.0) - sqrt(CH[2] + 1.0)) / (sqrt(2.0) +
sqrt(CH[2] + 1.0));
r_Abs_LEFT=r_Abs_RIGHT=0.3637;
V10[0][Y] = V10[0][Y]*(-r_Abs_LEFT);
V11[NX-1][Y] = V11[NX-1][Y] *(-r_Abs_RIGHT);
}
for (X=0; X<NX; X++)
{
if (X>NLB) r_Abs_BOTTOM = (sqrt(tempref89) - sqrt(CH[3] +
1.0)) / (sqrt(tempref89) + sqrt(CH[3] + 1.0));
else r_Abs_BOTTOM = (sqrt(tempref89) -
sqrt(CH[0] + 1.0)) / (sqrt(tempref89) + sqrt(CH[0] + 1.0));
if (X>NLB) r_Abs_TOP = (sqrt(tempref89) - sqrt(CH[3] + 1.0)) /
(sqrt(tempref89) + sqrt(CH[3] + 1.0));
else r_Abs_TOP = (sqrt(tempref89) - sqrt(CH[0] + 1.0)) /
(sqrt(tempref89) + sqrt(CH[0] + 1.0));
r_Abs_BOTTOM=r_Abs_TOP=0.3637;
V8[X][0] = V8[X][0] *(-r_Abs_BOTTOM);
V9[X][NY-1] = V9[X][NY-1] *(-r_Abs_TOP);
}
if (N==1000)
{
for (X=0; X<NX; X++)
{
for (Y=NY-1;Y>=0; Y--)
{
outfile5A<<X<<"\t"<<Y<<"\t"<<Vz[X][Y]<<endl;
}
outfile5A<<endl;
}
}
if (N==1200)
{
for (X=0; X<NX; X++)
{
for (Y=NY-1;Y>=0; Y--)
{
outfile5B<<X<<"\t"<<Y<<"\t"<<Vz[X][Y]<<endl;
}
outfile5B<<endl;
}
}
if (N==1400)
{
for (X=0; X<NX; X++)
{
for (Y=NY-1;Y>=0; Y--)
{
outfile5C<<X<<"\t"<<Y<<"\t"<<Vz[X][Y]<<endl;
}
outfile5C<<endl;
}
}
if (N==800)
{
for (X=0; X<NX; X++)
{
for (Y=NY-1;Y>=0; Y--)
{
outfile5D<<X<<"\t"<<Y<<"\t"<<Vz[X][Y]<<endl;
}
outfile5D<<endl;
}
}
if (N>1)
{
for (X=0; X<NX; X++)
{
{
}
}
}
}
for (X=0; X<NX; X++)
{
for (Y=NY-1;Y>=0; Y--)
{
outfile1<<X<<"\t"<<Y<<"\t"<<Ix[X][Y]<<endl;
outfile4<<X<<"\t"<<Y<<"\t"<<Iy[X][Y]<<endl;
outfile5<<X<<"\t"<<Y<<"\t"<<Vz[X][Y]<<endl;
outfile6<<X<<"\t"<<Y<<"\t"<<Iy[X][Y]*Iy[X][Y]+Ix[X][Y]*Ix[X]
[Y]<<endl;
StoreVoltages<<V8[X][Y]<<"\t"<<V9[X][Y]<<"\t"<<V10[X]
[Y]<<"\t"<<V11[X][Y]<<"\t"<<Ix[X][Y]<<"\t"<<Iy[X][Y]<<"\t"<<Vz[X]
[Y]<<"\t"<<Sez[X][Y]<<"\t"/*<<Sey[X][Y]*/<<"\t"<<X1z[X]
[Y]<<"\t"<<X2z[X][Y]<<"\t"<</*X1y[X][Y]<<"\t"<<X2y[X]
[Y]<<*/"\t"<<pez[X][Y]/*<<"\t"<<pey[X][Y]*/<<endl;
}
outfile1<<endl;
outfile4<<endl;
outfile5<<endl;
outfile6<<endl;
}
}