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

Add optical model importer and refactor imported optical materials #1520

Merged
merged 37 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ce9a226
Optical imported materials, model importer, and model builders
Hollenbeck-Hayden Nov 19, 2024
7daf813
Added model importer tests
Hollenbeck-Hayden Nov 19, 2024
1e15ad7
Reverted ImportedModel to ImportedModelAdapter
Hollenbeck-Hayden Nov 20, 2024
46652b9
Moved ModelImporter tests to use mock data
Hollenbeck-Hayden Nov 20, 2024
690ff4e
Optical root import test
Hollenbeck-Hayden Nov 21, 2024
d2864bb
Refactored optical mock tests to use GlobalTestBase, and to split val…
Hollenbeck-Hayden Nov 25, 2024
6fb680c
Merge branch 'RefactorOpticalMockTests' into RefactorOpticalMaterials
Hollenbeck-Hayden Nov 25, 2024
748de85
Minor edits to make tests pass after merge
Hollenbeck-Hayden Nov 25, 2024
e92b026
Added documentation to ModelBuilder and simplified RayleighModel cons…
Hollenbeck-Hayden Nov 25, 2024
a99557e
Added documentation to check_physics_vector
Hollenbeck-Hayden Nov 25, 2024
4f59e9a
Added missing includes to ValidationUtils.hh
Hollenbeck-Hayden Nov 25, 2024
fa23286
Changed templated unit constructors in optical tests to not explicitl…
Hollenbeck-Hayden Nov 25, 2024
f4efe93
Merge branch 'develop' into RefactorOpticalMockTests
sethrj Nov 26, 2024
a2740b4
Merge branch 'develop' of github.com:celeritas-project/celeritas into…
Hollenbeck-Hayden Dec 2, 2024
ae27ce9
Added some of Seth's suggested changes
Hollenbeck-Hayden Dec 2, 2024
28befc2
Test of using googletest formatters for grids and tables
Hollenbeck-Hayden Dec 2, 2024
52b11c7
Merge branch 'RefactorOpticalMockTests' of git-kcr8wx:hhollenb/celeri…
Hollenbeck-Hayden Dec 2, 2024
7881481
Cleaned up changes to GridAccessor and formatting
Hollenbeck-Hayden Dec 3, 2024
86dd6c3
Removed dangling override of IsVecEq in ValidationUtils.cc
Hollenbeck-Hayden Dec 3, 2024
ea769bf
Fixed size_t vs size_type in native_array_from
Hollenbeck-Hayden Dec 3, 2024
512acc8
Changed native_array_from signature to avoid collisions
Hollenbeck-Hayden Dec 3, 2024
fa01b4e
Changed native_array_from_indexer to use integer sequence to support …
Hollenbeck-Hayden Dec 3, 2024
8aefd5c
Merge branch 'RefactorOpticalMockTests' into RefactorOpticalMaterials
Hollenbeck-Hayden Dec 3, 2024
5fb422a
Updated to match optical mock test refactoring
Hollenbeck-Hayden Dec 3, 2024
051214a
Fixed use after move error in RayleighModel
Hollenbeck-Hayden Dec 3, 2024
d3eeda2
Merge branch 'develop' of github.com:celeritas-project/celeritas into…
Hollenbeck-Hayden Dec 9, 2024
73d6d64
Merge remote-tracking branch 'upstream/develop' into RefactorOpticalM…
sethrj Jan 7, 2025
062a92a
Merge branch 'develop' of github.com:celeritas-project/celeritas into…
Hollenbeck-Hayden Jan 14, 2025
28aaa16
Added some of Seth's suggested fixes
Hollenbeck-Hayden Jan 15, 2025
603440f
Change ModelBuilder to a std::function
Hollenbeck-Hayden Jan 15, 2025
bf4d23c
Merge branch 'RefactorOpticalMaterials' of git-kcr8wx:hhollenb/celeri…
Hollenbeck-Hayden Jan 15, 2025
988b03c
Merge branch 'develop' of github.com:celeritas-project/celeritas into…
Hollenbeck-Hayden Jan 15, 2025
c6fd4b3
Try to fix the material view host/device ref issue
Hollenbeck-Hayden Jan 16, 2025
87841f8
corrected SPConst return types in ModelImporter
Hollenbeck-Hayden Jan 16, 2025
302c365
Updated ImportedMaterials documentation
Hollenbeck-Hayden Jan 22, 2025
21ac17c
Merge branch 'develop' of github.com:celeritas-project/celeritas into…
Hollenbeck-Hayden Jan 22, 2025
01087c3
Merge branch 'develop' into RefactorOpticalMaterials
sethrj Jan 23, 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
2 changes: 2 additions & 0 deletions src/celeritas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ list(APPEND SOURCES
optical/CoreState.cc
optical/CoreTrackData.cc
optical/ImportedModelAdapter.cc
optical/ImportedMaterials.cc
optical/OpticalCollector.cc
optical/MaterialParams.cc
optical/ModelImporter.cc
optical/TrackInitParams.cc
optical/ScintillationParams.cc
optical/WavelengthShiftParams.cc
Expand Down
100 changes: 100 additions & 0 deletions src/celeritas/optical/ImportedMaterials.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//------------------------------- -*- C++ -*- -------------------------------//
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/optical/ImportedMaterials.cc
//---------------------------------------------------------------------------//
#include "ImportedMaterials.hh"

#include <algorithm>

#include "celeritas/io/ImportData.hh"
#include "celeritas/io/ImportOpticalMaterial.hh"

namespace celeritas
{
namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Construct from imported and shared data.
*/
std::shared_ptr<ImportedMaterials>
ImportedMaterials::from_import(ImportData const& data)
{
// If there's no material specific parameters, return a nullptr
if (!std::any_of(data.optical_materials.begin(),
data.optical_materials.end(),
[](auto const& mat) { return mat.rayleigh || mat.wls; }))
{
return nullptr;
}

OpticalMaterialId::size_type num_materials = data.optical_materials.size();

// Copy over Rayleigh and WLS data

std::vector<ImportOpticalRayleigh> rayleigh;
rayleigh.reserve(num_materials);

std::vector<ImportWavelengthShift> wls;
wls.reserve(num_materials);

for (auto const& mat : data.optical_materials)
{
rayleigh.push_back(mat.rayleigh);
wls.push_back(mat.wls);
}

CELER_ENSURE(rayleigh.size() == num_materials);
CELER_ENSURE(wls.size() == num_materials);

return std::make_shared<ImportedMaterials>(std::move(rayleigh),
std::move(wls));
}

//---------------------------------------------------------------------------//
/*!
* Construct directly from imported material properties.
*/
ImportedMaterials::ImportedMaterials(std::vector<ImportOpticalRayleigh> rayleigh,
std::vector<ImportWavelengthShift> wls)
: rayleigh_(std::move(rayleigh)), wls_(std::move(wls))
{
CELER_EXPECT(!rayleigh_.empty());
CELER_EXPECT(rayleigh_.size() == wls_.size());
}

//---------------------------------------------------------------------------//
/*!
* Number of imported optical materials.
*/
OpticalMaterialId::size_type ImportedMaterials::num_materials() const
{
return rayleigh_.size();
}

//---------------------------------------------------------------------------//
/*!
* Get imported Rayleigh properties for the given material.
*/
ImportOpticalRayleigh const&
ImportedMaterials::rayleigh(OpticalMaterialId mat) const
{
CELER_EXPECT(mat < this->num_materials());
return rayleigh_[mat.get()];
}

//---------------------------------------------------------------------------//
/*!
* Get imported wavelength shifting properties for the given material.
*/
ImportWavelengthShift const& ImportedMaterials::wls(OpticalMaterialId mat) const
{
CELER_EXPECT(mat < this->num_materials());
return wls_[mat.get()];
}

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

#include <memory>
#include <vector>

#include "celeritas/Types.hh"

namespace celeritas
{
struct ImportData;
struct ImportOpticalRayleigh;
struct ImportWavelengthShift;

namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Imported material data for optical models.
*
* Stores material properties relevant for Rayleigh scattering and
* wavelength shifting. A lookup table for optical to core material IDs is
* also constructed, so models can quickly access core material properties.
sethrj marked this conversation as resolved.
Show resolved Hide resolved
*/
class ImportedMaterials
{
public:
// Construct from imported and shared data
static std::shared_ptr<ImportedMaterials> from_import(ImportData const&);

// Construct directly from imported materials
ImportedMaterials(std::vector<ImportOpticalRayleigh> rayleigh,
std::vector<ImportWavelengthShift> wls);
sethrj marked this conversation as resolved.
Show resolved Hide resolved

// Get number of imported optical materials
OpticalMaterialId::size_type num_materials() const;

// Get imported Rayleigh material parameters
ImportOpticalRayleigh const& rayleigh(OpticalMaterialId mat) const;

// Get imported wavelength shifting material parameters
ImportWavelengthShift const& wls(OpticalMaterialId mat) const;

private:
std::vector<ImportOpticalRayleigh> rayleigh_;
std::vector<ImportWavelengthShift> wls_;
};

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
4 changes: 3 additions & 1 deletion src/celeritas/optical/MaterialData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct MaterialParamsData

OpticalMaterialItems<GenericGridRecord> refractive_index;
VolumeItems<OpticalMaterialId> optical_id;
OpticalMaterialItems<CoreMaterialId> core_material_id;

// Backend data
Items<real_type> reals;
Expand All @@ -46,7 +47,7 @@ struct MaterialParamsData
explicit CELER_FUNCTION operator bool() const
{
return !refractive_index.empty() && !optical_id.empty()
&& !reals.empty();
&& !core_material_id.empty() && !reals.empty();
}

//! Assign from another set of data
Expand All @@ -56,6 +57,7 @@ struct MaterialParamsData
CELER_EXPECT(other);
refractive_index = other.refractive_index;
optical_id = other.optical_id;
core_material_id = other.core_material_id;
reals = other.reals;
return *this;
}
Expand Down
31 changes: 30 additions & 1 deletion src/celeritas/optical/MaterialParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,24 @@ MaterialParams::from_import(ImportData const& data,

CELER_VALIDATE(has_opt_mat,
<< "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<CoreMaterialId>(inp.properties.size(), CoreMaterialId{});
for (auto core_id : range(CoreMaterialId{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(), LogicalTrue{}));

return std::make_shared<MaterialParams>(std::move(inp));
}

Expand All @@ -85,6 +101,7 @@ MaterialParams::MaterialParams(Input const& inp)
{
CELER_EXPECT(!inp.properties.empty());
CELER_EXPECT(!inp.volume_to_mat.empty());
CELER_EXPECT(inp.optical_to_core.size() == inp.properties.size());

HostVal<MaterialParamsData> data;
CollectionBuilder refractive_index{&data.refractive_index};
Expand Down Expand Up @@ -127,10 +144,22 @@ MaterialParams::MaterialParams(Input const& inp)
CollectionBuilder{&data.optical_id}.insert_back(inp.volume_to_mat.begin(),
inp.volume_to_mat.end());

CollectionBuilder{&data.core_material_id}.insert_back(
inp.optical_to_core.begin(), inp.optical_to_core.end());

data_ = CollectionMirror<MaterialParamsData>{std::move(data)};
CELER_ENSURE(data_);
}

//---------------------------------------------------------------------------//
/*!
* Construct a material view for the given identifier.
*/
MaterialView MaterialParams::get(OpticalMaterialId mat) const
sethrj marked this conversation as resolved.
Show resolved Hide resolved
{
return MaterialView(this->host_ref(), mat);
}

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
6 changes: 6 additions & 0 deletions src/celeritas/optical/MaterialParams.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "celeritas/io/ImportOpticalMaterial.hh"

#include "MaterialData.hh"
#include "MaterialView.hh"

namespace celeritas
{
Expand Down Expand Up @@ -51,6 +52,8 @@ class MaterialParams final : public ParamsDataInterface<MaterialParamsData>
std::vector<ImportOpticalProperty> properties;
//! Map logical volume ID to optical material ID
std::vector<OpticalMaterialId> volume_to_mat;
//! Map optical material ID to core material ID
std::vector<CoreMaterialId> optical_to_core;
};

public:
Expand All @@ -66,6 +69,9 @@ class MaterialParams final : public ParamsDataInterface<MaterialParamsData>
// Number of optical materials
inline OpticalMaterialId::size_type num_materials() const;

// Construct a material view for the given identifier
MaterialView get(OpticalMaterialId mat) const;

//! Access optical material on the host
HostRef const& host_ref() const final { return data_.host_ref(); }

Expand Down
12 changes: 12 additions & 0 deletions src/celeritas/optical/MaterialView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class MaterialView
// ID of this optical material
CELER_FORCEINLINE_FUNCTION MaterialId material_id() const;

// ID of the associated core material
CELER_FORCEINLINE_FUNCTION CoreMaterialId core_material_id() const;

//// PARAMETER DATA ////

// Access energy-dependent refractive index
Expand Down Expand Up @@ -104,6 +107,15 @@ CELER_FUNCTION auto MaterialView::material_id() const -> MaterialId
return mat_id_;
}

//---------------------------------------------------------------------------//
/*!
* Get the id of the core material associated with this optical material.
*/
CELER_FUNCTION CoreMaterialId MaterialView::core_material_id() const
{
return params_.core_material_id[mat_id_];
}

//---------------------------------------------------------------------------//
/*!
* Access energy-dependent refractive index.
Expand Down
Loading
Loading