Dear Friends
I want to stop the following code when all entities in the error[i][j] are simultaneously less than one. And if even one entity be greater than one I want to continue running the code.
Can someone suggest me any solution to the problem?
1 2 3 4 5 6 7
for (i=0;i<=3;i++)
{
for (j=0;j<3;j++)
{
error[i][j]= fabs(T[i][j]-TOLD[i][j]);
}
}
@ Grime
Thanks for your reply, but your code is breaking even for single value of error[i][j] is greater than 1.
I want to make all nine values of error[i][j] less than one simultaneously.
Regards
uSMAN
#include <cmath> // for abs()
usingnamespace std;
constint NI = 3, NJ = 3;
bool isConverged( double T[NI][NJ], double TOLD[NI][NJ] )
{
constdouble TOLERANCE = 1.0; // Too high for convergence tolerance
for ( int i = 0; i < NI; i++ )
{
for ( int j = 0; j < NJ; j++ )
{
if ( abs( T[i][j] - TOLD[i][j] ) > TOLERANCE ) returnfalse;
}
}
returntrue; // No large changes, so judge "converged"
}
However, you would be better having no array TOLD[][] at all. Just calculate the maximum change occurring at the same time as you do the update step on T[][].
If, at the end of the sweep, this maximum change exceeds your threshold (1.0 is actually rather large) then you have to keep sweeping through your array.
But it doesn't work. It breaks out of the inner loop, but the outer loop runs again. So this code stops updating each row if it detects a greater-than-one item in the row, but it then it moves on to the update the next row.