Skip to content
Snippets Groups Projects
Commit 089cc395 authored by Brian Groenke's avatar Brian Groenke
Browse files

Minor refactoring of nonlinear diffusion methods

parent efaa0493
No related branches found
No related tags found
1 merge request!71Fix regression caused by previous merge
......@@ -9,7 +9,6 @@ function finitediff!(∂x::AbstractVector, x::AbstractVector, Δ::AbstractVector
@. ∂x = (x₂ - x₁) / Δ
end
end
"""
lineardiffusion!(∂y::AbstractVector, x::AbstractVector, Δ::AbstractVector, k::Number)
......@@ -24,33 +23,8 @@ function lineardiffusion!(∂y::AbstractVector, x::AbstractVector, Δ::AbstractV
@. ∂y = k*((x₃ - x₂)/Δ₂ - (x₂-x₁)/Δ₁)/Δ₁
end
end
@propagate_inbounds function _nonlineardiffusion!(∂y, x₁, x₂, x₃, k₁, k₂, Δx₁, Δx₂, Δk)
@. ∂y = (k₂*(x₃ - x₂)/Δx₂ - k₁*(x₂ - x₁)/Δx₁)/Δk
end
@propagate_inbounds function _nonlineardiffusion!(
∂y::AbstractVector{Float64},
x₁::AbstractVector{Float64},
x₂::AbstractVector{Float64},
x₃::AbstractVector{Float64},
k₁::AbstractVector{Float64},
k₂::AbstractVector{Float64},
Δx₁::AbstractVector{Float64},
Δx₂::AbstractVector{Float64},
Δk::AbstractVector{Float64},
)
@turbo @. ∂y = (k₂*(x₃ - x₂)/Δx₂ - k₁*(x₂ - x₁)/Δx₁)/Δk
end
"""
nonlineardiffusion!(
∂y::AbstractVector{Float64},
x::AbstractVector{Float64},
Δx::AbstractVector{Float64},
k::AbstractVector{Float64},
Δk::AbstractVector{Float64}
)
nonlineardiffusion!(∂y, x, Δx, k, Δk)
Second order Laplacian with non-linear diffusion operator, `k`. Accelerated using `LoopVectorization.@turbo` for `Float64` vectors.
"""
......@@ -62,9 +36,31 @@ function nonlineardiffusion!(∂y::AbstractVector, x::AbstractVector, Δx::Abstr
k₂ = (@view k[2:end]),
Δx₁ = (@view Δx[1:end-1]),
Δx₂ = (@view Δx[2:end]);
_nonlineardiffusion!(∂y, x₁, x₂, x₃, k₁, k₂, Δx₁, Δx₂, Δk)
nonlineardiffusion!(∂y, x₁, x₂, x₃, k₁, k₂, Δx₁, Δx₂, Δk)
end
end
"""
nonlineardiffusion(x₁, x₂, x₃, k₁, k₂, Δx₁, Δx₂, Δk)
Scalar second order Laplacian with non-linear diffusion operator, `k`.
"""
nonlineardiffusion(x₁, x₂, x₃, k₁, k₂, Δx₁, Δx₂, Δk) = (k₂*(x₃ - x₂)/Δx₂ - k₁*(x₂ - x₁)/Δx₁)/Δk
@propagate_inbounds function nonlineardiffusion!(∂y, x₁, x₂, x₃, k₁, k₂, Δx₁, Δx₂, Δk)
@. ∂y = nonlineardiffusion(x₁, x₂, x₃, k₁, k₂, Δx₁, Δx₂, Δk)
end
@propagate_inbounds function nonlineardiffusion!(
∂y::AbstractVector{Float64},
x₁::AbstractVector{Float64},
x₂::AbstractVector{Float64},
x₃::AbstractVector{Float64},
k₁::AbstractVector{Float64},
k₂::AbstractVector{Float64},
Δx₁::AbstractVector{Float64},
Δx₂::AbstractVector{Float64},
Δk::AbstractVector{Float64},
)
@turbo @. ∂y = nonlineardiffusion(x₁, x₂, x₃, k₁, k₂, Δx₁, Δx₂, Δk)
end
"""
harmonicmean(x₁, x₂, w₁, w₂)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment