Skip to content

Commit

Permalink
Added optical physics executors
Browse files Browse the repository at this point in the history
  • Loading branch information
Hollenbeck-Hayden committed Jan 30, 2025
1 parent d13c4ed commit c5d60c8
Show file tree
Hide file tree
Showing 25 changed files with 306 additions and 55 deletions.
13 changes: 13 additions & 0 deletions app/celer-sim/Runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "celeritas/mat/MaterialParams.hh"
#include "celeritas/optical/CherenkovParams.hh"
#include "celeritas/optical/MaterialParams.hh"
#include "celeritas/optical/ModelImporter.hh"
#include "celeritas/optical/OpticalCollector.hh"
#include "celeritas/optical/ScintillationParams.hh"
#include "celeritas/phys/CutoffParams.hh"
Expand Down Expand Up @@ -633,6 +634,18 @@ void Runner::build_optical_collector(RunnerInput const& inp,
= ceil_div(inp.optical.initializer_capacity, num_streams);
oc_inp.auto_flush = ceil_div(inp.optical.auto_flush, num_streams);

// Import models
optical::ModelImporter importer{
imported, oc_inp.material, core_params_->material()};

for (auto const& model : imported.optical_models)
{
if (auto builder = importer(model.model_class))
{
oc_inp.model_builders.push_back(*builder);
}
}

CELER_ASSERT(oc_inp);
optical_collector_
= std::make_shared<OpticalCollector>(*core_params_, std::move(oc_inp));
Expand Down
4 changes: 4 additions & 0 deletions app/celer-sim/simple-driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def strtobool(text):
'msc': "urban" if core_geo == "vecgeom" else "none",
'eloss_fluctuation': True,
'lpm': True,
'optical': {
'absorption': True,
'rayleigh_scattering': True,
}
}

if geant_exp_exe:
Expand Down
1 change: 1 addition & 0 deletions src/celeritas/ext/GeantImporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ auto import_processes(GeantImporter::DataSelection::Flags process_flags,
}
}
CELER_LOG(debug) << "Loaded " << processes.size() << " processes";
CELER_LOG(debug) << "Loaded " << optical_models.size() << " optical models";
return {
std::move(processes), std::move(msc_models), std::move(optical_models)};
}
Expand Down
5 changes: 3 additions & 2 deletions src/celeritas/optical/CoreParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "CoreState.hh"
#include "MaterialParams.hh"
#include "PhysicsParams.hh"
#include "TrackInitParams.hh"
#include "action/AlongStepAction.hh"
#include "action/BoundaryAction.hh"
Expand Down Expand Up @@ -46,7 +47,7 @@ build_params_refs(CoreParams::Input const& p, CoreScalars const& scalars)
ref.scalars = scalars;
ref.geometry = get_ref<M>(*p.geometry);
ref.material = get_ref<M>(*p.material);
// TODO: ref.physics = get_ref<M>(*p.physics);
ref.physics = get_ref<M>(*p.physics);
ref.rng = get_ref<M>(*p.rng);
ref.init = get_ref<M>(*p.init);

Expand Down Expand Up @@ -112,7 +113,7 @@ CoreParams::CoreParams(Input&& input) : input_(std::move(input))
<< "optical core input is missing " << #MEMBER << " data")
CP_VALIDATE_INPUT(geometry);
CP_VALIDATE_INPUT(material);
// TODO: CP_VALIDATE_INPUT(physics);
CP_VALIDATE_INPUT(physics);
CP_VALIDATE_INPUT(rng);
CP_VALIDATE_INPUT(init);
CP_VALIDATE_INPUT(action_reg);
Expand Down
6 changes: 4 additions & 2 deletions src/celeritas/optical/CoreParams.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace optical
//---------------------------------------------------------------------------//
class MaterialParams;
class TrackInitParams;
// TODO: class PhysicsParams;
class PhysicsParams;

