Commit 8d71093c authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'refactoring/namespace-changes' into 'master'

Refactoring/namespace changes

See merge request spraetor/dune-vtk!28
parents 178a7777 a72229fb
dune_add_library("vtktypes" OBJECT
vtktypes.cc)
types.cc)
#install headers
install(FILES
......@@ -8,21 +8,23 @@ install(FILES
defaultvtkfunction.hh
filereader.hh
filewriter.hh
forward.hh
gridcreatorinterface.hh
legacyvtkfunction.hh
pvdwriter.hh
pvdwriter.impl.hh
vtkfunction.hh
vtklocalfunction.hh
vtklocalfunctioninterface.hh
function.hh
localfunction.hh
localfunctioninterface.hh
vtkreader.hh
vtkreader.impl.hh
vtktimeserieswriter.hh
vtktimeserieswriter.impl.hh
vtktypes.hh
types.hh
vtkwriter.hh
vtkwriterinterface.hh
vtkwriterinterface.impl.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter)
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtk)
add_subdirectory(datacollectors)
add_subdirectory(gridcreators)
......
......@@ -5,130 +5,133 @@
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
namespace Vtk
{
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
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:
* [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)
* \tparam GridViewType Model of Dune::GridView
* \tparam Derived Implementation of a concrete DataCollector.
* \tparam Partition Dune::PartitionType [Partitions::InteriorBorder]
**/
template <class T, class VtkFunction>
std::vector<T> pointData (VtkFunction const& fct) const
template <class GridViewType, class Derived, class Partition>
class DataCollectorInterface
{
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_;
};
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
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.
/**
* 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
#include "datacollectorinterface.impl.hh"
......@@ -3,6 +3,7 @@
#include <dune/geometry/referenceelements.hh>
namespace Dune {
namespace Vtk {
template <class GV, class D, class P>
template <class T, class VtkFunction>
......@@ -23,4 +24,4 @@ std::vector<T> DataCollectorInterface<GV,D,P>
return data;
}
} // end namespace Dune
} } // end namespace Dune::Vtk
......@@ -7,6 +7,6 @@ install(FILES
structureddatacollector.hh
unstructureddatacollector.hh
yaspdatacollector.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter/datacollectors)
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtk/datacollectors)
add_subdirectory(test)
\ No newline at end of file
......@@ -7,140 +7,142 @@
#include <dune/grid/utility/globalindexset.hh>
#include <dune/vtk/forward.hh>
#include <dune/vtk/vtktypes.hh>
#include <dune/vtk/types.hh>
#include "unstructureddatacollector.hh"
namespace Dune
{
namespace Vtk
{
/// Implementation of \ref DataCollector for linear cells, with continuous data.
template <class GridView, class 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);
}
}
/// Implementation of \ref DataCollector for linear cells, with continuous data.
template <class GridView, class Partition>
class ContinuousDataCollector
: public UnstructuredDataCollectorInterface<GridView, ContinuousDataCollector<GridView,Partition>, Partition>
{
using Self = ContinuousDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self, Partition>;
/// Return number of grid vertices
std::uint64_t numPointsImpl () const
{
return numPoints_;
}
public:
using Super::dim;
using Super::partition;
/// Return the coordinates of all grid vertices in the order given by the indexSet
template <class T>
std::vector<T> pointsImpl () const
{
std::vector<T> data;
data.reserve(numPoints_ * 3);
for (auto const& vertex : vertices(gridView_, partition)) {
auto v = vertex.geometry().center();
for (std::size_t j = 0; j < v.size(); ++j)
data.emplace_back(v[j]);
for (std::size_t j = v.size(); j < 3u; ++j)
data.emplace_back(0);
}
return data;
}
public:
ContinuousDataCollector (GridView const& gridView)
: Super(gridView)
{}
/// 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;
}
/// 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);
}
}
/// Return number of grid vertices
std::uint64_t numPointsImpl () const
{
return numPoints_;
}
/// Return number of grid cells
std::uint64_t numCellsImpl () const
{
return numCells_;
}
/// Return the coordinates of all grid vertices in the order given by the indexSet
template <class T>
std::vector<T> pointsImpl () const
{
std::vector<T> data;
data.reserve(numPoints_ * 3);
for (auto const& vertex : vertices(gridView_, partition)) {
auto v = vertex.geometry().center();
for (std::size_t j = 0; j < v.size(); ++j)
data.emplace_back(v[j]);
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
/// 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;
}
/// 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()};
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)));
/// 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;
}
localFct.unbind();
}
return data;
}
protected:
using Super::gridView_;
std::uint64_t numPoints_ = 0;
std::uint64_t numCells_ = 0;
std::vector<std::int64_t> indexMap_;
};
protected:
using Super::gridView_;
std::uint64_t numPoints_ = 0;
std::uint64_t numCells_ = 0;
std::vector<std::int64_t> indexMap_;
};
} // end namespace Vtk
} // end namespace Dune
......@@ -3,126 +3,128 @@
#include <vector>
#include <dune/vtk/forward.hh>
#include <dune/vtk/vtktypes.hh>
#include <dune/vtk/types.hh>
#include "unstructureddatacollector.hh"
namespace Dune
{
/// Implementation of \ref DataCollector for linear cells, with discontinuous data.
template <class GridView, class Partition>
class DiscontinuousDataCollector
: public UnstructuredDataCollectorInterface<GridView, DiscontinuousDataCollector<GridView,Partition>, Partition>
{
using Self = DiscontinuousDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self, Partition>;
public:
using Super::dim;
using Super::partition;