Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
CartesianGridDimension.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* CartesianMeshDimension.h (C) 2000-2023 */
9/* */
10/* Information about the dimensions of a Cartesian grid. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_CARTESIANGRIDDIMENSION_H
13#define ARCANE_CORE_CARTESIANGRIDDIMENSION_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Vector3.h"
18#include "arcane/utils/Vector2.h"
19
21
22#include <array>
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30// Temporary for friend classes
31namespace mesh
32{
36} // namespace mesh
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
48class ARCANE_CORE_EXPORT CartesianGridDimension
49{
53 friend class CartesianMeshUniqueIdRenumbering;
54 friend class CartesianMeshCoarsening;
55 friend class CartesianMeshCoarsening2;
56
57 private:
58
63 class NodeUniqueIdComputer2D
64 {
65 public:
66
67 NodeUniqueIdComputer2D(Int64 base_offset, Int64 nb_node_x)
68 : m_base_offset(base_offset)
69 , m_nb_node_x(nb_node_x)
70 {}
71
72 public:
73
74 Int64 compute(Int64 x, Int64 y)
75 {
76 return m_base_offset + x + y * m_nb_node_x;
77 }
78
79 std::array<Int64, 4> computeForCell(Int64 x, Int64 y)
80 {
81 std::array<Int64, 4> node_uids;
82 node_uids[0] = compute(x + 0, y + 0);
83 node_uids[1] = compute(x + 1, y + 0);
84 node_uids[2] = compute(x + 1, y + 1);
85 node_uids[3] = compute(x + 0, y + 1);
86 return node_uids;
87 }
88
89 private:
90
91 Int64 m_base_offset;
92 Int64 m_nb_node_x;
93 };
94
99 class CellUniqueIdComputer2D
100 {
101 public:
102
103 CellUniqueIdComputer2D(Int64 base_offset, Int64 all_nb_cell_x)
104 : m_base_offset(base_offset)
105 , m_all_nb_cell_x(all_nb_cell_x)
106 {}
107
108 public:
109
110 Int64 compute(Int64 x, Int64 y)
111 {
112 return m_base_offset + x + y * m_all_nb_cell_x;
113 }
114 Int64x3 compute(Int64 unique_id)
115 {
116 Int64 uid = unique_id - m_base_offset;
117 const Int64 y = uid / m_all_nb_cell_x;
118 const Int64 x = uid % m_all_nb_cell_x;
119 return Int64x3(x, y, 0);
120 }
121
122 private:
123
124 Int64 m_base_offset;
125 Int64 m_all_nb_cell_x;
126 };
127
132 class FaceUniqueIdComputer2D
133 {
134 public:
135
136 FaceUniqueIdComputer2D(Int64 base_offset, Int64 nb_cell_x, Int64 nb_face_x, Int64 nb_face_dir_x)
137 : m_base_offset(base_offset)
138 , m_nb_cell_x(nb_cell_x)
139 , m_nb_face_x(nb_face_x)
140 , m_nb_face_dir_x(nb_face_dir_x)
141 {}
142
143 public:
144
146 std::array<Int64, 4> computeForCell(Int64 x, Int64 y)
147 {
148 std::array<Int64, 4> face_uids;
149
150 // Faces according to Y
151 face_uids[0] = m_base_offset + (x + 0) + ((y + 0) * m_nb_cell_x) + m_nb_face_dir_x;
152 face_uids[2] = m_base_offset + (x + 0) + ((y + 1) * m_nb_cell_x) + m_nb_face_dir_x;
153
154 // Faces according to X
155 face_uids[1] = m_base_offset + (x + 1) + (y + 0) * m_nb_face_x;
156 face_uids[3] = m_base_offset + (x + 0) + (y + 0) * m_nb_face_x;
157
158 return face_uids;
159 }
160
161 private:
162
163 Int64 m_base_offset;
164 Int64 m_nb_cell_x;
165 Int64 m_nb_face_x;
166 Int64 m_nb_face_dir_x;
167 };
168
173 class NodeUniqueIdComputer3D
174 {
175 public:
176
177 NodeUniqueIdComputer3D(Int64 base_offset, Int64 nb_node_x, Int64 nb_node_xy)
178 : m_base_offset(base_offset)
179 , m_nb_node_x(nb_node_x)
180 , m_nb_node_xy(nb_node_xy)
181 {}
182
183 public:
184
185 Int64 compute(Int64 x, Int64 y, Int64 z)
186 {
187 return m_base_offset + x + y * m_nb_node_x + z * m_nb_node_xy;
188 }
189
190 std::array<Int64, 8> computeForCell(Int64 x, Int64 y, Int64 z)
191 {
192 std::array<Int64, 8> node_uids;
193 node_uids[0] = compute(x + 0, y + 0, z + 0);
194 node_uids[1] = compute(x + 1, y + 0, z + 0);
195 node_uids[2] = compute(x + 1, y + 1, z + 0);
196 node_uids[3] = compute(x + 0, y + 1, z + 0);
197 node_uids[4] = compute(x + 0, y + 0, z + 1);
198 node_uids[5] = compute(x + 1, y + 0, z + 1);
199 node_uids[6] = compute(x + 1, y + 1, z + 1);
200 node_uids[7] = compute(x + 0, y + 1, z + 1);
201 return node_uids;
202 }
203
204 private:
205
206 Int64 m_base_offset;
207 Int64 m_nb_node_x;
208 Int64 m_nb_node_xy;
209 };
210
215 class CellUniqueIdComputer3D
216 {
217 public:
218
219 CellUniqueIdComputer3D(Int64 base_offset, Int64 all_nb_cell_x, Int64 all_nb_cell_xy)
220 : m_base_offset(base_offset)
221 , m_all_nb_cell_x(all_nb_cell_x)
222 , m_all_nb_cell_xy(all_nb_cell_xy)
223 {}
224
225 public:
226
229 {
230 return m_base_offset + x + y * m_all_nb_cell_x + z * m_all_nb_cell_xy;
231 }
232
233 Int64x3 compute(Int64 unique_id)
234 {
235 Int64 uid = unique_id - m_base_offset;
236 Int64 z = uid / m_all_nb_cell_xy;
237 Int64 v = uid - (z * m_all_nb_cell_xy);
238 Int64 y = v / m_all_nb_cell_x;
239 Int64 x = v % m_all_nb_cell_x;
240 return Int64x3(x, y, z);
241 }
242
243 private:
244
245 Int64 m_base_offset;
246 Int64 m_all_nb_cell_x;
247 Int64 m_all_nb_cell_xy;
248 };
249
254 class FaceUniqueIdComputer3D
255 {
256 public:
257
258 FaceUniqueIdComputer3D(Int64 base_offset, Int64 nb_cell_x, Int64 nb_face_x, Int64x3 nb_face_dir,
259 Int64 total_nb_face_xy, Int64 total_nb_face_x)
260 : m_base_offset(base_offset)
261 , m_nb_cell_x(nb_cell_x)
262 , m_nb_face_x(nb_face_x)
263 , m_nb_face_dir(nb_face_dir)
264 , m_total_nb_face_xy(total_nb_face_xy)
265 , m_total_nb_face_x(total_nb_face_x)
266 {}
267
268 public:
269
271 std::array<Int64, 6> computeForCell(Int64 x, Int64 y, Int64 z)
272 {
273 std::array<Int64, 6> face_uids;
274
275 // Faces according to Z
276 face_uids[0] = (x + 0) + ((y + 0) * m_nb_cell_x) + ((z + 0) * m_nb_face_dir.z) + m_total_nb_face_xy;
277 face_uids[3] = (x + 0) + ((y + 0) * m_nb_cell_x) + ((z + 1) * m_nb_face_dir.z) + m_total_nb_face_xy;
278
279 // Faces according to X
280 face_uids[1] = (x + 0) + ((y + 0) * m_nb_face_x) + ((z + 0) * m_nb_face_dir.x);
281 face_uids[4] = (x + 1) + ((y + 0) * m_nb_face_x) + ((z + 0) * m_nb_face_dir.x);
282
283 // Faces according to Y
284 face_uids[2] = (x + 0) + ((y + 0) * m_nb_cell_x) + ((z + 0) * m_nb_face_dir.y) + m_total_nb_face_x;
285 face_uids[5] = (x + 0) + ((y + 1) * m_nb_cell_x) + ((z + 0) * m_nb_face_dir.y) + m_total_nb_face_x;
286
287 for (Int32 i = 0; i < 6; ++i)
288 face_uids[i] += m_base_offset;
289
290 return face_uids;
291 }
292
293 private:
294
295 Int64 m_base_offset;
296 Int64 m_nb_cell_x;
297 Int64 m_nb_face_x;
298 Int64x3 m_nb_face_dir;
299 Int64 m_total_nb_face_xy;
300 Int64 m_total_nb_face_x;
301 };
302
303 public:
304
305 CartesianGridDimension() = default;
307 CartesianGridDimension(Int64 nb_cell_x, Int64 nb_cell_y);
309 CartesianGridDimension(Int64 nb_cell_x, Int64 nb_cell_y, Int64 nb_cell_z);
311 explicit CartesianGridDimension(const Int64x2& dims);
313 explicit CartesianGridDimension(const Int64x3& dims);
315 explicit CartesianGridDimension(const Int32x2& dims);
317 explicit CartesianGridDimension(const Int32x3& dims);
318
319 public:
320
322 constexpr Int64x3 nbCell() const { return m_nb_cell; }
323
325 constexpr Int64x3 nbNode() const { return m_nb_node; }
326
328 constexpr Int64x3 nbFace() const { return m_nb_face; }
329
331 constexpr Int64x3 nbFaceParallelToDirection() const { return m_nb_face_oriented; }
332
334 constexpr Int64 totalNbCell() const { return m_total_nb_cell; }
335
336 private:
337
340 {
341 return { offset, m_nb_node.x };
342 }
343
345 {
346 return { offset, m_nb_node.x, m_nb_node.x * m_nb_node.y };
347 }
348
350 {
351 return { offset, m_nb_cell.x };
352 }
353
355 {
356 return { offset, m_nb_cell.x, m_nb_cell.x * m_nb_cell.y };
357 }
358
360 {
361 Int64x3 nb_face_dir = nbFaceParallelToDirection();
362 return { offset, m_nb_cell.x, m_nb_face.x, nb_face_dir.x };
363 }
364
366 {
367 Int64x3 nb_face_dir = nbFaceParallelToDirection();
368 Int64 total_nb_face_xy = (nb_face_dir.x + nb_face_dir.y) * m_nb_cell.z;
369 Int64 total_nb_face_x = (nb_face_dir.x * m_nb_cell.z);
370 return { offset, m_nb_cell.x, m_nb_face.x, nb_face_dir, total_nb_face_xy, total_nb_face_x };
371 }
372
373 private:
374
376 Int64x3 m_nb_cell;
378 Int64x3 m_nb_node;
380 Int64x3 m_nb_face;
383
384 Int64 m_nb_cell_xy = 0;
385 Int64 m_total_nb_cell = 0;
386
387 private:
388
389 void _init();
390};
391
392/*---------------------------------------------------------------------------*/
393/*---------------------------------------------------------------------------*/
394
395} // namespace Arcane
396
397/*---------------------------------------------------------------------------*/
398/*---------------------------------------------------------------------------*/
399
400#endif
Declarations of Arcane's general types.
Class for calculating the uniqueId() of a cell in 2D based on its position in the grid.
Class for calculating the uniqueId() of a cell in 3D based on its position in the grid.
Int64 compute(Int64 x, Int64 y, Int64 z)
Calculates the uniqueId() based on coordinates.
Int64x3 compute(Int64 unique_id)
Calculates the coordinates based on the uniqueId().
Class for calculating the uniqueId() of a face in 2D based on its position in the grid.
std::array< Int64, 4 > computeForCell(Int64 x, Int64 y)
Calculates the uniqueIds() of the 4 faces of the topological coordinate cell (x,y).
Class for calculating the uniqueId() of a face in 2D based on its position in the grid.
std::array< Int64, 6 > computeForCell(Int64 x, Int64 y, Int64 z)
Calculates the uniqueIds() of the 6 faces of the topological coordinate cell (x,y,...
Class for calculating the uniqueId() of a node in 2D based on its position in the grid.
Class for calculating the uniqueId() of a node in 3D based on its position in the grid.
Information about the dimensions of a Cartesian grid.
constexpr Int64x3 nbCell() const
Number of cells in each direction.
Int64x3 m_nb_node
Number of nodes in each direction.
CellUniqueIdComputer2D getCellComputer2D(Int64 offset) const
Instance to calculate the uniqueIds() of cells for this grid.
Int64x3 m_nb_cell
Number of cells in each direction.
constexpr Int64 totalNbCell() const
Total number of cells.
CellUniqueIdComputer3D getCellComputer3D(Int64 offset) const
Instance to calculate the uniqueIds() of cells for this grid.
FaceUniqueIdComputer3D getFaceComputer3D(Int64 offset) const
Instance to calculate the uniqueIds() of faces for this grid.
Int64x3 m_nb_face_oriented
Total number of faces in a given orientation.
NodeUniqueIdComputer3D getNodeComputer3D(Int64 offset) const
Instance to calculate the uniqueIds() of nodes for this grid.
NodeUniqueIdComputer2D getNodeComputer2D(Int64 offset) const
Instance to calculate the uniqueIds() of nodes for this grid.
constexpr Int64x3 nbFace() const
Number of faces in each direction.
Int64x3 m_nb_face
Number of faces in each direction.
constexpr Int64x3 nbFaceParallelToDirection() const
Total number of faces parallel to a given direction.
FaceUniqueIdComputer2D getFaceComputer2D(Int64 offset) const
Instance to calculate the uniqueIds() of faces for this grid.
constexpr Int64x3 nbNode() const
Number of nodes in each direction.
Construction of uniqueId() for faces in a cartesian mesh.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
std::int32_t Int32
Signed integer type of 32 bits.