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

Identify and kill looping tracks #685

Merged
merged 15 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
33 changes: 32 additions & 1 deletion app/celer-dump-data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,36 @@ void print_em_params(ImportEmParameters const& em_params)
)gfm";
cout << PEP_STREAM_BOOL(energy_loss_fluct) << PEP_STREAM_BOOL(lpm)
<< PEP_STREAM_BOOL(integral_approach)
<< PEP_STREAM_PARAM(linear_loss_limit) << endl;
<< PEP_STREAM_PARAM(linear_loss_limit) << PEP_STREAM_BOOL(auger)
<< endl;
#undef PEP_STREAM_PARAM
#undef PEP_STREAM_BOOL
}

//---------------------------------------------------------------------------//
/*!
* Print transportation parameters.
*/
void print_trans_params(ImportData::ImportTransParamMap const& trans_params,
ParticleParams const& particles)
{
#define PEP_STREAM_PARAM(NAME, PAR) \
"| " << setw(24) << #NAME << " | " << setw(9) << PAR << " | " << setw(7) \
<< kv.second.NAME << " |\n"
cout << R"gfm(
# Transportation parameters

| Transportation parameter | Particle | Value |
| ------------------------ | --------- | ------- |
)gfm";
for (auto const& kv : trans_params)
{
auto pid = particles.find(PDGNumber{kv.first});
auto par = particles.id_to_label(pid);
cout << PEP_STREAM_PARAM(threshold_trials, par)
<< PEP_STREAM_PARAM(important_energy, par);
}
cout << endl;
#undef PEP_STREAM_PARAM
}

Expand All @@ -440,6 +469,7 @@ void print_sb_data(ImportData::ImportSBMap const& sb_map)

cout << R"gfm(
# Seltzer-Berger data

| Atomic number | Endpoints (x, y, value [mb]) |
| ------------- | ---------------------------------------------------------- |
)gfm";
Expand Down Expand Up @@ -578,6 +608,7 @@ int main(int argc, char* argv[])
print_msc_models(data, *particle_params);
print_volumes(data.volumes, data.materials);
print_em_params(data.em_params);
print_trans_params(data.trans_params, *particle_params);
print_sb_data(data.sb_data);
print_livermore_pe_data(data.livermore_pe_data);
print_atomic_relaxation_data(data.atomic_relaxation_data);
Expand Down
7 changes: 7 additions & 0 deletions app/demo-loop/LDemoIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "celeritas/phys/PrimaryGeneratorOptionsIO.json.hh"
#include "celeritas/phys/ProcessBuilder.hh"
#include "celeritas/random/RngParams.hh"
#include "celeritas/track/SimParams.hh"
#include "celeritas/track/TrackInitParams.hh"

using namespace celeritas;
Expand Down Expand Up @@ -153,6 +154,7 @@ void from_json(nlohmann::json const& j, LDemoArgs& v)
get_optional(jfilter, "event_id", v.mctruth_filter.event_id);
get_optional(jfilter, "track_id", v.mctruth_filter.track_id);
get_optional(jfilter, "parent_id", v.mctruth_filter.parent_id);
get_optional(jfilter, "action_id", v.mctruth_filter.action_id);

if (v.mctruth_filter)
{
Expand Down Expand Up @@ -344,6 +346,11 @@ TransporterInput load_input(LDemoArgs const& args)
params.rng = std::make_shared<RngParams>(args.seed);
}

// Construct simulation params
{
params.sim = SimParams::from_import(imported_data, params.particle);
}

