Skip to content

Commit

Permalink
Add tests for Cone and Torus for different cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fhagemann committed Nov 3, 2021
1 parent b5b007f commit f2bb8a0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
66 changes: 66 additions & 0 deletions test/ConstructiveSolidGeometry/CSG_primitives.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Test
using SolidStateDetectors
using StaticArrays

import SolidStateDetectors.ConstructiveSolidGeometry as CSG
import SolidStateDetectors.ConstructiveSolidGeometry: Geometry

T = Float64

default_units = SolidStateDetectors.default_unit_tuple()
no_translations = (rotation = one(SMatrix{3, 3, T, 9}), translation = zero(CartesianVector{T}))

@testset "Test primitive parsing" begin
@testset "Cone" begin
for bot in (2.0, Dict("from" => 1.0, "to" => 2.0)),
top in (2.0, 1.0, Dict("from" => 1.0, "to" => 2.0), Dict("from" => 2.0, "to" => 4.0)),
φmax in (180,360)

dict = Dict("difference" => [
Dict("cone" => Dict(
"r" => Dict("bottom" => bot, "top" => top),
"phi" => Dict("from" => "", "to" => "$(φmax)°"),
"h" => 1.0))
for i in 1:2
])

c = Geometry(T, dict, default_units, no_translations)

# No warnings or errors when decomposing the Cones into surfaces
@test_nowarn CSG.surfaces(c.a)
@test_nowarn CSG.surfaces(c.b)

# Check if all Cones are saved the right way
@test c.a isa CSG.Cone
@test c.b isa CSG.Cone
end
end
@testset "Torus" begin
for r_tube in (2.0, Dict("from" => 1.0, "to" => 2.0)),
φmax in (180,360),
θmin in 0:45:90,
θmax in 135:45:270

dict = Dict("difference" => [
Dict( "torus" => Dict(
"r_torus" => 10.0,
"r_tube" => r_tube,
"phi" => Dict("from" => "", "to" => "$(φmax)°"),
"theta" => Dict("from" => "$(θmin)°", "to" => "$(θmax)°")))
for i in 1:2
])
t = Geometry(T, dict, default_units, no_translations)

# No warnings or errors when decomposing the Torus into surfaces
@test_nowarn CSG.surfaces(t.a)
@test_nowarn CSG.surfaces(t.b)

# Check that the r field for all ConeMantles is ordered
for surf in CSG.surfaces(t.a) surf isa CSG.ConeMantle && @test_skip surf.r[1] <= surf.r[2] end

# Check if all Torus are saved the right way
@test t.a isa CSG.Torus
@test t.b isa CSG.Torus
end
end
end
13 changes: 10 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ end
include("SOR_GPU_Backend.jl")
end

@testset "ConstructiveSolidGeometry" begin
include("ConstructiveSolidGeometry/CSG_IO.jl")
include("ConstructiveSolidGeometry/CSG_primitives.jl")
end

T = Float32

@testset "Test real detectors" begin
@testset "Simulate example detector: Inverted Coax" begin
sim = Simulation{T}(SSD_examples[:InvertedCoax])
Expand Down Expand Up @@ -157,7 +164,7 @@ end
end

@testset "Diffusion and Self-Repulsion" begin
sim = Simulation(SSD_examples[:InvertedCoax])
sim = Simulation{T}(SSD_examples[:InvertedCoax])
simulate!(sim, convergence_limit = 1e-5, refinement_limits = [0.2, 0.1], verbose = false)

pos = CartesianPoint{T}(0.02,0,0.05); Edep = 1u"eV"
Expand All @@ -175,7 +182,7 @@ end
end

@testset "Table Simulation" begin
sim = Simulation(SSD_examples[:InvertedCoax])
sim = Simulation{T}(SSD_examples[:InvertedCoax])
simulate!(sim, convergence_limit = 1e-5, refinement_limits = [0.2, 0.1], verbose = false)

evt_table = Table(
Expand Down Expand Up @@ -225,4 +232,4 @@ end
@test sim == Simulation(nt)
end

include("ConstructiveSolidGeometry/CSG_IO.jl")

0 comments on commit f2bb8a0

Please sign in to comment.