Skip to content
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
549d4b0
Initial draft of surface normals
Hollenbeck-Hayden Aug 28, 2025
65c4f11
Disabled some tests not using ORANGE
Hollenbeck-Hayden Aug 28, 2025
dfd419f
Merge branch 'develop' into surface-normal-state
Hollenbeck-Hayden Sep 9, 2025
42e220b
Revert regressions
Hollenbeck-Hayden Sep 9, 2025
f58138f
Polished and Smear roughness models
Hollenbeck-Hayden Aug 29, 2025
5a6c4ef
Saving progress after fixing some weird bugs
Hollenbeck-Hayden Aug 29, 2025
0335b15
Refactor RoughnessModel
Hollenbeck-Hayden Aug 29, 2025
03f801c
Switch roughness model to builtin surface model
Hollenbeck-Hayden Aug 29, 2025
fa0ac7b
Refined some of builtin roughness models
Hollenbeck-Hayden Aug 30, 2025
e9ab07c
Add missing data file from cherry-pick
Hollenbeck-Hayden Aug 30, 2025
0c591a8
Add documentation
Hollenbeck-Hayden Aug 30, 2025
b0b4130
Added builtin surface model builder
Hollenbeck-Hayden Aug 30, 2025
8551827
Added surface model view tests
Hollenbeck-Hayden Aug 30, 2025
89e572a
Cleanup surface physics view a bit
Hollenbeck-Hayden Aug 31, 2025
4ff7fa4
Pre PR clean up
Hollenbeck-Hayden Sep 2, 2025
9e2a05f
Revert sincos change in GaussianRoughnessSampler
Hollenbeck-Hayden Sep 2, 2025
966f24f
Added Seth's changes
Hollenbeck-Hayden Sep 9, 2025
29b5a25
Fix failing tests
Hollenbeck-Hayden Sep 9, 2025
71034e2
Merge branch 'develop' into surface-builtin-models
Hollenbeck-Hayden Sep 11, 2025
cfddbbf
Reverted sincos using global namespace
Hollenbeck-Hayden Sep 11, 2025
5d9fd4d
Merge branch 'develop' into surface-builtin-models
Hollenbeck-Hayden Sep 18, 2025
7941d43
Added some of Seth's minor suggestions
Hollenbeck-Hayden Sep 18, 2025
b9da2db
Refactored builtin surface model input
Hollenbeck-Hayden Sep 18, 2025
735416a
Cache track subsurface traversal direction
Hollenbeck-Hayden Sep 18, 2025
c6aa9e1
Re-enabled celer-sim tests involving surface normals
Hollenbeck-Hayden Sep 18, 2025
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
5 changes: 5 additions & 0 deletions app/celer-sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ celer_sim_test(lar
lar-sphere.gdml gamma-4evt-15prim.hepmc3 lar-mctruth.root
)

if(NOT CELERITAS_CORE_GEO STREQUAL "ORANGE")
set_tests_properties("app/celer-sim:lar:cpu" PROPERTIES DISABLED True)
set_tests_properties("app/celer-sim:lar:gpu" PROPERTIES DISABLED True)
endif()

#-----------------------------------------------------------------------------#
3 changes: 3 additions & 0 deletions src/celeritas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ celeritas_polysource(optical/gen/PrimaryGeneratorAction)
celeritas_polysource(optical/gen/detail/GeneratorAlgorithms)
celeritas_polysource(optical/gen/detail/OffloadAlgorithms)
celeritas_polysource(optical/surface/BoundaryAction)
celeritas_polysource(optical/surface/model/GaussianRoughnessModel)
celeritas_polysource(optical/surface/model/PolishedRoughnessModel)
celeritas_polysource(optical/surface/model/SmearRoughnessModel)
celeritas_polysource(phys/detail/DiscreteSelectAction)
celeritas_polysource(phys/detail/PreStepAction)
celeritas_polysource(phys/detail/TrackingCutAction)
Expand Down
3 changes: 3 additions & 0 deletions src/celeritas/optical/CoreTrackView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ CoreTrackView::operator=(TrackInitializer const& init)
// Initialize the physics state
this->physics() = PhysicsTrackView::Initializer{};

// Initialize the surface state
this->surface_physics().reset();

return *this;
}

Expand Down
9 changes: 6 additions & 3 deletions src/celeritas/optical/action/ActionLauncher.device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ class ActionLauncher : public KernelLauncher<F>
|| CELER_COMPILER == CELER_COMPILER_CLANG)
&& !std::is_pointer_v<F> && !std::is_reference_v<F>,
R"(Launched action must be a trivially copyable function object)");
using StepActionT = OpticalStepActionInterface;

public:
// Create a launcher from a string
using KernelLauncher<F>::KernelLauncher;

// Create a launcher from an action
template<class StepActionT>
explicit ActionLauncher(StepActionT const& action);

// Create a launcher with a string extension
template<class StepActionT>
ActionLauncher(StepActionT const& action, std::string_view ext);

