Arcane  v4.1.3.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AMRPatchPositionLevelGroup.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/* AMRPatchPositionLevelGroup.cc (C) 2000-2026 */
9/* */
10/* Groupe de position de patch AMR réparti par niveau. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/cartesianmesh/internal/AMRPatchPositionLevelGroup.h"
15
16#include "arcane/cartesianmesh/AMRPatchPosition.h"
17
18#include <algorithm>
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29AMRPatchPositionLevelGroup::
30AMRPatchPositionLevelGroup(Int32 max_level)
31: m_max_level(max_level)
32, m_patches(max_level+1)
33{}
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38AMRPatchPositionLevelGroup::
39~AMRPatchPositionLevelGroup()
40= default;
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45Int32 AMRPatchPositionLevelGroup::
46maxLevel() const
47{
48 return m_max_level;
49}
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
54ConstArrayView<AMRPatchPosition> AMRPatchPositionLevelGroup::
55patches(Int32 level)
56{
57 return m_patches[level];
58}
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
63void AMRPatchPositionLevelGroup::
64addPatch(const AMRPatchPosition& patch)
65{
66 m_patches[patch.level()].add(patch);
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72void AMRPatchPositionLevelGroup::
73fusionPatches(Int32 level)
74{
75 fusionPatches(m_patches[level], true);
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
81void AMRPatchPositionLevelGroup::
82fusionPatches(UniqueArray<AMRPatchPosition>& patch_position, bool remove_null)
83{
84 // Algo de fusion.
85 // D'abord, on trie les patchs du plus petit nb de mailles au plus grand nb de mailles (optionnel).
86 // Ensuite, pour chaque patch, on regarde si l'on peut le fusionner avec un autre.
87 // Si on arrive à faire une fusion, on recommence l'algo jusqu'à ne plus pouvoir fusionner.
88 bool fusion = true;
89 while (fusion) {
90 fusion = false;
91
92 // Le sort permet de fusionner les patchs les plus petits d'abord, ce qui
93 // permet d'équilibrer (un peu) la taille des patchs.
94 // Attention : retirer le sort change les hashs des tests.
95 std::stable_sort(patch_position.begin(), patch_position.end(),
96 [](const AMRPatchPosition& a, const AMRPatchPosition& b) {
97 return a.nbCells() < b.nbCells();
98 });
99
100 for (Integer p0 = 0; p0 < patch_position.size(); ++p0) {
101 AMRPatchPosition& patch_fusion_0 = patch_position[p0];
102 if (patch_fusion_0.isNull())
103 continue;
104
105 for (Integer p1 = p0 + 1; p1 < patch_position.size(); ++p1) {
106 AMRPatchPosition& patch_fusion_1 = patch_position[p1];
107 if (patch_fusion_1.isNull())
108 continue;
109
110 // if (tm) {
111 // tm->info() << "Check fusion";
112 // tm->info() << " 0 -- Min point : " << patch_fusion_0.minPoint()
113 // << " -- Max point : " << patch_fusion_0.maxPoint()
114 // << " -- Level : " << patch_fusion_0.level()
115 // << " -- NbCells : " << patch_fusion_0.nbCells();
116 // tm->info() << " 1 -- Min point : " << patch_fusion_1.minPoint()
117 // << " -- Max point : " << patch_fusion_1.maxPoint()
118 // << " -- Level : " << patch_fusion_1.level()
119 // << " -- NbCells : " << patch_fusion_1.nbCells();
120 // }
121
122 // Si la fusion est possible, le patch 0 est agrandi et le patch 1 devient null.
123 if (patch_fusion_0.fusion(patch_fusion_1)) {
124 // if (tm)
125 // tm->info() << "Fusion OK";
126 fusion = true;
127 break;
128 }
129 }
130 if (fusion) {
131 break;
132 }
133 }
134 }
135 if (remove_null) {
136 for (Integer i = 0; i < patch_position.size(); ++i) {
137 if (patch_position[i].isNull()) {
138 patch_position.remove(i);
139 i--;
140 }
141 }
142 }
143}
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
148} // End namespace Arcane
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
void fusionPatches(Int32 level)
Méthode permettant de fusionner tous les patchs d'un certain niveau qui peuvent l'être.
Classe permettant de définir la position d'un patch dans le maillage cartésien.
bool fusion(AMRPatchPosition &other_patch)
Méthode permettant de fusionner other_patch avec le nôtre.
bool isNull() const
Méthode permettant de savoir si la position du patch est nulle.
Integer size() const
Nombre d'éléments du vecteur.
iterator end()
Itérateur sur le premier élément après la fin du tableau.
void remove(Int64 index)
Supprime l'entité ayant l'indice index.
iterator begin()
Itérateur sur le premier élément du tableau.
Vecteur 1D de données avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.
std::int32_t Int32
Type entier signé sur 32 bits.