Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
SharedVariable.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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-2025 */
9/* */
10/* Class managing a shared view of a variable. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_SHAREDVARIABLE_H
13#define ARCANE_CORE_SHAREDVARIABLE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18#include "arcane/utils/FatalErrorException.h"
19
21#include "arcane/core/IVariable.h"
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/IMeshSubMeshTransition.h"
24#include "arcane/core/ItemGroup.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35/*! Shared variable based on an Arcane variable
36 * The preliminary implementation assumes that the uniqueId of the items
37 * is the same between sub-mesh and support mesh.
38 */
39template <typename ItemTypeT, typename DataTypeT>
40class SharedMeshVariableScalarRefT
41{
42 public:
43
44 typedef ItemTypeT ItemType;
45 typedef DataTypeT DataType;
46 typedef DataTypeT& DataTypeReturnReference;
48 typedef SharedMeshVariableScalarRefT<ItemTypeT, DataTypeT> ThisVariable;
49
50 public:
51
52 SharedMeshVariableScalarRefT()
53 : m_true_variable(nullptr)
54 , m_family(NULL)
55 , m_parent_family(NULL)
56 , m_direct_access(false)
57 , m_family_depth(0)
58 {
59 ;
60 }
61
62 // SharedMeshVariableScalarRefT(TrueVariable & v)
63 // : m_true_variable(v)
64 // , m_family(v.itemGroup().itemFamily())
65 // , m_parent_family(NULL)
66 // , m_direct_access(true)
67 // , m_family_depth(0)
68 // {
69 // ;
70 // }
71
72 SharedMeshVariableScalarRefT(IItemFamily* family, TrueVariable& v)
73 : m_true_variable(v)
74 , m_family(family)
75 , m_parent_family(family->parentFamily())
76 , m_direct_access(false)
77 , m_family_depth(-1)
78 {
79 IItemFamily* variable_family = v.itemGroup().itemFamily();
80
81 // Currently only handles up to one level of nesting
82 // If parent_family == family, do not use nesting
83 // Note then if item.parent()!=item
84 if (variable_family == m_family)
85 m_direct_access = true;
86 else if (m_parent_family == variable_family)
87 m_family_depth = 0;
88 else
89 throw FatalErrorException(A_FUNCINFO, "Incompatible Family on shared variable");
90 }
91
92 SharedMeshVariableScalarRefT(const ThisVariable& v)
93 : m_true_variable(v.m_true_variable)
94 , m_family(v.m_family)
95 , m_parent_family(v.m_parent_family)
96 , m_direct_access(v.m_direct_access)
97 , m_family_depth(v.m_family_depth)
98 {
99 ;
100 }
101
102 ~SharedMeshVariableScalarRefT()
103 {
104 ;
105 }
106
107 DataTypeReturnReference operator[](const ItemType& i)
108 {
109 ARCANE_ASSERT((m_family != m_parent_family || i.itemBase() == i.itemBase().parentBase(m_family_depth)), ("Confusion: item parent differs from item"));
110 return m_true_variable.asArray()[(m_direct_access) ? i.localId() : i.itemBase().parentId(m_family_depth)];
111 }
112
113 DataType operator[](const ItemType& i) const
114 {
115 ARCANE_ASSERT((m_family != m_parent_family || i.itemBase() == i.itemBase().parentBase(m_family_depth)), ("Confusion: item parent differs from item"));
116 return m_true_variable.asArray()[(m_direct_access) ? i.localId() : i.itemBase().parentId(m_family_depth)];
117 }
118
119 DataTypeReturnReference operator[](const ItemEnumeratorT<ItemType>& i)
120 {
121 ARCANE_ASSERT((m_family != m_parent_family || (*i).itemBase() == i->parent(m_family_depth)), ("Confusion: item parent differs from item"));
122 return m_true_variable.asArray()[(m_direct_access) ? i.localId() : i->itemBase().parentId(m_family_depth)];
123 }
124
125 DataType operator[](const ItemEnumeratorT<ItemType>& i) const
126 {
127 ARCANE_ASSERT((m_family != m_parent_family || (*i).internal() == i->parent(m_family_depth)), ("Confusion: item parent differs from item"));
128 return m_true_variable.asArray()[(m_direct_access) ? i.localId() : i->internal()->parentId(m_family_depth)];
129 }
130
131 TrueVariable& trueVariable()
132 {
133 return m_true_variable;
134 }
135
136 const TrueVariable& trueVariable() const
137 {
138 return m_true_variable;
139 }
140
141 public:
142
143 //! TODO GG: the assignment operator will need to be removed.
144 ARCANE_DEPRECATED_240 void operator=(const ThisVariable& v)
145 {
146 m_true_variable.refersTo(v.m_true_variable);
147 m_family = v.m_family;
148 m_parent_family = v.m_parent_family;
149 m_direct_access = v.m_direct_access;
150 m_family_depth = v.m_family_depth;
151 }
152
153 protected:
154
155 TrueVariable m_true_variable;
156 IItemFamily* m_family;
157 IItemFamily* m_parent_family;
158 bool m_direct_access;
159 Integer m_family_depth;
160};
161
162/*---------------------------------------------------------------------------*/
163/*---------------------------------------------------------------------------*/
164
165template <typename DataTypeT>
166class SharedItemVariableScalarRefT
167{
168 public:
169
170 typedef DataTypeT DataType;
171 typedef DataTypeT& DataTypeReturnReference;
172 typedef ItemVariableScalarRefT<DataTypeT> TrueVariable;
173 typedef SharedItemVariableScalarRefT<DataTypeT> ThisVariable;
174
175 public:
176
177 // SharedItemVariableScalarRefT(TrueVariable & v)
178 // : m_true_variable(v)
179 // , m_family(v.itemGroup().itemFamily())
180 // , m_parent_family(NULL)
181 // , m_direct_access(true)
182 // , m_family_depth(0)
183 // {
184 // ;
185 // }
186
187 SharedItemVariableScalarRefT(IItemFamily* family, TrueVariable& v)
188 : m_true_variable(v)
189 , m_family(family)
190 , m_parent_family(family->parentFamily())
191 , m_direct_access(false)
192 , m_family_depth(-1)
193 {
194 IItemFamily* variable_family = v.itemGroup().itemFamily();
195
196 // Currently only handles up to one level of nesting
197 // If parent_family == family, do not use nesting
198 // Note then if item.parent()!=item
199 if (variable_family == m_family)
200 m_direct_access = true;
201 else if (m_parent_family == variable_family)
202 m_family_depth = 0;
203 else
204 throw FatalErrorException(A_FUNCINFO, "Incompatible Family on shared variable");
205 }
206
207 SharedItemVariableScalarRefT(const ThisVariable& v)
208 : m_true_variable(v.m_true_variable)
209 , m_family(v.m_family)
210 , m_parent_family(v.m_parent_family)
211 , m_direct_access(v.m_direct_access)
212 , m_family_depth(v.m_family_depth)
213 {
214 ;
215 }
216
217 ~SharedItemVariableScalarRefT()
218 {
219 ;
220 }
221
222 DataTypeReturnReference operator[](const Item& i)
223 {
224 ARCANE_ASSERT((m_family != m_parent_family || i.itemBase() == i.itemBase().parentBase(m_family_depth)), ("Confusion: item parent differs from item"));
225 return m_true_variable.asArray()[(m_direct_access) ? i.localId() : i.itemBase().parentId(m_family_depth)];
226 }
227
228 DataType operator[](const Item& i) const
229 {
230 ARCANE_ASSERT((m_family != m_parent_family || i.itemBase() == i.itemBase().parentBase(m_family_depth)), ("Confusion: item parent differs from item"));
231 return m_true_variable.asArray()[(m_direct_access) ? i.localId() : i.itemBase().parentId(m_family_depth)];
232 }
233
234 DataTypeReturnReference operator[](const ItemEnumerator& i)
235 {
236 ARCANE_ASSERT((m_family != m_parent_family || (*i).itemBase() == i->parent(m_family_depth)), ("Confusion: item parent differs from item"));
237 return m_true_variable.asArray()[(m_direct_access) ? i.localId() : i->itemBase().parentId(m_family_depth)];
238 }
239
240 DataType operator[](const ItemEnumerator& i) const
241 {
242 ARCANE_ASSERT((m_family != m_parent_family || (*i).itemBase() == i->parent(m_family_depth)), ("Confusion: item parent differs from item"));
243 return m_true_variable.asArray()[(m_direct_access) ? i.localId() : i->itemBase().parentId(m_family_depth)];
244 }
245
246 TrueVariable& trueVariable()
247 {
248 return m_true_variable;
249 }
250
251 const TrueVariable& trueVariable() const
252 {
253 return m_true_variable;
254 }
255
256 public:
257
258 //! TODO GG: the assignment operator will need to be removed.
259 ARCANE_DEPRECATED_240 void operator=(const ThisVariable& v)
260 {
261 m_true_variable.refersTo(v.m_true_variable);
262 m_family = v.m_family;
263 m_parent_family = v.m_parent_family;
264 m_direct_access = v.m_direct_access;
265 m_family_depth = v.m_family_depth;
266 }
267
268 protected:
269
270 TrueVariable m_true_variable;
271 IItemFamily* m_family;
272 IItemFamily* m_parent_family;
273 bool m_direct_access;
274 Integer m_family_depth;
275};
276
277/*---------------------------------------------------------------------------*/
278/*---------------------------------------------------------------------------*/
279
280} // namespace Arcane
281
282/*---------------------------------------------------------------------------*/
283/*---------------------------------------------------------------------------*/
284
285#endif
Declarations of Arcane's general types.
Interface of an entity family.
Definition IItemFamily.h:83
virtual IItemFamily * parentFamily() const =0
IItemFamily parent.
Int32 localId() const
localId() of the current entity.
Enumerator over a typed list of entities of type ItemType.
Enumerator over a list of entities.
IItemFamily * itemFamily() const
Entity family to which this group belongs (0 for the null group).
Definition ItemGroup.h:128
Scalar variable on a mesh entity type.
Base class for a mesh element.
Definition Item.h:84
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
Definition Item.h:233
impl::ItemBase itemBase() const
Internal part of the entity.
Definition Item.h:383
Scalar variable on a mesh entity type.
GroupType itemGroup() const
Group associated with the quantity.
ARCANE_DEPRECATED_240 void operator=(const ThisVariable &v)
TODO GG: the assignment operator will need to be removed.
ARCANE_DEPRECATED_240 void operator=(const ThisVariable &v)
TODO GG: the assignment operator will need to be removed.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.