Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
MeshComponentData.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/* MeshComponentData.cc (C) 2000-2024 */
9/* */
10/* Données d'un constituant (matériau ou milieu) d'un maillage. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/materials/internal/MeshComponentData.h"
15
16#include "arcane/utils/FatalErrorException.h"
17
18#include "arcane/core/IItemFamily.h"
19#include "arcane/core/ItemPrinter.h"
20#include "arcane/core/materials/IMeshMaterialMng.h"
21#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
22
23#include "arcane/materials/internal/MeshMaterialVariableIndexer.h"
24#include "arcane/materials/internal/MeshComponentPartData.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane::Materials
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35MeshComponentData::
36MeshComponentData(IMeshComponent* component, const String& name,
37 Int16 component_id, ComponentItemSharedInfo* shared_info,
38 bool create_indexer)
39: TraceAccessor(component->traceMng())
40, m_component(component)
41, m_component_id(component_id)
42, m_name(name)
43, m_constituent_local_id_list(shared_info, String("MeshComponentDataIdList")+name)
44, m_recompute_part_data_functor(this, &MeshComponentData::_rebuildPartDataDirect)
45{
46 if (create_indexer) {
47 m_variable_indexer = new MeshMaterialVariableIndexer(traceMng(), name);
48 m_is_indexer_owner = true;
49 }
50}
51
52/*---------------------------------------------------------------------------*/
53/*---------------------------------------------------------------------------*/
54
55MeshComponentData::
56~MeshComponentData()
57{
58 delete m_part_data;
59 if (m_is_indexer_owner)
60 delete m_variable_indexer;
61}
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
69void MeshComponentData::
70_setPartInfo()
71{
72 if (m_part_data)
73 m_part_data->_setConstituentListView(m_constituent_local_id_list.view());
74}
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
79void MeshComponentData::
80_resizeItemsInternal(Integer nb_item)
81{
82 m_constituent_local_id_list.resize(nb_item);
83 _setPartInfo();
84}
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
89void MeshComponentData::
90_setVariableIndexer(MeshMaterialVariableIndexer* indexer)
91{
92 m_variable_indexer = indexer;
93 m_is_indexer_owner = false;
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99void MeshComponentData::
100_setItems(const ItemGroup& group)
101{
102 m_items = group;
103 if (m_variable_indexer)
104 m_variable_indexer->setCells(group);
105}
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109
110void MeshComponentData::
111_buildPartData()
112{
113 m_part_data = new MeshComponentPartData(m_component, m_name);
114 m_part_data->setRecomputeFunctor(&m_recompute_part_data_functor);
115 _setPartInfo();
116}
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120/*!
121 * \brief Met à jour les m_items_internal du constituant
122 * après changement de la numérotation locale.
123 *
124 * \warning il faut appeler cette méthode avant de mettre à jour le
125 * m_variable_indexer car on se sert de ses local_ids.
126 */
127void MeshComponentData::
128_changeLocalIdsForInternalList(Int32ConstArrayView old_to_new_ids)
129{
130 // TODO: regarder s'il est possible de supprimer le tableau temporaire
131 // new_internals (c'est à peu près sur que c'est possible).
132 ConstArrayView<ConstituentItemIndex> current_internals(m_constituent_local_id_list.localIds());
133 UniqueArray<ConstituentItemIndex> new_internals;
134
135 Int32ConstArrayView local_ids = variableIndexer()->localIds();
136
137 for (Integer i = 0, nb = current_internals.size(); i < nb; ++i) {
138 Int32 lid = local_ids[i];
139 Int32 new_lid = old_to_new_ids[lid];
140 if (new_lid != NULL_ITEM_LOCAL_ID) {
141 new_internals.add(current_internals[i]);
142 m_constituent_local_id_list.itemBase(i)._setGlobalItem(ItemLocalId(new_lid));
143 }
144 }
145
146 // TODO: regarder supprimer cette copie aussi.
147 {
148 _resizeItemsInternal(new_internals.size());
149 m_constituent_local_id_list.copy(new_internals);
150 }
151}
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156void MeshComponentData::
157_rebuildPartData(RunQueue& queue)
158{
159 if (!m_part_data)
160 _buildPartData();
161 _setPartInfo();
162 const bool do_lazy_evaluation = true;
163 if (do_lazy_evaluation)
164 m_part_data->setNeedRecompute();
165 else
166 m_part_data->_setFromMatVarIndexes(m_variable_indexer->matvarIndexes(), queue);
167}
168
169/*---------------------------------------------------------------------------*/
170/*---------------------------------------------------------------------------*/
171
172void MeshComponentData::
173_rebuildPartDataDirect()
174{
175 RunQueue& queue = m_component->materialMng()->_internalApi()->runQueue();
176 m_part_data->_setFromMatVarIndexes(m_variable_indexer->matvarIndexes(), queue);
177}
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182void MeshComponentData::
183checkValid()
184{
185 if (!arcaneIsCheck())
186 return;
187
188 info(4) << "Check valid component name=" << name();
189 m_variable_indexer->checkValid();
190
191 // Vérifie que les groupes sont cohérents entre cette instance
192 // et le groupe dans m_variable_indexer
193 if (m_items!=m_variable_indexer->cells())
194 ARCANE_FATAL("Incoherent group for component name={0} data={1} indexer={2}",
195 name(),m_items.name(),m_variable_indexer->cells().name());
196
197 // Vérifie que la liste des indexer->localIds() et celle
198 // du groupe 'cells' est la meme. Pour cela, on déclare un tableau
199 // qu'on indexe par le localId() de la maille. Pour chaque élément on
200 // ajoute 1 si la maille est dans le groupe et 2 si elle est dans les
201 // structures internes du composant. Si la valeur finale n'est pas 3 il
202 // y a incohérence.
203 {
204 IItemFamily* family = m_items.itemFamily();
205 UniqueArray<Int32> presence(family->maxLocalId());
206 presence.fill(0);
207 ENUMERATE_ITEM(iitem,m_items){
208 presence[iitem.itemLocalId()] = 1;
209 }
210 Int32ConstArrayView indexer_local_ids = m_variable_indexer->localIds();
211 for( Integer i=0, n=indexer_local_ids.size(); i<n; ++i )
212 presence[indexer_local_ids[i]] += 2;
213 ItemInfoListView items_internal = family->itemInfoListView();
214 Integer nb_error = 0;
215 for( Integer i=0, n=presence.size(); i<n; ++i ){
216 Int32 v = presence[i];
217 if (v==3 || v==0)
218 continue;
219 Cell cell(items_internal[i]);
220 ++nb_error;
221 info(4) << "WARNING: Incoherence between group and internals "
222 << " component=" << name() << " v=" << v
223 << " cell=" << ItemPrinter(cell);
224 }
225 if (nb_error!=0){
226 warning() << "WARNING: Incoherence between group and internals "
227 << " component=" << name() << " nb_error=" << nb_error;
228 }
229 }
230
231 // Vérifie la cohérence des MatVarIndex entre le tableau direct
232 // et les valeurs dans les m_items_internal
233 ConstArrayView<MatVarIndex> mat_var_indexes(m_variable_indexer->matvarIndexes());
234 Integer nb_val = mat_var_indexes.size();
235 info(4) << "CheckValid component_name=" << name()
236 << " matvar_indexes=" << mat_var_indexes;
237 info(4) << "Cells=" << m_variable_indexer->cells().view().localIds();
238 for( Integer i=0; i<nb_val; ++ i){
239 MatVarIndex component_mvi = m_constituent_local_id_list.variableIndex(i);
240 MatVarIndex mvi = mat_var_indexes[i];
241 if (component_mvi!=mvi)
242 ARCANE_FATAL("Bad 'var_index' environment={3} component='{0}' direct='{1}' i={2}",
243 component_mvi,mvi,i,name());
244 }
245
246 if (m_part_data)
247 m_part_data->checkValid();
248}
249
250/*---------------------------------------------------------------------------*/
251/*---------------------------------------------------------------------------*/
252
253}
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define ENUMERATE_ITEM(name, group)
Enumérateur générique d'un groupe de noeuds.
Active toujours les traces dans les parties Arcane concernant les matériaux.
bool arcaneIsCheck()
Vrai si on est en mode vérification.
Definition Misc.cc:151
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:640
Int32 Integer
Type représentant un entier.