Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
RealArrayVariant.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/* RealArrayVariant.cc (C) 2000-2023 */
9/* */
10/* Variant pouvant contenir les types ConstArrayView, Real2 et Real3. */
11/*---------------------------------------------------------------------------*/
12
13#include "arcane/datatype/RealArrayVariant.h"
14
15#include "arcane/utils/Array.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/NumVector.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
33void _arcaneTestRealArrayVariant()
34{
35 UniqueArray<Real> a1_({2.4, 5.6, 3.3, 5.4});
36 ConstArrayView<Real> a1 = a1_.constView();
37 Real2 a2{ 2.0, 3.1 };
38 Real3 a3{ 4.0, 7.2, 3.6 };
39
40 const Integer nb_variants = 3;
41 RealArrayVariant variants[nb_variants] = { RealArrayVariant(a1), RealArrayVariant(a2), RealArrayVariant(a3) };
42
43 for (Integer v=0 ; v<nb_variants ; ++v){
44 std::cout << "A" << v << "=[ ";
45 for (Integer i=0 ; i<variants[v].size() ; ++i)
46 std::cout << variants[v][i] << " ";
47 std::cout << "]\n";
48 }
49
50#if defined(ARCANE_HAS_ACCELERATOR_API)
51 NumArray<Real,MDDim1> num_data(4, { 2.4, 5.6, 3.3, 5.4 });
52 RealArrayVariant variant2{num_data};
53 NumArray<Real,MDDim1> num_data_copy(variant2);
54 if (num_data_copy.to1DSpan()!=num_data.to1DSpan())
55 ARCANE_FATAL("Bad value for copy");
56#endif
57
58 RealN2 b2{ 2.0, 3.1 };
59 RealN3 b3{ 4.0, 7.2, 3.6 };
60 NumVector<Real,3> b4{ 2.0, 1.2, 4.6 };
61 RealArrayVariant b2_variant(b2);
62 RealArrayVariant b3_variant(b3);
63 NumVector<Real,2> c2(b2_variant);
64 NumVector<Real,3> c3(b3_variant);
65 auto z = c3 + b4;
66 std::cout << "Z=" << z.vx() << "\n";
67 std::cout << "NORM=" << math::normalizedCrossProduct3(c3,b4).normL2();
68 for (Integer i=0 ; i<3 ; ++i)
69 std::cout << "V=" << i << " v=" << z(i) << "\n";
70}
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75} // End namespace Arcane
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
__host__ __device__ Real normL2() const
Retourne la norme L2 du triplet .
Definition Real3.h:232
Real3 normalizedCrossProduct3(Real3 v1, Real3 v2)
Produit vectoriel normalisé.
Definition MathUtils.h:755
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.