geodynamics / aspect

A parallel, extensible finite element code to simulate convection in both 2D and 3D models.
https://aspect.geodynamics.org/
Other
224 stars 235 forks source link

Output time in statistics file with higher accuracy #824

Closed bangerth closed 8 years ago

bangerth commented 8 years ago

In an email by @egpuckett , he outlined a case where he ran for 50,000 time steps, each of size around 1e-7. However, the statistics file lists times only in the form 0.01xxx (for example), i.e., with 6 actual digits. This does not allow zooming in to a particular area of just a few time steps because their respective times are all the same (or nearly the same).

To the best of my knowledge, the actual time is the only "cumulative" variable in these output files that are added up over many time steps. It may make sense to increase the accuracy of this one variable to more than just the existing 6 digits while leaving the accuracy of all other variables the same.

bangerth commented 8 years ago

The right place to do this is probably in Simulator::output_statistics(), in file source/simulator/helper_functions.cc. What's missing is likely just a call to TableHandler::set_precision ("...", 8) or similar.

egpuckett commented 8 years ago

Got it!

I've been thinking about (double) precision issues. I'm teaching an upper division 'Applied Linear Algebra' class using the textbook

"Matrix Methods in Data Mining and Pattern Recognition" by Lars Eldén

As we all know, double precision nominally has an accuracy of 1.0E-16.
After covering the IEEE Floating Standard Eldén has a super example where

*w*^T *v* - *v*^T *v*  = S

loses five orders of accuracy, when the vectors u^T and v *are close in magnitude and direction.*He actually shows this for the scalar equation

  w * v - v * v  = s

with

v = 100 and  w = 99.999

My question is this. How many base 10 digits would you save and expect them to still be reasonably*accurate?

- G

* On 4/19/2016 3:30 PM, Wolfgang Bangerth wrote:

The right place to do this is probably in |Simulator::output_statistics()|, in file |source/simulator/helper_functions.cc|. What's missing is likely just a call to |TableHandler::set_precision ("...", 8)| or similar.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/geodynamics/aspect/issues/824#issuecomment-212155099

class4kayaker commented 8 years ago

The expected accuracy would depend on the expected relative sizes of the numbers being accumulated, and how many such values need to be accumulated. Larger variations in value scale and more values accumulated would result in larger variations in the accumulated value. Given that the variable in question is time and therefore must be consistently positive, it is unlikely that the error in the accumulated value is ever large relative to the accumulated value. Therefore, the twelve digits in #830 is likely to be accurate and consistent for most cases.

If small variations in the accumulated variable are critical, such as for conservation checks, there are algorithms (Kahan or Knuth sum) that increase the precision of the accumulated value using an additional standard floating point variable and some relatively small calculation overhead. This is almost certainly overkill for the use case in question, but would be relatively simple to implement if desired.