Skip to content

Commit

Permalink
Add basic mesh and use it in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Feb 6, 2024
1 parent 2b0e6e7 commit 1160e6d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
11 changes: 5 additions & 6 deletions examples/build_delaunay_triangulation.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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]')
coordinates_min = [0.0, 0.0]
coordinates_max = [1.0, 1.0]
n_points_x = 4
n_points_y = 5
data_points = mesh_basic(coordinates_min, coordinates_max, n_points_x, n_points_y)

# Create triangulation
vertices = build_delaunay_triangulation(data_points; verbose = true)
Expand Down
15 changes: 5 additions & 10 deletions examples/build_polygon_mesh.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using Smesh

# Create data points
corners = collect([0.0 0.0
1.0 0.0
1.0 1.0
0.0 1.0]')
# inner points (randomly generated)
# n_points = 10
# data_points = rand(Float64, 2, n_points)
data_points = [0.110127 0.995047 0.636537 0.942174 0.22912 0.162025 0.616885 0.376891 0.475242 0.448486;
0.554234 0.431985 0.540326 0.0252587 0.702442 0.379256 0.80191 0.237447 0.745391 0.868326]
data_points = hcat(data_points, corners)
coordinates_min = [0.0, 0.0]
coordinates_max = [1.0, 1.0]
n_points_x = 4
n_points_y = 5
data_points = mesh_basic(coordinates_min, coordinates_max, n_points_x, n_points_y)

# Create triangulation
vertices = build_delaunay_triangulation(data_points; verbose = false)
Expand Down
3 changes: 3 additions & 0 deletions src/Smesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Preferences: @load_preference
using smesh_jll: smesh_jll

export build_delaunay_triangulation, delaunay_compute_neighbors, build_polygon_mesh, voronoi_compute_neighbors
export mesh_basic

const libsmesh = @load_preference("libsmesh", smesh_jll.libsmesh)

Expand Down Expand Up @@ -112,4 +113,6 @@ function voronoi_compute_neighbors(vertices, voronoi_vertices, voronoi_vertices_

return voronoi_neighbors
end

include("standard_meshes.jl")
end # module Smesh
25 changes: 25 additions & 0 deletions src/standard_meshes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function mesh_basic(coordinates_min, coordinates_max, n_points_x, n_points_y)
dx = (coordinates_max[1] - coordinates_min[1]) / n_points_x
dy = (coordinates_max[2] - coordinates_min[2]) / n_points_y

points = Matrix{eltype(coordinates_min)}(undef, 2, n_points_x * n_points_y +
div(n_points_y - n_points_y % 2, 2))
count = 1
for j in 1:n_points_y
for i in 1:n_points_x
points[1, count] = coordinates_min[1] + (i - 1) * dx
points[2, count] = coordinates_min[2] + (j - 1) * dy
if j % 2 == 0 && i != 1
points[1, count] -= 0.5dx
end
count += 1
if j % 2 == 0 && i == n_points_x
points[1, count] = points[1, count - 1] + 0.5dx
points[2, count] = points[2, count - 1]
count += 1
end
end
end

return points
end

0 comments on commit 1160e6d

Please sign in to comment.