Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
RealArray2Variant.cc
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/* RealArray2Variant.cc (C) 2000-2023 */
9/* */
10/* Variant pouvant contenir les types ConstArray2View, Real2x2 et Real3x3. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/datatype/RealArray2Variant.h"
15
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/NumMatrix.h"
18
19#include "arcane/MathUtils.h"
20
21#include <iostream>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32extern "C++" ARCANE_CORE_EXPORT void
33_arcaneTestRealArray2Variant()
34{
35 // NOTE: Les dimensions max pour un RealArray2Variant sont 3x3.
36 Real data[4] = {2.4, 5.6,3.3, 4.4};
37 ConstArray2View<Real> a(data, 2, 2);
38 Real2x2 a22{ Real2{ -1.0, -2.5 }, Real2{ -2.0, 3.7 } };
39 Real3x3 a33{ Real3{ -2.1, 3.9, 1.5 }, Real3{ 9.2, 3.4, 2.1 }, Real3{ 7.1, 4.5, 3.2 } };
40
41 const Integer nb_variants = 3;
42 RealArray2Variant variants[nb_variants] = { RealArray2Variant(a), RealArray2Variant(a22), RealArray2Variant(a33) };
43
44 for (Integer v=0 ; v<nb_variants ; ++v) {
45 std::cout << "A" << v << "=[ ";
46 for (Integer i=0 ; i<variants[v].dim1Size() ; ++i) {
47 std::cout << "[ ";
48 for (Integer j=0 ; j<variants[v].dim2Size() ; ++j)
49 std::cout << variants[v][i][j] << " ";
50 std::cout << "]\n";
51 }
52 std::cout << "]\n";
53 }
54
55#if defined(ARCANE_HAS_ACCELERATOR_API)
56 NumArray<Real,MDDim2> num_data(3, 2, {1.4, 2.3, 4.5, 5.7, 2.9 , 6.5 });
57 RealArray2Variant variant2{num_data};
58 NumArray<Real,MDDim2> num_data_copy(variant2);
59 Span<const Real> variant2_span(variant2.data(),variant2.dim1Size()*variant2.dim2Size());
60 std::cout << "NUM_DATA =" << num_data.to1DSpan() << "\n";
61 std::cout << "NUM_DATA_COPY=" << num_data_copy.to1DSpan() << "\n";
62 if (num_data_copy.to1DSpan()!=num_data.to1DSpan())
63 ARCANE_FATAL("Bad value for copy");
64#endif
65
66 RealN2x2 n22(a22);
67 RealN3x3 n33(a33);
68 NumMatrix<Real,3> m33(Real3x3( Real3{ 1.1, 2.9, 3.5 }, Real3{ 2.2, 4.4, 6.1 }, Real3{ -1.1, 2.5, 1.2 } ));
69 RealArray2Variant n22_variant(n22);
70 RealArray2Variant n33_variant(n33);
71 RealN2x2 c22(n22_variant);
72 RealN3x3 c33(n33_variant);
73
74 auto z = m33 + c33;
75 std::cout << "Z=" << z.vx().vx() << "\n";
76 std::cout << "NORM=" << math::matrixDeterminant(math::matrix3x3Prod(z,c33));
77 for (Integer i=0 ; i<3 ; ++i)
78 for (Integer j=0 ; j<3 ; ++j)
79 std::cout << "V1=" << i << " " << j << " v=" << m33(i,j) << "\n";
80 for (Integer i=0 ; i<3 ; ++i){
81 auto lc = m33(i);
82 for (Integer j=0 ; j<3 ; ++j)
83 std::cout << "V2=" << i << " " << j << " v=" << lc(j) << "\n";
84 }
85}
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90} // End namespace Arcane
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
__host__ __device__ Real matrixDeterminant(Real3x3 m)
Calcul du déterminant d'une matrice 3x3.
Definition MathUtils.h:640
Real3x3 matrix3x3Prod(Real3x3 m1, Real3x3 m2)
Multiplication de 2 matrices 3x3.
Definition MathUtils.h:788
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
double Real
Type représentant un réel.
Int32 Integer
Type représentant un entier.