From 77ee4f9b57db66b73efc279780849a536c116044 Mon Sep 17 00:00:00 2001 From: "Toby D. Young" <tyoung@ippt.pan.pl> Date: Thu, 10 Apr 2014 09:07:37 +0000 Subject: [PATCH] Chexk reinit() and m() and n() do not break. git-svn-id: https://svn.dealii.org/trunk@32755 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/lapack/full_matrix_00.cc | 113 +++++++++++++++++++++++++++++ tests/lapack/full_matrix_00.output | 7 ++ 2 files changed, 120 insertions(+) create mode 100644 tests/lapack/full_matrix_00.cc create mode 100644 tests/lapack/full_matrix_00.output diff --git a/tests/lapack/full_matrix_00.cc b/tests/lapack/full_matrix_00.cc new file mode 100644 index 0000000000..ed28930476 --- /dev/null +++ b/tests/lapack/full_matrix_00.cc @@ -0,0 +1,113 @@ +// --------------------------------------------------------------------- +// $Id: full_matrix_00.cc $ +// +// Copyright (C) 2014 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// Tests reinitialisation of square and rectangle LAPACKFullMatrix + +#include "../tests.h" +#include <deal.II/base/logstream.h> +#include <deal.II/lac/lapack_full_matrix.h> + +#include <fstream> +#include <iostream> + + +void test (const unsigned int size, + const bool reinit_square) +{ + // this test can not currently work with matrices smaller than + // 1\times2. + Assert (size>2, ExcInternalError()); + + // initialise a first matrix with the standard constructor and fill + // it with some numbers + LAPACKFullMatrix<double> M (size, size); + + for (unsigned int i=0; i<size; ++i) + for (unsigned int j=0; j<size; ++j) + M(i,j) = i+2.*j; + + // initialise a second matrix with the standard constructor and fill + // it with some numbers + LAPACKFullMatrix<double> N (size+2, size-2); + + for (unsigned int i=0; i<N.m(); ++i) + for (unsigned int j=0; j<N.n (); ++j) + N(i,j) = i+2.*j; + + // clearly, this should be the case + Assert (N.m () != M.m (), ExcInternalError()); + Assert (N.n () != M.n (), ExcInternalError()); + + // if reinit_square is true, reinitialise the rectangle matrix to a + // square matrix (use reinit (const unsigned int)) + if (reinit_square) + { + // reinitialise the matrix and fill it with some numbers + N.reinit (size); + + for (unsigned int i=0; i<N.m (); ++i) + for (unsigned int j=0; j<N.n (); ++j) + N(i,j) = i+2.*j; + } + + // otherwise reinitialise the rectangle matrix to a square one (use + // reinit (const unsigned int, const unsigned int)) + else + { + // reinitialise the matrix and fill it with some numbers + M.reinit (size+2, size-2); + + for (unsigned int i=0; i<M.m (); ++i) + for (unsigned int j=0; j<M.n (); ++j) + M(i,j) = i+2.*j; + } + + // and now this should be true + Assert (N.m () == M.m (), ExcInternalError()); + Assert (N.n () == M.n (), ExcInternalError()); + + // in fact, this should be true too, so check + for (unsigned int i=0; i<M.m (); ++i) + for (unsigned int j=0; j<M.n (); ++j) + Assert (M(i,j) == N(i,j), ExcInternalError()); + + deallog << "OK" << std::endl; +} + + +int main() +{ + const std::string logname = "output"; + std::ofstream logfile(logname.c_str()); + + logfile.precision(3); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + // Test square matrix initialisation + test (4, true); + test (5, true); + test (6, true); + + // Test rectangle matrix initialisation + test (4, false); + test (5, false); + test (6, false); + + +} diff --git a/tests/lapack/full_matrix_00.output b/tests/lapack/full_matrix_00.output new file mode 100644 index 0000000000..0aa61ff573 --- /dev/null +++ b/tests/lapack/full_matrix_00.output @@ -0,0 +1,7 @@ + +DEAL::OK +DEAL::OK +DEAL::OK +DEAL::OK +DEAL::OK +DEAL::OK -- 2.39.5