//---------------------------------------------------------------------------//
/*!
Expand All @@ -38,6 +38,7 @@ class CoreParams final : public ParamsDataInterface<CoreParamsData>
//! \name Type aliases
using SPConstGeo = std::shared_ptr<GeoParams const>;
using SPConstMaterial = std::shared_ptr<MaterialParams const>;
using SPConstPhysics = std::shared_ptr<PhysicsParams const>;
using SPConstRng = std::shared_ptr<RngParams const>;
using SPConstTrackInit = std::shared_ptr<TrackInitParams const>;
using SPActionRegistry = std::shared_ptr<ActionRegistry>;
Expand All @@ -52,7 +53,7 @@ class CoreParams final : public ParamsDataInterface<CoreParamsData>
{
SPConstGeo geometry;
SPConstMaterial material;
// TODO: physics
SPConstPhysics physics;
SPConstRng rng;
SPConstTrackInit init;

Expand Down Expand Up @@ -86,6 +87,7 @@ class CoreParams final : public ParamsDataInterface<CoreParamsData>
//! Access shared problem parameter data.
SPConstGeo const& geometry() const { return input_.geometry; }
SPConstMaterial const& material() const { return input_.material; }
SPConstPhysics const& physics() const { return input_.physics; }
SPConstRng const& rng() const { return input_.rng; }
SPConstTrackInit const& init() const { return input_.init; }
SPActionRegistry const& action_reg() const { return input_.action_reg; }
Expand Down
31 changes: 1 addition & 30 deletions src/celeritas/optical/CoreTrackData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "CoreTrackDataFwd.hh"
#include "MaterialData.hh"
#include "ParticleData.hh"
#include "PhysicsData.hh"
#include "SimData.hh"
#include "TrackInitData.hh"
#include "Types.hh"
Expand All @@ -24,36 +25,6 @@ namespace celeritas
namespace optical
{
//---------------------------------------------------------------------------//
// XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
// IMPLEMENT ME!

template<Ownership W, MemSpace M>
struct PhysicsParamsData
{
explicit CELER_FUNCTION operator bool() const { return true; }
};
template<Ownership W, MemSpace M>
struct PhysicsStateData
{
explicit CELER_FUNCTION operator bool() const { return true; }

//! Assign from another set of data
template<Ownership W2, MemSpace M2>
PhysicsStateData& operator=(PhysicsStateData<W2, M2>&)
{
return *this;
}
};

template<MemSpace M>
inline void resize(PhysicsStateData<Ownership::value, M>*,
HostCRef<PhysicsParamsData> const&,
size_type)
{
}

// XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
//---------------------------------------------------------------------------//
/*!
* Memspace-independent core variables.
*/
Expand Down
35 changes: 33 additions & 2 deletions src/celeritas/optical/CoreTrackView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "CoreTrackData.hh"
#include "MaterialView.hh"
#include "ParticleTrackView.hh"
#include "PhysicsStepView.hh"
#include "PhysicsTrackView.hh"
#include "SimTrackView.hh"
#include "TrackInitializer.hh"

Expand Down Expand Up @@ -51,7 +53,7 @@ class CoreTrackView
// Return a material view
inline CELER_FUNCTION MaterialView material() const;

// Return a material view (using an existing geo view
// Return a material view (using an existing geo view)
inline CELER_FUNCTION MaterialView material(GeoTrackView const&) const;

// Return a simulation management view
Expand All @@ -60,6 +62,12 @@ class CoreTrackView
// Return a particle view
inline CELER_FUNCTION ParticleTrackView particle() const;

// Return a physics view
inline CELER_FUNCTION PhysicsTrackView physics() const;

// Return a view to temporary physics data
inline CELER_FUNCTION PhysicsStepView physics_step() const;

// Return an RNG engine
inline CELER_FUNCTION RngEngine rng() const;

Expand Down Expand Up @@ -126,7 +134,8 @@ CoreTrackView::operator=(TrackInitializer const& init)
this->particle()
= ParticleTrackView::Initializer{init.energy, init.polarization};

//! \todo Add physics view and clear physics state
// Initialize the physics state
this->physics() = PhysicsTrackView::Initializer{};

return *this;
}
Expand Down Expand Up @@ -170,6 +179,28 @@ CELER_FUNCTION auto CoreTrackView::particle() const -> ParticleTrackView
return ParticleTrackView{states_.particle, this->track_slot_id()};
}

//---------------------------------------------------------------------------//
/*!
* Return a physics view.
*/
CELER_FUNCTION auto CoreTrackView::physics() const -> PhysicsTrackView
{
OpticalMaterialId mat_id = this->material().material_id();
CELER_ASSERT(mat_id);
return PhysicsTrackView{
params_.physics, states_.physics, mat_id, this->track_slot_id()};
}

//---------------------------------------------------------------------------//
/*!
* Return a view to temporary physics data.
*/
CELER_FUNCTION auto CoreTrackView::physics_step() const -> PhysicsStepView
{
return PhysicsStepView{
params_.physics, states_.physics, this->track_slot_id()};
};

