Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
AMRPatchPosition.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/* AMRPatchPosition.h (C) 2000-2026 */
9/* */
10/* Position of an AMR patch in a Cartesian mesh. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CARTESIANMESH_AMRPATCHPOSITION_H
13#define ARCANE_CARTESIANMESH_AMRPATCHPOSITION_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/cartesianmesh/CartesianMeshGlobal.h"
18#include "arcane/utils/Vector3.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29/*!
30 * \ingroup ArcaneCartesianMesh
31 * \brief Class allowing the definition of a patch position in the Cartesian
32 * mesh.
33 *
34 * The position of a patch is designated by the position of two cells in the
35 * grid. The "min" position and the "max" position form an enclosing box.
36 *
37 * \warning The cell at the "min" position is included in the box, but the
38 * cell at the "max" position is excluded.
39 *
40 * \note The patch position is global for the Cartesian mesh. The decomposition
41 * into subdomains is not taken into account (example with the \a nbCells()
42 * method of this class, which gives the number of cells in the patch without
43 * considering subdomains).
44 *
45 * Cell positions can be obtained via the CartesianMeshNumberingMng.
46 *
47 * \warning This class is only valid for a refinement pattern of 2 (modifying
48 * this should not be complex, if needed).
49 */
50class ARCANE_CARTESIANMESH_EXPORT AMRPatchPosition
51{
52 public:
53
54 /*!
55 * \brief Constructor for a null position.
56 * A null position is defined by a level = -2.
57 */
59 AMRPatchPosition(Int32 level, CartCoord3 min_point, CartCoord3 max_point, Int32 overlap_layer_size);
60
61 /*!
62 * \brief Copy constructor.
63 * \param src The position to copy.
64 */
66 AMRPatchPosition& operator=(const AMRPatchPosition&) = default;
67
69
70 public:
71
72 bool operator==(const AMRPatchPosition& other) const = default;
73
74 public:
75
76 /*!
77 * \brief Method to retrieve the patch level.
78 * \return The patch level.
79 */
80 Int32 level() const;
81
82 /*!
83 * \brief Method to set the patch level.
84 * \param level The patch level.
85 */
86 void setLevel(Int32 level);
87
88 /*!
89 * \brief Method to retrieve the min position of the enclosing box.
90 *
91 * \return The min position.
92 */
93 CartCoord3 minPoint() const;
94
95 /*!
96 * \brief Method to set the min position of the enclosing box.
97 * \param min_point the min position.
98 */
99 void setMinPoint(CartCoord3 min_point);
100
101 /*!
102 * \brief Method to retrieve the max position of the enclosing box.
103 *
104 * \return The max position.
105 */
106 CartCoord3 maxPoint() const;
107
108 /*!
109 * \brief Method to set the max position of the enclosing box.
110 * \param max_point the max position.
111 */
112 void setMaxPoint(CartCoord3 max_point);
113
114 /*!
115 * \brief Method to retrieve the number of overlap cell layers of the patch.
116 *
117 * \return the number of overlap cell layers
118 */
119 Int32 overlapLayerSize() const;
120
121 /*!
122 * \brief Method to set the number of overlap cell layers of the patch.
123 * \param layer_size the number of overlap cell layers
124 */
125 void setOverlapLayerSize(Int32 layer_size);
126
127 /*!
128 * \brief Method to retrieve the min position of the enclosing box including the overlap cell layer.
129 * \return The min position with the overlap cell layer.
130 */
132
133 /*!
134 * \brief Method to retrieve the max position of the enclosing box including the overlap cell layer.
135 * \return The max position with the overlap cell layer.
136 */
138
139 /*!
140 * \brief Method to know the number of cells in the patch according to its position.
141 *
142 * \warning The number of cells is calculated using the min and max positions
143 * (without the overlap layer). This number is therefore the same for all
144 * subdomains. Be careful not to compare this number with the number of cells
145 * in the cell group that may be associated with this class, which may be
146 * different for each subdomain.
147 *
148 * \return The number of cells in the patch.
149 */
150 Int64 nbCells() const;
151
152 /*!
153 * \brief Method to cut the patch into two patches according to a cut point.
154 *
155 * \param cut_point The cut point.
156 * \param dim The dimension that must be cut.
157 * \return The two patch positions resulting from the cut.
158 */
159 std::pair<AMRPatchPosition, AMRPatchPosition> cut(CartCoord cut_point, Integer dim) const;
160
161 /*!
162 * \brief Method to know if our patch can be merged with \a other_patch.
163 *
164 * \param other_patch The patch to check.
165 * \return True if merging is possible.
166 */
167 bool canBeFusion(const AMRPatchPosition& other_patch) const;
168
169 /*!
170 * \brief Method to merge \a other_patch with ours.
171 *
172 * A check for possible merging (via \a canBeFusion()) is performed before
173 * merging. If merging is impossible, false is returned. Otherwise, we merge
174 * and return true. If merged, \a other_patch becomes null.
175 *
176 * \param other_patch The patch to merge with.
177 * \return true if the merge was successful, false if the merge is impossible.
178 */
179 bool fusion(AMRPatchPosition& other_patch);
180
181 /*!
182 * \brief Method to know if the patch is null.
183 *
184 * \warning The validity of the position is not checked.
185 *
186 * \return True if the patch is null.
187 */
188 bool isNull() const;
189
190 /*!
191 * \brief Method to create an \a AMRPatchPosition for the higher level.
192 *
193 * \param dim The dimension of the mesh.
194 * \param higher_level The highest refinement level of the mesh.
195 * \param overlap_layer_size_top_level The number of overlap cell layers for patches at the highest refinement level.
196 * \return A higher-level \a AMRPatchPosition.
197 */
198 AMRPatchPosition patchUp(Integer dim, Int32 higher_level, Int32 overlap_layer_size_top_level) const;
199
200 /*!
201 * \brief Method to create an \a AMRPatchPosition for the lower level.
202 *
203 * If the min position is not divisible by two, it is rounded down to the lower integer.
204 * If the max position is not divisible by two, it is rounded up to the higher integer.
205 *
206 * For the overlap layer, this method ensures that there will never be more than one level difference between two cells of different levels.
207 *
208 * \warning patch.patchDown(patch.patchUp(X)) != patch and patch.patchUp(patch.patchDown(X)) != patch.
209 *
210 * \param dim The dimension of the mesh.
211 * \param higher_level The highest refinement level of the mesh.
212 * \param overlap_layer_size_top_level The number of overlap cell layers for patches at the highest refinement level.
213 * \return A lower-level \a AMRPatchPosition.
214 */
215 AMRPatchPosition patchDown(Integer dim, Int32 higher_level, Int32 overlap_layer_size_top_level) const;
216
217 /*!
218 * \brief Method to know the size of the patch (in number of cells per direction).
219 *
220 * \return The size of the patch.
221 */
222 CartCoord3 length() const;
223
224 /*!
225 * \brief Method to know if a cell at position x,y,z is included in this patch.
226 *
227 * To include the overlap layer, use the \a isInWithOverlap() method.
228 *
229 * \param x X position of the cell.
230 * \param y Y position of the cell.
231 * \param z Z position of the cell.
232 *
233 * \return True if the cell is in the patch.
234 */
235 bool isIn(CartCoord x, CartCoord y, CartCoord z) const;
236
237 /*!
238 * \brief Method to know if a cell is included in this patch.
239 *
240 * To include the overlap layer, use the \a isInWithOverlap() method.
241 *
242 * \param coord Position of the cell.
243 *
244 * \return True if the cell is in the patch.
245 */
246 bool isIn(CartCoord3 coord) const;
247
248 /*!
249 * \brief Method to know if a cell at position x,y,z is included in this patch with overlap layer.
250 *
251 * \param x X position of the cell.
252 * \param y Y position of the cell.
253 * \param z Z position of the cell.
254 *
255 * \return True if the cell is in the patch.
256 */
257 bool isInWithOverlap(CartCoord x, CartCoord y, CartCoord z) const;
258
259 /*!
260 * \brief Method to know if a cell is included in this patch with overlap layer.
261 *
262 * \param coord Position of the cell.
263 *
264 * \return True if the cell is in the patch.
265 */
266 bool isInWithOverlap(CartCoord3 coord) const;
267
268 /*!
269 * \brief Method to know if a cell at position x,y,z is included in this patch with a specified overlap layer.
270 *
271 * \param x X position of the cell.
272 * \param y Y position of the cell.
273 * \param z Z position of the cell.
274 * \param overlap The number of overlap cells in the layer.
275 *
276 * \return True if the cell is in the patch.
277 */
278 bool isInWithOverlap(CartCoord x, CartCoord y, CartCoord z, Integer overlap) const;
279
280 /*!
281 * \brief Method to know if a cell is included in this patch with a specified overlap layer.
282 *
283 * \param coord Position of the cell.
284 * \param overlap The number of overlap cells in the layer.
285 *
286 * \return True if the cell is in the patch.
287 */
288 bool isInWithOverlap(CartCoord3 coord, Integer overlap) const;
289
290 /*!
291 * \brief Method to know if our patch is in contact with \a other.
292 *
293 * \param other The patch to check.
294 * \return True if the patches are in contact.
295 */
296 bool haveIntersection(const AMRPatchPosition& other) const;
297
298 /*!
299 * \brief Method to calculate the number of overlap cell layers for a given level.
300 *
301 * \param level The requested level.
302 * \param higher_level The highest refinement level.
303 * \param overlap_layer_size_top_level The number of layers for the highest refinement level.
304 * \return The number of overlap cell layers for the requested level.
305 */
306 static Int32 computeOverlapLayerSize(Int32 level, Int32 higher_level, Int32 overlap_layer_size_top_level);
307
308 /*!
309 * \brief Method to calculate the number of overlap cell layers for our patch.
310 *
311 * \param higher_level The highest refinement level.
312 * \param overlap_layer_size_top_level The number of layers for the highest refinement level.
313 */
314 void computeOverlapLayerSize(Int32 higher_level, Int32 overlap_layer_size_top_level);
315
316 private:
317
318 Int32 m_level;
319 CartCoord3 m_min_point;
320 CartCoord3 m_max_point;
321 Int32 m_overlap_layer_size;
322};
323
324/*---------------------------------------------------------------------------*/
325/*---------------------------------------------------------------------------*/
326
327} // End namespace Arcane
328
329/*---------------------------------------------------------------------------*/
330/*---------------------------------------------------------------------------*/
331
332#endif
AMRPatchPosition patchUp(Integer dim, Int32 higher_level, Int32 overlap_layer_size_top_level) const
Method to create an AMRPatchPosition for the higher level.
bool isInWithOverlap(CartCoord x, CartCoord y, CartCoord z) const
Method to know if a cell at position x,y,z is included in this patch with overlap layer.
CartCoord3 minPointWithOverlap() const
Method to retrieve the min position of the enclosing box including the overlap cell layer.
AMRPatchPosition patchDown(Integer dim, Int32 higher_level, Int32 overlap_layer_size_top_level) const
Method to create an AMRPatchPosition for the lower level.
bool isIn(CartCoord x, CartCoord y, CartCoord z) const
Method to know if a cell at position x,y,z is included in this patch.
bool canBeFusion(const AMRPatchPosition &other_patch) const
Method to know if our patch can be merged with other_patch.
static Int32 computeOverlapLayerSize(Int32 level, Int32 higher_level, Int32 overlap_layer_size_top_level)
Method to calculate the number of overlap cell layers for a given level.
bool fusion(AMRPatchPosition &other_patch)
Method to merge other_patch with ours.
CartCoord3 minPoint() const
Method to retrieve the min position of the enclosing box.
void setMinPoint(CartCoord3 min_point)
Method to set the min position of the enclosing box.
CartCoord3 length() const
Method to know the size of the patch (in number of cells per direction).
AMRPatchPosition()
Constructor for a null position. A null position is defined by a level = -2.
void setLevel(Int32 level)
Method to set the patch level.
bool isNull() const
Method to know if the patch is null.
CartCoord3 maxPointWithOverlap() const
Method to retrieve the max position of the enclosing box including the overlap cell layer.
CartCoord3 maxPoint() const
Method to retrieve the max position of the enclosing box.
bool haveIntersection(const AMRPatchPosition &other) const
Method to know if our patch is in contact with other.
Int64 nbCells() const
Method to know the number of cells in the patch according to its position.
Int32 overlapLayerSize() const
Method to retrieve the number of overlap cell layers of the patch.
void setOverlapLayerSize(Int32 layer_size)
Method to set the number of overlap cell layers of the patch.
Int32 level() const
Method to retrieve the patch level.
std::pair< AMRPatchPosition, AMRPatchPosition > cut(CartCoord cut_point, Integer dim) const
Method to cut the patch into two patches according to a cut point.
void setMaxPoint(CartCoord3 max_point)
Method to set the max position of the enclosing box.
-- 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.
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}.