Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemInternal.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/* ItemInternal.cc (C) 2000-2025 */
9/* */
10/* Internal part of an entity. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/ItemInternal.h"
15
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/Iostream.h"
19#include "arcane/utils/TraceInfo.h"
20#include "arcane/utils/CheckedConvert.h"
21
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/IItemFamilyTopologyModifier.h"
24#include "arcane/core/ItemPrinter.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35ItemInternalConnectivityList ItemInternalConnectivityList::nullInstance;
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40void impl::MutableItemBase::
41_checkUniqueId(Int64 new_uid) const
42{
43 if (new_uid < 0) {
44 ARCANE_FATAL("Bad unique id - new_uid={0} local_id={1} current={2}",
45 new_uid, m_local_id, uniqueId().asInt64());
46 }
47}
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
54{
55#ifdef ARCANE_CHECK
56 _checkUniqueId(m_shared_info->m_unique_ids[m_local_id]);
57#endif
58 m_shared_info->m_unique_ids[m_local_id] = NULL_ITEM_UNIQUE_ID;
59}
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64Int32 ItemUniqueId::
65asInt32() const
66{
67 if (m_unique_id > 2147483647)
68 ARCANE_FATAL("Unique id is too big to be converted to a Int32");
69 return (Int32)(m_unique_id);
70}
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75ItemTypeId ItemTypeId::
77{
78 Int16 x = CheckedConvert::toInt16(v);
79 return ItemTypeId{ x };
80}
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85Int32 impl::ItemBase::
86_nbLinearNode() const
87{
88 ItemTypeInfo* iti = typeInfo();
89 Int16 linear_type_id = iti->linearTypeId();
90 ItemTypeInfo* linear_iti = m_shared_info->typeInfoFromId(linear_type_id);
91 Int32 nb_linear_node = linear_iti->nbLocalNode();
92 return std::min(nbNode(), nb_linear_node);
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101std::ostream&
102operator<<(std::ostream& o, const ItemUniqueId& id)
103{
104 o << id.asInt64();
105 return o;
106}
107
108//! AMR
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
113topHParent() const
114{
115 const ItemInternal* top_it = this;
116 while (top_it->nbHParent())
117 top_it = top_it->_internalHParent(0);
118 ARCANE_ASSERT((!top_it->null()), ("topHParent Problem!"));
119 ARCANE_ASSERT((top_it->level() == 0), ("topHParent Problem"));
120 return top_it;
121}
122
123/*---------------------------------------------------------------------------*/
124/*---------------------------------------------------------------------------*/
125
126impl::ItemBase impl::ItemBase::
127topHParentBase() const
128{
129 ItemBase top_it = *this;
130 while (top_it.nbHParent())
131 top_it = top_it.hParentBase(0);
132 ARCANE_ASSERT((!top_it.null()), ("topHParent Problem!"));
133 ARCANE_ASSERT((top_it.level() == 0), ("topHParent Problem"));
134 return top_it;
135}
136
137/*---------------------------------------------------------------------------*/
138/*---------------------------------------------------------------------------*/
139
140ItemInternal* ItemInternal::
142{
143 ItemInternal* top_it = this;
144 while (top_it->nbHParent())
145 top_it = top_it->_internalHParent(0);
146 ARCANE_ASSERT((!top_it->null()), ("topHParent Problem!"));
147 ARCANE_ASSERT((top_it->level() == 0), ("topHParent Problem"));
148 return top_it;
149}
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
155whichChildAmI(Int32 local_id) const
156{
157 ARCANE_ASSERT((this->hasHChildren()), ("item has non-child!"));
158 for (Integer c = 0; c < this->nbHChildren(); c++)
159 if (this->hChildId(c) == local_id)
160 return c;
161 return -1;
162}
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
168whichChildAmI(const ItemInternal* iitem) const
169{
170 ARCANE_ASSERT((this->hasHChildren()), ("item has non-child!"));
171 for (Integer c = 0; c < this->nbHChildren(); c++)
172 if (this->_internalHChild(c) == iitem)
173 return c;
174 return -1;
175}
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180ItemInternalVectorView impl::ItemBase::
181_internalActiveCells2(Int32Array& local_ids) const
182{
183 const Integer nbcell = this->nbCell();
184 for (Integer icell = 0; icell < nbcell; ++icell) {
185 ItemBase cell = this->cellBase(icell);
186 if (cell.isActive()) {
187 const Int32 local_id = cell.localId();
188 local_ids.add(local_id);
189 }
190 }
191 return ItemInternalVectorView(m_shared_info->m_items->m_cell_shared_info, local_ids, 0);
192}
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
197void impl::MutableItemBase::
198_setFaceInfos(Int32 mod_flags)
199{
200 Int32 face_flags = flags();
201 face_flags &= ~II_InterfaceFlags;
202 face_flags |= mod_flags;
203 setFlags(face_flags);
204}
205
206/*---------------------------------------------------------------------------*/
207/*---------------------------------------------------------------------------*/
208
209/*!
210 * \brief For a face, positions both the back cell and the front cell.
211 *
212 * \a back_cell_lid and/or \a front_cell_lid may be NULL_ITEM_LOCAL_ID
213 * which means that the entity does not have a back cell or a front cell. If both
214 * values are null, then the face is considered to have no connected cells.
215 *
216 * \note This method is used only by FaceFamily.
217 */
218void impl::MutableItemBase::
219_setFaceBackAndFrontCells(Int32 back_cell_lid, Int32 front_cell_lid)
220{
221 if (front_cell_lid == NULL_ITEM_LOCAL_ID) {
222 // Only the back_cell remains or no cell.
223 Int32 mod_flags = (back_cell_lid != NULL_ITEM_LOCAL_ID) ? (II_Boundary | II_HasBackCell | II_BackCellIsFirst) : 0;
224 _setFaceInfos(mod_flags);
225 }
226 else if (back_cell_lid == NULL_ITEM_LOCAL_ID) {
227 // Only the front cell remains
229 }
230 else {
231 // There are two connected cells.
233 }
234}
235
236/*---------------------------------------------------------------------------*/
237/*---------------------------------------------------------------------------*/
238
239void ItemInternal::
240setDataIndex(Integer)
241{
242 ARCANE_FATAL("This method is no longer valid");
243}
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
247
248/*---------------------------------------------------------------------------*/
249/*---------------------------------------------------------------------------*/
250
251bool ItemInternalVectorView::
252_isValid()
253{
254 if (!m_shared_info)
255 ARCANE_FATAL("Null ItemSharedInfo");
256 if (!m_local_ids.empty()) {
257 auto* items_data = _items().data();
258 if (!items_data)
259 ARCANE_FATAL("Null ItemsInternal list");
260 }
261 return true;
262}
263
264/*---------------------------------------------------------------------------*/
265/*---------------------------------------------------------------------------*/
266
267} // End namespace Arcane
268
269/*---------------------------------------------------------------------------*/
270/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Base class for mesh entities.
ItemUniqueId uniqueId() const
Unique number of the entity.
Integer nbCell() const
Number of cells connected to the entity (for nodes, edges, and faces).
bool isActive() const
Int32 level() const
Int32 flags() const
Flags of the entity.
ItemTypeInfo * typeInfo() const
Type of the entity.
Int32 nbHParent() const
Number of parents for AMR.
bool hasHChildren() const
Int32 whichChildAmI(Int32 local_id) const
Int32 nbHChildren() const
Number of children for AMR.
Integer nbNode() const
Number of nodes of the entity.
bool null() const
True if the entity is the null entity.
Int32 localId() const
Local number (in the subdomain) of the entity.
@ II_FrontCellIsFirst
The first cell of the entity is the front cell.
Definition ItemFlags.h:54
@ II_HasBackCell
The entity has a back cell.
Definition ItemFlags.h:53
@ II_Boundary
The entity is on the boundary.
Definition ItemFlags.h:51
@ II_HasFrontCell
The entity has a front cell.
Definition ItemFlags.h:52
@ II_BackCellIsFirst
The first cell of the entity is the back cell.
Definition ItemFlags.h:55
Int32 whichChildAmI(const ItemInternal *iitem) const
const ItemInternal * topHParent() const
AMR.
static ItemTypeId fromInteger(Int64 v)
Creates an instance from an integer.
Info on a mesh entity type.
Integer nbLocalNode() const
Number of nodes of the entity.
Int16 linearTypeId() const
Type of the corresponding linear element.
void setFlags(Int32 f)
Sets the entity flags.
void unsetUniqueId()
Nullifies the uniqueId to the value NULL_ITEM_UNIQUE_ID.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
std::int16_t Int16
Signed integer type of 16 bits.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
Definition UtilsTypes.h:127
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Output operator for a stream.
std::int32_t Int32
Signed integer type of 32 bits.