Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MeshCompacter.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* MeshCompacter.cc (C) 2000-2022 */
9/* */
10/* Gestion d'un échange de maillage entre sous-domaines. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/Timer.h"
15
16#include "arcane/ItemFamilyCompactInfos.h"
17#include "arcane/IItemFamily.h"
18#include "arcane/IItemFamilyPolicyMng.h"
19#include "arcane/IItemFamilyCompactPolicy.h"
20
21#include "arcane/mesh/MeshCompacter.h"
22#include "arcane/mesh/DynamicMesh.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane::mesh
28{
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32MeshCompacter::
33MeshCompacter(IMesh* mesh,ITimeStats* stats)
34: TraceAccessor(mesh->traceMng())
35, m_mesh(mesh)
36, m_time_stats(stats)
37, m_phase(ePhase::Init)
38, m_is_sorted(false)
39, m_is_compact_variables_and_groups(true)
40{
41 for( IItemFamily* family : m_mesh->itemFamilies() ){
42 _addFamily(family);
43 }
44}
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49MeshCompacter::
50MeshCompacter(IItemFamily* family,ITimeStats* stats)
51: TraceAccessor(family->traceMng())
52, m_mesh(family->mesh())
53, m_time_stats(stats)
54, m_phase(ePhase::Init)
55, m_is_sorted(false)
56, m_is_compact_variables_and_groups(true)
57{
58 _addFamily(family);
59}
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64MeshCompacter::
65~MeshCompacter()
66{
67 for( const auto& i : m_family_compact_infos_map )
68 delete i.second;
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77void MeshCompacter::
78_addFamily(IItemFamily* family)
79{
80 // N'ajoute la famille que si elle a une politique de compactage.
81 IItemFamilyCompactPolicy* c = family->policyMng()->compactPolicy();
82 if (c)
83 m_item_families.add(family);
84}
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
89void MeshCompacter::
90build()
91{
92 m_phase = ePhase::BeginCompact;
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98void MeshCompacter::
99_checkPhase(ePhase wanted_phase)
100{
101 if (m_phase!=wanted_phase)
102 ARCANE_FATAL("Invalid exchange phase wanted={0} current={1}",
103 (int)wanted_phase,(int)m_phase);
104}
105
106/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
108
109void MeshCompacter::
110beginCompact()
111{
112 _checkPhase(ePhase::BeginCompact);
113
114 // Débute un compactage et calcule les correspondances entre les
115 // nouveaux et les anciens localId().
116 {
117 Timer::Action ts_action(m_time_stats,"CompactItemsBegin");
118 for( IItemFamily* family : m_item_families ){
119 auto compact_infos = new ItemFamilyCompactInfos(this,family);
120 m_family_compact_infos_map.insert(std::make_pair(family,compact_infos));
121 }
122 for( IItemFamily* family : m_item_families ){
123 IItemFamilyCompactPolicy* c = family->policyMng()->compactPolicy();
124 auto iter = m_family_compact_infos_map.find(family);
125 if (iter==m_family_compact_infos_map.end())
126 ARCANE_FATAL("Can not find family '{0}'",family->name());
127 c->beginCompact(*iter->second);
128 }
129 }
130
131 m_phase = ePhase::CompactVariableAndGroups;
132}
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
137void MeshCompacter::
138compactVariablesAndGroups()
139{
140 _checkPhase(ePhase::CompactVariableAndGroups);
141
142 // Met à jour les groupes et les variables une fois les parents à jour.
143 // Il ne faut le faire que sur les familles qui sont compactées.
144 if (m_is_compact_variables_and_groups){
145 Timer::Action ts_action(m_time_stats,"CompactVariables");
146 for( const auto& iter : m_family_compact_infos_map ){
147 const ItemFamilyCompactInfos* compact_infos = iter.second;
148 IItemFamilyCompactPolicy* c = compact_infos->family()->policyMng()->compactPolicy();
149 c->compactVariablesAndGroups(*compact_infos);
150 }
151 }
152
153 m_phase = ePhase::UpdateInternalReferences;
154}
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
159void MeshCompacter::
160updateInternalReferences()
161{
162 _checkPhase(ePhase::UpdateInternalReferences);
163
164 // Met à jour les références de chaque entité.
165 {
166 Timer::Action ts_action(m_time_stats,"CompactUpdateInternalReferences");
167 for( IItemFamily* family : m_mesh->itemFamilies() ){
168 IItemFamilyCompactPolicy* c = family->policyMng()->compactPolicy();
169 if (c)
170 c->updateInternalReferences(this);
171 }
172 }
173
174 m_phase = ePhase::EndCompact;
175}
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180void MeshCompacter::
181endCompact()
182{
183 _checkPhase(ePhase::EndCompact);
184
185 // Termine le compactage.
186 {
187 Timer::Action ts_action(m_time_stats,"CompactItemFinish");
188
189 for( const auto& iter : m_family_compact_infos_map ){
190 ItemFamilyCompactInfos* compact_infos = iter.second;
191 IItemFamilyCompactPolicy* c = compact_infos->family()->policyMng()->compactPolicy();
192 c->endCompact(*compact_infos);
193 }
194 }
195
196 m_phase = ePhase::Finalize;
197}
198
199/*---------------------------------------------------------------------------*/
200/*---------------------------------------------------------------------------*/
201
202void MeshCompacter::
203finalizeCompact()
204{
205 _checkPhase(ePhase::Finalize);
206
207 // Notifie que le compactage est terminé.
208 {
209 Timer::Action ts_action(m_time_stats,"CompactItemFinish");
210
211 for( IItemFamily* family : m_mesh->itemFamilies() ){
212 IItemFamilyCompactPolicy* c = family->policyMng()->compactPolicy();
213 if (c)
214 c->finalizeCompact(this);
215 }
216 }
217
218 m_phase = ePhase::Ended;
219}
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
224const ItemFamilyCompactInfos* MeshCompacter::
225findCompactInfos(IItemFamily* family) const
226{
227 auto x = m_family_compact_infos_map.find(family);
228 if (x==m_family_compact_infos_map.end())
229 return nullptr;
230 return x->second;
231}
232
233/*---------------------------------------------------------------------------*/
234/*---------------------------------------------------------------------------*/
235
236IMesh* MeshCompacter::
237mesh() const
238{
239 return m_mesh;
240}
241
242/*---------------------------------------------------------------------------*/
243/*---------------------------------------------------------------------------*/
244
245void MeshCompacter::
246doAllActions()
247{
248 beginCompact();
249 compactVariablesAndGroups();
250 updateInternalReferences();
251 endCompact();
252 finalizeCompact();
253}
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258void MeshCompacter::
259setSorted(bool v)
260{
261 _checkPhase(ePhase::BeginCompact);
262 m_is_sorted = v;
263}
264
265/*---------------------------------------------------------------------------*/
266/*---------------------------------------------------------------------------*/
267
268void MeshCompacter::
269_setCompactVariablesAndGroups(bool v)
270{
271 _checkPhase(ePhase::BeginCompact);
272 m_is_compact_variables_and_groups = v;
273}
274
275/*---------------------------------------------------------------------------*/
276/*---------------------------------------------------------------------------*/
277
278ItemFamilyCollection MeshCompacter::
279families() const
280{
281 return m_item_families;
282}
283
284/*---------------------------------------------------------------------------*/
285/*---------------------------------------------------------------------------*/
286
287} // End namespace Arcane::mesh
288
289/*---------------------------------------------------------------------------*/
290/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Interface d'une famille d'entités.
Informations pour gérer le compactage des entités d'une famille.