Skip to content

Commit 62b4523

Browse files
committed
Change AbstractCoordinatePoint to not be a FieldVector
Implement proper math for affine frames, Refactor code base where necessary.
1 parent f9a03e6 commit 62b4523

File tree

39 files changed

+591
-218
lines changed

39 files changed

+591
-218
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Format = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
1313
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
1414
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
1515
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
16+
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
1617
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1718
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
1819
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
@@ -57,6 +58,7 @@ GPUArrays = "8, 9, 10, 11"
5758
Geant4 = "0.1.13, 0.2"
5859
Interpolations = "0.14, 0.15, 0.16"
5960
IntervalSets = "0.6, 0.7"
61+
InverseFunctions = "0.1"
6062
JSON = "0.21.2"
6163
KernelAbstractions = "0.8, 0.9"
6264
LaTeXStrings = "1.1"

devenv/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Julia development environments
2+
3+
This directory contains the Julia project environments `cpu` and `cuda`
4+
that can be used when developing SolidStateDetectors with Julia >= v1.11.
5+
They contain all direct, test and doc-gen dependencies of SolidStateDetectors,
6+
plus BenchmarkTools and Cthulhu.
7+
8+
Note: These environments can't be used with Julia versions <= v1.10, as they
9+
use a `[sources]` section in the `Project.toml` to ensure SolidStateDetectors
10+
is loaded from the local source directory, this Pkg feature was introduced
11+
in Julia v1.11.

devenv/cpu/Project.toml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[deps]
2+
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
3+
AffineMaps = "2c83c9a8-abf5-4329-a0d7-deffaf474661"
4+
ArraysOfArrays = "65a8f2f4-9b39-5baf-92e2-a9cc46fdf018"
5+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
6+
ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
7+
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
8+
Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f"
9+
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
10+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
11+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
12+
Format = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
13+
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
14+
Geant4 = "559df036-b7a0-42fd-85df-7d5dd9d70f44"
15+
HeterogeneousComputing = "2182be2a-124f-4a91-8389-f06db5907a21"
16+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
17+
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
18+
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
19+
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
20+
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
21+
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
22+
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
23+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
24+
LegendDataTypes = "99e09c13-5545-5ee2-bfa2-77f358fb75d8"
25+
LegendHDF5IO = "c9265ca6-b027-5446-b1a4-febfa8dd10b0"
26+
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
27+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
28+
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
29+
ParallelProcessingTools = "8e8a01fc-6193-5ca1-a2f1-20776dae4199"
30+
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
31+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
32+
PolygonOps = "647866c9-e3ac-4575-94e7-e3d426903924"
33+
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
34+
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
35+
RadiationDetectorSignals = "bf2c0563-65cf-5db2-a620-ceb7de82658c"
36+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
37+
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
38+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
39+
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
40+
SolidStateDetectors = "71e43887-2bd9-5f77-aebd-47f656f0a3f0"
41+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
42+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
43+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
44+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
45+
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
46+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
47+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
48+
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
49+
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
50+
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
51+
UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"
52+
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
53+
54+
[sources]
55+
SolidStateDetectors = {path = "../.."}

devenv/cuda/Project.toml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[deps]
2+
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
3+
AffineMaps = "2c83c9a8-abf5-4329-a0d7-deffaf474661"
4+
ArraysOfArrays = "65a8f2f4-9b39-5baf-92e2-a9cc46fdf018"
5+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
6+
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
7+
ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
8+
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
9+
Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f"
10+
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
11+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
12+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
13+
Format = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
14+
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
15+
Geant4 = "559df036-b7a0-42fd-85df-7d5dd9d70f44"
16+
HeterogeneousComputing = "2182be2a-124f-4a91-8389-f06db5907a21"
17+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
18+
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
19+
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
20+
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
21+
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
22+
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
23+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
24+
LegendDataTypes = "99e09c13-5545-5ee2-bfa2-77f358fb75d8"
25+
LegendHDF5IO = "c9265ca6-b027-5446-b1a4-febfa8dd10b0"
26+
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
27+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
28+
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
29+
ParallelProcessingTools = "8e8a01fc-6193-5ca1-a2f1-20776dae4199"
30+
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
31+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
32+
PolygonOps = "647866c9-e3ac-4575-94e7-e3d426903924"
33+
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
34+
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
35+
RadiationDetectorSignals = "bf2c0563-65cf-5db2-a620-ceb7de82658c"
36+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
37+
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
38+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
39+
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
40+
SolidStateDetectors = "71e43887-2bd9-5f77-aebd-47f656f0a3f0"
41+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
42+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
43+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
44+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
45+
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
46+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
47+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
48+
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
49+
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
50+
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
51+
UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"
52+
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
53+
54+
[sources]
55+
SolidStateDetectors = {path = "../.."}

