Skip to content

Commit be8457c

Browse files
author
Milan K
authored
Merge pull request #137 from milankl/nabla
Nabla operator for export
2 parents e967e1a + 63444ea commit be8457c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Gradients.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function ∇²!(du::Array{T,2},u::Array{T,2}) where {T<:AbstractFloat}
4040
end
4141
end
4242

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

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

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

6264
m,n = size(u)
6365

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

7375
return dudy
7476
end
77+
78+
""" ∇² is the 2nd order centred Laplace-operator ∂/∂x^2 + ∂/∂y^2 with grid spacing Δ (default 1)."""
79+
function ∇²(u::Array{T,2}::Real=1) where {T<:AbstractFloat}
80+
81+
m, n = size(u)
82+
du = Array{T,2}(undef,m-2,n-2)
83+
84+
minus_4 = T(-4.0)
85+
one_over_dx² = T(1/Δ^2)
86+
87+
@inbounds for j 2:n-1
88+
for i 2:m-1
89+
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])
90+
end
91+
end
92+
return du
93+
end

0 commit comments

Comments
 (0)