12#ifndef ARCANE_CARTESIANMESH_CARTESIANNUMBERING_H
13#define ARCANE_CARTESIANMESH_CARTESIANNUMBERING_H
17#include "arcane/cartesianmesh/CartesianMeshGlobal.h"
18#include "arcane/cartesianmesh/v2/CartesianTypes.h"
23namespace Arcane::CartesianMesh::V2
44template <
typename IdType>
45class CartesianNumbering
54 CartesianNumbering() {}
58 m_dimension = rhs.m_dimension;
59 for (
Integer d(0); d < 3; ++d) {
60 m_nitems_dir[d] = rhs.m_nitems_dir[d];
63 m_nitems = rhs.m_nitems;
64 m_first_item_id = rhs.m_first_item_id;
71 m_first_item_id = first_item_id;
73 for (
Integer d(0); d < m_dimension; ++d) {
74 m_nitems_dir[d] = nitems_dir[d];
75 m_nitems *= m_nitems_dir[d];
78 for (
Integer d(m_dimension); d < 3; ++d) {
86 for (
Integer d(1); d < m_dimension; ++d) {
107 return m_nitems_dir[dir];
119 return m_first_item_id;
137 ARCCORE_HOST_DEVICE
inline IdType
id(IdType i, IdType j, IdType k)
const
142 if (m_dimension < 3) {
143 item_id = m_first_item_id + i + j *
m_coef[1];
146 item_id = m_first_item_id + i + j *
m_coef[1] + k *
m_coef[2];
154 return id(item_ijk[0], item_ijk[1], item_ijk[2]);
159 ARCCORE_HOST_DEVICE
inline IdType
id(IdxType idx)
const
161 return id(
static_cast<IdType
>(idx[0]),
static_cast<IdType
>(idx[1]),
static_cast<IdType
>(idx[2]));
167 item_id -= m_first_item_id;
169 if (m_dimension < 3) {
171 item_ijk[1] = item_id /
m_coef[1];
172 item_ijk[0] = item_id %
m_coef[1];
175 item_ijk[2] = item_id /
m_coef[2];
176 IdType tmp = item_id %
m_coef[2];
177 item_ijk[1] = tmp /
m_coef[1];
178 item_ijk[0] = tmp %
m_coef[1];
183 ARCCORE_HOST_DEVICE IdxType
ijk(IdType item_id)
const
185 item_id -= m_first_item_id;
188 if (m_dimension < 3) {
195 IdType tmp = item_id %
m_coef[2];
206 return (item_id - m_first_item_id) %
m_coef[1];
212 return (m_dimension == 3 ? ((item_id - m_first_item_id) %
m_coef[2] /
m_coef[1]) : (item_id - m_first_item_id) /
m_coef[1]);
218 return (item_id - m_first_item_id) /
m_coef[2];
225 IdType3 m_nitems_dir = { 1, 1, 1 };
228 IdType m_first_item_id = 0;
Handling of a Cartesian numbering on a grid of items of up to 3 dimensions Allows conversion from a t...
IdType deltaDir(Integer dir) const
Offset to add to id() to get the ID of the next item in direction dir (if this item exists).
__host__ __device__ IdType id(IdType i, IdType j, IdType k) const
Conversion (i,j,k) => number.
void ijk(IdType item_id, IdType3 &item_ijk) const
Conversion number => (i,j,k).
__host__ __device__ IdxType ijk(IdType item_id) const
Conversion number => (i,j,k).
__host__ __device__ IdType id(IdxType idx) const
Conversion (i,j,k) => number.
IdType idxDir0(IdType item_id) const
Conversion number => i.
IdType3 m_coef
item_id = m_first_item_id + CartesianNumbering(i,j,k), allows an offset in the numbering
const IdType3 & nbItem3() const
Triplet of the number of items in each direction (grid definition).
IdType idxDir1(IdType item_id) const
Conversion number => j.
IdType[3] IdType3
Type for Cartesian triplets (i,j,k) and dimension triplets (ni,nj,nk).
IdType idxDir2(IdType item_id) const
Conversion number => k.
IdType id(const IdType3 &item_ijk) const
Conversion (i,j,k) => number.
Integer dimension() const
Dimension of the Cartesian grid on which the numbering is based.
IdType nbItem() const
Total number of items in the Cartesian grid (product of the number of items in each direction).
IdType nbItemDir(Integer dir) const
Number of items in the Cartesian grid according to direction dir (< dimension()).
const IdType3 & delta3() const
Triplet of offsets in all directions to move to the next items in each direction.
IdType firstId() const
Smallest identifier of the Cartesian numbering of the grid.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.