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

Field Propagation using Runge-Kutta integration and example15 as demo #166

Merged
merged 36 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
65a7551
First version of classes for Runge-Kutta integration of track in field
jonapost Nov 15, 2021
075f84c
Electrons.cu + RK: return iterations; print good & bad steps.
jonapost Feb 24, 2022
3197dd6
Runge-Kutta integration: changes to identify cause of errors. (For de…
jonapost Feb 26, 2022
21e549b
Fix for compilation - due to change to use fieldConstants.h
jonapost Feb 26, 2022
cfe68f1
electrons.cu: Adapted to changes in G4HepEM (using Example13)
jonapost Apr 4, 2022
fb56e4e
Example15: Fixed multiple parts using changes in Example13
jonapost Jun 14, 2022
a00464c
Fix to pass world volume to G4TransporationManager
jonapost Jun 23, 2022
0c54085
15/electrons: Improved printing of differences RK vs helix
jonapost Jun 30, 2022
fb4b884
fieldPropagatorRungeKutta: added checks vs Helix
jonapost Jun 30, 2022
f40109e
Example15 / magfield : revised prints, new header file.
jonapost Jun 30, 2022
89c3d92
fieldPropagatorRungeKutta: fix update of momentum in substep of Compu…
jonapost Jul 5, 2022
d80f073
fieldPropagatorRungeKutta: Refine intersection for comparisons
jonapost Jul 5, 2022
0a43dc1
Example15 / magneticfield: checks first refined, then disabled.
jonapost Jul 6, 2022
287cf68
fieldPropagatorRungeKutta: IntegrateToEnd reports if loopCt > 1
jonapost Jul 8, 2022
299e41b
fieldPropagatorRungeKutta: fix condition for ending - adding conditio…
jonapost Sep 5, 2022
49014e9
Example15: improvements to printing changes (investigating).
jonapost Sep 5, 2022
483bce4
fieldPropagatorRungeKutta: added step reduction for zero steps (copyi…
jonapost Sep 5, 2022
3be869b
example15.cu: fix call to ensure that ClearQueue occurs (not just whe…
jonapost Sep 22, 2022
9713b67
example15/electrons.cu: first cleanup, removed max_step=0.25mm, alway…
jonapost Sep 22, 2022
996e17f
fieldPropagatorRungeKutta.h: sharper step reduction for stuck tracks,…
jonapost Sep 22, 2022
fc01ae8
example15.cu: Added optional printing and info printing ; Revised ma…
jonapost Nov 24, 2022
fdae177
example15: reset cms2018.gdml as default geometryf
jonapost Nov 25, 2022
c36361b
example15.cu: removed most (optional) verbosity
jonapost Nov 25, 2022
114d404
fieldPropagatorConstBz::ComputeNextStepAndVolume: moved slot after sa…
jonapost Nov 25, 2022
ee1591f
Example13/electrons.cu : added arguments to ComputeStepAndNextVolume
jonapost Nov 25, 2022
4ea8f40
fieldPropagatorConstBz: After multiple zero steps move to other side of
jonapost Nov 25, 2022
1c5a8b5
fieldPropagatorConstBz: cleaned up several printouts; defaults in Com…
jonapost Nov 25, 2022
4787f69
fieldPropagatorRungeKutta: removed optional prints & cleanup
jonapost Nov 25, 2022
4225101
fieldPropagatorConstBz::ComputeStepAndNextVolume enforce that safety …
jonapost Oct 25, 2023
1b7f554
fieldPropagatorConstBz.h : clean-up; added const in arg
jonapost Nov 8, 2023
d033886
fieldPropagatorConstBz: fix vecgeom::Precision; cosmetics
jonapost Nov 16, 2023
efa21e6
Example13: set B=3.8T ; electrons.cu: took out slot in args of fieldP…
jonapost Nov 16, 2023
8c11d26
CompareResponces.h: Added Copyright, reuse
jonapost Nov 16, 2023
0d2cc3a
Example15/electrons.cu : cleanup. Fix to remove slot.
jonapost Nov 30, 2023
edbb17a
example15.cu: cleanup
jonapost Nov 30, 2023
e4cccd5
example15.cpp: Set stack limit to 8K
jonapost Dec 4, 2023
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
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_subdirectory(Example11)
add_subdirectory(Example12)
add_subdirectory(Example13)
add_subdirectory(Example14)
add_subdirectory(Example15)
add_subdirectory(Example16)
add_subdirectory(Example17)
add_subdirectory(Example18)
Expand Down
2 changes: 1 addition & 1 deletion examples/Example11/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Results are reproducible using one RANLUX++ state per track.
### Kernels

This example uses one stream per particle type to launch kernels asynchronously.
They are synchronized via a forth stream using CUDA events.
They are synchronized via a fourth stream using CUDA events.

#### `TransportElectrons<bool IsElectron>`

Expand Down
2 changes: 1 addition & 1 deletion examples/Example12/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Additionally, the kernels score energy deposit and the charged track length per
### Kernels

This example uses one stream per particle type to launch kernels asynchronously.
They are synchronized via a forth stream using CUDA events.
They are synchronized via a fourth stream using CUDA events.

#### `TransportElectrons<bool IsElectron>`

Expand Down
2 changes: 1 addition & 1 deletion examples/Example13/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Additionally, the kernels score energy deposit and the charged track length per
### Kernels

This example uses one stream per particle type to launch kernels asynchronously.
They are synchronized via a forth stream using CUDA events.
They are synchronized via a fourth stream using CUDA events.

#### `TransportElectrons<bool IsElectron>`

Expand Down
5 changes: 4 additions & 1 deletion examples/Example13/electrons.cu
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
bool propagated = true;
double geometryStepLength;
vecgeom::NavStateIndex nextState;
constexpr int max_iters = 10;
// printf("max_iters= %3d\n", max_iters);
if (BzFieldValue != 0) {
geometryStepLength = fieldPropagatorBz.ComputeStepAndNextVolume<BVHNavigator>(
energy, Mass, Charge, geometricalStepLengthFromPhysics, pos, dir, navState, nextState, propagated, safety);
energy, Mass, Charge, geometricalStepLengthFromPhysics, pos, dir, navState, nextState,
propagated, safety, max_iters );
} else {
geometryStepLength = BVHNavigator::ComputeStepAndNextVolume(pos, dir, geometricalStepLengthFromPhysics, navState,
nextState, kPush);
Expand Down
4 changes: 2 additions & 2 deletions examples/Example13/example13.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ extern __constant__ __device__ struct G4HepEmData g4HepEmData;

extern __constant__ __device__ int *MCIndex;

// constexpr vecgeom::Precision BzFieldValue = 0.1 * copcore::units::tesla;
constexpr vecgeom::Precision BzFieldValue = 0;
constexpr vecgeom::Precision BzFieldValue = 3.8 * copcore::units::tesla;
// constexpr vecgeom::Precision BzFieldValue = 0;

#endif
42 changes: 42 additions & 0 deletions examples/Example15/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-FileCopyrightText: 2021 CERN
# SPDX-License-Identifier: Apache-2.0

if(NOT TARGET G4HepEm::g4HepEm)
message(STATUS "Disabling example15 (needs G4HepEm)")
return()
endif()

if(Geant4_FOUND)
if(NOT Geant4_gdml_FOUND)
message(STATUS "Disabling example15 (needs Geant4 with GDML support)")
return()
endif()
else()
message(STATUS "Disabling example15 (needs Geant4)")
return()
endif()

# example15 is the AdePT demo example using material cuts as defined in the input gdml file
add_executable(example15
example15.cpp
example15.cu
electrons.cu
gammas.cu)
target_link_libraries(example15
PRIVATE
AdePT
CopCore::CopCore
VecGeom::vecgeom
VecGeom::vecgeomcuda_static
VecGeom::vgdml
${Geant4_LIBRARIES}
G4HepEm::g4HepEmData
G4HepEm::g4HepEmInit
G4HepEm::g4HepEmRun
CUDA::cudart)

set_target_properties(example15 PROPERTIES CUDA_SEPARABLE_COMPILATION ON CUDA_RESOLVE_DEVICE_SYMBOLS ON)

# Tests
add_test(NAME example15
COMMAND $<TARGET_FILE:example15> -gdml_file ${CMAKE_BINARY_DIR}/cms2018.gdml)
64 changes: 64 additions & 0 deletions examples/Example15/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--
SPDX-FileCopyrightText: 2021 CERN
SPDX-License-Identifier: CC-BY-4.0
-->

## Example 14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Example 14
## Example 15


Example demonstrating particle transportation on GPUs with a non-uniform magnetic field - in arbitrary geometry read from a GDML file.

New feature is
- definition of a non-uniform magnetic field
- integration of the equation of motion of charged particles using embedded Runge-Kutta method, Dormand Prince 4(5).
Caveats (at present) :
- fixed accuracy of integration (constant in source)

The features carried over from Example13 are:
* arbitrary geometry via gdml file (tested with cms2018.gdml from VecGeom persistency/gdml/gdmls folder) and optionally a magnetic field with constant Bz,
* geometry read as Geant4 geometry, reading in regions and cuts, to initialize G4HepEm data
* geometry read then into VecGeom, and synchronized to GPU
* G4HepEm material-cuts couple indices mapped to VecGeom logical volume id's
* physics processes for e-/e+ (including MSC) and gammas using G4HepEm.
* scoring per placed volume, no sensitive detector feature

Electrons, positrons, and gammas are stored in separate containers in device memory.
Free positions in the storage are handed out with monotonic slot numbers, slots are not reused.
Active tracks are passed via three queues per particle type (see `struct ParticleQueues`).
Results are reproducible using one RANLUX++ state per track.

Additionally, the kernels score energy deposit and the charged track length per volume.

### Kernels

This example uses one stream per particle type to launch kernels asynchronously.
They are synchronized via a fourth stream using CUDA events.

#### `TransportElectrons<bool IsElectron>`

1. Obtain safety unless the track is currently on a boundary.
2. Determine physics step limit, including conversion to geometric step length according to MSC.
3. Query geometry (or optionally magnetic field) to get geometry step length.
4. Convert geometry to true step length according to MSC, apply net direction change and discplacement.
5. Apply continuous effects; kill track if stopped.
6. If the particle reaches a boundary, perform relocation.
7. If not, and if there is a discrete process:
1. Sample the final state.
2. Update the primary and produce secondaries.

#### `TransportGammas`

1. Determine the physics step limit.
2. Query VecGeom to get geometry step length (no magnetic field for neutral particles!).
3. If the particle reaches a boundary, perform relocation.
4. If not, and if there is a discrete process:
1. Sample the final state.
2. Update the primary and produce secondaries.

#### `FinishIteration`

Clear the queues and return the tracks in flight.
This kernel runs after all secondary particles were produced.

#### `InitPrimaries` and `InitParticleQueues`

Used to initialize multiple primary particles with separate seeds.
Loading
Loading