Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ItemProperty.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* ItemProperty.h (C) 2000-2024 */
9/* */
10/* Property on item to handle new connectivities and future mesh properties */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_DOF_ITEMPROPERTY_H
13#define ARCANE_DOF_ITEMPROPERTY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include <algorithm>
18
19#include "arcane/utils/Array.h"
20#include "arcane/utils/Array2.h"
21#include "arcane/utils/MultiArray2.h"
22#include "arcane/ArcaneTypes.h"
23#include "arcane/IItemFamily.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28ARCANE_BEGIN_NAMESPACE
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33template <class DataType>
35{
36 public:
37
39 ItemScalarProperty() : m_default_value(DataType()) {}
40
41 public:
42
43 template <class AbstractFamily>
44 void resize(AbstractFamily* item_family, const DataType default_value) // SDC Template AbstractFamily necessaire pour applications IFPEN
45 {
46 m_data.resize(item_family->maxLocalId(),default_value);
47 m_default_value = default_value;
48 }
49
50 Integer size() const {return m_data.size();}
51
52 template<class AbstractItem>
53 DataType& operator[](const AbstractItem item) {return m_data[item.localId()];}
54
55 template<class AbstractItem>
56 DataType operator[](const AbstractItem item) const {return m_data[item.localId()];}
57
58 void print() const
59 {
60 std::cout << "== CONNECTIVITY ITEM PROPERTY CONTAINS " << std::endl;
61 for (Arcane::Integer i = 0; i < m_data.size();++i)
62 {
63 std::cout << "\""<< m_data[i] << "\"" << std::endl;
64 }
65 std::cout << std::endl;
66 }
67
68 ConstArrayView<DataType> view() {return m_data.constView();}
69
70 void updateSupport(Int32ConstArrayView new_to_old_ids)
71 {
72 if (new_to_old_ids.size() == 0)
73 return;
74 UniqueArray<DataType> old_data(m_data);
75 Integer new_size = new_to_old_ids.size();
76 m_data.resize(new_size);
77 // resize old_data with item recently added and not yet in connectivity
78 // this max size can be greater than new size if they were add and remove
79 Integer max_size = *(std::max_element(new_to_old_ids.begin(), new_to_old_ids.end())) + 1;
80 if (max_size > old_data.size())
81 old_data.resize(max_size, m_default_value); // padd new items
82 for (Integer i = 0; i < new_size; ++i) {
83 m_data[i] = old_data[new_to_old_ids[i]];
84 }
85 }
86
87 void copy(const ItemScalarProperty<DataType>& item_property_from)
88 {
89 m_data.copy(item_property_from.m_data); // copy values
90 m_default_value = item_property_from.m_default_value;
91 }
92
93 private:
94
95// UniqueArray<DataType> m_data;
96 SharedArray<DataType> m_data; // ItemProperty used in IFPEN applications as a shared object (Arcane-like...).
97 DataType m_default_value;
98};
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103template <class DataType>
105{
106 public:
107
110
111 public:
112
113 template <class AbstractFamily>
114 void resize(AbstractFamily* item_family, const Integer nb_element_per_item, const DataType default_value) // SDC Template AbstractFamily necessaire pour applications IFPEN
115 {
116 Integer dim1_old_size = m_data.dim1Size();
117 Integer dim2_old_size = m_data.dim2Size();
118 Integer dim1_new_size = item_family->maxLocalId();
120 m_data.resize(dim1_new_size,dim2_new_size);
121 // Fill new data
122 // if new dim 1 larger, enter loop
123 for (Integer i = dim1_old_size; i < dim1_new_size; ++i)
124 {
125 for (Integer j = 0; j < dim2_new_size; ++j) m_data[i][j] = default_value;
126 }
127 // test if dim2 larger before loop
128 if (dim2_new_size > dim2_old_size)
129 {
130 for (Arcane::Integer i = 0; i < dim1_old_size; ++i)
131 {
132 for (Integer j = dim2_old_size; j < dim2_new_size;++j) m_data[i][j] = default_value;
133 }
134 }
135 }
136
137 Integer dim1Size() const {return m_data.dim1Size();}
138 Integer dim2Size() const {return m_data.dim2Size();}
139
140 template<class AbstractItem>
141 ArrayView<DataType> operator[](AbstractItem item) { return m_data[item.localId()]; }
142
143 template<class AbstractItem>
144 ConstArrayView<DataType> operator[](AbstractItem item) const { return m_data[item.localId()]; }
145
146 void updateSupport(Int32ConstArrayView new_to_old_ids)
147 {
148 if (new_to_old_ids.size() == 0)
149 return;
150 UniqueArray2<DataType> old_data(m_data);
151 Integer new_dim1_size = new_to_old_ids.size();
152 Integer dim2_size = m_data.dim2Size();
153 m_data.resize(new_dim1_size);
154 // resize old_data with item recently added and not yet in connectivity
155 // this max_dim1_size size can be greater than new_dim1_size if they were add and remove
156 auto max_dim1_size = *(std::max_element(new_to_old_ids.begin(), new_to_old_ids.end())) + 1;
157 old_data.resize(max_dim1_size); // padd for new items with 0 (not connected)
158 for (Integer i = 0; i < new_dim1_size; ++i) {
159 for (Integer j = 0; j < dim2_size; ++j)
160 m_data[i][j] = old_data[new_to_old_ids[i]][j];
161 }
162 }
163
164 void copy(const ItemArrayProperty<DataType>& item_property_from)
165 {
166 m_data.copy(item_property_from.m_data); // copy values
167 }
168
169 private:
170
171 UniqueArray2<DataType> m_data;
172};
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177template <class DataType>
179{
180 public:
181
184
185 public:
186
187 typedef MultiArray2<DataType> InternalArray2;
188
189 // nb_element per item est de taille IItemFamily::maxLocalId
190 template <class AbstractFamily>
191 void resize([[maybe_unused]] AbstractFamily* item_family,
193 const DataType default_value) // SDC Template AbstractFamily necessaire pour applications IFPEN
194 {
195 ARCANE_ASSERT((nb_element_per_item.size() == item_family->maxLocalId()),
196 ("In item property resize : nb_element_per_item must have size IItemFamilyy::maxLocalId"))
197 Integer dim1_old_size = m_data.dim1Size();
198 Integer dim1_new_size = nb_element_per_item.size();
199 IntegerUniqueArray dim2_old_sizes(m_data.dim2Sizes());
201 m_data.resize(nb_element_per_item);
202 // Fill new data with default value
203 // Dim1 size larger
204 for (Arcane::Integer i = dim1_old_size; i < dim1_new_size; ++i)
205 {
206 for (Arcane::Integer j = 0; j < dim2_new_sizes[i]; ++j)
207 {
208 m_data[i][j] = default_value;
209 }
210 }
211 // Dim2 size larger (eventually, cannot know a priori, need to loop).
212 for (Arcane::Integer i = 0; i < dim1_old_size; ++i)
213 {
214 for (Arcane::Integer j = dim2_old_sizes[i]; j < dim2_new_sizes[i]; ++j)
215 {
216 m_data[i][j] = default_value;
217 }
218 }
219 }
220
221 Integer dim1Size() const {return m_data.dim1Size();}
222 IntegerConstArrayView dim2Sizes() const {return m_data.dim2Sizes();}
223
224 template<class AbstractItem>
225 ArrayView<DataType> operator[](const AbstractItem item) {return m_data[item.localId()];}
226
227 template<class AbstractItem>
228 ConstArrayView<DataType> operator[](const AbstractItem item) const {return m_data[item.localId()];}
229
230 void updateSupport(Int32ConstArrayView new_to_old_ids)
231 {
232 if (new_to_old_ids.size() == 0)
233 return;
234 UniqueMultiArray2<DataType> old_data(m_data);
235 Integer new_dim1_size = new_to_old_ids.size();
236 // new_to_old_ids may refer to items newly added and not yet in m_data (ie old_data) if there is add and removal in the same event
237 // compute max_dim1_size to take this into account
238 Integer max_dim1_size = *(std::max_element(new_to_old_ids.begin(), new_to_old_ids.end())) + 1;
239 IntegerUniqueArray dim2_sizes(m_data.dim2Sizes());
240 dim2_sizes.resize(max_dim1_size, 1); // padd for unknown items with 1 (connected with empty)
241 old_data.resize(dim2_sizes); // take into account unknown items. Recall these items are compacted but were not yet in m_data
242 IntegerUniqueArray new_dim2_sizes(new_dim1_size);
243 // Compute new sizes
244 for (Integer i = 0; i < new_dim1_size; ++i) {
245 new_dim2_sizes[i] = dim2_sizes[new_to_old_ids[i]];
246 }
247 m_data.resize(new_dim2_sizes);
248 for (Integer i = 0; i < new_dim1_size; ++i) {
249 for (Integer j = 0; j < new_dim2_sizes[i]; ++j)
250 m_data[i][j] = old_data[new_to_old_ids[i]][j];
251 }
252 }
253
254 void copy(const ItemMultiArrayProperty<DataType>& item_property_from)
255 {
256 m_data = item_property_from.m_data.constView(); // copy values
257 }
258
259 private:
260
261// UniqueMultiArray2<DataType> m_data;
262 SharedMultiArray2<DataType> m_data; // ItemProperty used in IFPEN applications as a shared object (Arcane-like...).
263};
264
265/*---------------------------------------------------------------------------*/
266/*---------------------------------------------------------------------------*/
267
268ARCANE_END_NAMESPACE
269
270/*---------------------------------------------------------------------------*/
271/*---------------------------------------------------------------------------*/
272
273#endif /* ITEMPROPERTY_H_ */
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Vue constante d'un tableau de type T.
Vecteur 1D de données avec sémantique par valeur (style STL).
char * copy(char *to, const char *from)
Copie from dans to.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
UniqueArray< Integer > IntegerUniqueArray
Tableau dynamique à une dimension d'entiers.
Definition UtilsTypes.h:519
ConstArrayView< Integer > IntegerConstArrayView
Equivalent C d'un tableau à une dimension d'entiers.
Definition UtilsTypes.h:644
Int32 Integer
Type représentant un entier.