// Construct track initialization params
{
CELER_VALIDATE(args.initializer_capacity > 0,
Expand Down
6 changes: 4 additions & 2 deletions app/demo-loop/LDemoIO.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace demo_loop
{
//---------------------------------------------------------------------------//
/*!
* Write when event ID matches and either track ID or parent ID matches.
* Write when event ID matches and either track ID or parent ID matches, or
* when action ID matches.
*/
struct MCTruthFilter
{
Expand All @@ -47,11 +48,12 @@ struct MCTruthFilter
std::vector<size_type> track_id;
size_type event_id = unspecified();
size_type parent_id = unspecified();
size_type action_id = unspecified();

explicit operator bool() const
{
return !track_id.empty() || event_id != unspecified()
|| parent_id != unspecified();
|| parent_id != unspecified() || action_id != unspecified();
}
};

Expand Down
12 changes: 7 additions & 5 deletions app/demo-loop/Transporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ class DiagnosticActionAdapter final : public ExplicitActionInterface
//! Execute the action with host data
void execute(CoreHostRef const& core) const final
{
this->execute_impl(core.states, diagnostics_->host);
this->execute_impl(core.params, core.states, diagnostics_->host);
}

//! Execute the action with device data
void execute(CoreDeviceRef const& core) const final
{
this->execute_impl(core.states, diagnostics_->device);
this->execute_impl(core.params, core.states, diagnostics_->device);
}

//!@{
Expand All @@ -99,12 +99,14 @@ class DiagnosticActionAdapter final : public ExplicitActionInterface
using VecUPDiag = DiagnosticStore::VecUPDiag<M>;

template<MemSpace M>
void execute_impl(CoreStateData<Ownership::reference, M> const& states,
VecUPDiag<M> const& diagnostics) const
void
execute_impl(CoreParamsData<Ownership::const_reference, M> const& params,
CoreStateData<Ownership::reference, M> const& states,
VecUPDiag<M> const& diagnostics) const
{
for (auto const& diag_ptr : diagnostics)
{
diag_ptr->mid_step(states);
diag_ptr->mid_step(params, states);
}
}
};
Expand Down
9 changes: 7 additions & 2 deletions app/demo-loop/demo-loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ bool rsw_filter_match(size_type step_trk_id,
/*!
* `RootStepWriter` filter.
*
* Write if any combination of event ID, track ID, and/or parent ID match. If
* no fields are specified or are set to -1, all steps are stored.
* Write if any combination of event ID, track ID, and/or parent ID match, or
* if the action ID matches. If no fields are specified or are set to -1, all
* steps are stored.
*/
std::function<bool(RootStepWriter::TStepData const&)>
make_root_step_writer_filter(LDemoArgs const& args)
Expand All @@ -105,6 +106,10 @@ make_root_step_writer_filter(LDemoArgs const& args)
{
rsw_filter = [opts = args.mctruth_filter](
RootStepWriter::TStepData const& step) {
if (opts.action_id != MCTruthFilter::unspecified())
{
return step.action_id == opts.action_id;
}
return (rsw_filter_match(step.event_id, opts.event_id)
&& rsw_filter_match(step.track_id, opts.track_id)
&& rsw_filter_match(step.parent_id, opts.parent_id));
Expand Down
3 changes: 2 additions & 1 deletion app/demo-loop/diagnostic/Diagnostic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class Diagnostic
{
public:
using EventId = celeritas::EventId;
using ParamsRef = celeritas::CoreParamsData<Ownership::const_reference, M>;
using StateRef = celeritas::CoreStateData<Ownership::reference, M>;

// Virtual destructor for polymorphic deletion
virtual ~Diagnostic() = 0;

// Collect diagnostic(s) in the middle of a step
virtual void mid_step(StateRef const&) {}
virtual void mid_step(ParamsRef const&, StateRef const&) {}

// Collect results from diagnostic
virtual void get_result(TransporterResult*) {}
Expand Down
6 changes: 4 additions & 2 deletions app/demo-loop/diagnostic/EnergyDiagnostic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ namespace demo_loop
//---------------------------------------------------------------------------//
// KERNEL INTERFACE
//---------------------------------------------------------------------------//
void bin_energy(CoreStateHostRef const& states, PointersHost& pointers)
void bin_energy(CoreParamsHostRef const& params,
CoreStateHostRef const& states,
PointersHost& pointers)
{
EnergyDiagnosticLauncher<MemSpace::host> launch(states, pointers);
EnergyDiagnosticLauncher<MemSpace::host> launch(params, states, pointers);
for (auto tid : range(TrackSlotId{states.size()}))
{
launch(tid);
Expand Down
12 changes: 8 additions & 4 deletions app/demo-loop/diagnostic/EnergyDiagnostic.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,29 @@ namespace demo_loop
/*!
* Get energy deposition from state data and accumulate in appropriate bin
*/
__global__ void
bin_energy_kernel(const CoreStateDeviceRef states, PointersDevice pointers)
__global__ void bin_energy_kernel(CoreParamsDeviceRef const params,
CoreStateDeviceRef const states,
PointersDevice pointers)
{
auto tid = KernelParamCalculator::thread_id();
if (!(tid < states.size()))
return;

EnergyDiagnosticLauncher<MemSpace::device> launch(states, pointers);
EnergyDiagnosticLauncher<MemSpace::device> launch(params, states, pointers);
launch(TrackSlotId{tid.unchecked_get()});
}

//---------------------------------------------------------------------------//
// KERNEL INTERFACE
//---------------------------------------------------------------------------//
void bin_energy(CoreStateDeviceRef const& states, PointersDevice& pointers)
void bin_energy(CoreParamsDeviceRef const& params,
CoreStateDeviceRef const& states,
PointersDevice& pointers)
{
CELER_LAUNCH_KERNEL(bin_energy,
celeritas::device().default_block_size(),
states.size(),
params,
states,
pointers);
}
Expand Down
28 changes: 19 additions & 9 deletions app/demo-loop/diagnostic/EnergyDiagnostic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class EnergyDiagnostic : public Diagnostic<M>
using real_type = celeritas::real_type;
using Axis = celeritas::Axis;
using Items = celeritas::Collection<real_type, Ownership::value, M>;
using ParamsRef = celeritas::CoreParamsData<Ownership::const_reference, M>;
using StateRef = celeritas::CoreStateData<Ownership::reference, M>;
//!@}

Expand All @@ -52,7 +53,7 @@ class EnergyDiagnostic : public Diagnostic<M>
explicit EnergyDiagnostic(std::vector<real_type> const& bounds, Axis axis);

// Number of alive tracks determined at the end of a step.
void mid_step(StateRef const& states) final;
void mid_step(ParamsRef const& params, StateRef const& states) final;

// Collect diagnostic results
void get_result(TransporterResult* result) final;
Expand Down Expand Up @@ -103,28 +104,34 @@ class EnergyDiagnosticLauncher
using real_type = celeritas::real_type;
using TrackSlotId = celeritas::TrackSlotId;
using Pointers = EnergyBinPointers<M>;
using ParamsRef = celeritas::CoreParamsData<Ownership::const_reference, M>;
using StateRef = celeritas::CoreStateData<Ownership::reference, M>;
//!@}

public:
// Construct with shared and state data
CELER_FUNCTION
EnergyDiagnosticLauncher(StateRef const& states, Pointers const& pointers);
EnergyDiagnosticLauncher(ParamsRef const& params,
StateRef const& states,
Pointers const& pointers);

// Perform energy binning by position
inline CELER_FUNCTION void operator()(TrackSlotId tid) const;

private:
ParamsRef const& params_;
StateRef const& states_;
Pointers const& pointers_;
};

using PointersDevice = EnergyBinPointers<MemSpace::device>;
using PointersHost = EnergyBinPointers<MemSpace::host>;

void bin_energy(celeritas::CoreStateDeviceRef const& states,
void bin_energy(celeritas::CoreParamsDeviceRef const& params,
celeritas::CoreStateDeviceRef const& states,
PointersDevice& pointers);
void bin_energy(celeritas::CoreStateHostRef const& states,
void bin_energy(celeritas::CoreParamsHostRef const& params,
celeritas::CoreStateHostRef const& states,
PointersHost& pointers);

//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -159,7 +166,8 @@ EnergyDiagnostic<M>::EnergyDiagnostic(std::vector<real_type> const& bounds,
* Accumulate energy deposition in diagnostic.
*/
template<MemSpace M>
void EnergyDiagnostic<M>::mid_step(StateRef const& states)
void EnergyDiagnostic<M>::mid_step(ParamsRef const& params,
StateRef const& states)
{
// Set up pointers to pass to device
EnergyBinPointers<M> pointers;
Expand All @@ -168,7 +176,7 @@ void EnergyDiagnostic<M>::mid_step(StateRef const& states)
pointers.edep = energy_per_bin_;

// Invoke kernel for binning energies
demo_loop::bin_energy(states, pointers);
demo_loop::bin_energy(params, states, pointers);
}

//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -199,10 +207,12 @@ std::vector<celeritas::real_type> EnergyDiagnostic<M>::energy_deposition()
//---------------------------------------------------------------------------//
template<MemSpace M>
CELER_FUNCTION
EnergyDiagnosticLauncher<M>::EnergyDiagnosticLauncher(StateRef const& states,
EnergyDiagnosticLauncher<M>::EnergyDiagnosticLauncher(ParamsRef const& params,
StateRef const& states,
Pointers const& pointers)
: states_(states), pointers_(pointers)
: params_(params), states_(states), pointers_(pointers)
{
CELER_EXPECT(params_);
CELER_EXPECT(states_);
CELER_EXPECT(pointers_);
}
Expand All @@ -212,7 +222,7 @@ template<MemSpace M>
CELER_FUNCTION void
EnergyDiagnosticLauncher<M>::operator()(TrackSlotId tid) const
{
celeritas::SimTrackView sim(states_.sim, tid);
celeritas::SimTrackView sim(params_.sim, states_.sim, tid);
if (sim.status() == celeritas::TrackStatus::inactive)
{
// Only apply to active and dying tracks
Expand Down
7 changes: 4 additions & 3 deletions app/demo-loop/diagnostic/ParticleProcessDiagnostic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ParticleProcessDiagnostic : public Diagnostic<M>
SPConstPhysics physics);

// Particle/model tallied after sampling discrete interaction
void mid_step(StateRef const& states) final;
void mid_step(ParamsRef const&, StateRef const& states) final;

// Collect diagnostic results
void get_result(TransporterResult* result) final;
Expand Down Expand Up @@ -164,7 +164,8 @@ ParticleProcessDiagnostic<M>::ParticleProcessDiagnostic(
* physics state if a discrete interaction occurred.
*/
template<MemSpace M>
void ParticleProcessDiagnostic<M>::mid_step(StateRef const& states)
void ParticleProcessDiagnostic<M>::mid_step(ParamsRef const&,
StateRef const& states)
{
using ItemsRef = celeritas::Collection<size_type, Ownership::reference, M>;

Expand Down Expand Up @@ -248,7 +249,7 @@ ParticleProcessLauncher<M>::operator()(TrackSlotId tid) const
{
using BinId = celeritas::ItemId<size_type>;

celeritas::SimTrackView sim(states_.sim, tid);
celeritas::SimTrackView sim(params_.sim, states_.sim, tid);

celeritas::ParticleTrackView particle(
params_.particles, states_.particles, tid);
Expand Down
6 changes: 3 additions & 3 deletions app/demo-loop/diagnostic/StepDiagnostic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class StepDiagnostic : public Diagnostic<M>
size_type max_steps);

// Number of steps per track, tallied before post-processing
void mid_step(StateRef const& states) final;
void mid_step(ParamsRef const&, StateRef const& states) final;

// Collect diagnostic results
void get_result(TransporterResult* result) final;
Expand Down Expand Up @@ -210,7 +210,7 @@ StepDiagnostic<M>::StepDiagnostic(ParamsRef const& params,
* the original track data.
*/
template<MemSpace M>
void StepDiagnostic<M>::mid_step(StateRef const& states)
void StepDiagnostic<M>::mid_step(ParamsRef const&, StateRef const& states)
{
StepDiagnosticDataRef<M> data_ref;
data_ref = data_;
Expand Down Expand Up @@ -292,7 +292,7 @@ CELER_FUNCTION void StepLauncher<M>::operator()(TrackSlotId tid) const

celeritas::ParticleTrackView particle(
params_.particles, states_.particles, tid);
celeritas::SimTrackView sim(states_.sim, tid);
celeritas::SimTrackView sim(params_.sim, states_.sim, tid);

// Tally the number of steps if the track was killed
if (sim.status() == celeritas::TrackStatus::killed)
Expand Down
6 changes: 6 additions & 0 deletions src/accel/SharedParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "celeritas/phys/Process.hh"
#include "celeritas/phys/ProcessBuilder.hh"
#include "celeritas/random/RngParams.hh"
#include "celeritas/track/SimParams.hh"
#include "celeritas/track/TrackInitParams.hh"
#include "celeritas/user/StepCollector.hh"

Expand Down Expand Up @@ -355,6 +356,11 @@ void SharedParams::initialize_core(SetupOptions const& options)
= std::make_shared<RngParams>(CLHEP::HepRandom::getTheSeed());
}

// Construct simulation params
{
params.sim = SimParams::from_import(*imported, params.particle);
}

// Construct track initialization params
{
TrackInitParams::Input input;
Expand Down
Loading