File indexing completed on 2025-04-05 07:57:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Material/GridSurfaceMaterial.hpp"
0012 #include "Acts/Material/MaterialSlab.hpp"
0013 #include "Acts/Utilities/GridAccessHelpers.hpp"
0014 #include "Acts/Utilities/ProtoAxis.hpp"
0015
0016 #include <memory>
0017 #include <vector>
0018
0019 namespace Acts::GridSurfaceMaterialFactory {
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 template <typename material_accessor_t>
0031 std::unique_ptr<
0032 IGridSurfaceMaterial<typename material_accessor_t::grid_value_type>>
0033 create1D(
0034 const ProtoAxis& pAxis, material_accessor_t&& materialAccessor,
0035 GridAccess::BoundToGridLocal1DimDelegate boundToGridLocal,
0036 GridAccess::GlobalToGridLocal1DimDelegate globalToGridLocal,
0037 const std::vector<typename material_accessor_t::grid_value_type>& payload) {
0038
0039 auto ism = pAxis.getAxis().visit(
0040 [&]<typename AxisType>(const AxisType& axis)
0041 -> std::unique_ptr<IGridSurfaceMaterial<
0042 typename material_accessor_t::grid_value_type>> {
0043 using GridType =
0044 Grid<typename material_accessor_t::grid_value_type, AxisType>;
0045 return std::make_unique<
0046 GridSurfaceMaterialT<GridType, material_accessor_t>>(
0047 GridType(axis), std::forward<material_accessor_t>(materialAccessor),
0048 std::move(boundToGridLocal), std::move(globalToGridLocal));
0049 });
0050
0051 AnyGridView<typename material_accessor_t::grid_value_type> gv =
0052 ism->gridView();
0053 auto indices = gv.numLocalBins();
0054 for (std::size_t i0 = 0; i0 < indices[0]; ++i0) {
0055
0056 gv.atLocalBins({i0 + 1u}) = payload[i0];
0057 }
0058 return ism;
0059 }
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 template <typename material_accessor_t>
0073 std::unique_ptr<
0074 IGridSurfaceMaterial<typename material_accessor_t::grid_value_type>>
0075 create2D(
0076 const ProtoAxis& pAxis0, const ProtoAxis& pAxis1,
0077 material_accessor_t&& materialAccessor,
0078 GridAccess::BoundToGridLocal2DimDelegate boundToGridLocal,
0079 GridAccess::GlobalToGridLocal2DimDelegate globalToGridLocal,
0080 const std::vector<
0081 std::vector<typename material_accessor_t::grid_value_type>>& payload) {
0082
0083 if (pAxis0.getAxisDirection() == pAxis1.getAxisDirection()) {
0084 throw std::invalid_argument(
0085 "createGridSurfaceMaterial: ProtoAxes must have different directions");
0086 }
0087 auto ism = pAxis0.getAxis().visit(
0088 [&]<typename AxisTypeA>(const AxisTypeA& axisA)
0089 -> std::unique_ptr<IGridSurfaceMaterial<
0090 typename material_accessor_t::grid_value_type>> {
0091 return pAxis1.getAxis().visit(
0092 [&]<typename AxisTypeB>(const AxisTypeB& axisB)
0093 -> std::unique_ptr<IGridSurfaceMaterial<
0094 typename material_accessor_t::grid_value_type>> {
0095 using GridType =
0096 Grid<typename material_accessor_t::grid_value_type, AxisTypeA,
0097 AxisTypeB>;
0098 return std::make_unique<
0099 GridSurfaceMaterialT<GridType, material_accessor_t>>(
0100 GridType(axisA, axisB),
0101 std::forward<material_accessor_t>(materialAccessor),
0102 std::move(boundToGridLocal), std::move(globalToGridLocal));
0103 });
0104 });
0105
0106
0107 AnyGridView<typename material_accessor_t::grid_value_type> gv =
0108 ism->gridView();
0109 auto indices = gv.numLocalBins();
0110 for (std::size_t i0 = 0; i0 < indices[0]; ++i0) {
0111 for (std::size_t i1 = 0; i1 < indices[1]; ++i1) {
0112
0113 gv.atLocalBins({i0 + 1, i1 + 1}) = payload[i0][i1];
0114 }
0115 }
0116
0117 return ism;
0118 }
0119
0120
0121
0122
0123
0124
0125
0126
0127 std::unique_ptr<IGridSurfaceMaterial<MaterialSlab>> create(
0128 const ProtoAxis& pAxis, GridMaterialAccessor&& materialAccessor,
0129 GridAccess::BoundToGridLocal1DimDelegate boundToGridLocal,
0130 GridAccess::GlobalToGridLocal1DimDelegate globalToGridLocal,
0131 const std::vector<MaterialSlab>& payload);
0132
0133
0134
0135
0136
0137
0138
0139
0140 std::unique_ptr<IGridSurfaceMaterial<IndexedMaterialAccessor::grid_value_type>>
0141 create(const ProtoAxis& pAxis, IndexedMaterialAccessor&& materialAccessor,
0142 GridAccess::BoundToGridLocal1DimDelegate boundToGridLocal,
0143 GridAccess::GlobalToGridLocal1DimDelegate globalToGridLocal,
0144 const std::vector<IndexedMaterialAccessor::grid_value_type>& payload);
0145
0146
0147
0148
0149
0150
0151
0152
0153 std::unique_ptr<
0154 IGridSurfaceMaterial<GloballyIndexedMaterialAccessor::grid_value_type>>
0155 create(const ProtoAxis& pAxis,
0156 GloballyIndexedMaterialAccessor&& materialAccessor,
0157 GridAccess::BoundToGridLocal1DimDelegate boundToGridLocal,
0158 GridAccess::GlobalToGridLocal1DimDelegate globalToGridLocal,
0159 const std::vector<GloballyIndexedMaterialAccessor::grid_value_type>&
0160 payload);
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 std::unique_ptr<IGridSurfaceMaterial<MaterialSlab>> create(
0171 const ProtoAxis& pAxis0, const ProtoAxis& pAxis1,
0172 GridMaterialAccessor&& materialAccessor,
0173 GridAccess::BoundToGridLocal2DimDelegate boundToGridLocal,
0174 GridAccess::GlobalToGridLocal2DimDelegate globalToGridLocal,
0175 const std::vector<std::vector<MaterialSlab>>& payload);
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185 std::unique_ptr<IGridSurfaceMaterial<IndexedMaterialAccessor::grid_value_type>>
0186 create(const ProtoAxis& pAxis0, const ProtoAxis& pAxis1,
0187 IndexedMaterialAccessor&& materialAccessor,
0188 GridAccess::BoundToGridLocal2DimDelegate boundToGridLocal,
0189 GridAccess::GlobalToGridLocal2DimDelegate globalToGridLocal,
0190 const std::vector<std::vector<IndexedMaterialAccessor::grid_value_type>>&
0191 payload);
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 std::unique_ptr<
0202 IGridSurfaceMaterial<GloballyIndexedMaterialAccessor::grid_value_type>>
0203 create(const ProtoAxis& pAxis0, const ProtoAxis& pAxis1,
0204 GloballyIndexedMaterialAccessor&& materialAccessor,
0205 GridAccess::BoundToGridLocal2DimDelegate boundToGridLocal,
0206 GridAccess::GlobalToGridLocal2DimDelegate globalToGridLocal,
0207 const std::vector<
0208 std::vector<GloballyIndexedMaterialAccessor::grid_value_type>>&
0209 payload);
0210 }