14#include "arcane/utils/TraceAccessor.h"
15#include "arcane/utils/NotImplementedException.h"
16#include "arcane/utils/AutoDestroyUserData.h"
17#include "arcane/utils/IUserDataList.h"
18#include "arcane/utils/Ref.h"
19#include "arcane/utils/ScopedPtr.h"
20#include "arcane/utils/PlatformUtils.h"
22#include "arcane/utils/Convert.h"
24#include "arcane/core/IMesh.h"
25#include "arcane/core/ItemPrinter.h"
26#include "arcane/core/IItemFamily.h"
27#include "arcane/core/IParallelMng.h"
28#include "arcane/core/VariableTypes.h"
29#include "arcane/core/Properties.h"
30#include "arcane/core/IMeshModifier.h"
31#include "arcane/core/MeshStats.h"
32#include "arcane/core/ICartesianMeshGenerationInfo.h"
33#include "arcane/core/MeshEvents.h"
34#include "arcane/core/MeshKind.h"
35#include "arcane/core/internal/IMeshInternal.h"
37#include "arcane/cartesianmesh/internal/CartesianPatchGroup.h"
38#include "arcane/cartesianmesh/ICartesianMesh.h"
39#include "arcane/cartesianmesh/AMRZonePosition.h"
40#include "arcane/cartesianmesh/CartesianConnectivity.h"
41#include "arcane/cartesianmesh/CartesianMeshRenumberingInfo.h"
42#include "arcane/cartesianmesh/CartesianMeshCoarsening.h"
43#include "arcane/cartesianmesh/CartesianMeshCoarsening2.h"
44#include "arcane/cartesianmesh/CartesianMeshPatchListView.h"
45#include "arcane/cartesianmesh/internal/CartesianMeshPatch.h"
46#include "arcane/cartesianmesh/internal/ICartesianMeshInternal.h"
48#include "arcane/cartesianmesh/internal/CartesianMeshUniqueIdRenumbering.h"
49#include "arcane/cartesianmesh/v2/CartesianMeshUniqueIdRenumberingV2.h"
50#include "arcane/cartesianmesh/CartesianMeshNumberingMng.h"
52#include "arcane/cartesianmesh/internal/CartesianMeshAMRPatchMng.h"
53#include "arcane/core/IGhostLayerMng.h"
54#include "arcane/cartesianmesh/internal/CartesianMeshNumberingMngInternal.h"
79class CartesianMeshImpl
84 :
public ICartesianMeshInternal
88 explicit InternalApi(CartesianMeshImpl* cartesian_mesh)
89 : m_cartesian_mesh(cartesian_mesh)
97 return m_cartesian_mesh->_createCartesianMeshCoarsening2();
101 m_cartesian_mesh->_addPatchFromExistingChildren(parent_cells_local_id);
103 void initCartesianMeshAMRPatchMng()
override
105 if (m_numbering_mng.
isNull()) {
106 initCartesianMeshNumberingMngInternal();
109 m_amr_mng =
makeRef(
new CartesianMeshAMRPatchMng(m_cartesian_mesh, m_numbering_mng.
get()));
116 void initCartesianMeshNumberingMngInternal()
override
118 if (m_numbering_mng.
isNull()) {
119 m_numbering_mng =
makeRef(
new CartesianMeshNumberingMngInternal(m_cartesian_mesh->
mesh()));
124 return m_numbering_mng;
126 CartesianPatchGroup& cartesianPatchGroup()
override {
return m_cartesian_mesh->_cartesianPatchGroup(); }
128 void saveInfosInProperties()
override { m_cartesian_mesh->_saveInfosInProperties(); }
132 CartesianMeshImpl* m_cartesian_mesh =
nullptr;
143 void build()
override;
153 return m_all_items_direction_info->cellDirection(dir);
158 return m_all_items_direction_info->cellDirection(idir);
163 return m_all_items_direction_info->faceDirection(dir);
168 return m_all_items_direction_info->faceDirection(idir);
173 return m_all_items_direction_info->nodeDirection(dir);
178 return m_all_items_direction_info->nodeDirection(idir);
187 return m_connectivity;
212 ICartesianMeshInternal*
_internalApi()
override {
return &m_internal_api; }
214 void computeDirectionsPatchV2(
Integer index)
override;
221 CartesianPatchGroup& _cartesianPatchGroup() {
return m_patch_group; }
222 void _computeDirectionsV2();
226 InternalApi m_internal_api;
229 Int32 m_local_face_direction[3] = { -1, -1, -1 };
230 IMesh* m_mesh =
nullptr;
231 Ref<CartesianMeshPatch> m_all_items_direction_info;
232 CartesianConnectivity m_connectivity;
233 UniqueArray<CartesianConnectivity::Index> m_nodes_to_cell_storage;
234 UniqueArray<CartesianConnectivity::Index> m_cells_to_node_storage;
235 UniqueArray<CartesianConnectivity::Permutation> m_permutation_storage;
236 bool m_is_amr =
false;
238 CartesianPatchGroup m_patch_group;
239 ScopedPtrT<Properties> m_properties;
241 EventObserverPool m_event_pool;
242 bool m_is_mesh_event_added =
false;
243 Int64 m_mesh_timestamp = 0;
248 void _computeMeshDirection(CartesianMeshPatch& cdi,
eMeshDirection dir,
253 void _computeMeshDirectionV2(CartesianMeshPatch& cdi,
eMeshDirection dir,
259 void _applyRefine(
const AMRZonePosition& position);
260 void _applyCoarse(
const AMRZonePosition& zone_position);
261 void _addPatch(ConstArrayView<Int32> parent_cells);
262 void _saveInfosInProperties();
264 std::tuple<CellGroup, NodeGroup>
266 void _checkNeedComputeDirections();
267 void _checkAddObservableMeshChanged();
274arcaneCreateCartesianMesh(
IMesh* mesh)
285CartesianMeshImpl(
IMesh* mesh)
287, m_internal_api(this)
293, m_amr_type(mesh->meshKind().meshAMRKind())
296 m_internal_api.initCartesianMeshNumberingMngInternal();
297 m_internal_api.initCartesianMeshAMRPatchMng();
299 m_all_items_direction_info = m_patch_group.groundPatch();
305void CartesianMeshImpl::
308 m_properties =
new Properties(*(
mesh()->properties()),
"CartesianMesh");
310 m_internal_api.cartesianMeshNumberingMngInternal()->build();
312 m_patch_group.build();
317 const Int32 SERIALIZE_VERSION = 1;
323void CartesianMeshImpl::
324_checkNeedComputeDirections()
327 if (m_mesh_timestamp != new_timestamp) {
328 info() <<
"Mesh timestamp has changed (old=" << m_mesh_timestamp <<
" new=" << new_timestamp <<
")";
336void CartesianMeshImpl::
337_saveInfosInProperties()
340 m_properties->set(
"Version", SERIALIZE_VERSION);
342 m_patch_group.saveInfosInProperties();
345 m_internal_api.cartesianMeshNumberingMngInternal()->saveInfosInProperties();
356 info() <<
"Creating 'CartesianMesh' infos from dump";
359 m_internal_api.cartesianMeshNumberingMngInternal()->recreateFromDump();
360 m_internal_api.cartesianMeshNumberingMngInternal()->printStatus();
364 Int32 v = m_properties->getInt32(
"Version");
365 if (v != SERIALIZE_VERSION)
366 ARCANE_FATAL(
"Bad serializer version: trying to read from incompatible checkpoint v={0} expected={1}",
367 v, SERIALIZE_VERSION);
369 m_patch_group.recreateFromDump();
371 m_all_items_direction_info = m_patch_group.groundPatch();
379void CartesianMeshImpl::
380_checkAddObservableMeshChanged()
382 if (m_is_mesh_event_added)
384 m_is_mesh_event_added =
true;
387 auto f1 = [&](
const MeshEventArgs&) { this->_checkNeedComputeDirections(); };
399 m_internal_api.cartesianMeshNumberingMngInternal()->renumberingFacesLevel0FromOriginalArcaneNumbering();
400 _computeDirectionsV2();
403 info() <<
"CartesianMesh: computeDirections()";
406 _checkAddObservableMeshChanged();
408 m_is_amr = m_mesh->isAmrActivated();
418 for (NodeLocalId inode : cell.
nodeIds())
419 center += nodes_coord[inode];
421 cells_center[icell] = center;
426 for (NodeLocalId inode : face.
nodeIds())
427 center += nodes_coord[inode];
429 faces_center[iface] = center;
434 Int32 next_face_x = -1;
435 Int32 next_face_y = -1;
436 Int32 next_face_z = -1;
439 Cell cell0 = cell_view[0];
442 Real3 cell_center = cells_center[cell0];
449 info(4) <<
"Cartesian mesh compute directions is_amr=" << m_is_amr;
451 for (
Integer i = 0; i < nb_node; ++i) {
453 info(4) <<
"Node I=" << i <<
" node=" <<
ItemPrinter(node) <<
" pos=" << nodes_coord[node];
456 bool is_3d = m_mesh->dimension() == 3;
466 for (
Integer i = 0; i < nb_face; ++i) {
469 Real3 next_center = faces_center[f];
471 Real diff_x = next_center.
x - cell_center.
x;
472 Real diff_y = next_center.
y - cell_center.
y;
473 Real diff_z = next_center.
z - cell_center.
z;
475 info(4) <<
"NEXT_FACE=" <<
ItemPrinter(f) <<
" center=" << next_center <<
" diff=" <<
Real3(diff_x, diff_y, diff_z);
477 if (diff_x > max_x) {
482 if (diff_y > max_y) {
487 if (diff_z > max_z) {
492 info(4) <<
"Advance in direction X -> " << next_face_x;
493 info(4) <<
"Advance in direction Y -> " << next_face_y;
494 info(4) <<
"Advance in direction Z -> " << next_face_z;
500 for (
Integer i = 0; i < nb_face; ++i) {
503 Real3 next_center = faces_center[f];
505 Real diff_x = next_center.
x - cell_center.
x;
506 Real diff_y = next_center.
y - cell_center.
y;
508 info(4) <<
"NEXT_FACE=" <<
ItemPrinter(f) <<
" center=" << next_center <<
" diff=" <<
Real2(diff_x, diff_y);
510 if (diff_x > max_x) {
515 if (diff_y > max_y) {
520 info(4) <<
"Advance in direction X -> " << next_face_x;
521 info(4) <<
"Advance in direction Y -> " << next_face_y;
523 m_all_items_direction_info->_internalComputeNodeCellInformations(cell0, cells_center[cell0], nodes_coord);
525 info() <<
"Informations from IMesh properties:";
527 auto* cmgi = ICartesianMeshGenerationInfo::getReference(m_mesh,
true);
529 info() <<
"GlobalNbCell = " << cmgi->globalNbCells();
530 info() <<
"OwnNbCell: " << cmgi->ownNbCells();
531 info() <<
"SubDomainOffset: " << cmgi->subDomainOffsets();
532 info() <<
"OwnCellOffset: " << cmgi->ownCellOffsets();
537 auto x = _buildPatchGroups(
mesh()->allLevelCells(0), 0);
538 all_cells = std::get<0>(x);
539 all_nodes = std::get<1>(x);
542 if (next_face_x != (-1)) {
543 m_local_face_direction[
MD_DirX] = next_face_x;
544 _computeMeshDirection(*m_all_items_direction_info.get(),
MD_DirX, cells_center, faces_center, all_cells, all_nodes);
546 if (next_face_y != (-1)) {
547 m_local_face_direction[
MD_DirY] = next_face_y;
548 _computeMeshDirection(*m_all_items_direction_info.get(),
MD_DirY, cells_center, faces_center, all_cells, all_nodes);
550 if (next_face_z != (-1)) {
551 m_local_face_direction[
MD_DirZ] = next_face_z;
552 _computeMeshDirection(*m_all_items_direction_info.get(),
MD_DirZ, cells_center, faces_center, all_cells, all_nodes);
556 for (
Integer idir = 0, nb_dir =
mesh()->dimension(); idir < nb_dir; ++idir) {
558 cdm._internalSetOffsetAndNbCellInfos(cmgi->globalNbCells()[idir], cmgi->ownNbCells()[idir],
559 cmgi->subDomainOffsets()[idir], cmgi->ownCellOffsets()[idir]);
562 info() <<
"Compute cartesian connectivity";
564 m_permutation_storage.resize(1);
565 m_permutation_storage[0].compute();
566 m_nodes_to_cell_storage.resize(
mesh()->nodeFamily()->maxLocalId());
567 m_cells_to_node_storage.resize(
mesh()->cellFamily()->maxLocalId());
568 m_connectivity._setStorage(m_nodes_to_cell_storage, m_cells_to_node_storage, &m_permutation_storage[0]);
569 m_connectivity._computeInfos(
mesh(), nodes_coord, cells_center);
573 for (
Integer patch_index = 1; patch_index < m_patch_group.nbPatch(); ++patch_index) {
574 CellGroup cells = m_patch_group.allCells(patch_index);
576 info() <<
"AMR Patch name=" << cells.
name() <<
" size=" << cells.
size() <<
" index=" << patch_index <<
" nbPatch=" << m_patch_group.nbPatch();
577 patch->_internalComputeNodeCellInformations(cell0, cells_center[cell0], nodes_coord);
578 auto [patch_cells, patch_nodes] = _buildPatchGroups(cells, patch_index);
579 _computeMeshDirection(*
patch.get(),
MD_DirX, cells_center, faces_center, patch_cells, patch_nodes);
580 _computeMeshDirection(*
patch.get(),
MD_DirY, cells_center, faces_center, patch_cells, patch_nodes);
582 _computeMeshDirection(*
patch.get(),
MD_DirZ, cells_center, faces_center, patch_cells, patch_nodes);
588 _saveInfosInProperties();
594std::tuple<CellGroup, NodeGroup> CartesianMeshImpl::
607 String cell_group_name =
String(
"AMRPatchCells") + patch_level;
612 String node_group_name =
String(
"AMRPatchNodes") + patch_level;
616 info(4) <<
"PATCH_CELLS name=" << patch_cells.
name() <<
" size=" << patch_cells.
size();
617 info(4) <<
"PATCH_NODES name=" << patch_nodes.
name() <<
" size=" << patch_nodes.
size();
618 return { patch_cells, patch_nodes };
624void CartesianMeshImpl::
628 IItemFamily* cell_family = m_mesh->cellFamily();
629 IItemFamily* face_family = m_mesh->faceFamily();
630 IItemFamily* node_family = m_mesh->nodeFamily();
633 Int32 max_face_id = face_family->maxLocalId();
634 Int32 max_node_id = node_family->maxLocalId();
636 CellDirectionMng& cell_dm = cdi.cellDirection(dir);
637 cell_dm._internalResizeInfos(max_cell_id);
639 FaceDirectionMng& face_dm = cdi.faceDirection(dir);
640 face_dm._internalResizeInfos(max_face_id);
642 NodeDirectionMng& node_dm = cdi.nodeDirection(dir);
643 node_dm._internalResizeInfos(max_node_id);
646 info(4) <<
"COMPUTE DIRECTION dir=" << dir;
648 Int32 prev_local_face = -1;
649 Int32 next_local_face = m_local_face_direction[dir];
650 Integer mesh_dim = m_mesh->dimension();
653 prev_local_face = (next_local_face + 2) % 4;
654 else if (mesh_dim == 3)
655 prev_local_face = (next_local_face + 3) % 6;
657 cell_dm._internalSetLocalFaceIndex(next_local_face, prev_local_face);
661 std::set<Int32> cells_set;
663 cells_set.insert(icell.itemLocalId());
670 Int32 my_level = cell.level();
671 Face next_face = cell.face(next_local_face);
672 Cell next_cell = next_face.backCell() == cell ? next_face.frontCell() : next_face.backCell();
673 if (cells_set.find(next_cell.localId()) == cells_set.end())
675 else if (next_cell.level() != my_level)
678 Face prev_face = cell.face(prev_local_face);
679 Cell prev_cell = prev_face.backCell() == cell ? prev_face.frontCell() : prev_face.backCell();
680 if (cells_set.find(prev_cell.localId()) == cells_set.end())
682 else if (prev_cell.level() != my_level)
684 cell_dm.m_infos_view[icell.itemLocalId()] = CellDirectionMng::ItemDirectionInfo(next_cell, prev_cell);
686 cell_dm._internalComputeInnerAndOuterItems(all_cells);
687 face_dm._internalComputeInfos(cell_dm, cells_center, faces_center);
688 node_dm._internalComputeInfos(cell_dm, all_nodes, cells_center);
694void CartesianMeshImpl::
695_computeDirectionsV2()
697 info() <<
"CartesianMesh: computeDirectionsV2()";
700 _checkAddObservableMeshChanged();
702 m_is_amr = m_mesh->isAmrActivated();
704 if (m_mesh->dimension() == 3) {
705 m_local_face_direction[
MD_DirX] = 4;
706 m_local_face_direction[
MD_DirY] = 5;
707 m_local_face_direction[
MD_DirZ] = 3;
710 m_local_face_direction[
MD_DirX] = 1;
711 m_local_face_direction[
MD_DirY] = 2;
714 info() <<
"Compute cartesian connectivity";
716 m_permutation_storage.resize(1);
717 m_permutation_storage[0].compute();
718 m_nodes_to_cell_storage.resize(
mesh()->nodeFamily()->maxLocalId());
719 m_cells_to_node_storage.resize(
mesh()->cellFamily()->maxLocalId());
720 m_connectivity._setStorage(m_nodes_to_cell_storage, m_cells_to_node_storage, &m_permutation_storage[0]);
721 m_connectivity._computeInfos(
this);
724 for (
Integer patch_index = 0; patch_index < m_patch_group.nbPatch(); ++patch_index) {
725 computeDirectionsPatchV2(patch_index);
731 _saveInfosInProperties();
737void CartesianMeshImpl::
738computeDirectionsPatchV2(
Integer patch_index)
740 bool is_3d = m_mesh->dimension() == 3;
742 CellGroup cells = m_patch_group.allCells(patch_index);
743 Ref<CartesianMeshPatch>
patch = m_patch_group.patch(patch_index);
745 if (
patch->index() == -1) {
746 auto* cmgi = ICartesianMeshGenerationInfo::getReference(m_mesh,
true);
747 info() <<
"Informations from IMesh properties:";
748 info() <<
"GlobalNbCell = " << cmgi->globalNbCells();
749 info() <<
"OwnNbCell: " << cmgi->ownNbCells();
750 info() <<
"SubDomainOffset: " << cmgi->subDomainOffsets();
751 info() <<
"OwnCellOffset: " << cmgi->ownCellOffsets();
753 for (
Integer idir = 0, nb_dir =
mesh()->dimension(); idir < nb_dir; ++idir) {
754 CellDirectionMng& cdm = m_all_items_direction_info->cellDirection(idir);
755 cdm._internalSetOffsetAndNbCellInfos(cmgi->globalNbCells()[idir], cmgi->ownNbCells()[idir],
756 cmgi->subDomainOffsets()[idir], cmgi->ownCellOffsets()[idir]);
760 info() <<
"AMR Patch name=" << cells.name() <<
" size=" << cells.size() <<
" index=" << patch_index <<
" trueindex=" <<
patch->index() <<
" nbPatch=" << m_patch_group.nbPatch();
762 const AMRPatchPosition position =
patch->position();
763 info() <<
" position min=" << position.minPoint() <<
" max=" << position.maxPoint() <<
" level=" << position.level() <<
" overlapLayerSize=" << position.overlapLayerSize();
765 patch->_internalComputeNodeCellInformations();
766 auto [patch_cells, patch_nodes] = _buildPatchGroups(cells, patch_index);
767 _computeMeshDirectionV2(*
patch.get(),
MD_DirX, m_patch_group.allCells(patch_index), m_patch_group.inPatchCells(patch_index), m_patch_group.overlapCells(patch_index), patch_nodes);
768 _computeMeshDirectionV2(*
patch.get(),
MD_DirY, m_patch_group.allCells(patch_index), m_patch_group.inPatchCells(patch_index), m_patch_group.overlapCells(patch_index), patch_nodes);
770 _computeMeshDirectionV2(*
patch.get(),
MD_DirZ, m_patch_group.allCells(patch_index), m_patch_group.inPatchCells(patch_index), m_patch_group.overlapCells(patch_index), patch_nodes);
776void CartesianMeshImpl::
779 IItemFamily* cell_family = m_mesh->cellFamily();
780 IItemFamily* face_family = m_mesh->faceFamily();
781 IItemFamily* node_family = m_mesh->nodeFamily();
783 Int32 max_cell_id = cell_family->maxLocalId();
784 Int32 max_face_id = face_family->maxLocalId();
785 Int32 max_node_id = node_family->maxLocalId();
787 CellDirectionMng& cell_dm = cdi.cellDirection(dir);
788 cell_dm._internalResizeInfos(max_cell_id);
790 FaceDirectionMng& face_dm = cdi.faceDirection(dir);
791 face_dm._internalResizeInfos(max_face_id);
793 NodeDirectionMng& node_dm = cdi.nodeDirection(dir);
794 node_dm._internalResizeInfos(max_node_id);
797 info(4) <<
"COMPUTE DIRECTION dir=" << dir;
799 Int32 prev_local_face = -1;
800 Int32 next_local_face = m_local_face_direction[dir];
801 Integer mesh_dim = m_mesh->dimension();
804 prev_local_face = (next_local_face + 2) % 4;
805 else if (mesh_dim == 3)
806 prev_local_face = (next_local_face + 3) % 6;
808 cell_dm._internalSetLocalFaceIndex(next_local_face, prev_local_face);
812 std::set<Int32> cells_set;
814 cells_set.insert(icell.itemLocalId());
821 Int32 my_level = cell.level();
822 Face next_face = cell.face(next_local_face);
823 Cell next_cell = next_face.backCell() == cell ? next_face.frontCell() : next_face.backCell();
824 if (!cells_set.contains(next_cell.localId()) || next_cell.level() != my_level) {
828 Face prev_face = cell.face(prev_local_face);
829 Cell prev_cell = prev_face.backCell() == cell ? prev_face.frontCell() : prev_face.backCell();
830 if (!cells_set.contains(prev_cell.localId()) || prev_cell.level() != my_level) {
834 cell_dm.m_infos_view[icell.itemLocalId()] = CellDirectionMng::ItemDirectionInfo(next_cell, prev_cell);
836 cell_dm._internalComputeCellGroups(all_cells, in_patch_cells, overlap_cells);
837 face_dm._internalComputeInfos(cell_dm);
838 node_dm._internalComputeInfos(cell_dm, all_nodes);
847 info() <<
"REFINEMENT 2D position=" << position <<
" length=" << length;
857 info() <<
"REFINEMENT 3D position=" << position <<
" length=" << length;
867 _applyRefine(position);
868 _saveInfosInProperties();
877 info() <<
"COARSEN 2D position=" << position <<
" length=" << length;
887 info() <<
"COARSEN 3D position=" << position <<
" length=" << length;
897 _applyCoarse(position);
898 _saveInfosInProperties();
908 ARCANE_FATAL(
"You cannot reduce number of ghost layer of level 0 with this method");
912 const Int32 max_nb_layer = 128;
916 level_max = std::max(level_max, icell->level());
924 Integer level_0_nb_ghost_layer = m_mesh->ghostLayerMng()->nbGhostLayer();
927 if (level_0_nb_ghost_layer == 0) {
936 if (target_nb_ghost_layers % 2 != 0) {
937 target_nb_ghost_layers++;
940 if (target_nb_ghost_layers == nb_ghost_layer) {
941 return nb_ghost_layer;
946 Integer parent_level = level - 1;
947 Integer parent_target_nb_ghost_layer = target_nb_ghost_layers / 2;
953 std::function<void(
Cell)> children_list;
955 children_list = [&cell_lid2, &children_list](
Cell cell) ->
void {
956 for (
Integer i = 0; i < cell.nbHChildren(); ++i) {
958 cell_lid2[cell.level()].
add(cell.hChild(i).localId());
959 children_list(cell.hChild(i));
972 Cell front_cell = iface->frontCell();
973 Cell back_cell = iface->backCell();
975 ((front_cell.
null() || (!front_cell.
isOwn() && front_cell.
level() == parent_level)) && ((!back_cell.
null()) && (back_cell.
isOwn() && back_cell.
level() == parent_level))) ||
976 ((back_cell.
null() || (!back_cell.
isOwn() && back_cell.
level() == parent_level)) && ((!front_cell.
null()) && (front_cell.
isOwn() && front_cell.
level() == parent_level)))) {
977 for (
Node node : iface->nodes()) {
978 level_node[node] = 0;
984 bool is_modif =
true;
985 Int32 current_layer = 0;
990 if (icell->isOwn() || icell->level() != parent_level || level_cell[icell] != -1) {
994 Int32 min = max_nb_layer;
997 for (
Node node : icell->nodes()) {
998 Int32 nlevel = level_node[node];
1000 min = std::min(min, nlevel);
1001 max = std::max(max, nlevel);
1006 if (min != current_layer) {
1011 if (min == max_nb_layer && max == -1) {
1015 Integer new_level = ((min == max) ? min + 1 : max);
1017 for (
Node node : icell->nodes()) {
1018 Int32 nlevel = level_node[node];
1020 level_node[node] = new_level;
1026 level_cell[icell] = min;
1031 if (min >= parent_target_nb_ghost_layer) {
1032 children_list(*icell);
1036 if (current_layer >= max_nb_layer) {
1037 ARCANE_FATAL(
"Error in ghost layer counter algo. Report it plz.");
1042 for (
Integer i = level_max - 1; i >= 0; --i) {
1049 m_mesh->modifier()->flagCellToCoarsen(cell_lid2[i]);
1050 m_mesh->modifier()->coarsenItemsV2(
false);
1053 info() <<
"Nb ghost layer for level " << level <<
" : " << target_nb_ghost_layers;
1055 return target_nb_ghost_layers;
1061void CartesianMeshImpl::
1064 _addPatch(parent_cells_local_id);
1072void CartesianMeshImpl::
1073_addPatch(ConstArrayView<Int32> parent_cells)
1078 UniqueArray<Int32> children_local_id;
1079 CellInfoListView cells(m_mesh->
cellFamily());
1080 for (Int32 cell_local_id : parent_cells) {
1081 Cell c = cells[cell_local_id];
1082 for (
Integer k = 0; k < c.nbHChildren(); ++k) {
1083 Cell child = c.hChild(k);
1084 children_local_id.add(child.localId());
1088 m_patch_group.addPatch(children_local_id);
1094void CartesianMeshImpl::
1098 UniqueArray<Int32> cells_local_id;
1099 position.cellsInPatch(
mesh(), cells_local_id);
1101 Integer nb_cell = cells_local_id.size();
1102 info(4) <<
"Local_NbCellToRefine = " << nb_cell;
1104 IParallelMng* pm = m_mesh->parallelMng();
1106 info(4) <<
"Global_NbCellToRefine = " << total_nb_cell;
1107 if (total_nb_cell == 0)
1110 debug() <<
"Refine with modifier() (for all mesh types)";
1111 m_mesh->modifier()->flagCellToRefine(cells_local_id);
1112 m_mesh->modifier()->adapt();
1114 _addPatch(cells_local_id);
1118 debug() <<
"Refine with specific refiner (for cartesian mesh only)";
1119 m_patch_group.addPatch(position);
1123 ARCANE_FATAL(
"General patch AMR is not implemented. Please use PatchCartesianMeshOnly (3)");
1130 MeshStats ms(
traceMng(), m_mesh, m_mesh->parallelMng());
1138void CartesianMeshImpl::
1142 UniqueArray<Int32> cells_local_id;
1144 zone_position.cellsInPatch(
mesh(), cells_local_id);
1146 Integer nb_cell = cells_local_id.size();
1147 info(4) <<
"Local_NbCellToCoarsen = " << nb_cell;
1149 IParallelMng* pm = m_mesh->parallelMng();
1151 info(4) <<
"Global_NbCellToCoarsen = " << total_nb_cell;
1152 if (total_nb_cell == 0)
1155 debug() <<
"Coarse with modifier() (for all mesh types)";
1156 m_patch_group.removeCellsInAllPatches(cells_local_id);
1158 m_mesh->modifier()->flagCellToCoarsen(cells_local_id);
1159 m_mesh->modifier()->coarsenItemsV2(
true);
1163 debug() <<
"Coarsen with specific coarser (for cartesian mesh only)";
1164 m_patch_group.removeCellsInZone(zone_position);
1168 ARCANE_FATAL(
"General patch AMR is not implemented. Please use PatchCartesianMeshOnly (3)");
1175 MeshStats ms(
traceMng(), m_mesh, m_mesh->parallelMng());
1186 info(4) <<
"Check valid CartesianMesh";
1188 for (
Integer i = 0; i < nb_patch; ++i) {
1200 auto* cmgi = ICartesianMeshGenerationInfo::getReference(m_mesh,
true);
1203 Int32 face_method = v.renumberFaceMethod();
1204 if (face_method != 0 && face_method != 1)
1205 ARCANE_FATAL(
"Invalid value '{0}' for renumberFaceMethod(). Valid values are 0 or 1",
1207 if (face_method == 1)
1211 Int32 patch_method = v.renumberPatchMethod();
1212 if (patch_method < 0 || patch_method > 4) {
1213 ARCANE_FATAL(
"Invalid value '{0}' for renumberPatchMethod(). Valid values are 0, 1, 2, 3 or 4",
1217 ARCANE_FATAL(
"Mesh items renumbering is not compatible with this type of AMR");
1220 if (patch_method == 1 || patch_method == 3 || patch_method == 4) {
1221 CartesianMeshUniqueIdRenumbering renumberer(
this, cmgi, v.parentPatch(), patch_method);
1222 renumberer.renumber();
1224 else if (patch_method == 2) {
1225 warning() <<
"The patch method 2 is experimental!";
1226 CartesianMeshUniqueIdRenumberingV2 renumberer(
this, cmgi);
1227 renumberer.renumber();
1231 if (v.isSortAfterRenumbering()) {
1232 info() <<
"Compacting and Sorting after renumbering";
1233 m_mesh->nodeFamily()->compactItems(
true);
1234 m_mesh->faceFamily()->compactItems(
true);
1235 m_mesh->cellFamily()->compactItems(
true);
1253_createCartesianMeshCoarsening2()
1269 const char* name =
"CartesianMesh";
1278 ARCANE_FATAL(
"The mesh {0} is not yet created", h.meshName());
1285 mesh->_internalApi()->setMeshKind(mk);
1292 return adud->data();
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
File containing event management mechanisms.
Class allowing the definition of a mesh zone.
Integer size() const
Number of elements in the vector.
void add(ConstReferenceType val)
Adds element val to the end of the array.
UserData that self-destructs once detached.
Connectivity information of a Cartesian mesh.
Coarsens a Cartesian mesh by 2.
Coarsens a Cartesian mesh by 2.
Specific information for a Cartesian mesh.
void refinePatch3D(Real3 position, Real3 length) override
Refines a block of the Cartesian mesh in 3D.
Int32 nbPatch() const override
Number of patches in the mesh.
Integer reduceNbGhostLayers(Integer level, Integer target_nb_ghost_layers) override
Method for deleting one or more layers of ghost cells at a defined refinement level.
void refinePatch(const AMRZonePosition &position) override
Refines a block of the Cartesian mesh.
ITraceMng * traceMng() const override
Associated trace manager.
CellDirectionMng cellDirection(Integer idir) override
List of cells in direction dir (0, 1 or 2).
void recreateFromDump() override
Recalculates Cartesian information after a restart.
void computeDirections() override
Calculates information for directional access.
FaceDirectionMng faceDirection(Integer idir) override
List of faces in direction dir (0, 1 or 2).
void coarseZone(const AMRZonePosition &position) override
Coarsens a block of the Cartesian mesh.
NodeDirectionMng nodeDirection(Integer idir) override
List of nodes in direction dir (0, 1 or 2).
void checkValid() const override
Performs checks on the validity of the instance.
IMesh * mesh() const override
Mesh associated with this Cartesian mesh.
FaceDirectionMng faceDirection(eMeshDirection dir) override
List of faces in direction dir.
NodeDirectionMng nodeDirection(eMeshDirection dir) override
List of nodes in direction dir.
void refinePatch2D(Real2 position, Real2 length) override
Refines a block of the Cartesian mesh in 2D.
ICartesianMeshPatch * patch(Int32 index) const override
Returns the index-th patch of the mesh.
void coarseZone2D(Real2 position, Real2 length) override
Coarsens a block of the Cartesian mesh in 2D.
void renumberItemsUniqueId(const CartesianMeshRenumberingInfo &v) override
Renumbers the uniqueId() of entities.
ICartesianMeshInternal * _internalApi() override
Internal API for Arcane.
void coarseZone3D(Real3 position, Real3 length) override
Coarsens a block of the Cartesian mesh in 3D.
Ref< CartesianMeshCoarsening > createCartesianMeshCoarsening() override
Creates an instance to manage mesh coarsening.
CartesianPatch amrPatch(Int32 index) const override
Returns the index-th patch of the mesh.
CellDirectionMng cellDirection(eMeshDirection dir) override
List of cells in direction dir.
CartesianMeshPatchListView patches() const override
View of the list of patches.
CartesianConnectivity connectivity() override
Connectivity information.
View of a list of patches.
Information for renumbering.
AMR Patch of a Cartesian mesh.
Info about the cells in a specific X, Y, or Z direction of a structured mesh.
View of cell information.
Face face(Int32 i) const
i-th face of the cell
Int32 nbFace() const
Number of faces of the cell.
Constant view of an array of type T.
Info on the faces of a specific direction X, Y, or Z of a structured mesh.
Interface of an AMR patch of a Cartesian mesh.
virtual void checkValid() const =0
Performs checks on the validity of the instance.
Interface of a Cartesian mesh.
static ICartesianMesh * getReference(const MeshHandleOrMesh &mesh, bool create=true)
Retrieves or creates the reference associated with mesh.
virtual IMesh * mesh() const =0
Mesh associated with this Cartesian mesh.
Interface of an entity family.
virtual ItemGroup allItems() const =0
Group of all entities.
virtual ItemGroup createGroup(const String &name, Int32ConstArrayView local_ids, bool do_override=false)=0
Creates an entity group named name containing the entities local_ids.
virtual Int32 maxLocalId() const =0
virtual IItemFamily * cellFamily()=0
Returns the cell family.
virtual Int64 timestamp()=0
Counter indicating the time of the last mesh modification.
virtual EventObservable< const MeshEventArgs & > & eventObservable(eMeshEventType type)=0
Observable for an event.
Interface of a list that manages user data.
virtual void setData(const String &name, IUserData *ud)=0
Sets the user data associated with the name name.
virtual IUserData * data(const String &name, bool allow_null=false) const =0
Data associated with name.
Interface for user data attached to another object.
Base class for a view on unstructured connectivity.
NodeGroup nodeGroup() const
Group of nodes of the elements of this group.
const String & name() const
Group name.
ItemVectorView view() const
View of the group entities.
Integer size() const
Number of elements in the group.
IItemFamily * itemFamily() const
Entity family to which this group belongs (0 for the null group).
void setItems(Int32ConstArrayView items_local_id)
Sets the entities of the group.
Utility class for printing information about an entity.
Int32ConstArrayView localIds() const
Array of local IDs of entities.
Node node(Int32 i) const
i-th node of the entity
Int32 nbNode() const
Number of nodes of the entity.
NodeLocalIdView nodeIds() const
List of nodes of the entity.
constexpr bool null() const
true if the entity is null (i.e. not connected to the mesh)
constexpr bool isOwn() const
true if the entity belongs to the subdomain
Arguments for mesh events.
Compatibility class to hold a MeshHandle or an IMesh*.
const MeshHandle & handle() const
Associated handle.
IMesh * meshOrNull() const
Returns the mesh associated with this instance.
IUserDataList * meshUserDataList() const
Associated user data.
Characteristics of a mesh.
Info about nodes in a specific direction X, Y, or Z of a structured mesh.
Class managing a 2-dimensional real vector.
Class managing a 3-dimensional real vector.
bool isNull() const
Indicates if the counter references a non-null instance.
InstanceType * get() const
Associated instance or nullptr if none.
Reference to an instance.
Unicode character string.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flow for a debug message.
TraceMessage info() const
Flow for an information message.
TraceMessage warning() const
Flow for a warning message.
ITraceMng * traceMng() const
Trace manager.
1D data vector with value semantics (STL style).
Parameters necessary for building a variable.
ItemGroupT< Cell > CellGroup
Group of cells.
ItemVectorViewT< Cell > CellVectorView
View over a vector of cells.
ItemGroupT< Node > NodeGroup
Group of nodes.
MeshVariableScalarRefT< Cell, Real3 > VariableCellReal3
Coordinate type quantity at cell center.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
MeshVariableScalarRefT< Node, Int32 > VariableNodeInt32
Quantity at the node of 32-bit integer type.
MeshVariableScalarRefT< Face, Real3 > VariableFaceReal3
Coordinate type quantity at face.
MeshVariableScalarRefT< Cell, Int32 > VariableCellInt32
Quantity at the cell center of 32-bit integer type.
Int32 toInt32(Real r)
Converts a Real to Int32.
@ ReduceSum
Sum of values.
@ ReduceMax
Maximum of values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
bool arcaneIsCheck()
True if running in check mode.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
@ Cartesian
Cartesian mesh.
eMeshDirection
Direction type for a structured mesh.
@ EndPrepareDump
Event sent at the end of prepareForDump().
double Real
Type representing a real number.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
eMeshAMRKind
AMR mesh type.
@ Patch
The mesh is AMR by patch.
@ Cell
The mesh is AMR by cell.
@ PatchCartesianMeshOnly
The mesh is AMR by Cartesian patch (rectangular).
std::int32_t Int32
Signed integer type of 32 bits.
Real y
second component of the triplet
Real z
third component of the triplet
Real x
first component of the triplet