tlestang / heatcompact3d

3D heat equation with 6th order compact schemes
https://tlestang.github.io/heatcompact3d/
GNU General Public License v3.0
0 stars 1 forks source link

Round-off error #4

Open mathrack opened 1 year ago

mathrack commented 1 year ago

Currently, the draft is using dot_product when computing derivatives

https://github.com/tlestang/heatcompact3d/blob/6b6e21817ccafc5ffde7c9bcf667b6a8f0a97e03/src/module_stencil.f90#L65

However, when computing derivatives, depending on the magnitude of the field, it is often more accurate to have df(i) = a * (f(i+1)-f(i-1)) + ... instead of df(i) = a * f(i+1) - a * f(i-1)) + ....

Of course, the impact of this choice is case-specific. For the heat equation at hand, this has a limited impact if the temperature is properly scaled (average is zero). However, this can be an issue if the temperature is not properly scaled (small amplitude derivatives combined with a temperature expressed in Kelvin for instance).

More generally, this choice can have some impact on the conservation of bulk quantities.

tlestang commented 1 year ago

Thanks @mathrack , defintely something to have in mind. I guess such issue would be straightforward to catch in tests? In which case the implementation of the stencil application could be written in a different way.