Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MaterialVariableViews.h
Go to the documentation of this file.
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/* MaterialVariableViews.h (C) 2000-2026 */
9/* */
10/* Management of views on material variables for accelerators. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ACCELERATOR_MATERIALVARIABLEVIEWS_H
13#define ARCANE_ACCELERATOR_MATERIALVARIABLEVIEWS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/materials/IMeshMaterialVariable.h"
20#include "arcane/core/materials/MatItem.h"
21
22#include "arcane/accelerator/AcceleratorGlobal.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27using namespace Arcane;
28using namespace Arcane::Materials;
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane::Accelerator
34{
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
42class ARCANE_ACCELERATOR_EXPORT MatVariableViewBase
43{
44 public:
45
46 // Currently does not use parameters yet
47 MatVariableViewBase(const ViewBuildInfo&, IMeshMaterialVariable*);
48
49 // Currently does not use parameters yet
50 MatVariableViewBase() = default;
51};
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
59template <typename ItemType, typename DataType>
60class MatItemVariableScalarInViewT
61: public MatVariableViewBase
62{
63 // TODO: Should SIMD handling be added like in ItemVariableScalarInViewT?
64
65 private:
66
67 using ItemIndexType = typename ItemTraitsT<ItemType>::LocalIdType;
68
69 public:
70
71 MatItemVariableScalarInViewT(const ViewBuildInfo& vbi, IMeshMaterialVariable* var, ArrayView<DataType>* v)
72 : MatVariableViewBase(vbi, var)
73 , m_value(v)
74 {}
75 MatItemVariableScalarInViewT() = default;
76
78 ARCCORE_HOST_DEVICE const DataType& operator[](ComponentItemLocalId lid) const
79 {
80 return this->m_value[lid.localId().arrayIndex()][lid.localId().valueIndex()];
81 }
82
84 ARCCORE_HOST_DEVICE const DataType& operator[](PureMatVarIndex pmvi) const
85 {
86 return this->m_value[0][pmvi.valueIndex()];
87 }
88
90 ARCCORE_HOST_DEVICE const DataType& operator[](ItemIndexType item) const
91 {
92 return this->m_value[0][item.localId()];
93 }
94
96 ARCCORE_HOST_DEVICE const DataType& value(ComponentItemLocalId mvi) const
97 {
98 return this->m_value[mvi.localId().arrayIndex()][mvi.localId().valueIndex()];
99 }
100
101 ARCCORE_HOST_DEVICE const DataType& value0(PureMatVarIndex idx) const
102 {
103 return this->m_value[0][idx.valueIndex()];
104 }
105
106 private:
107
108 ArrayView<DataType>* m_value = nullptr;
109};
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
117template <typename ItemType, typename Accessor>
118class MatItemVariableScalarOutViewT
119: public MatVariableViewBase
120{
121 private:
122
123 using DataType = typename Accessor::ValueType;
124 using DataTypeReturnType = DataType&;
125 using ItemIndexType = typename ItemTraitsT<ItemType>::LocalIdType;
126
127 // TODO: Should ARCANE_CHECK_AT(mvi.arrayIndex(), m_value.size()); be added?
128 // The check on the other dimension will still be missing.
129 // TODO: Should SIMD type handling be added like in ItemVariableScalarOutViewT?
130
131 public:
132
133 MatItemVariableScalarOutViewT(const ViewBuildInfo& vbi, IMeshMaterialVariable* var, ArrayView<DataType>* v)
134 : MatVariableViewBase(vbi, var)
135 , m_value(v)
136 {}
137 MatItemVariableScalarOutViewT() = default;
138
140 ARCCORE_HOST_DEVICE Accessor operator[](ComponentItemLocalId lid) const
141 {
142 return Accessor(this->m_value[lid.localId().arrayIndex()].data() + lid.localId().valueIndex());
143 }
144
145 ARCCORE_HOST_DEVICE Accessor operator[](PureMatVarIndex pmvi) const
146 {
147 return Accessor(this->m_value[0][pmvi.valueIndex()]);
148 }
149
151 ARCCORE_HOST_DEVICE Accessor operator[](ItemIndexType item) const
152 {
153 ARCANE_CHECK_AT(item.localId(), this->m_value[0].size());
154 return Accessor(this->m_value[0].data() + item.localId());
155 }
156
158 ARCCORE_HOST_DEVICE Accessor value(ComponentItemLocalId lid) const
159 {
160 return Accessor(this->m_value[lid.localId().arrayIndex()].data() + lid.localId().valueIndex());
161 }
162
164 ARCCORE_HOST_DEVICE void setValue(ComponentItemLocalId lid, const DataType& v) const
165 {
166 this->m_value[lid.localId().arrayIndex()][lid.localId().valueIndex()] = v;
167 }
168
169 ARCCORE_HOST_DEVICE Accessor value0(PureMatVarIndex idx) const
170 {
171 return Accessor(this->m_value[0][idx.valueIndex()]);
172 }
173
174 private:
175
176 ArrayView<DataType>* m_value = nullptr;
177};
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
185template <typename DataType> auto
187{
188 using Accessor = DataViewSetter<DataType>;
189 return MatItemVariableScalarOutViewT<Cell, Accessor>(vbi, var.materialVariable(), var._internalValue());
190}
191
192/*---------------------------------------------------------------------------*/
193/*---------------------------------------------------------------------------*/
194
198template <typename DataType> auto
200{
201 using Accessor = DataViewSetter<DataType>;
202 return MatItemVariableScalarOutViewT<Cell, Accessor>(vbi, var.materialVariable(), var._internalValue());
203}
204
205/*---------------------------------------------------------------------------*/
206/*---------------------------------------------------------------------------*/
207
211template <typename DataType> auto
213{
214 using Accessor = DataViewGetterSetter<DataType>;
215 return MatItemVariableScalarOutViewT<Cell, Accessor>(vbi, var.materialVariable(), var._internalValue());
216}
217
218/*---------------------------------------------------------------------------*/
219/*---------------------------------------------------------------------------*/
220
224template <typename DataType> auto
226{
227 using Accessor = DataViewGetterSetter<DataType>;
228 return MatItemVariableScalarOutViewT<Cell, Accessor>(vbi, var.materialVariable(), var._internalValue());
229}
230
231/*---------------------------------------------------------------------------*/
232/*---------------------------------------------------------------------------*/
233
237template <typename DataType> auto
239{
240 return MatItemVariableScalarInViewT<Cell, DataType>(vbi, var.materialVariable(), var._internalValue());
241}
242
243/*---------------------------------------------------------------------------*/
244/*---------------------------------------------------------------------------*/
245
249template <typename DataType> auto
251{
252 return MatItemVariableScalarInViewT<Cell, DataType>(vbi, var.materialVariable(), var._internalValue());
253}
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258} // namespace Arcane::Accelerator
259
260#endif
__host__ __device__ const DataType & operator[](ComponentItemLocalId lid) const
Access operator for entity item.
__host__ __device__ const DataType & value(ComponentItemLocalId mvi) const
Access operator for entity item.
__host__ __device__ const DataType & operator[](PureMatVarIndex pmvi) const
Access operator for entity item.
__host__ __device__ const DataType & operator[](ItemIndexType item) const
Override to access the global value from the cell id.
__host__ __device__ Accessor operator[](ComponentItemLocalId lid) const
Access operator for entity item.
__host__ __device__ Accessor value(ComponentItemLocalId lid) const
Access operator for entity item.
__host__ __device__ void setValue(ComponentItemLocalId lid, const DataType &v) const
Positions the value for entity item at v.
__host__ __device__ Accessor operator[](ItemIndexType item) const
Override to access the global value from the cell id.
Modifiable view of an array of type T.
Characteristics of mesh elements.
Definition ItemTypes.h:625
constexpr __host__ __device__ MatVarIndex localId() const
Generic index to access variable values.
Interface of a material variable on a mesh.
constexpr __host__ __device__ Int32 arrayIndex() const
Returns the index of the value array in the list of variables.
constexpr __host__ __device__ Int32 valueIndex() const
Returns the index in the value array.
IMeshMaterialVariable * materialVariable() const
Associated material variable.
Index of a pure material item in a variable.
auto viewInOut(const ViewBuildInfo &vbi, CellMaterialVariableScalarRef< DataType > &var)
Read/write view for scalar material variables.
auto viewOut(const ViewBuildInfo &vbi, CellMaterialVariableScalarRef< DataType > &var)
Write view for scalar material variables.
auto viewIn(const ViewBuildInfo &vbi, const CellMaterialVariableScalarRef< DataType > &var)
Read view for scalar material variables.
Always enables tracing in Arcane parts concerning materials.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --