From 7ab6f311c1b03d964f1dc2654321d404bc4e5c99 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 26 Mar 2021 15:52:55 +0100 Subject: [PATCH] Replace hypot with cheaper impl --- euler/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/euler/src/lib.rs b/euler/src/lib.rs index 6739380..d43339b 100644 --- a/euler/src/lib.rs +++ b/euler/src/lib.rs @@ -644,8 +644,12 @@ fn upwind_dissipation( assert!(p > 0.0); let c = (GAMMA * p / rho).sqrt(); - let alpha_u = uhat.abs() + c * Float::hypot(*detj_dxi_dx, *detj_dxi_dy); - let alpha_v = vhat.abs() + c * Float::hypot(*detj_deta_dx, *detj_deta_dy); + // The accurate hypot is very slow, and the accuracy is + // not that important in this case + let hypot = |x: Float, y: Float| Float::sqrt(x * x + y * y); + + let alpha_u = uhat.abs() + c * hypot(*detj_dxi_dx, *detj_dxi_dy); + let alpha_v = vhat.abs() + c * hypot(*detj_deta_dx, *detj_deta_dy); tmp0[0] = alpha_u * rho; tmp1[0] = alpha_v * rho;