From b0d2c6e32f0be90d0fe44ee581420db946c3cece Mon Sep 17 00:00:00 2001 From: Daniel_Doehring Date: Fri, 22 Mar 2024 08:49:36 +0100 Subject: [PATCH] avoid if --- src/equations/compressible_navier_stokes.jl | 4 ++++ src/equations/compressible_navier_stokes_1d.jl | 8 +------- src/equations/compressible_navier_stokes_2d.jl | 8 +------- src/equations/compressible_navier_stokes_3d.jl | 8 +------- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/equations/compressible_navier_stokes.jl b/src/equations/compressible_navier_stokes.jl index 3059771197c..d4bcb8c8181 100644 --- a/src/equations/compressible_navier_stokes.jl +++ b/src/equations/compressible_navier_stokes.jl @@ -62,3 +62,7 @@ Under `GradientVariablesEntropy`, the Navier-Stokes discretization is provably e """ struct GradientVariablesPrimitive end struct GradientVariablesEntropy end + +dynamic_viscosity(u, equations) = dynamic_viscosity(u, equations.mu, equations) +dynamic_viscosity(u, mu::Real, equations) = mu +dynamic_viscosity(u, mu::T, equations) where {T} = mu(u, equations) \ No newline at end of file diff --git a/src/equations/compressible_navier_stokes_1d.jl b/src/equations/compressible_navier_stokes_1d.jl index 666cd186b33..0e13a4e0111 100644 --- a/src/equations/compressible_navier_stokes_1d.jl +++ b/src/equations/compressible_navier_stokes_1d.jl @@ -166,13 +166,7 @@ function flux(u, gradients, orientation::Integer, # In the simplest cases, the user passed in `mu` or `mu()` # (which returns just a constant) but # more complex functions like Sutherland's law are possible. - if equations.mu isa Real - mu = equations.mu - else - # The equations are equipped with a function that computes the dynamic viscosity mu - # from the current state. - mu = equations.mu(u, equations) - end + mu = dynamic_viscosity(u, equations) # viscous flux components in the x-direction f1 = zero(rho) diff --git a/src/equations/compressible_navier_stokes_2d.jl b/src/equations/compressible_navier_stokes_2d.jl index ddf2f7e85f8..a4f11f27ede 100644 --- a/src/equations/compressible_navier_stokes_2d.jl +++ b/src/equations/compressible_navier_stokes_2d.jl @@ -175,13 +175,7 @@ function flux(u, gradients, orientation::Integer, # In the simplest cases, the user passed in `mu` or `mu()` # (which returns just a constant) but # more complex functions like Sutherland's law are possible. - if equations.mu isa Real - mu = equations.mu - else - # The equations are equipped with a function that computes the dynamic viscosity mu - # from the current state. - mu = equations.mu(u, equations) - end + mu = dynamic_viscosity(u, equations) if orientation == 1 # viscous flux components in the x-direction diff --git a/src/equations/compressible_navier_stokes_3d.jl b/src/equations/compressible_navier_stokes_3d.jl index e3154b21a44..cdc2bbba462 100644 --- a/src/equations/compressible_navier_stokes_3d.jl +++ b/src/equations/compressible_navier_stokes_3d.jl @@ -188,13 +188,7 @@ function flux(u, gradients, orientation::Integer, # In the simplest cases, the user passed in `mu` or `mu()` # (which returns just a constant) but # more complex functions like Sutherland's law are possible. - if equations.mu isa Real - mu = equations.mu - else - # The equations are equipped with a function that computes the dynamic viscosity mu - # from the current state. - mu = equations.mu(u, equations) - end + mu = dynamic_viscosity(u, equations) if orientation == 1 # viscous flux components in the x-direction