ext/Geant4/io_gdml.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using LightXML
2626
# Add <position> to <define> section, referenced in the geometry definition (in <solids>) via the name
2727
function create_position(e::AbstractConstructiveGeometry, x_define::XMLElement, name::String, v::Bool)
2828
# Calculate relative position of the volumes contained in the parent volume
29-
x, y, z = parse_origin(e.b) .- parse_origin(e.a)
29+
x, y, z = parse_origin(e.b) - parse_origin(e.a)
3030

3131
xpos = new_child(x_define, "position")
3232
set_attributes(xpos, OrderedDict(
@@ -515,9 +515,10 @@ function add_to_world(x_world::XMLElement, x_define::XMLElement, e::AbstractGeom
515515

516516
x_pos_ref = new_child(x_world, "positionref")
517517
set_attribute(x_pos_ref, "ref", "pos_" * name)
518-
518+
519519
x_pos_ref = new_child(x_define, "position")
520-
x, y, z = parse_origin(e)
520+
parsed_e = parse_origin(e)
521+
x, y, z = parsed_e.x, parsed_e.y, parsed_e.z
521522
set_attributes(x_pos_ref, OrderedDict(
522523
"name" => "pos_" * name,
523524
"x" => x,

src/ChargeDrift/ChargeDrift.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function _add_fieldvector_selfrepulsion!(step_vectors::Vector{CartesianVector{T}
126126
for m in eachindex(step_vectors)
127127
if done[m] continue end
128128
if m > n
129-
direction::CartesianVector{T} = current_pos[n] .- current_pos[m]
129+
direction::CartesianVector{T} = current_pos[n] - current_pos[m]
130130
if iszero(direction) # if the two charges are at the exact same position
131131
continue # don't let them self-repel each other but treat them as same change
132132
end # if diffusion is simulated, they will very likely be separated in the next step

src/ChargeTrapping/ChargeTrapping.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function _calculate_signal(
7878
running_sum::T = zero(T)
7979
q::T = charge
8080
@inbounds for i in eachindex(tmp_signal)
81-
Δldrift::T = (i > 1) ? norm(path[i] .- path[i-1]) : zero(T)
81+
Δldrift::T = (i > 1) ? norm(path[i] - path[i-1]) : zero(T)
8282
Δl::T = Δldrift > 0 ? hypot(Δldrift, vth * (pathtimestamps[i] - pathtimestamps[i-1])) : zero(T)
8383
Δq::T = q ** Δl
8484
q -= Δq

src/ConstructiveSolidGeometry/ConstructiveSolidGeometry.jl

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ module ConstructiveSolidGeometry
2121

2222
using OrderedCollections: OrderedDict
2323

24+
import InverseFunctions
25+
using InverseFunctions: inverse
26+
2427
import Base: in, *, +, -, &, size, zero
2528

2629
abstract type AbstractCoordinateSystem end
@@ -49,14 +52,25 @@ module ConstructiveSolidGeometry
4952
abstract type AbstractLinePrimitive{T} <: AbstractPrimitive{T} end
5053

5154
abstract type AbstractConstructiveGeometry{T} <: AbstractGeometry{T} end
55+
56+
include("Units.jl")
57+
include("PointsAndVectors/PointsAndVectors.jl")
58+
59+
affine_frame(p::AbstractPrimitive) = LocalAffineFrame(origin(p), rotation(p))
5260

61+
frame_transformation(a::AbstractAffineFrame, b::AbstractPrimitive) = frame_transformation(a, affine_frame(b))
62+
frame_transformation(a::AbstractPrimitive, b::AbstractAffineFrame) = frame_transformation(affine_frame(a), b)
63+
frame_transformation(a::AbstractPrimitive, b::AbstractPrimitive) = frame_transformation(affine_frame(a), affine_frame(b))
64+
5365
_csg_convert_args(::Type{T}, r::Real) where T = convert(T, r)
5466
_csg_convert_args(::Type{T}, r::Tuple) where T = broadcast(x -> _csg_convert_args(T, x), r)
5567
_csg_convert_args(::Type{T}, r::Nothing) where T = nothing
5668

5769
_csg_get_promoted_eltype(::Type{T}) where {T <: AbstractArray} = eltype(T)
5870
_csg_get_promoted_eltype(::Type{T}) where {T <: Real} = T
5971
_csg_get_promoted_eltype(::Type{Nothing}) = Int
72+
_csg_get_promoted_eltype(::Type{CartesianPoint{T}}) where {T<:Real} = T
73+
6074
_csg_get_promoted_eltype(::Type{Tuple{T}}) where {T<:Real} = T
6175
_csg_get_promoted_eltype(::Type{Tuple{T1,T2}}) where {T1<:Real, T2<:Real} = promote_type(T1, T2)
6276
_csg_get_promoted_eltype(::Type{Tuple{T1,T2}}) where {T1<:Union{Real, Tuple}, T2<:Union{Real, Tuple}} = promote_type(_csg_get_promoted_eltype(T1), _csg_get_promoted_eltype(T2))
@@ -66,17 +80,17 @@ module ConstructiveSolidGeometry
6680
_handle_phi(φ, rotation) = (φ, rotation)
6781
_handle_phi::Tuple, rotation) = (abs(φ[2]-φ[1]), rotation*RotZ(φ[1]))
6882

69-
include("Units.jl")
70-
include("PointsAndVectors/PointsAndVectors.jl")
71-
7283
rotation(p::AbstractPrimitive) = p.rotation
7384
origin(p::AbstractPrimitive) = p.origin
74-
_transform_into_global_coordinate_system(pt::CartesianPoint, p::AbstractPrimitive) = (rotation(p) * pt) + origin(p)
75-
_transform_into_global_coordinate_system(pt::CartesianVector, p::AbstractPrimitive) = rotation(p) * pt
85+
86+
# ToDo: Completely replace by frame_transformation and remove:
87+
_transform_into_global_coordinate_system(pt::CartesianPoint, p::AbstractPrimitive) = frame_transformation(p, global_frame, pt)
88+
_transform_into_global_coordinate_system(v::CartesianVector, p::AbstractPrimitive) = frame_transformation(p, global_frame, v)
7689
_transform_into_global_coordinate_system(pts::AbstractVector{<:CartesianPoint}, p::AbstractPrimitive) =
77-
broadcast(pt -> _transform_into_global_coordinate_system(pt, p), pts)
78-
_transform_into_object_coordinate_system(pt::CartesianPoint, p::AbstractPrimitive) = inv(rotation(p)) * (pt - origin(p))
79-
_transform_into_object_coordinate_system(pt::CartesianVector, p::AbstractPrimitive) = inv(rotation(p)) * pt
90+
frame_transformation(p, global_frame, pts)
91+
_transform_into_object_coordinate_system(pt::CartesianPoint, p::AbstractPrimitive) = frame_transformation(global_frame, p, pt)
92+
_transform_into_object_coordinate_system(v::CartesianVector, p::AbstractPrimitive) = frame_transformation(global_frame, p, v)
93+
8094
in(pt::CartesianPoint{T}, p::AbstractPrimitive{T}, csgtol::T = csg_default_tol(T)) where {T} =
8195
_in(_transform_into_object_coordinate_system(pt, p), p; csgtol = csgtol)
8296
in(pt::CylindricalPoint{T}, p::AbstractPrimitive{T}, csgtol::T = csg_default_tol(T)) where {T} =

src/ConstructiveSolidGeometry/LinePrimitives/Edge.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ function Edge{T}(;
2525
Edge{T}(a, b)
2626
end
2727

28-
direction(e::Edge) = e.b - e.a
29-
30-
Line(e::Edge{T}) where {T} = Line{T}(e.a, direction(e))
28+
Line(e::Edge) = Line(e.a, e.b)
3129

3230
function distance(pt::CartesianPoint{T}, e::Edge{T}) where {T}
33-
return if (pt - e.b) direction(e) >= 0
31+
v = e.b - e.a
32+
return if (pt - e.b) v >= 0
3433
norm(pt - e.b)
35-
elseif (pt - e.a) direction(e) <= 0
34+
elseif (pt - e.a) v <= 0
3635
norm(pt - e.a)
3736
else
3837
distance(pt, Line(e))
@@ -42,9 +41,9 @@ end
4241
function sample(e::Edge{T}; n = 2)::Vector{CartesianPoint{T}} where {T}
4342
xs = range(zero(T), stop = one(T), length = n)
4443
pts = Vector{CartesianPoint{T}}(undef, n)
45-
dir = direction(e)
44+
v = e.b - e.a
4645
for i in eachindex(pts)
47-
pts[i] = e.a + xs[i] .* dir
46+
pts[i] = e.a + xs[i] .* v
4847
end
4948
pts
5049
end

src/ConstructiveSolidGeometry/LinePrimitives/Line.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ struct Line{T} <: AbstractLinePrimitive{T}
1111
end
1212
end
1313

14+
# function Line(origin::CartesianPoint{T}, direction::CartesianVector{U}) where {T,U}
15+
# R = promote_type(T,U)
16+
# return Line(convert(CartesianPoint{R}, origin), convert(CartesianVector{R}, direction))
17+
# end
18+
19+
Line(a::CartesianPoint, b::CartesianPoint) = Line(a, normalize(b - a))
20+
1421
function Line(;
1522
origin = zero(CartesianPoint{Int}),
1623
direction = CartesianVector{Int}(0,0,1)

0 commit comments

Comments
 (0)