Nektar++
LibUtilities/LinearAlgebra/testNekVector.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestNekVector.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
38#include <boost/test/tools/floating_point_comparison.hpp>
39#include <boost/test/unit_test.hpp>
40
42{
43BOOST_AUTO_TEST_CASE(TestConstructorWithArrayAndUserSpecifiedSize)
44{
45 int nint = 1, nbndry = 1;
47
48 NekDouble buf[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
49 Array<OneD, NekDouble> out(10, buf);
50
51 NekVector<NekDouble> Fint(nint, offset = out + nbndry);
52 BOOST_CHECK_EQUAL(1u, Fint.GetDimension());
53 BOOST_CHECK_EQUAL(2u, Fint[0]);
54
55 NekVector<NekDouble> Vint(nint, offset = out + nbndry, eWrapper);
56 BOOST_CHECK_EQUAL(1u, Vint.GetDimension());
57 BOOST_CHECK_EQUAL(2, Vint[0]);
58
59 NekVector<NekDouble> testVector(4, offset = out + 3, eWrapper);
60 BOOST_CHECK_EQUAL(4u, testVector.GetDimension());
61 BOOST_CHECK_EQUAL(4, testVector[0]);
62 BOOST_CHECK_EQUAL(5, testVector[1]);
63 BOOST_CHECK_EQUAL(6, testVector[2]);
64 BOOST_CHECK_EQUAL(7, testVector[3]);
65
66 testVector[0] = 9.9;
67 BOOST_CHECK_EQUAL(9.9, testVector[0]);
68 BOOST_CHECK_EQUAL(9.9, offset[0]);
69 BOOST_CHECK_EQUAL(9.9, out[3]);
70}
71
72BOOST_AUTO_TEST_CASE(ItemsThatShouldNotCompile)
73{
75 // NekVector<NekDouble> wrapper(test, eWrapper);
76}
77
78BOOST_AUTO_TEST_CASE(TestVectorSubtraction)
79{
80 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0};
81 double rhs_buf[] = {10.0, 11.0, 12.0, 13.0};
82
83 NekVector<double> lhs(4, lhs_buf);
84 NekVector<double> rhs(4, rhs_buf);
85
86 NekVector<double> result = lhs - rhs;
87
88 double expected_result_buf[] = {1.0 - 10.0, 2.0 - 11.0, 3.0 - 12.0,
89 4.0 - 13.0};
90 NekVector<double> expected_result(4, expected_result_buf);
91
92 BOOST_CHECK_EQUAL(expected_result, result);
93}
94
95BOOST_AUTO_TEST_CASE(TestVectorAddition)
96{
97 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0};
98 double rhs_buf[] = {10.0, 11.0, 12.0, 13.0};
99
100 NekVector<double> lhs(4, lhs_buf);
101 NekVector<double> rhs(4, rhs_buf);
102
103 NekVector<double> result = lhs + rhs;
104
105 double expected_result_buf[] = {1.0 + 10.0, 2.0 + 11.0, 3.0 + 12.0,
106 4.0 + 13.0};
107 NekVector<double> expected_result(4, expected_result_buf);
108
109 BOOST_CHECK_EQUAL(expected_result, result);
110}
111
112} // namespace Nektar::VariableSizedNekVectorUnitTests
unsigned int GetDimension() const
Returns the number of dimensions for the point.
Definition: NekVector.cpp:201
BOOST_AUTO_TEST_CASE(TestConstructorWithArrayAndUserSpecifiedSize)
double NekDouble