Commit 6b0d1620 authored by Stenger, Florian's avatar Stenger, Florian
Browse files

namespace Vtk engulfs all

parent c66bd4cd
dune_add_library("vtktypes" OBJECT dune_add_library("vtktypes" OBJECT
vtktypes.cc) types.cc)
#install headers #install headers
install(FILES install(FILES
...@@ -8,20 +8,22 @@ install(FILES ...@@ -8,20 +8,22 @@ install(FILES
defaultvtkfunction.hh defaultvtkfunction.hh
filereader.hh filereader.hh
filewriter.hh filewriter.hh
forward.hh
gridcreatorinterface.hh
legacyvtkfunction.hh legacyvtkfunction.hh
pvdwriter.hh pvdwriter.hh
pvdwriter.impl.hh pvdwriter.impl.hh
vtkfunction.hh function.hh
vtklocalfunction.hh localfunction.hh
vtklocalfunctioninterface.hh localfunctioninterface.hh
vtkreader.hh reader.hh
vtkreader.impl.hh reader.impl.hh
vtktimeserieswriter.hh timeserieswriter.hh
vtktimeserieswriter.impl.hh timeserieswriter.impl.hh
vtktypes.hh types.hh
vtkwriter.hh writer.hh
vtkwriterinterface.hh writerinterface.hh
vtkwriterinterface.impl.hh writerinterface.impl.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter)
add_subdirectory(datacollectors) add_subdirectory(datacollectors)
......
...@@ -5,130 +5,135 @@ ...@@ -5,130 +5,135 @@
namespace Dune namespace Dune
{ {
/// Base class for data collectors in a CRTP style.
/**
* \tparam GridViewType Model of Dune::GridView
* \tparam Derived Implementation of a concrete DataCollector.
* \tparam Partition Dune::PartitionType [Partitions::InteriorBorder]
**/
template <class GridViewType, class Derived, class Partition>
class DataCollectorInterface
{
public:
/// The partitionset to collect data from
static constexpr auto partition = Partition{};
using GridView = GridViewType;
/// The dimension of the grid
enum { dim = GridView::dimension };
/// The dimension of the world
enum { dow = GridView::dimensionworld };
public:
/// Store a copy of the GridView
DataCollectorInterface (GridView const& gridView)
: gridView_(gridView)
{}
/// Update the DataCollector on the current GridView
void update ()
{
asDerived().updateImpl();
}
/// Return the number of ghost elements
int ghostLevel () const
{
return asDerived().ghostLevelImpl();
}
/// Return the number of cells in (this partition of the) grid namespace Vtk
std::uint64_t numCells () const {
{
return asDerived().numCellsImpl();
}
/// Return the number of points in (this partition of the) grid
std::uint64_t numPoints () const
{
return asDerived().numPointsImpl();
}
/// \brief Return a flat vector of point coordinates
/**
* All coordinates are extended to 3 components and concatenated.
* [p0_x, p0_y, p0_z, p1_x, p1_y, p1_z, ...]
* If the GridView::dimensionworld < 3, the remaining components are
* set to 0
**/
template <class T>
std::vector<T> points () const
{
return asDerived().template pointsImpl<T>();
}
/// \brief Return a flat vector of function values evaluated at the points. /// Base class for data collectors in a CRTP style.
/** /**
* In case of a vector valued function, flat the vector entries: * \tparam GridViewType Model of Dune::GridView
* [fct(p0)_0, fct(p0)_1, fct(p0)_2, fct(p1)_0, ...] * \tparam Derived Implementation of a concrete DataCollector.
* where the vector dimension must be 3 (possible extended by 0s) * \tparam Partition Dune::PartitionType [Partitions::InteriorBorder]
* In case of tensor valued function, flat the tensor row-wise:
* [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)
**/ **/
template <class T, class VtkFunction> template <class GridViewType, class Derived, class Partition>
std::vector<T> pointData (VtkFunction const& fct) const class DataCollectorInterface
{ {
return asDerived().template pointDataImpl<T>(fct); public:
} /// The partitionset to collect data from
static constexpr auto partition = Partition{};
/// \brief Return a flat vector of function values evaluated at the cells in the order of traversal.
/** using GridView = GridViewType;
* \see pointData.
* Note: Cells might be described explicitly by connectivity, offsets, and types, e.g. in /// The dimension of the grid
* an UnstructuredGrid, or might be described implicitly by the grid type, e.g. in enum { dim = GridView::dimension };
* StructuredGrid.
*/ /// The dimension of the world
template <class T, class VtkFunction> enum { dow = GridView::dimensionworld };
std::vector<T> cellData (VtkFunction const& fct) const
{ public:
return asDerived().template cellDataImpl<T>(fct); /// Store a copy of the GridView
} DataCollectorInterface (GridView const& gridView)
: gridView_(gridView)
protected: // cast to derived type {}
Derived& asDerived () /// Update the DataCollector on the current GridView
{ void update ()
return static_cast<Derived&>(*this); {
} asDerived().updateImpl();
}
const Derived& asDerived () const
{ /// Return the number of ghost elements
return static_cast<const Derived&>(*this); int ghostLevel () const
} {
return asDerived().ghostLevelImpl();
public: // default implementations }
void updateImpl () /// Return the number of cells in (this partition of the) grid
{ std::uint64_t numCells () const
/* do nothing */ {
} return asDerived().numCellsImpl();
}
int ghostLevelImpl () const
{ /// Return the number of points in (this partition of the) grid
return gridView_.overlapSize(0); std::uint64_t numPoints () const
} {
return asDerived().numPointsImpl();
// Evaluate `fct` in center of cell. }
template <class T, class VtkFunction>
std::vector<T> cellDataImpl (VtkFunction const& fct) const; /// \brief Return a flat vector of point coordinates
/**
protected: * All coordinates are extended to 3 components and concatenated.
GridView gridView_; * [p0_x, p0_y, p0_z, p1_x, p1_y, p1_z, ...]
}; * If the GridView::dimensionworld < 3, the remaining components are
* set to 0
**/
template <class T>
std::vector<T> points () const
{
return asDerived().template pointsImpl<T>();
}
/// \brief Return a flat vector of function values evaluated at the points.
/**
* In case of a vector valued function, flat the vector entries:
* [fct(p0)_0, fct(p0)_1, fct(p0)_2, fct(p1)_0, ...]
* where the vector dimension must be 3 (possible extended by 0s)
* In case of tensor valued function, flat the tensor row-wise:
* [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)
**/
template <class T, class VtkFunction>
std::vector<T> pointData (VtkFunction const& fct) const
{
return asDerived().template pointDataImpl<T>(fct);
}
/// \brief Return a flat vector of function values evaluated at the cells in the order of traversal.
/**
* \see pointData.
* Note: Cells might be described explicitly by connectivity, offsets, and types, e.g. in
* an UnstructuredGrid, or might be described implicitly by the grid type, e.g. in
* StructuredGrid.
*/
template <class T, class VtkFunction>
std::vector<T> cellData (VtkFunction const& fct) const
{
return asDerived().template cellDataImpl<T>(fct);
}
protected: // cast to derived type
Derived& asDerived ()
{
return static_cast<Derived&>(*this);
}
const Derived& asDerived () const
{
return static_cast<const Derived&>(*this);
}
public: // default implementations
void updateImpl ()
{
/* do nothing */
}
int ghostLevelImpl () const
{
return gridView_.overlapSize(0);
}
// Evaluate `fct` in center of cell.
template <class T, class VtkFunction>
std::vector<T> cellDataImpl (VtkFunction const& fct) const;
protected:
GridView gridView_;
};
} // end namespace Vtk
} // end namespace Dune } // end namespace Dune
#include "datacollectorinterface.impl.hh" #include "datacollectorinterface.impl.hh"
...@@ -2,25 +2,30 @@ ...@@ -2,25 +2,30 @@
#include <dune/geometry/referenceelements.hh> #include <dune/geometry/referenceelements.hh>
namespace Dune { namespace Dune
template <class GV, class D, class P>
template <class T, class VtkFunction>
std::vector<T> DataCollectorInterface<GV,D,P>
::cellDataImpl (VtkFunction const& fct) const
{ {
std::vector<T> data;
data.reserve(this->numCells() * fct.ncomps());
auto localFct = localFunction(fct); namespace Vtk
for (auto const& e : elements(gridView_, partition)) { {
localFct.bind(e);
auto refElem = referenceElement<T,dim>(e.type()); template <class GV, class D, class P>
for (int comp = 0; comp < fct.ncomps(); ++comp) template <class T, class VtkFunction>
data.emplace_back(localFct.evaluate(comp, refElem.position(0,0))); std::vector<T> DataCollectorInterface<GV,D,P>
localFct.unbind(); ::cellDataImpl (VtkFunction const& fct) const
} {
return data; std::vector<T> data;
} data.reserve(this->numCells() * fct.ncomps());
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e);
auto refElem = referenceElement<T,dim>(e.type());
for (int comp = 0; comp < fct.ncomps(); ++comp)
data.emplace_back(localFct.evaluate(comp, refElem.position(0,0)));
localFct.unbind();
}
return data;
}
} // end namespace Vtk
} // end namespace Dune } // end namespace Dune
...@@ -7,140 +7,144 @@ ...@@ -7,140 +7,144 @@
#include <dune/grid/utility/globalindexset.hh> #include <dune/grid/utility/globalindexset.hh>
#include <dune/vtk/forward.hh> #include <dune/vtk/forward.hh>
#include <dune/vtk/vtktypes.hh> #include <dune/vtk/types.hh>
#include "unstructureddatacollector.hh" #include "unstructureddatacollector.hh"
namespace Dune namespace Dune
{ {
/// Implementation of \ref DataCollector for linear cells, with continuous data. namespace Vtk
template <class GridView, class Partition> {
class ContinuousDataCollector
: public UnstructuredDataCollectorInterface<GridView, ContinuousDataCollector<GridView,Partition>, Partition>
{
using Self = ContinuousDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self, Partition>;
public: /// Implementation of \ref DataCollector for linear cells, with continuous data.
using Super::dim; template <class GridView, class Partition>
using Super::partition; class ContinuousDataCollector
: public UnstructuredDataCollectorInterface<GridView, ContinuousDataCollector<GridView,Partition>, Partition>
{
using Self = ContinuousDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self, Partition>;
public:
using Super::dim;
using Super::partition;
public:
ContinuousDataCollector (GridView const& gridView)
: Super(gridView)
{}
/// Collect the vertex indices
void updateImpl ()
{
numPoints_ = 0;
indexMap_.resize(gridView_.size(dim));
auto const& indexSet = gridView_.indexSet();
for (auto const& vertex : vertices(gridView_, partition))
indexMap_[indexSet.index(vertex)] = std::int64_t(numPoints_++);
if (gridView_.comm().size() > 1) {
auto&& e = elements(gridView_, partition);
numCells_ = std::distance(std::begin(e), std::end(e));
} else {
numCells_ = gridView_.size(0);
}
}
public: /// Return number of grid vertices
ContinuousDataCollector (GridView const& gridView) std::uint64_t numPointsImpl () const
: Super(gridView) {
{} return numPoints_;
}
/// Collect the vertex indices /// Return the coordinates of all grid vertices in the order given by the indexSet
void updateImpl () template <class T>
{ std::vector<T> pointsImpl () const
numPoints_ = 0; {
indexMap_.resize(gridView_.size(dim)); std::vector<T> data;
auto const& indexSet = gridView_.indexSet(); data.reserve(numPoints_ * 3);
for (auto const& vertex : vertices(gridView_, partition)) for (auto const& vertex : vertices(gridView_, partition)) {
indexMap_[indexSet.index(vertex)] = std::int64_t(numPoints_++); auto v = vertex.geometry().center();
for (std::size_t j = 0; j < v.size(); ++j)
if (gridView_.comm().size() > 1) { data.emplace_back(v[j]);
auto&& e = elements(gridView_, partition); for (std::size_t j = v.size(); j < 3u; ++j)
numCells_ = std::distance(std::begin(e), std::end(e)); data.emplace_back(0);
} else { }
numCells_ = gridView_.size(0); return data;
} }
}
/// Return number of grid vertices
std::uint64_t numPointsImpl () const
{
return numPoints_;
}
/// Return the coordinates of all grid vertices in the order given by the indexSet /// Return a vector of global unique ids of the points
template <class T> std::vector<std::uint64_t> pointIdsImpl () const
std::vector<T> pointsImpl () const {
{ std::vector<std::uint64_t> data;
std::vector<T> data; data.reserve(numPoints_);
data.reserve(numPoints_ * 3); GlobalIndexSet<GridView> globalIndexSet(gridView_, dim);
for (auto const& vertex : vertices(gridView_, partition)) { for (auto const& vertex : vertices(gridView_, partition)) {
auto v = vertex.geometry().center(); data.emplace_back(globalIndexSet.index(vertex));
for (std::size_t j = 0; j < v.size(); ++j) }
data.emplace_back(v[j]); return data;
for (std::size_t j = v.size(); j < 3u; ++j) }
data.emplace_back(0);
}
return data;
}
/// Return a vector of global unique ids of the points
std::vector<std::uint64_t> pointIdsImpl () const
{
std::vector<std::uint64_t> data;
data.reserve(numPoints_);
GlobalIndexSet<GridView> globalIndexSet(gridView_, dim);
for (auto const& vertex : vertices(gridView_, partition)) {
data.emplace_back(globalIndexSet.index(vertex));
}
return data;
}
/// Return number of grid cells
std::uint64_t numCellsImpl () const
{
return numCells_;
}
/// Return the types, offsets and connectivity of the cells, using the same connectivity as /// Return number of grid cells
/// given by the grid. std::uint64_t numCellsImpl () const
Cells cellsImpl () const {
{ return numCells_;
auto const& indexSet = gridView_.indexSet();
auto types = indexSet.types(0);
int maxVertices = std::accumulate(types.begin(), types.end(), 1, [](int m, GeometryType t) {
auto refElem = referenceElement<double,dim>(t);
return std::max(m, refElem.size(dim));
});
Cells cells;
cells.connectivity.reserve(numCells_ * maxVertices);
cells.offsets.reserve(numCells_);
cells.types.reserve(numCells_);
std::int64_t old_o = 0;
for (auto const& c : elements(gridView_, partition)) {
Vtk::CellType cellType(c.type());
for (unsigned int j = 0; j < c.subEntities(dim); ++j)
cells.connectivity.emplace_back(indexMap_[indexSet.subIndex(c,cellType.permutation(j),dim)]);
cells.offsets.push_back(old_o += c.subEntities(dim));
cells.types.push_back(cellType.type());
}
return cells;
}
/// Evaluate the `fct` at the corners of the elements
template <class T, class GlobalFunction>
std::vector<T> pointDataImpl (GlobalFunction const& fct) const
{
std::vector<T> data(numPoints_ * fct.ncomps());
auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e);
Vtk::CellType cellType{e.type()};
auto refElem = referenceElement(e.geometry());
for (unsigned int j = 0; j < e.subEntities(dim); ++j) {
std::size_t idx = fct.ncomps() * indexMap_[indexSet.subIndex(e,cellType.permutation(j),dim)];
for (int comp = 0; comp < fct.ncomps(); ++comp)
data[idx + comp] = T(localFct.evaluate(comp, refElem.position(cellType.permutation(j),dim)));
} }
localFct.unbind();
}
return data;
}
protected:
using Super::gridView_;
std::uint64_t numPoints_ = 0;
std::uint64_t numCells_ = 0;
std::vector<std::int64_t> indexMap_;
};
/// Return the types, offsets and connectivity of the cells, using the same connectivity as
/// given by the grid.
Cells cellsImpl () const
{
auto const& indexSet = gridView_.indexSet();
auto types = indexSet.types(0);
int maxVertices = std::accumulate(types.begin(), types.end(), 1, [](int m, GeometryType t) {
auto refElem = referenceElement<double,dim>(t);
return std::max(m, refElem.size(dim));
});
Cells cells;
cells.connectivity.reserve(numCells_ * maxVertices);
cells.offsets.reserve(numCells_);
cells.types.reserve(numCells_);
std::int64_t old_o = 0;
for (auto const& c : elements(gridView_, partition)) {
Vtk::CellType cellType(c.type());
for (unsigned int j = 0; j < c.subEntities(dim); ++j)
cells.connectivity.emplace_back(indexMap_[indexSet.subIndex(c,cellType.permutation(j),dim)]);
cells.offsets.push_back(old_o += c.subEntities(dim));
cells.types.push_back(cellType.type());
}
return cells;
}
/// Evaluate the `fct` at the corners of the elements
template <class T, class GlobalFunction>
std::vector<T> pointDataImpl (GlobalFunction const& fct) const
{
std::vector<T> data(numPoints_ * fct.ncomps());
auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e);
Vtk::CellType cellType{e.type()};