Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemInternalMap.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/* ItemInternalMap.cc (C) 2000-2025 */
9/* */
10/* Associative map of ItemInternal. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/mesh/ItemInternalMap.h"
15
16#include "arcane/utils/Iterator.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/NotSupportedException.h"
19
20#include "arcane/core/Item.h"
21
22#include <unordered_set>
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane::mesh
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33ItemInternalMap::
34ItemInternalMap()
35{
36}
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
43{
44 if (arcaneIsCheck()) {
45 // Checks that there are no two instances of the same key.
46 std::unordered_set<Int64> uids;
47 this->eachItem([&](Item item) {
48 Int64 uid = item.uniqueId().asInt64();
49 if (uids.find(uid) != uids.end())
50 ARCANE_FATAL("Duplicated uniqueId '{0}'", uid);
51 uids.insert(uid);
52 });
53 }
54
55 Int64 nb_item = m_new_impl.size();
56 UniqueArray<ItemInternal*> items(nb_item);
57 Int64 index = 0;
58 for (auto& x : m_new_impl) {
59 items[index] = x.second;
60 ++index;
61 }
62 m_new_impl.clear();
63 for (index = 0; index < nb_item; ++index) {
64 ItemInternal* item = items[index];
65 m_new_impl.insert(std::make_pair(item->uniqueId(), item));
66 }
67
68 checkValid();
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
76 ConstArrayView<Int32> old_to_new_local_ids)
77{
78 checkValid();
79
80 for (auto& iter : m_new_impl) {
81 ItemInternal* old_ii = iter.second;
82 Int32 current_local_id = old_ii->localId();
83 ItemInternal* new_ii = items_internal[old_to_new_local_ids[current_local_id]];
84 iter.second = new_ii;
85 }
86}
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91void ItemInternalMap::
92checkValid() const
93{
94 if (!arcaneIsCheck())
95 return;
96
97 for (auto& x : m_new_impl) {
98 if (x.first != x.second->uniqueId())
99 ARCANE_FATAL("Incoherent uid key={0} item_internal={1}", x.first, x.second->uniqueId());
100 }
101}
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106void ItemInternalMap::
107_throwNotFound(Int64 key) const
108{
109 ARCANE_FATAL("ERROR: can not find key={0}", key);
110}
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
115void ItemInternalMap::
116_throwNotSupported(const char* func_name) const
117{
118 ARCANE_THROW(NotSupportedException, func_name);
119}
120
121/*---------------------------------------------------------------------------*/
122/*---------------------------------------------------------------------------*/
123
124void ItemInternalMap::
125_checkValid(Int64 uid, ItemInternal* v) const
126{
127 if (v->uniqueId() != uid)
128 ARCANE_FATAL("Bad found uniqueId found={0} expected={1}", v->uniqueId(), uid);
129}
130
131/*---------------------------------------------------------------------------*/
132/*---------------------------------------------------------------------------*/
133
134} // End namespace Arcane::mesh
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Modifiable view of an array of type T.
Constant view of an array of type T.
ItemUniqueId uniqueId() const
Unique number of the entity.
Int32 localId() const
Local number (in the subdomain) of the entity.
Internal structure of a mesh entity.
Base class for a mesh element.
Definition Item.h:84
ItemUniqueId uniqueId() const
Unique identifier across all domains.
Definition Item.h:239
1D data vector with value semantics (STL style).
void notifyUniqueIdsChanged()
Notifies that the unique IDs of the entities have changed.
void eachItem(const Lambda &lambda)
Template function to iterate over the instance's entities.
void _changeLocalIds(ArrayView< ItemInternal * > items_internal, ConstArrayView< Int32 > old_to_new_local_ids)
Changes the values of localId().
bool arcaneIsCheck()
True if running in check mode.
Definition Misc.cc:66
std::int64_t Int64
Signed integer type of 64 bits.
std::int32_t Int32
Signed integer type of 32 bits.