Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
CartesianMeshUniqueIdRenumberingV2.cc
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/* CartesianMeshUniqueIdRenumberingV2.cc (C) 2000-2024 */
9/* */
10/* Renumbering of uniqueId() for Cartesian meshes. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/cartesianmesh/v2/CartesianMeshUniqueIdRenumberingV2.h"
15
16#include "arcane/utils/PlatformUtils.h"
17
18#include "arcane/cartesianmesh/ICartesianMesh.h"
19#include "arcane/cartesianmesh/ICartesianMeshPatch.h"
20
21#include "arcane/core/VariableTypes.h"
22#include "arcane/core/IMesh.h"
23#include "arcane/core/IItemFamily.h"
24#include "arcane/core/ICartesianMeshGenerationInfo.h"
25
26#include <array>
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Arcane
32{
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37CartesianMeshUniqueIdRenumberingV2::
38CartesianMeshUniqueIdRenumberingV2(ICartesianMesh* cmesh, ICartesianMeshGenerationInfo* gen_info)
39: TraceAccessor(cmesh->traceMng())
40, m_cartesian_mesh(cmesh)
41, m_generation_info(gen_info)
42{
43 if (platform::getEnvironmentVariable("ARCANE_DEBUG_AMR_RENUMBERING") == "1")
44 m_is_verbose = true;
45}
46
47/*---------------------------------------------------------------------------*/
48/*---------------------------------------------------------------------------*/
49
50void CartesianMeshUniqueIdRenumberingV2::
51renumber()
52{
53 IMesh* mesh = m_cartesian_mesh->mesh();
54 Int32 dimension = mesh->dimension();
55 Int64 cartesian_global_nb_cell = m_generation_info->globalNbCell();
56 info() << "Apply UniqueId renumbering to mesh '" << mesh->name() << "'"
57 << " global_nb_cell=" << cartesian_global_nb_cell
58 << " global_nb_cell_by_dim=" << m_generation_info->globalNbCells();
59
60 VariableCellInt64 cells_new_uid(VariableBuildInfo(mesh, "ArcaneRenumberCellsNewUid"));
61 VariableNodeInt64 nodes_new_uid(VariableBuildInfo(mesh, "ArcaneRenumberNodesNewUid"));
62 VariableFaceInt64 faces_new_uid(VariableBuildInfo(mesh, "ArcaneRenumberFacesNewUid"));
63
64 cells_new_uid.fill(-1);
65 nodes_new_uid.fill(-1);
66 faces_new_uid.fill(-1);
67
68 // Marks the entities derived from the Cartesian mesh as level 0
69 // They will not be renumbered
70 ICartesianMeshPatch* patch0 = m_cartesian_mesh->patch(0);
71 ENUMERATE_ (Cell, icell, patch0->cells()) {
72 Cell c{ *icell };
73 cells_new_uid[icell] = c.uniqueId().asInt64();
74 for (Node n : c.nodes())
75 nodes_new_uid[n] = n.uniqueId();
76 for (Face f : c.faces())
77 faces_new_uid[f] = f.uniqueId();
78 }
79
80 // For each level 0 cell, calculate its index (i,j) in the Cartesian mesh
81
82 // For this, we assume that the mesh was created with the 'CartesianMeshGenerator'
83 // (or a generator that has the same numbering) and that the uniqueId() of a cell is:
84 // Int64 cell_unique_id = i + j * all_nb_cell_x;
85 // with:
86 // all_nb_cell_x = m_generation_info->globalNbCells()[MD_DirX];
87
88 // In 3D:
89 // Int64 cell_unique_id = i + j * all_nb_cell_x + k * (all_nb_cell_x * all_nb_cell_y);
90 // with:
91 // all_nb_cell_x = m_generation_info->globalNbCells()[MD_DirX];
92 // all_nb_cell_y = m_generation_info->globalNbCells()[MD_DirY];
93
94 Int64ConstArrayView global_nb_cells_by_direction = m_generation_info->globalNbCells();
95 Int64 nb_cell_x = global_nb_cells_by_direction[MD_DirX];
96 if (nb_cell_x <= 0)
97 ARCANE_FATAL("Bad value '{0}' for globalNbCells()[MD_DirX] (should be >0)", nb_cell_x);
98
99 Int64 nb_cell_y = global_nb_cells_by_direction[MD_DirY];
100 if (nb_cell_y <= 0)
101 ARCANE_FATAL("Bad value '{0}' for globalNbCells()[MD_DirY] (should be >0)", nb_cell_y);
102
103 Int64 nb_cell_z = ((dimension == 2) ? 1 : global_nb_cells_by_direction[MD_DirZ]);
104 if (nb_cell_z <= 0)
105 ARCANE_FATAL("Bad value '{0}' for globalNbCells()[MD_DirZ] (should be >0)", nb_cell_z);
106
107 if (dimension == 2) {
108 ENUMERATE_ (Cell, icell, patch0->cells()) {
109 Cell cell{ *icell };
110 Int64 uid = cell.uniqueId();
111 Int64 coord_i = uid % nb_cell_x;
112 Int64 coord_j = uid / nb_cell_x;
113 if (m_is_verbose)
114 info() << "Renumbering: PARENT: cell_uid=" << cell.uniqueId() << " I=" << coord_i
115 << " J=" << coord_j << " nb_cell_x=" << nb_cell_x;
116 _applyChildrenCell2D(cell, nodes_new_uid, faces_new_uid, cells_new_uid,
117 coord_i, coord_j, nb_cell_x, nb_cell_y,
118 0, 0, 0, 0);
119 }
120 }
121
122 else if (dimension == 3) {
123 ENUMERATE_ (Cell, icell, patch0->cells()) {
124 Cell cell{ *icell };
125 Int64 uid = cell.uniqueId();
126 Int64 to2d = uid % (nb_cell_x * nb_cell_y);
127 Int64 coord_i = to2d % nb_cell_x;
128 Int64 coord_j = to2d / nb_cell_x;
129 Int64 coord_k = uid / (nb_cell_x * nb_cell_y);
130 if (m_is_verbose)
131 info() << "Renumbering: PARENT: cell_uid=" << cell.uniqueId() << " I=" << coord_i
132 << " J=" << coord_j << " K=" << coord_k
133 << " nb_cell_x=" << nb_cell_x << " nb_cell_y=" << nb_cell_y;
134 _applyChildrenCell3D(cell, nodes_new_uid, faces_new_uid, cells_new_uid,
135 coord_i, coord_j, coord_k,
136 nb_cell_x, nb_cell_y, nb_cell_z,
137 0, 0, 0, 0);
138 }
139 }
140
141 // TODO: create a class for this.
142 //info() << "Change CellFamily";
143 //mesh->cellFamily()->notifyItemsUniqueIdChanged();
144
145 _applyFamilyRenumbering(mesh->cellFamily(), cells_new_uid);
146 _applyFamilyRenumbering(mesh->nodeFamily(), nodes_new_uid);
147 _applyFamilyRenumbering(mesh->faceFamily(), faces_new_uid);
148 mesh->checkValidMesh();
149}
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154void CartesianMeshUniqueIdRenumberingV2::
155_applyFamilyRenumbering(IItemFamily* family, VariableItemInt64& items_new_uid)
156{
157 info() << "Change uniqueId() for family=" << family->name();
158 items_new_uid.synchronize();
159 ENUMERATE_ (Item, iitem, family->allItems()) {
160 Item item{ *iitem };
161 Int64 current_uid = item.uniqueId();
162 Int64 new_uid = items_new_uid[iitem];
163 if (new_uid >= 0 && new_uid != current_uid) {
164 if (m_is_verbose)
165 info() << "Change ItemUID old=" << current_uid << " new=" << new_uid;
166 item.mutableItemBase().setUniqueId(new_uid);
167 }
168 }
169 family->notifyItemsUniqueIdChanged();
170}
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175void CartesianMeshUniqueIdRenumberingV2::
176_applyChildrenCell2D(Cell cell, VariableNodeInt64& nodes_new_uid, VariableFaceInt64& faces_new_uid,
177 VariableCellInt64& cells_new_uid,
178 Int64 coord_i, Int64 coord_j,
179 Int64 current_level_nb_cell_x, Int64 current_level_nb_cell_y,
180 Int32 current_level, Int64 cell_adder, Int64 node_adder, Int64 face_adder)
181{
182 // TODO: to be able to adapt to all refinements, instead of 4,
183 // it would be necessary to take the max of nbHChildren()
184 // TODO : See if it works for pattern != 2.
185 const Int32 pattern = 2;
186
187 const Int64 current_level_nb_node_x = current_level_nb_cell_x + 1;
188 const Int64 current_level_nb_node_y = current_level_nb_cell_y + 1;
189
190 const Int64 current_level_nb_face_x = current_level_nb_cell_x + 1;
191
192 // // Non-recursive version for cell_adder, node_adder, and face_adder.
193 // cell_adder = 0;
194 // node_adder = 0;
195 // face_adder = 0;
196 // const Int64 parent_level_nb_cell_x = current_level_nb_cell_x / pattern;
197 // const Int64 parent_level_nb_cell_y = current_level_nb_cell_y / pattern;
198 // Int64 level_i_nb_cell_x = parent_level_nb_cell_x;
199 // Int64 level_i_nb_cell_y = parent_level_nb_cell_y;
200 // for(Int32 i = current_level-1; i >= 0; i--){
201 // face_adder += (level_i_nb_cell_x * level_i_nb_cell_y) * 2 + level_i_nb_cell_x*2 + level_i_nb_cell_y;
202 // cell_adder += level_i_nb_cell_x * level_i_nb_cell_y;
203 // node_adder += (level_i_nb_cell_x + 1) * (level_i_nb_cell_y + 1);
204 // level_i_nb_cell_x /= pattern;
205 // level_i_nb_cell_y /= pattern;
206 // }
207
208 // Renumbers the cell.
209 {
210 Int64 new_uid = (coord_i + coord_j * current_level_nb_cell_x) + cell_adder;
211 if (cells_new_uid[cell] < 0) {
212 cells_new_uid[cell] = new_uid;
213 if (m_is_verbose)
214 info() << "APPLY_CELL_CHILD: uid=" << cell.uniqueId() << " I=" << coord_i << " J=" << coord_j
215 << " current_level=" << current_level << " new_uid=" << new_uid << " CellAdder=" << cell_adder;
216 }
217 }
218
219 // Renumbers the nodes of the current cell.
220 // Assumes we have 4 nodes
221 // WARNING: we cannot easily maintain the order
222 // of the uniqueIds() between the old and new numbering.
223 // This invalidates the face orientation, which will need to be redone.
224 {
225 if (cell.nbNode() != 4)
226 ARCANE_FATAL("Invalid number of nodes N={0}, expected=4", cell.nbNode());
227 std::array<Int64, 4> new_uids;
228
229 new_uids[0] = (coord_i + 0) + ((coord_j + 0) * current_level_nb_node_x);
230 new_uids[1] = (coord_i + 1) + ((coord_j + 0) * current_level_nb_node_x);
231 new_uids[2] = (coord_i + 1) + ((coord_j + 1) * current_level_nb_node_x);
232 new_uids[3] = (coord_i + 0) + ((coord_j + 1) * current_level_nb_node_x);
233
234 for (Integer z = 0; z < 4; ++z) {
235 Node node = cell.node(z);
236 if (nodes_new_uid[node] < 0) {
237 new_uids[z] += node_adder;
238 if (m_is_verbose)
239 info() << "APPLY_NODE_CHILD: uid=" << node.uniqueId() << " parent_cell=" << cell.uniqueId()
240 << " I=" << z << " new_uid=" << new_uids[z];
241 nodes_new_uid[node] = new_uids[z];
242 }
243 }
244 }
245
246 // Renumbers the faces
247 // |-0--|--2-|
248 // 4| 6| 8|
249 // |-5--|-7--|
250 // 9| 11| 13|
251 // |-10-|-12-|
252 //
253 // With this numbering, TOP < LEFT < BOTTOM < RIGHT
254 // Aside from the uniqueIds of the first row of faces, all
255 // the uniqueIds are contiguous.
256 {
257 if (cell.nbFace() != 4)
258 ARCANE_FATAL("Invalid number of faces N={0}, expected=4", cell.nbFace());
259 std::array<Int64, 4> new_uids;
260
261 // TOP
262 // - "(current_level_nb_face_x + current_level_nb_cell_x)" :
263 // the number of LEFT BOTTOM RIGHT faces above.
264 // - "coord_j * (current_level_nb_face_x + current_level_nb_cell_x)" :
265 // the total number of LEFT BOTTOM RIGHT faces above.
266 // - "coord_i * 2"
267 // we advance two by two on the faces of the same "side".
268 new_uids[0] = coord_i * 2 + coord_j * (current_level_nb_face_x + current_level_nb_cell_x);
269
270 // BOTTOM
271 // For BOTTOM, it is like TOP but with an additional "number of faces above".
272 new_uids[2] = new_uids[0] + (current_level_nb_face_x + current_level_nb_cell_x);
273 // LEFT
274 // For LEFT, it is the UID of BOTTOM - 1.
275 new_uids[3] = new_uids[2] - 1;
276 // RIGHT
277 // For RIGHT, it is the UID of BOTTOM + 1.
278 new_uids[1] = new_uids[2] + 1;
279
280 for (Integer z = 0; z < 4; ++z) {
281 Face face = cell.face(z);
282 if (faces_new_uid[face] < 0) {
283 new_uids[z] += face_adder;
284 if (m_is_verbose)
285 info() << "APPLY_FACE_CHILD: uid=" << face.uniqueId() << " parent_cell=" << cell.uniqueId()
286 << " I=" << z << " new_uid=" << new_uids[z];
287 faces_new_uid[face] = new_uids[z];
288 }
289 }
290 }
291
292 // Renumbers the sub-cells
293 // Assumes we have 4 child cells arranged as follows by cells
294 // -------
295 // | 2| 3|
296 // -------
297 // | 0| 1|
298 // -------
299 cell_adder += current_level_nb_cell_x * current_level_nb_cell_y;
300 node_adder += current_level_nb_node_x * current_level_nb_node_y;
301 face_adder += (current_level_nb_cell_x * current_level_nb_cell_y) * 2 + current_level_nb_cell_x * 2 + current_level_nb_cell_y;
302
303 current_level_nb_cell_x *= pattern;
304 current_level_nb_cell_y *= pattern;
305
306 current_level += 1;
307
308 coord_i *= pattern;
309 coord_j *= pattern;
310
311 Int32 nb_child = cell.nbHChildren();
312 for (Int32 icell = 0; icell < nb_child; ++icell) {
313 Cell sub_cell = cell.hChild(icell);
314 Int64 my_coord_i = coord_i + icell % pattern;
315 Int64 my_coord_j = coord_j + icell / pattern;
316
317 _applyChildrenCell2D(sub_cell, nodes_new_uid, faces_new_uid, cells_new_uid, my_coord_i, my_coord_j,
318 current_level_nb_cell_x, current_level_nb_cell_y, current_level, cell_adder, node_adder, face_adder);
319 }
320}
321
322/*---------------------------------------------------------------------------*/
323/*---------------------------------------------------------------------------*/
324
325void CartesianMeshUniqueIdRenumberingV2::
326_applyChildrenCell3D(Cell cell, VariableNodeInt64& nodes_new_uid, VariableFaceInt64& faces_new_uid,
327 VariableCellInt64& cells_new_uid,
328 Int64 coord_i, Int64 coord_j, Int64 coord_k,
329 Int64 current_level_nb_cell_x, Int64 current_level_nb_cell_y, Int64 current_level_nb_cell_z,
330 Int32 current_level, Int64 cell_adder, Int64 node_adder, Int64 face_adder)
331{
332 // TODO: to be able to adapt to all refinements, instead of 8,
333 // we should take the max of nbHChildren()
334 // TODO: Check if it works for pattern != 2.
335 const Int32 pattern = 2;
336
337 const Int64 current_level_nb_node_x = current_level_nb_cell_x + 1;
338 const Int64 current_level_nb_node_y = current_level_nb_cell_y + 1;
339 const Int64 current_level_nb_node_z = current_level_nb_cell_z + 1;
340
341 const Int64 current_level_nb_face_x = current_level_nb_cell_x + 1;
342 const Int64 current_level_nb_face_y = current_level_nb_cell_y + 1;
343 const Int64 current_level_nb_face_z = current_level_nb_cell_z + 1;
344
345 // // Version non récursive pour cell_adder, node_adder et face_adder.
346 // cell_adder = 0;
347 // node_adder = 0;
348 // face_adder = 0;
349 // const Int64 parent_level_nb_cell_x = current_level_nb_cell_x / pattern;
350 // const Int64 parent_level_nb_cell_y = current_level_nb_cell_y / pattern;
351 // const Int64 parent_level_nb_cell_z = current_level_nb_cell_z / pattern;
352 // Int64 level_i_nb_cell_x = parent_level_nb_cell_x;
353 // Int64 level_i_nb_cell_y = parent_level_nb_cell_y;
354 // Int64 level_i_nb_cell_z = parent_level_nb_cell_z;
355 // for(Int32 i = current_level-1; i >= 0; i--){
356 // face_adder += (level_i_nb_cell_z + 1) * level_i_nb_cell_x * level_i_nb_cell_y
357 // + (level_i_nb_cell_x + 1) * level_i_nb_cell_y * level_i_nb_cell_z
358 // + (level_i_nb_cell_y + 1) * level_i_nb_cell_z * level_i_nb_cell_x;
359
360 // cell_adder += level_i_nb_cell_x * level_i_nb_cell_y * level_i_nb_cell_z;
361 // node_adder += (level_i_nb_cell_x + 1) * (level_i_nb_cell_y + 1) * (level_i_nb_cell_z + 1);
362
363 // level_i_nb_cell_x /= pattern;
364 // level_i_nb_cell_y /= pattern;
365 // level_i_nb_cell_z /= pattern;
366 // }
367
368 // Renumbers the cell.
369 {
370 Int64 new_uid = (coord_i + coord_j * current_level_nb_cell_x + coord_k * current_level_nb_cell_x * current_level_nb_cell_y) + cell_adder;
371 if (cells_new_uid[cell] < 0) {
372 cells_new_uid[cell] = new_uid;
373 if (m_is_verbose)
374 info() << "APPLY_CELL_CHILD: uid=" << cell.uniqueId() << " I=" << coord_i << " J=" << coord_j << " K=" << coord_k
375 << " current_level=" << current_level << " new_uid=" << new_uid << " CellAdder=" << cell_adder;
376 }
377 }
378
379 // Renumbers the nodes of the current cell.
380 // Assumes we have 8 nodes
381 // WARNING: initially, we cannot easily maintain the order
382 // of uniqueIds() between the old and new numbering.
383 // This invalidates the face orientation, which will need to be redone.
384 {
385 if (cell.nbNode() != 8)
386 ARCANE_FATAL("Invalid number of nodes N={0}, expected=8", cell.nbNode());
387 std::array<Int64, 8> new_uids;
388 new_uids[0] = (coord_i + 0) + ((coord_j + 0) * current_level_nb_node_x) + ((coord_k + 0) * current_level_nb_node_x * current_level_nb_node_y);
389 new_uids[1] = (coord_i + 1) + ((coord_j + 0) * current_level_nb_node_x) + ((coord_k + 0) * current_level_nb_node_x * current_level_nb_node_y);
390 new_uids[2] = (coord_i + 1) + ((coord_j + 1) * current_level_nb_node_x) + ((coord_k + 0) * current_level_nb_node_x * current_level_nb_node_y);
391 new_uids[3] = (coord_i + 0) + ((coord_j + 1) * current_level_nb_node_x) + ((coord_k + 0) * current_level_nb_node_x * current_level_nb_node_y);
392
393 new_uids[4] = (coord_i + 0) + ((coord_j + 0) * current_level_nb_node_x) + ((coord_k + 1) * current_level_nb_node_x * current_level_nb_node_y);
394 new_uids[5] = (coord_i + 1) + ((coord_j + 0) * current_level_nb_node_x) + ((coord_k + 1) * current_level_nb_node_x * current_level_nb_node_y);
395 new_uids[6] = (coord_i + 1) + ((coord_j + 1) * current_level_nb_node_x) + ((coord_k + 1) * current_level_nb_node_x * current_level_nb_node_y);
396 new_uids[7] = (coord_i + 0) + ((coord_j + 1) * current_level_nb_node_x) + ((coord_k + 1) * current_level_nb_node_x * current_level_nb_node_y);
397
398 for (Integer z = 0; z < 8; ++z) {
399 Node node = cell.node(z);
400 if (nodes_new_uid[node] < 0) {
401 new_uids[z] += node_adder;
402 if (m_is_verbose)
403 info() << "APPLY_NODE_CHILD: uid=" << node.uniqueId() << " parent_cell=" << cell.uniqueId()
404 << " I=" << z << " new_uid=" << new_uids[z];
405 nodes_new_uid[node] = new_uids[z];
406 }
407 }
408 }
409
410 // Renumbers the faces
411 // This algorithm is not based on the 2D algorithm.
412 // The generated UniqueIDs are contiguous.
413 // It is also possible to find the UniqueIDs of the faces
414 // using the cell position and the mesh size.
415 // Furthermore, the order of the face UniqueIDs of a cell is always the
416 // same (in Arcane localId notation (cell.face(i)) : 0, 3, 1, 4, 2, 5).
417 // The generated UniqueIDs are therefore the same regardless of the decomposition.
418 /*
419 x z
420 ┌──► │ ┌──►
421 │ │ │
422 y▼12 13 14 │y▼ ┌────┬────┐
423 │ 26 │ 27 │ │ │ 24 │ 25 │
424 └────┴────┘ │ 0 4 8
425 15 16 17 │
426 │ 28 │ 29 │ │ │ │ │
427 └────┴────┘ │ 2 6 10
428 z=0 │ x=0
429 - - - - - - - - - - - - - - - - - -
430 z=1 │ x=1
431 18 19 20 │ ┌────┬────┐
432 │ 32 │ 33 │ │ │ 30 │ 31 │
433 └────┴────┘ │ 1 5 9
434 21 22 23 │
435 │ 34 │ 35 │ │ │ │ │
436 └────┴────┘ │ 3 7 11
437
438 */
439 // We have a cube decomposed into eight cells (2x2x2).
440 // The diagram above represents the faces of the cells of this cube with
441 // the uniqueIDs that the algorithm will generate (without face_adder).
442 // For this algorithm, we start with the "xy" faces.
443 // We enumerate first in x, then in y, then in z.
444 // Once the "xy" faces are numbered, we do the "yz" faces.
445 // Always the same numbering order.
446 // We finish with the "zx" faces, still in the same order.
447 //
448 // In the implementation below, we do the numbering
449 // cell by cell.
450 const Int64 total_face_xy = current_level_nb_face_z * current_level_nb_cell_x * current_level_nb_cell_y;
451 const Int64 total_face_xy_yz = total_face_xy + current_level_nb_face_x * current_level_nb_cell_y * current_level_nb_cell_z;
452 const Int64 total_face_xy_yz_zx = total_face_xy_yz + current_level_nb_face_y * current_level_nb_cell_z * current_level_nb_cell_x;
453 {
454 if (cell.nbFace() != 6)
455 ARCANE_FATAL("Invalid number of faces N={0}, expected=6", cell.nbFace());
456 std::array<Int64, 6> new_uids;
457
459 // new_uids[0] = (coord_k * current_level_nb_cell_x * current_level_nb_cell_y)
460 // + (coord_j * current_level_nb_cell_x)
461 // + (coord_i);
462
463 // new_uids[3] = ((coord_k+1) * current_level_nb_cell_x * current_level_nb_cell_y)
464 // + (coord_j * current_level_nb_cell_x)
465 // + (coord_i);
466
467 // new_uids[1] = (coord_k * current_level_nb_face_x * current_level_nb_cell_y)
468 // + (coord_j * current_level_nb_face_x)
469 // + (coord_i) + total_face_xy;
470
471 // new_uids[4] = (coord_k * current_level_nb_face_x * current_level_nb_cell_y)
472 // + (coord_j * current_level_nb_face_x)
473 // + (coord_i+1) + total_face_xy;
474
475 // new_uids[2] = (coord_k * current_level_nb_cell_x * current_level_nb_face_y)
476 // + (coord_j * current_level_nb_cell_x)
477 // + (coord_i) + total_face_xy_yz;
478
479 // new_uids[5] = (coord_k * current_level_nb_cell_x * current_level_nb_face_y)
480 // + ((coord_j+1) * current_level_nb_cell_x)
481 // + (coord_i) + total_face_xy_yz;
483
484 const Int64 nb_cell_before_j = coord_j * current_level_nb_cell_x;
485
486 new_uids[0] = (coord_k * current_level_nb_cell_x * current_level_nb_cell_y) + nb_cell_before_j + (coord_i);
487
488 new_uids[3] = new_uids[0] + current_level_nb_cell_x * current_level_nb_cell_y;
489
490 new_uids[1] = (coord_k * current_level_nb_face_x * current_level_nb_cell_y) + (coord_j * current_level_nb_face_x) + (coord_i) + total_face_xy;
491
492 new_uids[4] = new_uids[1] + 1;
493
494 new_uids[2] = (coord_k * current_level_nb_cell_x * current_level_nb_face_y) + nb_cell_before_j + (coord_i) + total_face_xy_yz;
495
496 new_uids[5] = new_uids[2] + current_level_nb_cell_x;
497
498 for (Integer z = 0; z < 6; ++z) {
499 Face face = cell.face(z);
500 if (faces_new_uid[face] < 0) {
501 new_uids[z] += face_adder;
502 if (m_is_verbose)
503 info() << "APPLY_FACE_CHILD: uid=" << face.uniqueId() << " parent_cell=" << cell.uniqueId()
504 << " I=" << z << " new_uid=" << new_uids[z];
505 faces_new_uid[face] = new_uids[z];
506 }
507 }
508 }
509
510 // Renumbers the sub-cells
511 // Assumes we have 8 child cells (2x2x2) arranged as follows by cells
512 // -------
513 // | 2| 3|
514 // -------
515 // | 0| 1|
516 // -------
517 cell_adder += current_level_nb_cell_x * current_level_nb_cell_y * current_level_nb_cell_z;
518 node_adder += current_level_nb_node_x * current_level_nb_node_y * current_level_nb_node_z;
519 face_adder += total_face_xy_yz_zx;
520
521 coord_i *= pattern;
522 coord_j *= pattern;
523 coord_k *= pattern;
524
525 current_level_nb_cell_x *= pattern;
526 current_level_nb_cell_y *= pattern;
527 current_level_nb_cell_z *= pattern;
528
529 current_level += 1;
530
531 const Int32 pattern_cube = pattern * pattern;
532
533 Int32 nb_child = cell.nbHChildren();
534 for (Int32 icell = 0; icell < nb_child; ++icell) {
535 Cell sub_cell = cell.hChild(icell);
536 Int64 my_coord_i = coord_i + icell % pattern;
537 Int64 my_coord_j = coord_j + (icell % pattern_cube) / pattern;
538 Int64 my_coord_k = coord_k + icell / pattern_cube;
539
540 _applyChildrenCell3D(sub_cell, nodes_new_uid, faces_new_uid, cells_new_uid, my_coord_i, my_coord_j, my_coord_k,
541 current_level_nb_cell_x, current_level_nb_cell_y, current_level_nb_cell_z,
542 current_level, cell_adder, node_adder, face_adder);
543 }
544}
545
546/*---------------------------------------------------------------------------*/
547/*---------------------------------------------------------------------------*/
548
549} // End namespace Arcane
550
551/*---------------------------------------------------------------------------*/
552/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ENUMERATE_(type, name, group)
Generic enumerator for an entity group.
Brief: Cartesian mesh generation information.
MeshVariableScalarRefT< Cell, Int64 > VariableCellInt64
Quantity at the cell center of 64-bit integer type.
MeshVariableScalarRefT< Node, Int64 > VariableNodeInt64
Quantity at the node of 64-bit integer type.
MeshVariableScalarRefT< Face, Int64 > VariableFaceInt64
Quantity at the face of 64-bit integer type.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:480
@ MD_DirZ
Z Direction.
@ MD_DirY
Y Direction.
@ MD_DirX
X Direction.
@ Cell
The mesh is AMR by cell.
Definition MeshKind.h:53