-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abc3816
commit 13abbc5
Showing
10 changed files
with
265 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** Detray library, part of the ACTS project (R&D line) | ||
* | ||
* (c) 2022-2023 CERN for the benefit of the ACTS project | ||
* | ||
* Mozilla Public License Version 2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
// Project include(s). | ||
#include "detray/geometry/detector_volume.hpp" | ||
#include "detray/geometry/surface.hpp" | ||
#include "detray/tools/bin_association.hpp" | ||
#include "detray/tools/bin_fillers.hpp" | ||
#include "detray/tools/grid_factory.hpp" | ||
#include "detray/tools/surface_factory_interface.hpp" | ||
#include "detray/tools/volume_builder.hpp" | ||
#include "detray/tools/volume_builder_interface.hpp" | ||
|
||
// System include(s) | ||
#include <array> | ||
#include <cassert> | ||
#include <memory> | ||
#include <vector> | ||
|
||
namespace detray { | ||
|
||
/// @brief Build a grid of a certain shape. | ||
/// | ||
/// Decorator class to a volume builder that adds a grid as the volumes | ||
/// geometry accelerator structure. | ||
template <typename detector_t, | ||
typename bin_filler_t = detail::fill_by_pos> | ||
class material_map_builder final { | ||
|
||
public: | ||
using scalar_type = typename detector_t::scalar_type; | ||
using detector_type = detector_t; | ||
using value_type = typename detector_type::surface_type; | ||
|
||
struct bin_data { | ||
n_axis::multi_bin<2u> local_bin; | ||
material_slab<scalar_type> mat; | ||
}; | ||
|
||
// TODO: nullptr can lead to exceptions, remove in the full implementation | ||
DETRAY_HOST | ||
material_map_builder( | ||
std::unique_ptr<volume_builder_interface<detector_t>> vol_builder) | ||
: grid_builder_t(std::move(vol_builder)) {} | ||
|
||
/// Add the volume and the grid to the detector @param det | ||
DETRAY_HOST | ||
auto build(detector_t &det, typename detector_t::geometry_context ctx = {}) | ||
-> typename detector_t::volume_type * override { | ||
|
||
/// Build the material grid for every surface that has material | ||
for (auto& [idx, sf_desc] : detray::views::enumerate(this->surfaces())) { | ||
// Only map material to surfaces | ||
if (bin_data_per_surface.at(idx).empty()) { | ||
continue; | ||
} | ||
} | ||
// Add the grid to the detector and link it to its surface | ||
constexpr auto gid{detector_t::materials::template get_id<grid_t>()}; | ||
det.material_store().template push_back<gid>(m_grid); | ||
sf_desc.material() = | ||
{gid, det.material_store().template size<gid>() - 1}; | ||
|
||
// Call the underlying volume builder(s) and give the volume to the | ||
// next decorator | ||
return volume_decorator<detector_t>::build(det, ctx); | ||
} | ||
|
||
private: | ||
/// The surface this material map belongs to (index is volume local) | ||
std::map<dindex, std::vector<bin_data>> bin_data_per_surface; | ||
grid_factory<material_slab<scalar_type>, simple_serializer, replacer> m_factory{}; | ||
bin_filler_t m_bin_filler{}; | ||
}; | ||
|
||
} // namespace detray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** Detray library, part of the ACTS project (R&D line) | ||
* | ||
* (c) 2023 CERN for the benefit of the ACTS project | ||
* | ||
* Mozilla Public License Version 2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
// Project include(s) | ||
#include "detray/io/common/detail/grid_reader.hpp" | ||
#include "detray/io/common/io_interface.hpp" | ||
#include "detray/io/common/payloads.hpp" | ||
#include "detray/materials/material_slab.hpp" | ||
#include "detray/tools/detector_builder.hpp" | ||
#include "detray/tools/material_map_builder.hpp" | ||
|
||
// System include(s) | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
namespace detray { | ||
|
||
/// @brief Abstract base class for surface grid readers | ||
template <class detector_t, | ||
typename DIM = std::integral_constant<std::size_t, 2>> | ||
class material_map_reader : public detail::grid_reader<detector_t, material_slab<typename detector_t::surface_type>, material_map_builder, 1u, DIM> { | ||
|
||
using scalar_t = typename detector_t::surface_type; | ||
using grid_reader_t = detail::grid_reader<detector_t, material_slab<scalar_t>, material_map_builder, 1u, DIM>; | ||
using base_type = grid_reader_t; | ||
|
||
using material_reader_t = homogeneous_material_reader<detector_t>; | ||
|
||
protected: | ||
/// Tag the reader as "surface_grids" | ||
inline static const std::string tag = "material_maps"; | ||
|
||
public: | ||
/// Same constructors for this class as for base_type | ||
using base_type::base_type; | ||
|
||
protected: | ||
/// Deserialize the detector grids @param grids_data from their IO | ||
/// payload | ||
static void deserialize( | ||
detector_builder<typename detector_t::metadata, volume_builder> | ||
&det_builder, | ||
typename detector_t::name_map &, | ||
const detector_grids_payload<material_slab_payload> &grids_data) { | ||
|
||
// Go through the full grid deserialization once volume material is | ||
// added, until then, giving the explicit bounds and binnings should be | ||
// enough | ||
using regular_t = regular<host_container_types, scalar_t>; | ||
using bounds2D_ts = types::type_list<closed<0u>, closed<1u>>; | ||
using binning2D_ts = types::type_list<regular_t, regular_t>; | ||
|
||
for (const grid_payload<material_slab_payload>& g_data : grids_data) { | ||
// Start form finding the grid local frame and then build the grid | ||
if constexpr (DIM == 2) { | ||
grid_reader_t::deserialize<bounds2D_ts, binning2D_ts>(g_data, det_builder); | ||
} else if constexpr (DIM == 3) { | ||
using bounds3D_ts = types::push_back<bounds2D_ts, closed<2u>>; | ||
using binning3D_ts = types::push_back<binning2D_ts, regular_t>; | ||
|
||
grid_reader_t::deserialize<bounds3D_ts, binning3D_ts>(g_data, det_builder); | ||
} else { | ||
throw std::invalid_argument("No 1D material grid type defined in detray"); | ||
} | ||
} | ||
} | ||
|
||
}; | ||
|
||
} // namespace detray |
Oops, something went wrong.