M
Martin Joergensen
Hi,
I've encountered a really, *really*, REALLY strange error
I have a for-loop and after 8 runs I get strange results...... I
mean: A really strange result....
I'm calculating temperatures. T[j] = 20 degrees at all
times.... The 2D T-array looks like this:
| 2: 3: ..... i-direction goes to the right ->
--+----------
2: | 20 20
3: | 20 20
j-direction goes down
(index 1 and 4 = 0, but they don't matter)
The code *that works* looks like this:
- - - - - - - - - - - -
{
/* copy 2D (old) temperatures to 1D-array */
count = 0;
solved_temp[0] = 0;
/* number_of_interior_cells = 4 */
for(j=2, i=1, no=1; no<=(int) number_of_interior_cells; no++)
{
/* update columns (x-value) */
i++;
solved_temp[no] = T[j];
solved_temp[no] += ( hx[j] * ( T[j][i-1]-T[j] ) )
/ h0[j];
solved_temp[no] += ( hx[j][i+1] * ( T[j][i+1]-T[j] ) )
/ h0[j];
solved_temp[no] += ( hy[j] * ( T[j-1]-T[j] ) )
/ h0[j];
solved_temp[no] += ( hy[j+1] * ( T[j+1]-T[j] ) )
/ h0[j];
/* below you see the code that *doesn't work* - isn't it
the same??? */
//solved_temp[no] = T[j] + (
// hx[j] * ( T[j][i-1]-T[j] ) + hx[j][i+1] * (
T[j][i+1]-T[j] ) +
// hy[j] * ( T[j-1]-T[j] ) + hy[j+1] * (
T[j+1]-T[j] )
// ) / h0[j];
if(i == nx-1) /* hits east boundary? */
{
j++; /* next row */
i=1; /* reset x-coordinate */
}
}
}
The expected result is that solved_temp[1] = 20, solved_temp[2] =
20, solved_temp[3] = 20, solved_temp[4] = 20 at all times. If I
swap the above outcommented/commented sections with each other, I
get what I expect the first 7 times. On the 8th time I get that
the next result for solved_temp[1] = -1.#IND000000000000, but the
other results are okay....
What exactly is that -1.#IND000000000000 means?
And isn't it exactly the same code??? I'm pretty confused...
In case you're wondering, hx or hy is either 0 or 1 as you can
see below and all the temperature differences is 0, so it
shouldn't matter anyway... h0 = 2 but also that shouldn't change
anything since everything gives 0 so I have something which is 0
divided by 2 and that ofcourse should give 0........ It all ends
up in (20 + 0) = 20...
Printing hx (step = 8):
i=1: i=2: i=3:
i=4:
j=1: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
j=2: -> 0.00000 -> 0.00000 -> 1.00000 -> 0.00000
j=3: -> 0.00000 -> 0.00000 -> 1.00000 -> 0.00000
j=4: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
Printing hy (step = 8):
i=1: i=2: i=3:
i=4:
j=1: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
j=2: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
j=3: -> 0.00000 -> 1.00000 -> 1.00000 -> 0.00000
j=4: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
(only 5 decimal digits shown, but it shouldn't change anything in
the big picture I guess)....
Why does it work when I calculate solved_temp[no] in 5 individual
steps instead of in one long calculation? Even Microsoft Visual
Studio 2005 debugger agrees with me, but then I step over the
calculation line and find this stupid/strange result......!
I hope somebody can explain this really weird behaviour... I hope
there's a "natural" explanation like "stack overflow" or
whatever....?
I was a bit afraid of posting this if I didn't check my code
properly but now I've looked at it for about 1-2 hours and when
my debugger even agrees with me and I then choose F10 "step over"
and get another result, then I think I need professional help
It works now (with 5 individual calculations), but I just want to
be sure that this error doesn't come back later....
Best regards / Med venlig hilsen
Martin Jørgensen
I've encountered a really, *really*, REALLY strange error
I have a for-loop and after 8 runs I get strange results...... I
mean: A really strange result....
I'm calculating temperatures. T[j] = 20 degrees at all
times.... The 2D T-array looks like this:
| 2: 3: ..... i-direction goes to the right ->
--+----------
2: | 20 20
3: | 20 20
j-direction goes down
(index 1 and 4 = 0, but they don't matter)
The code *that works* looks like this:
- - - - - - - - - - - -
{
/* copy 2D (old) temperatures to 1D-array */
count = 0;
solved_temp[0] = 0;
/* number_of_interior_cells = 4 */
for(j=2, i=1, no=1; no<=(int) number_of_interior_cells; no++)
{
/* update columns (x-value) */
i++;
solved_temp[no] = T[j];
solved_temp[no] += ( hx[j] * ( T[j][i-1]-T[j] ) )
/ h0[j];
solved_temp[no] += ( hx[j][i+1] * ( T[j][i+1]-T[j] ) )
/ h0[j];
solved_temp[no] += ( hy[j] * ( T[j-1]-T[j] ) )
/ h0[j];
solved_temp[no] += ( hy[j+1] * ( T[j+1]-T[j] ) )
/ h0[j];
/* below you see the code that *doesn't work* - isn't it
the same??? */
//solved_temp[no] = T[j] + (
// hx[j] * ( T[j][i-1]-T[j] ) + hx[j][i+1] * (
T[j][i+1]-T[j] ) +
// hy[j] * ( T[j-1]-T[j] ) + hy[j+1] * (
T[j+1]-T[j] )
// ) / h0[j];
if(i == nx-1) /* hits east boundary? */
{
j++; /* next row */
i=1; /* reset x-coordinate */
}
}
}
The expected result is that solved_temp[1] = 20, solved_temp[2] =
20, solved_temp[3] = 20, solved_temp[4] = 20 at all times. If I
swap the above outcommented/commented sections with each other, I
get what I expect the first 7 times. On the 8th time I get that
the next result for solved_temp[1] = -1.#IND000000000000, but the
other results are okay....
What exactly is that -1.#IND000000000000 means?
And isn't it exactly the same code??? I'm pretty confused...
In case you're wondering, hx or hy is either 0 or 1 as you can
see below and all the temperature differences is 0, so it
shouldn't matter anyway... h0 = 2 but also that shouldn't change
anything since everything gives 0 so I have something which is 0
divided by 2 and that ofcourse should give 0........ It all ends
up in (20 + 0) = 20...
Printing hx (step = 8):
i=1: i=2: i=3:
i=4:
j=1: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
j=2: -> 0.00000 -> 0.00000 -> 1.00000 -> 0.00000
j=3: -> 0.00000 -> 0.00000 -> 1.00000 -> 0.00000
j=4: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
Printing hy (step = 8):
i=1: i=2: i=3:
i=4:
j=1: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
j=2: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
j=3: -> 0.00000 -> 1.00000 -> 1.00000 -> 0.00000
j=4: -> 0.00000 -> 0.00000 -> 0.00000 -> 0.00000
(only 5 decimal digits shown, but it shouldn't change anything in
the big picture I guess)....
Why does it work when I calculate solved_temp[no] in 5 individual
steps instead of in one long calculation? Even Microsoft Visual
Studio 2005 debugger agrees with me, but then I step over the
calculation line and find this stupid/strange result......!
I hope somebody can explain this really weird behaviour... I hope
there's a "natural" explanation like "stack overflow" or
whatever....?
I was a bit afraid of posting this if I didn't check my code
properly but now I've looked at it for about 1-2 hours and when
my debugger even agrees with me and I then choose F10 "step over"
and get another result, then I think I need professional help
It works now (with 5 individual calculations), but I just want to
be sure that this error doesn't come back later....
Best regards / Med venlig hilsen
Martin Jørgensen