From cd9137e66fcaa8f040d0577a8b922e38089809ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carsten=20Gr=C3=A4ser?= <graeser@mi.fu-berlin.de>
Date: Wed, 21 Jun 2017 13:05:44 +0200
Subject: [PATCH] Extract reusable functionality to header

---
 src/04-gridviews.cc | 55 +-----------------------------------
 src/04-gridviews.hh | 69 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 54 deletions(-)
 create mode 100644 src/04-gridviews.hh

diff --git a/src/04-gridviews.cc b/src/04-gridviews.cc
index 17574cc..911c7a8 100644
--- a/src/04-gridviews.cc
+++ b/src/04-gridviews.cc
@@ -9,7 +9,6 @@
 
 // included standard library headers
 #include <iostream>
-#include <array>
 
 // included dune-common headers
 #include <dune/common/parallel/mpihelper.hh>
@@ -17,64 +16,12 @@
 #include <dune/common/fvector.hh>
 #include <dune/common/stringutility.hh>
 
-// included dune-geometry headers
-#include <dune/geometry/quadraturerules.hh>
-
 // included dune-grid headers
-#include <dune/grid/io/file/vtk/vtkwriter.hh>
-#include <dune/grid/utility/structuredgridfactory.hh>
 #include <dune/grid/yaspgrid.hh>
 #include <dune/grid/uggrid.hh>
 
 // included dune-fu-tutorial headers
-
-
-template<class Grid>
-auto createCubeGrid()
-{
-  static const int dim = Grid::dimension;
-
-  auto lowerLeft = Dune::FieldVector<double,dim>(0);
-  auto upperRight = Dune::FieldVector<double,dim>(1);
-  auto elementsPerDirection = std::array<unsigned int,dim>();
-  for(auto& e : elementsPerDirection)
-    e = 2;
-
-  return Dune::StructuredGridFactory<Grid>::createCubeGrid(lowerLeft, upperRight, elementsPerDirection);
-}
-
-template<class Grid>
-auto createSimplexGrid()
-{
-  static const int dim = Grid::dimension;
-
-  auto lowerLeft = Dune::FieldVector<double,dim>(0);
-  auto upperRight = Dune::FieldVector<double,dim>(1);
-  auto elementsPerDirection = std::array<unsigned int,dim>();
-  for(auto& e : elementsPerDirection)
-    e = 2;
-
-  return Dune::StructuredGridFactory<Grid>::createSimplexGrid(lowerLeft, upperRight, elementsPerDirection);
-}
-
-
-template<class GridView>
-void writeGridView(const GridView& gridView, std::string postFix)
-{
-  Dune::VTKWriter<GridView> vtkWriter(gridView);
-  vtkWriter.write(std::string("04-gridviews-")+postFix);
-}
-
-template<class Grid>
-void writeAllGridViews(const Grid& grid, std::string gridName)
-{
-  for(int level = 0; level <= grid.maxLevel(); ++level)
-    writeGridView(grid.levelGridView(level), Dune::formatString(gridName+"-level-%02d", level));
-  
-  writeGridView(grid.leafGridView(), gridName+"-leaf");
-}
-
-
+#include "04-gridviews.hh"
 
 
 
diff --git a/src/04-gridviews.hh b/src/04-gridviews.hh
new file mode 100644
index 0000000..d30b5e6
--- /dev/null
+++ b/src/04-gridviews.hh
@@ -0,0 +1,69 @@
+// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+// vi: set et ts=4 sw=2 sts=2:
+#ifndef DUNE_FUTUTORIAL_SRC_04GRIDVIEWS_HH
+#define DUNE_FUTUTORIAL_SRC_04GRIDVIEWS_HH
+
+// included standard library headers
+#include <string>
+#include <array>
+
+// included dune-common headers
+#include <dune/common/fvector.hh>
+#include <dune/common/stringutility.hh>
+
+// included dune-grid headers
+#include <dune/grid/io/file/vtk/vtkwriter.hh>
+#include <dune/grid/utility/structuredgridfactory.hh>
+#include <dune/grid/yaspgrid.hh>
+#include <dune/grid/uggrid.hh>
+
+
+
+template<class Grid>
+auto createCubeGrid()
+{
+  static const int dim = Grid::dimension;
+
+  auto lowerLeft = Dune::FieldVector<double,dim>(0);
+  auto upperRight = Dune::FieldVector<double,dim>(1);
+  auto elementsPerDirection = std::array<unsigned int,dim>();
+  for(auto& e : elementsPerDirection)
+    e = 2;
+
+  return Dune::StructuredGridFactory<Grid>::createCubeGrid(lowerLeft, upperRight, elementsPerDirection);
+}
+
+template<class Grid>
+auto createSimplexGrid()
+{
+  static const int dim = Grid::dimension;
+
+  auto lowerLeft = Dune::FieldVector<double,dim>(0);
+  auto upperRight = Dune::FieldVector<double,dim>(1);
+  auto elementsPerDirection = std::array<unsigned int,dim>();
+  for(auto& e : elementsPerDirection)
+    e = 2;
+
+  return Dune::StructuredGridFactory<Grid>::createSimplexGrid(lowerLeft, upperRight, elementsPerDirection);
+}
+
+
+template<class GridView>
+void writeGridView(const GridView& gridView, std::string postFix)
+{
+  Dune::VTKWriter<GridView> vtkWriter(gridView);
+  vtkWriter.write(std::string("04-gridviews-")+postFix);
+}
+
+template<class Grid>
+void writeAllGridViews(const Grid& grid, std::string gridName)
+{
+  for(int level = 0; level <= grid.maxLevel(); ++level)
+    writeGridView(grid.levelGridView(level), Dune::formatString(gridName+"-level-%02d", level));
+  
+  writeGridView(grid.leafGridView(), gridName+"-leaf");
+}
+
+
+
+#endif // DUNE_FUTUTORIAL_SRC_04GRIDVIEWS_HH
-- 
GitLab