mantaflow: Avoid computation errors by using hypot for vector norm…#14
mantaflow: Avoid computation errors by using hypot for vector norm…#14bartoszkosiorek wants to merge 2 commits intothunil:masterfrom
Conversation
f494c54 to
d4a65b8
Compare
|
Hi, just looked into the patch and the examples you posted on b.org. It looks like a great fix! One thing I'd do though is keep the hypot patch separate from the README & python3 updates (could go in another pull request). |
Thanks for fast feedback. I just noticed that you have your own fork of mantaflow:
Sure. Will do. |
|
Yes sure, I can help with that. From the top of my head, I think the norm functions in |
I already implemented vector4d on blender side, with commit (any comment is welcomed): Unfortunately there is no hypot4 implementation in libstdc++, so I have to implement it myself. I would also be glad to cover vector4d norm with tests. |
…alization functions Fix for Blender issue: https://projects.blender.org/blender/blender/pulls/136966 In Mantaflow calculating of Vector Normalize iis using the Pythagorean addition, which is defined as: a ⊕ b = sqrt(a^2+b^2) This is hypotenuse, or the length of the longest side of a right-angled triangle, that we know the other 2 sides, a and b. https://en.wikipedia.org/wiki/Pythagorean_addition By using sqrt(a * a + b * b), for large (or small) a or b, there is a possibility of overflow (underflow), although the result itself is not that big (small) to cause overflow (underflow). To overcome this problem, there are implementations of hypotenuse that do not use power of 2, and use other methods to calculate the result. To calculate a ⊕ b, you can easily use hypot(a,b). https://en.cppreference.com/w/cpp/numeric/math/hypot This patch is limiting unpredicteble behaviour of the Mantaflow, caused by computation errors.
|
Here is the next issue which was fixed by this PR: Exported script: liquid_viscosity_flashing_84349_script.py.txt Exported script for: |
…alization functions
Original fix:
https://projects.blender.org/blender/blender/pulls/136966
for Blender issues
https://projects.blender.org/blender/blender/issues/102755
and
https://projects.blender.org/blender/blender/issues/84349
In Mantaflow calculating of Vector Normalize iis using the Pythagorean addition, which is defined as:
This is hypotenuse, or the length of the longest side of a right-angled triangle, that we know the other 2 sides, a and b. https://en.wikipedia.org/wiki/Pythagorean_addition
By using sqrt(a * a + b * b), for large (or small) a or b, there is a possibility of overflow (underflow), although the result itself is not that big (small) to cause overflow (underflow).
To overcome this problem, there are implementations of hypotenuse that do not use power of 2, and use other methods to calculate the result.
To calculate a ⊕ b, you can easily use hypot(a,b). https://en.cppreference.com/w/cpp/numeric/math/hypot
This patch is limiting unpredicteble behaviour of the Mantaflow, caused by computation errors.