Skip to content

Commit

Permalink
Refactor optical data to use extensible params/states (#1280)
Browse files Browse the repository at this point in the history
* Pass core data into optical collector
* Pass core by reference as a separate argument
* Refactor GenData
* There is no quantum flux, there's no auxiliary
* Add OpticalGenParams/State
* Refactor optical params using aux state
  • Loading branch information
sethrj authored Jun 18, 2024
1 parent 17d96db commit 855b707
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 179 deletions.
1 change: 1 addition & 0 deletions src/celeritas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ list(APPEND SOURCES
optical/OpticalCollector.cc
optical/OpticalPropertyParams.cc
optical/OpticalTrackData.cc
optical/detail/OpticalGenParams.cc
phys/CutoffParams.cc
phys/ImportedModelAdapter.cc
phys/ImportedProcessAdapter.cc
Expand Down
6 changes: 3 additions & 3 deletions src/celeritas/global/CoreState.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CoreStateInterface
virtual CoreStateCounters const& counters() const = 0;

//! Access auxiliary state data
virtual AuxStateVec const& auxiliary() const = 0;
virtual AuxStateVec const& aux() const = 0;

// Inject primaries to be turned into TrackInitializers
virtual void insert_primaries(Span<Primary const> host_primaries) = 0;
Expand Down Expand Up @@ -140,10 +140,10 @@ class CoreState final : public CoreStateInterface
//// USER DATA ////

//! Access auxiliary state data
AuxStateVec const& auxiliary() const final { return aux_state_; }
AuxStateVec const& aux() const final { return aux_state_; }

//! Access auxiliary state data (mutable)
AuxStateVec& auxiliary() { return aux_state_; }
AuxStateVec& aux() { return aux_state_; }

// Convenience function to access auxiliary "collection group" data
template<template<Ownership, MemSpace> class S>
Expand Down
59 changes: 37 additions & 22 deletions src/celeritas/optical/OpticalCollector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,75 @@
//---------------------------------------------------------------------------//
#include "OpticalCollector.hh"

#include "corecel/data/AuxParamsRegistry.hh"
#include "celeritas/global/ActionRegistry.hh"
#include "celeritas/global/CoreParams.hh"
#include "celeritas/optical/CerenkovParams.hh"
#include "celeritas/optical/OpticalGenData.hh"
#include "celeritas/optical/OpticalPropertyParams.hh"
#include "celeritas/optical/ScintillationParams.hh"

#include "detail/OpticalGenStorage.hh"
#include "detail/OpticalGenParams.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Construct with optical params, number of streams, and action registry.
* Construct with core data and optical data.
*/
OpticalCollector::OpticalCollector(Input inp)
: storage_(std::make_shared<detail::OpticalGenStorage>())
OpticalCollector::OpticalCollector(CoreParams const& core, Input&& inp)
{
CELER_EXPECT(inp);

// Create params and stream storage
HostVal<OpticalGenParamsData> host_data;
host_data.cerenkov = inp.cerenkov && inp.properties;
host_data.scintillation = static_cast<bool>(inp.scintillation);
host_data.capacity = inp.buffer_capacity;
storage_->obj = {std::move(host_data), inp.num_streams};
storage_->size.resize(inp.num_streams, {});
OpticalGenSetup setup;
setup.cerenkov = inp.cerenkov && inp.properties;
setup.scintillation = static_cast<bool>(inp.scintillation);
setup.capacity = inp.buffer_capacity;

// Create aux params and add to core
gen_params_ = std::make_shared<detail::OpticalGenParams>(
core.aux_reg()->next_id(), setup);
core.aux_reg()->insert(gen_params_);

// Action to gather pre-step data needed to generate optical distributions
ActionRegistry& actions = *core.action_reg();
gather_action_ = std::make_shared<detail::PreGenGatherAction>(
inp.action_registry->next_id(), storage_);
inp.action_registry->insert(gather_action_);
actions.next_id(), gen_params_->aux_id());
actions.insert(gather_action_);

if (host_data.cerenkov)
if (setup.cerenkov)
{
// Action to generate Cerenkov optical distributions
cerenkov_pregen_action_
= std::make_shared<detail::CerenkovPreGenAction>(
inp.action_registry->next_id(),
inp.properties,
inp.cerenkov,
storage_);
inp.action_registry->insert(cerenkov_pregen_action_);
actions.next_id(),
gen_params_->aux_id(),
std::move(inp.properties),
std::move(inp.cerenkov));
actions.insert(cerenkov_pregen_action_);
}

if (host_data.scintillation)
if (setup.scintillation)
{
// Action to generate scintillation optical distributions
scint_pregen_action_ = std::make_shared<detail::ScintPreGenAction>(
inp.action_registry->next_id(), inp.scintillation, storage_);
inp.action_registry->insert(scint_pregen_action_);
actions.next_id(),
gen_params_->aux_id(),
std::move(inp.scintillation));
actions.insert(scint_pregen_action_);
}

// TODO: add an action to launch optical tracking loop
}

//---------------------------------------------------------------------------//
/*!
* Aux ID for optical generator data.
*/
AuxId OpticalCollector::aux_id() const
{
return gen_params_->aux_id();
}

//---------------------------------------------------------------------------//
} // namespace celeritas
34 changes: 19 additions & 15 deletions src/celeritas/optical/OpticalCollector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@

#include <memory>

#include "corecel/data/AuxInterface.hh"
#include "celeritas/Types.hh"
#include "celeritas/optical/OpticalGenData.hh"

#include "OpticalGenData.hh"

