Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MDIndex.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* MDIndex.h (C) 2000-2024 */
9/* */
10/* Gestion des indices des tableaux multi-dimensionnels. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_MDINDEX_H
13#define ARCANE_UTILS_MDINDEX_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include <array>
20
21/*
22 * ATTENTION:
23 *
24 * Toutes les classes de ce fichier sont expérimentales et l'API n'est pas
25 * figée. A NE PAS UTILISER EN DEHORS DE ARCANE.
26 */
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
38template <int RankValue, typename IndexType_>
40{
41 protected:
42
43 // Note: on pourrait utiliser '= default' mais cela ne passe pas
44 // avec VS2017 car pour lui le constructeur n'est pas 'constexpr'
45 constexpr MDIndexBase() {}
46 constexpr MDIndexBase(std::array<Int32, RankValue> _id)
47 : m_indexes(_id)
48 {}
49
50 public:
51
53 constexpr std::array<Int32, RankValue> operator()() const { return m_indexes; }
54
56 constexpr ARCCORE_HOST_DEVICE Int32 operator[](int i) const
57 {
58 ARCCORE_CHECK_AT(i, RankValue);
59 return m_indexes[i];
60 }
62 constexpr ARCCORE_HOST_DEVICE Int64 asInt64(int i) const
63 {
64 ARCCORE_CHECK_AT(i, RankValue);
65 return m_indexes[i];
66 }
67
69 constexpr ARCCORE_HOST_DEVICE void add(const MDIndexBase<RankValue>& rhs)
70 {
71 for (int i = 0; i < RankValue; ++i)
72 m_indexes[i] += rhs[i];
73 }
74
75 protected:
76
77 std::array<Int32, RankValue> m_indexes = {};
78};
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83template <typename IndexType_>
85: public MDIndexBase<0, IndexType_>
86{
87 public:
88
89 MDIndex() = default;
90 ARCCORE_HOST_DEVICE constexpr MDIndex(std::array<Int32, 0> _id)
92 {}
93};
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98template <typename IndexType_>
100: public MDIndexBase<1, IndexType_>
101{
103 using BaseClass::m_indexes;
104
105 public:
106
107 MDIndex() = default;
108 ARCCORE_HOST_DEVICE constexpr MDIndex(Int32 _id0)
109 : BaseClass()
110 {
111 m_indexes[0] = _id0;
112 }
113 ARCCORE_HOST_DEVICE constexpr MDIndex(std::array<Int32, 1> _id)
114 : BaseClass(_id)
115 {}
116
117 public:
118
119 ARCCORE_HOST_DEVICE constexpr Int32 id0() const { return m_indexes[0]; }
120 ARCCORE_HOST_DEVICE constexpr Int64 largeId0() const { return m_indexes[0]; }
121};
122
123/*---------------------------------------------------------------------------*/
124/*---------------------------------------------------------------------------*/
125
126template <typename IndexType_>
128: public MDIndexBase<2, IndexType_>
129{
131 using BaseClass::m_indexes;
132
133 public:
134
135 MDIndex() = default;
136 ARCCORE_HOST_DEVICE constexpr MDIndex(Int32 _id0, Int32 _id1)
137 : BaseClass()
138 {
139 m_indexes[0] = _id0;
140 m_indexes[1] = _id1;
141 }
142 ARCCORE_HOST_DEVICE constexpr MDIndex(std::array<Int32, 2> _id)
143 : BaseClass(_id)
144 {}
145
146 public:
147
148 ARCCORE_HOST_DEVICE constexpr Int32 id0() const { return m_indexes[0]; }
149 ARCCORE_HOST_DEVICE constexpr Int32 id1() const { return m_indexes[1]; }
150 ARCCORE_HOST_DEVICE constexpr Int64 largeId0() const { return m_indexes[0]; }
151 ARCCORE_HOST_DEVICE constexpr Int64 largeId1() const { return m_indexes[1]; }
152};
153
154/*---------------------------------------------------------------------------*/
155/*---------------------------------------------------------------------------*/
156
157template <typename IndexType_>
159: public MDIndexBase<3, IndexType_>
160{
162 using BaseClass::m_indexes;
163
164 public:
165
166 MDIndex() = default;
167 ARCCORE_HOST_DEVICE constexpr MDIndex(Int32 _id0, Int32 _id1, Int32 _id2)
168 : BaseClass()
169 {
170 m_indexes[0] = _id0;
171 m_indexes[1] = _id1;
172 m_indexes[2] = _id2;
173 }
174 ARCCORE_HOST_DEVICE constexpr MDIndex(std::array<Int32, 3> _id)
175 : BaseClass(_id)
176 {}
177
178 public:
179
180 ARCCORE_HOST_DEVICE constexpr Int32 id0() const { return m_indexes[0]; }
181 ARCCORE_HOST_DEVICE constexpr Int32 id1() const { return m_indexes[1]; }
182 ARCCORE_HOST_DEVICE constexpr Int32 id2() const { return m_indexes[2]; }
183 ARCCORE_HOST_DEVICE constexpr Int64 largeId0() const { return m_indexes[0]; }
184 ARCCORE_HOST_DEVICE constexpr Int64 largeId1() const { return m_indexes[1]; }
185 ARCCORE_HOST_DEVICE constexpr Int64 largeId2() const { return m_indexes[2]; }
186};
187
188/*---------------------------------------------------------------------------*/
189/*---------------------------------------------------------------------------*/
190
191template <typename IndexType_>
193: public MDIndexBase<4, IndexType_>
194{
196 using BaseClass::m_indexes;
197
198 public:
199
200 MDIndex() = default;
201 ARCCORE_HOST_DEVICE constexpr MDIndex(Int32 _id0, Int32 _id1, Int32 _id2, Int32 _id3)
203 {
204 m_indexes[0] = _id0;
205 m_indexes[1] = _id1;
206 m_indexes[2] = _id2;
207 m_indexes[3] = _id3;
208 }
209 ARCCORE_HOST_DEVICE constexpr MDIndex(std::array<Int32, 4> _id)
211 {}
212
213 public:
214
215 ARCCORE_HOST_DEVICE constexpr Int32 id0() const { return m_indexes[0]; }
216 ARCCORE_HOST_DEVICE constexpr Int32 id1() const { return m_indexes[1]; }
217 ARCCORE_HOST_DEVICE constexpr Int32 id2() const { return m_indexes[2]; }
218 ARCCORE_HOST_DEVICE constexpr Int32 id3() const { return m_indexes[3]; }
219 ARCCORE_HOST_DEVICE constexpr Int64 largeId0() const { return m_indexes[0]; }
220 ARCCORE_HOST_DEVICE constexpr Int64 largeId1() const { return m_indexes[1]; }
221 ARCCORE_HOST_DEVICE constexpr Int64 largeId2() const { return m_indexes[2]; }
222 ARCCORE_HOST_DEVICE constexpr Int64 largeId3() const { return m_indexes[3]; }
223};
224
225/*---------------------------------------------------------------------------*/
226/*---------------------------------------------------------------------------*/
227
228} // namespace Arcane
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
233#endif
Déclarations des types utilisés dans Arcane.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Classe de base de la gestion des indices d'un tableau N-dimension.
Definition MDIndex.h:40
constexpr ARCCORE_HOST_DEVICE void add(const MDIndexBase< RankValue > &rhs)
Ajoute rhs aux valeurs des indices de l'instance.
Definition MDIndex.h:69
constexpr ARCCORE_HOST_DEVICE Int32 operator[](int i) const
Retourne le i-ème indice.
Definition MDIndex.h:56
constexpr ARCCORE_HOST_DEVICE Int64 asInt64(int i) const
Retourne le i-ème indice sous la forme d'un Int64.
Definition MDIndex.h:62
constexpr std::array< Int32, RankValue > operator()() const
Liste des indices.
Definition MDIndex.h:53
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-