14#include "arcane/cartesianmesh/v2/CartesianMeshUniqueIdRenumberingV2.h"
16#include "arcane/utils/PlatformUtils.h"
18#include "arcane/cartesianmesh/ICartesianMesh.h"
19#include "arcane/cartesianmesh/ICartesianMeshPatch.h"
21#include "arcane/core/VariableTypes.h"
22#include "arcane/core/IMesh.h"
23#include "arcane/core/IItemFamily.h"
24#include "arcane/core/ICartesianMeshGenerationInfo.h"
37CartesianMeshUniqueIdRenumberingV2::
38CartesianMeshUniqueIdRenumberingV2(ICartesianMesh* cmesh, ICartesianMeshGenerationInfo* gen_info)
39: TraceAccessor(cmesh->traceMng())
40, m_cartesian_mesh(cmesh)
41, m_generation_info(gen_info)
43 if (platform::getEnvironmentVariable(
"ARCANE_DEBUG_AMR_RENUMBERING") ==
"1")
50void CartesianMeshUniqueIdRenumberingV2::
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();
60 VariableCellInt64 cells_new_uid(VariableBuildInfo(mesh,
"ArcaneRenumberCellsNewUid"));
61 VariableNodeInt64 nodes_new_uid(VariableBuildInfo(mesh,
"ArcaneRenumberNodesNewUid"));
62 VariableFaceInt64 faces_new_uid(VariableBuildInfo(mesh,
"ArcaneRenumberFacesNewUid"));
64 cells_new_uid.fill(-1);
65 nodes_new_uid.fill(-1);
66 faces_new_uid.fill(-1);
70 ICartesianMeshPatch* patch0 = m_cartesian_mesh->patch(0);
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();
97 ARCANE_FATAL(
"Bad value '{0}' for globalNbCells()[MD_DirX] (should be >0)", nb_cell_x);
101 ARCANE_FATAL(
"Bad value '{0}' for globalNbCells()[MD_DirY] (should be >0)", nb_cell_y);
103 Int64 nb_cell_z = ((dimension == 2) ? 1 : global_nb_cells_by_direction[
MD_DirZ]);
105 ARCANE_FATAL(
"Bad value '{0}' for globalNbCells()[MD_DirZ] (should be >0)", nb_cell_z);
107 if (dimension == 2) {
110 Int64 uid = cell.uniqueId();
111 Int64 coord_i = uid % nb_cell_x;
112 Int64 coord_j = uid / nb_cell_x;
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,
122 else if (dimension == 3) {
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);
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,
145 _applyFamilyRenumbering(mesh->cellFamily(), cells_new_uid);
146 _applyFamilyRenumbering(mesh->nodeFamily(), nodes_new_uid);
147 _applyFamilyRenumbering(mesh->faceFamily(), faces_new_uid);
148 mesh->checkValidMesh();
154void CartesianMeshUniqueIdRenumberingV2::
155_applyFamilyRenumbering(IItemFamily* family, VariableItemInt64& items_new_uid)
157 info() <<
"Change uniqueId() for family=" << family->name();
158 items_new_uid.synchronize();
159 ENUMERATE_ (Item, iitem, family->allItems()) {
161 Int64 current_uid = item.uniqueId();
162 Int64 new_uid = items_new_uid[iitem];
163 if (new_uid >= 0 && new_uid != current_uid) {
165 info() <<
"Change ItemUID old=" << current_uid <<
" new=" << new_uid;
166 item.mutableItemBase().setUniqueId(new_uid);
169 family->notifyItemsUniqueIdChanged();
175void CartesianMeshUniqueIdRenumberingV2::
176_applyChildrenCell2D(Cell cell, VariableNodeInt64& nodes_new_uid, VariableFaceInt64& faces_new_uid,
177 VariableCellInt64& cells_new_uid,
179 Int64 current_level_nb_cell_x,
Int64 current_level_nb_cell_y,
185 const Int32 pattern = 2;
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;
190 const Int64 current_level_nb_face_x = current_level_nb_cell_x + 1;
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;
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;
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;
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);
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;
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];
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;
268 new_uids[0] = coord_i * 2 + coord_j * (current_level_nb_face_x + current_level_nb_cell_x);
272 new_uids[2] = new_uids[0] + (current_level_nb_face_x + current_level_nb_cell_x);
275 new_uids[3] = new_uids[2] - 1;
278 new_uids[1] = new_uids[2] + 1;
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;
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];
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;
303 current_level_nb_cell_x *= pattern;
304 current_level_nb_cell_y *= pattern;
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;
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);
325void CartesianMeshUniqueIdRenumberingV2::
326_applyChildrenCell3D(Cell cell, VariableNodeInt64& nodes_new_uid, VariableFaceInt64& faces_new_uid,
327 VariableCellInt64& cells_new_uid,
329 Int64 current_level_nb_cell_x,
Int64 current_level_nb_cell_y,
Int64 current_level_nb_cell_z,
335 const Int32 pattern = 2;
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;
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;
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;
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;
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);
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);
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;
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];
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;
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;
484 const Int64 nb_cell_before_j = coord_j * current_level_nb_cell_x;
486 new_uids[0] = (coord_k * current_level_nb_cell_x * current_level_nb_cell_y)
490 new_uids[3] = new_uids[0] + current_level_nb_cell_x * current_level_nb_cell_y;
492 new_uids[1] = (coord_k * current_level_nb_face_x * current_level_nb_cell_y)
493 + (coord_j * current_level_nb_face_x)
494 + (coord_i) + total_face_xy;
496 new_uids[4] = new_uids[1] + 1;
498 new_uids[2] = (coord_k * current_level_nb_cell_x * current_level_nb_face_y)
500 + (coord_i) + total_face_xy_yz;
502 new_uids[5] = new_uids[2] + current_level_nb_cell_x;
504 for (Integer z = 0; z < 6; ++z) {
505 Face face = cell.face(z);
506 if (faces_new_uid[face] < 0) {
507 new_uids[z] += face_adder;
509 info() <<
"APPLY_FACE_CHILD: uid=" << face.uniqueId() <<
" parent_cell=" << cell.uniqueId()
510 <<
" I=" << z <<
" new_uid=" << new_uids[z];
511 faces_new_uid[face] = new_uids[z];
523 cell_adder += current_level_nb_cell_x * current_level_nb_cell_y * current_level_nb_cell_z;
524 node_adder += current_level_nb_node_x * current_level_nb_node_y * current_level_nb_node_z;
525 face_adder += total_face_xy_yz_zx;
531 current_level_nb_cell_x *= pattern;
532 current_level_nb_cell_y *= pattern;
533 current_level_nb_cell_z *= pattern;
537 const Int32 pattern_cube = pattern * pattern;
539 Int32 nb_child = cell.nbHChildren();
540 for (
Int32 icell = 0; icell < nb_child; ++icell) {
541 Cell sub_cell = cell.hChild(icell);
542 Int64 my_coord_i = coord_i + icell % pattern;
543 Int64 my_coord_j = coord_j + (icell % pattern_cube) / pattern;
544 Int64 my_coord_k = coord_k + icell / pattern_cube;
546 _applyChildrenCell3D(sub_cell, nodes_new_uid, faces_new_uid, cells_new_uid, my_coord_i, my_coord_j, my_coord_k,
547 current_level_nb_cell_x, current_level_nb_cell_y, current_level_nb_cell_z,
548 current_level, cell_adder, node_adder, face_adder);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
MeshVariableScalarRefT< Cell, Int64 > VariableCellInt64
Grandeur au centre des mailles de type entier 64 bits.
MeshVariableScalarRefT< Node, Int64 > VariableNodeInt64
Grandeur au noeud de type entier 64 bits.
MeshVariableScalarRefT< Face, Int64 > VariableFaceInt64
Grandeur aux faces de type entier 64 bits.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
ConstArrayView< Int64 > Int64ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.