diff --git a/dune/vtk/datacollectors/spdatacollector.hh b/dune/vtk/datacollectors/spdatacollector.hh index 14283856eb337b12e65c6663070d3fd6b8d61b4e..f70cf553de1ae9fa6df143d828c2f508268c20c5 100644 --- a/dune/vtk/datacollectors/spdatacollector.hh +++ b/dune/vtk/datacollectors/spdatacollector.hh @@ -97,6 +97,14 @@ private: std::vector<std::size_t> indexMap_; }; -#endif +namespace Impl +{ + template<class GridView, class ct, int dim, template< int > class Ref, class Comm> + struct StructuredDataCollector<GridView, SPGrid<ct,dim,Ref,Comm>> + { + using type = SPDataCollector<GridView>; + }; +} +#endif // HAVE_DUNE_SPGRID }} // end namespace Dune::experimental diff --git a/dune/vtk/datacollectors/structureddatacollector.hh b/dune/vtk/datacollectors/structureddatacollector.hh index 667696f8f103275edda9fd28f13d6cc6bc249461..7dc731685e1af382bc8496a36b2b23a377e7899f 100644 --- a/dune/vtk/datacollectors/structureddatacollector.hh +++ b/dune/vtk/datacollectors/structureddatacollector.hh @@ -4,6 +4,19 @@ namespace Dune { namespace experimental { + +namespace Impl +{ + // Should be specialized for concrete structured grid + template <class GridView, class Grid> + struct StructuredDataCollector; +} + +template <class GridView> +using StructuredDataCollector = typename Impl::StructuredDataCollector<GridView, typename GridView::Grid>::type; + + +/// The Interface for structured data-collectors template <class GridView, class Derived> class StructuredDataCollectorInterface : public DataCollectorInterface<GridView, Derived> diff --git a/dune/vtk/datacollectors/yaspdatacollector.hh b/dune/vtk/datacollectors/yaspdatacollector.hh index e557941a123417e10fd19f5e35be818e0f6266fe..3a87772b898c4a35017f32b5e0b1e0b31d8ff303 100644 --- a/dune/vtk/datacollectors/yaspdatacollector.hh +++ b/dune/vtk/datacollectors/yaspdatacollector.hh @@ -121,4 +121,13 @@ private: int level_; }; +namespace Impl +{ + template<class GridView, int dim, class Coordinates> + struct StructuredDataCollector<GridView, YaspGrid<dim,Coordinates>> + { + using type = YaspDataCollector<GridView>; + }; +} + }} // end namespace Dune::experimental diff --git a/dune/vtk/vtkimagedatawriter.hh b/dune/vtk/vtkimagedatawriter.hh index 55a1df5eae36f2065ae739b5f64a6fdc229329d4..b1e43457aaefbd2c4d160f8df30f54a8e7f0a14c 100644 --- a/dune/vtk/vtkimagedatawriter.hh +++ b/dune/vtk/vtkimagedatawriter.hh @@ -14,7 +14,7 @@ namespace Dune { namespace experimental { /// File-Writer for VTK .vtu files - template <class GridView, class DataCollector> + template <class GridView, class DataCollector = StructuredDataCollector<GridView>> class VtkImageDataWriter : public VtkWriter<GridView, DataCollector> { diff --git a/dune/vtk/vtkstructuredgridwriter.hh b/dune/vtk/vtkstructuredgridwriter.hh index a3c3b68b20f63eb2d6c33279fd9874648f447bbc..8c3aaa23ff4dd54b92901105392f1ce80b2f5443 100644 --- a/dune/vtk/vtkstructuredgridwriter.hh +++ b/dune/vtk/vtkstructuredgridwriter.hh @@ -9,11 +9,12 @@ #include "vtkfunction.hh" #include "vtktypes.hh" #include "vtkwriter.hh" +#include "datacollectors/structureddatacollector.hh" namespace Dune { namespace experimental { /// File-Writer for VTK .vtu files - template <class GridView, class DataCollector> + template <class GridView, class DataCollector = StructuredDataCollector<GridView>> class VtkStructuredGridWriter : public VtkWriter<GridView, DataCollector> { diff --git a/src/structuredgridwriter.cc b/src/structuredgridwriter.cc index 48afc46ba53b3b23485c8062f2e2e43d6f40904e..b52d6db0f5b36b55355f480bbc89119013667c92 100644 --- a/src/structuredgridwriter.cc +++ b/src/structuredgridwriter.cc @@ -29,63 +29,26 @@ using namespace Dune; using namespace Dune::experimental; using namespace Dune::Functions; -namespace Impl_ -{ - template <class GridView, class Grid> - struct StructuredDataCollector; - -#if HAVE_DUNE_SPGRID - template<class GridView, class ct, int dim, template< int > class Ref, class Comm> - struct StructuredDataCollector<GridView, SPGrid<ct,dim,Ref,Comm>> - { - using type = SPDataCollector<GridView>; - }; -#endif - - template<class GridView, int dim, class Coordinates> - struct StructuredDataCollector<GridView, YaspGrid<dim,Coordinates>> - { - using type = YaspDataCollector<GridView>; - }; -} - -template <class GridView> -using StructuredDataCollector = typename Impl_::StructuredDataCollector<GridView, typename GridView::Grid>::type; - - template <int dim> using int_ = std::integral_constant<int,dim>; template <class GridView> void write(std::string prefix, GridView const& gridView) { - using namespace BasisFactory; - auto basis = makeBasis(gridView, lagrange<1>()); - - std::vector<double> p1function(basis.dimension()); - interpolate(basis, p1function, [](auto const& x) { - return 100*x[0] + 10*x[1] + 1*x[2]; - }); - - auto fct1 = makeDiscreteGlobalBasisFunction<double>(basis, p1function); auto fct2 = makeAnalyticGridViewFunction([](auto const& x) { return std::sin(10*x[0])*std::cos(10*x[1])+std::sin(10*x[2]); }, gridView); { - using Writer = VtkStructuredGridWriter<GridView, StructuredDataCollector<GridView>>; + using Writer = VtkStructuredGridWriter<GridView>; Writer vtkWriter(gridView); - vtkWriter.addPointData(fct1, "p1"); - vtkWriter.addCellData(fct1, "p0"); vtkWriter.addPointData(fct2, "analytic"); vtkWriter.write(prefix + "sg_ascii_float32.vts", Vtk::ASCII); } { - using Writer = VtkImageDataWriter<GridView, StructuredDataCollector<GridView>>; + using Writer = VtkImageDataWriter<GridView>; Writer vtkWriter(gridView); - vtkWriter.addPointData(fct1, "p1"); - vtkWriter.addCellData(fct1, "p0"); vtkWriter.addPointData(fct2, "analytic"); vtkWriter.write(prefix + "id_ascii_float32.vti", Vtk::ASCII); } @@ -98,6 +61,7 @@ void write_yaspgrid(std::integral_constant<int,dim>) FieldVector<double,dim> upperRight; upperRight = 1.0; auto numElements = filledArray<dim,int>(8); GridType grid(upperRight,numElements,0,0); + grid.globalRefine(1); write("yasp_" + std::to_string(dim) + "d_", grid.leafGridView()); } @@ -110,6 +74,7 @@ void write_spgrid(std::integral_constant<int,dim>) FieldVector<double,dim> upperRight; upperRight = 1.0; auto numElements = filledArray<dim,int>(8); GridType grid(SPDomain<double,dim>::unitCube(),numElements); + grid.globalRefine(1); write("sp_" + std::to_string(dim) + "d_", grid.leafGridView()); #endif