Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
RealArrayVariant.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/* RealArrayVariant.h (C) 2000-2024 */
9/* */
10/* Variant pouvant contenir les types ConstArrayView, Real2 et Real3. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_DATATYPE_REALARRAYVARIANT_H
14#define ARCANE_DATATYPE_REALARRAYVARIANT_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/Array.h"
19#include "arcane/utils/ArrayView.h"
20#include "arcane/utils/Real2.h"
21#include "arcane/utils/Real3.h"
22#if defined(ARCANE_HAS_ACCELERATOR_API)
23#include "arcane/utils/NumArray.h"
24#endif
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34/*!
35 * \internal
36 * \brief Variant pouvant contenir les types ConstArrayView, Real2 et Real3.
37 */
39{
40 public:
41
42 static const Integer MAX_SIZE = 9;
43
44 RealArrayVariant() = default;
47 {}
49 {
50 _setValue(v.data(), v.size());
51 }
52#if defined(ARCANE_HAS_ACCELERATOR_API)
53 template<typename LayoutType>
55 : RealArrayVariant(v.mdspan())
56 {}
57 template<typename LayoutType>
59 {
60 _setValue(v.to1DSpan().data(), v.extent0());
61 }
62 template<typename LayoutType>
64 {
65 _setValue(v.to1DSpan().data(), v.extent0());
66 }
67#endif
69 {
70 _setValue(reinterpret_cast<Real*>(&r), 2);
71 }
73 {
74 _setValue(reinterpret_cast<Real*>(&r), 3);
75 }
76
77 RealArrayVariant& operator=(const RealArrayVariant& rhs) = default;
79 {
80 _setValue(v.data(), v.size());
81 return (*this);
82 }
83 RealArrayVariant& operator=(Real2 r)
84 {
85 _setValue(reinterpret_cast<Real*>(&r), 2);
86 return (*this);
87 }
88 RealArrayVariant& operator=(Real3 r)
89 {
90 _setValue(reinterpret_cast<Real*>(&r), 3);
91 return (*this);
92 }
93
94 Real& operator[](Integer index)
95 {
96 ARCANE_ASSERT(index < m_nb_value, ("Index out of range"));
97 return m_value[index];
98 }
99 Real operator[](Integer index) const
100 {
101 ARCANE_ASSERT(index < m_nb_value, ("Index out of range"));
102 return m_value[index];
103 }
104 Real& operator()(Integer index)
105 {
106 ARCANE_ASSERT(index < m_nb_value, ("Index out of range"));
107 return m_value[index];
108 }
109 Real operator()(Integer index) const
110 {
111 ARCANE_ASSERT(index < m_nb_value, ("Index out of range"));
112 return m_value[index];
113 }
114
115 Int32 size() const { return m_nb_value; }
116 Real* data() { return m_value; }
117 const Real* data() const { return m_value; }
118 operator ConstArrayView<Real>() const { return ConstArrayView<Real>(m_nb_value, m_value); }
119 operator Real2() const { return Real2(m_value[0], m_value[1]); }
120 operator Real3() const { return Real3(m_value[0], m_value[1], m_value[2]); }
121
122#if defined(ARCANE_HAS_ACCELERATOR_API)
123 operator NumArray<Real,MDDim1>() const
124 {
125 NumArray<Real,MDDim1> v(m_nb_value);
126 for( Integer i=0, n=m_nb_value; i<n; ++i )
127 v[i] = m_value[i];
128 return v;
129 }
130#endif
131
132 private:
133
134 Real m_value[MAX_SIZE];
135 Int32 m_nb_value = 0;
136
137 private:
138
139 void _setValue(const Real* v, Int32 nb_value)
140 {
141 m_nb_value = nb_value;
142 ARCANE_ASSERT(nb_value <= MAX_SIZE, ("Size is too large"));
143 for (Integer i = 0 ; i < nb_value; ++i)
144 m_value[i] = v[i];
145 }
146};
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151} // namespace Arcane
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156#endif
Classe de base des vues multi-dimensionnelles.
Definition MDSpan.h:44
constexpr __host__ __device__ Int32 extent0() const
Valeur de la première dimension.
Definition MDSpan.h:102
Tableaux multi-dimensionnels pour les types numériques accessibles sur accélérateurs.
Classe gérant un vecteur de réel de dimension 2.
Definition Real2.h:121
Classe gérant un vecteur de réel de dimension 3.
Definition Real3.h:132
ConstArrayView< T > constView() const
Vue constante sur ce tableau.
Vue constante d'un tableau de type T.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
constexpr const_pointer data() const noexcept
Pointeur sur la mémoire allouée.
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
Definition Span.h:419
Vecteur 1D de données avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-