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 direction of rows.
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;
}
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 direction of rows.
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;
}