Nektar++
ScaledMatrixUnitTests.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: ScaledMatrixUnitTests.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: Tests NekMatrix functionality.
32//
33///////////////////////////////////////////////////////////////////////////////
34
36#include <boost/test/tools/floating_point_comparison.hpp>
37#include <boost/test/unit_test.hpp>
38#include <iostream>
39
41{
42BOOST_AUTO_TEST_CASE(TestConstruction)
43{
44 typedef NekMatrix<double> OwnedType;
45 double d[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0,
46 7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
47 std::shared_ptr<OwnedType> o(new OwnedType(3, 4, d));
49 std::shared_ptr<ConstMatrix<double>> m2(
51 std::shared_ptr<NekMatrix<OwnedType, ScaledMatrixTag>> m3(
53
54 BOOST_CHECK_EQUAL(m1.Scale(), 2.0);
55 // BOOST_CHECK_EQUAL(m2->Scale(), 3.0);
56 BOOST_CHECK_EQUAL(m3->Scale(), 0.0);
57
58 BOOST_CHECK_EQUAL(m1.GetOwnedMatrix(), o);
59 // BOOST_CHECK_EQUAL(m2->GetOwnedMatrix(), o);
60 BOOST_CHECK_EQUAL(m3->GetOwnedMatrix(), o);
61}
62
63BOOST_AUTO_TEST_CASE(TestElementAccessScaledMatrix)
64{
65 typedef NekMatrix<double> OwnedType;
66 double d[] = {1.0, 5.0, 9.0, 2.0, 6.0, 10.0,
67 3.0, 7.0, 11.0, 4.0, 8.0, 12.0};
68 std::shared_ptr<OwnedType> o(new OwnedType(3, 4, d));
70 std::shared_ptr<ConstMatrix<double>> m2(
72 std::shared_ptr<NekMatrix<OwnedType, ScaledMatrixTag>> m3(
74
75 BOOST_CHECK_EQUAL(m1(0, 0), 2.0);
76 BOOST_CHECK_EQUAL(m1(0, 1), 4.0);
77 BOOST_CHECK_EQUAL(m1(0, 2), 6.0);
78 BOOST_CHECK_EQUAL(m1(0, 3), 8.0);
79 BOOST_CHECK_EQUAL(m1(1, 0), 10.0);
80 BOOST_CHECK_EQUAL(m1(1, 1), 12.0);
81 BOOST_CHECK_EQUAL(m1(1, 2), 14.0);
82 BOOST_CHECK_EQUAL(m1(1, 3), 16.0);
83 BOOST_CHECK_EQUAL(m1(2, 0), 18.0);
84 BOOST_CHECK_EQUAL(m1(2, 1), 20.0);
85 BOOST_CHECK_EQUAL(m1(2, 2), 22.0);
86 BOOST_CHECK_EQUAL(m1(2, 3), 24.0);
87
88 BOOST_CHECK_EQUAL((*m2)(0, 0), 3.0);
89 BOOST_CHECK_EQUAL((*m2)(0, 1), 6.0);
90 BOOST_CHECK_EQUAL((*m2)(0, 2), 9.0);
91 BOOST_CHECK_EQUAL((*m2)(0, 3), 12.0);
92 BOOST_CHECK_EQUAL((*m2)(1, 0), 15.0);
93 BOOST_CHECK_EQUAL((*m2)(1, 1), 18.0);
94 BOOST_CHECK_EQUAL((*m2)(1, 2), 21.0);
95 BOOST_CHECK_EQUAL((*m2)(1, 3), 24.0);
96 BOOST_CHECK_EQUAL((*m2)(2, 0), 27.0);
97 BOOST_CHECK_EQUAL((*m2)(2, 1), 30.0);
98 BOOST_CHECK_EQUAL((*m2)(2, 2), 33.0);
99 BOOST_CHECK_EQUAL((*m2)(2, 3), 36.0);
100
101 BOOST_CHECK_EQUAL((*m3)(0, 0), 0.0);
102 BOOST_CHECK_EQUAL((*m3)(0, 1), 0.0);
103 BOOST_CHECK_EQUAL((*m3)(0, 2), 0.0);
104 BOOST_CHECK_EQUAL((*m3)(0, 3), 0.0);
105 BOOST_CHECK_EQUAL((*m3)(1, 0), 0.0);
106 BOOST_CHECK_EQUAL((*m3)(1, 1), 0.0);
107 BOOST_CHECK_EQUAL((*m3)(1, 2), 0.0);
108 BOOST_CHECK_EQUAL((*m3)(1, 3), 0.0);
109 BOOST_CHECK_EQUAL((*m3)(2, 0), 0.0);
110 BOOST_CHECK_EQUAL((*m3)(2, 1), 0.0);
111 BOOST_CHECK_EQUAL((*m3)(2, 2), 0.0);
112 BOOST_CHECK_EQUAL((*m3)(2, 3), 0.0);
113}
114
115BOOST_AUTO_TEST_CASE(TestGetNumElements)
116{
117 typedef NekMatrix<double> OwnedType;
118 double d[] = {1.0, 5.0, 9.0, 2.0, 6.0, 10.0,
119 3.0, 7.0, 11.0, 4.0, 8.0, 12.0};
120 std::shared_ptr<OwnedType> o(new OwnedType(3, 4, d));
122 std::shared_ptr<ConstMatrix<double>> m2(
124 std::shared_ptr<NekMatrix<OwnedType, ScaledMatrixTag>> m3(
126
127 BOOST_CHECK_EQUAL(m1.GetStorageSize(), 12);
128 BOOST_CHECK_EQUAL(m2->GetStorageSize(), 12);
129 BOOST_CHECK_EQUAL(m3->GetStorageSize(), 12);
130}
131
132BOOST_AUTO_TEST_CASE(TestGetStorageType)
133{
134 typedef NekMatrix<double> OwnedType;
135 double d[] = {1.0, 5.0, 9.0, 2.0, 6.0, 10.0,
136 3.0, 7.0, 11.0, 4.0, 8.0, 12.0};
137 std::shared_ptr<OwnedType> o(new OwnedType(3, 4, d));
139 std::shared_ptr<ConstMatrix<double>> m2(
141 std::shared_ptr<NekMatrix<OwnedType, ScaledMatrixTag>> m3(
143
144 BOOST_CHECK_EQUAL(m1.GetStorageType(), eFULL);
145 BOOST_CHECK_EQUAL(m2->GetStorageType(), eFULL);
146 BOOST_CHECK_EQUAL(m3->GetStorageType(), eFULL);
147}
148} // namespace Nektar::ScaledMatrixUnitTests
BOOST_AUTO_TEST_CASE(TestDefaultConstructor)
std::vector< double > d(NPUPPER *NPUPPER)