From 9d877119cb1ea4805b2f4d3b322d813e4f224f1d Mon Sep 17 00:00:00 2001 From: "dakshina.ilangova" Date: Sat, 8 Mar 2014 19:44:15 +0000 Subject: [PATCH] Added tests for lac/ProductMatrix git-svn-id: https://svn.dealii.org/trunk@32628 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/lac/product_matrix_01.cc | 90 +++++++++++++++++++ tests/lac/product_matrix_01.output | 6 ++ tests/lac/product_matrix_02.cc | 89 +++++++++++++++++++ tests/lac/product_matrix_02.output | 6 ++ tests/lac/product_matrix_03.cc | 88 +++++++++++++++++++ tests/lac/product_matrix_03.output | 6 ++ tests/lac/product_matrix_04.cc | 89 +++++++++++++++++++ tests/lac/product_matrix_04.output | 5 ++ tests/lac/product_matrix_05.cc | 96 ++++++++++++++++++++ tests/lac/product_matrix_05.output | 6 ++ tests/lac/product_matrix_06.cc | 88 +++++++++++++++++++ tests/lac/product_matrix_06.output | 5 ++ tests/lac/product_matrix_07.cc | 96 ++++++++++++++++++++ tests/lac/product_matrix_07.output | 6 ++ tests/lac/product_matrix_08.cc | 135 +++++++++++++++++++++++++++++ tests/lac/product_matrix_08.output | 13 +++ 16 files changed, 824 insertions(+) create mode 100644 tests/lac/product_matrix_01.cc create mode 100644 tests/lac/product_matrix_01.output create mode 100644 tests/lac/product_matrix_02.cc create mode 100644 tests/lac/product_matrix_02.output create mode 100644 tests/lac/product_matrix_03.cc create mode 100644 tests/lac/product_matrix_03.output create mode 100644 tests/lac/product_matrix_04.cc create mode 100644 tests/lac/product_matrix_04.output create mode 100644 tests/lac/product_matrix_05.cc create mode 100644 tests/lac/product_matrix_05.output create mode 100644 tests/lac/product_matrix_06.cc create mode 100644 tests/lac/product_matrix_06.output create mode 100644 tests/lac/product_matrix_07.cc create mode 100644 tests/lac/product_matrix_07.output create mode 100644 tests/lac/product_matrix_08.cc create mode 100644 tests/lac/product_matrix_08.output diff --git a/tests/lac/product_matrix_01.cc b/tests/lac/product_matrix_01.cc new file mode 100644 index 0000000000..683410b10a --- /dev/null +++ b/tests/lac/product_matrix_01.cc @@ -0,0 +1,90 @@ +// --------------------------------------------------------------------- +// $Id: product_matrix_01.cc 32491 2014-02-14 20:52:51Z bangerth $ +// +// 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. +// +// --------------------------------------------------------------------- + +// Check ProductMatrix::constructor1 + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include +#include + +template + void + checkConstructor1(FullMatrix &A, FullMatrix &B) + { + deallog << "Init with empty constructor" << std::endl; + GrowingVectorMemory < Vector > mem; + ProductMatrix < Vector > P; + P.initialize(A, B, mem); + + deallog << "Multiplying with all ones vector" << std::endl; + Vector V(B.n()); + for (unsigned int i = 0; i < V.size(); ++i) + V(i) = 1; + + Vector O(A.m()); + + P.vmult(O, V); + + // Check the dimensions of the result matrix + Assert(A.m() == O.size(), ExcInternalError()); + deallog << "Dimensions of result vector verified" << std::endl; + + // Verifying results with Method 2: O=(A*B)*V + FullMatrix AB_Product(A.m(), B.n()); + Vector O_(A.m()); + + A.mmult(AB_Product, B, false); + AB_Product.vmult(O_, V); + + Assert(O == O_, ExcInternalError()); + deallog << "Result vector data verified" << std::endl; + + for (unsigned int i = 0; i < O.size(); ++i) + deallog << O(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + const double Adata[] = + { 2, 3, 4, 5 }; + + const double Bdata[] = + { 0, 1, 2, 3 }; + + FullMatrix A(2, 2); + FullMatrix B(2, 2); + + A.fill(Adata); + B.fill(Bdata); + + checkConstructor1(A, B); + +} diff --git a/tests/lac/product_matrix_01.output b/tests/lac/product_matrix_01.output new file mode 100644 index 0000000000..33dd94a27a --- /dev/null +++ b/tests/lac/product_matrix_01.output @@ -0,0 +1,6 @@ + +DEAL::Init with empty constructor +DEAL::Multiplying with all ones vector +DEAL::Dimensions of result vector verified +DEAL::Result vector data verified +DEAL::17.0000 29.0000 diff --git a/tests/lac/product_matrix_02.cc b/tests/lac/product_matrix_02.cc new file mode 100644 index 0000000000..5fdc7b893e --- /dev/null +++ b/tests/lac/product_matrix_02.cc @@ -0,0 +1,89 @@ +// --------------------------------------------------------------------- +// $Id: product_matrix_01.cc 32491 2014-02-14 20:52:51Z bangerth $ +// +// 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. +// +// --------------------------------------------------------------------- + +// Check ProductMatrix::constructor2 + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include +#include + +template + void + checkConstructor2(FullMatrix &A, FullMatrix &B) + { + deallog << "Init with vector memory. Delayed reinit" << std::endl; + GrowingVectorMemory < Vector > mem; + ProductMatrix < Vector > P(mem); + P.reinit(A, B); + + deallog << "Multiplying with all ones vector" << std::endl; + Vector V(B.n()); + for (unsigned int i = 0; i < V.size(); ++i) + V(i) = 1; + Vector O(A.m()); + + P.vmult(O, V); + + // Check the dimensions of the result matrix + Assert(A.m() == O.size(), ExcInternalError()); + deallog << "Dimensions of result vector verified" << std::endl; + + // Verifying results with Method 2: O=(A*B)*V + FullMatrix AB_Product(A.m(), B.n()); + Vector O_(A.m()); + + A.mmult(AB_Product, B, false); + AB_Product.vmult(O_, V); + + Assert(O == O_, ExcInternalError()); + deallog << "Result vector data verified" << std::endl; + + for (unsigned int i = 0; i < O.size(); ++i) + deallog << O(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + const double Adata[] = + { 2, 3, 4, 5 }; + + const double Bdata[] = + { 0, 1, 2, 3 }; + + FullMatrix A(2, 2); + FullMatrix B(2, 2); + + A.fill(Adata); + B.fill(Bdata); + + checkConstructor2(A, B); + +} diff --git a/tests/lac/product_matrix_02.output b/tests/lac/product_matrix_02.output new file mode 100644 index 0000000000..26b5a6b223 --- /dev/null +++ b/tests/lac/product_matrix_02.output @@ -0,0 +1,6 @@ + +DEAL::Init with vector memory. Delayed reinit +DEAL::Multiplying with all ones vector +DEAL::Dimensions of result vector verified +DEAL::Result vector data verified +DEAL::17.0000 29.0000 diff --git a/tests/lac/product_matrix_03.cc b/tests/lac/product_matrix_03.cc new file mode 100644 index 0000000000..13dc09ed5c --- /dev/null +++ b/tests/lac/product_matrix_03.cc @@ -0,0 +1,88 @@ +// --------------------------------------------------------------------- +// $Id: product_matrix_01.cc 32491 2014-02-14 20:52:51Z bangerth $ +// +// 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. +// +// --------------------------------------------------------------------- + +// Check ProductMatrix::constructor3 + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include +#include + +template + void + checkConstructor3(FullMatrix &A, FullMatrix &B) + { + deallog << "Init with vector memory, matrix 1 and matrix 2" << std::endl; + GrowingVectorMemory < Vector > mem; + ProductMatrix < Vector > P(A, B, mem); + + deallog << "Multiplying with all ones vector" << std::endl; + Vector V(B.n()); + for (unsigned int i = 0; i < V.size(); ++i) + V(i) = 1; + Vector O(A.m()); + + P.vmult(O, V); + + // Check the dimensions of the result matrix + Assert(A.m() == O.size(), ExcInternalError()); + deallog << "Dimensions of result vector verified" << std::endl; + + // Verifying results with Method 2: O=(A*B)*V + FullMatrix AB_Product(A.m(), B.n()); + Vector O_(A.m()); + + A.mmult(AB_Product, B, false); + AB_Product.vmult(O_, V); + + Assert(O == O_, ExcInternalError()); + deallog << "Result vector data verified" << std::endl; + + for (unsigned int i = 0; i < O.size(); ++i) + deallog << O(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + const double Adata[] = + { 2, 3, 4, 5 }; + + const double Bdata[] = + { 0, 1, 2, 3 }; + + FullMatrix A(2, 2); + FullMatrix B(2, 2); + + A.fill(Adata); + B.fill(Bdata); + + checkConstructor3(A, B); + +} diff --git a/tests/lac/product_matrix_03.output b/tests/lac/product_matrix_03.output new file mode 100644 index 0000000000..096275148e --- /dev/null +++ b/tests/lac/product_matrix_03.output @@ -0,0 +1,6 @@ + +DEAL::Init with vector memory, matrix 1 and matrix 2 +DEAL::Multiplying with all ones vector +DEAL::Dimensions of result vector verified +DEAL::Result vector data verified +DEAL::17.0000 29.0000 diff --git a/tests/lac/product_matrix_04.cc b/tests/lac/product_matrix_04.cc new file mode 100644 index 0000000000..8ab726e92b --- /dev/null +++ b/tests/lac/product_matrix_04.cc @@ -0,0 +1,89 @@ +// --------------------------------------------------------------------- +// $Id: product_matrix_01.cc 32491 2014-02-14 20:52:51Z bangerth $ +// +// 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. +// +// --------------------------------------------------------------------- + +// Check ProductMatrix::vmult + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include +#include + +template + void + checkVmult(FullMatrix &A, FullMatrix &B, Vector &V) + { + deallog << "vmult" << std::endl; + + GrowingVectorMemory < Vector > mem; + ProductMatrix < Vector > P(A, B, mem); + + Vector O(A.m()); + + P.vmult(O, V); + + // Check the dimensions of the result matrix + Assert(A.m() == O.size(), ExcInternalError()); + deallog << "Dimensions of result vector verified" << std::endl; + + // Verifying results with Method 2: O=(A*B)*V + FullMatrix AB_Product(A.m(), B.n()); + Vector O_(A.m()); + + A.mmult(AB_Product, B, false); + AB_Product.vmult(O_, V); + + Assert(O == O_, ExcInternalError()); + deallog << "Result vector data verified" << std::endl; + + for (unsigned int i = 0; i < O.size(); ++i) + deallog << O(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + const double Adata[] = + { 2, 3, 4, 5 }; + + const double Bdata[] = + { 0, 1, 2, 3 }; + + FullMatrix A(2, 2); + FullMatrix B(2, 2); + + A.fill(Adata); + B.fill(Bdata); + + Vector V(2); + V(0) = 1; + V(1) = 2; + + checkVmult(A, B, V); + +} diff --git a/tests/lac/product_matrix_04.output b/tests/lac/product_matrix_04.output new file mode 100644 index 0000000000..a55771472f --- /dev/null +++ b/tests/lac/product_matrix_04.output @@ -0,0 +1,5 @@ + +DEAL::vmult +DEAL::Dimensions of result vector verified +DEAL::Result vector data verified +DEAL::28.0000 48.0000 diff --git a/tests/lac/product_matrix_05.cc b/tests/lac/product_matrix_05.cc new file mode 100644 index 0000000000..0e153518c1 --- /dev/null +++ b/tests/lac/product_matrix_05.cc @@ -0,0 +1,96 @@ +// --------------------------------------------------------------------- +// $Id: product_matrix_01.cc 32491 2014-02-14 20:52:51Z bangerth $ +// +// 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. +// +// --------------------------------------------------------------------- + +// Check ProductMatrix::vmult_add + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include +#include + +template + void + checkVmult_add(FullMatrix &A, FullMatrix &B, + Vector &V) + { + deallog << "vmult_add" << std::endl; + GrowingVectorMemory < Vector > mem; + ProductMatrix < Vector > P(A, B, mem); + + deallog + << "Result vector set to all ones and to be added with product result vector" + << std::endl; + Vector O(V.size()); + for (unsigned int i = 0; i < O.size(); ++i) + O(i) = 1; + + P.vmult_add(O, V); + + // Check the dimensions of the result matrix + Assert(A.m() == O.size(), ExcInternalError()); + deallog << "Dimensions of result vector verified" << std::endl; + + // Verifying results with Method 2: O=(A*B)*V + FullMatrix AB_Product(A.m(), B.n()); + Vector O_(A.m()); + for (unsigned int i = 0; i < O_.size(); ++i) + O_(i) = 1; + + A.mmult(AB_Product, B, false); + AB_Product.vmult_add(O_, V); + + Assert(O == O_, ExcInternalError()); + deallog << "Result vector data verified" << std::endl; + + for (unsigned int i = 0; i < O.size(); ++i) + deallog << O(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + const double Adata[] = + { 2, 3, 4, 5 }; + + const double Bdata[] = + { 0, 1, 2, 3 }; + + FullMatrix A(2, 2); + FullMatrix B(2, 2); + + A.fill(Adata); + B.fill(Bdata); + + Vector V(2); + V(0) = 1; + V(1) = 2; + + checkVmult_add(A, B, V); + +} diff --git a/tests/lac/product_matrix_05.output b/tests/lac/product_matrix_05.output new file mode 100644 index 0000000000..836a996f4d --- /dev/null +++ b/tests/lac/product_matrix_05.output @@ -0,0 +1,6 @@ + +DEAL::vmult_add +DEAL::Result vector set to all ones and to be added with product result vector +DEAL::Dimensions of result vector verified +DEAL::Result vector data verified +DEAL::29.0000 49.0000 diff --git a/tests/lac/product_matrix_06.cc b/tests/lac/product_matrix_06.cc new file mode 100644 index 0000000000..a53732ae5c --- /dev/null +++ b/tests/lac/product_matrix_06.cc @@ -0,0 +1,88 @@ +// --------------------------------------------------------------------- +// $Id: product_matrix_01.cc 32491 2014-02-14 20:52:51Z bangerth $ +// +// 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. +// +// --------------------------------------------------------------------- + +// Check ProductMatrix::Tvmult + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include +#include + +template + void + checkTvmult(FullMatrix &A, FullMatrix &B, Vector &V) + { + deallog << "Tvmult" << std::endl; + GrowingVectorMemory < Vector > mem; + ProductMatrix < Vector > P(A, B, mem); + + Vector O(V.size()); + + P.Tvmult(O, V); + + // Check the dimensions of the result matrix + Assert(A.m() == O.size(), ExcInternalError()); + deallog << "Dimensions of result vector verified" << std::endl; + + // Verifying results with Method 2: O=(A*B)*V + FullMatrix AB_Product(A.m(), B.n()); + Vector O_(A.m()); + + A.mmult(AB_Product, B, false); + AB_Product.Tvmult(O_, V); + + Assert(O == O_, ExcInternalError()); + deallog << "Result vector data verified" << std::endl; + + for (unsigned int i = 0; i < O.size(); ++i) + deallog << O(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + const double Adata[] = + { 2, 3, 4, 5 }; + + const double Bdata[] = + { 0, 1, 2, 3 }; + + FullMatrix A(2, 2); + FullMatrix B(2, 2); + + A.fill(Adata); + B.fill(Bdata); + + Vector V(2); + V(0) = 1; + V(1) = 2; + + checkTvmult(A, B, V); + +} diff --git a/tests/lac/product_matrix_06.output b/tests/lac/product_matrix_06.output new file mode 100644 index 0000000000..beec1ee7ec --- /dev/null +++ b/tests/lac/product_matrix_06.output @@ -0,0 +1,5 @@ + +DEAL::Tvmult +DEAL::Dimensions of result vector verified +DEAL::Result vector data verified +DEAL::26.0000 49.0000 diff --git a/tests/lac/product_matrix_07.cc b/tests/lac/product_matrix_07.cc new file mode 100644 index 0000000000..2301e7372c --- /dev/null +++ b/tests/lac/product_matrix_07.cc @@ -0,0 +1,96 @@ +// --------------------------------------------------------------------- +// $Id: product_matrix_01.cc 32491 2014-02-14 20:52:51Z bangerth $ +// +// 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. +// +// --------------------------------------------------------------------- + +// Check ProductMatrix::Tvmult_add + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include +#include + +template + void + checkTvmult_add(FullMatrix &A, FullMatrix &B, + Vector &V) + { + deallog << "Tvmult_add" << std::endl; + GrowingVectorMemory < Vector > mem; + ProductMatrix < Vector > P(A, B, mem); + + deallog + << "Result vector set to all ones and to be added with product result vector" + << std::endl; + Vector O(V.size()); + for (unsigned int i = 0; i < O.size(); ++i) + O(i) = 1; + + P.Tvmult_add(O, V); + + // Check the dimensions of the result matrix + Assert(A.m() == O.size(), ExcInternalError()); + deallog << "Dimensions of result vector verified" << std::endl; + + // Verifying results with Method 2: O=(A*B)*V + FullMatrix AB_Product(A.m(), B.n()); + Vector O_(A.m()); + for (unsigned int i = 0; i < O_.size(); ++i) + O_(i) = 1; + + A.mmult(AB_Product, B, false); + AB_Product.Tvmult_add(O_, V); + + Assert(O == O_, ExcInternalError()); + deallog << "Result vector data verified" << std::endl; + + for (unsigned int i = 0; i < O.size(); ++i) + deallog << O(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + const double Adata[] = + { 2, 3, 4, 5 }; + + const double Bdata[] = + { 0, 1, 2, 3 }; + + FullMatrix A(2, 2); + FullMatrix B(2, 2); + + A.fill(Adata); + B.fill(Bdata); + + Vector V(2); + V(0) = 1; + V(1) = 2; + + checkTvmult_add(A, B, V); + +} diff --git a/tests/lac/product_matrix_07.output b/tests/lac/product_matrix_07.output new file mode 100644 index 0000000000..3c2323165a --- /dev/null +++ b/tests/lac/product_matrix_07.output @@ -0,0 +1,6 @@ + +DEAL::Tvmult_add +DEAL::Result vector set to all ones and to be added with product result vector +DEAL::Dimensions of result vector verified +DEAL::Result vector data verified +DEAL::27.0000 50.0000 diff --git a/tests/lac/product_matrix_08.cc b/tests/lac/product_matrix_08.cc new file mode 100644 index 0000000000..1e0d194b67 --- /dev/null +++ b/tests/lac/product_matrix_08.cc @@ -0,0 +1,135 @@ +// --------------------------------------------------------------------- +// $Id: product_matrix_01.cc 32491 2014-02-14 20:52:51Z bangerth $ +// +// 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. +// +// --------------------------------------------------------------------- + +// Check ProductMatrix::clear + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include +#include + +template + void + checkClear(FullMatrix &A, FullMatrix &B, + FullMatrix &C, FullMatrix &D) + { + deallog << "clear" << std::endl; + deallog << "Init with vector memory, matrix 1 and matrix 2" << std::endl; + GrowingVectorMemory < Vector > mem; + ProductMatrix < Vector > P(A, B, mem); + + deallog << "Multiplying with all ones vector" << std::endl; + Vector V(B.n()); + for (unsigned int i = 0; i < V.size(); ++i) + V(i) = 1; + + Vector O(A.m()); + + P.vmult(O, V); + + // Check the dimensions of the result vector + Assert(A.m() == O.size(), ExcInternalError()); + deallog << "Dimensions of result vector verified" << std::endl; + + // Verifying results with Method 2: O=(A*B)*V + FullMatrix AB_Product(A.m(), B.n()); + Vector O_(A.m()); + + A.mmult(AB_Product, B, false); + AB_Product.vmult(O_, V); + + Assert(O == O_, ExcInternalError()); + deallog << "Result vector data verified" << std::endl; + + for (unsigned int i = 0; i < O.size(); ++i) + deallog << O(i) << '\t'; + deallog << std::endl; + + deallog << "Clearing product matrix" << std::endl; + P.clear(); + + deallog << "Reinitializing product matrix with matrix 3 and matrix 4" + << std::endl; + P.reinit(C, D); + + deallog << "Multiplying with all ones vector" << std::endl; + Vector _V(D.n()); + for (unsigned int i = 0; i < _V.size(); ++i) + _V(i) = 1; + + Vector _O(C.m()); + + P.vmult(_O, _V); + + // Check the dimensions of the result vector + Assert(C.m() == _O.size(), ExcInternalError()); + deallog << "Dimensions of result vector verified" << std::endl; + + // Verifying results with Method 2: _O=(C*D)*_V + FullMatrix CD_Product(C.m(), D.n()); + Vector _O_(C.m()); + + C.mmult(CD_Product, D, false); + CD_Product.vmult(_O_, _V); + + Assert(_O == _O_, ExcInternalError()); + deallog << "Result vector data verified" << std::endl; + + for (unsigned int i = 0; i < _O.size(); ++i) + deallog << _O(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + const double Adata[] = + { 2, 3, 4, 5 }; + + const double Bdata[] = + { 0, 1, 2, 3 }; + + const double Cdata[] = + { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + const double Ddata[] = + { 10, 11, 12, 13, 14, 15, 16, 17, 18 }; + + FullMatrix A(2, 2); + FullMatrix B(2, 2); + FullMatrix C(3, 3); + FullMatrix D(3, 3); + + A.fill(Adata); + B.fill(Bdata); + C.fill(Cdata); + D.fill(Ddata); + + checkClear(A, B, C, D); + +} diff --git a/tests/lac/product_matrix_08.output b/tests/lac/product_matrix_08.output new file mode 100644 index 0000000000..c0d230975f --- /dev/null +++ b/tests/lac/product_matrix_08.output @@ -0,0 +1,13 @@ + +DEAL::clear +DEAL::Init with vector memory, matrix 1 and matrix 2 +DEAL::Multiplying with all ones vector +DEAL::Dimensions of result vector verified +DEAL::Result vector data verified +DEAL::17.0000 29.0000 +DEAL::Clearing product matrix +DEAL::Reinitializing product matrix with matrix 3 and matrix 4 +DEAL::Multiplying with all ones vector +DEAL::Dimensions of result vector verified +DEAL::Result vector data verified +DEAL::270.0000 648.0000 1026.0000 -- 2.39.5