Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
43 changes: 16 additions & 27 deletions src/celeritas/optical/MaterialParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,43 +52,32 @@ MaterialParams::from_import(ImportData const& data,
inp.properties.push_back(opt_mat.properties);
}

// Construct volume-to-optical mapping
inp.volume_to_mat.reserve(geo_mat.num_volumes());
bool has_opt_mat{false};
for (auto impl_id : range(ImplVolumeId{geo_mat.num_volumes()}))
// Construct impl-volume-to-optical mapping
inp.volume_to_mat.assign(geo_mat.num_volumes(), OptMatId{});
inp.optical_to_core.assign(inp.properties.size(), PhysMatId{});

std::unordered_set<OptMatId> all_optmat;
for (auto iv_id : range(ImplVolumeId{geo_mat.num_volumes()}))
{
OptMatId optmat;
if (PhysMatId matid = geo_mat.material_id(impl_id))
if (PhysMatId matid = geo_mat.material_id(iv_id))
{
auto mat_view = mat.get(matid);
optmat = mat_view.optical_material_id();
OptMatId optmat = mat_view.optical_material_id();
if (optmat)
{
has_opt_mat = true;
CELER_ASSERT(optmat < inp.optical_to_core.size());
all_optmat.insert(optmat);
inp.optical_to_core[optmat.get()] = matid;
inp.volume_to_mat[iv_id.get()] = optmat;
}
}
inp.volume_to_mat.push_back(optmat);
}

CELER_VALIDATE(has_opt_mat,
CELER_VALIDATE(!all_optmat.empty(),
<< "no volumes have associated optical materials");
CELER_ENSURE(inp.volume_to_mat.size() == geo_mat.num_volumes());

// Construct optical to core material mapping
inp.optical_to_core
= std::vector<PhysMatId>(inp.properties.size(), PhysMatId{});
for (auto core_id : range(PhysMatId{mat.num_materials()}))
{
if (auto opt_mat_id = mat.get(core_id).optical_material_id())
{
CELER_EXPECT(opt_mat_id < inp.optical_to_core.size());
CELER_EXPECT(!inp.optical_to_core[opt_mat_id.get()]);
inp.optical_to_core[opt_mat_id.get()] = core_id;
}
}

CELER_ENSURE(std::all_of(
inp.optical_to_core.begin(), inp.optical_to_core.end(), Identity{}));
CELER_LOG(info) << "Constructed " << inp.properties.size()
<< " optical materials with " << all_optmat.size()
<< " present in the geometry";

return std::make_shared<MaterialParams>(std::move(inp));
}
Expand Down
8 changes: 6 additions & 2 deletions src/celeritas/optical/PhysicsStepUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ inline CELER_FUNCTION StepLimit calc_physics_step_limit(
total_xs += physics.calc_xs(model, particle.energy());
}
physics.macro_xs(total_xs);

CELER_ASSERT(physics.macro_xs() > 0);
CELER_ASSERT(physics.macro_xs() >= 0);

StepLimit limit;
limit.action = physics.discrete_action();
limit.step = physics.interaction_mfp() / total_xs;

if (CELER_UNLIKELY(total_xs == 0))
{
limit.action = {};
}

return limit;
}

Expand Down
14 changes: 12 additions & 2 deletions test/accel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,16 @@ celeritas_add_integration_tests(
RMTYPE serial mt
)

#-----------------------------------------------------------------------------#
# Disable MT Geant4 geometry for optical physics
#-----------------------------------------------------------------------------#

set(_optical_rm_type "serial")
if(NOT (CELERITAS_CORE_GEO STREQUAL "Geant4"))
list(APPEND _optical_rm_type "mt")
endif()

# Test with optical physics, except that currently trying to use Geant4
# navigation for the optical tracks wreaks havoc
# Test optical
celeritas_add_integration_tests(
TrackingManagerIntegration LarSphereOptical run
OFFLOAD cpu gpu g4
Expand All @@ -122,4 +125,11 @@ celeritas_add_integration_tests(
RMTYPE ${_optical_rm_type}
)

# Test optical surface physics
celeritas_add_integration_tests(
TrackingManagerIntegration OpticalSurfaces run
OFFLOAD cpu gpu g4
RMTYPE ${_optical_rm_type}
)

#-----------------------------------------------------------------------------#
20 changes: 20 additions & 0 deletions test/accel/IntegrationTestBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,26 @@ auto IntegrationTestBase::make_sens_det(std::string const&) -> UPSensDet
return nullptr;
}

//---------------------------------------------------------------------------//
// FREE FUNCTIONS
//---------------------------------------------------------------------------//
void enable_optical_physics(IntegrationTestBase::PhysicsInput& phys_inp)
{
// Set default optical physics
auto& optical = phys_inp.optical;
optical = {};
EXPECT_TRUE(optical);
EXPECT_TRUE(optical.cherenkov);
EXPECT_TRUE(optical.scintillation);

// Disable WLS which isn't yet working (reemission) in Celeritas
using WLSO = WavelengthShiftingOptions;
optical.wavelength_shifting = WLSO::deactivated();
optical.wavelength_shifting2 = WLSO::deactivated();
}

//---------------------------------------------------------------------------//
// TEST PROBLEM MIXINS
//---------------------------------------------------------------------------//
/*!
* Create physics list: default is EM only using make_physics_input.
Expand Down
8 changes: 8 additions & 0 deletions test/accel/IntegrationTestBase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ class IntegrationTestBase : public ::celeritas::test::Test
//!@}
};

//---------------------------------------------------------------------------//
// FREE FUNCTIONS
//---------------------------------------------------------------------------//

void enable_optical_physics(IntegrationTestBase::PhysicsInput&);

//---------------------------------------------------------------------------//
// TEST PROBLEM MIXINS
//---------------------------------------------------------------------------//
//! Generate LAr sphere geometry with 10 MeV electrons and functional hit call
class LarSphereIntegrationMixin : virtual public IntegrationTestBase
Expand Down
Loading
Loading