Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
CartesianMeshAMRMng.h
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.h (C) 2000-2026 */
9/* */
10/* AMR Manager for a Cartesian Mesh. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#ifndef ARCANE_CARTESIANMESH_CARTESIANMESHAMRMNG_H
15#define ARCANE_CARTESIANMESH_CARTESIANMESHAMRMNG_H
16
17/*---------------------------------------------------------------------------*/
18/*---------------------------------------------------------------------------*/
19
21
22#include "arcane/cartesianmesh/CartesianMeshGlobal.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33/*!
34 * \ingroup ArcaneCartesianMesh
35 * \brief Class allowing access to the specific AMR methods of the Cartesian mesh.
36 *
37 * An instance of this class is valid as long as the ICartesianMesh passed in
38 * the constructor is valid.
39 */
40class ARCANE_CARTESIANMESH_EXPORT CartesianMeshAMRMng
41{
42 public:
43
44 /*!
45 * \brief Constructor.
46 */
47 explicit CartesianMeshAMRMng(ICartesianMesh* cmesh);
48
49 public:
50
51 /*!
52 * \brief Number of mesh patches.
53 *
54 * There is always at least one patch representing the Cartesian mesh.
55 */
56 Int32 nbPatch() const;
57
58 /*!
59 * \brief Returns the \a index-th patch of the mesh.
60 *
61 * If the mesh is Cartesian, there is only one patch.
62 *
63 * The returned instance remains valid as long as this instance is not destroyed.
64 */
65 CartesianPatch amrPatch(Int32 index) const;
66
67 /*!
68 * \brief View of the list of patches.
69 */
71
72 /*!
73 * \brief Refines a block of the Cartesian mesh.
74 *
75 * This method can only be called if the mesh is an
76 * AMR mesh (IMesh::isAmrActivated()==true).
77 *
78 * The cells whose center positions are between
79 * \a position and \a (position+length) are refined, and the corresponding
80 * connectivity information is updated.
81 *
82 * This operation is collective.
83 */
84 void refineZone(const AMRZonePosition& position) const;
85
86 /*!
87 * \brief Coarsens a block of the Cartesian mesh.
88 *
89 * This method can only be called if the mesh is an
90 * AMR mesh (IMesh::isAmrActivated()==true).
91 *
92 * The cells whose center positions are between
93 * \a position and \a (position+length) are coarsened, and the corresponding
94 * connectivity information is updated.
95 *
96 * All cells in the coarsening zone must be of the same
97 * level.
98 *
99 * Patches that no longer contain cells after calling this method
100 * will be deleted.
101 *
102 * This operation is collective.
103 */
104 void coarseZone(const AMRZonePosition& position) const;
105
106 /*!
107 * \brief Method to start mesh refinement.
108 *
109 * \warning Experimental method.
110 *
111 * This method can only be called if the mesh is an
112 * AMR mesh (IMesh::isAmrActivated()==true) and the AMR type is 3
113 * (PatchCartesianMeshOnly).
114 *
115 * This method is the first of a trio of methods necessary to
116 * refine the mesh:
117 * - \a void beginAdaptMesh(Int32 max_nb_levels, Int32 level_to_refine_first)
118 * - \a void adaptLevel(Int32 level_to_adapt)
119 * - \a void endAdaptMesh()
120 *
121 * This first method will prepare the mesh for
122 * refinement.
123 *
124 * It is necessary to pass the number of
125 * refinement levels that will occur during this refinement phase (\a max_nb_levels).
126 *
127 * It is recommended to specify the exact number of levels to avoid
128 * adjustment of the number of overlap cell layers during
129 * the call to the third method, which is computationally expensive.
130 *
131 *
132 * It is also necessary to pass the first level to be
133 * refined.
134 * If two levels are already present on the mesh (0 and 1) and you
135 * only want to create a third level (level 2) from
136 * the second level (level 1), you can set 1 for the parameter
137 * \a level_to_refine_first.
138 *
139 *
140 * If two levels are already present on the mesh (0 and 1) and you
141 * want to start from scratch, you can set 0 for the parameter
142 * \a level_to_refine_first.
143 * In this case, the level 1 patches will be deleted, but not the
144 * cells/faces/nodes. Once the new level 1 patches are created using the second method, the third method will handle
145 * deleting the excess items.
146 * This allows the variable values for the
147 * cells/faces/nodes that were in a patch before and are
148 * preserved in a new patch.
149 *
150 *
151 * Execution example:
152 * * CartesianMeshAMRMng amr_mng(cmesh());
153 * amr_mng.clearRefineRelatedFlags();
154 *
155 * amr_mng.beginAdaptMesh(2, 0);
156 * for (Integer level = 0; level < 2; ++level){
157 * // Will perform its calculations and set II_Refine flags on the cells
158 * // of level level.
159 * computeInLevel(level);
160 * amr_mng.adaptLevel(level);
161 * }
162 * amr_mng.endAdaptMesh();
163 * *
164 * This operation is collective.
165 *
166 * \param max_nb_levels The desired number of refinement levels.
167 * \param level_to_refine_first The level that will be refined first.
168 */
169 void beginAdaptMesh(Int32 max_nb_levels, Int32 level_to_refine_first);
170
171 /*!
172 * \brief Method to create a level of mesh refinement.
173 *
174 * \warning Experimental method.
175 *
176 * This method can only be called if the mesh is an
177 * AMR mesh (IMesh::isAmrActivated()==true) and the AMR type is 3
178 * (PatchCartesianMeshOnly).
179 *
180 * This second method will allow the mesh to be refined level by
181 * level.
182 *
183 * Note that the parameter \a level_to_adapt designates the level to
184 * refine, meaning the creation of level \a level_to_adapt +1 (if we want
185 * to refine level 0, then level 1 will be created).
186 *
187 * Before calling this method, you must add the "II_Refine" flag to the
188 * cells that must be refined, only on level \a level_to_adapt.
189 * To ensure no flags are already present on the mesh, it is
190 * possible to call the method \a clearRefineRelatedFlags().
191 *
192 * For the refinement of cells outside of level 0 (this "ground" level having
193 * a special status), the cells that can be refined must
194 * possess the "II_InPatch" flag. Cells without the "II_InPatch" flag
195 * cannot be refined.
196 * \todo Add the "II_InPatch" flag to all level 0 cells?
197 *
198 * Cells on level \a level_to_adapt that are already refined, but do not have
199 * the "II_Refine" flag, may be deleted when calling the
200 * third method.
201 * This method redraws the patches and creates the new child cells
202 * if necessary, but does not delete any cells. The third method will
203 * handle the deletion of all cells that do not belong to any patch.
204 *
205 * Once this method is called, level \a level_to_adapt +1 is ready to
206 * be used, notably to mark cells "II_Refine", and call
207 * this method again to create another level, etc.
208 *
209 * This method is intended to be called iteratively, level by level
210 * (from the lowest level to the highest level). If patches of levels
211 * higher than \a level_to_adapt are detected, they will be deleted.
212 * It is therefore possible to call this method for level n, and then call it
213 * again for level n-1, for example (however, pay attention to the number of
214 * new cells created).
215 *
216 * This operation is collective.
217 *
218 * \param level_to_adapt The level to adapt.
219 * \param do_fatal_if_useless Triggers an exception if no cells are
220 * to refine or if level_to_adapt designates a
221 * level too high compared to the previous
222 * call.
223 */
224 void adaptLevel(Int32 level_to_adapt, bool do_fatal_if_useless = false) const;
225
226 /*!
227 * \brief Method to finish mesh refinement.
228 *
229 * \warning Experimental method.
230 *
231 * This method can only be called if the mesh is an
232 * AMR mesh (IMesh::isAmrActivated()==true) and the AMR type is 3
233 * (PatchCartesianMeshOnly).
234 *
235 * This third method will allow the mesh refinement to finish, specifically
236 * by deleting cells that no longer belong to any patch.
237 *
238 * If the highest level refined with the second method does not correspond
239 * to the \a max_nb_levels parameter of the first method, there will be
240 * an adjustment of the number of overlap cell layers.
241 *
242 * This operation is collective.
243 */
244 void endAdaptMesh();
245
246 /*!
247 * \brief Method to delete flags related to mesh refinement
248 * for all cells.
249 *
250 * The flags concerned are:
251 * - ItemFlags::II_Coarsen
252 * - ItemFlags::II_Refine
253 * - ItemFlags::II_JustCoarsened
254 * - ItemFlags::II_JustRefined
255 * - ItemFlags::II_JustAdded
256 * - ItemFlags::II_CoarsenInactive
257 */
258 void clearRefineRelatedFlags() const;
259
260 /*!
261 * \brief Method to modify the number of overlap cell layers on the highest refinement level.
262 *
263 * A call to this method will trigger the adjustment of the number of layers
264 * for all existing patches.
265 *
266 * The parameter \a new_size must be an even number (otherwise, it will be modified
267 * to the next highest even number).
268 *
269 * \param new_size The new number of overlap cell layers.
270 */
271 void setOverlapLayerSizeTopLevel(Int32 new_size) const;
272
273 /*!
274 * \brief Method to disable overlap cell layers (and destroy them if present).
275 *
276 * \warning Without this layer, there may be more than one level of
277 * refinement between two cells. It is up to the user to manage
278 * this constraint.
279 *
280 * \note To reactivate these layers, a call to
281 * \a setOverlapLayerSizeTopLevel() is sufficient.
282 */
283 void disableOverlapLayer();
284
285 /*!
286 * \brief Method to delete one or more layers
287 * of ghost cells on a defined refinement level.
288 *
289 * The desired number of ghost cell layers may be increased
290 * by the method. It is necessary to retrieve the returned value
291 * to get the final number of ghost cell layers.
292 *
293 * \param level The refinement level concerned by the deletion
294 * of ghost cells.
295 *
296 * \param target_nb_ghost_layers The desired number of layers after
297 * calling this method. ATTENTION: It may be adjusted by the method.
298 *
299 * \return The final number of ghost cell layers.
300 */
301 Integer reduceNbGhostLayers(Integer level, Integer target_nb_ghost_layers) const;
302
303 /*!
304 * \brief Method to merge patches that can be merged.
305 *
306 * This method can only be called if the mesh is an
307 * AMR mesh (IMesh::isAmrActivated()==true).
308 * If the AMR type is not 3 (PatchCartesianMeshOnly), the method does nothing.
309 *
310 * This method can be useful after several calls to \a refineZone() and \a coarseZone(). However, calling this method is useless after a call to \a adaptLevel() because \a adaptLevel() handles it.
311 */
312 void mergePatches() const;
313
314 /*!
315 * \brief Method to create a sub-level ("level -1").
316 *
317 * This method can only be called if the mesh is an
318 * AMR mesh (IMesh::isAmrActivated()==true).
319 *
320 * In the case of using AMR type 3 (PatchCartesianMeshOnly), it is
321 * possible to call this method during calculation and as many times as
322 * necessary (as long as it is possible to divide the size of level 0 by
323 * 2).
324 * Once level -1 is created, all levels are "upgraded" (meaning level -1 becomes the
325 * level 0 "ground").
326 */
327 void createSubLevel() const;
328
329 private:
330
331 ICartesianMesh* m_cmesh;
332};
333
334/*---------------------------------------------------------------------------*/
335/*---------------------------------------------------------------------------*/
336
337} // End namespace Arcane
338
339/*---------------------------------------------------------------------------*/
340/*---------------------------------------------------------------------------*/
341
342#endif
Declarations of types on entities.
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.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
std::int32_t Int32
Signed integer type of 32 bits.