Arcane  v3.16.0.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
CartesianPatchGroup.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/* CartesianPatchGroup.cc (C) 2000-2025 */
9/* */
10/* Gestion du groupe de patchs du maillage cartésien. */
11/*---------------------------------------------------------------------------*/
12
13#include "arcane/cartesianmesh/CartesianPatchGroup.h"
14
15#include "arcane/cartesianmesh/internal/CartesianMeshPatch.h"
16#include "arcane/core/IMesh.h"
17#include "arcane/core/IParallelMng.h"
18#include "arccore/trace/ITraceMng.h"
19
20#include "arcane/cartesianmesh/ICartesianMeshNumberingMng.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31Ref<CartesianMeshPatch> CartesianPatchGroup::
32groundPatch()
33{
34 _createGroundPatch();
35 return patch(0);
36}
37
38void CartesianPatchGroup::
39addPatch(CellGroup cell_group)
40{
41 _createGroundPatch();
42 if (cell_group.null()) ARCANE_FATAL("Null cell group");
43 auto* cdi = new CartesianMeshPatch(m_cmesh, nextIndexForNewPatch()+1); // +1 pour reproduire l'ancien comportement.
44 m_amr_patch_cell_groups.add(cell_group);
45 _addPatchInstance(makeRef(cdi));
46 m_cmesh->traceMng()->info() << "m_amr_patch_cell_groups : " << m_amr_patch_cell_groups.size()
47 << " -- m_amr_patches : " << m_amr_patches.size()
48 << " -- m_amr_patches_pointer : " << m_amr_patches_pointer.size()
49 << " -- cell_group name : " << m_amr_patch_cell_groups[nextIndexForNewPatch()-1].name()
50 << " -- index : " << nextIndexForNewPatch()-1
51 ;
52}
53
54// Attention : avant _createGroundPatch() = 0, après _createGroundPatch(); = 1
55Integer CartesianPatchGroup::
56nbPatch() const
57{
58 return m_amr_patches.size();
59}
60
61Ref<CartesianMeshPatch> CartesianPatchGroup::
62patch(const Integer index) const
63{
64 return m_amr_patches[index];
65}
66
67CartesianMeshPatchListView CartesianPatchGroup::
68patchListView() const
69{
70 return CartesianMeshPatchListView{m_amr_patches_pointer};
71}
72
73CellGroup CartesianPatchGroup::
74cells(const Integer index)
75{
76 if (index == 0) {
77 ARCANE_FATAL("You cannot get cells of ground patch with this method");
78 }
79 return m_amr_patch_cell_groups[index-1];
80}
81
82// Attention : efface aussi le ground patch. Nécessaire de le récupérer après coup.
83void CartesianPatchGroup::
84clear()
85{
86 m_amr_patch_cell_groups.clear();
87 m_amr_patches_pointer.clear();
88 m_amr_patches.clear();
89 _createGroundPatch();
90}
91
92void CartesianPatchGroup::
93removePatch(const Integer index)
94{
95 if (m_patches_to_delete.contains(index)) {
96 return;
97 }
98 if (index == 0) {
99 ARCANE_FATAL("You cannot remove ground patch");
100 }
101 if (index < 1 || index >= m_amr_patch_cell_groups.size()) {
102 ARCANE_FATAL("Invalid index");
103 }
104
105 m_patches_to_delete.add(index);
106}
107
108void CartesianPatchGroup::
109removeCellsInAllPatches(ConstArrayView<Int32> cells_local_id)
110{
111 for (CellGroup cells : m_amr_patch_cell_groups) {
112 cells.removeItems(cells_local_id);
113 }
114}
115
116void CartesianPatchGroup::
117removeCellsInAllPatches(ConstArrayView<Int32> cells_local_id, SharedArray<Integer> altered_patches)
118{
119 UniqueArray<Integer> size_of_patches_before(m_amr_patch_cell_groups.size());
120 for (Integer i = 0; i < m_amr_patch_cell_groups.size(); ++i) {
121 size_of_patches_before[i] = m_amr_patch_cell_groups[i].size();
122 }
123 m_cmesh->mesh()->parallelMng()->reduce(MessagePassing::ReduceMax, size_of_patches_before);
124
125 for (CellGroup cells : m_amr_patch_cell_groups) {
126 cells.removeItems(cells_local_id);
127 }
128
129 UniqueArray<Integer> size_of_patches_after(m_amr_patch_cell_groups.size());
130 for (Integer i = 0; i < m_amr_patch_cell_groups.size(); ++i) {
131 size_of_patches_after[i] = m_amr_patch_cell_groups[i].size();
132 }
133 m_cmesh->mesh()->parallelMng()->reduce(MessagePassing::ReduceMax, size_of_patches_after);
134
135 altered_patches.clear();
136 for (Integer i = 0; i < size_of_patches_after.size(); ++i) {
137 if (size_of_patches_before[i] != size_of_patches_after[i]) {
138 altered_patches.add(i+1);
139 }
140 }
141}
142
143void CartesianPatchGroup::
144applyPatchEdit(bool remove_empty_patches)
145{
146 _removeMultiplePatches(m_patches_to_delete);
147 m_patches_to_delete.clear();
148
149 if (remove_empty_patches) {
150 UniqueArray<Integer> size_of_patches(m_amr_patch_cell_groups.size());
151 for (Integer i = 0; i < m_amr_patch_cell_groups.size(); ++i) {
152 size_of_patches[i] = m_amr_patch_cell_groups[i].size();
153 }
154 m_cmesh->mesh()->parallelMng()->reduce(MessagePassing::ReduceMax, size_of_patches);
155 for (Integer i = 0; i < size_of_patches.size(); ++i) {
156 if (size_of_patches[i] == 0) {
157 m_patches_to_delete.add(i+1);
158 }
159 }
160 _removeMultiplePatches(m_patches_to_delete);
161 m_patches_to_delete.clear();
162 }
163}
164
165// void CartesianPatchGroup::
166// repairPatch(Integer index, ICartesianMeshNumberingMng* numbering_mng)
167// {
168// UniqueArray<Integer> size_of_line;
169// UniqueArray<Integer> begin_of_line;
170//
171// ENUMERATE_ ()
172// CellDirectionMng cells = m_amr_patches_pointer[index]->cellDirection(eMeshDirection::MD_DirX);
173// cells.cell()
174//
175// // Localement, découper le old_patch en patch X.
176// // Echange pour avoir la taille réel des patchs X.
177// // Fusion des patchs X ayant le même originX et lenghtX (entre Y et Y+1).
178// // (3D) Fusion des patchs XY ayant le même originXY et lenghtXY (entre Z et Z+1).
179// }
180
181void CartesianPatchGroup::
182updateLevelsBeforeCoarsen()
183{
184 for (ICartesianMeshPatch* patch : m_amr_patches_pointer) {
185 patch->setLevel(patch->level() + 1);
186 }
187}
188
189Integer CartesianPatchGroup::
190nextIndexForNewPatch(){
191 return m_amr_patch_cell_groups.size();
192}
193
194void CartesianPatchGroup::
195_addPatchInstance(Ref<CartesianMeshPatch> v)
196{
197 m_amr_patches.add(v);
198 m_amr_patches_pointer.add(v.get());
199}
200
201void CartesianPatchGroup::
202_removeOnePatch(Integer index)
203{
204 m_amr_patch_cell_groups.remove(index-1);
205 m_amr_patches_pointer.remove(index);
206 m_amr_patches.remove(index);
207}
208void CartesianPatchGroup::
209_removeMultiplePatches(ConstArrayView<Integer> indexes)
210{
211 Integer count = 0;
212 for (const Integer index : indexes) {
213 _removeOnePatch(index - count);
214 count++;
215 }
216}
217
218void CartesianPatchGroup::
219_createGroundPatch()
220{
221 if (!m_amr_patches.empty()) return;
222 _addPatchInstance(makeRef(new CartesianMeshPatch(m_cmesh, -1)));
223}
224
225/*---------------------------------------------------------------------------*/
226/*---------------------------------------------------------------------------*/
227
228} // End namespace Arcane
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Vue constante d'un tableau de type T.
Référence à une instance.
Vecteur 1D de données avec sémantique par référence.
ItemGroupT< Cell > CellGroup
Groupe de mailles.
Definition ItemTypes.h:183
@ ReduceMax
Maximum des valeurs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.