Arcane  v4.1.0.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-2025 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/* 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/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33ItemInternalMap::
34ItemInternalMap()
35{
36}
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
43{
44 if (arcaneIsCheck()) {
45 // Vérifie qu'on n'a pas deux fois la même clé.
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 pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Vue modifiable d'un tableau d'un type T.
Vue constante d'un tableau de type T.
ItemUniqueId uniqueId() const
Numéro unique de l'entité
Int32 localId() const
Numéro local (au sous-domaine) 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:225
Vecteur 1D de données avec sémantique par valeur (style STL).
void notifyUniqueIdsChanged()
Notifie que les numéros uniques des entités ont changés.
void eachItem(const Lambda &lambda)
Fonction template pour itérer sur les entités de l'instance.
void _changeLocalIds(ArrayView< ItemInternal * > items_internal, ConstArrayView< Int32 > old_to_new_local_ids)
Change la valeurs des localId()
bool arcaneIsCheck()
Vrai si on est en mode vérification.
Definition Misc.cc:68
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.