I'm writing a program that calculates the velocity of a certain current around an object like for example a square. Now, I use the Jacobi Iteration method and when I run it the results aren't what I'm expecting. I have no idea what I'am doing wrong. I have 2 classes, one that makes a Grid that I cant adjust, and another that creates an object with a parameter 'voneindig'.
If I make a square and a grid and run the Iterate() function it seems to happen that my square object becomes bigger. ( I get more and more zero's around my original square )
the member function getStatusElement() is a grid I've made with one's where the square is located and zero's elsewhere.
void Object::Iterate()
{
double gem=1, jacobielement, som; //locale variabelen
double epsilon=pow(10,-5); //convergentiecriterium
const int d= grid1.GetDimension(); //dimension of the grid
while(gem > epsilon)
{
for( int i = 0; i < d; i++ )
{
for( int j = 0; j < d; j++ )
{
grid2.SetElement(i,j,grid1.GetElement(i,j));
}
}
for(int i=1; i<d-1; ++ i)
{
for(int j=1; j<d-1; ++ j)
{
if( grid1.getStatusElement(i,j) == 0 )
{//jacobie
jacobielement= (grid1.GetElement(i,j+1) + grid1.GetElement(i,j-1) + grid1.GetElement(i+1,j) + grid1.GetElement(i-1,j))/4;
grid1.SetElement(i,j,jacobielement);
}
}
}
som=0;
for(int i=0; i<d; ++ i){
for(int j=0;j<d; ++ j){
//Convergention
som=som+std::abs(grid1.GetElement(i,j)-grid2.GetElement(i,j));
}
}
gem= som/pow(d,2);
}
}
I hope I've given enoug information for this problem, otherwise I can give you all my code. Thanks alot!