Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
RealArrayVariant.cc
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/* RealArrayVariant.cc (C) 2000-2023 */
9/* */
10/* Variant that can contain the types ConstArrayView, Real2, and 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
20
21#include <iostream>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32extern "C++" ARCANE_CORE_EXPORT void _arcaneTestRealArrayVariant()
33{
34 UniqueArray<Real> a1_({ 2.4, 5.6, 3.3, 5.4 });
35 ConstArrayView<Real> a1 = a1_.constView();
36 Real2 a2{ 2.0, 3.1 };
37 Real3 a3{ 4.0, 7.2, 3.6 };
38
39 const Integer nb_variants = 3;
40 RealArrayVariant variants[nb_variants] = { RealArrayVariant(a1), RealArrayVariant(a2), RealArrayVariant(a3) };
41
42 for (Integer v = 0; v < nb_variants; ++v) {
43 std::cout << "A" << v << "=[ ";
44 for (Integer i = 0; i < variants[v].size(); ++i)
45 std::cout << variants[v][i] << " ";
46 std::cout << "]\n";
47 }
48
49#if defined(ARCANE_HAS_ACCELERATOR_API)
50 NumArray<Real, MDDim1> num_data(4, { 2.4, 5.6, 3.3, 5.4 });
51 RealArrayVariant variant2{ num_data };
52 NumArray<Real, MDDim1> num_data_copy(variant2);
53 if (num_data_copy.to1DSpan() != num_data.to1DSpan())
54 ARCANE_FATAL("Bad value for copy");
55#endif
56
57 RealN2 b2{ 2.0, 3.1 };
58 RealN3 b3{ 4.0, 7.2, 3.6 };
59 NumVector<Real, 3> b4{ 2.0, 1.2, 4.6 };
60 RealArrayVariant b2_variant(b2);
61 RealArrayVariant b3_variant(b3);
62 NumVector<Real, 2> c2(b2_variant);
63 NumVector<Real, 3> c3(b3_variant);
64 auto z = c3 + b4;
65 std::cout << "Z=" << z.vx() << "\n";
66 std::cout << "NORM=" << math::normalizedCrossProduct3(c3, b4).normL2();
67 for (Integer i = 0; i < 3; ++i)
68 std::cout << "V=" << i << " v=" << z(i) << "\n";
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74} // End namespace Arcane
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Various mathematical functions.
Constant view of an array of type T.
Multi-dimensional arrays for numerical types accessible on accelerators.
Small fixed-size vector of N numerical data points.
Definition NumVector.h:44
Class managing a 2-dimensional real vector.
Definition Real2.h:122
Class managing a 3-dimensional real vector.
Definition Real3.h:132
__host__ __device__ Real normL2() const
Returns the L2 norm of the triplet $ .
Definition Real3.h:585
1D data vector with value semantics (STL style).
Real3 normalizedCrossProduct3(Real3 v1, Real3 v2)
Normalized cross product.
Definition MathUtils.h:793
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.