Skip to content

Commit

Permalink
add test data
Browse files Browse the repository at this point in the history
  • Loading branch information
LasNikas committed Jun 20, 2024
1 parent 8879a76 commit b61302b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/preprocessing/shapes/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Supported file formats are `.stl` and `.asc`.
# Keywords
- `element_type`: Element type (default is `Float64`)
"""
function load_shape(filename; element_type=Float64)
ELTYPE = element_type
Expand Down
55 changes: 39 additions & 16 deletions test/preprocessing/shapes/shapes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,62 @@
@testset verbose=true "2D" begin
files = ["hexagon", "circle", "inverted_open_curve"]
n_edges = [6, 63, 241]
spot_check = [3, 17, 137] # Random edge samples

normals_edge = [
[-0.5000001748438417, -0.8660253028382761],
[-0.06234627263265082, -0.9980545788126094],
[0.8255794226893319, -0.5642859353483385],
]
@testset "Test File `$(files[i])`" for i in eachindex(files)
# Checked in ParaView with `trixi2vtk(shape)`
data = TrixiParticles.CSV.read(joinpath("test", "preprocessing", "data",
"normals_" * files[i] * ".csv"),
TrixiParticles.DataFrame)

normals_vertex = vcat((data.var"normals_vertex:0")',
(data.var"normals_vertex:1")')

points = vcat((data.var"Points:0")',
(data.var"Points:1")')

@testset verbose=true "Test File `$(files[i])`" for i in eachindex(files)
shape = load_shape(joinpath("examples", "preprocessing", files[i] * ".asc"))

@test TrixiParticles.nfaces(shape) == n_edges[i]
@test shape.normals_edge[spot_check[i]] normals_edge[i]

@testset "Normals $j" for j in eachindex(shape.vertices)
@test isapprox(shape.normals_vertex[j][1], normals_vertex[:, j],
atol=1e-4)
end
@testset "Points $j" for j in eachindex(shape.vertices)
@test isapprox(shape.vertices[j], points[:, j], atol=1e-4)
end
end
end
@testset verbose=true "3D" begin
files = ["sphere", "bar", "drive_gear"]
n_faces = [192, 12, 1392]
n_vertices = [98, 8, 696]
spot_check = [37, 5, 329] # Random face samples

normals_vertex = [
[0.30382471570741304, -0.6736804313398639, -0.6736803533984385],
[0.5773502691896257, -0.5773502691896258, -0.5773502691896258],
[0.5715080389137815, -0.3430758125127828, -0.7454378232459212],
]
@testset "Test File `$(files[i])`" for i in eachindex(files)
# Checked in ParaView with `trixi2vtk(shape)`
data = TrixiParticles.CSV.read(joinpath("test", "preprocessing", "data",
"normals_" * files[i] * ".csv"),
TrixiParticles.DataFrame)

normals_vertex = vcat((data.var"normals_vertex:0")',
(data.var"normals_vertex:1")',
(data.var"normals_vertex:2")')

points = vcat((data.var"Points:0")',
(data.var"Points:1")',
(data.var"Points:2")')

@testset verbose=true "Test File `$(files[i])`" for i in eachindex(files)
shape = load_shape(joinpath("examples", "preprocessing", files[i] * ".stl"))

@test TrixiParticles.nfaces(shape) == n_faces[i]
@test length(shape.vertices) == n_vertices[i]
@test shape.normals_vertex[spot_check[i]] normals_vertex[i]

@testset "Normals $j" for j in eachindex(shape.vertices)
@test isapprox(shape.normals_vertex[j], normals_vertex[:, j], atol=1e-5)
end
@testset "Points $j" for j in eachindex(shape.vertices)
@test isapprox(shape.vertices[j], points[:, j], atol=1e-5)
end
end
end
end
Expand Down

0 comments on commit b61302b

Please sign in to comment.