Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First example to actually use smesh #3

Merged
merged 14 commits into from
Jan 26, 2024
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
18 changes: 18 additions & 0 deletions .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Manifest.toml
LocalPreferences.toml
run/
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<smesh-install-prefix>/lib/libsmesh.so"
```
* On macOS:
```toml
[Smesh]
libsmesh = "<smesh-install-prefix>/lib/libsmesh.dylib"
```
* On Windows:
```toml
[Smesh]
libsmesh = "<smesh-install-prefix>/bin/libsmesh.dll"
```

Where `<smesh-install-prefix>` 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/)
Expand Down
12 changes: 12 additions & 0 deletions examples/build_delaunay_triangulation.jl
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 0 additions & 3 deletions examples/dummy.jl

This file was deleted.

47 changes: 43 additions & 4 deletions src/Smesh.jl
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/test_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions test/test_unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading