Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
RealArray2Variant.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/* RealArray2Variant.h (C) 2000-2024 */
9/* */
10/* Variant pouvant contenir les types ConstArray2View, Real2x2 et Real3x3. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_DATATYPE_REALARRAY2VARIANT_H
14#define ARCANE_DATATYPE_REALARRAY2VARIANT_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/Array2.h"
19#include "arcane/utils/Array2View.h"
20#include "arcane/utils/Real2x2.h"
21#include "arcane/utils/Real3x3.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 ConstArray2View, Real2x2 et Real3x3.
37 */
39{
40 public:
41
42 static const Integer MAX_DIM1_SIZE = 3;
43 static const Integer MAX_DIM2_SIZE = 3;
44
45 RealArray2Variant() = default;
47 : RealArray2Variant(v.constView())
48 {}
50 {
51 _setValue(v.data(), v.dim1Size(), v.dim2Size());
52 }
54 {
55 _setValue(reinterpret_cast<Real*>(&r), 2, 2);
56 }
58 {
59 _setValue(reinterpret_cast<Real*>(&r), 3, 3);
60 }
61
62#if defined(ARCANE_HAS_ACCELERATOR_API)
63 template<typename LayoutType>
65 : RealArray2Variant(v.mdspan())
66 {}
67 template<typename LayoutType>
69 {
70 _setValue(v.to1DSpan().data(), v.extent0(), v.extent1());
71 }
72 template<typename LayoutType>
74 {
75 _setValue(v.to1DSpan().data(), v.extent0(), v.extent1());
76 }
77#endif
78
79 RealArray2Variant& operator=(const RealArray2Variant& rhs) = default;
81 {
82 _setValue(v.data(), v.dim1Size(), v.dim2Size());
83 return (*this);
84 }
85 RealArray2Variant& operator=(Real2x2 r)
86 {
87 _setValue(reinterpret_cast<Real*>(&r), 2, 2);
88 return (*this);
89 }
90 RealArray2Variant& operator=(Real3x3 r)
91 {
92 _setValue(reinterpret_cast<Real*>(&r), 3, 3);
93 return (*this);
94 }
95
96 Real* operator[](Integer index)
97 {
98 ARCANE_ASSERT(index < m_nb_dim1, ("Index out of range"));
99 return m_value[index];
100 }
101 const Real* operator [](Integer index) const
102 {
103 ARCANE_ASSERT(index < m_nb_dim1, ("Index out of range"));
104 return m_value[index];
105 }
106
107 Real& operator()(Int32 i,Int32 j)
108 {
109 ARCANE_ASSERT(i < m_nb_dim1, ("Index i out of range"));
110 ARCANE_ASSERT(j < m_nb_dim2, ("Index j out of range"));
111 return m_value[i][j];
112 }
113 Real operator()(Int32 i,Int32 j) const
114 {
115 ARCANE_ASSERT(i < m_nb_dim1, ("Index i out of range"));
116 ARCANE_ASSERT(j < m_nb_dim2, ("Index j out of range"));
117 return m_value[i][j];
118 }
119
120 Int32 dim1Size() const { return m_nb_dim1; }
121 Int32 dim2Size() const { return m_nb_dim2; }
122 Real* data() { return reinterpret_cast<Real*>(&m_value[0]); }
123 const Real* data() const { return reinterpret_cast<const Real*>(m_value); }
124 operator ConstArray2View<Real>() const
125 {
126 return ConstArray2View<Real>(data(), m_nb_dim1, m_nb_dim2);
127 }
128 operator Real2x2() const
129 {
130 return Real2x2::fromLines(m_value[0][0], m_value[0][1], m_value[1][0], m_value[1][1]);
131 }
132 operator Real3x3() const
133 {
134 return Real3x3::fromLines(m_value[0][0], m_value[0][1], m_value[0][2],
135 m_value[1][0], m_value[1][1], m_value[1][2],
136 m_value[2][0], m_value[2][1], m_value[2][2]);
137 }
138#if defined(ARCANE_HAS_ACCELERATOR_API)
139 template<typename LayoutType>
140 operator NumArray<Real,MDDim2,LayoutType>() const
141 {
142 NumArray<Real,MDDim2> v(m_nb_dim1,m_nb_dim2);
143 for( Integer i=0, m=m_nb_dim1; i<m; ++i )
144 for( Integer j=0, n=m_nb_dim2; j<n; ++j )
145 v(i,j) = m_value[i][j];
146 return v;
147 }
148#endif
149
150 private:
151
152 Real m_value[MAX_DIM1_SIZE][MAX_DIM2_SIZE];
153 Int32 m_nb_dim1 = 0;
154 Int32 m_nb_dim2 = 0;
155
156 private:
157
158 void _setValue(const Real* v, Integer nb_dim1, Integer nb_dim2)
159 {
160 m_nb_dim1 = nb_dim1;
161 ARCANE_ASSERT(nb_dim1 <= MAX_DIM1_SIZE, ("Dim1 size too large"));
162 m_nb_dim2 = nb_dim2;
163 ARCANE_ASSERT(nb_dim2 <= MAX_DIM2_SIZE, ("Dim2 size too large"));
164 for (Integer i = 0 ; i < nb_dim1; ++i)
165 for (Integer j = 0 ; j < nb_dim2; ++j)
166 m_value[i][j] = v[i * nb_dim2 + j];
167 }
168};
169
170/*---------------------------------------------------------------------------*/
171/*---------------------------------------------------------------------------*/
172
173} // namespace Arcane
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
178#endif
Classe de base des vues multi-dimensionnelles.
Definition MDSpan.h:44
constexpr __host__ __device__ Int32 extent1() const
Valeur de la deuxième dimension.
Definition MDSpan.h:104
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 une matrice de réel de dimension 2x2.
Definition Real2x2.h:53
constexpr __host__ static __device__ Real2x2 fromLines(Real ax, Real bx, Real ay, Real by)
Construit le couple ((ax,bx),(ay,by)).
Definition Real2x2.h:113
Classe gérant une matrice de réel de dimension 3x3.
Definition Real3x3.h:66
constexpr __host__ static __device__ Real3x3 fromLines(Real ax, Real bx, Real cx, Real ay, Real by, Real cy, Real az, Real bz, Real cz)
Construit la matrice ((ax,bx,cx),(ay,by,cy),(az,bz,cz)).
Definition Real3x3.h:139
constexpr const DataType * data() const
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 de données 2D avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-