Arcane  v4.1.2.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AMRPatchPosition.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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.cc (C) 2000-2025 */
9/* */
10/* Position d'un patch AMR d'un maillage cartésien. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/cartesianmesh/AMRPatchPosition.h"
15
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/Math.h"
19
20#include <cmath>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
33: m_level(-2)
34, m_overlap_layer_size(0)
35{}
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
41AMRPatchPosition(Int32 level, CartCoord3Type min_point, CartCoord3Type max_point, Int32 overlap_layer_size)
42: m_level(level)
43, m_min_point(min_point)
44, m_max_point(max_point)
45, m_overlap_layer_size(overlap_layer_size)
46{}
47
48/*---------------------------------------------------------------------------*/
49/*---------------------------------------------------------------------------*/
50
53: m_level(src.level())
54, m_min_point(src.minPoint())
55, m_max_point(src.maxPoint())
56, m_overlap_layer_size(src.overlapLayerSize())
57{
58}
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
63AMRPatchPosition::
64~AMRPatchPosition()
65= default;
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
71level() const
72{
73 return m_level;
74}
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
81{
82 m_level = level;
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88CartCoord3Type AMRPatchPosition::
89minPoint() const
90{
91 return m_min_point;
92}
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
98setMinPoint(CartCoord3Type min_point)
99{
100 m_min_point = min_point;
101}
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106CartCoord3Type AMRPatchPosition::
107maxPoint() const
108{
109 return m_max_point;
110}
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
116setMaxPoint(CartCoord3Type max_point)
117{
118 m_max_point = max_point;
119}
120
121/*---------------------------------------------------------------------------*/
122/*---------------------------------------------------------------------------*/
123
125overlapLayerSize() const
126{
127 return m_overlap_layer_size;
128}
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
132
134setOverlapLayerSize(Int32 layer_size)
135{
136 m_overlap_layer_size = layer_size;
137}
138
139/*---------------------------------------------------------------------------*/
140/*---------------------------------------------------------------------------*/
141
142CartCoord3Type AMRPatchPosition::
144{
145 return m_min_point - m_overlap_layer_size;
146}
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151CartCoord3Type AMRPatchPosition::
153{
154 return m_max_point + m_overlap_layer_size;
155}
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
161nbCells() const
162{
163 return static_cast<Int64>(m_max_point.x - m_min_point.x) * (m_max_point.y - m_min_point.y) * (m_max_point.z - m_min_point.z);
164}
165
166/*---------------------------------------------------------------------------*/
167/*---------------------------------------------------------------------------*/
168
169std::pair<AMRPatchPosition, AMRPatchPosition> AMRPatchPosition::
170cut(CartCoordType cut_point, Integer dim) const
171{
172 CartCoord3Type patch_max_cut = m_max_point;
173 CartCoord3Type patch_min_cut = m_min_point;
174
175 if (dim == MD_DirX) {
176 patch_max_cut.x = cut_point;
177 patch_min_cut.x = cut_point;
178 }
179 else if (dim == MD_DirY) {
180 patch_max_cut.y = cut_point;
181 patch_min_cut.y = cut_point;
182 }
183 else {
184 patch_max_cut.z = cut_point;
185 patch_min_cut.z = cut_point;
186 }
187
188 AMRPatchPosition p0(*this);
189 p0.setMaxPoint(patch_max_cut);
190
191 AMRPatchPosition p1(*this);
192 p1.setMinPoint(patch_min_cut);
193
194 return { p0, p1 };
195}
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
201canBeFusion(const AMRPatchPosition& other_patch) const
202{
203 const CartCoord3Type min_point = other_patch.minPoint();
204 const CartCoord3Type max_point = other_patch.maxPoint();
205 return m_level == other_patch.level() &&
206 (((m_min_point.x == max_point.x || m_max_point.x == min_point.x) &&
207 (m_min_point.y == min_point.y && m_max_point.y == max_point.y) &&
208 (m_min_point.z == min_point.z && m_max_point.z == max_point.z)) ||
209
210 ((m_min_point.x == min_point.x && m_max_point.x == max_point.x) &&
211 (m_min_point.y == max_point.y || m_max_point.y == min_point.y) &&
212 (m_min_point.z == min_point.z && m_max_point.z == max_point.z)) ||
213
214 ((m_min_point.x == min_point.x && m_max_point.x == max_point.x) &&
215 (m_min_point.y == min_point.y && m_max_point.y == max_point.y) &&
216 (m_min_point.z == max_point.z || m_max_point.z == min_point.z)));
217}
218
219/*---------------------------------------------------------------------------*/
220/*---------------------------------------------------------------------------*/
221
223fusion(const AMRPatchPosition& other_patch)
224{
225 if (!canBeFusion(other_patch)) {
226 return false;
227 }
228
229 const CartCoord3Type min_point = other_patch.minPoint();
230 const CartCoord3Type max_point = other_patch.maxPoint();
231
232 if (m_min_point.x > min_point.x) {
233 m_min_point.x = min_point.x;
234 }
235 else if (m_max_point.x < max_point.x) {
236 m_max_point.x = max_point.x;
237 }
238
239 else if (m_min_point.y > min_point.y) {
240 m_min_point.y = min_point.y;
241 }
242 else if (m_max_point.y < max_point.y) {
243 m_max_point.y = max_point.y;
244 }
245
246 else if (m_min_point.z > min_point.z) {
247 m_min_point.z = min_point.z;
248 }
249 else if (m_max_point.z < max_point.z) {
250 m_max_point.z = max_point.z;
251 }
252
253 return true;
254}
255
256/*---------------------------------------------------------------------------*/
257/*---------------------------------------------------------------------------*/
258
260isNull() const
261{
262 return m_level == -2;
263}
264
265/*---------------------------------------------------------------------------*/
266/*---------------------------------------------------------------------------*/
267
269patchUp(Integer dim) const
270{
272 p.setLevel(m_level + 1);
273 p.setMinPoint(m_min_point * 2);
274 if (dim == 2) {
275 p.setMaxPoint({ m_max_point.x * 2, m_max_point.y * 2, 1 });
276 }
277 else {
278 p.setMaxPoint(m_max_point * 2);
279 }
280 p.setOverlapLayerSize(m_overlap_layer_size * 2);
281 return p;
282}
283
284/*---------------------------------------------------------------------------*/
285/*---------------------------------------------------------------------------*/
286
288patchDown(Integer dim) const
289{
291 p.setLevel(m_level - 1);
292 p.setMinPoint(m_min_point / 2);
293 if (dim == 2) {
294 p.setMaxPoint({ static_cast<CartCoordType>(std::ceil(m_max_point.x / 2.)), static_cast<CartCoordType>(std::ceil(m_max_point.y / 2.)), 1 });
295 }
296 else {
297 p.setMaxPoint({ static_cast<CartCoordType>(std::ceil(m_max_point.x / 2.)), static_cast<CartCoordType>(std::ceil(m_max_point.y / 2.)), static_cast<CartCoordType>(std::ceil(m_max_point.z / 2.)) });
298 }
299 p.setOverlapLayerSize((m_overlap_layer_size / 2) + 1);
300 return p;
301}
302
303/*---------------------------------------------------------------------------*/
304/*---------------------------------------------------------------------------*/
305
306CartCoord3Type AMRPatchPosition::
307length() const
308{
309 return m_max_point - m_min_point;
310}
311
312/*---------------------------------------------------------------------------*/
313/*---------------------------------------------------------------------------*/
314
316isIn(CartCoordType x, CartCoordType y, CartCoordType z) const
317{
318 return x >= m_min_point.x && x < m_max_point.x && y >= m_min_point.y && y < m_max_point.y && z >= m_min_point.z && z < m_max_point.z;
319}
320
321/*---------------------------------------------------------------------------*/
322/*---------------------------------------------------------------------------*/
323
325isIn(CartCoord3Type coord) const
326{
327 return coord.x >= m_min_point.x && coord.x < m_max_point.x && coord.y >= m_min_point.y && coord.y < m_max_point.y && coord.z >= m_min_point.z && coord.z < m_max_point.z;
328}
329
330/*---------------------------------------------------------------------------*/
331/*---------------------------------------------------------------------------*/
332
334isInWithOverlap(CartCoordType x, CartCoordType y, CartCoordType z) const
335{
336 const CartCoord3Type min_point = minPointWithOverlap();
337 const CartCoord3Type max_point = maxPointWithOverlap();
338 return x >= min_point.x && x < max_point.x && y >= min_point.y && y < max_point.y && z >= min_point.z && z < max_point.z;
339}
340
341/*---------------------------------------------------------------------------*/
342/*---------------------------------------------------------------------------*/
343
345isInWithOverlap(CartCoord3Type coord) const
346{
347 const CartCoord3Type min_point = minPointWithOverlap();
348 const CartCoord3Type max_point = maxPointWithOverlap();
349 return coord.x >= min_point.x && coord.x < max_point.x && coord.y >= min_point.y && coord.y < max_point.y && coord.z >= min_point.z && coord.z < max_point.z;
350}
351
352/*---------------------------------------------------------------------------*/
353/*---------------------------------------------------------------------------*/
354
356isInWithOverlap(CartCoordType x, CartCoordType y, CartCoordType z, Integer overlap) const
357{
358 const CartCoord3Type min_point = m_min_point - overlap;
359 const CartCoord3Type max_point = m_max_point + overlap;
360 return x >= min_point.x && x < max_point.x && y >= min_point.y && y < max_point.y && z >= min_point.z && z < max_point.z;
361}
362
363/*---------------------------------------------------------------------------*/
364/*---------------------------------------------------------------------------*/
365
367isInWithOverlap(CartCoord3Type coord, Integer overlap) const
368{
369 const CartCoord3Type min_point = m_min_point - overlap;
370 const CartCoord3Type max_point = m_max_point + overlap;
371 return coord.x >= min_point.x && coord.x < max_point.x && coord.y >= min_point.y && coord.y < max_point.y && coord.z >= min_point.z && coord.z < max_point.z;
372}
373
374/*---------------------------------------------------------------------------*/
375/*---------------------------------------------------------------------------*/
376
378haveIntersection(const AMRPatchPosition& other) const
379{
380 return (
381 (other.level() == level()) &&
382 (other.maxPoint().x > minPoint().x && maxPoint().x > other.minPoint().x) &&
383 (other.maxPoint().y > minPoint().y && maxPoint().y > other.minPoint().y) &&
384 (other.maxPoint().z > minPoint().z && maxPoint().z > other.minPoint().z));
385}
386
387/*---------------------------------------------------------------------------*/
388/*---------------------------------------------------------------------------*/
389
390} // End namespace Arcane
391
392/*---------------------------------------------------------------------------*/
393/*---------------------------------------------------------------------------*/
Déclarations des types généraux de Arcane.
CartCoord3Type minPointWithOverlap() const
Méthode permettant de récupérer la position min de la boite englobante en incluant la couche de maill...
CartCoord3Type length() const
Méthode permettant de connaitre la taille du patch (en nombre de mailles par direction).
void setMaxPoint(CartCoord3Type max_point)
Méthode permettant de définir la position max de la boite englobante.
bool canBeFusion(const AMRPatchPosition &other_patch) const
Méthode permettant de savoir si notre patch peut être fusionné avec other_patch.
AMRPatchPosition patchDown(Integer dim) const
Méthode permettant de créer un AMRPatchPosition pour le niveau inférieur.
AMRPatchPosition()
Constructeur pour une position nulle. Une position nulle est définie par un level = -2.
std::pair< AMRPatchPosition, AMRPatchPosition > cut(CartCoordType cut_point, Integer dim) const
Méthode permettant de découper le patch en deux patchs selon un point de découpe.
void setLevel(Int32 level)
Méthode permettant de définir le niveau du patch.
CartCoord3Type maxPoint() const
Méthode permettant de récupérer la position max de la boite englobante.
bool isNull() const
Méthode permettant de savoir si la position du patch est nulle.
void setMinPoint(CartCoord3Type min_point)
Méthode permettant de définir la position min de la boite englobante.
bool fusion(const AMRPatchPosition &other_patch)
Méthode permettant de fusionner other_patch avec le nôtre.
AMRPatchPosition patchUp(Integer dim) const
Méthode permettant de créer un AMRPatchPosition pour le niveau supérieur.
bool haveIntersection(const AMRPatchPosition &other) const
Méthode permettant de savoir si notre patch est en contact avec le patch other.
Int64 nbCells() const
Méthode permettant de connaitre le nombre de mailles du patch selon sa position.
Int32 overlapLayerSize() const
Méthode permettant de récupérer le nombre de couches de mailles de recouvrement du patch.
bool isIn(CartCoordType x, CartCoordType y, CartCoordType z) const
Méthode permettant de savoir si une maille de position x,y,z est incluse dans ce patch.
void setOverlapLayerSize(Int32 layer_size)
Méthode permettant de définir le nombre de couches de mailles de recouvrement du patch.
bool isInWithOverlap(CartCoordType x, CartCoordType y, CartCoordType z) const
Méthode permettant de savoir si une maille de position x,y,z est incluse dans ce patch avec couche de...
Int32 level() const
Méthode permettant de récupérer le niveau du patch.
CartCoord3Type maxPointWithOverlap() const
Méthode permettant de récupérer la position max de la boite englobante en incluant la couche de maill...
CartCoord3Type minPoint() const
Méthode permettant de récupérer la position min de la boite englobante.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
@ MD_DirY
Direction Y.
@ MD_DirX
Direction X.
std::int32_t Int32
Type entier signé sur 32 bits.