19 #include <initializer_list>
29 const std::function<
size_t(std::array<size_t, 2> binsRZ,
30 std::array<size_t, 2> nBinsRZ)>&
31 materialVectorToGridMapper,
32 std::vector<double> rPos, std::vector<double> zPos,
36 detail::EquidistantAxis>> {
38 std::vector<Material::ParametersVector> materialVector;
39 materialVector.reserve(
material.size());
42 materialVector.push_back(mat.parameters());
50 rPos.erase(std::unique(rPos.begin(), rPos.end()), rPos.end());
51 zPos.erase(std::unique(zPos.begin(), zPos.end()), zPos.end());
55 size_t nBinsR = rPos.size();
56 size_t nBinsZ = zPos.size();
59 auto minMaxR = std::minmax_element(rPos.begin(), rPos.end());
60 auto minMaxZ = std::minmax_element(zPos.begin(), zPos.end());
61 double rMin = *minMaxR.first;
62 double zMin = *minMaxZ.first;
63 double rMax = *minMaxR.second;
64 double zMax = *minMaxZ.second;
67 double stepZ = std::fabs(zMax - zMin) / (nBinsZ - 1);
68 double stepR = std::fabs(rMax - rMin) / (nBinsR - 1);
73 detail::EquidistantAxis rAxis(rMin *
lengthUnit, rMax * lengthUnit, nBinsR);
74 detail::EquidistantAxis zAxis(zMin * lengthUnit, zMax * lengthUnit, nBinsZ);
84 std::array<size_t, 2> nIndices = {{rPos.size(), zPos.size()}};
85 Grid_t::index_t indices = {{
i,
j}};
89 grid.atLocalBins(indices) = materialVector.at(
90 materialVectorToGridMapper({{
i - 1,
j - 1}}, nIndices));
93 Material::ParametersVector
vec;
94 vec << std::numeric_limits<float>::max(), std::numeric_limits<float>::max(),
96 grid.setExteriorBins(vec);
108 detail::EquidistantAxis>>(transformPos,
std::move(grid));
112 const std::function<
size_t(std::array<size_t, 3> binsXYZ,
113 std::array<size_t, 3> nBinsXYZ)>&
114 materialVectorToGridMapper,
115 std::vector<double> xPos, std::vector<double> yPos,
116 std::vector<double> zPos,
const std::vector<Material>&
material,
122 std::vector<Material::ParametersVector> materialVector;
123 materialVector.reserve(
material.size());
126 materialVector.push_back(mat.parameters());
135 xPos.erase(std::unique(xPos.begin(), xPos.end()), xPos.end());
136 yPos.erase(std::unique(yPos.begin(), yPos.end()), yPos.end());
137 zPos.erase(std::unique(zPos.begin(), zPos.end()), zPos.end());
138 xPos.shrink_to_fit();
139 yPos.shrink_to_fit();
140 zPos.shrink_to_fit();
142 size_t nBinsX = xPos.size();
143 size_t nBinsY = yPos.size();
144 size_t nBinsZ = zPos.size();
147 auto minMaxX = std::minmax_element(xPos.begin(), xPos.end());
148 auto minMaxY = std::minmax_element(yPos.begin(), yPos.end());
149 auto minMaxZ = std::minmax_element(zPos.begin(), zPos.end());
152 double xMin = *minMaxX.first;
153 double yMin = *minMaxY.first;
154 double zMin = *minMaxZ.first;
156 double xMax = *minMaxX.second;
157 double yMax = *minMaxY.second;
158 double zMax = *minMaxZ.second;
161 double stepZ = std::fabs(zMax - zMin) / (nBinsZ - 1);
162 double stepY = std::fabs(yMax - yMin) / (nBinsY - 1);
163 double stepX = std::fabs(xMax - xMin) / (nBinsX - 1);
168 detail::EquidistantAxis xAxis(xMin *
lengthUnit, xMax * lengthUnit, nBinsX);
169 detail::EquidistantAxis yAxis(yMin * lengthUnit, yMax * lengthUnit, nBinsY);
170 detail::EquidistantAxis zAxis(zMin * lengthUnit, zMax * lengthUnit, nBinsZ);
179 for (
size_t i = 1;
i <= nBinsX; ++
i) {
180 for (
size_t j = 1;
j <= nBinsY; ++
j) {
182 Grid_t::index_t indices = {{
i,
j,
k}};
183 std::array<size_t, 3> nIndices = {
184 {xPos.size(), yPos.size(), zPos.size()}};
188 grid.atLocalBins(indices) = materialVector.at(
189 materialVectorToGridMapper({{
i - 1,
j - 1,
k - 1}}, nIndices));
193 Material::ParametersVector
vec;
194 vec << std::numeric_limits<float>::max(), std::numeric_limits<float>::max(),
196 grid.setExteriorBins(vec);