Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemGroup.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* ItemGroup.cc (C) 2000-2025 */
9/* */
10/* Mesh entity groups. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/ItemGroup.h"
15
16#include "arcane/utils/String.h"
17#include "arcane/utils/ArgumentException.h"
18
19#include "arcane/core/IItemFamily.h"
20#include "arcane/core/IMesh.h"
21#include "arcane/core/ICaseMng.h"
22#include "arcane/core/CaseOptionBase.h"
23#include "arcane/core/ICaseOptionList.h"
24#include "arcane/core/MeshHandle.h"
25#include "arcane/core/internal/ItemGroupInternal.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
124: m_impl(grp)
125{
126 // If \a grp is null, it is replaced by the null group.
127 // This is done (version 2.3) for compatibility reasons.
128 // Eventually, this constructor will be explicit, and in that case, you will have to do:
129 // ARCANE_CHECK_POINTER(grp);
130 if (!grp) {
131 std::cerr << "Creating group with null pointer is not allowed\n";
132 m_impl = ItemGroupImpl::checkSharedNull();
133 }
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
140ItemGroup()
141: m_impl(ItemGroupImpl::checkSharedNull())
142{
143}
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
149isOwn() const
150{
151 if (null())
152 return true;
153
154 return m_impl->isOwn();
155}
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
161setOwn(bool v)
162{
163 if (!null())
164 m_impl->setOwn(v);
165}
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
169
182own() const
183{
184 if (null() || isOwn())
185 return (*this);
186 m_impl->checkNeedUpdate();
187 return ItemGroup(m_impl->ownGroup());
188}
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
193// group of items owned by the subdomain
194ItemGroup ItemGroup::
195ghost() const
196{
197 if (null())
198 return ItemGroup();
199 m_impl->checkNeedUpdate();
200 return ItemGroup(m_impl->ghostGroup());
201}
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
206// Items in the group lying on the boundary between two subdomains
207// Implemented for faces only
208ItemGroup ItemGroup::
209interface() const
210{
211 if (null())
212 return ItemGroup();
213 m_impl->checkNeedUpdate();
214 return ItemGroup(m_impl->interfaceGroup());
215}
216
217// HANDLE CRASH SORTED
218/*---------------------------------------------------------------------------*/
219/*---------------------------------------------------------------------------*/
220
222nodeGroup() const
223{
224 if (null())
225 return ItemGroup();
226 m_impl->checkNeedUpdate();
227 return NodeGroup(m_impl->nodeGroup());
228}
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
234edgeGroup() const
235{
236 if (null())
237 return ItemGroup();
238 m_impl->checkNeedUpdate();
239 return EdgeGroup(m_impl->edgeGroup());
240}
241
242/*---------------------------------------------------------------------------*/
243/*---------------------------------------------------------------------------*/
244
246faceGroup() const
247{
248 if (null())
249 return ItemGroup();
250 m_impl->checkNeedUpdate();
251 return FaceGroup(m_impl->faceGroup());
252}
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
256
258cellGroup() const
259{
260 if (null())
261 return ItemGroup();
262 m_impl->checkNeedUpdate();
263 return CellGroup(m_impl->cellGroup());
264}
265
266/*---------------------------------------------------------------------------*/
267/*---------------------------------------------------------------------------*/
268
270innerFaceGroup() const
271{
272 if (null())
273 return ItemGroup();
274 m_impl->checkNeedUpdate();
275 return FaceGroup(m_impl->innerFaceGroup());
276}
277
278/*---------------------------------------------------------------------------*/
279/*---------------------------------------------------------------------------*/
280
282outerFaceGroup() const
283{
284 if (null())
285 return ItemGroup();
286 m_impl->checkNeedUpdate();
287 return FaceGroup(m_impl->outerFaceGroup());
288}
289
290/*---------------------------------------------------------------------------*/
291/*---------------------------------------------------------------------------*/
293/*---------------------------------------------------------------------------*/
294/*---------------------------------------------------------------------------*/
295
297activeCellGroup() const
298{
299 if (null())
300 return ItemGroup();
301 m_impl->checkNeedUpdate();
302 return CellGroup(m_impl->activeCellGroup());
303}
304
305/*---------------------------------------------------------------------------*/
306/*---------------------------------------------------------------------------*/
307
309ownActiveCellGroup() const
310{
311 if (null())
312 return ItemGroup();
313 m_impl->checkNeedUpdate();
314 return CellGroup(m_impl->ownActiveCellGroup());
315}
316
317/*---------------------------------------------------------------------------*/
318/*---------------------------------------------------------------------------*/
319
321levelCellGroup(const Integer& level) const
322{
323 if (null())
324 return ItemGroup();
325 m_impl->checkNeedUpdate();
326 return CellGroup(m_impl->levelCellGroup(level));
327}
328
329/*---------------------------------------------------------------------------*/
330/*---------------------------------------------------------------------------*/
331
333ownLevelCellGroup(const Integer& level) const
334{
335 if (null())
336 return ItemGroup();
337 m_impl->checkNeedUpdate();
338 return CellGroup(m_impl->ownLevelCellGroup(level));
339}
340/*---------------------------------------------------------------------------*/
341/*---------------------------------------------------------------------------*/
342
344activeFaceGroup() const
345{
346 if (null())
347 return ItemGroup();
348 m_impl->checkNeedUpdate();
349 return FaceGroup(m_impl->activeFaceGroup());
350}
351
352/*---------------------------------------------------------------------------*/
353/*---------------------------------------------------------------------------*/
354
356ownActiveFaceGroup() const
357{
358 if (null())
359 return ItemGroup();
360 m_impl->checkNeedUpdate();
361 return FaceGroup(m_impl->ownActiveFaceGroup());
362}
363
364/*---------------------------------------------------------------------------*/
365/*---------------------------------------------------------------------------*/
366
367/*---------------------------------------------------------------------------*/
368/*---------------------------------------------------------------------------*/
369
372{
373 if (null())
374 return ItemGroup();
375 m_impl->checkNeedUpdate();
376 return FaceGroup(m_impl->innerActiveFaceGroup());
377}
378
379/*---------------------------------------------------------------------------*/
380/*---------------------------------------------------------------------------*/
381
384{
385 if (null())
386 return ItemGroup();
387 m_impl->checkNeedUpdate();
388 return FaceGroup(m_impl->outerActiveFaceGroup());
389}
390
391/*---------------------------------------------------------------------------*/
392/*---------------------------------------------------------------------------*/
393
394/*---------------------------------------------------------------------------*/
395/*---------------------------------------------------------------------------*/
396
398createSubGroup(const String& suffix, IItemFamily* family, ItemGroupComputeFunctor* functor) const
399{
400 if (null())
401 return ItemGroup();
402 m_impl->checkNeedUpdate();
403 return ItemGroup(m_impl->createSubGroup(suffix, family, functor));
404}
405
406/*---------------------------------------------------------------------------*/
407/*---------------------------------------------------------------------------*/
408
410findSubGroup(const String& suffix) const
411{
412 if (null())
413 return ItemGroup();
414 return ItemGroup(m_impl->findSubGroup(suffix));
415}
416
417/*---------------------------------------------------------------------------*/
418/*---------------------------------------------------------------------------*/
419
421clear()
422{
423 m_impl->clear();
424}
425
426/*---------------------------------------------------------------------------*/
427/*---------------------------------------------------------------------------*/
428
439addItems(Int32ConstArrayView items_local_id, bool check_if_present)
440{
441 if (null())
442 throw ArgumentException(A_FUNCINFO, "Can not addItems() to null group");
443 if (isAllItems())
444 throw ArgumentException(A_FUNCINFO, "Can not addItems() to all-items group");
445 m_impl->_checkNeedUpdateNoPadding();
446 m_impl->addItems(items_local_id, check_if_present);
447}
448
449/*---------------------------------------------------------------------------*/
450/*---------------------------------------------------------------------------*/
451
462removeItems(Int32ConstArrayView items_local_id, bool check_if_present)
463{
464 if (null())
465 throw ArgumentException(A_FUNCINFO, "Can not removeItems() to null group");
466 if (isAllItems())
467 throw ArgumentException(A_FUNCINFO, "Can not removeItems() to all-items group");
468 m_impl->_checkNeedUpdateNoPadding();
469 m_impl->removeItems(items_local_id, check_if_present);
470}
471
472/*---------------------------------------------------------------------------*/
473/*---------------------------------------------------------------------------*/
474
484setItems(Int32ConstArrayView items_local_id)
485{
486 if (null())
487 throw ArgumentException(A_FUNCINFO, "Can not setItems() to null group");
488 m_impl->setItems(items_local_id);
489}
490
491/*---------------------------------------------------------------------------*/
492/*---------------------------------------------------------------------------*/
493
505setItems(Int32ConstArrayView items_local_id, bool do_sort)
506{
507 if (null())
508 throw ArgumentException(A_FUNCINFO, "Can not setItems() to null group");
509 m_impl->setItems(items_local_id, do_sort);
510}
511
512/*---------------------------------------------------------------------------*/
513/*---------------------------------------------------------------------------*/
514
520{
521 m_impl->checkValid();
522}
523
524/*---------------------------------------------------------------------------*/
525/*---------------------------------------------------------------------------*/
526
529{
530 if (null())
531 return;
532 m_impl->checkNeedUpdate();
533 m_impl->applyOperation(operation);
534}
535
536/*---------------------------------------------------------------------------*/
537/*---------------------------------------------------------------------------*/
538
540enumerator() const
541{
542 if (null())
543 return ItemEnumerator();
544 m_impl->_checkNeedUpdateNoPadding();
545 return ItemEnumerator(m_impl->itemInfoListView(), m_impl->itemsLocalId(), m_impl.get());
546}
547
548/*---------------------------------------------------------------------------*/
549/*---------------------------------------------------------------------------*/
550
552_simdEnumerator() const
553{
554 if (null())
555 return ItemEnumerator();
556 m_impl->_checkNeedUpdateWithPadding();
557 return ItemEnumerator(m_impl->itemInfoListView(), m_impl->itemsLocalId(), m_impl.get());
558}
559
560/*---------------------------------------------------------------------------*/
561/*---------------------------------------------------------------------------*/
562
563ItemVectorView ItemGroup::
564_view(bool do_padding) const
565{
566 if (null())
567 return ItemVectorView();
568 m_impl->_checkNeedUpdate(do_padding);
569 Int32 flags = 0;
570 if (m_impl->isContiguousLocalIds())
571 flags |= ItemIndexArrayView::F_Contigous;
572 // TODO: gérer l'offset
573 return ItemVectorView(m_impl->itemFamily(), ItemIndexArrayView(m_impl->itemsLocalId(), 0, flags));
574}
575
576/*---------------------------------------------------------------------------*/
577/*---------------------------------------------------------------------------*/
578
580view() const
581{
582 return _view(true);
583}
584
585/*---------------------------------------------------------------------------*/
586/*---------------------------------------------------------------------------*/
587
589_paddedView() const
590{
591 return _view(true);
592}
593
594/*---------------------------------------------------------------------------*/
595/*---------------------------------------------------------------------------*/
596
598_unpaddedView() const
599{
600 return _view(false);
601}
602
603/*---------------------------------------------------------------------------*/
604/*---------------------------------------------------------------------------*/
605
607isAllItems() const
608{
609 return m_impl->isAllItems();
610}
611
612/*---------------------------------------------------------------------------*/
613/*---------------------------------------------------------------------------*/
614
616synchronizer() const
617{
618 return m_impl->synchronizer();
619}
620
621/*---------------------------------------------------------------------------*/
622/*---------------------------------------------------------------------------*/
623
625isAutoComputed() const
626{
627 return m_impl->hasComputeFunctor();
628}
629
630/*---------------------------------------------------------------------------*/
631/*---------------------------------------------------------------------------*/
632
634hasSynchronizer() const
635{
636 return m_impl->hasSynchronizer();
637}
638
639/*---------------------------------------------------------------------------*/
640/*---------------------------------------------------------------------------*/
641
643_internalApi() const
644{
645 return m_impl->_internalApi();
646}
647
648/*---------------------------------------------------------------------------*/
649/*---------------------------------------------------------------------------*/
650
652checkIsSorted() const
653{
654 m_impl->_checkNeedUpdate(false);
655 return m_impl->checkIsSorted();
656}
657
658/*---------------------------------------------------------------------------*/
659/*---------------------------------------------------------------------------*/
660
662incrementTimestamp() const
663{
664 m_impl->m_p->updateTimestamp();
665}
666
667/*---------------------------------------------------------------------------*/
668/*---------------------------------------------------------------------------*/
669
670extern ARCANE_CORE_EXPORT bool
671_caseOptionConvert(const CaseOptionBase& co, const String& name, ItemGroup& obj)
672{
674 obj = mesh->findGroup(name);
675 return obj.null();
676}
677
678extern ARCANE_CORE_EXPORT bool
679_caseOptionConvert(const CaseOptionBase& co, const String& name, NodeGroup& obj)
680{
681 IMesh* mesh = co.parentOptionList()->meshHandle().mesh();
682 obj = mesh->nodeFamily()->findGroup(name);
683 return obj.null();
684}
685
686extern ARCANE_CORE_EXPORT bool
687_caseOptionConvert(const CaseOptionBase& co, const String& name, EdgeGroup& obj)
688{
689 IMesh* mesh = co.parentOptionList()->meshHandle().mesh();
690 obj = mesh->edgeFamily()->findGroup(name);
691 return obj.null();
692}
693
694extern ARCANE_CORE_EXPORT bool
695_caseOptionConvert(const CaseOptionBase& co, const String& name, FaceGroup& obj)
696{
697 IMesh* mesh = co.parentOptionList()->meshHandle().mesh();
698 obj = mesh->faceFamily()->findGroup(name);
699 return obj.null();
700}
701
702extern ARCANE_CORE_EXPORT bool
703_caseOptionConvert(const CaseOptionBase& co, const String& name, CellGroup& obj)
704{
705 IMesh* mesh = co.parentOptionList()->meshHandle().mesh();
706 obj = mesh->cellFamily()->findGroup(name);
707 return obj.null();
708}
709
710/*---------------------------------------------------------------------------*/
711/*---------------------------------------------------------------------------*/
712
713} // End namespace Arcane
714
715/*---------------------------------------------------------------------------*/
716/*---------------------------------------------------------------------------*/
Base class for a data set option.
ICaseOptionList * parentOptionList() const
Parent OptionList.
virtual MeshHandle meshHandle() const =0
Handle of the associated mesh.
Interface of an entity family.
Definition IItemFamily.h:83
virtual ItemGroup findGroup(const String &name) const =0
Searches for a group.
Interface of an operator on entities sorted by type.
virtual IItemFamily * nodeFamily()=0
Returns the node family.
Interface of a variable synchronization service.
Enumerator over a list of entities.
Functor for calculating elements of a group.
Internal API of ItemGroupImpl in Arcane.
Brief: Implementation of a mesh entity group.
Mesh entity group.
Definition ItemGroup.h:51
ItemEnumerator enumerator() const
Enumerator over the group entities.
Definition ItemGroup.cc:540
bool checkIsSorted() const
Checks and returns whether the group is sorted by increasing uniqueId().
Definition ItemGroup.cc:652
void clear()
Clears the entities of the group.
Definition ItemGroup.cc:421
ItemGroup findSubGroup(const String &suffix) const
Access to a subgroup.
Definition ItemGroup.cc:410
ItemGroup createSubGroup(const String &suffix, IItemFamily *family, ItemGroupComputeFunctor *functor) const
Creates a computed subgroup.
Definition ItemGroup.cc:398
IVariableSynchronizer * synchronizer() const
Group synchronizer.
Definition ItemGroup.cc:616
NodeGroup nodeGroup() const
Group of nodes of the elements of this group.
Definition ItemGroup.cc:222
bool isAutoComputed() const
True if it is an automatically computed group.
Definition ItemGroup.cc:625
FaceGroup faceGroup() const
Group of faces of the elements of this group.
Definition ItemGroup.cc:246
void incrementTimestamp() const
Increments the last modification time of the group.
Definition ItemGroup.cc:662
bool isOwn() const
Returns whether the group contains only elements belonging to the subdomain.
Definition ItemGroup.cc:149
void removeItems(Int32ConstArrayView items_local_id, bool check_if_present=true)
Removes entities.
Definition ItemGroup.cc:462
FaceGroup activeFaceGroup() const
Group of active faces.
Definition ItemGroup.cc:344
FaceGroup innerActiveFaceGroup() const
Group of internal faces of the elements of this group.
Definition ItemGroup.cc:371
ItemVectorView view() const
View of the group entities.
Definition ItemGroup.cc:580
void setItems(Int32ConstArrayView items_local_id)
Sets the entities of the group.
Definition ItemGroup.cc:484
FaceGroup ownActiveFaceGroup() const
Group of active faces belonging to the domain of the elements of this group.
Definition ItemGroup.cc:356
CellGroup cellGroup() const
Group of cells of the elements of this group.
Definition ItemGroup.cc:258
void applyOperation(IItemOperationByBasicType *operation) const
Applies the operation operation to the entities of the group.
Definition ItemGroup.cc:528
AutoRefT< ItemGroupImpl > m_impl
Internal representation of the group.
Definition ItemGroup.h:360
CellGroup levelCellGroup(const Integer &level) const
Group of level l cells of the elements of this group.
Definition ItemGroup.cc:321
void addItems(Int32ConstArrayView items_local_id, bool check_if_present=true)
Adds entities.
Definition ItemGroup.cc:439
FaceGroup innerFaceGroup() const
Group of internal faces of the elements of this group.
Definition ItemGroup.cc:270
ItemGroupImplInternal * _internalApi() const
Internal Arcane API.
Definition ItemGroup.cc:643
ItemEnumerator _simdEnumerator() const
Enumerator over the group entities for vectorization.
Definition ItemGroup.cc:552
ItemVectorView _paddedView() const
View of the group entities with padding for vectorization.
Definition ItemGroup.cc:589
bool hasSynchronizer() const
Indicates if the group has an active synchronizer.
Definition ItemGroup.cc:634
bool isAllItems() const
Indicates if the group is that of all entities.
Definition ItemGroup.cc:607
ItemVectorView _unpaddedView() const
View of the group entities without padding for vectorization.
Definition ItemGroup.cc:598
EdgeGroup edgeGroup() const
Group of edges of the elements of this group.
Definition ItemGroup.cc:234
CellGroup ownActiveCellGroup() const
Group of own active cells of the elements of this group.
Definition ItemGroup.cc:309
void checkValid()
Internal check of group validity.
Definition ItemGroup.cc:519
bool null() const
true means the group is the null group
Definition ItemGroup.h:75
void setOwn(bool v)
Sets whether the group property is local or not.
Definition ItemGroup.cc:161
CellGroup ownLevelCellGroup(const Integer &level) const
Group of own level l cells of the elements of this group.
Definition ItemGroup.cc:333
ItemGroup()
Constructs a null group.
Definition ItemGroup.cc:140
FaceGroup outerActiveFaceGroup() const
Group of active external faces of the elements of this group.
Definition ItemGroup.cc:383
ItemGroup own() const
Group equivalent to this one but containing only the local elements of the subdomain.
Definition ItemGroup.cc:182
CellGroup activeCellGroup() const
AMR.
Definition ItemGroup.cc:297
FaceGroup outerFaceGroup() const
Group of external faces of the elements of this group.
Definition ItemGroup.cc:282
View over an index array (localIds()) of entities.
View on a vector of entities.
IMesh * mesh() const
Associated mesh.
ItemGroupT< Cell > CellGroup
Group of cells.
Definition ItemTypes.h:184
ItemGroupT< Face > FaceGroup
Group of faces.
Definition ItemTypes.h:179
ItemGroupT< Edge > EdgeGroup
Group of edges.
Definition ItemTypes.h:174
ItemGroupT< Node > NodeGroup
Group of nodes.
Definition ItemTypes.h:168
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
std::int32_t Int32
Signed integer type of 32 bits.