Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ExtraGhostCellsBuilder.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* ExtraGhostCellsBuilder.cc (C) 2000-2024 */
9/* */
10/* Construction des mailles fantômes supplémentaires. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ScopedPtr.h"
15#include "arcane/utils/CheckedConvert.h"
16
17#include "arcane/IExtraGhostCellsBuilder.h"
18#include "arcane/IParallelExchanger.h"
19#include "arcane/IParallelMng.h"
20#include "arcane/ISerializeMessage.h"
21#include "arcane/ParallelMngUtils.h"
22
23#include "arcane/mesh/ExtraGhostCellsBuilder.h"
24#include "arcane/mesh/DynamicMesh.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane::mesh
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35ExtraGhostCellsBuilder::
36ExtraGhostCellsBuilder(DynamicMesh* mesh)
37: TraceAccessor(mesh->traceMng())
38, m_mesh(mesh)
39{
40}
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45void ExtraGhostCellsBuilder::
46addExtraGhostCellsBuilder(IExtraGhostCellsBuilder* builder)
47{
48 if (m_builders.contains(builder))
49 ARCANE_FATAL("Instance {0} is already registered",builder);
50 m_builders.add(builder);
51}
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
56void ExtraGhostCellsBuilder::
57removeExtraGhostCellsBuilder(IExtraGhostCellsBuilder* builder)
58{
59 auto iter_begin = m_builders.begin();
60 auto iter_end = m_builders.end();
61 auto x = std::find(iter_begin,iter_end,builder);
62 if (x==iter_end)
63 ARCANE_FATAL("Instance {0} is not registered",builder);
64 m_builders.remove(x - iter_begin);
65}
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
70bool ExtraGhostCellsBuilder::
71hasBuilder() const
72{
73 return !m_builders.empty();
74}
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
79void ExtraGhostCellsBuilder::
80computeExtraGhostCells()
81{
82 if (m_builders.empty())
83 return;
84
85 info() << "Compute extra ghost cells";
86
87 for( IExtraGhostCellsBuilder* v : m_builders ){
88 // Calcul de mailles extraordinaires à envoyer
89 v->computeExtraCellsToSend();
90 }
91
92 IParallelMng* pm = m_mesh->parallelMng();
93
94 auto exchanger { ParallelMngUtils::createExchangerRef(pm) };
95
96 const Int32 nsd = pm->commSize();
97
98 // Construction des items à envoyer
99 UniqueArray<std::set<Integer> > to_sends(nsd);
100
101 // Initialisation de l'échangeur de données
102 for(Integer isd=0;isd<nsd;++isd) {
103 std::set<Integer>& cell_set = to_sends[isd];
104 for( IExtraGhostCellsBuilder* builder : m_builders ){
105 Int32ConstArrayView extra_cells = builder->extraCellsToSend(isd);
106 // On trie les lids à envoyer pour éviter les doublons
107 for(Integer j=0, size=extra_cells.size(); j<size; ++j)
108 cell_set.insert(extra_cells[j]);
109 }
110 if (!cell_set.empty())
111 exchanger->addSender(isd);
112 }
113 exchanger->initializeCommunicationsMessages();
114
115 // Envoi des mailles
116 for (Integer i=0, ns=exchanger->nbSender(); i<ns; ++i) {
117 ISerializeMessage* sm = exchanger->messageToSend(i);
118 const Int32 rank = sm->destination().value();
119 ISerializer* s = sm->serializer();
120 const std::set<Integer>& cell_set = to_sends[rank];
121 Int32UniqueArray items_to_send(cell_set.size());
122 std::copy(std::begin(cell_set),std::end(cell_set),std::begin(items_to_send));
123 m_mesh->serializeCells(s, items_to_send);
124 }
125 exchanger->processExchange();
126
127 // Réception des mailles
128 for( Integer i=0, ns=exchanger->nbReceiver(); i<ns; ++i ) {
129 ISerializeMessage* sm = exchanger->messageToReceive(i);
130 ISerializer* s = sm->serializer();
131 m_mesh->addCells(s);
132 }
133
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
139} // End namespace Arcane::mesh
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
virtual Int32 commSize() const =0
Nombre d'instance dans le communicateur.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:640
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:515