diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml index 3cfbcdb..398bec9 100644 --- a/.github/workflows/Documenter.yml +++ b/.github/workflows/Documenter.yml @@ -27,6 +27,24 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + # BEGIN - Build smesh locally - remove once JLL package is available + - name: Get smesh + uses: actions/checkout@v4 + with: + repository: trixi-framework/smesh + path: smesh + - name: Build smesh (Linux) + run: | + mkdir smesh/build && cd smesh/build + cmake .. -DCMAKE_INSTALL_PREFIX=../install + cmake --build . + cmake --install . + cd ../../docs + cat << EOF > LocalPreferences.toml + [Smesh] + libsmesh = "$(pwd)/smesh/install/lib/libsmesh.so" + EOF + # END - Build smesh locally - remove once JLL package is available - uses: julia-actions/setup-julia@v1 with: version: '1' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b6023b..c045d06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,55 @@ jobs: - windows-latest steps: - uses: actions/checkout@v4 + # BEGIN - Build smesh locally - remove once JLL package is available + - uses: msys2/setup-msys2@v2 + if: ${{ matrix.os == 'windows-latest' }} + with: + update: true + install: git base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake + - name: Get smesh + uses: actions/checkout@v4 + with: + repository: trixi-framework/smesh + path: smesh + - name: Build smesh (Linux) + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + mkdir smesh/build && cd smesh/build + cmake .. -DCMAKE_INSTALL_PREFIX=../install + cmake --build . + cmake --install . + cd ../.. + cat << EOF > LocalPreferences.toml + [Smesh] + libsmesh = "$(pwd)/smesh/install/lib/libsmesh.so" + EOF + - name: Build smesh (macOS) + if: ${{ matrix.os == 'macos-latest' }} + run: | + mkdir smesh/build && cd smesh/build + FC=gfortran-13 cmake .. -DCMAKE_INSTALL_PREFIX=../install + cmake --build . + cmake --install . + cd ../.. + cat << EOF > LocalPreferences.toml + [Smesh] + libsmesh = "$(pwd)/smesh/install/lib/libsmesh.dylib" + EOF + - name: Build smesh + if: ${{ matrix.os == 'windows-latest' }} + run: | + mkdir smesh/build && cd smesh/build + FC=gfortran cmake .. -DCMAKE_INSTALL_PREFIX=../install + cmake --build . + cmake --install . + cd ../.. + cat << EOF > LocalPreferences.toml + [Smesh] + libsmesh = "D:\\\\a\\\\Smesh.jl\\\\Smesh.jl\\\\smesh\\\\install\\\\bin\\\\libsmesh.dll" + EOF + shell: 'msys2 {0}' + # END - Build smesh locally - remove once JLL package is available - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.version }} diff --git a/.gitignore b/.gitignore index 359e63b..4c7705c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ Manifest.toml +LocalPreferences.toml run/ diff --git a/README.md b/README.md index 2a7ca56..7979d0a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,68 @@ a simple Fortran package for generating and handling unstructured triangular and meshes. +## Getting started +### Prerequisites +If you have not yet installed Julia, please [follow the instructions for your +operating system](https://julialang.org/downloads/platform/). +[Smesh.jl](https://github.com/trixi-framewor/Smesh.jl) works with Julia v1.8 +and later on Linux, macOS and Windows platforms. + +To use Smesh.jl, you currently need to manually install the underlying Fortran package smesh +(note that this is subject to change in the near future). For installation instructions, +please follow the README in the [smesh](https://github.com/trixi-framework/smesh) +repository. + +### Installation +Since Smesh.jl is a not registered Julia package yet, you can install it by executing +the following commands in the Julia REPL: +```julia +julia> import Pkg; Pkg.add("https://github.com/trixi-framework/Smesh.jl") +``` + +To make use of the local smesh build, you need to tell Smesh.jl where to find the library. +For this, create a `LocalPreferences.toml` file next to your `Project.toml` for the project +in which you use Smesh.jl. It should have the following content: + +* On Linux: + ```toml + [Smesh] + libsmesh = "/lib/libsmesh.so" + ``` +* On macOS: + ```toml + [Smesh] + libsmesh = "/lib/libsmesh.dylib" + ``` +* On Windows: + ```toml + [Smesh] + libsmesh = "/bin/libsmesh.dll" + ``` + +Where `` is where you have installed the local smesh build. + +### Usage +The easiest way to get started is to run one of the examples from the +[`examples`](https://github.com/trixi-framework/Smesh.jl/tree/main/examples) directory by +`include`ing them in Julia, e.g., +``` +julia> using Smesh + +julia> include(joinpath(pkgdir(Smesh), "examples", "build_delaunay_triangulation.jl")) +Computing Delaunay triangulation. +Triangulation elements: 2 +Total flipped edges: 0 +Average search time: 1.25 +Flips/triangle: 0.00 +Flips/node: 0.00 +3×2 Matrix{Int64}: + 3 1 + 1 3 + 2 4 + ``` + + ## Authors Smesh.jl was initiated by [Simone Chiocchetti](https://www.mi.uni-koeln.de/NumSim/dr-simone-chiocchetti/) diff --git a/examples/build_delaunay_triangulation.jl b/examples/build_delaunay_triangulation.jl new file mode 100644 index 0000000..bda809e --- /dev/null +++ b/examples/build_delaunay_triangulation.jl @@ -0,0 +1,12 @@ +using Smesh + +# Create data points +# Note: the transpose + collect is just such that we can write the matrix in human readable +# form here +data_points = collect([0.0 0.0 + 1.0 0.0 + 1.0 1.0 + 0.0 1.0]') + +# Create triangulation +ve = build_delaunay_triangulation(data_points; verbose = true) diff --git a/examples/dummy.jl b/examples/dummy.jl deleted file mode 100644 index 065499d..0000000 --- a/examples/dummy.jl +++ /dev/null @@ -1,3 +0,0 @@ -using Smesh - -Smesh.greet() diff --git a/src/Smesh.jl b/src/Smesh.jl index e9fb662..1731af7 100644 --- a/src/Smesh.jl +++ b/src/Smesh.jl @@ -1,10 +1,49 @@ module Smesh -""" - greet() +using Preferences: @load_preference, @has_preference + +export build_delaunay_triangulation + +if !@has_preference("libsmesh") + error(""" + Missing preference `libsmesh` for package Smesh.jl. Please add a + `LocalPreferences.toml` file to your current Julia project with the following + content, where `path/to/libsmesh.{ext}` is the path to your local build of + libsmesh and `{ext}` is the appropriate extension for shared libraries on your + system (e.g., `so` on Linux, `dylib` on macOS, `dll` on Windows). Afterwards, + you need to restart Julia. + + Content of `LocalPreferences.toml` (between the '```' marks): + + ``` + [Smesh] + libsmesh = "path/to/libsmesh.{ext}" + ``` + """) +end +const libsmesh = @load_preference("libsmesh") -Say hello to the world. + +""" """ -greet() = print("Hello World!") +function build_delaunay_triangulation(data_points; shuffle = false, verbose = false) + # Pre-allocate output array + npoints = size(data_points, 2) + ve_max = @ccall libsmesh.delaunay_triangulation_temparray_size_c(npoints::Cint)::Cint + ve_internal = Matrix{Cint}(undef, 3, ve_max) + + # Perform triangulation + ntriangles = @ccall libsmesh.build_delaunay_triangulation_c(ve_internal::Ref{Cint}, + data_points::Ref{Float64}, + npoints::Cint, + ve_max::Cint, + shuffle::Cint, + verbose::Cint)::Cint + + # Copy to array of appropriate size and convert to Julia `Int`s for convenience + ve_out = convert(Matrix{Int}, ve_internal[:, 1:ntriangles]) + + return ve_out +end end # module Smesh diff --git a/test/test_examples.jl b/test/test_examples.jl index bca07d6..4ad85fe 100644 --- a/test/test_examples.jl +++ b/test/test_examples.jl @@ -5,8 +5,8 @@ using Smesh @testset verbose=true showtiming=true "test_examples.jl" begin -@testset verbose=true showtiming=true "examples/dummy.jl" begin - @test_nowarn include("../examples/dummy.jl") +@testset verbose=true showtiming=true "examples/build_delaunay_triangulation.jl" begin + @test_nowarn include("../examples/build_delaunay_triangulation.jl") end end # @testset "test_examples.jl" diff --git a/test/test_unit.jl b/test/test_unit.jl index 79cd771..021b37b 100644 --- a/test/test_unit.jl +++ b/test/test_unit.jl @@ -5,8 +5,13 @@ using Smesh @testset verbose=true showtiming=true "test_unit.jl" begin -@testset verbose=true showtiming=true "greet" begin - @test_nowarn Smesh.greet() +@testset verbose=true showtiming=true "build_delaunay_triangulation" begin + data_points = collect([0.0 0.0 + 1.0 0.0 + 1.0 1.0 + 0.0 1.0]') + + @test build_delaunay_triangulation(data_points) == [3 1; 1 3; 2 4] end end # @testset "test_unit.jl"