25#include "ElementsKernel/Exception.h"
29namespace GridContainer {
31template <
typename GridCellManager,
typename... AxesTypes>
38template <
typename GridCellManager,
typename... AxesTypes>
40 : m_axes{
std::move(axes_tuple)} {
46template <
typename GridCellManager,
typename... AxesTypes>
47template <
typename... Args>
50 : m_axes{
std::move(axes_tuple)} {
56template <
typename... AxesTypes>
64template <
typename GridCellManager,
typename... AxesTypes>
70template <
typename GridCellManager,
typename... AxesTypes>
72 size_t axis,
size_t index)
73 : m_axes{other.m_axes}
74 , m_axes_fixed{
fixAxis(other.m_axes, axis, index)}
75 , m_fixed_indices{other.m_fixed_indices}
76 , m_cell_manager{other.m_cell_manager} {
79 throw Elements::Exception() <<
"Axis " << axis <<
" is already fixed";
84template <
typename GridCellManager,
typename... AxesTypes>
91template <
typename GridCellManager,
typename... AxesTypes>
94 return std::get<I>(m_axes);
97template <
typename GridCellManager,
typename... AxesTypes>
99 return std::tuple_size<
decltype(m_axes_fixed)>::value;
102template <
typename GridCellManager,
typename... AxesTypes>
105 return std::get<I>(m_axes_fixed);
108template <
typename GridCellManager,
typename... AxesTypes>
113template <
typename GridCellManager,
typename... AxesTypes>
120template <
typename GridCellManager,
typename... AxesTypes>
127template <
typename GridCellManager,
typename... AxesTypes>
134template <
typename GridCellManager,
typename... AxesTypes>
139template <
typename GridCellManager,
typename... AxesTypes>
144template <
typename GridCellManager,
typename... AxesTypes>
149template <
typename GridCellManager,
typename... AxesTypes>
151 return m_index_helper_fixed.m_axes_index_factors.back();
154template <
typename GridCellManager,
typename... AxesTypes>
157 size_t total_index = m_index_helper.totalIndex(indices...);
159 for (
auto& pair : m_fixed_indices) {
160 total_index += pair.second * m_index_helper.m_axes_index_factors[pair.first];
162 return (*m_cell_manager)[total_index];
165template <
typename GridCellManager,
typename... AxesTypes>
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];
173 return (*m_cell_manager)[total_index];
176template <
typename GridCellManager,
typename... AxesTypes>
182template <
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];
192 return (*m_cell_manager)[total_index];
195template <std::
size_t I>
200 template <
typename... AxesType>
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();
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();
237template <
typename GridCellManager,
typename... AxesTypes>
243template <
typename GridCellManager,
typename... AxesTypes>
249template <
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() <<
")";
260template <
typename GridCellManager,
typename... AxesTypes>
264 return const_cast<GridContainer<GridCellManager, AxesTypes...
>*>(
this)->fixAxisByIndex<I>(index);
267template <
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());
279template <
typename GridCellManager,
typename... AxesTypes>
283 return const_cast<GridContainer<GridCellManager, AxesTypes...
>*>(
this)->fixAxisByValue<I>(value);
Provides information related with an axis of a GridContainer.
GridContainer construction helper class.
static void fixIteratorAxes(IterType &iter, std::map< size_t, size_t > fix_indices, const TemplateLoopCounter< I > &)
Class to iterate through the GridContainer cells.
Representation of a multi-dimensional grid which contains axis information.
const_iterator cend()
Returns a constant iterator to the cell after the last of the grid.
std::shared_ptr< GridCellManager > m_cell_manager
A pointer to the data of the grid.
GridContainer copy() const
But if needed be, allow explicit copies.
const GridAxis< axis_type< I > > & getOriginalAxis() const
GridContainer< GridCellManager, AxesTypes... > fixAxisByValue(const axis_type< I > &value)
Returns a slice of the grid based on an axis value.
std::tuple< GridAxis< AxesTypes >... > m_axes
A tuple containing the axes of the grid.
const reference_type operator()(decltype(std::declval< GridAxis< AxesTypes > >().size())... indices) const
const std::tuple< GridAxis< AxesTypes >... > & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.
const GridAxis< axis_type< I > > & getAxis() const
static constexpr size_t axisNumber()
Returns the number of axes of the grid (dimensionality)
std::tuple< decltype(std::declval< GridAxis< AxesTypes > >().size())... > infimum(const AxesTypes... coordinates) const
Returns the grid indexes to the greatest knot less or equal to the given coordinates.
iterator end()
Returns an iterator to the cell after the last of the grid.
size_t size() const
Returns the total number of cells of the grid.
decltype(ref_test< GridCellManagerTraits< GridCellManager > >(nullptr)) reference_type
typename std::tuple_element< I, std::tuple< AxesTypes... > >::type axis_type
const_iterator cbegin()
Returns a constant iterator to the first cell of the grid.
iterator begin()
Returns an iterator to the first cell of the grid.
const reference_type at(decltype(std::declval< GridAxis< AxesTypes > >().size())... indices) const
std::map< size_t, size_t > m_fixed_indices
A map containing the axes which have been fixed, if this grid is a slice.
GridContainer< GridCellManager, AxesTypes... > fixAxisByIndex(size_t index)
Returns a slice of the grid based on an axis index.
iter< cell_type const, pointer_type const, reference_type const > const_iterator
std::tuple< GridAxis< AxesTypes >... > fixAxis(const std::tuple< GridAxis< AxesTypes >... > &original, size_t axis, size_t index)
Class used by the GridContainer to access the different CellManagers.
static std::unique_ptr< GridCellManager > factory(size_t size)
static iterator end(GridCellManager &cell_manager)
static iterator begin(GridCellManager &cell_manager)
static void getIndex(const std::tuple< AxesType... > &coords, const std::tuple< GridAxis< AxesType >... > &axes, IndexTuple &index)
static std::tuple< std::size_t > getIndex(const std::tuple< AxesType... > &coords, const std::tuple< GridAxis< AxesType >... > &axes)
static void getIndex(const std::tuple< AxesType... > &coords, const std::tuple< GridAxis< AxesType >... > &axes, IndexTuple &index)
static std::tuple< Index< AxesType >... > getIndex(const std::tuple< AxesType... > &coords, const std::tuple< GridAxis< AxesType >... > &axes)