// Launch a kernel for a thread range or number of threads
Expand All @@ -77,8 +78,9 @@ class ActionLauncher : public KernelLauncher<F>
* Create a launcher from an action.
*/
template<class F>
template<class StepActionT>
ActionLauncher<F>::ActionLauncher(StepActionT const& action)
: ActionLauncher{action.label()}
: KernelLauncher<F>{action.label()}
{
}

Expand All @@ -87,9 +89,10 @@ ActionLauncher<F>::ActionLauncher(StepActionT const& action)
* Create a launcher with a string extension.
*/
template<class F>
template<class StepActionT>
ActionLauncher<F>::ActionLauncher(StepActionT const& action,
std::string_view ext)
: ActionLauncher{std::string(action.label()) + "-" + std::string(ext)}
: KernelLauncher<F>{std::string(action.label()) + "-" + std::string(ext)}
{
}

Expand Down
5 changes: 5 additions & 0 deletions src/celeritas/optical/action/detail/AlongStepExecutor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ struct AlongStepExecutor
//---------------------------------------------------------------------------//
CELER_FUNCTION void AlongStepExecutor::operator()(CoreTrackView& track)
{
if (track.surface_physics().is_crossing_boundary())
{
return;
}

auto sim = track.sim();

CELER_ASSERT(sim.status() == TrackStatus::alive);
Expand Down
5 changes: 5 additions & 0 deletions src/celeritas/optical/action/detail/PreStepExecutor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ CELER_FUNCTION void PreStepExecutor::operator()(CoreTrackView const& track)
|| sim.status() == TrackStatus::alive);
sim.status(TrackStatus::alive);

if (track.surface_physics().is_crossing_boundary())
{
return;
}

