0

Dear all,

I'm a C++ beginner and I'm facing a problem with C++ program running on Dev C++ 4.9.9.2. The following program builds and compiles just fine however when I try to execute it it stops before getting any output. Actually the line causing the problem might be the "y_pos[][]" array definition line but I don't know why!!! I just get the following when the debugger reaches this line:

An Access violation (Segmentation fault) is raised in the program.

The code:

```
#include<math.h>
#include<cstdlib>
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
#define TM 0
#define Di 1
#define Nsteps 40000
#define pi 3.14159265
#define courant_factor 1
#define nwave 20
#define dx 0.00001
#define dy 0.00001
int main()
{
float c;
float etao;
float dt;
char boundarytype_xn = 'p';
int boundaryair_buffer_number_of_cells_xn = 160;
int boundarypml_number_of_cells_xn = 15;
char boundarytype_xp = 'p';
int boundaryair_buffer_number_of_cells_xp = 160;
int boundarypml_number_of_cells_xp = 15;
char boundarytype_yn = 'p';
int boundaryair_buffer_number_of_cells_yn = 160;
int boundarypml_number_of_cells_yn = 15;
char boundarytype_yp = 'p';
int boundaryair_buffer_number_of_cells_yp = 160;
int boundarypml_number_of_cells_yp = 15;
int boundarypml_order = 2;
float boundarypml_R_0 = 1e-8;
float matter_typeser [2];
float matter_typesmr [2];
float matter_typesse [2];
float matter_typessm [2];
float t_er[2];
float t_mr[2];
float t_se[2];
float t_sm[2];
float time[Nsteps];
int incident_waveE_theta,incident_waveE_phi;
float incident_wavetheta_incident,incident_wavephi_incident;
char incident_wavewaveform_type;
float frequency_domainstart;
float frequency_domainend;
float frequency_domainstep;
float V;
float sampledx;
float sampledy;
char sampledcomponent;
bool sampleddisplay_plot;
bool draw_domainenable;
bool draw_domaindraw_axis;
bool draw_domaindraw_grid;
bool is_pml_xp;
bool is_pml_xn;
bool is_pml_yp;
bool is_pml_yn;
bool is_any_side_pml;
int n_pml_xn;
int n_pml_xp;
int n_pml_yn;
int n_pml_yp;
int number_of_circles;
int number_of_objects;
float min_x;
float min_y;
float max_x;
float max_y;
float fxx_domainmin_x;
float fxx_domainmin_y;
float fxx_domainmax_x;
float fxx_domainmax_y;
float fxx_domainsize_x;
float fxx_domainsize_y;
int ind;
int ind2;
float theta_incident;
float phi_incident;
float E_theta;
float E_phi;
float Exi0,Eyi0,Ezi0,Hxi0,Hyi0,Hzi0;
float circlescenter_x = 0.04;
float circlescenter_y = 0.05;
float circlesradius = 0.00075;
int circlesmaterial_type = 2;
float measurept=0.0015;
float measureangle=0;
matter_typeser [0]=1.0;
if(Di==1)
matter_typeser [1]= 22.39;
else
matter_typeser [1]= 1.0;
matter_typesmr [0] = 1.0;
matter_typesmr [1]=1.0;
matter_typesse [0]=0.0;
if(Di==1)
matter_typesse [1]=53.73;
else
matter_typesse [1]=10000000000.0;
matter_typessm [0]=0.0;
matter_typessm [1]=0.0;
// Define incident wave, angles are in degrees
if(TM==1)
{incident_waveE_theta= 1;
incident_waveE_phi = 0;}
else
{incident_waveE_theta = 0;
incident_waveE_phi = 1;}
incident_wavetheta_incident = 90;
incident_wavephi_incident = 0;
incident_wavewaveform_type = 'g';
// frequency domain parameters
frequency_domainstart = 30e9;
frequency_domainend = 60e9;
frequency_domainstep = 0.5e9;
V=measureangle+180;
sampledx = circlescenter_x+(circlesradius+measurept)*cos((V*pi)/180.0);
sampledy = circlescenter_y+(circlesradius+measurept)*sin((V*pi)/180.0);
if(TM==1)
sampledcomponent = 'z';
else
sampledcomponent = 'm';
sampleddisplay_plot = false;
draw_domainenable = true;
draw_domaindraw_axis = false;
draw_domaindraw_grid = false;
is_pml_xn = true;
is_pml_xp = true;
is_pml_yn = true;
is_pml_yp = true;
is_any_side_pml = true;
n_pml_xn = boundarypml_number_of_cells_xn;
n_pml_xp = boundarypml_number_of_cells_xp;
n_pml_yn = boundarypml_number_of_cells_yn;
n_pml_yp = boundarypml_number_of_cells_yp;
number_of_circles = 1;
number_of_objects = 1;
min_x = circlescenter_x - circlesradius;
min_y = circlescenter_y - circlesradius;
max_x = circlescenter_x + circlesradius;
max_y = circlescenter_y + circlesradius;
if (number_of_objects == 0)
{fxx_domainmin_x = 0;
fxx_domainmin_y = 0;
fxx_domainmax_x = 0;
fxx_domainmax_y = 0;}
else
{fxx_domainmin_x = min_x;
fxx_domainmin_y = min_y;
fxx_domainmax_x = max_x;
fxx_domainmax_y = max_y;}
// Determine the problem space boundaries including air buffers
fxx_domainmin_x = fxx_domainmin_x - dx * (boundaryair_buffer_number_of_cells_xn + n_pml_xn);
fxx_domainmin_y = fxx_domainmin_y - dy * (boundaryair_buffer_number_of_cells_yn + n_pml_yn);
fxx_domainmax_x = fxx_domainmax_x + dx * (boundaryair_buffer_number_of_cells_xp + n_pml_xp);
fxx_domainmax_y = fxx_domainmax_y + dy * (boundaryair_buffer_number_of_cells_yp + n_pml_yp);
// Determining the problem space size
fxx_domainsize_x = fxx_domainmax_x - fxx_domainmin_x;
fxx_domainsize_y = fxx_domainmax_y - fxx_domainmin_y;
// number of cells in x, y, and z directions
int nx=static_cast<int>(round(fxx_domainsize_x/dx));
int ny=static_cast<int>(round(fxx_domainsize_y/dy));
int nxp1=nx+1;
int nxm1=nx-1;
int nxm2=nx-2;
int nyp1=ny+1;
int nym1=ny-1;
int nym2=ny-2;
fxx_domainsize_x = nx * dx;
fxx_domainsize_y = ny * dy;
fxx_domainmax_x = fxx_domainmin_x + fxx_domainsize_x;
fxx_domainmax_y = fxx_domainmin_y + fxx_domainsize_y;
float x_pos[nxp1][nyp1];
float y_pos[nxp1][nyp1];
for(ind=0;ind<nxp1;ind++)
for(ind2=0;ind2<nyp1;ind2++)
{
x_pos[ind][ind2]=0.0;
y_pos[ind][ind2]=0.0;
}
float cx[nx][ny];
float cy[nx][ny];
int matter_2d[nx][ny];
for(ind=0;ind<nx;ind++)
for(ind2=0;ind2<ny;ind2++)
{
cx[ind][ind2]=0.0;
cy[ind][ind2]=0.0;
matter_2d[ind][ind2]=1;
}
cin.get();
return 0;
}
```

*Edited 4 Years Ago by johnnydarten*: n/a