Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ItemInternalMap.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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-2024 */
9/* */
10/* Tableau associatif de 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#define ENUMERATE_ITEM_INTERNAL_MAP_DATA2(iter, item_list) \
31 for (auto __i__##iter : item_list.buckets()) \
32 for (auto* iter = __i__##iter; iter; iter = iter->next())
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37ItemInternalMap::
38ItemInternalMap()
39: m_impl(5000, false)
40{
41}
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
46void ItemInternalMap::
47notifyUniqueIdsChanged()
48{
49 if (arcaneIsCheck()) {
50 // Vérifie qu'on n'a pas deux fois la même clé.
51 std::unordered_set<Int64> uids;
52 this->eachItem([&](Item item) {
53 Int64 uid = item.uniqueId().asInt64();
54 if (uids.find(uid) != uids.end())
55 ARCANE_FATAL("Duplicated uniqueId '{0}'", uid);
56 uids.insert(uid);
57 });
58 }
59
60 if constexpr (UseNewImpl) {
61 Int64 nb_item = m_new_impl.size();
63 Int64 index = 0;
64 for (auto& x : m_new_impl) {
65 items[index] = x.second;
66 ++index;
67 }
68 m_new_impl.clear();
69 for (index = 0; index < nb_item; ++index) {
70 ItemInternal* item = items[index];
71 m_new_impl.insert(std::make_pair(item->uniqueId(), item));
72 }
73 }
74 else {
75 ENUMERATE_ITEM_INTERNAL_MAP_DATA2 (nbid, m_impl) {
76 nbid->setKey(nbid->value()->uniqueId().asInt64());
77 }
78
79 m_impl.rehash();
80 }
81
82 checkValid();
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88void ItemInternalMap::
91{
92 checkValid();
93
94 if constexpr (UseNewImpl) {
95 for (auto& iter : m_new_impl) {
96 ItemInternal* old_ii = iter.second;
97 Int32 current_local_id = old_ii->localId();
99 iter.second = new_ii;
100 }
101 }
102 else {
103 ENUMERATE_ITEM_INTERNAL_MAP_DATA2 (nbid, m_impl) {
104 ItemInternal* old_ii = nbid->value();
105 Int32 current_local_id = old_ii->localId();
107 nbid->setValue(new_ii);
108 }
109 }
110}
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
115void ItemInternalMap::
116checkValid() const
117{
118 if (!arcaneIsCheck())
119 return;
120
121 if constexpr (UseNewImpl) {
122 for (auto& x : m_new_impl) {
123 if (x.first != x.second->uniqueId())
124 ARCANE_FATAL("Incoherent uid key={0} item_internal={1}", x.first, x.second->uniqueId());
125 }
126 }
127 else {
128 ENUMERATE_ITEM_INTERNAL_MAP_DATA2(nbid, m_impl)
129 {
130 if (nbid->key() != nbid->value()->uniqueId())
131 ARCANE_FATAL("Incoherent uid key={0} item_internal={1}", nbid->key(), nbid->value()->uniqueId());
132 }
133 }
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
139void ItemInternalMap::
140_throwNotFound(Int64 key) const
141{
142 ARCANE_FATAL("ERROR: can not find key={0}", key);
143}
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
148void ItemInternalMap::
149_throwNotSupported(const char* func_name) const
150{
151 ARCANE_THROW(NotSupportedException, func_name);
152}
153
154void ItemInternalMap::
155_checkValid(Int64 uid, ItemInternal* v) const
156{
157 if (v->uniqueId() != uid)
158 ARCANE_FATAL("Bad found uniqueId found={0} expected={1}", v->uniqueId(), uid);
159}
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
164} // End namespace Arcane::mesh
165
166/*---------------------------------------------------------------------------*/
167/*---------------------------------------------------------------------------*/
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
ItemUniqueId uniqueId() const
Numéro unique de l'entité
Structure interne d'une entité de maillage.
Classe de base d'un élément de maillage.
Definition Item.h:83
ItemUniqueId uniqueId() const
Identifiant unique sur tous les domaines.
Definition Item.h:216
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
bool arcaneIsCheck()
Vrai si on est en mode vérification.
Definition Misc.cc:151