]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Added tests for lac/VectorView
authordakshina.ilangova <dakshina.ilangova@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 5 Apr 2014 19:34:33 +0000 (19:34 +0000)
committerdakshina.ilangova <dakshina.ilangova@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 5 Apr 2014 19:34:33 +0000 (19:34 +0000)
git-svn-id: https://svn.dealii.org/trunk@32721 0785d39b-7218-0410-832d-ea1e28bc413d

tests/lac/vector_view_01.cc [new file with mode: 0644]
tests/lac/vector_view_01.output [new file with mode: 0644]
tests/lac/vector_view_02.cc [new file with mode: 0644]
tests/lac/vector_view_02.output [new file with mode: 0644]
tests/lac/vector_view_03.cc [new file with mode: 0644]
tests/lac/vector_view_03.output [new file with mode: 0644]
tests/lac/vector_view_04.cc [new file with mode: 0644]
tests/lac/vector_view_04.output [new file with mode: 0644]
tests/lac/vector_view_05.cc [new file with mode: 0644]
tests/lac/vector_view_05.output [new file with mode: 0644]

diff --git a/tests/lac/vector_view_01.cc b/tests/lac/vector_view_01.cc
new file mode 100644 (file)
index 0000000..7e8e80b
--- /dev/null
@@ -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 <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/lac/vector_view.h>
+#include <cmath>
+#include <fstream>
+#include <iomanip>
+
+template<typename number>
+  void
+  checkReadOnlyConstructor(const Vector<number> &V)
+  {
+    deallog << "Read-only constructor" << std::endl;
+    VectorView<number> VV(V.size(), V.begin());
+
+    deallog << "Printing Vector<number>" << std::endl;
+    for (unsigned int i = 0; i < V.size(); ++i)
+      deallog << V(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Printing VectorView<number> pointing to Vector<number>"
+        << std::endl;
+    for (unsigned int i = 0; i < VV.size(); ++i)
+      deallog << VV(i) << '\t';
+    deallog << std::endl;
+
+    /* deallog << "Incrementing Vector<number> elements using Read-only handle of VectorView<number>" << std::endl;
+     deallog << "Function fails beyond this point" << std::endl;
+     for (unsigned int i=0; i<VV.size(); ++i)
+     VV(i)=VV(i)+1; */
+  }
+
+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<double> V1(5);
+  V1(0) = 1;
+  V1(1) = 2;
+  V1(2) = 3;
+  V1(3) = 4;
+  V1(4) = 5;
+
+  const Vector<double> V2(V1);
+
+  checkReadOnlyConstructor<double>(V2);
+}
+
diff --git a/tests/lac/vector_view_01.output b/tests/lac/vector_view_01.output
new file mode 100644 (file)
index 0000000..7ab6f1a
--- /dev/null
@@ -0,0 +1,6 @@
+
+DEAL::Read-only constructor
+DEAL::Printing Vector<number>
+DEAL::1.00     2.00    3.00    4.00    5.00    
+DEAL::Printing VectorView<number> pointing to Vector<number>
+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 (file)
index 0000000..c980ab7
--- /dev/null
@@ -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 <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/lac/vector_view.h>
+#include <cmath>
+#include <fstream>
+#include <iomanip>
+
+template<typename number, typename size_type>
+  void
+  checkReinit1(const size_type N, const bool fast = false)
+  {
+    deallog << "Reinit with const size and fast" << std::endl;
+
+    deallog
+        << "Creating Vector<number> 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<number> of size N+10 pointing to Vector<number>"
+        << std::endl;
+    VectorView<number> VV(V.size(), V.begin());
+
+    deallog << "Printing Vector<number>" << std::endl;
+    for (unsigned int i = 0; i < V.size(); ++i)
+      deallog << V(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Printing VectorView<number> pointing to Vector<number>"
+        << std::endl;
+    for (unsigned int i = 0; i < VV.size(); ++i)
+      deallog << VV(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Reinit VectorView<number> to size N from N+10 with fast="
+        << fast << std::endl;
+    VV.reinit(N, fast);
+
+    deallog << "Printing Vector<number>" << std::endl;
+    for (unsigned int i = 0; i < V.size(); ++i)
+      deallog << V(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Printing VectorView<number> pointing to Vector<number>"
+        << 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<double, int>(10, false);
+  checkReinit1<double, int>(10, true);
+}
+
diff --git a/tests/lac/vector_view_02.output b/tests/lac/vector_view_02.output
new file mode 100644 (file)
index 0000000..46a5169
--- /dev/null
@@ -0,0 +1,25 @@
+
+DEAL::Reinit with const size and fast
+DEAL::Creating Vector<number> of size N+10 and filling with values 1 to N+10
+DEAL::Creating VectorView<number> of size N+10 pointing to Vector<number>
+DEAL::Printing Vector<number>
+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<number> pointing to Vector<number>
+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<number> to size N from N+10 with fast=0
+DEAL::Printing Vector<number>
+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<number> pointing to Vector<number>
+DEAL::0        0       0       0       0       0       0       0       0       0       
+DEAL::Reinit with const size and fast
+DEAL::Creating Vector<number> of size N+10 and filling with values 1 to N+10
+DEAL::Creating VectorView<number> of size N+10 pointing to Vector<number>
+DEAL::Printing Vector<number>
+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<number> pointing to Vector<number>
+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<number> to size N from N+10 with fast=1
+DEAL::Printing Vector<number>
+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<number> pointing to Vector<number>
+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 (file)
index 0000000..758e01e
--- /dev/null
@@ -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 <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/lac/vector_view.h>
+#include <cmath>
+#include <fstream>
+#include <iomanip>
+
+template<typename number>
+  void
+  checkReinit3(const Vector<number> &V)
+  {
+    deallog
+        << "Reinit a ReadOnly VectorView<number> with const Vector<number> and const size"
+        << std::endl;
+
+    deallog
+        << "Creating dummy Vector<number> of size V.size() and filling with zeros"
+        << std::endl;
+
+    Vector<number> _V(V.size());
+    for (unsigned int i = 0; i < _V.size(); i++)
+      _V(i) = 0;
+
+    deallog << "Creating VectorView<number> pointing to dummy Vector<number>"
+        << std::endl;
+    VectorView<number> VV(_V.size(), _V.begin());
+
+    deallog << "Printing dummy Vector<number>" << std::endl;
+    for (unsigned int i = 0; i < _V.size(); ++i)
+      deallog << _V(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Printing VectorView<number> pointing to dummy Vector<number>"
+        << std::endl;
+    for (unsigned int i = 0; i < VV.size(); ++i)
+      deallog << VV(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Reinit VectorView<number> to half of Vector<number>"
+        << std::endl;
+    VV.reinit(V.size() / 2, V.begin());
+
+    deallog << "Printing Vector<number>" << std::endl;
+    for (unsigned int i = 0; i < V.size(); ++i)
+      deallog << V(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Printing VectorView<number> pointing to half of Vector<number>"
+        << std::endl;
+    for (unsigned int i = 0; i < VV.size(); ++i)
+      deallog << VV(i) << '\t';
+    deallog << std::endl;
+
+    /* deallog << "Incrementing Vector<number> elements using Read-only handle of VectorView<number>" << std::endl;
+     deallog << "Function fails beyond this point" << std::endl;
+     for (unsigned int i=0; i<VV.size(); ++i)
+     VV(i)=VV(i)+1; */
+  }
+
+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<double> V1(5);
+  V1(0) = 1;
+  V1(1) = 2;
+  V1(2) = 3;
+  V1(3) = 4;
+  V1(4) = 5;
+
+  const Vector<double> V2(V1);
+
+  checkReinit3<double>(V2);
+}
+
diff --git a/tests/lac/vector_view_03.output b/tests/lac/vector_view_03.output
new file mode 100644 (file)
index 0000000..cfac6a7
--- /dev/null
@@ -0,0 +1,13 @@
+
+DEAL::Reinit a ReadOnly VectorView<number> with const Vector<number> and const size
+DEAL::Creating dummy Vector<number> of size V.size() and filling with zeros
+DEAL::Creating VectorView<number> pointing to dummy Vector<number>
+DEAL::Printing dummy Vector<number>
+DEAL::0        0       0       0       0       
+DEAL::Printing VectorView<number> pointing to dummy Vector<number>
+DEAL::0        0       0       0       0       
+DEAL::Reinit VectorView<number> to half of Vector<number>
+DEAL::Printing Vector<number>
+DEAL::1.00     2.00    3.00    4.00    5.00    
+DEAL::Printing VectorView<number> pointing to half of Vector<number>
+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 (file)
index 0000000..7ffdf13
--- /dev/null
@@ -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 <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/lac/vector_view.h>
+#include <cmath>
+#include <fstream>
+#include <iomanip>
+
+template<typename number>
+  void
+  checkReinit2(Vector<number> &V)
+  {
+    deallog
+        << "Reinit a ReadWrite VectorView<number> with Vector<number> and const size"
+        << std::endl;
+
+    deallog
+        << "Creating dummy Vector<number> of size V.size() and filling with zeros"
+        << std::endl;
+
+    Vector<number> _V(V.size());
+    for (unsigned int i = 0; i < _V.size(); i++)
+      _V(i) = 0;
+
+    deallog << "Creating VectorView<number> pointing to dummy Vector<number>"
+        << std::endl;
+    VectorView<number> VV(_V.size(), _V.begin());
+
+    deallog << "Printing dummy Vector<number>" << std::endl;
+    for (unsigned int i = 0; i < _V.size(); ++i)
+      deallog << _V(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Printing VectorView<number> pointing to dummy Vector<number>"
+        << std::endl;
+    for (unsigned int i = 0; i < VV.size(); ++i)
+      deallog << VV(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Reinit VectorView<number> to half of Vector<number>"
+        << std::endl;
+    VV.reinit(V.size() / 2, V.begin());
+
+    deallog << "Printing Vector<number>" << std::endl;
+    for (unsigned int i = 0; i < V.size(); ++i)
+      deallog << V(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Printing VectorView<number> pointing to half of Vector<number>"
+        << std::endl;
+    for (unsigned int i = 0; i < VV.size(); ++i)
+      deallog << VV(i) << '\t';
+    deallog << std::endl;
+
+    deallog
+        << "Incrementing Vector<number> elements using Read-write handle of VectorView<number>"
+        << std::endl;
+    for (unsigned int i = 0; i < VV.size(); ++i)
+      VV(i) = VV(i) + 1;
+
+    deallog << "Printing modified Vector<number>" << 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<double> V1(5);
+  V1(0) = 1;
+  V1(1) = 2;
+  V1(2) = 3;
+  V1(3) = 4;
+  V1(4) = 5;
+
+  checkReinit2<double>(V1);
+}
+
diff --git a/tests/lac/vector_view_04.output b/tests/lac/vector_view_04.output
new file mode 100644 (file)
index 0000000..19d52f0
--- /dev/null
@@ -0,0 +1,16 @@
+
+DEAL::Reinit a ReadWrite VectorView<number> with Vector<number> and const size
+DEAL::Creating dummy Vector<number> of size V.size() and filling with zeros
+DEAL::Creating VectorView<number> pointing to dummy Vector<number>
+DEAL::Printing dummy Vector<number>
+DEAL::0        0       0       0       0       
+DEAL::Printing VectorView<number> pointing to dummy Vector<number>
+DEAL::0        0       0       0       0       
+DEAL::Reinit VectorView<number> to half of Vector<number>
+DEAL::Printing Vector<number>
+DEAL::1.00     2.00    3.00    4.00    5.00    
+DEAL::Printing VectorView<number> pointing to half of Vector<number>
+DEAL::1.00     2.00    
+DEAL::Incrementing Vector<number> elements using Read-write handle of VectorView<number>
+DEAL::Printing modified Vector<number>
+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 (file)
index 0000000..7ff1b97
--- /dev/null
@@ -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 <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/lac/vector_view.h>
+#include <cmath>
+#include <fstream>
+#include <iomanip>
+
+template<typename number>
+  void
+  checkReadWriteConstructor(Vector<number> &V)
+  {
+    deallog << "Read-write constructor" << std::endl;
+    VectorView<number> VV(V.size(), V.begin());
+
+    deallog << "Printing Vector<number>" << std::endl;
+    for (unsigned int i = 0; i < V.size(); ++i)
+      deallog << V(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Printing VectorView<number> pointing to Vector<number>"
+        << std::endl;
+    for (unsigned int i = 0; i < VV.size(); ++i)
+      deallog << VV(i) << '\t';
+    deallog << std::endl;
+
+    deallog
+        << "Incrementing Vector<number> elements using Read-write handle of VectorView<number>"
+        << std::endl;
+    for (unsigned int i = 0; i < VV.size(); ++i)
+      VV(i) = VV(i) + 1;
+
+    deallog << "Printing modified Vector<number>" << 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<double> V1(5);
+  V1(0) = 1;
+  V1(1) = 2;
+  V1(2) = 3;
+  V1(3) = 4;
+  V1(4) = 5;
+
+  checkReadWriteConstructor<double>(V1);
+}
+
diff --git a/tests/lac/vector_view_05.output b/tests/lac/vector_view_05.output
new file mode 100644 (file)
index 0000000..e3fa623
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::Read-write constructor
+DEAL::Printing Vector<number>
+DEAL::1.00     2.00    3.00    4.00    5.00    
+DEAL::Printing VectorView<number> pointing to Vector<number>
+DEAL::1.00     2.00    3.00    4.00    5.00    
+DEAL::Incrementing Vector<number> elements using Read-write handle of VectorView<number>
+DEAL::Printing modified Vector<number>
+DEAL::2.00     3.00    4.00    5.00    6.00    

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.