Skip to content

Commit

Permalink
Merge pull request #137 from milankl/nabla
Browse files Browse the repository at this point in the history
Nabla operator for export
  • Loading branch information
Milan K authored Mar 4, 2020
2 parents e967e1a + 63444ea commit be8457c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Gradients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function ∇²!(du::Array{T,2},u::Array{T,2}) where {T<:AbstractFloat}
end
end

"""∂x is the 2nd order centred Gradient-operator ∂/∂x with grid spacing Δ (default 1)."""
function ∂x(u::Array{T,2},Δx::Real) where {T<:AbstractFloat}

m,n = size(u)
Expand All @@ -57,7 +58,8 @@ function ∂x(u::Array{T,2},Δx::Real) where {T<:AbstractFloat}
return dudx
end

function ∂y(u::Array{T,2},Δy::Real) where {T<:AbstractFloat}
"""∂y is the 2nd order centred Gradient-operator ∂/∂y with grid spacing Δ (default 1)."""
function ∂y(u::Array{T,2},Δy::Real=1) where {T<:AbstractFloat}

m,n = size(u)

Expand All @@ -72,3 +74,20 @@ function ∂y(u::Array{T,2},Δy::Real) where {T<:AbstractFloat}

return dudy
end

""" ∇² is the 2nd order centred Laplace-operator ∂/∂x^2 + ∂/∂y^2 with grid spacing Δ (default 1)."""
function ∇²(u::Array{T,2}::Real=1) where {T<:AbstractFloat}

m, n = size(u)
du = Array{T,2}(undef,m-2,n-2)

minus_4 = T(-4.0)
one_over_dx² = T(1/Δ^2)

@inbounds for j 2:n-1
for i 2:m-1
du[i-1,j-1] = one_over_dx²*(minus_4*u[i,j] + u[i,j-1] + u[i,j+1] + u[i-1,j] + u[i+1,j])
end
end
return du
end

0 comments on commit be8457c

Please sign in to comment.