puncproject / PUNCpp

Particles-in-UNstructured-Cells, C++ version
https://punc.readthedocs.io
GNU General Public License v3.0
12 stars 6 forks source link

Improve accuracy of history-file #56

Closed sigvaldm closed 6 years ago

sigvaldm commented 6 years ago

Consider this excerpt from a history file:

149988  0.000168173 4.18826e+06 3.40103e+06 7.16698e-10 0   13  -0.00010055 1.91847e-10
149989  0.000168173 4.18826e+06 3.40103e+06 7.16691e-10 0   13  -7.70173e-05    1.91848e-10
149990  0.000168173 4.18828e+06 3.40103e+06 7.16721e-10 0   13  -4.92055e-05    1.91849e-10
149991  0.000168173 4.1883e+06  3.40102e+06 7.16724e-10 0   13  -7.05992e-05    1.9185e-10
149992  0.000168173 4.18832e+06 3.40102e+06 7.16739e-10 0   13  -6.20417e-05    1.9185e-10
149993  0.000168174 4.18833e+06 3.40103e+06 7.16725e-10 0   13  -8.1296e-05 1.91849e-10
149994  0.000168174 4.18831e+06 3.40103e+06 7.1672e-10  0   13  -7.27386e-05    1.9185e-10
149995  0.000168174 4.18833e+06 3.40103e+06 7.16741e-10 0   13  -5.56236e-05    1.9185e-10
149996  0.000168174 4.18834e+06 3.40103e+06 7.16742e-10 0   13  -7.27386e-05    1.91851e-10
149997  0.000168174 4.18833e+06 3.40104e+06 7.16776e-10 0   13  -5.13449e-05    1.91852e-10

When the simulation time (second column) becomes large enough, the %g specifier (or stream in C++) prefers to not use scientific notation (e.g. 1.234e-4). However, in this case the time-step is still very small, so it takes many steps before the time increments. I do not know how much an EMA-filter likes this. In any case, round-off errors are un-avoidable in base 10 representations. Perhaps we could have an option to use hexadecimal representation like the one used by %a? This would be exact. Metaplot may have to be updated to support this (I'm not sure).

diakodarian commented 6 years ago

I have now increased the accuracy of history-file without using hexadecimal representation. If it is still necessary to use hexadecimal representation, I can implement it as an option in the History class.

diakodarian commented 6 years ago

I have implemented the option to write data to history.dat using hexadecimal representation. I'm using std::hexfloat which dumps exact representation of a floating point value. However, it does not work with GCC 4.8.5. We need GCC 5.1.0 or above. Unfortunately, I'm stuck with GCC 4.8.5. My implementation is still there in diagnostics.h, but it has been commented out. Once we have CGG 5.1.0 or above, it can be uncommented.

But I think we have already improved the precision using decimal representation, and this issue has been solved. What do you think?

sigvaldm commented 6 years ago

Right! I agree it's not worthwhile changing GCC at this point (although GCC 4.8.5 is quite old). I think we can close this.