Commit 6411139a authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

cleanup of datacollectors and some examples

parent f7590a3d
...@@ -3,14 +3,20 @@ dune_add_library("vtktypes" OBJECT ...@@ -3,14 +3,20 @@ dune_add_library("vtktypes" OBJECT
#install headers #install headers
install(FILES install(FILES
defaultvtkfunction.hh
filereader.hh filereader.hh
filewriter.hh filewriter.hh
gridcreator.hh
legacyvtkfunction.hh
vtkfunction.hh vtkfunction.hh
vtklocalfunction.hh
vtklocalfunctioninterface.hh
vtkreader.hh vtkreader.hh
vtkreader.impl.hh vtkreader.impl.hh
vtktypes.hh vtktypes.hh
vtkwriter.hh vtkwriter.hh
vtkwriter.impl.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter)
add_subdirectory(datacollectors)
add_subdirectory(utility) add_subdirectory(utility)
add_subdirectory(writers)
#install headers
install(FILES
continuousdatacollector.hh
datacollectorinterface.hh
discontinuousdatacollector.hh
quadraticdatacollector.hh
spdatacollector.hh
structureddatacollector.hh
unstructureddatacollector.hh
yaspdatacollector.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter/datacollectors)
#pragma once #pragma once
#include <dune/vtk/datacollector.hh> #include "unstructureddatacollector.hh"
namespace Dune { namespace experimental namespace Dune { namespace experimental
{ {
/// Implementation of \ref DataCollector for linear cells, with continuous data. /// Implementation of \ref DataCollector for linear cells, with continuous data.
template <class GridView> template <class GridView>
class DefaultDataCollector class ContinuousDataCollector
: public DataCollectorInterface<GridView, DefaultDataCollector<GridView>> : public UnstructuredDataCollectorInterface<GridView, ContinuousDataCollector<GridView>>
{ {
enum { dim = GridView::dimension }; enum { dim = GridView::dimension };
using Self = DefaultDataCollector; using Self = ContinuousDataCollector;
using Super = DataCollectorInterface<GridView, Self>; using Super = UnstructuredDataCollectorInterface<GridView, Self>;
using Super::gridView_;
public: public:
DefaultDataCollector (GridView const& gridView) ContinuousDataCollector (GridView const& gridView)
: Super(gridView) : Super(gridView)
{} {}
...@@ -31,7 +30,7 @@ public: ...@@ -31,7 +30,7 @@ public:
template <class T> template <class T>
std::vector<T> pointsImpl () const std::vector<T> pointsImpl () const
{ {
std::vector<T> data(this->numPoints() * 3); std::vector<T> data(gridView_.size(dim) * 3);
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
for (auto const& vertex : vertices(gridView_, Partitions::all)) { for (auto const& vertex : vertices(gridView_, Partitions::all)) {
std::size_t idx = 3 * indexSet.index(vertex); std::size_t idx = 3 * indexSet.index(vertex);
...@@ -44,6 +43,12 @@ public: ...@@ -44,6 +43,12 @@ public:
return data; return data;
} }
/// Return number of grid cells
std::uint64_t numCellsImpl () const
{
return gridView_.size(0);
}
/// Return the types, offsets and connectivity of the cells, using the same connectivity as /// Return the types, offsets and connectivity of the cells, using the same connectivity as
/// given by the grid. /// given by the grid.
Cells cellsImpl () const Cells cellsImpl () const
...@@ -56,9 +61,9 @@ public: ...@@ -56,9 +61,9 @@ public:
}); });
Cells cells; Cells cells;
cells.connectivity.reserve(this->numCells() * maxVertices); cells.connectivity.reserve(gridView_.size(0) * maxVertices);
cells.offsets.reserve(this->numCells()); cells.offsets.reserve(gridView_.size(0));
cells.types.reserve(this->numCells()); cells.types.reserve(gridView_.size(0));
std::int64_t old_o = 0; std::int64_t old_o = 0;
for (auto const& c : elements(gridView_, Partitions::all)) { for (auto const& c : elements(gridView_, Partitions::all)) {
...@@ -68,7 +73,6 @@ public: ...@@ -68,7 +73,6 @@ public:
cells.offsets.push_back(old_o += c.subEntities(dim)); cells.offsets.push_back(old_o += c.subEntities(dim));
cells.types.push_back(cellType.type()); cells.types.push_back(cellType.type());
} }
return cells; return cells;
} }
...@@ -76,7 +80,7 @@ public: ...@@ -76,7 +80,7 @@ public:
template <class T, class GlobalFunction> template <class T, class GlobalFunction>
std::vector<T> pointDataImpl (GlobalFunction const& fct) const std::vector<T> pointDataImpl (GlobalFunction const& fct) const
{ {
std::vector<T> data(this->numPoints() * fct.ncomps()); std::vector<T> data(gridView_.size(dim) * fct.ncomps());
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct); auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::all)) { for (auto const& e : elements(gridView_, Partitions::all)) {
...@@ -92,6 +96,9 @@ public: ...@@ -92,6 +96,9 @@ public:
} }
return data; return data;
} }
protected:
using Super::gridView_;
}; };
}} // end namespace Dune::experimental }} // end namespace Dune::experimental
#pragma once #pragma once
#include <algorithm> #include <dune/vtk/vtktypes.hh>
#include <cstdint>
#include <vector>
#include "vtktypes.hh"
namespace Dune { namespace experimental { namespace Dune { namespace experimental {
struct Cells
{
std::vector<std::uint8_t> types;
std::vector<std::int64_t> offsets;
std::vector<std::int64_t> connectivity;
};
template <class GridView, class Derived> template <class GridView, class Derived>
class DataCollectorInterface class DataCollectorInterface
{ {
public: public:
DataCollectorInterface (GridView const& gridView) DataCollectorInterface (GridView const& gridView)
: gridView_(gridView) : gridView_(gridView)
{} {}
/// \brief Return the number of points in the grid
std::uint64_t numPoints () const
{
return asDerived().numPointsImpl();
}
/// \brief Return the number of cells in the grid
std::uint64_t numCells () const
{
return asDerived().numCellsImpl();
}
/// Update the DataCollector on the current GridView /// Update the DataCollector on the current GridView
void update () void update ()
{ {
...@@ -48,6 +24,12 @@ public: ...@@ -48,6 +24,12 @@ public:
return asDerived().ghostLevelImpl(); return asDerived().ghostLevelImpl();
} }
/// \brief Return the number of points in the grid
std::uint64_t numPoints () const
{
return asDerived().numPointsImpl();
}
/// \brief Return a flat vector of point coordinates /// \brief Return a flat vector of point coordinates
/** /**
* All coordinates are extended to 3 components and concatenated. * All coordinates are extended to 3 components and concatenated.
...@@ -61,12 +43,6 @@ public: ...@@ -61,12 +43,6 @@ public:
return asDerived().template pointsImpl<T>(); return asDerived().template pointsImpl<T>();
} }
/// \brief Return cell types, offsets, and connectivity. \see Cells
Cells cells () const
{
return asDerived().cellsImpl();
}
/// \brief Return a flat vector of function values evaluated at the grid points. /// \brief Return a flat vector of function values evaluated at the grid points.
/** /**
* In case of a vector valued function, flat the vector entries: * In case of a vector valued function, flat the vector entries:
...@@ -76,20 +52,19 @@ public: ...@@ -76,20 +52,19 @@ public:
* [fct(p0)_00, fct(p0)_01, fct(p0)_02, fct(p0)_10, fct(p0)_11, fct(p0)_12, fct(p0)_20...] * [fct(p0)_00, fct(p0)_01, fct(p0)_02, fct(p0)_10, fct(p0)_11, fct(p0)_12, fct(p0)_20...]
* where the tensor dimension must be 3x3 (possible extended by 0s) * where the tensor dimension must be 3x3 (possible extended by 0s)
**/ **/
template <class T, class GlobalFunction> template <class T, class VtkFunction>
std::vector<T> pointData (GlobalFunction const& fct) const std::vector<T> pointData (VtkFunction const& fct) const
{ {
return asDerived().template pointDataImpl<T>(fct); return asDerived().template pointDataImpl<T>(fct);
} }
/// \brief Return a flat vector of function values evaluated at the grid cells. \see pointData. /// \brief Return a flat vector of function values evaluated at the grid cells. \see pointData.
template <class T, class GlobalFunction> template <class T, class VtkFunction>
std::vector<T> cellData (GlobalFunction const& fct) const std::vector<T> cellData (VtkFunction const& fct) const
{ {
return asDerived().template cellDataImpl<T>(fct); return asDerived().template cellDataImpl<T>(fct);
} }
protected: // cast to derived type protected: // cast to derived type
Derived& asDerived () Derived& asDerived ()
...@@ -102,13 +77,7 @@ protected: // cast to derived type ...@@ -102,13 +77,7 @@ protected: // cast to derived type
return static_cast<const Derived&>(*this); return static_cast<const Derived&>(*this);
} }
public: // default implementations
protected: // default implementations
std::uint64_t numCellsImpl () const
{
return gridView_.size(0);
}
void updateImpl () void updateImpl ()
{ {
...@@ -121,10 +90,10 @@ protected: // default implementations ...@@ -121,10 +90,10 @@ protected: // default implementations
} }
// Evaluate `fct` in center of cell // Evaluate `fct` in center of cell
template <class T, class GlobalFunction> template <class T, class VtkFunction>
std::vector<T> cellDataImpl (GlobalFunction const& fct) const std::vector<T> cellDataImpl (VtkFunction const& fct) const
{ {
std::vector<T> data(numCells() * fct.ncomps()); std::vector<T> data(gridView_.size(0) * fct.ncomps());
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct); auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::all)) { for (auto const& e : elements(gridView_, Partitions::all)) {
...@@ -138,9 +107,7 @@ protected: // default implementations ...@@ -138,9 +107,7 @@ protected: // default implementations
return data; return data;
} }
protected: protected:
GridView gridView_; GridView gridView_;
}; };
......
#pragma once #pragma once
#include <dune/vtk/datacollector.hh> #include "unstructureddatacollector.hh"
namespace Dune { namespace experimental namespace Dune { namespace experimental
{ {
...@@ -8,20 +8,17 @@ namespace Dune { namespace experimental ...@@ -8,20 +8,17 @@ namespace Dune { namespace experimental
/// Implementation of \ref DataCollector for linear cells, with discontinuous data. /// Implementation of \ref DataCollector for linear cells, with discontinuous data.
template <class GridView> template <class GridView>
class DiscontinuousDataCollector class DiscontinuousDataCollector
: public DataCollectorInterface<GridView, DiscontinuousDataCollector<GridView>> : public UnstructuredDataCollectorInterface<GridView, DiscontinuousDataCollector<GridView>>
{ {
enum { dim = GridView::dimension }; enum { dim = GridView::dimension };
using Self = DiscontinuousDataCollector; using Self = DiscontinuousDataCollector;
using Super = DataCollectorInterface<GridView, Self>; using Super = UnstructuredDataCollectorInterface<GridView, Self>;
using Super::gridView_;
public: public:
DiscontinuousDataCollector (GridView const& gridView) DiscontinuousDataCollector (GridView const& gridView)
: Super(gridView) : Super(gridView)
{ {}
this->update();
}
/// Create an index map the uniquely assignes an index to each pair (element,corner) /// Create an index map the uniquely assignes an index to each pair (element,corner)
void updateImpl () void updateImpl ()
...@@ -47,7 +44,7 @@ public: ...@@ -47,7 +44,7 @@ public:
template <class T> template <class T>
std::vector<T> pointsImpl () const std::vector<T> pointsImpl () const
{ {
std::vector<T> data(this->numPoints() * 3); std::vector<T> data(numPoints_ * 3);
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
for (auto const& element : elements(gridView_, Partitions::interior)) { for (auto const& element : elements(gridView_, Partitions::interior)) {
for (unsigned int i = 0; i < element.subEntities(dim); ++i) { for (unsigned int i = 0; i < element.subEntities(dim); ++i) {
...@@ -62,13 +59,19 @@ public: ...@@ -62,13 +59,19 @@ public:
return data; return data;
} }
/// Return number of grid cells
std::uint64_t numCellsImpl () const
{
return gridView_.size(0);
}
/// Connect the corners of each cell. The leads to a global discontinuous grid /// Connect the corners of each cell. The leads to a global discontinuous grid
Cells cellsImpl () const Cells cellsImpl () const
{ {
Cells cells; Cells cells;
cells.connectivity.reserve(this->numPoints()); cells.connectivity.reserve(numPoints_);
cells.offsets.reserve(this->numCells()); cells.offsets.reserve(gridView_.size(0));
cells.types.reserve(this->numCells()); cells.types.reserve(gridView_.size(0));
std::int64_t old_o = 0; std::int64_t old_o = 0;
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
...@@ -89,7 +92,7 @@ public: ...@@ -89,7 +92,7 @@ public:
template <class T, class GlobalFunction> template <class T, class GlobalFunction>
std::vector<T> pointDataImpl (GlobalFunction const& fct) const std::vector<T> pointDataImpl (GlobalFunction const& fct) const
{ {
std::vector<T> data(this->numPoints() * fct.ncomps()); std::vector<T> data(numPoints_ * fct.ncomps());
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct); auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::interior)) { for (auto const& e : elements(gridView_, Partitions::interior)) {
...@@ -106,7 +109,8 @@ public: ...@@ -106,7 +109,8 @@ public:
return data; return data;
} }
private: protected:
using Super::gridView_;
std::uint64_t numPoints_ = 0; std::uint64_t numPoints_ = 0;
std::vector<std::int64_t> indexMap_; std::vector<std::int64_t> indexMap_;
}; };
......
#pragma once #pragma once
#include <dune/vtk/datacollector.hh> #include "unstructureddatacollector.hh"
namespace Dune { namespace experimental namespace Dune { namespace experimental
{ {
...@@ -8,13 +8,12 @@ namespace Dune { namespace experimental ...@@ -8,13 +8,12 @@ namespace Dune { namespace experimental
/// Implementation of \ref DataCollector for quadratic cells, with continuous data. /// Implementation of \ref DataCollector for quadratic cells, with continuous data.
template <class GridView> template <class GridView>
class QuadraticDataCollector class QuadraticDataCollector
: public DataCollectorInterface<GridView, QuadraticDataCollector<GridView>> : public UnstructuredDataCollectorInterface<GridView, QuadraticDataCollector<GridView>>
{ {
enum { dim = GridView::dimension }; enum { dim = GridView::dimension };
using Self = QuadraticDataCollector; using Self = QuadraticDataCollector;
using Super = DataCollectorInterface<GridView, Self>; using Super = UnstructuredDataCollectorInterface<GridView, Self>;
using Super::gridView_;
public: public:
QuadraticDataCollector (GridView const& gridView) QuadraticDataCollector (GridView const& gridView)
...@@ -63,6 +62,12 @@ public: ...@@ -63,6 +62,12 @@ public:
return data; return data;
} }
/// Return number of grid cells
std::uint64_t numCellsImpl () const
{
return gridView_.size(0);
}
/// \brief Return cell types, offsets, and connectivity. \see Cells /// \brief Return cell types, offsets, and connectivity. \see Cells
/** /**
* The cell connectivity is composed of cell vertices first and second cell edges, * The cell connectivity is composed of cell vertices first and second cell edges,
...@@ -92,7 +97,6 @@ public: ...@@ -92,7 +97,6 @@ public:
cells.offsets.push_back(old_o += c.subEntities(dim)+c.subEntities(dim-1)); cells.offsets.push_back(old_o += c.subEntities(dim)+c.subEntities(dim-1));
cells.types.push_back(cellType.type()); cells.types.push_back(cellType.type());
} }
return cells; return cells;
} }
...@@ -123,6 +127,9 @@ public: ...@@ -123,6 +127,9 @@ public:
} }
return data; return data;
} }
protected:
using Super::gridView_;
}; };
}} // end namespace Dune::extensions }} // end namespace Dune::extensions
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
#if HAVE_DUNE_SPGRID #if HAVE_DUNE_SPGRID
#include <dune/grid/spgrid.hh> #include <dune/grid/spgrid.hh>
#endif #endif
#include <dune/vtk/datacollectors/structureddatacollector.hh>
#include "structureddatacollector.hh"
namespace Dune { namespace experimental namespace Dune { namespace experimental
{ {
...@@ -18,7 +19,6 @@ class SPDataCollector ...@@ -18,7 +19,6 @@ class SPDataCollector
using Self = SPDataCollector; using Self = SPDataCollector;
using Super = StructuredDataCollectorInterface<GridView, Self>; using Super = StructuredDataCollectorInterface<GridView, Self>;
using Super::gridView_;
using ctype = typename GridView::ctype; using ctype = typename GridView::ctype;
public: public:
...@@ -69,7 +69,8 @@ public: ...@@ -69,7 +69,8 @@ public:
} }
} }
private: protected:
using Super::gridView_;
std::array<int, 6> wholeExtent_; std::array<int, 6> wholeExtent_;
std::array<int, 6> extent_; std::array<int, 6> extent_;
FieldVector<ctype,3> spacing_; FieldVector<ctype,3> spacing_;
......
#pragma once #pragma once
#include <dune/vtk/datacollectors/continuousdatacollector.hh> #include <array>
#include <dune/common/fvector.hh>
#include "continuousdatacollector.hh"
namespace Dune { namespace experimental namespace Dune { namespace experimental
{ {
...@@ -23,14 +26,13 @@ class StructuredDataCollectorInterface ...@@ -23,14 +26,13 @@ class StructuredDataCollectorInterface
{ {
protected: protected: