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
40namespace Nektar
41{
42namespace ScaledMatrixUnitTests
43{
44BOOST_AUTO_TEST_CASE(TestConstruction)
45{
46 typedef NekMatrix<double> OwnedType;
47 double d[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0,
48 7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
49 std::shared_ptr<OwnedType> o(new OwnedType(3, 4, d));
51 std::shared_ptr<ConstMatrix<double>> m2(
53 std::shared_ptr<NekMatrix<OwnedType, ScaledMatrixTag>> m3(
55
56 BOOST_CHECK_EQUAL(m1.Scale(), 2.0);
57 // BOOST_CHECK_EQUAL(m2->Scale(), 3.0);
58 BOOST_CHECK_EQUAL(m3->Scale(), 0.0);
59
60 BOOST_CHECK_EQUAL(m1.GetOwnedMatrix(), o);
61 // BOOST_CHECK_EQUAL(m2->GetOwnedMatrix(), o);
62 BOOST_CHECK_EQUAL(m3->GetOwnedMatrix(), o);
63}
64
65BOOST_AUTO_TEST_CASE(TestElementAccessScaledMatrix)
66{
67 typedef NekMatrix<double> OwnedType;
68 double d[] = {1.0, 5.0, 9.0, 2.0, 6.0, 10.0,
69 3.0, 7.0, 11.0, 4.0, 8.0, 12.0};
70 std::shared_ptr<OwnedType> o(new OwnedType(3, 4, d));
72 std::shared_ptr<ConstMatrix<double>> m2(
74 std::shared_ptr<NekMatrix<OwnedType, ScaledMatrixTag>> m3(
76
77 BOOST_CHECK_EQUAL(m1(0, 0), 2.0);
78 BOOST_CHECK_EQUAL(m1(0, 1), 4.0);
79 BOOST_CHECK_EQUAL(m1(0, 2), 6.0);
80 BOOST_CHECK_EQUAL(m1(0, 3), 8.0);
81 BOOST_CHECK_EQUAL(m1(1, 0), 10.0);
82 BOOST_CHECK_EQUAL(m1(1, 1), 12.0);
83 BOOST_CHECK_EQUAL(m1(1, 2), 14.0);
84 BOOST_CHECK_EQUAL(m1(1, 3), 16.0);
85 BOOST_CHECK_EQUAL(m1(2, 0), 18.0);
86 BOOST_CHECK_EQUAL(m1(2, 1), 20.0);
87 BOOST_CHECK_EQUAL(m1(2, 2), 22.0);
88 BOOST_CHECK_EQUAL(m1(2, 3), 24.0);
89
90 BOOST_CHECK_EQUAL((*m2)(0, 0), 3.0);
91 BOOST_CHECK_EQUAL((*m2)(0, 1), 6.0);
92 BOOST_CHECK_EQUAL((*m2)(0, 2), 9.0);
93 BOOST_CHECK_EQUAL((*m2)(0, 3), 12.0);
94 BOOST_CHECK_EQUAL((*m2)(1, 0), 15.0);
95 BOOST_CHECK_EQUAL((*m2)(1, 1), 18.0);
96 BOOST_CHECK_EQUAL((*m2)(1, 2), 21.0);
97 BOOST_CHECK_EQUAL((*m2)(1, 3), 24.0);
98 BOOST_CHECK_EQUAL((*m2)(2, 0), 27.0);
99 BOOST_CHECK_EQUAL((*m2)(2, 1), 30.0);
100 BOOST_CHECK_EQUAL((*m2)(2, 2), 33.0);
101 BOOST_CHECK_EQUAL((*m2)(2, 3), 36.0);
102
103 BOOST_CHECK_EQUAL((*m3)(0, 0), 0.0);
104 BOOST_CHECK_EQUAL((*m3)(0, 1), 0.0);
105 BOOST_CHECK_EQUAL((*m3)(0, 2), 0.0);
106 BOOST_CHECK_EQUAL((*m3)(0, 3), 0.0);
107 BOOST_CHECK_EQUAL((*m3)(1, 0), 0.0);
108 BOOST_CHECK_EQUAL((*m3)(1, 1), 0.0);
109 BOOST_CHECK_EQUAL((*m3)(1, 2), 0.0);
110 BOOST_CHECK_EQUAL((*m3)(1, 3), 0.0);
111 BOOST_CHECK_EQUAL((*m3)(2, 0), 0.0);
112 BOOST_CHECK_EQUAL((*m3)(2, 1), 0.0);
113 BOOST_CHECK_EQUAL((*m3)(2, 2), 0.0);
114 BOOST_CHECK_EQUAL((*m3)(2, 3), 0.0);
115}
116
117BOOST_AUTO_TEST_CASE(TestGetNumElements)
118{
119 typedef NekMatrix<double> OwnedType;
120 double d[] = {1.0, 5.0, 9.0, 2.0, 6.0, 10.0,
121 3.0, 7.0, 11.0, 4.0, 8.0, 12.0};
122 std::shared_ptr<OwnedType> o(new OwnedType(3, 4, d));
124 std::shared_ptr<ConstMatrix<double>> m2(
126 std::shared_ptr<NekMatrix<OwnedType, ScaledMatrixTag>> m3(
128
129 BOOST_CHECK_EQUAL(m1.GetStorageSize(), 12);
130 BOOST_CHECK_EQUAL(m2->GetStorageSize(), 12);
131 BOOST_CHECK_EQUAL(m3->GetStorageSize(), 12);
132}
133
134BOOST_AUTO_TEST_CASE(TestGetStorageType)
135{
136 typedef NekMatrix<double> OwnedType;
137 double d[] = {1.0, 5.0, 9.0, 2.0, 6.0, 10.0,
138 3.0, 7.0, 11.0, 4.0, 8.0, 12.0};
139 std::shared_ptr<OwnedType> o(new OwnedType(3, 4, d));
141 std::shared_ptr<ConstMatrix<double>> m2(
143 std::shared_ptr<NekMatrix<OwnedType, ScaledMatrixTag>> m3(
145
146 BOOST_CHECK_EQUAL(m1.GetStorageType(), eFULL);
147 BOOST_CHECK_EQUAL(m2->GetStorageType(), eFULL);
148 BOOST_CHECK_EQUAL(m3->GetStorageType(), eFULL);
149}
150} // namespace ScaledMatrixUnitTests
151} // namespace Nektar
BOOST_AUTO_TEST_CASE(TestDefaultConstructor)
std::vector< double > d(NPUPPER *NPUPPER)
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2