Go Back   Velocity Reviews > General Computer Discussion > Software
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
Old 08-02-2006, 06:05 PM   #1
Question Segmentation Fault in C++


Hi Guys,

I have a problem to calculate the diffusion from a cell in a grid cell layout. I am passing the value from 0 to n as (x,y), nx is no of cell in the grid in x direction.

geoCellCurrent is a vector of Geographic Region Class....

geoCellCurrent[nx*(x-1)+(y-1)] might not exist if it goes beyond the index range.

index = nx * (x-1) + (y-1)

i guess i am getting segmentation fault because of this problem

Is there any way where i can ignore this object c*State or v*State if index goes beyond range...and it cannot be used further in the equation of diff_M


Here is the code
double GeographicRegion::getDiffusionM(unsigned int x,unsigned int y)
{

CellState& c1State = geoCellCurrent[nx*(x-1)+(y-1)].c1State;
VectorState& v1State = geoCellCurrent[nx*(x-1)+(y-1)].v1State;

CellState& c2State = geoCellCurrent[nx*(x-1)+y].c2State;
VectorState& v2State = geoCellCurrent[nx*(x-1)+y].v2State;

CellState& c3State = geoCellCurrent[nx*(x-1)+(y+1)].c3State;
VectorState& v3State = geoCellCurrent[nx*(x-1)+(y+1)].v3State;

CellState& c4State = geoCellCurrent[nx*x+(y-1)].c4State;
VectorState& v4State = geoCellCurrent[nx*x+(y-1)].v4State;

CellState& c5State = geoCellCurrent[nx*x+(y+1)].c5State; //Cell whose concentratxon is caculated
VectorState& v5State = geoCellCurrent[nx*x+(y+1)].v5State;

CellState& c6State = geoCellCurrent[nx*(x+1)+(y-1)].c6State;
VectorState& v6State = geoCellCurrent[nx*(x+1)+(y-1)].v6State;

CellState& c7State = geoCellCurrent[nx*(x+1)+y].c7State;
VectorState& v7State = geoCellCurrent[nx*(x+1)+y].v7State;

CellState& c8State = geoCellCurrent[nx*(x+1)+(y+1)].c8State;
VectorState& v8State = geoCellCurrent[nx*(x+1)+(y+1)].v8State;

CellState& c9State = geoCellCurrent[nx*(x+1)+(y+1)].c9State;
VectorState& v9State = geoCellCurrent[nx*(x+1)+(y+1)].v9State;

double outRate1 = diffTabM[c5State.getClassification()][c1State.getClassification()];
double inRate1 = diffTabM[c1State.getClassification()][c5State.getClassification()];

double outRate2 = diffTabM[c5State.getClassification()][c2State.getClassification()];
double inRate2 = diffTabM[c2State.getClassification()][c5State.getClassification()];

double outRate3 = diffTabM[c5State.getClassification()][c3State.getClassification()];
double inRate3 = diffTabM[c3State.getClassification()][c5State.getClassification()];

double outRate4 = diffTabM[c5State.getClassification()][c4State.getClassification()];
double inRate4 = diffTabM[c4State.getClassification()][c5State.getClassification()];

double outRate6 = diffTabM[c5State.getClassification()][c6State.getClassification()];
double inRate6 = diffTabM[c6State.getClassification()][c5State.getClassification()];

double outRate7 = diffTabM[c5State.getClassification()][c7State.getClassification()];
double inRate7 = diffTabM[c7State.getClassification()][c5State.getClassification()];

double outRate8 = diffTabM[c5State.getClassification()][c8State.getClassification()];
double inRate8 = diffTabM[c8State.getClassification()][c5State.getClassification()];

double outRate9 = diffTabM[c5State.getClassification()][c9State.getClassification()];
double inRate9 = diffTabM[c9State.getClassification()][c5State.getClassification()];

diff_M = outRate1*v5State.getVectorStateM() - inRate1*v1State.getVectorStateM() + outRate2*v5State.getVectorStateM() - inRate2*v2State.getVectorStateM() + outRate3*v5State.getVectorStateM() - inRate3*v3State.getVectorStateM() + outRate4*v5State.getVectorStateM() - inRate4*v4State.getVectorStateM() + outRate6*v5State.getVectorStateM() - inRate6*v6State.getVectorStateM() + outRate7*v5State.getVectorStateM() - inRate7*v7State.getVectorStateM() + outRate8*v5State.getVectorStateM() - inRate8*v8State.getVectorStateM() + outRate9*v5State.getVectorStateM() - inRate9*v9State.getVectorStateM();

cout << " Male Diffusion " << diff_M << endl;
return diff_M;
}


deltaone
deltaone is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
BSOD When Running IE (Page Fault To NonPaged Area) san1965 Software 0 09-30-2009 10:13 AM
I am getting segmentation fault - WHY? bhavinvyas Software 0 12-31-2008 12:08 PM
Segmentation fault in C (fclose) sakura Software 1 10-20-2006 10:57 PM
I have an Invalid Page Fault in module XVID.AX Wassup Mang! DVD Video 1 10-19-2003 02:40 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46