Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ItemData.h
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/* ItemData.h (C) 2000-2018 */
9/* */
10/* Class gathering item data : ids and connectivities */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ITEMDATA_H_
13#define ARCANE_ITEMDATA_H_
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include <stdexcept>
18#include <map>
19
21#include "arcane/mesh/MeshGlobal.h"
22#include "arcane/ArcaneTypes.h"
23#include "arcane/utils/Array.h"
24#include "arcane/utils/FatalErrorException.h"
25
26#include "arcane/IItemFamily.h"
27#include "arcane/IItemFamilyModifier.h"
28#include "arcane/ISerializer.h"
29#include "arcane/IMesh.h"
30#include "arcane/ISubDomain.h"
31#include "arcane/IParallelMng.h"
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36ARCANE_BEGIN_NAMESPACE
37ARCANE_MESH_BEGIN_NAMESPACE
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42class ARCANE_MESH_EXPORT ItemData
43{
44public:
45
64 ItemData() : m_nb_items(0), m_item_family(nullptr), m_item_family_modifier(nullptr), m_subdomain_id(-1){}
65
67 ItemData(const ItemData& rhs) = default;
68
75 : m_nb_items(nb_items)
76 , m_item_infos(info_size)
77 , m_item_lids(item_lids)
78 , m_item_family(item_family)
79 , m_item_family_modifier(item_family_modifier)
80 , m_subdomain_id(subdomain_id){}
81
85 ItemData(Integer nb_items, Integer info_size, IItemFamily* item_family,
87 : m_nb_items(nb_items)
88 , m_item_infos(info_size)
89 , _internal_item_lids(nb_items)
90 , m_item_lids(_internal_item_lids)
91 , m_item_family(item_family)
92 , m_item_family_modifier(item_family_modifier)
93 , m_subdomain_id(subdomain_id){}
94
96 virtual ~ItemData() {}
97
98public:
99
100 Integer nbItems() const {return m_nb_items;}
101 Int64Array& itemInfos() {return m_item_infos;} // Need to return Array& since size is not always known at construction
102 Int64ConstArrayView itemInfos() const {return m_item_infos;}
103 Int32ArrayView itemLids() {return m_item_lids;}
104 Int32ArrayView itemOwners() { if (m_item_owners.empty()) _ownerDefaultInit(); return m_item_owners;}
105 IItemFamily* itemFamily() {return m_item_family;}
106 IItemFamily const* itemFamily() const {return m_item_family;}
107 IItemFamilyModifier* itemFamilyModifier() {return m_item_family_modifier;}
108 Integer subDomainId() const {return m_subdomain_id;}
109
110 void serialize(ISerializer* buffer); // Fill the buffer from the data
111 void deserialize(ISerializer* buffer, IMesh* mesh); // Fill the buffer from the data : using an internal lids array
112 void deserialize(ISerializer* buffer, IMesh* mesh, Int32Array& item_lids); // Fill the data from the buffer using external lids array. item_lids must live as long as ItemData does...
113
114
115private:
116
117 void _deserialize(ISerializer* buffer, IMesh* mesh);
118 void _ownerDefaultInit() { m_item_owners.resize(m_nb_items); m_item_owners.fill(m_subdomain_id);}
119
120 Integer m_nb_items;
121 // Todo optimization use std::reference_wrapper to avoid copy ids (int64 & int32)
122 // => in this case the second constructor won't be possible ?...(resize not possible with reference wrapper since not default constructible)
123 Int64SharedArray m_item_infos;
124 Int32UniqueArray _internal_item_lids; // m_item_lids points on it if the view is not given in the constructor
125 Int32ArrayView m_item_lids;
126 IItemFamily* m_item_family;
127 IItemFamilyModifier* m_item_family_modifier;
128 Integer m_subdomain_id;
129 Int32UniqueArray m_item_owners;
130
131};
132
133/*---------------------------------------------------------------------------*/
134/*---------------------------------------------------------------------------*/
135
136class ARCANE_MESH_EXPORT ItemDataList
137{
138public:
139
149
151 virtual ~ItemDataList() {}
152
153public:
154
155 ItemData& itemData(const Integer family_id)
156 {
157 auto inserter = m_item_infos_list.insert(std::make_pair(family_id,ItemData()));
158 ARCANE_ASSERT((inserter.second),(String::format("Cannot insert twice ItemData for family with id {0} in ItemInfosList",family_id).localstr()));
159 return inserter.first->second;
160 }
161
162 ItemData& itemData(const Integer family_id,
163 Integer nb_items,
164 Integer info_size,
165 Int32ArrayView item_lids,
166 IItemFamily* item_family,
167 IItemFamilyModifier* family_modifier,
168 const Integer& subdomain_id)
169 {
170 auto inserter = m_item_infos_list.insert(std::make_pair(family_id,ItemData(nb_items,info_size,item_lids,item_family,family_modifier,subdomain_id)));
171 ARCANE_ASSERT((inserter.second),(String::format("Cannot insert twice ItemData for family with id {0} in ItemInfosList",family_id).localstr()));
172 return inserter.first->second;
173 }
174
175 ItemData& operator[] (const Integer family_id){
176 return m_item_infos_list[family_id];
177 }
178
179 const ItemData& operator[] (const Integer family_id) const {
180 try {
181 return m_item_infos_list.at(family_id);
182 } catch (const std::out_of_range&) {
183 ARCANE_FATAL("Cannot return family with id {0}, not inserted in current ItemDataList",family_id);
184 }
185 }
186
187 Integer size() const { return arcaneCheckArraySize(m_item_infos_list.size()); }
188
189 bool contains(const Integer family_id) {
190 return m_item_infos_list.find(family_id) != m_item_infos_list.end();
191 }
192
193 void clear(const Integer family_id) {
194 m_item_infos_list.erase(family_id);
195 }
196
197private:
198 std::map<Integer, ItemData> m_item_infos_list;
199};
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
203
204ARCANE_MESH_END_NAMESPACE
205ARCANE_END_NAMESPACE
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
209
210#endif /* ITEMDATA_H_ */
Fichier de configuration d'Arcane.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Interface de modification d'une famille.
Interface d'une famille d'entités.
ItemDataList()
Collection de structure de données nécessaire à l'ajout générique d'item (ItemData).
Definition ItemData.h:148
virtual ~ItemDataList()
Definition ItemData.h:151
ItemData(const ItemData &rhs)=default
Constructeur de recopie.
virtual ~ItemData()
Definition ItemData.h:96
ItemData(Integer nb_items, Integer info_size, Int32ArrayView item_lids, IItemFamily *item_family, IItemFamilyModifier *item_family_modifier, Int32 subdomain_id)
Definition ItemData.h:73
ItemData(Integer nb_items, Integer info_size, IItemFamily *item_family, IItemFamilyModifier *item_family_modifier, Int32 subdomain_id)
Definition ItemData.h:85
ItemData()
Structure de données nécessaire à l'ajout générique d'item.
Definition ItemData.h:64
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Vue modifiable d'un tableau d'un type T.
SharedArray< Int64 > Int64SharedArray
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:545
Integer arcaneCheckArraySize(unsigned long long size)
Vérifie que size peut être converti dans un 'Integer' pour servir de taille à un tableau....
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:515
ConstArrayView< Int64 > Int64ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:638
ArrayView< Int32 > Int32ArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:611
Int32 Integer
Type représentant un entier.