Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
BasicItemPairGroupComputeFunctor.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* BasicItemPairGroupComputeFunctor.cc (C) 2000-2023 */
9/* */
10/* Fonctions basiques de calcul des valeurs des ItemPairGroup. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/NotImplementedException.h"
15#include "arcane/utils/ArgumentException.h"
16
17#include "arcane/IMesh.h"
18#include "arcane/ItemPairGroup.h"
19#include "arcane/ItemGroup.h"
20#include "arcane/IItemFamily.h"
21
22#include "arcane/mesh/BasicItemPairGroupComputeFunctor.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32/*
33 * TODO: Regarder pourquoi les méthodes de calcul suivantes:
34 * _computeCellCellFaceAdjency(ItemPairGroupImpl* array)
35 * _computeFaceCellNodeAdjency(ItemPairGroupImpl* array)
36 * _computeCellFaceFaceAdjency(ItemPairGroupImpl* array)
37 * sont spéciales et les fusionner avec les autres.
38 */
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42BasicItemPairGroupComputeFunctor::
43BasicItemPairGroupComputeFunctor(ITraceMng* tm)
44: TraceAccessor(tm)
45{
46 _addComputeAdjency(IK_Cell,IK_Cell,IK_Node,
47 &BasicItemPairGroupComputeFunctor::_computeCellCellNodeAdjency);
48 _addComputeAdjency(IK_Cell,IK_Cell,IK_Face,
49 &BasicItemPairGroupComputeFunctor::_computeCellCellFaceAdjency);
50 _addComputeAdjency(IK_Node,IK_Node,IK_Cell,
51 &BasicItemPairGroupComputeFunctor::_computeNodeNodeCellAdjency);
52 _addComputeAdjency(IK_Face,IK_Cell,IK_Node,
53 &BasicItemPairGroupComputeFunctor::_computeFaceCellNodeAdjency);
54 _addComputeAdjency(IK_Face,IK_Face,IK_Node,
55 &BasicItemPairGroupComputeFunctor::_computeFaceFaceNodeAdjency);
56 _addComputeAdjency(IK_Cell,IK_Face,IK_Face,
57 &BasicItemPairGroupComputeFunctor::_computeCellFaceFaceAdjency);
58 _addComputeAdjency(IK_Node,IK_Node,IK_Face,
59 &BasicItemPairGroupComputeFunctor::_computeNodeNodeFaceAdjency);
60 _addComputeAdjency(IK_Node,IK_Node,IK_Edge,
61 &BasicItemPairGroupComputeFunctor::_computeNodeNodeEdgeAdjency);
62 _addComputeAdjency(IK_Face,IK_Face,IK_Edge,
63 &BasicItemPairGroupComputeFunctor::_computeFaceFaceEdgeAdjency);
64 _addComputeAdjency(IK_Face,IK_Face,IK_Cell,
65 &BasicItemPairGroupComputeFunctor::_computeFaceFaceCellAdjency);
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
71void BasicItemPairGroupComputeFunctor::
72computeAdjency(ItemPairGroup adjency_array,eItemKind link_kind,
73 Integer nb_layer)
74{
75 if (nb_layer!=1)
76 throw ArgumentException(A_FUNCINFO,"nb_layer should be 1");
77 eItemKind item_kind = adjency_array.itemKind();
78 eItemKind sub_item_kind = adjency_array.subItemKind();
79 AdjencyType atype(item_kind,sub_item_kind,link_kind);
80 auto i = m_compute_adjency_functions.find(atype);
81 if (i==m_compute_adjency_functions.end()){
82 String s = String::format("Invalid adjency computation item_kind={0} sub_item_kind={1} link_item_kind={2}",
83 item_kind,sub_item_kind,link_kind);
84 throw NotImplementedException(A_FUNCINFO,s);
85 }
86 auto acf = new AdjencyComputeFunctor(this,adjency_array.internal(),i->second);
87 adjency_array.internal()->setComputeFunctor(acf);
88 adjency_array.invalidate();
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94void BasicItemPairGroupComputeFunctor::
95_addComputeAdjency(eItemKind ik,eItemKind sik,eItemKind lik,ComputeFunctor f)
96{
97 m_compute_adjency_functions.insert(std::make_pair(AdjencyType(ik,sik,lik),f));
98}
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103void BasicItemPairGroupComputeFunctor::
104_computeAdjency(ItemPairGroupImpl* array,
105 GetItemVectorViewFunctor get_link_item_enumerator,
106 GetItemVectorViewFunctor get_sub_item_enumerator)
107{
108 const ItemGroup& group = array->itemGroup();
109 const ItemGroup& sub_group = array->subItemGroup();
110 auto& indexes = array->unguardedIndexes();
111 indexes.clear();
112 auto& sub_items_local_id = array->unguardedLocalIds();
113 sub_items_local_id.clear();
114
115 IItemFamily* sub_family = sub_group.itemFamily();
116 const Integer max_sub_id = sub_family->maxLocalId();
117 Int32UniqueArray items_list(max_sub_id); // indéxé par des sub-items
118
119 IItemFamily* family = group.itemFamily();
120 const Integer max_id = family->maxLocalId(); // index maxi des items
121
122 const Integer forbidden_value = NULL_ITEM_ID;
123 const Integer undef_value = max_id+1;
124 items_list.fill(forbidden_value);
125
126 ENUMERATE_ITEM(iitem,sub_group) {
127 items_list[iitem.itemLocalId()] = undef_value;
128 }
129
130 indexes.add(0);
131 ENUMERATE_ITEM(iitem,group){
132 Item item = *iitem;
133 Integer local_id = iitem.itemLocalId();
134 // Pour ne pas s'ajouter à sa propre liste
135 if (items_list[local_id] != forbidden_value)
136 items_list[local_id] = local_id;
137 for( Item linkitem : get_link_item_enumerator(item) ){
138 for( Item subitem : get_sub_item_enumerator(linkitem) ){
139 Int32 sub_local_id = subitem.localId();
140 if (items_list[sub_local_id]==forbidden_value || items_list[sub_local_id]==local_id)
141 continue;
142 items_list[sub_local_id] = local_id;
143 sub_items_local_id.add(sub_local_id);
144 }
145 }
146 indexes.add(sub_items_local_id.largeSize());
147 }
148}
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
153void BasicItemPairGroupComputeFunctor::
154_computeCellCellFaceAdjency(ItemPairGroupImpl* array)
155{
156 const ItemGroup& group = array->itemGroup();
157 const ItemGroup& sub_group = array->subItemGroup();
158 auto& indexes = array->unguardedIndexes();
159 indexes.clear();
160 auto& sub_items_local_id = array->unguardedLocalIds();
161 sub_items_local_id.clear();
162
163 IItemFamily* sub_family = sub_group.itemFamily();
164 const Integer max_sub_id = sub_family->maxLocalId();
165 Int32UniqueArray items_list(max_sub_id); // indéxé par des sub-items
166
167 IItemFamily* family = group.itemFamily();
168 const Integer max_id = family->maxLocalId(); // index maxi des items
169
170 const Integer forbidden_value = NULL_ITEM_ID;
171 const Integer undef_value = max_id+1;
172 items_list.fill(forbidden_value);
173
174 ENUMERATE_CELL(icell,sub_group) {
175 items_list[icell.itemLocalId()] = undef_value;
176 }
177
178 indexes.add(0);
179 ENUMERATE_CELL(icell,group){
180 Cell cell = *icell;
181 //Integer local_id = cell.localId();
182 for( Face face : cell.faces() ){
183 if (face.nbCell()!=2)
184 continue;
185 Cell back_cell = face.backCell();
186 Cell front_cell = face.frontCell();
187
188 // On choisit l'autre cellule du cote de la face
189 const Integer sub_local_id = (back_cell==cell)?front_cell.localId():back_cell.localId();
190 if (items_list[sub_local_id] == forbidden_value)
191 continue;
192 sub_items_local_id.add(sub_local_id);
193 }
194 indexes.add(sub_items_local_id.largeSize());
195 }
196}
197
198/*---------------------------------------------------------------------------*/
199/*---------------------------------------------------------------------------*/
200
201void BasicItemPairGroupComputeFunctor::
202_computeFaceCellNodeAdjency(ItemPairGroupImpl* array)
203{
204 const ItemGroup& group = array->itemGroup();
205 const ItemGroup& sub_group = array->subItemGroup();
206 auto& indexes = array->unguardedIndexes();
207 indexes.clear();
208 auto& sub_items_local_id = array->unguardedLocalIds();
209 sub_items_local_id.clear();
210
211 IItemFamily* sub_family = sub_group.itemFamily();
212 const Integer max_sub_id = sub_family->maxLocalId();
213 Int32UniqueArray items_list(max_sub_id); // indéxé par des sub-items
214
215 IItemFamily* family = group.itemFamily();
216 const Integer max_id = family->maxLocalId(); // index maxi des items
217
218 const Integer forbidden_value = NULL_ITEM_ID;
219 const Integer undef_value = max_id+1;
220 items_list.fill(forbidden_value);
221
222 ENUMERATE_CELL(icell,sub_group) {
223 items_list[icell.itemLocalId()] = undef_value;
224 }
225
226 indexes.add(0);
227 ENUMERATE_FACE(iface,group){
228 Face face = *iface;
229 Int32 local_id = face.localId();
230 for( Node node : face.nodes() ){
231 for( Cell isubcell : node.cells() ){
232 Int32 sub_local_id = isubcell.localId();
233 if (items_list[sub_local_id]==forbidden_value || items_list[sub_local_id]==local_id)
234 continue;
235 items_list[sub_local_id] = local_id;
236 sub_items_local_id.add(sub_local_id);
237 }
238 }
239 indexes.add(sub_items_local_id.largeSize());
240 }
241}
242
243/*---------------------------------------------------------------------------*/
244/*---------------------------------------------------------------------------*/
245
246void BasicItemPairGroupComputeFunctor::
247_computeCellFaceFaceAdjency(ItemPairGroupImpl* array)
248{
249 const ItemGroup& group = array->itemGroup();
250 const ItemGroup& sub_group = array->subItemGroup();
251 auto& indexes = array->unguardedIndexes();
252 indexes.clear();
253 auto& sub_items_local_id = array->unguardedLocalIds();
254 sub_items_local_id.clear();
255
256 IItemFamily* sub_family = sub_group.itemFamily();
257 const Integer max_sub_id = sub_family->maxLocalId();
258 Int32UniqueArray items_list(max_sub_id); // indéxé par des sub-items
259
260 IItemFamily* family = group.itemFamily();
261 const Integer max_id = family->maxLocalId(); // index maxi des items
262
263 const Integer forbidden_value = NULL_ITEM_ID;
264 const Integer undef_value = max_id+1;
265 items_list.fill(forbidden_value);
266
267 ENUMERATE_FACE(iface,sub_group) {
268 items_list[iface.itemLocalId()] = undef_value;
269 }
270
271 indexes.add(0);
272 ENUMERATE_CELL(icell,group){
273 Cell cell = *icell;
274 for( FaceLocalId iface : cell.faceIds() ){
275 Int32 sub_local_id = iface.localId();
276 // Les controles sur les faces sont inutiles car on ne peut pas retomber dessus par l'énumération actuelle.
277 if (items_list[sub_local_id]==forbidden_value /* or items_list[sub_local_id]==local_id */)
278 continue;
279 // items_list[sub_local_id] = local_id;
280 sub_items_local_id.add(sub_local_id);
281 }
282 indexes.add(sub_items_local_id.largeSize());
283 }
284}
285
286/*---------------------------------------------------------------------------*/
287/*---------------------------------------------------------------------------*/
288
289void BasicItemPairGroupComputeFunctor::
290_computeCellCellNodeAdjency(ItemPairGroupImpl* array)
291{
292 GetItemVectorViewFunctor x = [](Item cell){ return cell.toCell().nodes(); };
293 GetItemVectorViewFunctor y = [](Item node){ return node.toNode().cells(); };
294
295 return _computeAdjency(array,x,y);
296}
297
298/*---------------------------------------------------------------------------*/
299/*---------------------------------------------------------------------------*/
300
301void BasicItemPairGroupComputeFunctor::
302_computeNodeNodeCellAdjency(ItemPairGroupImpl* array)
303{
304 GetItemVectorViewFunctor x = [](Item node){ return node.toNode().cells(); };
305 GetItemVectorViewFunctor y = [](Item cell){ return cell.toCell().nodes(); };
306
307 return _computeAdjency(array,x,y);
308}
309
310/*---------------------------------------------------------------------------*/
311/*---------------------------------------------------------------------------*/
312
313void BasicItemPairGroupComputeFunctor::
314_computeFaceFaceNodeAdjency(ItemPairGroupImpl* array)
315{
316 GetItemVectorViewFunctor x = [](Item face){ return face.toFace().nodes(); };
317 GetItemVectorViewFunctor y = [](Item node){ return node.toNode().faces(); };
318
319 return _computeAdjency(array,x,y);
320}
321
322/*---------------------------------------------------------------------------*/
323/*---------------------------------------------------------------------------*/
324
325void BasicItemPairGroupComputeFunctor::
326_computeNodeNodeFaceAdjency(ItemPairGroupImpl* array)
327{
328 GetItemVectorViewFunctor x = [](Item node){ return node.toNode().faces(); };
329 GetItemVectorViewFunctor y = [](Item face){ return face.toFace().nodes(); };
330
331 return _computeAdjency(array,x,y);
332}
333
334/*---------------------------------------------------------------------------*/
335/*---------------------------------------------------------------------------*/
336
337void BasicItemPairGroupComputeFunctor::
338_computeNodeNodeEdgeAdjency(ItemPairGroupImpl* array)
339{
340 GetItemVectorViewFunctor x = [](Item node){ return node.toNode().edges(); };
341 GetItemVectorViewFunctor y = [](Item edge){ return edge.toEdge().nodes(); };
342
343 return _computeAdjency(array,x,y);
344}
345
346/*---------------------------------------------------------------------------*/
347/*---------------------------------------------------------------------------*/
348
349void BasicItemPairGroupComputeFunctor::
350_computeFaceFaceEdgeAdjency(ItemPairGroupImpl* array)
351{
352 GetItemVectorViewFunctor x = [](Item face){ return face.toFace().edges(); };
353 GetItemVectorViewFunctor y = [](Item edge){ return edge.toEdge().faces(); };
354
355 return _computeAdjency(array,x,y);
356}
357
358/*---------------------------------------------------------------------------*/
359/*---------------------------------------------------------------------------*/
360
361void BasicItemPairGroupComputeFunctor::
362_computeFaceFaceCellAdjency(ItemPairGroupImpl* array)
363{
364 GetItemVectorViewFunctor x = [](Item face){ return face.toFace().cells(); };
365 GetItemVectorViewFunctor y = [](Item cell){ return cell.toCell().faces(); };
366
367 return _computeAdjency(array,x,y);
368}
369
370/*---------------------------------------------------------------------------*/
371/*---------------------------------------------------------------------------*/
372
373} // End namespace Arcane
374
375/*---------------------------------------------------------------------------*/
376/*---------------------------------------------------------------------------*/
#define ENUMERATE_FACE(name, group)
Enumérateur générique d'un groupe de faces.
#define ENUMERATE_CELL(name, group)
Enumérateur générique d'un groupe de mailles.
#define ENUMERATE_ITEM(name, group)
Enumérateur générique d'un groupe de noeuds.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:515
eItemKind
Genre d'entité de maillage.
Int32 Integer
Type représentant un entier.