Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .JuliaFormatter.toml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/Lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
version: "1"
- name: Use Julia cache
uses: julia-actions/cache@v2
- name: Install JuliaFormatter.jl
run: julia -e 'using Pkg; pkg"add JuliaFormatter"'
- name: Install Runic.jl
run: julia -e 'using Pkg; pkg"add Runic"'
- name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807
run: touch requirements.txt
- name: Setup Python
Expand Down
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ repos:
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: file-contents-sorter
files: .JuliaFormatter.toml
args: [--unique]
- id: mixed-line-ending
args: [--fix=lf]
# - id: no-commit-to-branch
Expand All @@ -43,7 +40,7 @@ repos:
rev: v1.37.1
hooks:
- id: yamllint
- repo: https://github.com/domluna/JuliaFormatter.jl
rev: v2.1.6
- repo: https://github.com/fredrikekre/runic-pre-commit
rev: v2.0.1
hooks:
- id: julia-formatter
- id: runic
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![Build Status](https://github.com/maltezfaria/LevelSetMethods.jl/workflows/Test/badge.svg)](https://github.com/maltezfaria/LevelSetMethods.jl/actions)
[![Test workflow status](https://github.com/maltezfaria/LevelSetMethods.jl/actions/workflows/Test.yml/badge.svg?branch=main)](https://github.com/maltezfaria/LevelSetMethods.jl/actions/workflows/Test.yml?query=branch%3Amain)
[![Lint workflow Status](https://github.com/maltezfaria/LevelSetMethods.jl/actions/workflows/Lint.yml/badge.svg?branch=main)](https://github.com/maltezfaria/LevelSetMethods.jl/actions/workflows/Lint.yml?query=branch%3Amain)
[![Runic Badge](https://img.shields.io/badge/Runic-formatting-brightgreen.svg)](https://github.com/fredrikekre/Runic.jl)
[![Docs workflow Status](https://github.com/maltezfaria/LevelSetMethods.jl/actions/workflows/Docs.yml/badge.svg?branch=main)](https://github.com/maltezfaria/LevelSetMethods.jl/actions/workflows/Docs.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/maltezfaria/LevelSetMethods.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/maltezfaria/LevelSetMethods.jl)
[![BestieTemplate](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/JuliaBesties/BestieTemplate.jl/main/docs/src/assets/badge.json)](https://github.com/JuliaBesties/BestieTemplate.jl)
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DocMeta.setdocmeta!(
const page_rename = Dict("developer.md" => "Developer docs") # Without the numbers
const numbered_pages = [
file for file in readdir(joinpath(@__DIR__, "src")) if
file != "index.md" && splitext(file)[2] == ".md" && occursin(r"^\d", file)
file != "index.md" && splitext(file)[2] == ".md" && occursin(r"^\d", file)
]

modules = [LevelSetMethods]
Expand Down
2 changes: 1 addition & 1 deletion ext/InterpolationsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Interpolations as Itp
import LevelSetMethods as LSM

function __init__()
@info "Loading Interpolations extension for LevelSetMethods.jl"
return @info "Loading Interpolations extension for LevelSetMethods.jl"
end

Itp.interpolate(ϕ::LSM.LevelSet) = Itp.interpolate(ϕ, Itp.BSpline(Itp.Cubic()))
Expand Down
18 changes: 9 additions & 9 deletions ext/MMGSurfaceExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import MarchingCubes
import LevelSetMethods as LSM

function __init__()
@info "Loading MMGSurface extension for LevelSetMethods.jl"
return @info "Loading MMGSurface extension for LevelSetMethods.jl"
end

"""
Expand Down Expand Up @@ -37,13 +37,13 @@ boundary and the reconstructed ideal boundary
Only works for 3 dimensional level-set.
"""
function LSM.export_surface_mesh(
ϕ::LSM.LevelSet,
output::String;
hgrad = nothing,
hmin = nothing,
hmax = nothing,
hausd = nothing,
)
ϕ::LSM.LevelSet,
output::String;
hgrad = nothing,
hmin = nothing,
hmax = nothing,
hausd = nothing,
)
N = LSM.dimension(ϕ)
if N != 3
throw(ArgumentError("export_mesh of $N dimensional level-set not supported."))
Expand Down Expand Up @@ -85,7 +85,7 @@ function LSM.export_surface_mesh(
end

function _write_3D_triangular_mesh(path, vertices, triangles)
open(path, "w") do file
return open(path, "w") do file
write(file, "MeshVersionFormatted 1\n")
write(file, "Dimension 3\n")

Expand Down
20 changes: 10 additions & 10 deletions ext/MMGVolumeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import LevelSetMethods as LSM
# using DelimitedFiles # using or import ? # faster with writedlm ?

function __init__()
@info "Loading MMGVolume extension for LevelSetMethods.jl"
return @info "Loading MMGVolume extension for LevelSetMethods.jl"
end

"""
Expand Down Expand Up @@ -39,13 +39,13 @@ For more information, see the official [MMG documentation](http://www.mmgtools.o
Only works for 2 and 3 dimensional level-set.
"""
function LSM.export_volume_mesh(
ϕ::LSM.LevelSet,
output::String;
hgrad = nothing,
hmin = nothing,
hmax = nothing,
hausd = nothing,
)
ϕ::LSM.LevelSet,
output::String;
hgrad = nothing,
hmin = nothing,
hmax = nothing,
hausd = nothing,
)
N = LSM.dimension(ϕ)
if N != 2 && N != 3
throw(ArgumentError("export_mesh of $N dimensional level-set not supported."))
Expand Down Expand Up @@ -78,7 +78,7 @@ function LSM.export_volume_mesh(
num_triangles = 2(nx - 1) * (ny - 1)
write(file, "\nTriangles\n")
write(file, "$num_triangles\n")
for x_id in 1:(nx-1), y_id in 1:(ny-1)
for x_id in 1:(nx - 1), y_id in 1:(ny - 1)
c00 = (y_id - 1) * nx + x_id
c10 = c00 + 1
c01 = c00 + nx
Expand All @@ -96,7 +96,7 @@ function LSM.export_volume_mesh(
num_tetrahedrons = 6(nx - 1) * (ny - 1) * (nz - 1)
write(file, "\nTetrahedra\n")
write(file, "$num_tetrahedrons\n")
for x_id in 1:(nx-1), y_id in 1:(ny-1), z_id in 1:(nz-1)
for x_id in 1:(nx - 1), y_id in 1:(ny - 1), z_id in 1:(nz - 1)
c000 = (z_id - 1) * nx * ny + (y_id - 1) * nx + x_id
c100 = c000 + 1
c010 = c000 + nx
Expand Down
7 changes: 5 additions & 2 deletions ext/MakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Makie
import LevelSetMethods as LSM

function __init__()
@info "Loading Makie extension for LevelSetMethods.jl"
return @info "Loading Makie extension for LevelSetMethods.jl"
end

# NOTE: Makie recipes currently can't modify the Axis (https://discourse.julialang.org/t/makie-plot-recipe-collections/86434)
Expand Down Expand Up @@ -37,7 +37,10 @@ end
# end
# end

function Makie.convert_arguments(::Union{Type{<:Contour},Type{<:Contourf}}, ϕ::LSM.LevelSet)
function Makie.convert_arguments(
::Union{Type{<:Contour}, Type{<:Contourf}, Type{<:Heatmap}},
ϕ::LSM.LevelSet,
)
LSM.dimension(ϕ) == 2 ||
throw(ArgumentError("Contour plot only supported for 2D level-sets."))
return _contour_plot(ϕ)
Expand Down
34 changes: 17 additions & 17 deletions src/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Centered finite difference scheme for first order derivative at grid point `I`
along dimension `dim`.
"""
function D⁰(ϕ::CartesianMeshField, I, dim)
h = meshsize(ϕ, dim)
h = meshsize(ϕ, dim)
Im = _decrement_index(I, dim)
Ip = _increment_index(I, dim)
return (ϕ[Ip] - ϕ[Im]) / (2h)
Expand All @@ -24,14 +24,14 @@ Forward finite difference scheme for first order derivative at grid point `I`
along dimension `dim`.
"""
@inline function D⁺(ϕ::CartesianMeshField, I, dim)
h = meshsize(ϕ, dim)
h = meshsize(ϕ, dim)
Ip = _increment_index(I, dim)
return (ϕ[Ip] - ϕ[I]) / h
end

function D⁺⁺(ϕ::CartesianMeshField, I, dim)
h = meshsize(ϕ, dim)
Ip = _increment_index(I, dim)
h = meshsize(ϕ, dim)
Ip = _increment_index(I, dim)
Ipp = _increment_index(I, dim, 2)
return (-1.5 * ϕ[I] + 2 * ϕ[Ip] - 1 / 2 * ϕ[Ipp]) / h
end
Expand All @@ -43,7 +43,7 @@ Backward finite difference scheme for first order derivative at grid point `I`
along dimension `dim`.
"""
function D⁻(ϕ::CartesianMeshField, I, dim)
h = meshsize(ϕ, dim)
h = meshsize(ϕ, dim)
Im = _decrement_index(I, dim)
return (ϕ[I] - ϕ[Im]) / h
end
Expand All @@ -57,9 +57,9 @@ end

function weno5⁻(ϕ::CartesianMeshField, I, dim)
# see section 3.4 of Osher-Fedwik
Im = _decrement_index(I, dim)
Im = _decrement_index(I, dim)
Imm = _decrement_index(Im, dim)
Ip = _increment_index(I, dim)
Ip = _increment_index(I, dim)
Ipp = _increment_index(Ip, dim)
# finite differences
v1 = D⁻(ϕ, Imm, dim)
Expand All @@ -76,7 +76,7 @@ function weno5⁻(ϕ::CartesianMeshField, I, dim)
S2 = (13 / 12) * (v2 - 2 * v3 + v4)^2 + (1 / 4) * (v2 - v4)^2
S3 = (13 / 12) * (v3 - 2 * v4 + v5)^2 + (1 / 4) * (3 * v3 - 4 * v4 + v5)^2
# fudge factor
ϵ = 1e-6 * max(v1^2, v2^2, v3^2, v4^2, v5^2) + 1e-99
ϵ = 1.0e-6 * max(v1^2, v2^2, v3^2, v4^2, v5^2) + 1.0e-99
# weights
α1 = 0.1 / (S1 + ϵ)^2
α2 = 0.6 / (S2 + ϵ)^2
Expand All @@ -90,9 +90,9 @@ end

function weno5⁺(ϕ::CartesianMeshField, I, dim)
# see section 3.4 of Osher-Fedwik
Im = _decrement_index(I, dim)
Im = _decrement_index(I, dim)
Imm = _decrement_index(Im, dim)
Ip = _increment_index(I, dim)
Ip = _increment_index(I, dim)
Ipp = _increment_index(Ip, dim)
# finite differences
v1 = D⁺(ϕ, Ipp, dim)
Expand All @@ -109,7 +109,7 @@ function weno5⁺(ϕ::CartesianMeshField, I, dim)
S2 = (13 / 12) * (v2 - 2 * v3 + v4)^2 + (1 / 4) * (v2 - v4)^2
S3 = (13 / 12) * (v3 - 2 * v4 + v5)^2 + (1 / 4) * (3 * v3 - 4 * v4 + v5)^2
# fudge factor
ϵ = 1e-6 * max(v1^2, v2^2, v3^2, v4^2, v5^2) + 1e-99
ϵ = 1.0e-6 * max(v1^2, v2^2, v3^2, v4^2, v5^2) + 1.0e-99
# weights
α1 = 0.1 / (S1 + ϵ)^2
α2 = 0.6 / (S2 + ϵ)^2
Expand All @@ -128,7 +128,7 @@ Centered finite difference scheme for second order derivative at grid point `I`
along dimension `dim`. E.g. if `dim=1`, this approximates `∂ₓₓ`.
"""
function D2⁰(ϕ::CartesianMeshField, I, dim)
h = meshsize(ϕ, dim)
h = meshsize(ϕ, dim)
Im = _decrement_index(I, dim)
Ip = _increment_index(I, dim)
return (ϕ[Ip] - 2ϕ[I] + ϕ[Im]) / h^2
Expand All @@ -143,7 +143,7 @@ along the dimensions `dims`.
If `dims[1] == dims[2]`, it is more efficient to call `D2⁰(ϕ,I,dims[1])`.
"""
function D2(ϕ, I, dims)
h = meshsize(ϕ)
h = meshsize(ϕ)
Ip = _increment_index(I, dims[1])
Im = _decrement_index(I, dims[1])
return (D⁰(ϕ, Ip, dims[2]) - D⁰(ϕ, Im, dims[2])) / (2 * h[dims[1]])
Expand All @@ -156,8 +156,8 @@ Upward finite difference scheme for second order derivative at grid point `I`
along dimension `dim`. E.g. if `dim=1`, this approximates `∂ₓₓ`.
"""
function D2⁺⁺(ϕ::CartesianMeshField, I, dim)
h = meshsize(ϕ, dim)
Ip = _increment_index(I, dim, 1)
h = meshsize(ϕ, dim)
Ip = _increment_index(I, dim, 1)
Ipp = _increment_index(I, dim, 2)
return (ϕ[I] - 2ϕ[Ip] + ϕ[Ipp]) / h^2
end
Expand All @@ -169,8 +169,8 @@ Backward finite difference scheme for second order derivative at grid point `I`
along dimension `dim`. E.g. if `dim=1`, this approximates `∂ₓₓ`.
"""
function D2⁻⁻(ϕ::CartesianMeshField, I, dim)
h = meshsize(ϕ, dim)
Im = _decrement_index(I, dim, 1)
h = meshsize(ϕ, dim)
Im = _decrement_index(I, dim, 1)
Imm = _decrement_index(I, dim, 2)
return (ϕ[Imm] - 2ϕ[Im] + ϕ[I]) / h^2
end
Expand Down
16 changes: 8 additions & 8 deletions src/levelset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Alias for [`MeshField`](@ref) with `vals` as an `AbstractArray` of `Real`s.
"""
const LevelSet{V<:AbstractArray{<:Real},M,B} = MeshField{V,M,B}
const LevelSet{V <: AbstractArray{<:Real}, M, B} = MeshField{V, M, B}

function LevelSet(f::Function, m)
vals = map(f, m)
Expand Down Expand Up @@ -113,24 +113,24 @@ https://en.wikipedia.org/wiki/Mean_curvature#Implicit_form_of_mean_curvature
function curvature(ϕ::LevelSet, I)
N = dimension(ϕ)
if N == 2
ϕx = D⁰(ϕ, I, 1)
ϕy = D⁰(ϕ, I, 2)
ϕx = D⁰(ϕ, I, 1)
ϕy = D⁰(ϕ, I, 2)
ϕxx = D2⁰(ϕ, I, 1)
ϕyy = D2⁰(ϕ, I, 2)
ϕxy = D2(ϕ, I, (2, 1))
κ = (ϕxx * (ϕy)^2 - 2 * ϕy * ϕx * ϕxy + ϕyy * ϕx^2) / (ϕx^2 + ϕy^2)^(3 / 2)
κ = (ϕxx * (ϕy)^2 - 2 * ϕy * ϕx * ϕxy + ϕyy * ϕx^2) / (ϕx^2 + ϕy^2)^(3 / 2)
return κ
elseif N == 3
ϕx = D⁰(ϕ, I, 1)
ϕy = D⁰(ϕ, I, 2)
ϕz = D⁰(ϕ, I, 3)
ϕx = D⁰(ϕ, I, 1)
ϕy = D⁰(ϕ, I, 2)
ϕz = D⁰(ϕ, I, 3)
ϕxx = D2⁰(ϕ, I, 1)
ϕyy = D2⁰(ϕ, I, 2)
ϕzz = D2⁰(ϕ, I, 3)
ϕxy = D2(ϕ, I, (2, 1))
ϕxz = D2(ϕ, I, (3, 1))
ϕyz = D2(ϕ, I, (3, 2))
κ = (ϕxx * ϕy^2 + ϕyy * ϕx^2 + ϕxx * ϕz^2 + ϕzz * ϕx^2 + ϕyy * ϕz^2 + ϕzz * ϕy^2 - 2 * ϕx * ϕz * ϕxz - 2 * ϕy * ϕz * ϕyz - 2 * ϕy * ϕx * ϕxy) / (ϕx^2 + ϕy^2 + ϕz^2)^(3 / 2)
κ = (ϕxx * ϕy^2 + ϕyy * ϕx^2 + ϕxx * ϕz^2 + ϕzz * ϕx^2 + ϕyy * ϕz^2 + ϕzz * ϕy^2 - 2 * ϕx * ϕz * ϕxz - 2 * ϕy * ϕz * ϕyz - 2 * ϕy * ϕx * ϕxy) / (ϕx^2 + ϕy^2 + ϕz^2)^(3 / 2)
return κ
else
# generic method
Expand Down
6 changes: 3 additions & 3 deletions src/levelsetequation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ function integrate!(ls::LevelSetEquation, tf, Δt = Inf)
the level-set equation cannot be solved back in time"
@assert tf >= tc msg
# append boundary conditions for integration
ϕ = current_state(ls)
buf = buffers(ls)
ϕ = current_state(ls)
buf = buffers(ls)
integrator = time_integrator(ls)
# dynamic dispatch. Should not be a problem provided enough computation is
# done inside of the function below
Expand Down Expand Up @@ -229,7 +229,7 @@ function _integrate!(ϕ::LevelSet, buffers, integrator::RK3, terms, tc, tf, Δt)
end

function _compute_terms(terms, ϕ, I, t)
sum(terms) do term
return sum(terms) do term
return _compute_term(term, ϕ, I, t)
end
end
Loading
Loading