From: dakshina.ilangova Date: Sat, 5 Apr 2014 19:34:33 +0000 (+0000) Subject: Added tests for lac/VectorView X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ef0b962bc6a9f01d545b076a506bb6b0a817633;p=dealii-svn.git Added tests for lac/VectorView git-svn-id: https://svn.dealii.org/trunk@32721 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/lac/vector_view_01.cc b/tests/lac/vector_view_01.cc new file mode 100644 index 0000000000..7e8e80bf08 --- /dev/null +++ b/tests/lac/vector_view_01.cc @@ -0,0 +1,72 @@ +// --------------------------------------------------------------------- +// $Id: vector_view_01.cc 2014-03-14 dilangov $ +// +// Copyright (C) 1998 - 2013 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 VectorView::checkReadOnlyConstructor + +#include "../tests.h" +#include +#include +#include +#include +#include +#include + +template + void + checkReadOnlyConstructor(const Vector &V) + { + deallog << "Read-only constructor" << std::endl; + VectorView VV(V.size(), V.begin()); + + deallog << "Printing Vector" << std::endl; + for (unsigned int i = 0; i < V.size(); ++i) + deallog << V(i) << '\t'; + deallog << std::endl; + + deallog << "Printing VectorView pointing to Vector" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + deallog << VV(i) << '\t'; + deallog << std::endl; + + /* deallog << "Incrementing Vector elements using Read-only handle of VectorView" << std::endl; + deallog << "Function fails beyond this point" << std::endl; + for (unsigned int i=0; i V1(5); + V1(0) = 1; + V1(1) = 2; + V1(2) = 3; + V1(3) = 4; + V1(4) = 5; + + const Vector V2(V1); + + checkReadOnlyConstructor(V2); +} + diff --git a/tests/lac/vector_view_01.output b/tests/lac/vector_view_01.output new file mode 100644 index 0000000000..7ab6f1aa86 --- /dev/null +++ b/tests/lac/vector_view_01.output @@ -0,0 +1,6 @@ + +DEAL::Read-only constructor +DEAL::Printing Vector +DEAL::1.00 2.00 3.00 4.00 5.00 +DEAL::Printing VectorView pointing to Vector +DEAL::1.00 2.00 3.00 4.00 5.00 diff --git a/tests/lac/vector_view_02.cc b/tests/lac/vector_view_02.cc new file mode 100644 index 0000000000..c980ab7b9a --- /dev/null +++ b/tests/lac/vector_view_02.cc @@ -0,0 +1,86 @@ +// --------------------------------------------------------------------- +// $Id: vector_view_01.cc 2014-03-14 dilangov $ +// +// Copyright (C) 1998 - 2013 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 VectorView::checkReinit1 + +#include "../tests.h" +#include +#include +#include +#include +#include +#include + +template + void + checkReinit1(const size_type N, const bool fast = false) + { + deallog << "Reinit with const size and fast" << std::endl; + + deallog + << "Creating Vector of size N+10 and filling with values 1 to N+10" + << std::endl; + + Vector < number > V(N + 10); + for (unsigned int i = 0; i < V.size(); i++) + V(i) = i + 1; + + deallog + << "Creating VectorView of size N+10 pointing to Vector" + << std::endl; + VectorView VV(V.size(), V.begin()); + + deallog << "Printing Vector" << std::endl; + for (unsigned int i = 0; i < V.size(); ++i) + deallog << V(i) << '\t'; + deallog << std::endl; + + deallog << "Printing VectorView pointing to Vector" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + deallog << VV(i) << '\t'; + deallog << std::endl; + + deallog << "Reinit VectorView to size N from N+10 with fast=" + << fast << std::endl; + VV.reinit(N, fast); + + deallog << "Printing Vector" << std::endl; + for (unsigned int i = 0; i < V.size(); ++i) + deallog << V(i) << '\t'; + deallog << std::endl; + + deallog << "Printing VectorView pointing to Vector" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + deallog << VV(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(2); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + checkReinit1(10, false); + checkReinit1(10, true); +} + diff --git a/tests/lac/vector_view_02.output b/tests/lac/vector_view_02.output new file mode 100644 index 0000000000..46a51699ce --- /dev/null +++ b/tests/lac/vector_view_02.output @@ -0,0 +1,25 @@ + +DEAL::Reinit with const size and fast +DEAL::Creating Vector of size N+10 and filling with values 1 to N+10 +DEAL::Creating VectorView of size N+10 pointing to Vector +DEAL::Printing Vector +DEAL::1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00 +DEAL::Printing VectorView pointing to Vector +DEAL::1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00 +DEAL::Reinit VectorView to size N from N+10 with fast=0 +DEAL::Printing Vector +DEAL::0 0 0 0 0 0 0 0 0 0 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00 +DEAL::Printing VectorView pointing to Vector +DEAL::0 0 0 0 0 0 0 0 0 0 +DEAL::Reinit with const size and fast +DEAL::Creating Vector of size N+10 and filling with values 1 to N+10 +DEAL::Creating VectorView of size N+10 pointing to Vector +DEAL::Printing Vector +DEAL::1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00 +DEAL::Printing VectorView pointing to Vector +DEAL::1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00 +DEAL::Reinit VectorView to size N from N+10 with fast=1 +DEAL::Printing Vector +DEAL::1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00 +DEAL::Printing VectorView pointing to Vector +DEAL::1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 diff --git a/tests/lac/vector_view_03.cc b/tests/lac/vector_view_03.cc new file mode 100644 index 0000000000..758e01ec10 --- /dev/null +++ b/tests/lac/vector_view_03.cc @@ -0,0 +1,100 @@ +// --------------------------------------------------------------------- +// $Id: vector_view_01.cc 2014-03-14 dilangov $ +// +// Copyright (C) 1998 - 2013 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 VectorView::checkReinit3 + +#include "../tests.h" +#include +#include +#include +#include +#include +#include + +template + void + checkReinit3(const Vector &V) + { + deallog + << "Reinit a ReadOnly VectorView with const Vector and const size" + << std::endl; + + deallog + << "Creating dummy Vector of size V.size() and filling with zeros" + << std::endl; + + Vector _V(V.size()); + for (unsigned int i = 0; i < _V.size(); i++) + _V(i) = 0; + + deallog << "Creating VectorView pointing to dummy Vector" + << std::endl; + VectorView VV(_V.size(), _V.begin()); + + deallog << "Printing dummy Vector" << std::endl; + for (unsigned int i = 0; i < _V.size(); ++i) + deallog << _V(i) << '\t'; + deallog << std::endl; + + deallog << "Printing VectorView pointing to dummy Vector" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + deallog << VV(i) << '\t'; + deallog << std::endl; + + deallog << "Reinit VectorView to half of Vector" + << std::endl; + VV.reinit(V.size() / 2, V.begin()); + + deallog << "Printing Vector" << std::endl; + for (unsigned int i = 0; i < V.size(); ++i) + deallog << V(i) << '\t'; + deallog << std::endl; + + deallog << "Printing VectorView pointing to half of Vector" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + deallog << VV(i) << '\t'; + deallog << std::endl; + + /* deallog << "Incrementing Vector elements using Read-only handle of VectorView" << std::endl; + deallog << "Function fails beyond this point" << std::endl; + for (unsigned int i=0; i V1(5); + V1(0) = 1; + V1(1) = 2; + V1(2) = 3; + V1(3) = 4; + V1(4) = 5; + + const Vector V2(V1); + + checkReinit3(V2); +} + diff --git a/tests/lac/vector_view_03.output b/tests/lac/vector_view_03.output new file mode 100644 index 0000000000..cfac6a7daf --- /dev/null +++ b/tests/lac/vector_view_03.output @@ -0,0 +1,13 @@ + +DEAL::Reinit a ReadOnly VectorView with const Vector and const size +DEAL::Creating dummy Vector of size V.size() and filling with zeros +DEAL::Creating VectorView pointing to dummy Vector +DEAL::Printing dummy Vector +DEAL::0 0 0 0 0 +DEAL::Printing VectorView pointing to dummy Vector +DEAL::0 0 0 0 0 +DEAL::Reinit VectorView to half of Vector +DEAL::Printing Vector +DEAL::1.00 2.00 3.00 4.00 5.00 +DEAL::Printing VectorView pointing to half of Vector +DEAL::1.00 2.00 diff --git a/tests/lac/vector_view_04.cc b/tests/lac/vector_view_04.cc new file mode 100644 index 0000000000..7ffdf13358 --- /dev/null +++ b/tests/lac/vector_view_04.cc @@ -0,0 +1,104 @@ +// --------------------------------------------------------------------- +// $Id: vector_view_01.cc 2014-03-14 dilangov $ +// +// Copyright (C) 1998 - 2013 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 VectorView::checkReinit2 + +#include "../tests.h" +#include +#include +#include +#include +#include +#include + +template + void + checkReinit2(Vector &V) + { + deallog + << "Reinit a ReadWrite VectorView with Vector and const size" + << std::endl; + + deallog + << "Creating dummy Vector of size V.size() and filling with zeros" + << std::endl; + + Vector _V(V.size()); + for (unsigned int i = 0; i < _V.size(); i++) + _V(i) = 0; + + deallog << "Creating VectorView pointing to dummy Vector" + << std::endl; + VectorView VV(_V.size(), _V.begin()); + + deallog << "Printing dummy Vector" << std::endl; + for (unsigned int i = 0; i < _V.size(); ++i) + deallog << _V(i) << '\t'; + deallog << std::endl; + + deallog << "Printing VectorView pointing to dummy Vector" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + deallog << VV(i) << '\t'; + deallog << std::endl; + + deallog << "Reinit VectorView to half of Vector" + << std::endl; + VV.reinit(V.size() / 2, V.begin()); + + deallog << "Printing Vector" << std::endl; + for (unsigned int i = 0; i < V.size(); ++i) + deallog << V(i) << '\t'; + deallog << std::endl; + + deallog << "Printing VectorView pointing to half of Vector" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + deallog << VV(i) << '\t'; + deallog << std::endl; + + deallog + << "Incrementing Vector elements using Read-write handle of VectorView" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + VV(i) = VV(i) + 1; + + deallog << "Printing modified Vector" << std::endl; + for (unsigned int i = 0; i < V.size(); ++i) + deallog << V(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(2); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + Vector V1(5); + V1(0) = 1; + V1(1) = 2; + V1(2) = 3; + V1(3) = 4; + V1(4) = 5; + + checkReinit2(V1); +} + diff --git a/tests/lac/vector_view_04.output b/tests/lac/vector_view_04.output new file mode 100644 index 0000000000..19d52f0f9a --- /dev/null +++ b/tests/lac/vector_view_04.output @@ -0,0 +1,16 @@ + +DEAL::Reinit a ReadWrite VectorView with Vector and const size +DEAL::Creating dummy Vector of size V.size() and filling with zeros +DEAL::Creating VectorView pointing to dummy Vector +DEAL::Printing dummy Vector +DEAL::0 0 0 0 0 +DEAL::Printing VectorView pointing to dummy Vector +DEAL::0 0 0 0 0 +DEAL::Reinit VectorView to half of Vector +DEAL::Printing Vector +DEAL::1.00 2.00 3.00 4.00 5.00 +DEAL::Printing VectorView pointing to half of Vector +DEAL::1.00 2.00 +DEAL::Incrementing Vector elements using Read-write handle of VectorView +DEAL::Printing modified Vector +DEAL::2.00 3.00 3.00 4.00 5.00 diff --git a/tests/lac/vector_view_05.cc b/tests/lac/vector_view_05.cc new file mode 100644 index 0000000000..7ff1b973a2 --- /dev/null +++ b/tests/lac/vector_view_05.cc @@ -0,0 +1,76 @@ +// --------------------------------------------------------------------- +// $Id: vector_view_01.cc 2014-03-14 dilangov $ +// +// Copyright (C) 1998 - 2013 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 VectorView::checkReadWriteConstructor + +#include "../tests.h" +#include +#include +#include +#include +#include +#include + +template + void + checkReadWriteConstructor(Vector &V) + { + deallog << "Read-write constructor" << std::endl; + VectorView VV(V.size(), V.begin()); + + deallog << "Printing Vector" << std::endl; + for (unsigned int i = 0; i < V.size(); ++i) + deallog << V(i) << '\t'; + deallog << std::endl; + + deallog << "Printing VectorView pointing to Vector" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + deallog << VV(i) << '\t'; + deallog << std::endl; + + deallog + << "Incrementing Vector elements using Read-write handle of VectorView" + << std::endl; + for (unsigned int i = 0; i < VV.size(); ++i) + VV(i) = VV(i) + 1; + + deallog << "Printing modified Vector" << std::endl; + for (unsigned int i = 0; i < V.size(); ++i) + deallog << V(i) << '\t'; + deallog << std::endl; + } + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(2); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + Vector V1(5); + V1(0) = 1; + V1(1) = 2; + V1(2) = 3; + V1(3) = 4; + V1(4) = 5; + + checkReadWriteConstructor(V1); +} + diff --git a/tests/lac/vector_view_05.output b/tests/lac/vector_view_05.output new file mode 100644 index 0000000000..e3fa623e5b --- /dev/null +++ b/tests/lac/vector_view_05.output @@ -0,0 +1,9 @@ + +DEAL::Read-write constructor +DEAL::Printing Vector +DEAL::1.00 2.00 3.00 4.00 5.00 +DEAL::Printing VectorView pointing to Vector +DEAL::1.00 2.00 3.00 4.00 5.00 +DEAL::Incrementing Vector elements using Read-write handle of VectorView +DEAL::Printing modified Vector +DEAL::2.00 3.00 4.00 5.00 6.00