// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: #include #include #include #include #include #include #include "laplacian.hh" /* "tests" the writeMatrixToMatlabHelper and writeSVGMatrix methods by calling * them for a Laplacian with a given BlockType and writing to cout. * Actual functionality is not tested. */ template void testWriteMatrix(BlockType b=BlockType(0.0)) { typedef Dune::BCRSMatrix Matrix; Matrix A; setupLaplacian(A, 3); A[0][0] += b; writeMatrixToMatlabHelper(A, 0, 0, std::cout); writeSVGMatrix(std::cout, A); } /* uses the writeVectorToMatlab method, filled with dummy data */ template void testWriteVectorToMatlab() { VectorType v; for (unsigned int i = 0; i < v.size(); ++i) { v[i] = i; } Dune::writeVectorToMatlabHelper(v, std::cout); } int main(int argc, char** argv) { /* testing the writeMatrixToMatlabHelper method for BlockType=FieldMatrix with different field_types */ testWriteMatrix >(); testWriteMatrix >(); // testWriteMatrix >(); // commented because setUpLaplacian cannot handle block_types with more rows than cols testWriteMatrix >(); // testWriteMatrix >(); // commented because setUpLaplacian cannot handle block_types with more rows than cols testWriteMatrix >(); testWriteMatrix,1,1> >(Dune::FieldMatrix,1,1>(std::complex(0, 1))); testWriteMatrix,1,2> >(Dune::FieldMatrix,1,2>(std::complex(0, 1))); // testWriteMatrix,2,1> >(); // commented because setUpLaplacian cannot handle block_types with more rows than cols testWriteMatrix,4,7> >(Dune::FieldMatrix,4,7>(std::complex(0, 1))); // testWriteMatrix,7,4> >(); // commented because setUpLaplacian cannot handle block_types with more rows than cols testWriteMatrix,2,2> >(Dune::FieldMatrix,2,2>(std::complex(0, 1))); testWriteMatrix(); testWriteMatrix >(); /* testing the writeMatrixToMatlabHelper method for BlockType=[Diagonal|ScaledIdentity]Matrix with different field_types */ testWriteMatrix >(); testWriteMatrix >(); testWriteMatrix >(); testWriteMatrix >(); testWriteMatrix,1> >(Dune::DiagonalMatrix,1>(std::complex(0,1))); testWriteMatrix,1> >(Dune::ScaledIdentityMatrix,1>(std::complex(0,1))); testWriteMatrix,2> >(Dune::DiagonalMatrix,2>(std::complex(0,1))); testWriteMatrix,2> >(Dune::ScaledIdentityMatrix,2>(std::complex(0,1))); /* testing the writeVectorToMatlabHelper method for FieldVector */ testWriteVectorToMatlab >(); testWriteVectorToMatlab >(); testWriteVectorToMatlab,5> >(); /* testing the writeVectorToMatlabHelper method for BlockVector */ Dune::BlockVector > v1 = {{1.0, 2.0, 3.0}}; Dune::writeVectorToMatlabHelper(v1, std::cout); Dune::BlockVector > > v2 = {{1.0, 2.0}, {3.0, 4.0, 5.0}, {6.0}}; Dune::writeVectorToMatlabHelper(v2, std::cout); /* testing the writeVectorToMatlabHelper method for STL containers */ testWriteVectorToMatlab >(); std::vector v3; v3.push_back(1); v3.push_back(2); Dune::writeVectorToMatlabHelper(v3, std::cout); // Test the printmatrix and printSparseMatrix methods // BCRSMatrix { Dune::BCRSMatrix matrix; setupLaplacian(matrix, 3); Dune::printmatrix(std::cout, matrix, "BCRSMatrix", "--"); Dune::printSparseMatrix(std::cout, matrix, "BCRSMatrix", "--"); } { Dune::BCRSMatrix > matrix; setupLaplacian(matrix, 3); Dune::printmatrix(std::cout, matrix, "BCRSMatrix >", "--"); Dune::printSparseMatrix(std::cout, matrix, "BCRSMatrix >", "--"); } { Dune::BCRSMatrix > matrix; setupLaplacian(matrix, 3); Dune::printSparseMatrix(std::cout, matrix, "BCRSMatrix >", "--"); } { Dune::BCRSMatrix > matrix; setupLaplacian(matrix, 3); Dune::printmatrix(std::cout, matrix, "BCRSMatrix >", "--"); Dune::printSparseMatrix(std::cout, matrix, "BCRSMatrix >", "--"); } // Matrix { Dune::Matrix matrix(3,3); matrix = 0; Dune::printmatrix(std::cout, matrix, "Matrix", "--"); } { Dune::Matrix > matrix(3,3); matrix = 0; Dune::printmatrix(std::cout, matrix, "Matrix >", "--"); } { Dune::Matrix > matrix(3,3); matrix = 0; Dune::printmatrix(std::cout, matrix, "Matrix >", "--"); } }