Hi I need to create arrays with large sizes and I've written below code. as long as x & y (array size) ate small, there is no problem. but as soon as I enter bigger numbers for them it gives below error and make me break. Unhandled exception at 0x778d15de in twoDacid.exe: 0xC0000005: Access violation.
here is the code:
include "StdAfx.h"
include "math.h"
include "iostream"
include "fstream"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//////////////////////////////////////////////////// constants
double poro0=0.2; // initial porosity
double mu=0.05; // acid viscusity (cp)
double L=0.5; // length of the core (cm)
double H=0.5; // width of the core
double q=1/60; // injection rate (cm3/s)
double A=HH; // core surface area (cm2)
double U0=q/A; // initial velocity (cm/s)
double r0=1e-4; // initial mean pore radius (cm)
double a0=50; // initial interface area per unit volume (cm2/cm3)
double k0=1; // initial permeability (md)
double C0=0.15; // initial acid concentration (volume fraction)
double ks=0.2; // surface reaction rate constant (cm/s)
double Dm=4e-6; // acid diffusivity (cm2/s)
double beta=2; // Pore broadening parameter
double landaX=0.5; // constant in axial dispersion
double landaT=0.1; // constant in Transverse dispersion
double alfaos=0.5; // constant in dispersion correlation
double alfa=100/2; // gravimetric dissolving power of the acid (gr of rock / mole of acid) here for CaCO3 2moles of acid is...
//needed to dissolce 1 mole of rock ////////////// 100(gr/mol)1mole / 2mole
double Pe=0;
double Ros=2.71; // solid density (gr/cm3)
double Roa=1; // acid density (gr/cm3) supposed to be constant
double phi2P=0.007; //2*ks*r0/Dm; // pore scale thielie module
double phi2D=1e6; //ks*a0*L^2/Dm; // Darcy scale thielie module
double Da=ks*a0*L/U0; // damkohler number
double Nac=0.1; //alfa*C0/Ros; // acid capacity number
double eta=2*r0/L;
///////////////////////////////////////////////////// solution parameters
const int x=100; // number of element in x direction
const int y=100; // number of element in y direction
double dx=1.0/x; // x block length (dimless)
double dy=(H/L)/y;
double endt=1; // end time (s)
double endtD=(endt/L)*U0; //dimless end time
const int T=100000; // number of time steps
double dt=endtD/T; // length of time steps
/////////////////////////////////////// initial valuse for parameters that vary with time:
double r[x][y];
double Av[x][y];
double K[x][y];
double u[x][y];
double Cf[x][y];
double ReP[x][y];
double Sh[x][y];
for (int i=0;i<=x-1;i++){
for (int j=0;j<=y-1;j++){
r[i][j]=1;
Av[i][j]=1;
K[i][j]=1;
u[i][j]=1;
Cf[i][j]=1;
ReP[i][j]=2*Roa*U0*r0/mu;
Sh[i][j]=3+7*(sqrt(ReP[i][j]));
}
}
///////////////////////////////////////////////// heterogenous medium
double poro[x][y];
for (int i=0;i<=x-1;i++){
for (int j=0;j<=y-1;j++){
if (j==2 && i==0)
poro[i][j]=.25;
else
poro[i][j]=.2;
}
}
///////////////////////////////////////////// K, Av, r
for (int i=0;i<=x-1;i++){
for (int j=0;j<=y-1;j++){
K[i][j]=pow((poro[i][j]/poro0)*(((poro[i][j]*(1-poro0)) / (poro0*(1-poro[i][j])))),(2*beta));
r[i][j]=K[i][j]*poro0/poro[i][j];
Av[i][j]=poro[i][j]/(poro0*r[i][j]);
}
}
for (int t=0;t<=0;t++){
/////////////////////////////////////// P calculation
double Zm[x*y][x*y];
for (int i=0;i<=x*y-1;i++){
for (int j=0;j<=x*y-1;j++){
Zm[i][j]=0;
}
}
Zm[0][0]=-1/pow(dx,2) - 1/pow(dy,2);
Zm[0][1]= 1/pow(dy,2);
Zm[0][y]= 1/pow(dx,2);
for (int j=1;j<=y-2;j++){
Zm[j][j] =-1/pow(dx,2) - 2/pow(dy,2);
Zm[j][j-1]= 1/pow(dy,2);
Zm[j][j+1]= 1/pow(dy,2);
Zm[j][j+y]= 1/pow(dx,2);
}
Zm[y-1][y-1] =-1/pow(dx,2) - 1/pow(dy,2);
Zm[y-1][y-2] = 1/pow(dy,2);
Zm[y-1][y-1+y]= 1/pow(dx,2);
for (int i=1;i<=(x-2);i++){
Zm[i*y][i*y] =-2/pow(dx,2) - 1/pow(dy,2);
Zm[i*y][i*y+1]= 1/pow(dy,2);
Zm[i*y][i*y-y]= 1/pow(dx,2);
Zm[i*y][i*y+y]= 1/pow(dx,2);
for (int j=1;j<=y-2;j++){
Zm[i*y+j][i*y+j] =-2/pow(dx,2) - 2/pow(dy,2);
Zm[i*y+j][i*y+j-1]= 1/pow(dy,2);
Zm[i*y+j][i*y+j+1]= 1/pow(dy,2);
Zm[i*y+j][i*y+j+y]= 1/pow(dx,2);
Zm[i*y+j][i*y+j-y]= 1/pow(dx,2);
}
Zm[i*y+y-1][i*y+y-1] =-2/pow(dx,2) - 1/pow(dy,2);
Zm[i*y+y-1][i*y+y-2] = 1/pow(dy,2);
Zm[i*y+y-1][i*y+y-1+y]= 1/pow(dx,2);
Zm[i*y+y-1][i*y+y-1-y]= 1/pow(dx,2);
}
Zm[(x-1)*y][(x-1)*y] =-2/pow(dx,2) - 1/pow(dy,2);
Zm[(x-1)*y][(x-1)*y+1]=1/pow(dy,2);
Zm[(x-1)*y][(x-2)*y] =1/pow(dx,2);
for (int j=1;j<=y-2;j++){
Zm[(x-1)*y+j][(x-1)*y+j] =-2/pow(dx,2) - 2/pow(dy,2);
Zm[(x-1)*y+j][(x-1)*y+j-1]= 1/pow(dy,2);
Zm[(x-1)*y+j][(x-1)*y+1+j]= 1/pow(dy,2);
Zm[(x-1)*y+j][(x-2)*y+j] = 1/pow(dx,2);
}
Zm[y*x-1][y*x-1] =-1/pow(dx,2) - 1/pow(dy,2);
Zm[y*x-1][y*x-2] = 1/pow(dy,2);
Zm[y*x-1][y*(x-1)-1]= 1/pow(dx,2);
// output Zm matrix
ofstream file;
file.open("Zm.txt");
for (int i=0;i<y*x;i++){
for(int j=0;j<y*x;j++){
file<<Zm[i][j]<<" ";
}
file<<endl;
}
file.close();
// constants matrix
}
//cin>>L;
return 0;
}