//---------------------------------------------------------------------------//
/*!
* Return the RNG engine.
Expand Down
1 change: 1 addition & 0 deletions src/celeritas/optical/OpticalCollector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ OpticalCollector::OpticalCollector(CoreParams const& core, Input&& inp)

// Create launch action with optical params+state and access to gen data
detail::OpticalLaunchAction::Input la_inp;
la_inp.model_builders = std::move(inp.model_builders);
la_inp.material = inp.material;
la_inp.offload = offload_params_;
la_inp.num_track_slots = inp.num_track_slots;
Expand Down
4 changes: 4 additions & 0 deletions src/celeritas/optical/OpticalCollector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "corecel/data/AuxInterface.hh"
#include "celeritas/Types.hh"

#include "Model.hh"
#include "OffloadData.hh"

namespace celeritas
Expand Down Expand Up @@ -70,6 +71,9 @@ class OpticalCollector

struct Input
{
//! Optical physics models
std::vector<optical::Model::ModelBuilder> model_builders;

//! Optical physics material for materials
SPConstMaterial material;
SPConstCherenkov cherenkov;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/optical/PhysicsStepView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PhysicsStepView
PhysicsStateRef const& state_;
TrackSlotId track_id_;

ItemId<real_type> per_model_xs_id(ModelId) const;
inline ItemId<real_type> per_model_xs_id(ModelId) const;

CELER_FORCEINLINE_FUNCTION PhysicsTrackState& state();
CELER_FORCEINLINE_FUNCTION PhysicsTrackState const& state() const;
Expand Down
17 changes: 15 additions & 2 deletions src/celeritas/optical/action/DiscreteSelectAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
//---------------------------------------------------------------------------//
#include "DiscreteSelectAction.hh"

#include "celeritas/optical/CoreParams.hh"
#include "celeritas/optical/CoreState.hh"

#include "ActionLauncher.hh"
#include "DiscreteSelectExecutor.hh"
#include "TrackSlotExecutor.hh"

namespace celeritas
{
namespace optical
Expand All @@ -26,9 +33,15 @@ DiscreteSelectAction::DiscreteSelectAction(ActionId id)
/*!
* Launch the discrete-select action on host.
*/
void DiscreteSelectAction::step(CoreParams const&, CoreStateHost&) const
void DiscreteSelectAction::step(CoreParams const& core_params,
CoreStateHost& core_state) const
{
CELER_NOT_IMPLEMENTED("Optical discrete select executor not implemented.");
launch_action(
core_state,
make_action_thread_executor(core_params.ptr<MemSpace::native>(),
core_state.ptr(),
this->action_id(),
DiscreteSelectExecutor{}));
}

//---------------------------------------------------------------------------//
Expand Down
18 changes: 16 additions & 2 deletions src/celeritas/optical/action/DiscreteSelectAction.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
//---------------------------------------------------------------------------//
#include "DiscreteSelectAction.hh"

#include "celeritas/optical/CoreParams.hh"
#include "celeritas/optical/CoreState.hh"

#include "ActionLauncher.hh"
#include "DiscreteSelectExecutor.hh"
#include "TrackSlotExecutor.hh"

namespace celeritas
{
namespace optical
Expand All @@ -15,9 +22,16 @@ namespace optical
/*!
* Launch the discrete-select action on device.
*/
void DiscreteSelectAction::step(CoreParams const&, CoreStateDevice&) const
void DiscreteSelectAction::step(CoreParams const& core_params,
CoreStateDevice& core_state) const
{
CELER_NON_IMPLEMENTED("Optical discrete select executor not implemented.");
launch_action(
core_state,
make_action_thread_executor(core_params.ptr<MemSpace::native>(),
core_state.ptr(),
this->action_id(),
DiscreteSelectExecutor{}));
}
}

//---------------------------------------------------------------------------//
Expand Down
36 changes: 36 additions & 0 deletions src/celeritas/optical/action/DiscreteSelectExecutor.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//------------------------------- -*- C++ -*- -------------------------------//
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/optical/action/DiscreteSelectExecutor.hh
//---------------------------------------------------------------------------//
#pragma once

#include "../CoreTrackView.hh"
#include "../PhysicsData.hh"
#include "../PhysicsStepUtils.hh"
#include "../PhysicsTrackView.hh"

namespace celeritas
{
namespace optical
{
//---------------------------------------------------------------------------//
/*!
*/
struct DiscreteSelectExecutor
{
inline CELER_FUNCTION void operator()(CoreTrackView const& track);
};

//---------------------------------------------------------------------------//
/*!
*/
CELER_FUNCTION void DiscreteSelectExecutor::operator()(CoreTrackView const&)
{
// TODO: Implement executor
}

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
9 changes: 9 additions & 0 deletions src/celeritas/optical/detail/OpticalLaunchAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "celeritas/global/CoreState.hh"
#include "celeritas/optical/CoreParams.hh"
#include "celeritas/optical/CoreState.hh"
#include "celeritas/optical/PhysicsParams.hh"
#include "celeritas/optical/TrackInitParams.hh"
#include "celeritas/optical/action/ActionGroups.hh"
#include "celeritas/optical/action/BoundaryAction.hh"
Expand Down Expand Up @@ -72,6 +73,14 @@ OpticalLaunchAction::OpticalLaunchAction(ActionId action_id,
input.initializer_capacity);
inp.action_reg = std::make_shared<ActionRegistry>();
inp.max_streams = core.max_streams();
{
optical::PhysicsParams::Input phys_input;
phys_input.model_builders = std::move(input.model_builders);
phys_input.materials = inp.material;
phys_input.action_registry = inp.action_reg.get();
inp.physics = std::make_shared<optical::PhysicsParams>(
std::move(phys_input));
}
CELER_ENSURE(inp);
return inp;
}());
Expand Down
3 changes: 3 additions & 0 deletions src/celeritas/optical/detail/OpticalLaunchAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "corecel/data/AuxInterface.hh"
#include "celeritas/global/ActionInterface.hh"

#include "../Model.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -56,6 +58,7 @@ class OpticalLaunchAction : public AuxParamsInterface,
struct Input
{
SPConstMaterial material;
std::vector<optical::Model::ModelBuilder> model_builders;
SPOffloadParams offload;
size_type num_track_slots{};
size_type initializer_capacity{};
Expand Down
Loading

0 comments on commit c5d60c8

Please sign in to comment.