29 namespace GridContainer {
31 template <
typename GridCellManager,
typename... AxesTypes>
38 template <
typename GridCellManager,
typename... AxesTypes>
46 template <
typename GridCellManager,
typename... AxesTypes>
47 template <
typename... Args>
53 std::forward<Args>(args)...);
56 template <
typename... AxesTypes>
64 template <
typename GridCellManager,
typename... AxesTypes>
70 template <
typename GridCellManager,
typename... AxesTypes>
72 size_t axis,
size_t index)
73 : m_axes{other.m_axes}
84 template <
typename GridCellManager,
typename... AxesTypes>
86 GridContainer clone{m_axes};
91 template <
typename GridCellManager,
typename... AxesTypes>
94 return std::get<I>(m_axes);
97 template <
typename GridCellManager,
typename... AxesTypes>
99 return std::tuple_size<decltype(m_axes_fixed)>::value;
102 template <
typename GridCellManager,
typename... AxesTypes>
108 template <
typename GridCellManager,
typename... AxesTypes>
113 template <
typename GridCellManager,
typename... AxesTypes>
115 iterator result{*
this, GridCellManagerTraits<GridCellManager>::begin(*
m_cell_manager)};
116 GridConstructionHelper<AxesTypes...>::fixIteratorAxes(result,
m_fixed_indices, TemplateLoopCounter<0>{});
120 template <
typename GridCellManager,
typename... AxesTypes>
122 const_iterator result{*
this, GridCellManagerTraits<GridCellManager>::begin(*
m_cell_manager)};
123 GridConstructionHelper<AxesTypes...>::fixIteratorAxes(result,
m_fixed_indices, TemplateLoopCounter<0>{});
127 template <
typename GridCellManager,
typename... AxesTypes>
129 const_iterator result{*
this, GridCellManagerTraits<GridCellManager>::begin(*
m_cell_manager)};
130 GridConstructionHelper<AxesTypes...>::fixIteratorAxes(result,
m_fixed_indices, TemplateLoopCounter<0>{});
134 template <
typename GridCellManager,
typename... AxesTypes>
136 return iterator{*
this, GridCellManagerTraits<GridCellManager>::end(*
m_cell_manager)};
139 template <
typename GridCellManager,
typename... AxesTypes>
141 return const_iterator{*
this, GridCellManagerTraits<GridCellManager>::end(*
m_cell_manager)};
144 template <
typename GridCellManager,
typename... AxesTypes>
146 return const_iterator{*
this, GridCellManagerTraits<GridCellManager>::end(*
m_cell_manager)};
149 template <
typename GridCellManager,
typename... AxesTypes>
151 return m_index_helper_fixed.m_axes_index_factors.back();
154 template <
typename GridCellManager,
typename... AxesTypes>
156 decltype(
std::declval<GridAxis<AxesTypes>>().size())... indices) const -> const reference_type {
157 size_t total_index = m_index_helper.totalIndex(indices...);
160 total_index += pair.second * m_index_helper.m_axes_index_factors[pair.first];
165 template <
typename GridCellManager,
typename... AxesTypes>
167 decltype(
std::declval<GridAxis<AxesTypes>>().size())... indices) -> reference_type {
168 size_t total_index = m_index_helper.totalIndex(indices...);
170 for (
auto& pair : m_fixed_indices) {
171 total_index += pair.second * m_index_helper.m_axes_index_factors[pair.first];
176 template <
typename GridCellManager,
typename... AxesTypes>
178 decltype(
std::declval<GridAxis<AxesTypes>>().size())... indices) const -> const reference_type {
179 return const_cast<GridContainer*
>(
this)->at(indices...);
182 template <
typename GridCellManager,
typename... AxesTypes>
186 m_index_helper.checkAllFixedAreZero(m_fixed_indices, indices...);
187 size_t total_index = m_index_helper.totalIndexChecked(indices...);
189 for (
auto& pair : m_fixed_indices) {
190 total_index += pair.second * m_index_helper.m_axes_index_factors[pair.first];
195 template <std::
size_t I>
196 struct InfimumHelper {
200 template <
typename... AxesType>
202 const std::tuple<GridAxis<AxesType>...>& axes) {
204 getIndex(coords, axes, index);
208 template <
typename IndexTuple,
typename... AxesType>
211 auto& axn = std::get<I>(axes);
212 std::get<I>(index) = axn.infimum(std::get<I>(coords)) - axn.begin();
213 InfimumHelper<I - 1>::getIndex(coords, axes, index);
218 struct InfimumHelper<0> {
222 template <
typename... AxesType>
225 auto i0 = std::get<0>(axes).infimum(std::get<0>(coords));
229 template <
typename IndexTuple,
typename... AxesType>
232 auto& ax0 = std::get<0>(axes);
233 std::get<0>(index) = ax0.infimum(std::get<0>(coords)) - ax0.begin();
237 template <
typename GridCellManager,
typename... AxesTypes>
239 -> std::tuple<decltype(std::declval<
GridAxis<AxesTypes>>().size())...> {
243 template <
typename GridCellManager,
typename... AxesTypes>
246 return InfimumHelper<
sizeof...(AxesTypes) - 1>::getIndex(coords, m_axes);
249 template <
typename GridCellManager,
typename... AxesTypes>
253 if (index >= getOriginalAxis<I>().size()) {
254 throw Elements::Exception() <<
"Index (" << index <<
") out of axis " << getOriginalAxis<I>().name() <<
" size ("
255 << getOriginalAxis<I>().size() <<
")";
257 return GridContainer<GridCellManager, AxesTypes...>(*
this, I, index);
260 template <
typename GridCellManager,
typename... AxesTypes>
264 return const_cast<GridContainer<GridCellManager, AxesTypes...
>*>(
this)->fixAxisByIndex<I>(index);
267 template <
typename GridCellManager,
typename... AxesTypes>
271 auto& axis = getOriginalAxis<I>();
272 auto found_axis =
std::find(axis.begin(), axis.end(), value);
273 if (found_axis == axis.end()) {
274 throw Elements::Exception() <<
"Failed to fix axis " << getOriginalAxis<I>().name() <<
" (given value not found)";
276 return GridContainer<GridCellManager, AxesTypes...>(*
this, I, found_axis - axis.begin());
279 template <
typename GridCellManager,
typename... AxesTypes>
283 return const_cast<GridContainer<GridCellManager, AxesTypes...
>*>(
this)->fixAxisByValue<I>(value);
size_t size() const
Returns the total number of cells of the grid.
GridContainer copy() const
But if needed be, allow explicit copies.
std::tuple< GridAxis< AxesTypes >...> m_axes
A tuple containing the axes of the grid.
static void getIndex(const std::tuple< AxesType...> &coords, const std::tuple< GridAxis< AxesType >...> &axes, IndexTuple &index)
const reference_type at(decltype(std::declval< GridAxis< AxesTypes >>().size())...indices) const
const GridAxis< axis_type< I > > & getAxis() const
const_iterator cbegin()
Returns a constant iterator to the first cell of the grid.
const_iterator cend()
Returns a constant iterator to the cell after the last of the grid.
Representation of a multi-dimensional grid which contains axis information.
const GridAxis< axis_type< I > > & getOriginalAxis() const
const reference_type operator()(decltype(std::declval< GridAxis< AxesTypes >>().size())...indices) const
static std::unique_ptr< GridCellManager > factory(size_t size)
Provides information related with an axis of a GridContainer.
GridContainer construction helper class.
typename std::tuple_element< I, std::tuple< AxesTypes...>>::type axis_type
static constexpr size_t axisNumber()
Returns the number of axes of the grid (dimensionality)
iterator end()
Returns an iterator to the cell after the last of the grid.
iterator begin()
Returns an iterator to the first cell of the grid.
static std::tuple< std::size_t > getIndex(const std::tuple< AxesType...> &coords, const std::tuple< GridAxis< AxesType >...> &axes)
std::tuple< GridAxis< AxesTypes >...> fixAxis(const std::tuple< GridAxis< AxesTypes >...> &original, size_t axis, size_t index)
const std::tuple< GridAxis< AxesTypes >...> & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.