Nektar++
TestCombinationRunner.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestCombinationRunner.h
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
35#ifndef NEKTAR_UNIT_TESTS_LIB_UTILITIES_LINEAR_ALGEBRA_TEST_COMBINATION_RUNNER_H
36#define NEKTAR_UNIT_TESTS_LIB_UTILITIES_LINEAR_ALGEBRA_TEST_COMBINATION_RUNNER_H
37
38#include <boost/test/tools/floating_point_comparison.hpp>
39#include <boost/test/unit_test.hpp>
40
41#include <memory>
42
43namespace Nektar
44{
45template <typename LhsScaledInnerMatrixType, typename LhsBlockInnerMatrixType,
46 typename RhsScaledInnerMatrixType, typename RhsBlockInnerMatrixType>
50 ScaledMatrixTag> &l2,
52 BlockMatrixTag> &l3,
55 ScaledMatrixTag> &r2,
57 BlockMatrixTag> &r3,
59{
60 BOOST_CHECK_EQUAL(l1 + r1, result);
61 BOOST_CHECK_EQUAL(l1 + r2, result);
62 BOOST_CHECK_EQUAL(l1 + r3, result);
63 BOOST_CHECK_EQUAL(l2 + r1, result);
64 BOOST_CHECK_EQUAL(l2 + r2, result);
65 BOOST_CHECK_EQUAL(l2 + r3, result);
66 BOOST_CHECK_EQUAL(l3 + r1, result);
67 BOOST_CHECK_EQUAL(l3 + r2, result);
68 BOOST_CHECK_EQUAL(l3 + r3, result);
69}
70
71template <typename LhsScaledInnerMatrixType, typename LhsBlockInnerMatrixType,
72 typename RhsScaledInnerMatrixType, typename RhsBlockInnerMatrixType>
76 ScaledMatrixTag> &l2,
78 BlockMatrixTag> &l3,
81 ScaledMatrixTag> &r2,
83 BlockMatrixTag> &r3,
85{
86 BOOST_CHECK_EQUAL(l1 - r1, result);
87 BOOST_CHECK_EQUAL(l1 - r2, result);
88 BOOST_CHECK_EQUAL(l1 - r3, result);
89 BOOST_CHECK_EQUAL(l2 - r1, result);
90 BOOST_CHECK_EQUAL(l2 - r2, result);
91 BOOST_CHECK_EQUAL(l2 - r3, result);
92 BOOST_CHECK_EQUAL(l3 - r1, result);
93 BOOST_CHECK_EQUAL(l3 - r2, result);
94 BOOST_CHECK_EQUAL(l3 - r3, result);
95}
96
97template <typename NumberType>
99 const NekMatrix<NumberType, StandardMatrixTag> &m1, NumberType scale,
100 unsigned int blockRows, unsigned int blockColumns,
102 ScaledMatrixTag>> &m2,
103 std::shared_ptr<NekMatrix<NekMatrix<NumberType>, BlockMatrixTag>> &m3)
104{
105 NumberType *inner_values = new NumberType[m1.GetStorageSize()];
106 std::transform(
107 m1.begin(), m1.end(), inner_values,
108 std::bind(std::divides<NumberType>(), std::placeholders::_1, scale));
109 MatrixStorage s = m1.GetType();
110
111 std::shared_ptr<NekMatrix<NumberType, StandardMatrixTag>> inner(
113 m1.GetRows(), m1.GetColumns(), inner_values, s,
114 m1.GetNumberOfSubDiagonals(), m1.GetNumberOfSuperDiagonals()));
115 m2 = std::make_shared<
117 scale, inner);
118
119 unsigned int numberOfRows = m1.GetRows() / blockRows;
120 unsigned int numberOfColumns = m1.GetColumns() / blockColumns;
121 m3 = std::make_shared<NekMatrix<NekMatrix<NumberType>, BlockMatrixTag>>(
122 blockRows, blockColumns, numberOfRows, numberOfColumns);
123
124 for (unsigned int blockRow = 0; blockRow < blockRows; ++blockRow)
125 {
126 for (unsigned int blockColumn = 0; blockColumn < blockColumns;
127 ++blockColumn)
128 {
129 std::shared_ptr<NekMatrix<NumberType>> block(
130 new NekMatrix<NumberType>(numberOfRows, numberOfColumns));
131 for (unsigned int i = 0; i < numberOfRows; ++i)
132 {
133 for (unsigned int j = 0; j < numberOfRows; ++j)
134 {
135 (*block)(i, j) = m1(numberOfRows * blockRow + i,
136 numberOfColumns * blockColumn + j);
137 }
138 }
139
140 m3->SetBlock(blockRow, blockColumn, block);
141 }
142 }
143
144 delete[] inner_values;
145}
146} // namespace Nektar
147
148#endif // NEKTAR_UNIT_TESTS_LIB_UTILITIES_LINEAR_ALGEBRA_TEST_COMBINATION_RUNNER_H
void GenerateMatrices(const NekMatrix< NumberType, StandardMatrixTag > &m1, NumberType scale, unsigned int blockRows, unsigned int blockColumns, std::shared_ptr< NekMatrix< NekMatrix< NumberType, StandardMatrixTag >, ScaledMatrixTag > > &m2, std::shared_ptr< NekMatrix< NekMatrix< NumberType >, BlockMatrixTag > > &m3)
void RunAllAddCombinations(const NekMatrix< NekDouble, StandardMatrixTag > &l1, const NekMatrix< NekMatrix< NekDouble, LhsScaledInnerMatrixType >, ScaledMatrixTag > &l2, const NekMatrix< NekMatrix< NekDouble, LhsBlockInnerMatrixType >, BlockMatrixTag > &l3, const NekMatrix< NekDouble, StandardMatrixTag > &r1, const NekMatrix< NekMatrix< NekDouble, RhsScaledInnerMatrixType >, ScaledMatrixTag > &r2, const NekMatrix< NekMatrix< NekDouble, RhsBlockInnerMatrixType >, BlockMatrixTag > &r3, const NekMatrix< NekDouble, StandardMatrixTag > &result)
void RunAllSubCombinations(const NekMatrix< NekDouble, StandardMatrixTag > &l1, const NekMatrix< NekMatrix< NekDouble, LhsScaledInnerMatrixType >, ScaledMatrixTag > &l2, const NekMatrix< NekMatrix< NekDouble, LhsBlockInnerMatrixType >, BlockMatrixTag > &l3, const NekMatrix< NekDouble, StandardMatrixTag > &r1, const NekMatrix< NekMatrix< NekDouble, RhsScaledInnerMatrixType >, ScaledMatrixTag > &r2, const NekMatrix< NekMatrix< NekDouble, RhsBlockInnerMatrixType >, BlockMatrixTag > &r3, const NekMatrix< NekDouble, StandardMatrixTag > &result)