Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
SharedVariable.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* SharedVariable.h (C) 2000-2023 */
9/* */
10/* Classe gérant une vue partagée d'une variable. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_SHARED_VARIABLE_H
13#define ARCANE_SHARED_VARIABLE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18#include "arcane/ArcaneTypes.h"
19#include "arcane/IVariable.h"
20#include "arcane/IItemFamily.h"
21#include "arcane/utils/FatalErrorException.h"
22
23#include "arcane/IMeshSubMeshTransition.h"
24#include "arcane/ItemGroup.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35/*! Variable partagée à partir d'une variable Arcane
36 * L'implémentation préliminaire suppose que le uniqueId des items
37 * est le même entre sous-maillage et maillage support.
38 */
39template<typename ItemTypeT, typename DataTypeT>
41public:
42 typedef ItemTypeT ItemType;
43 typedef DataTypeT DataType;
44 typedef DataTypeT & DataTypeReturnReference;
47
48public:
50 : m_true_variable(nullptr)
51 , m_family(NULL)
52 , m_parent_family(NULL)
53 , m_direct_access(false)
54 , m_family_depth(0)
55 {
56 ;
57 }
58
59// SharedMeshVariableScalarRefT(TrueVariable & v)
60// : m_true_variable(v)
61// , m_family(v.itemGroup().itemFamily())
62// , m_parent_family(NULL)
63// , m_direct_access(true)
64// , m_family_depth(0)
65// {
66// ;
67// }
68
69 SharedMeshVariableScalarRefT(IItemFamily * family, TrueVariable & v)
70 : m_true_variable(v)
71 , m_family(family)
72 , m_parent_family(family->parentFamily())
73 , m_direct_access(false)
74 , m_family_depth(-1)
75 {
76 IItemFamily * variable_family = v.itemGroup().itemFamily();
77
78 // Ne gère actuellement qu'au plus un niveau d'imbrication
79 // Si parent_family == family, n'utilise pas l'imbrication
80 // Attn alors si item.parent()!=item
81 if (variable_family == m_family)
82 m_direct_access = true;
83 else if (m_parent_family == variable_family)
84 m_family_depth = 0;
85 else
86 throw FatalErrorException(A_FUNCINFO,"Incompatible Family on shared variable");
87 }
88
89 SharedMeshVariableScalarRefT(const ThisVariable & v)
90 : m_true_variable(v.m_true_variable)
91 , m_family(v.m_family)
92 , m_parent_family(v.m_parent_family)
93 , m_direct_access(v.m_direct_access)
94 , m_family_depth(v.m_family_depth)
95 {
96 ;
97 }
98
100 {
101 ;
102 }
103
104 DataTypeReturnReference operator[](const ItemType & i)
105 {
106 ARCANE_ASSERT((m_family!=m_parent_family || i.itemBase()==i.itemBase().parentBase(m_family_depth)),("Confusion: item parent differs from item"));
107 return m_true_variable.asArray()[(m_direct_access)?i.localId():i.itemBase().parentId(m_family_depth)];
108 }
109
110 DataType operator[](const ItemType & i) const
111 {
112 ARCANE_ASSERT((m_family!=m_parent_family || i.itemBase()==i.itemBase().parentBase(m_family_depth)),("Confusion: item parent differs from item"));
113 return m_true_variable.asArray()[(m_direct_access)?i.localId():i.itemBase().parentId(m_family_depth)];
114 }
115
116
117 DataTypeReturnReference operator[](const ItemEnumeratorT<ItemType> & i)
118 {
119 ARCANE_ASSERT((m_family!=m_parent_family || (*i).itemBase()==i->parent(m_family_depth)),("Confusion: item parent differs from item"));
120 return m_true_variable.asArray()[(m_direct_access)?i.localId():i->itemBase().parentId(m_family_depth)];
121 }
122
123 DataType operator[](const ItemEnumeratorT<ItemType> & i) const
124 {
125 ARCANE_ASSERT((m_family!=m_parent_family || (*i).internal()==i->parent(m_family_depth)),("Confusion: item parent differs from item"));
126 return m_true_variable.asArray()[(m_direct_access)?i.localId():i->internal()->parentId(m_family_depth)];
127 }
128
129 TrueVariable & trueVariable()
130 {
131 return m_true_variable;
132 }
133
134 const TrueVariable & trueVariable() const
135 {
136 return m_true_variable;
137 }
138 public:
139 //! TODO GG: il faudra supprimer l'opérateur d'assignement.
140 ARCANE_DEPRECATED_240 void operator=(const ThisVariable & v)
141 {
142 m_true_variable.refersTo(v.m_true_variable);
143 m_family = v.m_family;
144 m_parent_family = v.m_parent_family;
145 m_direct_access = v.m_direct_access;
146 m_family_depth = v.m_family_depth;
147 }
148
149protected:
150 TrueVariable m_true_variable;
151 IItemFamily * m_family;
152 IItemFamily * m_parent_family;
153 bool m_direct_access;
154 Integer m_family_depth;
155};
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
160template<typename DataTypeT>
162public:
163 typedef DataTypeT DataType;
164 typedef DataTypeT & DataTypeReturnReference;
165 typedef ItemVariableScalarRefT<DataTypeT> TrueVariable;
166 typedef SharedItemVariableScalarRefT<DataTypeT> ThisVariable;
167
168public:
169// SharedItemVariableScalarRefT(TrueVariable & v)
170// : m_true_variable(v)
171// , m_family(v.itemGroup().itemFamily())
172// , m_parent_family(NULL)
173// , m_direct_access(true)
174// , m_family_depth(0)
175// {
176// ;
177// }
178
179 SharedItemVariableScalarRefT(IItemFamily * family, TrueVariable & v)
180 : m_true_variable(v)
181 , m_family(family)
182 , m_parent_family(family->parentFamily())
183 , m_direct_access(false)
184 , m_family_depth(-1)
185 {
186 IItemFamily * variable_family = v.itemGroup().itemFamily();
187
188 // Ne gère actuellement qu'au plus un niveau d'imbrication
189 // Si parent_family == family, n'utilise pas l'imbrication
190 // Attn alors si item.parent()!=item
191 if (variable_family == m_family)
192 m_direct_access = true;
193 else if (m_parent_family == variable_family)
194 m_family_depth = 0;
195 else
196 throw FatalErrorException(A_FUNCINFO,"Incompatible Family on shared variable");
197 }
198
199 SharedItemVariableScalarRefT(const ThisVariable & v)
200 : m_true_variable(v.m_true_variable)
201 , m_family(v.m_family)
202 , m_parent_family(v.m_parent_family)
203 , m_direct_access(v.m_direct_access)
204 , m_family_depth(v.m_family_depth)
205 {
206 ;
207 }
208
210 {
211 ;
212 }
213
214 DataTypeReturnReference operator[](const Item & i)
215 {
216 ARCANE_ASSERT((m_family!=m_parent_family || i.itemBase()==i.itemBase().parentBase(m_family_depth)),("Confusion: item parent differs from item"));
217 return m_true_variable.asArray()[(m_direct_access)?i.localId():i.itemBase().parentId(m_family_depth)];
218 }
219
220 DataType operator[](const Item & i) const
221 {
222 ARCANE_ASSERT((m_family!=m_parent_family || i.itemBase()==i.itemBase().parentBase(m_family_depth)),("Confusion: item parent differs from item"));
223 return m_true_variable.asArray()[(m_direct_access)?i.localId():i.itemBase().parentId(m_family_depth)];
224 }
225
226
227 DataTypeReturnReference operator[](const ItemEnumerator & i)
228 {
229 ARCANE_ASSERT((m_family!=m_parent_family || (*i).itemBase()==i->parent(m_family_depth)),("Confusion: item parent differs from item"));
230 return m_true_variable.asArray()[(m_direct_access)?i.localId():i->itemBase().parentId(m_family_depth)];
231 }
232
233 DataType operator[](const ItemEnumerator & i) const
234 {
235 ARCANE_ASSERT((m_family!=m_parent_family || (*i).itemBase()==i->parent(m_family_depth)),("Confusion: item parent differs from item"));
236 return m_true_variable.asArray()[(m_direct_access)?i.localId():i->itemBase().parentId(m_family_depth)];
237 }
238
239 TrueVariable & trueVariable()
240 {
241 return m_true_variable;
242 }
243
244 const TrueVariable & trueVariable() const
245 {
246 return m_true_variable;
247 }
248 public:
249 //! TODO GG: il faudra supprimer l'opérateur d'assignement.
250 ARCANE_DEPRECATED_240 void operator=(const ThisVariable & v)
251 {
252 m_true_variable.refersTo(v.m_true_variable);
253 m_family = v.m_family;
254 m_parent_family = v.m_parent_family;
255 m_direct_access = v.m_direct_access;
256 m_family_depth = v.m_family_depth;
257 }
258protected:
259 TrueVariable m_true_variable;
260 IItemFamily * m_family;
261 IItemFamily * m_parent_family;
262 bool m_direct_access;
263 Integer m_family_depth;
264};
265
266/*---------------------------------------------------------------------------*/
267/*---------------------------------------------------------------------------*/
268
269}
270
271/*---------------------------------------------------------------------------*/
272/*---------------------------------------------------------------------------*/
273
274#endif /* ARCANE_SHARED_VARIABLE_H */
275
Interface d'une famille d'entités.
virtual IItemFamily * parentFamily() const =0
IItemFamily parent.
Int32 localId() const
localId() de l'entité courante.
Enumérateur sur une liste typée d'entités de type ItemType.
Enumérateur sur une liste d'entités.
Variable scalaire sur un type d'entité du maillage.
Classe de base d'un élément de maillage.
Definition Item.h:83
constexpr Int32 localId() const
Identifiant local de l'entité dans le sous-domaine du processeur.
Definition Item.h:210
impl::ItemBase itemBase() const
Partie interne de l'entité.
Definition Item.h:354
Variable scalaire sur un type d'entité du maillage.
ARCANE_DEPRECATED_240 void operator=(const ThisVariable &v)
TODO GG: il faudra supprimer l'opérateur d'assignement.
ARCANE_DEPRECATED_240 void operator=(const ThisVariable &v)
TODO GG: il faudra supprimer l'opérateur d'assignement.
Exception lorsqu'une erreur fatale est survenue.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-