auto phys = track.physics();
if (!phys.has_interaction_mfp())
{
Expand Down
5 changes: 5 additions & 0 deletions src/celeritas/optical/action/detail/PropagateExecutor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct PropagateExecutor
//---------------------------------------------------------------------------//
CELER_FUNCTION void PropagateExecutor::operator()(CoreTrackView& track)
{
if (track.surface_physics().is_crossing_boundary())
{
return;
}

auto&& sim = track.sim();
CELER_ASSERT(sim.status() == TrackStatus::alive);

Expand Down
5 changes: 5 additions & 0 deletions src/celeritas/optical/action/detail/TrackingCutExecutor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ struct TrackingCutExecutor
//---------------------------------------------------------------------------//
CELER_FUNCTION void TrackingCutExecutor::operator()(CoreTrackView& track)
{
if (track.surface_physics().is_crossing_boundary())
{
return;
}

using Energy = ParticleTrackView::Energy;

auto deposited = track.particle().energy().value();
Expand Down
126 changes: 126 additions & 0 deletions src/celeritas/optical/surface/SurfaceModelView.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//------------------------------- -*- C++ -*- -------------------------------//
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/optical/surface/SurfaceModelView.hh
//---------------------------------------------------------------------------//
#pragma once

#include "celeritas/optical/Types.hh"
#include "celeritas/phys/SurfacePhysicsMapView.hh"

namespace celeritas
{
namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Optical surface data for a model.
*
* Wraps common behavior for querying the surface model data for a given
* physics surface interface.
*/
class SurfaceModelView
{
public:
//!@{
//! \name Type aliases
using InternalSurfaceId = SurfacePhysicsMapView::InternalSurfaceId;
//!@}

public:
// Construct from a direction, map view, and materials
inline CELER_FUNCTION SurfaceModelView(SubsurfaceDirection,
SurfacePhysicsMapView,
OptMatId pre_mat,
OptMatId post_mat);

// Get subsurface track direction
inline CELER_FUNCTION SubsurfaceDirection direction() const;

// Get surface model ID
inline CELER_FUNCTION SurfaceModelId surface_model() const;

// Get internal surface ID for the model
inline CELER_FUNCTION InternalSurfaceId internal_surface_id() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to clarify whether this is "internal" as in "implementation" or "sub-surface" (I can't remember what we ended up deciding or postponing...)

EDIT: I remember, originally this was a type alias inside SurfaceModel , and it's just a local index for the data. I wonder if it'd be better to call it ModelSurfaceId or something after all? :\

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe PerModelSurfaceId?


// Get pre-volume optical material
inline CELER_FUNCTION OptMatId pre_material() const;

// Get post-volume optical material
inline CELER_FUNCTION OptMatId post_material() const;

private:
SubsurfaceDirection dir_;
SurfacePhysicsMapView physics_map_;
OptMatId pre_material_;
OptMatId post_material_;
};

//---------------------------------------------------------------------------//
// INLINE DEFINITIONS
//---------------------------------------------------------------------------//
/*!
* Construct from track direction, physics map view, and materials.
*/
CELER_FUNCTION
SurfaceModelView::SurfaceModelView(SubsurfaceDirection dir,
SurfacePhysicsMapView physics_map,
OptMatId pre_material,
OptMatId post_material)
: dir_(dir)
, physics_map_(physics_map)
, pre_material_(pre_material)
, post_material_(post_material)
{
}

//---------------------------------------------------------------------------//
/*!
* Get the subsurface track direction pointing to this surface.
*/
CELER_FUNCTION SubsurfaceDirection SurfaceModelView::direction() const
{
return dir_;
}

//---------------------------------------------------------------------------//
/*!
* Get the surface model for this physics surface.
*/
CELER_FUNCTION SurfaceModelId SurfaceModelView::surface_model() const
{
return physics_map_.surface_model_id();
}

//---------------------------------------------------------------------------//
/*!
* Get the internal surface ID for the physics surface in this model.
*/
CELER_FUNCTION auto SurfaceModelView::internal_surface_id() const
-> InternalSurfaceId
{
return physics_map_.internal_surface_id();
}

//---------------------------------------------------------------------------//
/*!
* Get the optical material before the interface.
*/
CELER_FUNCTION OptMatId SurfaceModelView::pre_material() const
{
return pre_material_;
}

//---------------------------------------------------------------------------//
/*!
* Get the optical material after the interface.
*/
CELER_FUNCTION OptMatId SurfaceModelView::post_material() const
{
return post_material_;
}

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
97 changes: 18 additions & 79 deletions src/celeritas/optical/surface/SurfacePhysicsParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,80 +11,18 @@
#include "celeritas/inp/SurfacePhysics.hh"
#include "celeritas/phys/SurfacePhysicsMapBuilder.hh"

#include "model/GaussianRoughnessModel.hh"
#include "model/PolishedRoughnessModel.hh"
#include "model/SmearRoughnessModel.hh"

#include "detail/BuiltinSurfaceModelBuilder.hh"

namespace celeritas
{
namespace optical
{
namespace
{
//---------------------------------------------------------------------------//
/*!
* A fake model used to mock actual surface physics models.
*
* TODO: Remove and replace with actual built-in surface models.
*/
template<class T>
class FakeModel : public SurfaceModel
{
public:
FakeModel(SurfaceModelId model_id,
std::string_view label,
std::map<PhysSurfaceId, T> const& layer_map)
: SurfaceModel(model_id, label), layers_(layer_map)
{
}

VecSurfaceLayer get_surfaces() const final
{
VecSurfaceLayer result;
for ([[maybe_unused]] auto const& [layer, data] : layers_)
{
result.push_back(PhysSurfaceId(layer.get()));
}
return result;
}

void step(CoreParams const&, CoreStateHost&) const final {}
void step(CoreParams const&, CoreStateDevice&) const final {}

private:
std::map<PhysSurfaceId, T> layers_;
};

//---------------------------------------------------------------------------//
/*!
* Helper to build fake models.
*
* Doesn't insert empty models and keeps track of number of physics surfaces
* for validation purposes.
*/
class FakeModelBuilder
{
public:
FakeModelBuilder(std::vector<std::shared_ptr<SurfaceModel>>& models)
: models_(models)
{
}

template<class T>
void operator()(std::string_view label,
std::map<PhysSurfaceId, T> const& layer_map)
{
if (!layer_map.empty())
{
models_.push_back(std::make_shared<FakeModel<T>>(
SurfaceModelId(models_.size()), label, layer_map));
num_surf_ += layer_map.size();
}
}

size_type num_surfaces() const { return num_surf_; }

private:
std::vector<std::shared_ptr<SurfaceModel>>& models_;
size_type num_surf_{0};
};

//---------------------------------------------------------------------------//
/*!
* Calculate number of physics surfaces as defined by interstitial materials.
Expand Down Expand Up @@ -196,24 +134,25 @@ auto SurfacePhysicsParams::build_models(
for (auto step : range(SurfacePhysicsOrder::size_))
{
// Build fake models
FakeModelBuilder build_model{step_models[step]};
detail::BuiltinSurfaceModelBuilder build_model{step_models[step]};
switch (step)
{
case SurfacePhysicsOrder::roughness:
build_model("polished", input.roughness.polished);
build_model("smear", input.roughness.smear);
build_model("gaussian", input.roughness.gaussian);
build_model.build<PolishedRoughnessModel>(
input.roughness.polished);
build_model.build<SmearRoughnessModel>(input.roughness.smear);
build_model.build<GaussianRoughnessModel>(
input.roughness.gaussian);
break;

case SurfacePhysicsOrder::reflectivity:
build_model("grid", input.reflectivity.grid);
build_model("fresnel", input.reflectivity.fresnel);
build_model.build_fake("grid", input.reflectivity.grid);
build_model.build_fake("fresnel", input.reflectivity.fresnel);
break;
case SurfacePhysicsOrder::interaction:
build_model("dielectric-dielectric",
input.interaction.dielectric_dielectric);
build_model("dielectric-metal",
input.interaction.dielectric_metal);
build_model.build_fake("dielectric-dielectric",
input.interaction.dielectric_dielectric);
build_model.build_fake("dielectric-metal",
input.interaction.dielectric_metal);
break;
default:
CELER_ASSERT_UNREACHABLE();
Expand Down
Loading
Loading