Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemGroupBuilder.h
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#ifndef ITEMGROUPBUILDER_H
8#define ITEMGROUPBUILDER_H
9/*---------------------------------------------------------------------------*/
10/*---------------------------------------------------------------------------*/
11
12#include <set>
13#include <cstring>
14#include <cctype>
15
16#include "arcane/utils/String.h"
17#include "arcane/utils/StringBuilder.h"
18
19#include "arcane/core/ArcaneVersion.h"
20#include "arcane/core/ItemGroup.h"
21#include "arcane/core/IMesh.h"
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/ItemGroupRangeIterator.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28using namespace Arcane;
29
30#define STRINGIFY(x) #x
31#define TOSTRING(x) STRINGIFY(x)
32
33//! Macro for object name construction
34/*! Generally used to name groups for ItemGroupBuilder */
35#define IMPLICIT_NAME ItemGroupBuilder_cleanString(__FILE__ "__" TOSTRING(__LINE__), false)
36#define IMPLICIT_UNIQ_NAME ItemGroupBuilder_cleanString(__FILE__ "__" TOSTRING(__LINE__), true)
37
38/*
39 * \internal
40 * \brief Assisted group building tool
41 *
42 * The uniqueness of the group elements is guaranteed by construction. It
43 * is possible to use the IMPLICIT_NAME macro to name the group.
44 */
45template <typename T>
47{
48 private:
49
50 IMesh* m_mesh;
51 std::set<Integer> m_ids;
52 String m_group_name;
53
54 public:
55
56 //! Constructor
57 ItemGroupBuilder(IMesh* mesh, const String& groupName)
58 : m_mesh(mesh)
59 , m_group_name(groupName)
60 {}
61
62 //! Destructor
63 virtual ~ItemGroupBuilder() {}
64
65 public:
66
67 //! Add a set of items provided by an enumerator
68 void add(ItemEnumeratorT<T> enumerator)
69 {
70 while (enumerator.hasNext()) {
71 m_ids.insert(enumerator.localId());
72 ++enumerator;
73 }
74 }
75
76 //! Add a set of items provided by an enumerator
78 {
79 while (enumerator.hasNext()) {
80 m_ids.insert(enumerator.itemLocalId());
81 ++enumerator;
82 }
83 }
84
85 //! Add a unique item
86 void add(const T& item)
87 {
88 m_ids.insert(item.localId());
89 }
90
91 //! Constructor for the new group
93 {
94 Int32UniqueArray localIds(m_ids.size());
95
96 std::set<Integer>::const_iterator is = m_ids.begin();
97 Integer i = 0;
98
99 while (is != m_ids.end()) {
100 localIds[i] = *is;
101 ++is;
102 ++i;
103 }
104
105 // ItemGroup newGroup(new ItemGroupImpl(m_mesh->itemFamily(ItemTraitsT<T>::kind()),
106 // m_group_name));
107 ItemGroup newGroup = m_mesh->itemFamily(ItemTraitsT<T>::kind())->findGroup(m_group_name, true);
108 // m_item_family->createGroup(own_name,ItemGroup(this));
109
110 newGroup.clear();
111 newGroup.setItems(localIds);
112 // newGroup.setLocalToSubDomain(true); // Forces the new group to be local: do not transfer in case of rebalancing
113
114 return newGroup;
115 }
116
117 //! Group name
119 {
120 return m_group_name;
121 }
122};
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127#endif
virtual ItemGroup findGroup(const String &name) const =0
Searches for a group.
Int32 localId() const
localId() of the current entity.
constexpr bool hasNext()
True if the end of the enumerator has not been reached (index()<count()).
Enumerator over a typed list of entities of type ItemType.
Iteration range over a group of mesh entities.
Reference to a group of a given kind.
Definition ItemGroup.h:420
Mesh entity group.
Definition ItemGroup.h:51
void clear()
Clears the entities of the group.
Definition ItemGroup.cc:421
IItemFamily * itemFamily() const
Entity family to which this group belongs (0 for the null group).
Definition ItemGroup.h:128
void setItems(Int32ConstArrayView items_local_id)
Sets the entities of the group.
Definition ItemGroup.cc:484
static eItemKind kind()
Entity kind.
Definition ItemTypes.h:629
String getName() const
Group name.
void add(ItemEnumeratorT< T > enumerator)
Add a set of items provided by an enumerator.
virtual ~ItemGroupBuilder()
Destructor.
ItemGroupT< T > buildGroup()
Constructor for the new group.
void add(const T &item)
Add a unique item.
void add(ItemGroupRangeIteratorT< T > enumerator)
Add a set of items provided by an enumerator.
ItemGroupBuilder(IMesh *mesh, const String &groupName)
Constructor.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
Definition UtilsTypes.h:341