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>
87 return std::get<I>(m_axes);
90 template <
typename GridCellManager,
typename... AxesTypes>
92 return std::tuple_size<decltype(m_axes_fixed)>::value;
95 template <
typename GridCellManager,
typename... AxesTypes>
101 template <
typename GridCellManager,
typename... AxesTypes>
106 template <
typename GridCellManager,
typename... AxesTypes>
108 iterator result{*
this, GridCellManagerTraits<GridCellManager>::begin(*
m_cell_manager)};
109 GridConstructionHelper<AxesTypes...>::fixIteratorAxes(result,
m_fixed_indices, TemplateLoopCounter<0>{});
113 template <
typename GridCellManager,
typename... AxesTypes>
115 const_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 return iterator{*
this, GridCellManagerTraits<GridCellManager>::end(*
m_cell_manager)};
132 template <
typename GridCellManager,
typename... AxesTypes>
134 return const_iterator{*
this, GridCellManagerTraits<GridCellManager>::end(*
m_cell_manager)};
137 template <
typename GridCellManager,
typename... AxesTypes>
139 return const_iterator{*
this, GridCellManagerTraits<GridCellManager>::end(*
m_cell_manager)};
142 template <
typename GridCellManager,
typename... AxesTypes>
144 return m_index_helper_fixed.m_axes_index_factors.back();
147 template <
typename GridCellManager,
typename... AxesTypes>
149 decltype(
std::declval<GridAxis<AxesTypes>>().size())... indices) const -> const reference_type {
150 size_t total_index = m_index_helper.totalIndex(indices...);
153 total_index += pair.second * m_index_helper.m_axes_index_factors[pair.first];
158 template <
typename GridCellManager,
typename... AxesTypes>
160 decltype(
std::declval<GridAxis<AxesTypes>>().size())... indices) -> reference_type {
161 size_t total_index = m_index_helper.totalIndex(indices...);
163 for (
auto& pair : m_fixed_indices) {
164 total_index += pair.second * m_index_helper.m_axes_index_factors[pair.first];
169 template <
typename GridCellManager,
typename... AxesTypes>
171 decltype(
std::declval<GridAxis<AxesTypes>>().size())... indices) const -> const reference_type {
172 return const_cast<GridContainer*
>(
this)->at(indices...);
175 template <
typename GridCellManager,
typename... AxesTypes>
179 m_index_helper.checkAllFixedAreZero(m_fixed_indices, indices...);
180 size_t total_index = m_index_helper.totalIndexChecked(indices...);
182 for (
auto& pair : m_fixed_indices) {
183 total_index += pair.second * m_index_helper.m_axes_index_factors[pair.first];
188 template <std::
size_t I>
189 struct InfimumHelper {
193 template <
typename... AxesType>
195 const std::tuple<GridAxis<AxesType>...>& axes) {
197 getIndex(coords, axes, index);
201 template <
typename IndexTuple,
typename... AxesType>
204 auto& axn = std::get<I>(axes);
205 std::get<I>(index) = axn.infimum(std::get<I>(coords)) - axn.begin();
206 InfimumHelper<I - 1>::getIndex(coords, axes, index);
211 struct InfimumHelper<0> {
215 template <
typename... AxesType>
218 auto i0 = std::get<0>(axes).infimum(std::get<0>(coords));
222 template <
typename IndexTuple,
typename... AxesType>
225 auto& ax0 = std::get<0>(axes);
226 std::get<0>(index) = ax0.infimum(std::get<0>(coords)) - ax0.begin();
230 template <
typename GridCellManager,
typename... AxesTypes>
232 -> std::tuple<decltype(std::declval<
GridAxis<AxesTypes>>().size())...> {
236 template <
typename GridCellManager,
typename... AxesTypes>
239 return InfimumHelper<
sizeof...(AxesTypes) - 1>::getIndex(coords, m_axes);
242 template <
typename GridCellManager,
typename... AxesTypes>
246 if (index >= getOriginalAxis<I>().size()) {
247 throw Elements::Exception() <<
"Index (" << index <<
") out of axis " << getOriginalAxis<I>().name() <<
" size ("
248 << getOriginalAxis<I>().size() <<
")";
250 return GridContainer<GridCellManager, AxesTypes...>(*
this, I, index);
253 template <
typename GridCellManager,
typename... AxesTypes>
257 return const_cast<GridContainer<GridCellManager, AxesTypes...
>*>(
this)->fixAxisByIndex<I>(index);
260 template <
typename GridCellManager,
typename... AxesTypes>
264 auto& axis = getOriginalAxis<I>();
265 auto found_axis =
std::find(axis.begin(), axis.end(), value);
266 if (found_axis == axis.end()) {
267 throw Elements::Exception() <<
"Failed to fix axis " << getOriginalAxis<I>().name() <<
" (given value not found)";
269 return GridContainer<GridCellManager, AxesTypes...>(*
this, I, found_axis - axis.begin());
272 template <
typename GridCellManager,
typename... AxesTypes>
276 return const_cast<GridContainer<GridCellManager, AxesTypes...
>*>(
this)->fixAxisByValue<I>(value);
size_t size() const
Returns the total number of cells of the grid.
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.