#include "detail/CerenkovPreGenAction.hh"
#include "detail/PreGenGatherAction.hh"
#include "detail/ScintPreGenAction.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
class ActionRegistry;
class CerenkovParams;
class OpticalPropertyParams;
class ScintillationParams;
class CoreParams;

namespace detail
{
struct OpticalGenStorage;
class OpticalGenParams;
} // namespace detail

//---------------------------------------------------------------------------//
Expand All @@ -48,54 +52,54 @@ class OpticalCollector
//!@{
//! \name Type aliases
using SPConstCerenkov = std::shared_ptr<CerenkovParams const>;
using SPConstCore = std::shared_ptr<CoreParams const>;
using SPConstProperties = std::shared_ptr<OpticalPropertyParams const>;
using SPConstScintillation = std::shared_ptr<ScintillationParams const>;
using SPGenStorage = std::shared_ptr<detail::OpticalGenStorage>;
//!@}

struct Input
{
//! Optical physics properties for materials
SPConstProperties properties;
SPConstCerenkov cerenkov;
SPConstScintillation scintillation;
// TODO: main core params?
ActionRegistry* action_registry;

//! Number of steps that have created optical particles
size_type buffer_capacity{};
size_type num_streams{};

//! True if all input is assigned and valid
explicit operator bool() const
{
return (scintillation || (cerenkov && properties))
&& action_registry && buffer_capacity > 0 && num_streams > 0;
&& buffer_capacity > 0;
}
};

public:
// Construct with optical params, number of streams, and action registry
explicit OpticalCollector(Input);
// Construct with core data and optical params
OpticalCollector(CoreParams const&, Input&&);

// Default destructor and move and copy
~OpticalCollector() = default;
CELER_DEFAULT_COPY_MOVE(OpticalCollector);

//! Get the distribution data
SPGenStorage const& storage() const { return storage_; };
// Aux ID for optical generator data
AuxId aux_id() const;

private:
//// TYPES ////

using SPOpticalGenParams = std::shared_ptr<detail::OpticalGenParams>;
using SPCerenkovPreGenAction
= std::shared_ptr<detail::CerenkovPreGenAction>;
using SPScintPreGenAction = std::shared_ptr<detail::ScintPreGenAction>;
using SPGatherAction = std::shared_ptr<detail::PreGenGatherAction>;

//// DATA ////

SPGenStorage storage_;
SPOpticalGenParams gen_params_;

SPGatherAction gather_action_;
SPCerenkovPreGenAction cerenkov_pregen_action_;
SPScintPreGenAction scint_pregen_action_;

// TODO: tracking loop launcher
// TODO: store optical core params and state?
};
Expand Down
48 changes: 33 additions & 15 deletions src/celeritas/optical/OpticalGenData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#include "corecel/Macros.hh"
#include "corecel/Types.hh"
#include "corecel/data/Collection.hh"
#include "corecel/data/CollectionBuilder.hh"
#include "celeritas/Quantities.hh"
#include "celeritas/Types.hh"
#include "celeritas/optical/CerenkovData.hh"
#include "celeritas/optical/OpticalDistributionData.hh"
#include "celeritas/optical/OpticalPropertyData.hh"
#include "celeritas/optical/ScintillationData.hh"

#include "CerenkovData.hh"
#include "OpticalDistributionData.hh"
#include "OpticalPropertyData.hh"
#include "ScintillationData.hh"

namespace celeritas
{
Expand All @@ -31,6 +33,25 @@ struct OpticalBufferSize
size_type scintillation{0};
};

//---------------------------------------------------------------------------//
/*!
* Setup options for optical generation.
*
* At least one of cerenkov and scintillation must be enabled.
*/
struct OpticalGenSetup
{
bool cerenkov{false}; //!< Whether Cerenkov is enabled
bool scintillation{false}; //!< Whether scintillation is enabled
size_type capacity{0}; //!< Distribution data buffer capacity

//! True if valid
explicit CELER_FUNCTION operator bool() const
{
return (cerenkov || scintillation) && capacity > 0;
}
};

//---------------------------------------------------------------------------//
/*!
* Immutable problem data for generating optical photon distributions.
Expand All @@ -40,26 +61,22 @@ struct OpticalGenParamsData
{
//// DATA ////

bool cerenkov{false}; //!< Whether Cerenkov is enabled
bool scintillation{false}; //!< Whether scintillation is enabled
size_type capacity{0}; //!< Distribution data buffer capacity
OpticalGenSetup setup;

//// METHODS ////

//! True if all params are assigned
explicit CELER_FUNCTION operator bool() const
{
return (cerenkov || scintillation) && capacity > 0;
return static_cast<bool>(setup);
}

//! Assign from another set of data
template<Ownership W2, MemSpace M2>
OpticalGenParamsData& operator=(OpticalGenParamsData<W2, M2> const& other)
{
CELER_EXPECT(other);
cerenkov = other.cerenkov;
scintillation = other.scintillation;
capacity = other.capacity;
setup = other.setup;
return *this;
}
};
Expand Down Expand Up @@ -146,13 +163,14 @@ void resize(OpticalGenStateData<Ownership::value, M>* state,
CELER_EXPECT(size > 0);

resize(&state->step, size);
if (params.cerenkov)
OpticalGenSetup const& setup = params.setup;
if (setup.cerenkov)
{
resize(&state->cerenkov, params.capacity);
resize(&state->cerenkov, setup.capacity);
}
if (params.scintillation)
if (setup.scintillation)
{
resize(&state->scintillation, params.capacity);
resize(&state->scintillation, setup.capacity);
}

CELER_ENSURE(*state);
Expand Down
Loading

0 comments on commit 855b707

Please sign in to comment.