16#include "arcane/cartesianmesh/internal/CartesianMeshNumberingMngInternal.h"
18#include "arcane/utils/Vector2.h"
19#include "arcane/utils/ITraceMng.h"
21#include "arcane/core/IMesh.h"
22#include "arcane/core/IParallelMng.h"
23#include "arcane/core/VariableTypes.h"
24#include "arcane/core/ICartesianMeshGenerationInfo.h"
25#include "arcane/core/IItemFamily.h"
26#include "arcane/core/IMeshModifier.h"
27#include "arcane/core/Properties.h"
38CartesianMeshNumberingMngInternal::
39CartesianMeshNumberingMngInternal(
IMesh*
mesh)
42, m_dimension(
mesh->dimension())
46, m_converting_numbering_face(true)
50 const auto* m_generation_info = ICartesianMeshGenerationInfo::getReference(m_mesh,
true);
51 ConstArrayView<Int64> global_nb_cells_by_direction = m_generation_info->globalNbCells();
53 const Int64x3 nb_cell_ground = {
54 global_nb_cells_by_direction[
MD_DirX],
55 global_nb_cells_by_direction[
MD_DirY],
56 ((m_dimension == 2) ? 1 : global_nb_cells_by_direction[
MD_DirZ])
59 m_nb_cell_ground.x =
static_cast<CartCoord>(nb_cell_ground.x);
60 m_nb_cell_ground.y =
static_cast<CartCoord>(nb_cell_ground.y);
61 m_nb_cell_ground.z =
static_cast<CartCoord>(nb_cell_ground.z);
63 if (nb_cell_ground.x <= 0)
64 ARCANE_FATAL(
"Bad value '{0}' for globalNbCells()[MD_DirX] (should be >0)", nb_cell_ground.x);
65 if (nb_cell_ground.y <= 0)
66 ARCANE_FATAL(
"Bad value '{0}' for globalNbCells()[MD_DirY] (should be >0)", nb_cell_ground.y);
67 if (nb_cell_ground.z <= 0)
68 ARCANE_FATAL(
"Bad value '{0}' for globalNbCells()[MD_DirZ] (should be >0)", nb_cell_ground.z);
70 if (m_dimension == 2) {
71 m_latest_cell_uid = nb_cell_ground.x * nb_cell_ground.y;
72 m_latest_node_uid = (nb_cell_ground.x + 1) * (nb_cell_ground.y + 1);
73 m_latest_face_uid = (nb_cell_ground.x * nb_cell_ground.y) * 2 + nb_cell_ground.x * 2 + nb_cell_ground.y;
76 m_latest_cell_uid = nb_cell_ground.x * nb_cell_ground.y * nb_cell_ground.z;
77 m_latest_node_uid = (nb_cell_ground.x + 1) * (nb_cell_ground.y + 1) * (nb_cell_ground.z + 1);
78 m_latest_face_uid = (nb_cell_ground.x + 1) * nb_cell_ground.y * nb_cell_ground.z + (nb_cell_ground.y + 1) * nb_cell_ground.z * nb_cell_ground.x + (nb_cell_ground.z + 1) * nb_cell_ground.x * nb_cell_ground.y;
82 m_first_cell_uid_level.add(0);
83 m_first_node_uid_level.add(0);
84 m_first_face_uid_level.add(0);
89 if (m_converting_numbering_face) {
90 UniqueArray<Int64> face_uid(CartesianMeshNumberingMngInternal::nbFaceByCell());
91 ENUMERATE_ (Cell, icell, m_mesh->allLevelCells(0)) {
92 CartesianMeshNumberingMngInternal::cellFaceUniqueIds(icell->uniqueId(), 0, face_uid);
93 for (Integer i = 0; i < CartesianMeshNumberingMngInternal::nbFaceByCell(); ++i) {
94 m_face_ori_numbering_to_new[icell->face(i).uniqueId()] = face_uid[i];
95 m_face_new_numbering_to_ori[face_uid[i]] = icell->face(i).uniqueId();
105void CartesianMeshNumberingMngInternal::
108 m_properties =
makeRef(
new Properties(*(m_mesh->properties()),
"CartesianMeshNumberingMngInternal"));
114void CartesianMeshNumberingMngInternal::
115saveInfosInProperties()
117 m_properties->set(
"Version", 1);
118 m_properties->set(
"FirstCellUIDByLevel", m_first_cell_uid_level);
121 m_properties->set(
"FirstNodeUIDByLevel", m_first_node_uid_level);
122 m_properties->set(
"FirstFaceUIDByLevel", m_first_face_uid_level);
124 m_properties->set(
"OriginalGroundLevelForConverting", m_ori_level);
130void CartesianMeshNumberingMngInternal::
133 Int32 v = m_properties->getInt32(
"Version");
135 ARCANE_FATAL(
"Bad numbering mng version: trying to read from incompatible checkpoint v={0} expected={1}", v, 1);
137 m_properties->get(
"FirstCellUIDByLevel", m_first_cell_uid_level);
138 m_properties->get(
"FirstNodeUIDByLevel", m_first_node_uid_level);
139 m_properties->get(
"FirstFaceUIDByLevel", m_first_face_uid_level);
141 m_properties->get(
"OriginalGroundLevelForConverting", m_ori_level);
142 if (m_ori_level == -1) {
143 m_converting_numbering_face =
false;
144 m_face_ori_numbering_to_new.clear();
145 m_face_new_numbering_to_ori.clear();
148 m_nb_cell_ground = { globalNbCellsX(0), globalNbCellsY(0), globalNbCellsZ(0) };
150 m_max_level = m_first_cell_uid_level.size() - 1;
156 for (
const Int64 elem : m_first_cell_uid_level) {
163 m_latest_cell_uid = m_first_cell_uid_level[pos] + nbCellInLevel(pos);
164 m_latest_node_uid = m_first_node_uid_level[pos] + nbNodeInLevel(pos);
165 m_latest_face_uid = m_first_face_uid_level[pos] + nbFaceInLevel(pos);
172void CartesianMeshNumberingMngInternal::
173renumberingFacesLevel0FromOriginalArcaneNumbering()
175 if (!m_converting_numbering_face)
178 info() <<
"Renumbering faces of level 0...";
185 icell->face(i).mutableItemBase().setUniqueId(face_uid[i]);
188 m_mesh->faceFamily()->notifyItemsUniqueIdChanged();
189 m_mesh->modifier()->endUpdate();
190 m_mesh->checkValidMesh();
192 m_converting_numbering_face =
false;
194 m_face_ori_numbering_to_new.clear();
195 m_face_new_numbering_to_ori.clear();
201void CartesianMeshNumberingMngInternal::
207 tm->
info() <<
"CartesianMeshNumberingMngInternal status :";
213 tm->
info() <<
"LatestCellUID : " << m_latest_cell_uid;
214 tm->
info() <<
"LatestNodeUID : " << m_latest_node_uid;
215 tm->
info() <<
"LatestFaceUID : " << m_latest_face_uid;
217 tm->
info() <<
"MinLevel : " << m_min_level;
218 tm->
info() <<
"MaxLevel : " << m_max_level;
220 tm->
info() <<
"GroundLevelNbCells : " << m_nb_cell_ground;
222 if (m_ori_level == -1) {
223 tm->
info() <<
"Ground Level is renumbered";
226 tm->
info() <<
"Ground Level is not renumbered -- OriginalGroundLevel : " << m_ori_level;
229 for (
Integer i = m_min_level; i <= m_max_level; ++i) {
230 tm->
info() <<
"Level " << i <<
" : ";
236 const auto* m_generation_info = ICartesianMeshGenerationInfo::getReference(m_mesh,
true);
239 tm->
info() <<
"global_nb_cells_by_direction.x : " << global_nb_cells_by_direction[
MD_DirX];
240 tm->
info() <<
"global_nb_cells_by_direction.y : " << global_nb_cells_by_direction[
MD_DirY];
241 tm->
info() <<
"global_nb_cells_by_direction.z : " << global_nb_cells_by_direction[
MD_DirZ];
247void CartesianMeshNumberingMngInternal::
248prepareLevel(
Int32 level)
250 if (level <= m_max_level && level >= m_min_level)
252 if (level == m_max_level + 1) {
254 m_first_cell_uid_level.add(m_latest_cell_uid);
255 m_first_node_uid_level.add(m_latest_node_uid);
256 m_first_face_uid_level.add(m_latest_face_uid);
258 else if (level == m_min_level - 1) {
260 _pushFront(m_first_cell_uid_level, m_latest_cell_uid);
261 _pushFront(m_first_node_uid_level, m_latest_node_uid);
262 _pushFront(m_first_face_uid_level, m_latest_face_uid);
276void CartesianMeshNumberingMngInternal::
279 const Int32 nb_levels_to_add = -m_min_level;
280 m_ori_level += nb_levels_to_add;
282 if (nb_levels_to_add == 0) {
286 m_max_level += nb_levels_to_add;
287 m_min_level += nb_levels_to_add;
289 const Integer to_div = m_pattern * nb_levels_to_add;
290 if (m_dimension == 2) {
291 m_nb_cell_ground.x /= to_div;
292 m_nb_cell_ground.y /= to_div;
296 m_nb_cell_ground /= to_div;
302 auto* cmgi = ICartesianMeshGenerationInfo::getReference(m_mesh,
false);
308 cmgi->setOwnCellOffsets(v[0] / to_div, v[1] / to_div, v[2] / to_div);
312 cmgi->setGlobalNbCells(v[0] / to_div, v[1] / to_div, v[2] / to_div);
316 cmgi->setOwnNbCells(v[0] / to_div, v[1] / to_div, v[2] / to_div);
326Int64 CartesianMeshNumberingMngInternal::
327firstCellUniqueId(
Int32 level)
const
329 return m_first_cell_uid_level[level - m_min_level];
335Int64 CartesianMeshNumberingMngInternal::
336firstNodeUniqueId(
Int32 level)
const
338 return m_first_node_uid_level[level - m_min_level];
344Int64 CartesianMeshNumberingMngInternal::
345firstFaceUniqueId(
Int32 level)
const
347 return m_first_face_uid_level[level - m_min_level];
354globalNbCellsX(
Int32 level)
const
356 return static_cast<CartCoord>(
static_cast<Real>(m_nb_cell_ground.x) * std::pow(m_pattern, level));
363globalNbCellsY(
Int32 level)
const
365 return static_cast<CartCoord>(
static_cast<Real>(m_nb_cell_ground.y) * std::pow(m_pattern, level));
372globalNbCellsZ(
Int32 level)
const
374 return static_cast<CartCoord>(
static_cast<Real>(m_nb_cell_ground.z) * std::pow(m_pattern, level));
381globalNbNodesX(
Int32 level)
const
390globalNbNodesY(
Int32 level)
const
399globalNbNodesZ(
Int32 level)
const
408globalNbFacesX(
Int32 level)
const
417globalNbFacesY(
Int32 level)
const
426globalNbFacesZ(
Int32 level)
const
435globalNbFacesXCartesianView(
Int32 level)
const
444globalNbFacesYCartesianView(
Int32 level)
const
453globalNbFacesZCartesianView(
Int32 level)
const
461Int64 CartesianMeshNumberingMngInternal::
462nbCellInLevel(
Int32 level)
const
464 if (m_dimension == 2) {
466 return nb_cell.x * nb_cell.y;
470 return nb_cell.x * nb_cell.y * nb_cell.z;
476Int64 CartesianMeshNumberingMngInternal::
477nbNodeInLevel(
Int32 level)
const
479 if (m_dimension == 2) {
481 return (nb_cell.x + 1) * (nb_cell.y + 1);
485 return (nb_cell.x + 1) * (nb_cell.y + 1) * (nb_cell.z + 1);
491Int64 CartesianMeshNumberingMngInternal::
492nbFaceInLevel(
Int32 level)
const
494 if (m_dimension == 2) {
496 return (nb_cell.x * nb_cell.y) * 2 + nb_cell.x * 2 + nb_cell.y;
500 return (nb_cell.x + 1) * nb_cell.y * nb_cell.z + (nb_cell.y + 1) * nb_cell.z * nb_cell.x + (nb_cell.z + 1) * nb_cell.x * nb_cell.y;
506Int32 CartesianMeshNumberingMngInternal::
515Int32 CartesianMeshNumberingMngInternal::
516cellLevel(
Int64 uid)
const
521 for (
Int32 i = m_min_level; i <= m_max_level; ++i) {
523 if (first_uid <= uid && first_uid > max) {
530 ARCANE_FATAL(
"CellUID is not in any patch (UID too low)");
533 ARCANE_FATAL(
"CellUID is not in any patch (UID too high)");
542Int32 CartesianMeshNumberingMngInternal::
543nodeLevel(
Int64 uid)
const
548 for (
Int32 i = m_min_level; i <= m_max_level; ++i) {
550 if (first_uid <= uid && first_uid > max) {
557 ARCANE_FATAL(
"NodeUID is not in any patch (UID too low)");
560 ARCANE_FATAL(
"NodeUID is not in any patch (UID too high)");
569Int32 CartesianMeshNumberingMngInternal::
570faceLevel(
Int64 uid)
const
575 for (
Int32 i = m_min_level; i <= m_max_level; ++i) {
577 if (first_uid <= uid && first_uid > max) {
584 ARCANE_FATAL(
"FaceUID is not in any patch (UID too low)");
587 ARCANE_FATAL(
"FaceUID is not in any patch (UID too high)");
600 if (level_from == level_to) {
603 if (level_from < level_to) {
604 return coord *
static_cast<CartCoord>(std::pow(m_pattern, (level_to - level_from)));
606 return coord /
static_cast<CartCoord>(std::pow(m_pattern, (level_from - level_to)));
615 if (level_from == level_to) {
618 if (level_from < level_to) {
619 return coord *
static_cast<CartCoord>(std::pow(m_pattern, (level_to - level_from)));
621 return coord /
static_cast<CartCoord>(std::pow(m_pattern, (level_from - level_to)));
651 if (level_from == level_to) {
655 if (level_from < level_to) {
656 const Int32 pattern = m_pattern * (level_to - level_from);
657 if (coord % 2 == 0) {
660 return ((coord - 1) *
pattern) + 1;
663 const Int32 pattern = m_pattern * (level_from - level_to);
664 if (coord % 2 == 0) {
665 if (coord % (
pattern * 2) == 0) {
679 return coord - (((coord - 1) / (
pattern * 2) * (2 * (
pattern - 1))) + ((coord - 1) % (
pattern * 2)));
692 uid -= first_cell_uid;
694 const Int64 to2d = uid % (nb_cell_x * nb_cell_y);
696 return {
static_cast<CartCoord>(to2d % nb_cell_x),
static_cast<CartCoord>(to2d / nb_cell_x),
static_cast<CartCoord>(uid / (nb_cell_x * nb_cell_y)) };
703cellUniqueIdToCoord(
Cell cell)
718 uid -= first_cell_uid;
720 const Int64 to2d = uid % (nb_cell_x * nb_cell_y);
721 return static_cast<CartCoord>(to2d % nb_cell_x);
728cellUniqueIdToCoordX(
Cell cell)
743 uid -= first_cell_uid;
745 const Int64 to2d = uid % (nb_cell_x * nb_cell_y);
746 return static_cast<CartCoord>(to2d / nb_cell_x);
753cellUniqueIdToCoordY(
Cell cell)
768 uid -= first_cell_uid;
770 return static_cast<CartCoord>(uid / (nb_cell_x * nb_cell_y));
777cellUniqueIdToCoordZ(
Cell cell)
792 uid -= first_node_uid;
794 const Int64 to2d = uid % (nb_node_x * nb_node_y);
795 return static_cast<CartCoord>(to2d % nb_node_x);
802nodeUniqueIdToCoordX(
Node node)
818 uid -= first_node_uid;
820 const Int64 to2d = uid % (nb_node_x * nb_node_y);
821 return static_cast<CartCoord>(to2d / nb_node_x);
828nodeUniqueIdToCoordY(
Node node)
844 uid -= first_node_uid;
846 return static_cast<CartCoord>(uid / (nb_node_x * nb_node_y));
853nodeUniqueIdToCoordZ(
Node node)
865 if (m_dimension == 2) {
870 uid -= first_face_uid;
892 return static_cast<CartCoord>(uid % nb_face_x);
901 uid -= first_face_uid;
928 if (uid < three_parts_numbering.x) {
938 return static_cast<CartCoord>((uid % nb_face_x) * 2);
944 if (uid < three_parts_numbering.x + three_parts_numbering.y) {
945 uid -= three_parts_numbering.x;
954 return static_cast<CartCoord>((uid % nb_cell_x) * 2 + 1);
960 uid -= three_parts_numbering.x + three_parts_numbering.y;
969 return static_cast<CartCoord>((uid % nb_cell_x) * 2 + 1);
976faceUniqueIdToCoordX(
Face face)
988 if (m_dimension == 2) {
992 uid -= first_face_uid;
1015 const Int64 flat_pos = uid / nb_face_x;
1016 return static_cast<CartCoord>((flat_pos * 2) + (flat_pos % 2 == uid % 2 ? 0 : 1) - 1);
1026 uid -= first_face_uid;
1053 if (uid < three_parts_numbering.x) {
1054 uid %= nb_face_x * nb_cell_y;
1065 return static_cast<CartCoord>((uid / nb_face_x) * 2 + 1);
1071 if (uid < three_parts_numbering.x + three_parts_numbering.y) {
1072 uid -= three_parts_numbering.x;
1073 uid %= nb_cell_x * nb_face_y;
1084 return static_cast<CartCoord>((uid / nb_cell_x) * 2);
1090 uid -= three_parts_numbering.x + three_parts_numbering.y;
1091 uid %= nb_cell_x * nb_cell_y;
1102 return static_cast<CartCoord>((uid / nb_cell_x) * 2 + 1);
1109faceUniqueIdToCoordY(
Face face)
1129 uid -= first_face_uid;
1156 if (uid < three_parts_numbering.x) {
1167 return static_cast<CartCoord>((uid / (nb_face_x * nb_cell_y)) * 2 + 1);
1173 if (uid < three_parts_numbering.x + three_parts_numbering.y) {
1174 uid -= three_parts_numbering.x;
1185 return static_cast<CartCoord>((uid / (nb_cell_x * nb_face_y)) * 2 + 1);
1191 uid -= three_parts_numbering.x + three_parts_numbering.y;
1202 return static_cast<CartCoord>((uid / (nb_cell_x * nb_cell_y)) * 2);
1209faceUniqueIdToCoordZ(
Face face)
1218Int64 CartesianMeshNumberingMngInternal::
1225 return (cell_coord.x + cell_coord.y * nb_cell_x + cell_coord.z * nb_cell_x * nb_cell_y) + first_cell_uid;
1231Int64 CartesianMeshNumberingMngInternal::
1237 return (cell_coord.x + cell_coord.y * nb_cell_x) + first_cell_uid;
1243Int64 CartesianMeshNumberingMngInternal::
1250 return (node_coord.x + node_coord.y * nb_node_x + node_coord.z * nb_node_x * nb_node_y) + first_node_uid;
1256Int64 CartesianMeshNumberingMngInternal::
1262 return (node_coord.x + node_coord.y * nb_node_x) + first_node_uid;
1268Int64 CartesianMeshNumberingMngInternal::
1304 if (face_coord.x % 2 == 0) {
1314 uid += face_coord.x + (face_coord.y * nb_face_x) + (face_coord.z * nb_face_x * nb_cell_y);
1318 else if (face_coord.y % 2 == 0) {
1319 uid += three_parts_numbering.x;
1329 uid += face_coord.x + (face_coord.y * nb_cell_x) + (face_coord.z * nb_cell_x * nb_face_y);
1333 else if (face_coord.z % 2 == 0) {
1334 uid += three_parts_numbering.x + three_parts_numbering.y;
1344 uid += face_coord.x + (face_coord.y * nb_cell_x) + (face_coord.z * nb_cell_x * nb_cell_y);
1347 ARCANE_FATAL(
"Bizarre -- x : {0} -- y : {1} -- z : {2}", face_coord.x, face_coord.y, face_coord.z);
1356Int64 CartesianMeshNumberingMngInternal::
1384 const Int64 a = (face_coord.y / 2) * nb_face_x;
1386 return (face_coord.x + a - 1) + first_face_uid;
1392Int32 CartesianMeshNumberingMngInternal::
1395 return (m_dimension == 2 ? 4 : 8);
1401void CartesianMeshNumberingMngInternal::
1411 const Int64 x0 = cell_coord.x + 0;
1412 const Int64 x1 = cell_coord.x + 1;
1414 const Int64 y0 = (cell_coord.y + 0) * nb_node_x;
1415 const Int64 y1 = (cell_coord.y + 1) * nb_node_x;
1417 const Int64 z0 = (cell_coord.z + 0) * nb_node_x * nb_node_y;
1418 const Int64 z1 = (cell_coord.z + 1) * nb_node_x * nb_node_y;
1420 uid[0] = x0 + y0 + z0 + first_node_uid;
1421 uid[1] = x1 + y0 + z0 + first_node_uid;
1422 uid[2] = x1 + y1 + z0 + first_node_uid;
1423 uid[3] = x0 + y1 + z0 + first_node_uid;
1425 uid[4] = x0 + y0 + z1 + first_node_uid;
1426 uid[5] = x1 + y0 + z1 + first_node_uid;
1427 uid[6] = x1 + y1 + z1 + first_node_uid;
1428 uid[7] = x0 + y1 + z1 + first_node_uid;
1434void CartesianMeshNumberingMngInternal::
1443 const Int64 x0 = cell_coord.x + 0;
1444 const Int64 x1 = cell_coord.x + 1;
1446 const Int64 y0 = (cell_coord.y + 0) * nb_node_x;
1447 const Int64 y1 = (cell_coord.y + 1) * nb_node_x;
1449 uid[0] = x0 + y0 + first_node_uid;
1450 uid[1] = x1 + y0 + first_node_uid;
1451 uid[2] = x1 + y1 + first_node_uid;
1452 uid[3] = x0 + y1 + first_node_uid;
1458void CartesianMeshNumberingMngInternal::
1461 if (m_dimension == 2) {
1474void CartesianMeshNumberingMngInternal::
1483Int32 CartesianMeshNumberingMngInternal::
1486 return (m_dimension == 2 ? 4 : 6);
1492void CartesianMeshNumberingMngInternal::
1499 const Int64x3 nb_face(nb_cell + 1);
1543 const Int64 total_face_yz = nb_face.x * nb_cell.y * nb_cell.z;
1544 const Int64 total_face_yz_zx = total_face_yz + nb_face.y * nb_cell.z * nb_cell.x;
1546 const Int64 nb_cell_before_j = cell_coord.y * nb_cell.x;
1548 uid[0] = (cell_coord.z * nb_cell.x * nb_cell.y) + nb_cell_before_j + cell_coord.x + total_face_yz_zx;
1550 uid[3] = uid[0] + nb_cell.x * nb_cell.y;
1552 uid[1] = (cell_coord.z * nb_face.x * nb_cell.y) + (cell_coord.y * nb_face.x) + cell_coord.x;
1554 uid[4] = uid[1] + 1;
1556 uid[2] = (cell_coord.z * nb_cell.x * nb_face.y) + nb_cell_before_j + cell_coord.x + total_face_yz;
1558 uid[5] = uid[2] + nb_cell.x;
1560 uid[0] += first_face_uid;
1561 uid[1] += first_face_uid;
1562 uid[2] += first_face_uid;
1563 uid[3] += first_face_uid;
1564 uid[4] += first_face_uid;
1565 uid[5] += first_face_uid;
1573void CartesianMeshNumberingMngInternal::
1580 const Int64 nb_face_x = nb_cell_x + 1;
1601 uid[0] = cell_coord.x * 2 + cell_coord.y * (nb_face_x + nb_cell_x);
1605 uid[2] = uid[0] + (nb_face_x + nb_cell_x);
1608 uid[3] = uid[2] - 1;
1611 uid[1] = uid[2] + 1;
1613 uid[0] += first_face_uid;
1614 uid[1] += first_face_uid;
1615 uid[2] += first_face_uid;
1616 uid[3] += first_face_uid;
1622void CartesianMeshNumberingMngInternal::
1625 if (m_dimension == 2) {
1638void CartesianMeshNumberingMngInternal::
1647void CartesianMeshNumberingMngInternal::
1650 ARCANE_ASSERT((uid.
size() == 27), (
"Size of uid array != 27"));
1659 const CartCoord coord_around_cell_z = cell_coord.z + k;
1660 if (coord_around_cell_z >= 0 && coord_around_cell_z < nb_cells_z) {
1662 const CartCoord coord_around_cell_y = cell_coord.y + j;
1664 if (coord_around_cell_y >= 0 && coord_around_cell_y < nb_cells_y) {
1666 const CartCoord coord_around_cell_x = cell_coord.x + i;
1668 if (coord_around_cell_x >= 0 && coord_around_cell_x < nb_cells_x) {
1669 uid[(i + 1) + ((j + 1) * 3) + ((k + 1) * 9)] =
cellUniqueId(
CartCoord3{ coord_around_cell_x, coord_around_cell_y, coord_around_cell_z }, level);
1681void CartesianMeshNumberingMngInternal::
1684 ARCANE_ASSERT((uid.
size() == 9), (
"Size of uid array != 9"));
1692 const CartCoord coord_around_cell_y = cell_coord.y + j;
1693 if (coord_around_cell_y >= 0 && coord_around_cell_y < nb_cells_y) {
1696 const CartCoord coord_around_cell_x = cell_coord.x + i;
1697 if (coord_around_cell_x >= 0 && coord_around_cell_x < nb_cells_x) {
1698 uid[(i + 1) + ((j + 1) * 3)] =
cellUniqueId(
CartCoord2{ coord_around_cell_x, coord_around_cell_y }, level);
1708void CartesianMeshNumberingMngInternal::
1711 if (m_dimension == 2) {
1724void CartesianMeshNumberingMngInternal::
1733void CartesianMeshNumberingMngInternal::
1736 ARCANE_ASSERT((uid.
size() == 8), (
"Size of uid array != 8"));
1745 const CartCoord coord_cell_z = node_coord.z + k;
1746 if (coord_cell_z >= 0 && coord_cell_z < nb_cells_z) {
1749 const CartCoord coord_cell_y = node_coord.y + j;
1750 if (coord_cell_y >= 0 && coord_cell_y < nb_cells_y) {
1753 const CartCoord coord_cell_x = node_coord.x + i;
1754 if (coord_cell_x >= 0 && coord_cell_x < nb_cells_x) {
1755 uid[(i + 1) + ((j + 1) * 2) + ((k + 1) * 4)] =
cellUniqueId(
CartCoord3{ coord_cell_x, coord_cell_y, coord_cell_z }, level);
1767void CartesianMeshNumberingMngInternal::
1770 ARCANE_ASSERT((uid.
size() == 4), (
"Size of uid array != 4"));
1778 const CartCoord coord_cell_y = node_coord.y + j;
1779 if (coord_cell_y >= 0 && coord_cell_y < nb_cells_y) {
1782 const CartCoord coord_cell_x = node_coord.x + i;
1783 if (coord_cell_x >= 0 && coord_cell_x < nb_cells_x) {
1794void CartesianMeshNumberingMngInternal::
1797 if (m_dimension == 2) {
1810void CartesianMeshNumberingMngInternal::
1819void CartesianMeshNumberingMngInternal::
1820setChildNodeCoordinates(
Cell parent_cell)
1828 const Real3& node0(nodes_coords[parent_cell.
node(0)]);
1829 const Real3& node1(nodes_coords[parent_cell.
node(1)]);
1830 const Real3& node2(nodes_coords[parent_cell.
node(2)]);
1831 const Real3& node3(nodes_coords[parent_cell.
node(3)]);
1833 if (m_dimension == 2) {
1865 const Real x =
static_cast<Real>(pos_x) /
static_cast<Real>(m_pattern);
1866 const Real y =
static_cast<Real>(pos_y) /
static_cast<Real>(m_pattern);
1868 const Real i = (node3.
x - node0.
x) * y + node0.
x;
1869 const Real j = (node2.
x - node1.
x) * y + node1.
x;
1871 const Real k = (node1.
y - node0.
y) * x + node0.
y;
1872 const Real l = (node2.
y - node3.
y) * x + node3.
y;
1874 const Real tx = (j - i) * x + i;
1875 const Real ty = (l - k) * y + k;
1892 return { tx, ty, 0 };
1895 constexpr CartCoord node_1d_2d_x[] = { 0, 1, 1, 0 };
1896 constexpr CartCoord node_1d_2d_y[] = { 0, 0, 1, 1 };
1898 for (
CartCoord j = 0; j < m_pattern; ++j) {
1899 for (
CartCoord i = 0; i < m_pattern; ++i) {
1901 Int32 begin = (i == 0 && j == 0 ? 0 : j == 0 ? 1
1906 for (
Int32 inode = begin; inode < end; ++inode) {
1907 nodes_coords[child.
node(inode)] = txty(i + node_1d_2d_x[inode], j + node_1d_2d_y[inode]);
1920 const Real3& node4(nodes_coords[parent_cell.
node(4)]);
1921 const Real3& node5(nodes_coords[parent_cell.
node(5)]);
1922 const Real3& node6(nodes_coords[parent_cell.
node(6)]);
1923 const Real3& node7(nodes_coords[parent_cell.
node(7)]);
1930 const Real x =
static_cast<Real>(pos_x) /
static_cast<Real>(m_pattern);
1931 const Real y =
static_cast<Real>(pos_y) /
static_cast<Real>(m_pattern);
1932 const Real z =
static_cast<Real>(pos_z) /
static_cast<Real>(m_pattern);
1935 const Real3 m = (node4 - node0) * z + node0;
1936 const Real3 n = (node5 - node1) * z + node1;
1937 const Real3 o = (node6 - node2) * z + node2;
1938 const Real3 p = (node7 - node3) * z + node3;
1941 const Real i = (p.
x - m.
x) * y + m.
x;
1942 const Real j = (o.
x - n.
x) * y + n.
x;
1944 const Real tx = (j - i) * x + i;
1946 const Real k = (n.
y - m.
y) * x + m.
y;
1947 const Real l = (o.
y - p.
y) * x + p.
y;
1949 const Real ty = (l - k) * y + k;
1951 const Real q = (p.
z - m.
z) * y + m.
z;
1952 const Real r = (o.
z - n.
z) * y + n.
z;
1954 const Real s = (n.
z - m.
z) * x + m.
z;
1955 const Real t = (o.
z - p.
z) * x + p.
z;
1957 const Real tz = (((r - q) * x + q) + ((t - s) * y + s)) * 0.5;
1987 return { tx, ty, tz };
1990 constexpr CartCoord node_1d_3d_x[] = { 0, 1, 1, 0, 0, 1, 1, 0 };
1991 constexpr CartCoord node_1d_3d_y[] = { 0, 0, 1, 1, 0, 0, 1, 1 };
1992 constexpr CartCoord node_1d_3d_z[] = { 0, 0, 0, 0, 1, 1, 1, 1 };
1994 for (
CartCoord k = 0; k < m_pattern; ++k) {
1995 for (
CartCoord j = 0; j < m_pattern; ++j) {
1996 for (
CartCoord i = 0; i < m_pattern; ++i) {
2003 for (
Int32 inode = begin; inode < end; ++inode) {
2004 nodes_coords[child.
node(inode)] = txtytz(i + node_1d_3d_x[inode], j + node_1d_3d_y[inode], k + node_1d_3d_z[inode]);
2022void CartesianMeshNumberingMngInternal::
2023setParentNodeCoordinates(
Cell parent_cell)
2031 if (m_dimension == 2) {
2046 nodes_coords[parent_cell.
node(6)] = nodes_coords[
childCellOfCell(parent_cell,
CartCoord3(m_pattern - 1, m_pattern - 1, m_pattern - 1)).node(6)];
2054Int64 CartesianMeshNumberingMngInternal::
2055parentCellUniqueIdOfCell(
Int64 uid,
Int32 level,
bool do_fatal)
2066 return NULL_ITEM_UNIQUE_ID;
2069 if (m_dimension == 2) {
2084Int64 CartesianMeshNumberingMngInternal::
2085parentCellUniqueIdOfCell(
Cell cell,
bool do_fatal)
2093Int64 CartesianMeshNumberingMngInternal::
2094childCellUniqueIdOfCell(
Cell cell,
CartCoord3 child_coord_in_parent)
2096 ARCANE_ASSERT((child_coord_in_parent.x < m_pattern && child_coord_in_parent.x >= 0), (
"Bad child_coord_in_parent.x"))
2097 ARCANE_ASSERT((child_coord_in_parent.y < m_pattern && child_coord_in_parent.y >= 0), (
"Bad child_coord_in_parent.y"))
2098 ARCANE_ASSERT((child_coord_in_parent.z < m_pattern && child_coord_in_parent.z >= 0), (
"Bad child_coord_in_parent.z"))
2112Int64 CartesianMeshNumberingMngInternal::
2113childCellUniqueIdOfCell(
Cell cell,
CartCoord2 child_coord_in_parent)
2115 ARCANE_ASSERT((child_coord_in_parent.x < m_pattern && child_coord_in_parent.x >= 0), (
"Bad child_coord_in_parent.x"))
2116 ARCANE_ASSERT((child_coord_in_parent.y < m_pattern && child_coord_in_parent.y >= 0), (
"Bad child_coord_in_parent.y"))
2129Int64 CartesianMeshNumberingMngInternal::
2130childCellUniqueIdOfCell(
Cell cell,
Int32 child_index_in_parent)
2132 if (m_dimension == 2) {
2133 ARCANE_ASSERT((child_index_in_parent < m_pattern * m_pattern && child_index_in_parent >= 0), (
"Bad child_index_in_parent"))
2137 child_index_in_parent % m_pattern,
2138 child_index_in_parent / m_pattern));
2141 ARCANE_ASSERT((child_index_in_parent < m_pattern * m_pattern * m_pattern && child_index_in_parent >= 0), (
"Bad child_index_in_parent"))
2143 const CartCoord to_2d = child_index_in_parent % (m_pattern * m_pattern);
2148 child_index_in_parent / (m_pattern * m_pattern)));
2154Cell CartesianMeshNumberingMngInternal::
2157 ARCANE_ASSERT((child_coord_in_parent.x < m_pattern && child_coord_in_parent.x >= 0), (
"Bad child_coord_in_parent.x"))
2158 ARCANE_ASSERT((child_coord_in_parent.y < m_pattern && child_coord_in_parent.y >= 0), (
"Bad child_coord_in_parent.y"))
2160 Cell child = cell.
hChild(child_coord_in_parent.x + (child_coord_in_parent.y * m_pattern) + (child_coord_in_parent.z * m_pattern * m_pattern));
2167 for (
Integer i = 0; i < nb_children; ++i) {
2180Cell CartesianMeshNumberingMngInternal::
2183 ARCANE_ASSERT((child_coord_in_parent.x < m_pattern && child_coord_in_parent.x >= 0), (
"Bad child_coord_in_parent.x"))
2184 ARCANE_ASSERT((child_coord_in_parent.y < m_pattern && child_coord_in_parent.y >= 0), (
"Bad child_coord_in_parent.y"))
2186 Cell child = cell.
hChild(child_coord_in_parent.x + (child_coord_in_parent.y * m_pattern));
2193 for (
Integer i = 0; i < nb_children; ++i) {
2206Int64 CartesianMeshNumberingMngInternal::
2207parentNodeUniqueIdOfNode(
Int64 uid,
Int32 level,
bool do_fatal)
2216 if (coord_x % m_pattern != 0 || coord_y % m_pattern != 0) {
2220 return NULL_ITEM_UNIQUE_ID;
2223 if (m_dimension == 2) {
2231 if (coord_z % m_pattern != 0) {
2235 return NULL_ITEM_UNIQUE_ID;
2246Int64 CartesianMeshNumberingMngInternal::
2247parentNodeUniqueIdOfNode(
Node node,
bool do_fatal)
2256Int64 CartesianMeshNumberingMngInternal::
2257childNodeUniqueIdOfNode(
Int64 uid,
Int32 level)
2259 if (m_dimension == 2) {
2274Int64 CartesianMeshNumberingMngInternal::
2275childNodeUniqueIdOfNode(
Node node)
2284Int64 CartesianMeshNumberingMngInternal::
2285parentFaceUniqueIdOfFace(
Int64 uid,
Int32 level,
bool do_fatal)
2287 if (m_converting_numbering_face && level == m_ori_level) {
2288 uid = m_face_ori_numbering_to_new[uid];
2305 if (parent_coord_x == -1 || parent_coord_y == -1) {
2309 return NULL_ITEM_UNIQUE_ID;
2315 if (m_dimension == 2) {
2316 if (m_converting_numbering_face && level - 1 == m_ori_level) {
2327 if (parent_coord_z == -1) {
2331 return NULL_ITEM_UNIQUE_ID;
2338 if (m_converting_numbering_face && level - 1 == m_ori_level) {
2339 return m_face_new_numbering_to_ori[
faceUniqueId(
CartCoord3(parent_coord_x, parent_coord_y, parent_coord_z), level - 1)];
2348Int64 CartesianMeshNumberingMngInternal::
2349parentFaceUniqueIdOfFace(
Face face,
bool do_fatal)
2358Int64 CartesianMeshNumberingMngInternal::
2359childFaceUniqueIdOfFace(
Int64 uid,
Int32 level,
Int32 child_index_in_parent)
2361 if (m_converting_numbering_face && level == m_ori_level) {
2362 uid = m_face_ori_numbering_to_new[uid];
2374 ARCANE_ASSERT((first_child_coord_x <
globalNbFacesXCartesianView(level + 1) && first_child_coord_x >= 0), (
"Bad first_child_coord_x"))
2375 ARCANE_ASSERT((first_child_coord_y <
globalNbFacesYCartesianView(level + 1) && first_child_coord_y >= 0), (
"Bad first_child_coord_y"))
2377 if (m_dimension == 2) {
2378 ARCANE_ASSERT((child_index_in_parent < m_pattern && child_index_in_parent >= 0), (
"Invalid child_index_in_parent"))
2380 if (coord_y % 2 == 0) {
2381 first_child_coord_x += child_index_in_parent * 2;
2383 else if (coord_x % 2 == 0) {
2384 first_child_coord_y += child_index_in_parent *
globalNbFacesY(level + 1);
2390 if (m_converting_numbering_face && level + 1 == m_ori_level) {
2391 return m_face_new_numbering_to_ori[
faceUniqueId(
CartCoord2(first_child_coord_x, first_child_coord_y), level + 1)];
2397 ARCANE_ASSERT((child_index_in_parent < m_pattern * m_pattern && child_index_in_parent >= 0), (
"Invalid child_index_in_parent"))
2403 ARCANE_ASSERT((first_child_coord_z <
globalNbFacesZCartesianView(level + 1) && first_child_coord_z >= 0), (
"Bad first_child_coord_z"))
2405 const CartCoord child_x = child_index_in_parent % m_pattern;
2406 const CartCoord child_y = child_index_in_parent / m_pattern;
2410 if (uid < three_parts_numbering.x) {
2411 first_child_coord_y += child_x * 2;
2412 first_child_coord_z += child_y * 2;
2414 else if (uid < three_parts_numbering.x + three_parts_numbering.y) {
2415 first_child_coord_x += child_x * 2;
2416 first_child_coord_z += child_y * 2;
2419 first_child_coord_x += child_x * 2;
2420 first_child_coord_y += child_y * 2;
2423 if (m_converting_numbering_face && level + 1 == m_ori_level) {
2424 return m_face_new_numbering_to_ori[
faceUniqueId(
CartCoord3(first_child_coord_x, first_child_coord_y, first_child_coord_z), level + 1)];
2427 return faceUniqueId(
CartCoord3(first_child_coord_x, first_child_coord_y, first_child_coord_z), level + 1);
2433Int64 CartesianMeshNumberingMngInternal::
2434childFaceUniqueIdOfFace(
Face face,
Int32 child_index_in_parent)
2443Int64x3 CartesianMeshNumberingMngInternal::
2444_face3DNumberingThreeParts(
Int32 level)
const
2447 return { (nb_cell.x + 1) * nb_cell.y * nb_cell.z, (nb_cell.y + 1) * nb_cell.z * nb_cell.x, (nb_cell.z + 1) * nb_cell.x * nb_cell.y };
2453void CartesianMeshNumberingMngInternal::
2457 array.
back() = elem;
2459 std::swap(array[i], array[i + 1]);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Integer size() const
Number of elements in the vector.
Modifiable view of an array of type T.
void fill(const T &o) noexcept
Fills the array with the value o.
constexpr Integer size() const noexcept
Returns the size of the array.
void resize(Int64 s)
Changes the number of elements in the array to s.
T & back()
Last element of the array.
CartCoord globalNbFacesXCartesianView(Int32 level) const override
Method allowing the retrieval of the size of the "Cartesian grid" view containing the faces.
Int32 pattern() const override
Method allowing the retrieval of the refinement pattern used in each cell. For example,...
Int64 childNodeUniqueIdOfNode(Int64 uid, Int32 level) override
Method to retrieve the uniqueId of a child node of a parent node.
Int64x3 _face3DNumberingThreeParts(Int32 level) const
Method to retrieve the number of faces for the three parts of the numbering.
Int64 nbNodeInLevel(Int32 level) const override
Method allowing the retrieval of the total number of nodes in a level.
Cell childCellOfCell(Cell cell, CartCoord3 child_coord_in_parent) override
Method to retrieve a child cell of a parent cell based on the position of the child cell within the p...
Int64 nbCellInLevel(Int32 level) const override
Method allowing the retrieval of the total number of cells in a level.
CartCoord faceUniqueIdToCoordX(Int64 uid, Int32 level) override
Method to retrieve the X coordinate of a face using its uniqueId.
void cellFaceUniqueIds(CartCoord3 cell_coord, Int32 level, ArrayView< Int64 > uid) override
Method to retrieve the uniqueIds of a cell's faces based on its coordinates.
CartCoord cellUniqueIdToCoordX(Int64 uid, Int32 level) override
Method to retrieve the X coordinate of a cell using its uniqueId.
Int64 childFaceUniqueIdOfFace(Int64 uid, Int32 level, Int32 child_index_in_parent) override
Method to retrieve the uniqueId of a child face of a parent face based on the index of the child face...
void cellUniqueIdsAroundCell(CartCoord3 cell_coord, Int32 level, ArrayView< Int64 > uid) override
Method to retrieve the uniqueIds of cells around a cell.
CartCoord3 cellUniqueIdToCoord(Int64 uid, Int32 level) override
Method to retrieve the coordinates of a cell using its uniqueId.
CartCoord offsetLevelToLevel(CartCoord coord, Int32 level_from, Int32 level_to) const override
Method allowing the retrieval of the position of the first child node/cell from the position of the p...
void cellUniqueIdsAroundNode(CartCoord3 node_coord, Int32 level, ArrayView< Int64 > uid) override
Method to retrieve the uniqueIds of cells around a node.
CartCoord nodeUniqueIdToCoordX(Int64 uid, Int32 level) override
Method to retrieve the X coordinate of a node using its uniqueId.
CartCoord globalNbFacesYCartesianView(Int32 level) const override
Method allowing the retrieval of the size of the "Cartesian grid" view containing the faces.
Int64 parentFaceUniqueIdOfFace(Int64 uid, Int32 level, bool do_fatal) override
Method to retrieve the uniqueId of a face's parent.
Int64 firstFaceUniqueId(Int32 level) const override
Method allowing the retrieval of the first unique ID used by the faces of a level....
Int64 nbFaceInLevel(Int32 level) const override
Method allowing the retrieval of the total number of faces in a level.
CartCoord nodeUniqueIdToCoordY(Int64 uid, Int32 level) override
Method to retrieve the Y coordinate of a node using its uniqueId.
Int32 faceLevel(Int64 uid) const override
Method allowing the retrieval of the level of a face with its UID.
CartCoord faceOffsetLevelToLevel(CartCoord coord, Int32 level_from, Int32 level_to) const override
Method to obtain the position of the first child face from the position of the parent face.
CartCoord globalNbCellsZ(Int32 level) const override
Method allowing the retrieval of the global number of cells in Z for a level.
CartCoord nodeUniqueIdToCoordZ(Int64 uid, Int32 level) override
Method to retrieve the Z coordinate of a node using its uniqueId.
Int64 firstCellUniqueId(Int32 level) const override
Method allowing the retrieval of the first unique ID used by the cells of a level....
Int64 parentNodeUniqueIdOfNode(Int64 uid, Int32 level, bool do_fatal) override
Method to retrieve the uniqueId of a node's parent.
CartCoord globalNbFacesZCartesianView(Int32 level) const override
Method allowing the retrieval of the size of the "Cartesian grid" view containing the faces.
Int32 nbNodeByCell() override
Method to retrieve the number of nodes in a cell.
CartCoord globalNbNodesX(Int32 level) const override
Method allowing the retrieval of the global number of nodes in X for a level.
CartCoord cellUniqueIdToCoordZ(Int64 uid, Int32 level) override
Method to retrieve the Z coordinate of a cell using its uniqueId.
Int32 nbFaceByCell() override
Method to retrieve the number of faces in a cell.
void cellNodeUniqueIds(CartCoord3 cell_coord, Int32 level, ArrayView< Int64 > uid) override
Method to retrieve the uniqueIds of the nodes of a cell from its coordinates.
CartCoord faceUniqueIdToCoordZ(Int64 uid, Int32 level) override
Method to retrieve the Z coordinate of a face using its uniqueId.
CartCoord faceUniqueIdToCoordY(Int64 uid, Int32 level) override
Method to retrieve the Y coordinate of a face using its uniqueId.
Int64 cellUniqueId(CartCoord3 cell_coord, Int32 level) override
Method to retrieve the uniqueId of a cell from its position and level.
CartCoord globalNbCellsX(Int32 level) const override
Method allowing the retrieval of the global number of cells in X for a level.
Int64 nodeUniqueId(CartCoord3 node_coord, Int32 level) override
Method to retrieve the uniqueId of a node from its position and level.
CartCoord globalNbCellsY(Int32 level) const override
Method allowing the retrieval of the global number of cells in Y for a level.
Int64 firstNodeUniqueId(Int32 level) const override
Method allowing the retrieval of the first unique ID used by the nodes of a level....
CartCoord globalNbNodesY(Int32 level) const override
Method allowing the retrieval of the global number of nodes in Y for a level.
Int64 faceUniqueId(CartCoord3 face_coord, Int32 level) override
Method to retrieve the uniqueId of a face from its position and level.
CartCoord globalNbFacesY(Int32 level) const override
Method allowing the retrieval of the global number of faces in Y for a level.
Int32 nodeLevel(Int64 uid) const override
Method allowing the retrieval of the level of a node with its UID.
Int64 childCellUniqueIdOfCell(Cell cell, CartCoord3 child_coord_in_parent) override
Method to retrieve the uniqueId of a child cell of a parent cell based on the position of the child c...
CartCoord globalNbFacesX(Int32 level) const override
Method allowing the retrieval of the global number of faces in X for a level.
CartCoord cellUniqueIdToCoordY(Int64 uid, Int32 level) override
Method to retrieve the Y coordinate of a cell using its uniqueId.
Int64 parentCellUniqueIdOfCell(Int64 uid, Int32 level, bool do_fatal) override
Method to retrieve the uniqueId of a cell's parent.
Int32 nbHChildren() const
Number of children for AMR.
Cell hChild(Int32 i) const
i-th AMR child
Constant view of an array of type T.
virtual TraceMessage info()=0
Stream for an information message.
Int32 flags() const
Flags of the entity.
@ II_JustAdded
The entity has just been added.
@ II_JustRefined
The entity has just been refined.
Node node(Int32 i) const
i-th node of the entity
ItemUniqueId uniqueId() const
Unique identifier across all domains.
impl::ItemBase itemBase() const
Internal part of the entity.
Class managing a 3-dimensional real vector.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
T max(const T &a, const T &b, const T &c)
Returns the maximum of three elements.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 CartCoord
Represents a coordinate of an element in the Cartesian grid (in X or Y or Z).
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
double Real
Type representing a real number.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
Int32x2 CartCoord2
Represents the 2D coordinates of an element in the Cartesian grid {x, y}.
std::int32_t Int32
Signed integer type of 32 bits.
Int32x3 CartCoord3
Represents the 3D coordinates of an element in the Cartesian grid {x, y, z}.
Real y
second component of the triplet
Real z
third component of the triplet
Real x
first component of the triplet