Arcane  v4.1.1.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/*---------------------------------------------------------------------------*/
40
43: m_level(src.level())
44, m_min_point(src.minPoint())
45, m_max_point(src.maxPoint())
46, m_overlap_layer_size(src.overlapLayerSize())
47{
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
53AMRPatchPosition::
54~AMRPatchPosition()
55= default;
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
61level() const
62{
63 return m_level;
64}
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
71{
72 m_level = level;
73}
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
79minPoint() const
80{
81 return m_min_point;
82}
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
88setMinPoint(Int64x3 min_point)
89{
90 m_min_point = min_point;
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
97maxPoint() const
98{
99 return m_max_point;
100}
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
106setMaxPoint(Int64x3 max_point)
107{
108 m_max_point = max_point;
109}
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
115overlapLayerSize() const
116{
117 return m_overlap_layer_size;
118}
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
125{
126 m_overlap_layer_size = layer_size;
127}
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
131
134{
135 return m_min_point - m_overlap_layer_size;
136}
137
138/*---------------------------------------------------------------------------*/
139/*---------------------------------------------------------------------------*/
140
143{
144 return m_max_point + m_overlap_layer_size;
145}
146
147/*---------------------------------------------------------------------------*/
148/*---------------------------------------------------------------------------*/
149
151nbCells() const
152{
153 return (m_max_point.x - m_min_point.x) * (m_max_point.y - m_min_point.y) * (m_max_point.z - m_min_point.z);
154}
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
159std::pair<AMRPatchPosition, AMRPatchPosition> AMRPatchPosition::
160cut(Int64 cut_point, Integer dim) const
161{
162 Int64x3 patch_max_cut = m_max_point;
163 Int64x3 patch_min_cut = m_min_point;
164
165 if (dim == MD_DirX) {
166 patch_max_cut.x = cut_point;
167 patch_min_cut.x = cut_point;
168 }
169 else if (dim == MD_DirY) {
170 patch_max_cut.y = cut_point;
171 patch_min_cut.y = cut_point;
172 }
173 else {
174 patch_max_cut.z = cut_point;
175 patch_min_cut.z = cut_point;
176 }
177
178 AMRPatchPosition p0(*this);
179 p0.setMaxPoint(patch_max_cut);
180
181 AMRPatchPosition p1(*this);
182 p1.setMinPoint(patch_min_cut);
183
184 return { p0, p1 };
185}
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
189
191canBeFusion(const AMRPatchPosition& other_patch) const
192{
193 const Int64x3 min_point = other_patch.minPoint();
194 const Int64x3 max_point = other_patch.maxPoint();
195 return m_level == other_patch.level() &&
196 (((m_min_point.x == max_point.x || m_max_point.x == min_point.x) &&
197 (m_min_point.y == min_point.y && m_max_point.y == max_point.y) &&
198 (m_min_point.z == min_point.z && m_max_point.z == max_point.z)) ||
199
200 ((m_min_point.x == min_point.x && m_max_point.x == max_point.x) &&
201 (m_min_point.y == max_point.y || m_max_point.y == min_point.y) &&
202 (m_min_point.z == min_point.z && m_max_point.z == max_point.z)) ||
203
204 ((m_min_point.x == min_point.x && m_max_point.x == max_point.x) &&
205 (m_min_point.y == min_point.y && m_max_point.y == max_point.y) &&
206 (m_min_point.z == max_point.z || m_max_point.z == min_point.z)));
207}
208
209/*---------------------------------------------------------------------------*/
210/*---------------------------------------------------------------------------*/
211
213fusion(const AMRPatchPosition& other_patch)
214{
215 if (!canBeFusion(other_patch)) {
216 return false;
217 }
218
219 const Int64x3 min_point = other_patch.minPoint();
220 const Int64x3 max_point = other_patch.maxPoint();
221
222 if (m_min_point.x > min_point.x) {
223 m_min_point.x = min_point.x;
224 }
225 else if (m_max_point.x < max_point.x) {
226 m_max_point.x = max_point.x;
227 }
228
229 else if (m_min_point.y > min_point.y) {
230 m_min_point.y = min_point.y;
231 }
232 else if (m_max_point.y < max_point.y) {
233 m_max_point.y = max_point.y;
234 }
235
236 else if (m_min_point.z > min_point.z) {
237 m_min_point.z = min_point.z;
238 }
239 else if (m_max_point.z < max_point.z) {
240 m_max_point.z = max_point.z;
241 }
242
243 return true;
244}
245
246/*---------------------------------------------------------------------------*/
247/*---------------------------------------------------------------------------*/
248
250isNull() const
251{
252 return m_level == -2;
253}
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
259patchUp(Integer dim) const
260{
262 p.setLevel(m_level + 1);
263 p.setMinPoint(m_min_point * 2);
264 if (dim == 2) {
265 p.setMaxPoint({ m_max_point.x * 2, m_max_point.y * 2, 1 });
266 }
267 else {
268 p.setMaxPoint(m_max_point * 2);
269 }
270 p.setOverlapLayerSize(m_overlap_layer_size * 2);
271 return p;
272}
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
278patchDown(Integer dim) const
279{
281 p.setLevel(m_level - 1);
282 p.setMinPoint(m_min_point / 2);
283 if (dim == 2) {
284 p.setMaxPoint({ static_cast<Int64>(std::ceil(m_max_point.x / 2.)), static_cast<Int64>(std::ceil(m_max_point.y / 2.)), 1 });
285 }
286 else {
287 p.setMaxPoint({ static_cast<Int64>(std::ceil(m_max_point.x / 2.)), static_cast<Int64>(std::ceil(m_max_point.y / 2.)), static_cast<Int64>(std::ceil(m_max_point.z / 2.)) });
288 }
289 p.setOverlapLayerSize((m_overlap_layer_size / 2) + 1);
290 return p;
291}
292
293/*---------------------------------------------------------------------------*/
294/*---------------------------------------------------------------------------*/
295
297length() const
298{
299 return m_max_point - m_min_point;
300}
301
302/*---------------------------------------------------------------------------*/
303/*---------------------------------------------------------------------------*/
304
306isIn(Int64 x, Int64 y, Int64 z) const
307{
308 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;
309}
310
311/*---------------------------------------------------------------------------*/
312/*---------------------------------------------------------------------------*/
313
315isInWithOverlap(Int64 x, Int64 y, Int64 z) const
316{
317 const Int64x3 min_point = minPointWithOverlap();
318 const Int64x3 max_point = maxPointWithOverlap();
319 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;
320}
321
322/*---------------------------------------------------------------------------*/
323/*---------------------------------------------------------------------------*/
324
326isInWithOverlap(Int64 x, Int64 y, Int64 z, Integer overlap) const
327{
328 const Int64x3 min_point = m_min_point - overlap;
329 const Int64x3 max_point = m_max_point + overlap;
330 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;
331}
332
333/*---------------------------------------------------------------------------*/
334/*---------------------------------------------------------------------------*/
335
337haveIntersection(const AMRPatchPosition& other) const
338{
339 return (
340 (other.maxPoint().x > minPoint().x && maxPoint().x > other.minPoint().x) &&
341 (other.maxPoint().y > minPoint().y && maxPoint().y > other.minPoint().y) &&
342 (other.maxPoint().z > minPoint().z && maxPoint().z > other.minPoint().z));
343}
344
345/*---------------------------------------------------------------------------*/
346/*---------------------------------------------------------------------------*/
347
348} // End namespace Arcane
349
350/*---------------------------------------------------------------------------*/
351/*---------------------------------------------------------------------------*/
Déclarations des types généraux de Arcane.
bool isIn(Int64 x, Int64 y, Int64 z) const
Méthode permettant de savoir si une maille de position x,y,z est incluse dans ce patch.
bool canBeFusion(const AMRPatchPosition &other_patch) const
Méthode permettant de savoir si notre patch peut être fusionné avec other_patch.
Int64x3 maxPointWithOverlap() const
Méthode permettant de récupérer la position max de la boite englobante en incluant la couche de maill...
void setOverlapLayerSize(Integer layer_size)
Méthode permettant de définir le nombre de couches de mailles de recouvrement du patch.
AMRPatchPosition patchDown(Integer dim) const
Méthode permettant de créer un AMRPatchPosition pour le niveau inférieur.
Int64x3 minPoint() const
Méthode permettant de récupérer la position min de la boite englobante.
void setLevel(Integer level)
Méthode permettant de définir le niveau du patch.
Int64x3 maxPoint() const
Méthode permettant de récupérer la position max de la boite englobante.
AMRPatchPosition()
Constructeur pour une position nulle. Une position nulle est définie par un level = -2.
bool isNull() const
Méthode permettant de savoir si la position du patch est nulle.
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.
Int64x3 minPointWithOverlap() const
Méthode permettant de récupérer la position min de la boite englobante en incluant la couche de maill...
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.
void setMinPoint(Int64x3 min_point)
Méthode permettant de définir la position min de la boite englobante.
Int64x3 length() const
Méthode permettant de connaitre la taille du patch (en nombre de mailles par direction).
std::pair< AMRPatchPosition, AMRPatchPosition > cut(Int64 cut_point, Integer dim) const
Méthode permettant de découper le patch en deux patchs selon un point de découpe.
void setMaxPoint(Int64x3 max_point)
Méthode permettant de définir la position max de la boite englobante.
Integer overlapLayerSize() const
Méthode permettant de récupérer le nombre de couches de mailles de recouvrement du patch.
bool isInWithOverlap(Int64 x, Int64 y, Int64 z) const
Méthode permettant de savoir si une maille de position x,y,z est incluse dans ce patch avec couche de...
Integer level() const
Méthode permettant de récupérer le niveau du patch.
-*- 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.