Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
CartesianMeshAMRMng.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/* CartesianMeshAMRMng.cc (C) 2000-2026 */
9/* */
10/* AMR Manager for a Cartesian Mesh. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/cartesianmesh/CartesianMeshAMRMng.h"
15
16#include "arcane/utils/FatalErrorException.h"
17
18#include "arcane/core/IMesh.h"
19#include "arcane/core/MeshKind.h"
20
21#include "arcane/cartesianmesh/ICartesianMesh.h"
22#include "arcane/cartesianmesh/CartesianPatch.h"
23#include "arcane/cartesianmesh/CartesianMeshCoarsening2.h"
24#include "arcane/cartesianmesh/CartesianMeshPatchListView.h"
25#include "arcane/cartesianmesh/CartesianMeshUtils.h"
26
27#include "arcane/cartesianmesh/internal/ICartesianMeshInternal.h"
28#include "arcane/cartesianmesh/internal/CartesianPatchGroup.h"
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane
34{
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
48nbPatch() const
49{
50 return m_cmesh->nbPatch();
51}
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
57amrPatch(Int32 index) const
58{
59 return m_cmesh->amrPatch(index);
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
66patches() const
67{
68 return m_cmesh->patches();
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
75refineZone(const AMRZonePosition& position) const
76{
77 m_cmesh->refinePatch(position);
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
84coarseZone(const AMRZonePosition& position) const
85{
86 m_cmesh->coarseZone(position);
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
93beginAdaptMesh(Int32 max_nb_levels, Int32 level_to_refine_first)
94{
95 // We calculate the number of overlap cells for each level.
96 m_cmesh->_internalApi()->cartesianPatchGroup().beginAdaptMesh(max_nb_levels, level_to_refine_first);
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
103adaptLevel(Int32 level_to_adapt, bool do_fatal_if_useless) const
104{
105 m_cmesh->_internalApi()->cartesianPatchGroup().adaptLevel(level_to_adapt, do_fatal_if_useless);
106}
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
113{
114 m_cmesh->_internalApi()->cartesianPatchGroup().endAdaptMesh();
115 m_cmesh->_internalApi()->saveInfosInProperties();
116}
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
123{
124 m_cmesh->_internalApi()->cartesianPatchGroup().clearRefineRelatedFlags();
125}
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
132{
133 auto amr_type = m_cmesh->mesh()->meshKind().meshAMRKind();
134 if (amr_type == eMeshAMRKind::Cell) {
135 return;
136 }
137 m_cmesh->_internalApi()->cartesianPatchGroup().setOverlapLayerSizeTopLevel(new_size);
138 m_cmesh->_internalApi()->saveInfosInProperties();
139}
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
146{
147 auto amr_type = m_cmesh->mesh()->meshKind().meshAMRKind();
148 if (amr_type == eMeshAMRKind::Cell) {
149 return;
150 }
151 m_cmesh->_internalApi()->cartesianPatchGroup().setOverlapLayerSizeTopLevel(-1);
152 m_cmesh->_internalApi()->saveInfosInProperties();
153}
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
159reduceNbGhostLayers(Integer level, Integer target_nb_ghost_layers) const
160{
161 return m_cmesh->reduceNbGhostLayers(level, target_nb_ghost_layers);
162}
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
168mergePatches() const
169{
170 auto amr_type = m_cmesh->mesh()->meshKind().meshAMRKind();
171 if (amr_type == eMeshAMRKind::Cell) {
172 return;
173 }
174
175 m_cmesh->_internalApi()->cartesianPatchGroup().mergePatches();
176 m_cmesh->_internalApi()->saveInfosInProperties();
177}
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
183createSubLevel() const
184{
185 auto amr_type = m_cmesh->mesh()->meshKind().meshAMRKind();
186 if (amr_type == eMeshAMRKind::Cell) {
188 coarser->createCoarseCells();
189 }
190 else if (amr_type == eMeshAMRKind::PatchCartesianMeshOnly) {
191 m_cmesh->_internalApi()->cartesianPatchGroup().updateLevelsAndAddGroundPatch();
192 }
193 else if (amr_type == eMeshAMRKind::Patch) {
194 ARCANE_FATAL("General patch AMR is not implemented. Please use PatchCartesianMeshOnly (3)");
195 }
196 else {
197 ARCANE_FATAL("AMR is not enabled");
198 }
199 m_cmesh->_internalApi()->saveInfosInProperties();
200}
201
202/*---------------------------------------------------------------------------*/
203/*---------------------------------------------------------------------------*/
204
205} // End namespace Arcane
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Class allowing the definition of a mesh zone.
void setOverlapLayerSizeTopLevel(Int32 new_size) const
Method to modify the number of overlap cell layers on the highest refinement level.
void coarseZone(const AMRZonePosition &position) const
Coarsens a block of the Cartesian mesh.
CartesianMeshPatchListView patches() const
View of the list of patches.
void mergePatches() const
Method to merge patches that can be merged.
void clearRefineRelatedFlags() const
Method to delete flags related to mesh refinement for all cells.
CartesianMeshAMRMng(ICartesianMesh *cmesh)
Constructor.
Int32 nbPatch() const
Number of mesh patches.
void endAdaptMesh()
Method to finish mesh refinement.
void disableOverlapLayer()
Method to disable overlap cell layers (and destroy them if present).
Integer reduceNbGhostLayers(Integer level, Integer target_nb_ghost_layers) const
Method to delete one or more layers of ghost cells on a defined refinement level.
void adaptLevel(Int32 level_to_adapt, bool do_fatal_if_useless=false) const
Method to create a level of mesh refinement.
void beginAdaptMesh(Int32 max_nb_levels, Int32 level_to_refine_first)
Method to start mesh refinement.
CartesianPatch amrPatch(Int32 index) const
Returns the index-th patch of the mesh.
void refineZone(const AMRZonePosition &position) const
Refines a block of the Cartesian mesh.
void createSubLevel() const
Method to create a sub-level ("level -1").
AMR Patch of a Cartesian mesh.
Reference to an instance.
ARCANE_CARTESIANMESH_EXPORT Ref< CartesianMeshCoarsening2 > createCartesianMeshCoarsening2(ICartesianMesh *cm)
Creates an instance to manage mesh coarsening (V2).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
@ Patch
The mesh is AMR by patch.
Definition MeshKind.h:55
@ Cell
The mesh is AMR by cell.
Definition MeshKind.h:53
@ PatchCartesianMeshOnly
The mesh is AMR by Cartesian patch (rectangular).
Definition MeshKind.h:57
std::int32_t Int32
Signed integer type of 32 bits.