12#include "detray/builders/homogeneous_material_factory.hpp"
13#include "detray/builders/surface_factory.hpp"
14#include "detray/definitions/indexing.hpp"
15#include "detray/geometry/shapes/unmasked.hpp"
16#include "detray/material/material.hpp"
17#include "detray/utils/logging.hpp"
18#include "detray/utils/ranges.hpp"
38template <concepts::detector detector_t,
typename index_t = dindex>
40 using mask_id =
typename detector_t::masks::id;
41 using material_id =
typename detector_t::material::id;
42 using index_type = index_t;
53 using base_factory::operator();
61 std::make_unique<placeholder_factory_t>())
62 : base_factory(std::move(sf_factory)) {}
68 const dindex n_surfaces{
static_cast<dindex>(m_links.size())};
71 assert(m_n_bins.size() == n_surfaces);
72 assert(m_axis_spans.size() == n_surfaces);
73 assert(m_materials.size() == n_surfaces);
74 assert(m_thickness.size() == n_surfaces);
82 std::map<std::
size_t, std::
pair<material_id, std::vector<index_type>>> & {
96 -> const std::map<std::
size_t, std::vector<
scalar_type>> & {
109 std::vector<std::size_t> &&n_bins,
110 std::vector<std::vector<scalar_type>> &&axis_spans,
111 std::vector<index_type> &&indices) {
112 DETRAY_VERBOSE_HOST(
"Received material map data");
114 auto [sf_index, mat,
thickness] = std::move(mat_data).get_data();
116 assert(!detail::is_invalid_value(sf_index));
118 m_links.emplace(sf_index, std::make_pair(
id, std::move(indices)));
119 m_n_bins.emplace(sf_index, std::move(n_bins));
120 m_axis_spans.emplace(sf_index, std::move(axis_spans));
121 m_materials.emplace(sf_index, std::move(mat));
122 m_thickness.emplace(sf_index, std::move(
thickness));
130 m_axis_spans.clear();
151 template <
typename bin_data_t, std::
size_t N>
153 typename detector_t::surface_lookup_container &surfaces,
156 std::map<
dindex,
darray<std::vector<scalar_type>, N>> &axis_spans) {
157 DETRAY_VERBOSE_HOST(
"Add material maps...");
159 using link_t =
typename detector_t::surface_type::material_link;
163 if (n_materials == 0) {
169 DETRAY_VERBOSE_HOST(
"-> Have " << m_materials.size()
170 <<
" configured material map(s) to assign");
173 for (
auto &[i,
materials] : m_materials) {
174 const auto sf_idx{
static_cast<dindex>(i)};
176 DETRAY_DEBUG_HOST(
"--> #" << sf_idx <<
" sf = " << surfaces.at(sf_idx));
179 assert(m_n_bins.at(sf_idx).size() == N);
181 std::ranges::copy_n(m_n_bins.at(sf_idx).begin(), N,
182 n_bins.at(sf_idx).begin());
185 axis_spans.emplace(sf_idx,
darray<std::vector<scalar_type>, N>{});
186 for (std::size_t in = 0; in < N; ++in) {
187 if (m_axis_spans.at(sf_idx).size() > in) {
188 axis_spans.at(sf_idx).at(in) = m_axis_spans.at(sf_idx).at(in);
195 auto &loc_bin_idx{m_links.at(sf_idx).second.at(j)};
198 bin_data_t data{loc_bin_idx, mat_slab};
202 material_map.emplace(sf_idx, std::vector<bin_data_t>{data});
204 search->second.push_back(data);
208 auto map_id{m_links.at(sf_idx).first};
209 DETRAY_DEBUG_HOST(
"--> Set surface material id: " << map_id);
213 DETRAY_DEBUG_HOST(
"Finished");
218 std::map<std::size_t, std::pair<material_id, std::vector<index_type>>>
221 std::map<std::size_t, std::vector<std::size_t>> m_n_bins{};
223 std::map<std::size_t, std::vector<std::vector<scalar_type>>> m_axis_spans{};
225 std::map<std::size_t, std::vector<scalar_type>> m_thickness{};
228 std::map<std::size_t, std::vector<material<scalar_type>>> m_materials{};
factory_decorator(std::unique_ptr< surface_factory_interface< detector_t > > factory)
Wrap a concrete surface factory and forward interface calls to it.
Definition surface_factory_interface.hpp:203
Bind components for material together.
Definition homogeneous_material_factory.hpp:35
auto operator()(typename detector_t::surface_lookup_container &surfaces, std::map< dindex, std::vector< bin_data_t > > &material_map, std::map< dindex, darray< std::size_t, N > > &n_bins, std::map< dindex, darray< std::vector< scalar_type >, N > > &axis_spans)
Add data for material maps to the containers of a volume builder.
Definition material_map_factory.hpp:152
auto links() const -> const std::map< std::size_t, std::pair< material_id, std::vector< index_type > > > &
Definition material_map_factory.hpp:81
auto n_materials() const -> dindex
Definition material_map_factory.hpp:67
auto materials() const -> const std::map< std::size_t, std::vector< material< scalar_type > > > &
Definition material_map_factory.hpp:88
dscalar< typename detector_t::algebra_type > scalar_type
Scalar type used by material map values.
Definition material_map_factory.hpp:49
material_map_factory(std::unique_ptr< surface_factory_interface< detector_t > > sf_factory=std::make_unique< placeholder_factory_t >())
Factory with surfaces potentially already filled or empty placeholder that will not be used.
Definition material_map_factory.hpp:59
material_data< scalar_type > data_type
Material data type consumed by this factory.
Definition material_map_factory.hpp:51
auto thickness() const -> const std::map< std::size_t, std::vector< scalar_type > > &
Definition material_map_factory.hpp:95
auto clear() -> void override
Clear old data.
Definition material_map_factory.hpp:127
void add_material(material_id id, data_type &&mat_data, std::vector< std::size_t > &&n_bins, std::vector< std::vector< scalar_type > > &&axis_spans, std::vector< index_type > &&indices)
Add all necessary components to the factory for a material map.
Definition material_map_factory.hpp:108
How to generate surfaces with their corresponding masks and transforms.
Definition surface_factory_interface.hpp:120
Generates a number of surfaces for a volume (can be portals, passives or sensitives) and fills them i...
Definition surface_factory.hpp:43
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
grid< algebra_t, axes< shape_t >, bins::single< material_slab< dscalar< algebra_t > > >, simple_serializer, container_t, owning > material_map
Definition of binned material.
Definition material_map.hpp:29
unsigned int dindex
Default index type.
Definition indexing.hpp:18
constexpr dindex dindex_invalid
Global invalid index definition.
Definition indexing.hpp:21
std::array< value_t, kDIM > darray
Fixed-size array container.
Definition containers.hpp:30
tuple< T1, T2 > pair
A two-element tuple alias.
Definition tuple.hpp:145
Slab structure to be mapped on the mask (plane, cylinder).
Definition material_slab.hpp:25
Material composition properties and density data used by interactions.
Definition material.hpp:36
Range adaptor that creates an enumerate view, optionally starting at a selected index.
Definition enumerate.hpp:266