From fe853ba78059814010807851c6897d35a4d854fb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carsten=20Gr=C3=A4ser?= <graeser@mi.fu-berlin.de>
Date: Wed, 18 Apr 2012 15:18:57 +0000
Subject: [PATCH] Allow to test with more refinement by command line argument

[[Imported from SVN: r6047]]
---
 dune/solvers/test/obstacletnnmgtest.cc | 39 +++++++++++++++++---------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/dune/solvers/test/obstacletnnmgtest.cc b/dune/solvers/test/obstacletnnmgtest.cc
index b3126ba0..98560c97 100644
--- a/dune/solvers/test/obstacletnnmgtest.cc
+++ b/dune/solvers/test/obstacletnnmgtest.cc
@@ -1,5 +1,8 @@
 #include <config.h>
 
+#include <iostream>
+#include <sstream>
+
 // dune-common includes
 #include <dune/common/bitsetvector.hh>
 
@@ -19,8 +22,6 @@
 
 #include "common.hh"
 
-#define DIMENSION 2
-
 template <class DomainType, class RangeType>
 class ConstantFunction :
     public Dune::VirtualFunction<DomainType, RangeType>
@@ -108,7 +109,7 @@ void solveObstacleProblemByTNNMG(const GridType& grid, const MatrixType& mat, Ve
 
 
 template <class GridType>
-bool checkWithGrid(const GridType& grid)
+bool checkWithGrid(const GridType& grid, const std::string fileName="")
 {
     bool passed = true;
 
@@ -147,9 +148,12 @@ bool checkWithGrid(const GridType& grid)
 
     solveObstacleProblemByTNNMG(grid, A, u, rhs, ignore);
 
-    typename Dune::VTKWriter<GridView> vtkWriter(gridView);
-    vtkWriter.addVertexData(u, "solution");
-    vtkWriter.write("obstacletnnmgtest_solution");
+    if (fileName!="")
+    {
+        typename Dune::VTKWriter<GridView> vtkWriter(gridView);
+        vtkWriter.addVertexData(u, "solution");
+        vtkWriter.write(fileName);
+    }
 
 
     return passed;
@@ -157,7 +161,7 @@ bool checkWithGrid(const GridType& grid)
 
 
 template <int dim>
-bool checkWithYaspGrid(int refine)
+bool checkWithYaspGrid(int refine, const std::string fileName="")
 {
     bool passed = true;
 
@@ -176,7 +180,7 @@ bool checkWithYaspGrid(int refine)
     std::cout << "Number of levels: " << (grid.maxLevel()+1) << std::endl;
     std::cout << "Number of leaf nodes: " << grid.leafView().size(dim) << std::endl;
 
-    passed = passed and checkWithGrid(grid);
+    passed = passed and checkWithGrid(grid, fileName);
 
 
     return passed;
@@ -187,14 +191,23 @@ bool checkWithYaspGrid(int refine)
 
 int main(int argc, char** argv) try
 {
-    static const int dim = DIMENSION;
-
     bool passed(true);
 
 
-    passed = passed and checkWithYaspGrid<1>(15);
-    passed = passed and checkWithYaspGrid<2>(10);
-    passed = passed and checkWithYaspGrid<3>(5);
+    int refine1d = 16;
+    int refine2d = 8;
+    int refine3d = 5;
+
+    if (argc>1)
+        std::istringstream(argv[1]) >> refine1d;
+    if (argc>2)
+        std::istringstream(argv[2]) >> refine2d;
+    if (argc>3)
+        std::istringstream(argv[3]) >> refine3d;
+
+    passed = passed and checkWithYaspGrid<1>(refine1d, "obstacletnnmgtest_yasp_1d_solution");
+    passed = passed and checkWithYaspGrid<2>(refine2d, "obstacletnnmgtest_yasp_2d_solution");
+    passed = passed and checkWithYaspGrid<3>(refine3d, "obstacletnnmgtest_yasp_3d_solution");
 
     return passed ? 0 : 1;
 }
-- 
GitLab