Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemConnectivitySelector.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/*---------------------------------------------------------------------------*/
8/* ItemConnectivitySelector.h (C) 2000-2021 */
9/* */
10/* Selection between historical and on-demand connectivities. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MESH_ITEMCONNECTIVITYSELECTOR_H
13#define ARCANE_MESH_ITEMCONNECTIVITYSELECTOR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18#include "arcane/utils/ArrayView.h"
19#include "arcane/utils/TraceAccessor.h"
20#include "arcane/utils/FatalErrorException.h"
21
22#include "arcane/mesh/MeshGlobal.h"
23
24#include "arcane/core/ItemInternal.h"
25
26#include "arcane/mesh/ConnectivityNewWithDependenciesTypes.h"
27
28#include "arcane/core/IItemFamilyNetwork.h"
29
30#include <type_traits>
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35namespace Arcane
36{
37class IItemFamily;
39} // namespace Arcane
40
41namespace Arcane::mesh
42{
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
47class ItemFamily;
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
54class ARCANE_MESH_EXPORT ItemConnectivitySelector
55: public TraceAccessor
56{
57 public:
58
59 ItemConnectivitySelector(ItemFamily* source_family, IItemFamily* target_family,
60 const String& connectivity_name, Integer connectivity_index);
61 virtual ~ItemConnectivitySelector()
62 {
63 }
64
65 public:
66
67 virtual void build();
68 ARCCORE_DEPRECATED_2021("This method always return 'nullptr'")
69 virtual IIncrementalItemConnectivity* legacyConnectivity() const { return nullptr; }
70 virtual IIncrementalItemConnectivity* customConnectivity() const = 0;
71 ARCCORE_DEPRECATED_2021("This method doesn't do anything")
72 virtual void updateItemConnectivityList(Int32ConstArrayView) const {}
73 virtual void checkValidConnectivityList() const = 0;
74 virtual void compactConnectivities() = 0;
75
76 public:
77
78 void setPreAllocatedSize(Integer size);
79 Integer preAllocatedSize() const { return m_pre_allocated_size; }
80 Int32 itemConnectivityIndex() const { return m_item_connectivity_index; }
81
82 protected:
83
84 virtual void _createCustomConnectivity(const String& name) = 0;
85 virtual void _buildCustomConnectivity() = 0;
86
87 protected:
88
89 ItemFamily* m_source_family;
90 IItemFamily* m_target_family;
91 String m_connectivity_name;
92 Integer m_pre_allocated_size;
93 // Index in ItemInternalConnectivityList. (-1) if none.
94 Int32 m_item_connectivity_index;
95 ItemInternalConnectivityList* m_item_connectivity_list;
96 bool m_is_built;
97};
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
104template <typename ConnectivityIndexType, typename CustomType>
105class ARCANE_MESH_EXPORT ItemConnectivitySelectorT
106: public ItemConnectivitySelector
107{
108 public:
109
110 ItemConnectivitySelectorT(ItemFamily* source_family, IItemFamily* target_family,
111 const String& connectivity_name)
112 : ItemConnectivitySelector(source_family, target_family, connectivity_name, ConnectivityIndexType::connectivityIndex())
113 , m_custom_connectivity(nullptr)
114 {
115 }
116 ~ItemConnectivitySelectorT()
117 {
118 // NOTE: connectivities are deleted by the families.
119 }
120
121 public:
122
123 IIncrementalItemConnectivity* customConnectivity() const override
124 {
125 return trueCustomConnectivity();
126 }
127
128 void checkValidConnectivityList() const override
129 {
130 if (m_item_connectivity_index < 0)
131 return;
132 auto x = m_item_connectivity_list;
133 ItemConnectivityContainerView ref_con_view = m_custom_connectivity->connectivityContainerView();
134 x->containerView(m_item_connectivity_index).checkSame(ref_con_view);
135 }
136
137 void compactConnectivities() override
138 {
139 if (m_custom_connectivity)
140 m_custom_connectivity->compactConnectivityList();
141 }
142
143 public:
144
145 void addConnectedItem(ItemLocalId item_lid, ItemLocalId sub_item_lid)
146 {
147 if (m_custom_connectivity)
148 m_custom_connectivity->addConnectedItem(item_lid, sub_item_lid);
149 }
150
151 void removeConnectedItem(ItemLocalId item_lid, ItemLocalId sub_item_lid)
152 {
153 if (m_custom_connectivity)
154 m_custom_connectivity->removeConnectedItem(item_lid, sub_item_lid);
155 }
156
157 void removeConnectedItems(ItemLocalId item_lid)
158 {
159 if (m_custom_connectivity)
160 m_custom_connectivity->removeConnectedItems(item_lid);
161 }
162
163 void replaceItems(ItemLocalId item_lid, Int32ConstArrayView sub_item_lids)
164 {
165 if (m_custom_connectivity)
166 m_custom_connectivity->replaceConnectedItems(item_lid, sub_item_lids);
167 }
168
169 void replaceItem(ItemLocalId item_lid, Integer index, ItemLocalId sub_item_lid)
170 {
171 if (m_custom_connectivity)
172 m_custom_connectivity->replaceConnectedItem(item_lid, index, sub_item_lid);
173 }
174
175 bool hasConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) const
176 {
177 if (m_custom_connectivity)
178 return m_custom_connectivity->hasConnectedItem(source_item, target_local_id);
179
180 return false;
181 }
182
183 CustomType* trueCustomConnectivity() const { return m_custom_connectivity; }
184
185 protected:
186
187 void _createCustomConnectivity(const String& name) override
188 {
189 m_custom_connectivity = new CustomType(m_source_family, m_target_family, name);
190 }
191
192 // used only with family dependencies. The concrete type of families are needed only for FaceToCellConnectivity
193 // where the IncrementalItemConnectivity has been overloaded (to handle back/front cell connectivity)
194 template <class SourceFamily, class TargetFamily>
195 void _createCustomConnectivity(const String& name)
196 {
197 m_custom_connectivity = new typename CustomConnectivity<SourceFamily, TargetFamily>::type(m_source_family, m_target_family, name);
198 }
199
200 void _buildCustomConnectivity() override
201 {
202 // Instruct the IncrementalItemConnectivity that it must update
203 // the ItemInternal accessors.
204 if (m_custom_connectivity)
205 m_custom_connectivity->setItemConnectivityList(m_item_connectivity_list,
206 m_item_connectivity_index);
207 }
208
209 public:
210
211 // Build called when using family dependencies
212 template <class SourceFamily, class TargetFamily>
213 void build()
214 {
215 if (m_is_built)
216 return;
217
218 _createCustomConnectivity<SourceFamily, TargetFamily>(m_connectivity_name);
219 info() << "Family: " << m_source_family->fullName()
220 << " create new connectivity: " << m_connectivity_name;
221
222 _buildCustomConnectivity();
223 m_is_built = true;
224 }
225
226 private:
227
228 CustomType* m_custom_connectivity;
229};
230
231/*---------------------------------------------------------------------------*/
232/*---------------------------------------------------------------------------*/
233
234} // End namespace Arcane::mesh
235
236/*---------------------------------------------------------------------------*/
237/*---------------------------------------------------------------------------*/
238
239#endif
Interface for managing an incremental connectivity.
Interface of an entity family.
Definition IItemFamily.h:83
Views of containers holding connectivity. This class allows the containers used to be opaque outside ...
void checkSame(ItemConnectivityContainerView rhs) const
Checks that the two instances this and rhs have the same values.
Connectivity information, for an entity family, allowing transition between old and new connectivity ...
Index of an Item in a variable.
Definition ItemLocalId.h:42
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessage info() const
Flow for an information message.
-- 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.