-
Notifications
You must be signed in to change notification settings - Fork 35
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
Log and kill geometry/propagation errors #1290
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,57 @@ | ||||||
//----------------------------------*-C++-*----------------------------------// | ||||||
// Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers. | ||||||
// See the top-level COPYRIGHT file for details. | ||||||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||
//---------------------------------------------------------------------------// | ||||||
//! \file celeritas/geo/detail/GeoErrorAction.cc | ||||||
//---------------------------------------------------------------------------// | ||||||
#include "GeoErrorAction.hh" | ||||||
|
||||||
#include <string> | ||||||
|
||||||
#include "corecel/Assert.hh" | ||||||
#include "corecel/Types.hh" | ||||||
#include "celeritas/global/ActionLauncher.hh" | ||||||
#include "celeritas/global/CoreParams.hh" | ||||||
#include "celeritas/global/CoreState.hh" | ||||||
#include "celeritas/global/TrackExecutor.hh" | ||||||
|
||||||
#include "GeoErrorExecutor.hh" // IWYU pragma: associated | ||||||
|
||||||
namespace celeritas | ||||||
{ | ||||||
namespace detail | ||||||
{ | ||||||
//---------------------------------------------------------------------------// | ||||||
/*! | ||||||
* Construct with action ID. | ||||||
*/ | ||||||
GeoErrorAction::GeoErrorAction(ActionId aid) | ||||||
: ConcreteAction(aid, "geo-kill", "kill a track due to a navigation error") | ||||||
{ | ||||||
} | ||||||
|
||||||
//---------------------------------------------------------------------------// | ||||||
/*! | ||||||
* Launch the boundary action on host. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
void GeoErrorAction::execute(CoreParams const& params, | ||||||
CoreStateHost& state) const | ||||||
{ | ||||||
auto execute = make_action_track_executor(params.ptr<MemSpace::native>(), | ||||||
state.ptr(), | ||||||
this->action_id(), | ||||||
GeoErrorExecutor{}); | ||||||
return launch_action(*this, params, state, execute); | ||||||
} | ||||||
|
||||||
#if !CELER_USE_DEVICE | ||||||
void GeoErrorAction::execute(CoreParams const&, CoreStateDevice&) const | ||||||
{ | ||||||
CELER_NOT_CONFIGURED("CUDA OR HIP"); | ||||||
} | ||||||
#endif | ||||||
|
||||||
//---------------------------------------------------------------------------// | ||||||
} // namespace detail | ||||||
} // namespace celeritas |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||
//---------------------------------*-CUDA-*----------------------------------// | ||||||
// Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers. | ||||||
// See the top-level COPYRIGHT file for details. | ||||||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||
//---------------------------------------------------------------------------// | ||||||
//! \file celeritas/geo/detail/GeoErrorAction.cu | ||||||
//---------------------------------------------------------------------------// | ||||||
#include "GeoErrorAction.hh" | ||||||
|
||||||
#include "celeritas/global/ActionLauncher.device.hh" | ||||||
#include "celeritas/global/CoreParams.hh" | ||||||
#include "celeritas/global/CoreState.hh" | ||||||
#include "celeritas/global/TrackExecutor.hh" | ||||||
|
||||||
#include "GeoErrorExecutor.hh" | ||||||
|
||||||
namespace celeritas | ||||||
{ | ||||||
namespace detail | ||||||
{ | ||||||
//---------------------------------------------------------------------------// | ||||||
/*! | ||||||
* Launch the boundary action on device. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
void GeoErrorAction::execute(CoreParams const& params, | ||||||
CoreStateDevice& state) const | ||||||
{ | ||||||
auto execute = make_action_track_executor(params.ptr<MemSpace::native>(), | ||||||
state.ptr(), | ||||||
this->action_id(), | ||||||
GeoErrorExecutor{}); | ||||||
|
||||||
static ActionLauncher<decltype(execute)> const launch_kernel(*this); | ||||||
launch_kernel(params, state, *this, execute); | ||||||
} | ||||||
|
||||||
//---------------------------------------------------------------------------// | ||||||
} // namespace detail | ||||||
} // namespace celeritas |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file celeritas/geo/detail/GeoErrorAction.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include "celeritas/global/ActionInterface.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace detail | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Kill the track due to a geometry error. | ||
* | ||
* \sa CoreTrackView::geo_error_action | ||
*/ | ||
class GeoErrorAction final : public ExplicitCoreActionInterface, | ||
public ConcreteAction | ||
{ | ||
public: | ||
// Construct with ID | ||
explicit GeoErrorAction(ActionId); | ||
|
||
// Launch kernel with host data | ||
void execute(CoreParams const&, CoreStateHost&) const final; | ||
|
||
// Launch kernel with device data | ||
void execute(CoreParams const&, CoreStateDevice&) const final; | ||
|
||
//! Dependency ordering of the action | ||
ActionOrder order() const final { return ActionOrder::post; } | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace detail | ||
} // namespace celeritas |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,80 @@ | ||||||
//----------------------------------*-C++-*----------------------------------// | ||||||
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers. | ||||||
// See the top-level COPYRIGHT file for details. | ||||||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||
//---------------------------------------------------------------------------// | ||||||
//! \file celeritas/geo/detail/GeoErrorExecutor.hh | ||||||
//---------------------------------------------------------------------------// | ||||||
#pragma once | ||||||
|
||||||
#include "corecel/Macros.hh" | ||||||
#include "celeritas/Types.hh" | ||||||
#include "celeritas/global/CoreTrackView.hh" | ||||||
#include "celeritas/phys/ParticleTrackView.hh" | ||||||
#include "celeritas/track/SimTrackView.hh" | ||||||
|
||||||
#include "../GeoMaterialView.hh" | ||||||
#include "../GeoTrackView.hh" | ||||||
|
||||||
#if !CELER_DEVICE_COMPILE | ||||||
# include "corecel/io/Logger.hh" | ||||||
# include "corecel/io/Repr.hh" | ||||||
#endif | ||||||
|
||||||
namespace celeritas | ||||||
{ | ||||||
namespace detail | ||||||
{ | ||||||
//---------------------------------------------------------------------------// | ||||||
/*! | ||||||
* Kill the track due to a geometry error. | ||||||
*/ | ||||||
struct GeoErrorExecutor | ||||||
{ | ||||||
inline CELER_FUNCTION void | ||||||
operator()(celeritas::CoreTrackView const& track); | ||||||
}; | ||||||
|
||||||
//---------------------------------------------------------------------------// | ||||||
CELER_FUNCTION void | ||||||
GeoErrorExecutor::operator()(celeritas::CoreTrackView const& track) | ||||||
{ | ||||||
using Energy = ParticleTrackView::Energy; | ||||||
|
||||||
auto particle = track.make_particle_view(); | ||||||
auto sim = track.make_sim_view(); | ||||||
|
||||||
// Deposit the remaining energy locally | ||||||
auto deposited = particle.energy().value(); | ||||||
if (particle.is_antiparticle()) | ||||||
{ | ||||||
// Energy conservation for killed positrons | ||||||
deposited += 2 * particle.mass().value(); | ||||||
} | ||||||
track.make_physics_step_view().deposit_energy(Energy{deposited}); | ||||||
particle.subtract_energy(particle.energy()); | ||||||
|
||||||
// Mark that this track was abandoned while looping | ||||||
sim.status(TrackStatus::killed); | ||||||
|
||||||
#if !CELER_DEVICE_COMPILE | ||||||
auto geo = track.make_geo_view(); | ||||||
auto msg = CELER_LOG_LOCAL(error); | ||||||
msg << "Tracking error at " << repr(geo.pos()) << " along " | ||||||
<< repr(geo.dir()) << ": "; | ||||||
if (!geo.is_outside()) | ||||||
{ | ||||||
msg << "depositing " << deposited << " [" << Energy::unit_type::label() | ||||||
<< "] in " | ||||||
<< "volume " << geo.volume_id().unchecked_get(); | ||||||
} | ||||||
else | ||||||
{ | ||||||
msg << "lost " << deposited << " energy"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm apparently I forgot to push! |
||||||
} | ||||||
#endif | ||||||
} | ||||||
|
||||||
//---------------------------------------------------------------------------// | ||||||
} // namespace detail | ||||||
} // namespace celeritas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under what circumstances might this occur?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our
GeoMaterial
input takes a map of volume name/material IDs and fills the rest with invalid IDs. Those IDs can be legitimate if the volume isn't reachable by the tracking routine (e.g., the[EXTERIOR]
volume, or other "imaginary" volumes defined for convenience by vecgeom/g4). However if there's an error in the input or importing or something, you can end up with undefined materials...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, makes sense. In what cases do you think we should be asserting/validating vs. logging an error and killing on the CPU/silently killing the track on the GPU?