A Very Strange Phenomenon

Dear C++ programmers!

I am experiencing a very strange phenomenon. I am coding up a CFD code solving a totally hyperbolic problem. Governing Equation is compressible inviscid Euler equations. If you take a look at the following two lines:

rinteg[2][i][0] = 2.0*(5.0 / 9.0*rhov_1*gd_1 + 8.0 / 9.0*rhov0*gd0 + 5.0 / 9.0*rhov1*gd1);

and

rinteg[2][i][0] = 2.0*(5.0 / 9.0*(rhov_1*gd_1) + 8.0 / 9.0*(rhov0*gd0) + 5.0 / 9.0*(rhov1*gd1));

they are completely the same! Except that I put extra parenthesis, which are trivial. The strange phenomenon is, the time history results are firstly same, then quickly different, and are different throughout the time range I am interested. Does anyone have similar experiences?

Many thanks and regards!

nsi
How different is "different"? The bracketing may affect the order of evaluation, so floating-point rounding might lead to very small differences. If any terms haven't been initialised (look, in particular, at your "minus 1" and "plus 1" density*velocity and gradient terms at boundaries) then this would also lead to differences (and be a significant error).

On an unrelated note, your weights look a bit unusual and since those inside the bracket add up to 2.0 then I'm surprised to see 2.0 and not 0.5 outside. However, only you know what you are doing with rinteg outside this code snippet.
Last edited on
they are completely the same
No they aren't.
5.0 / 9.0*rhov_1*gd_1 is the same as ((5.0 / 9.0)*rhov_1)*gd_1

5.0 / 9.0*(rhov_1*gd_1) is the same as (5.0 / 9.0)*(rhov_1*gd_1).

The order of evaluation causes differences in rounding.

One simple fix: are you using float instead of double?
Topic archived. No new replies allowed.