Arcane  4.1.12.0
User 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{
33 class DynamicMeshCartesian2DBuilder;
34 class DynamicMeshCartesian3DBuilder;
35 class CartesianFaceUniqueIdBuilder;
36} // namespace mesh
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41/*!
42 * \brief Information about the dimensions of a Cartesian grid.
43 *
44 * This class allows obtaining, based on the number of cells in
45 * each direction, the various information about the dimensions
46 * of the mesh.
47 */
48class ARCANE_CORE_EXPORT CartesianGridDimension
49{
50 friend mesh::DynamicMeshCartesian2DBuilder;
51 friend mesh::DynamicMeshCartesian3DBuilder;
52 friend mesh::CartesianFaceUniqueIdBuilder;
53 friend class CartesianMeshUniqueIdRenumbering;
54 friend class CartesianMeshCoarsening;
55 friend class CartesianMeshCoarsening2;
56
57 private:
58
59 /*!
60 * \brief Class for calculating the uniqueId() of a node in 2D based on
61 * its position in the grid.
62 */
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
95 /*!
96 * \brief Class for calculating the uniqueId() of a cell in 2D based on
97 * its position in the grid.
98 */
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
128 /*!
129 * \brief Class for calculating the uniqueId() of a face in 2D based on
130 * its position in the grid.
131 */
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
145 //! Calculates the uniqueIds() of the 4 faces of the topological coordinate cell (x,y)
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
169 /*!
170 * \brief Class for calculating the uniqueId() of a node in 3D based on
171 * its position in the grid.
172 */
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
211 /*!
212 * \brief Class for calculating the uniqueId() of a cell in 3D based on
213 * its position in the grid.
214 */
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
227 //! Calculates the uniqueId() based on coordinates
228 Int64 compute(Int64 x, Int64 y, Int64 z)
229 {
230 return m_base_offset + x + y * m_all_nb_cell_x + z * m_all_nb_cell_xy;
231 }
232 //! Calculates the coordinates based on the uniqueId().
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
250 /*!
251 * \brief Class for calculating the uniqueId() of a face in 2D based on
252 * its position in the grid.
253 */
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
270 //! Calculates the uniqueIds() of the 6 faces of the topological coordinate cell (x,y,z)
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;
306 //! Constructs a 2D grid of dimension (nb_cell_x,nb_cell_y)
307 CartesianGridDimension(Int64 nb_cell_x, Int64 nb_cell_y);
308 //! Constructs a 3D grid of dimension (nb_cell_x,nb_cell_y,nb_cell_z)
309 CartesianGridDimension(Int64 nb_cell_x, Int64 nb_cell_y, Int64 nb_cell_z);
310 //! Constructs a 2D grid of dimension \a dims
311 explicit CartesianGridDimension(const Int64x2& dims);
312 //! Constructs a 3D grid of dimension \a dims
313 explicit CartesianGridDimension(const Int64x3& dims);
314 //! Constructs a 2D grid of dimension \a dims
315 explicit CartesianGridDimension(const Int32x2& dims);
316 //! Constructs a 3D grid of dimension \a dims
317 explicit CartesianGridDimension(const Int32x3& dims);
318
319 public:
320
321 //! Number of cells in each direction
322 constexpr Int64x3 nbCell() const { return m_nb_cell; }
323
324 //! Number of nodes in each direction
325 constexpr Int64x3 nbNode() const { return m_nb_node; }
326
327 //! Number of faces in each direction
328 constexpr Int64x3 nbFace() const { return m_nb_face; }
329
330 //! Total number of faces parallel to a given direction
331 constexpr Int64x3 nbFaceParallelToDirection() const { return m_nb_face_oriented; }
332
333 //! Total number of cells
334 constexpr Int64 totalNbCell() const { return m_total_nb_cell; }
335
336 private:
337
338 //! Instance to calculate the uniqueIds() of nodes for this grid
339 NodeUniqueIdComputer2D getNodeComputer2D(Int64 offset) const
340 {
341 return { offset, m_nb_node.x };
342 }
343 //! Instance to calculate the uniqueIds() of nodes for this grid
344 NodeUniqueIdComputer3D getNodeComputer3D(Int64 offset) const
345 {
346 return { offset, m_nb_node.x, m_nb_node.x * m_nb_node.y };
347 }
348 //! Instance to calculate the uniqueIds() of cells for this grid
349 CellUniqueIdComputer2D getCellComputer2D(Int64 offset) const
350 {
351 return { offset, m_nb_cell.x };
352 }
353 //! Instance to calculate the uniqueIds() of cells for this grid
354 CellUniqueIdComputer3D getCellComputer3D(Int64 offset) const
355 {
356 return { offset, m_nb_cell.x, m_nb_cell.x * m_nb_cell.y };
357 }
358 //! Instance to calculate the uniqueIds() of faces for this grid
359 FaceUniqueIdComputer2D getFaceComputer2D(Int64 offset) const
360 {
361 Int64x3 nb_face_dir = nbFaceParallelToDirection();
362 return { offset, m_nb_cell.x, m_nb_face.x, nb_face_dir.x };
363 }
364 //! Instance to calculate the uniqueIds() of faces for this grid
365 FaceUniqueIdComputer3D getFaceComputer3D(Int64 offset) const
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
375 //! Number of cells in each direction
376 Int64x3 m_nb_cell;
377 //! Number of nodes in each direction
378 Int64x3 m_nb_node;
379 //! Number of faces in each direction
380 Int64x3 m_nb_face;
381 //! Total number of faces in a given orientation
382 Int64x3 m_nb_face_oriented;
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.
constexpr Int64x3 nbCell() const
Number of cells in each direction.
constexpr Int64 totalNbCell() const
Total number of cells.
constexpr Int64x3 nbFace() const
Number of faces in each direction.
constexpr Int64x3 nbFaceParallelToDirection() const
Total number of faces parallel to a given direction.
constexpr Int64x3 nbNode() const
Number of nodes in each direction.
-- 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.