Commit 583c7476 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

merge branch feature/parallel_vtk_reader

parents 87d18b8f 9513392d
*.vtu
*.pvtu
*.vti
*.pvti
*.vtr
*.pvtr
*.vtp
*.pvtp
*.vts
*.pvts
build*/
*.log
*.tmp
\ No newline at end of file
......@@ -3,18 +3,26 @@ before_script:
- duneci-install-module https://gitlab.dune-project.org/martin.nolte/dune-polygongrid.git
- duneci-install-module https://gitlab.dune-project.org/extensions/dune-spgrid.git
debian:10 gcc-8-17:
image: registry.dune-project.org/docker/ci/dune:2.6-debian-10-gcc-8-17
dune-2.6 gcc-6-14:
image: registry.dune-project.org/docker/ci/dune-pdelab-deps:2.6-debian-9-gcc-6-14
script: duneci-standard-test
debian:10 clang-6-libcpp-17:
image: registry.dune-project.org/docker/ci/dune:2.6-debian-10-clang-6-libcpp-17
dune-2.6 gcc-8-17:
image: registry.dune-project.org/docker/ci/dune-pdelab-deps:2.6-debian-10-gcc-8-17
script: duneci-standard-test
debian:9 gcc-6-14:
image: registry.dune-project.org/docker/ci/dune:2.6-debian-9-gcc-6-14
dune-2.6 clang-7-17:
image: registry.dune-project.org/docker/ci/dune-pdelab-deps:2.6-debian-10-clang-7-libcpp-17
script: duneci-standard-test
ubuntu:18.04 clang-6-17:
image: registry.dune-project.org/docker/ci/dune:2.6-ubuntu-18.04-clang-6-17
dune-git gcc-7-14:
image: registry.dune-project.org/docker/ci/dune-pdelab-deps:git-debian-10-gcc-7-14
script: duneci-standard-test
dune-git gcc-8-17:
image: registry.dune-project.org/docker/ci/dune-pdelab-deps:git-debian-10-gcc-8-noassert-17
script: duneci-standard-test
dune-git clang-7-17:
image: registry.dune-project.org/docker/ci/dune-pdelab-deps:git-debian-10-clang-7-libcpp-17
script: duneci-standard-test
\ No newline at end of file
......@@ -4,7 +4,7 @@
#Name of the module
Module: dune-vtk
Version: 0.1
Version: 0.2
Maintainer: simon.praetorius@tu-dresden.de
#depending on
Depends: dune-common (>= 2.6) dune-geometry (>= 2.6) dune-grid
......
......@@ -8,7 +8,6 @@ install(FILES
defaultvtkfunction.hh
filereader.hh
filewriter.hh
gridcreator.hh
legacyvtkfunction.hh
pvdwriter.hh
pvdwriter.impl.hh
......@@ -26,5 +25,6 @@ install(FILES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter)
add_subdirectory(datacollectors)
add_subdirectory(gridcreators)
add_subdirectory(utility)
add_subdirectory(writers)
......@@ -5,10 +5,21 @@
namespace Dune {
template <class GridView, class Derived>
template <class GridView, class Derived, class Partition>
class DataCollectorInterface
{
public:
/// The partitionset to collect data from
static constexpr auto partition = Partition{};
/// 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)
{}
......@@ -19,13 +30,19 @@ public:
asDerived().updateImpl();
}
/// Return the number of overlapping elements
/// Return the number of ghost elements
int ghostLevel () const
{
return asDerived().ghostLevelImpl();
}
/// Return the number of points in the grid
/// \brief 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();
......@@ -59,8 +76,9 @@ public:
return asDerived().template pointDataImpl<T>(fct);
}
/// Return a flat vector of function values evaluated at the cells. \see pointData.
/// Return a flat vector of function values evaluated at the cells in the order of traversal.
/**
* \see pointData.
* Note: Cells might be descibred explicitly by connectivity, offsets, and types, e.g. in
* an UnstructuredGrid, or might be described implicitly by the grid type, e.g. in
* StructuredGrid.
......@@ -95,7 +113,7 @@ public: // default implementations
return gridView_.overlapSize(0);
}
// Evaluate `fct` in center of cell
// Evaluate `fct` in center of cell.
template <class T, class VtkFunction>
std::vector<T> cellDataImpl (VtkFunction const& fct) const;
......
......@@ -6,20 +6,20 @@
namespace Dune {
template <class GridView, class Derived>
template <class GV, class D, class P>
template <class T, class VtkFunction>
std::vector<T> DataCollectorInterface<GridView, Derived>
std::vector<T> DataCollectorInterface<GV,D,P>
::cellDataImpl (VtkFunction const& fct) const
{
std::vector<T> data(gridView_.size(0) * fct.ncomps());
MultipleCodimMultipleGeomTypeMapper<GridView> mapper(gridView_, mcmgElementLayout());
std::vector<T> data;
data.reserve(this->numCells() * fct.ncomps());
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::all)) {
for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e);
auto refElem = referenceElement<T,GridView::dimension>(e.type());
std::size_t idx = fct.ncomps() * mapper.index(e);
auto refElem = referenceElement<T,dim>(e.type());
for (int comp = 0; comp < fct.ncomps(); ++comp)
data[idx + comp] = T(localFct.evaluate(comp, refElem.position(0,0)));
data.emplace_back(localFct.evaluate(comp, refElem.position(0,0)));
localFct.unbind();
}
return data;
......
......@@ -3,43 +3,75 @@
#include <numeric>
#include "unstructureddatacollector.hh"
#include <dune/grid/utility/globalindexset.hh>
namespace Dune
{
/// Implementation of \ref DataCollector for linear cells, with continuous data.
template <class GridView>
template <class GridView, class Partition>
class ContinuousDataCollector
: public UnstructuredDataCollectorInterface<GridView, ContinuousDataCollector<GridView>>
: public UnstructuredDataCollectorInterface<GridView, ContinuousDataCollector<GridView,Partition>, Partition>
{
enum { dim = GridView::dimension };
using Self = ContinuousDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self>;
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);
}
}
/// Return number of grid vertices
std::uint64_t numPointsImpl () const
{
return gridView_.size(dim);
return numPoints_;
}
/// 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(gridView_.size(dim) * 3);
auto const& indexSet = gridView_.indexSet();
for (auto const& vertex : vertices(gridView_, Partitions::all)) {
std::size_t idx = 3 * indexSet.index(vertex);
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[idx + j] = T(v[j]);
data.emplace_back(v[j]);
for (std::size_t j = v.size(); j < 3u; ++j)
data[idx + j] = T(0);
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;
}
......@@ -47,7 +79,7 @@ public:
/// Return number of grid cells
std::uint64_t numCellsImpl () const
{
return gridView_.size(0);
return numCells_;
}
/// Return the types, offsets and connectivity of the cells, using the same connectivity as
......@@ -62,15 +94,15 @@ public:
});
Cells cells;
cells.connectivity.reserve(gridView_.size(0) * maxVertices);
cells.offsets.reserve(gridView_.size(0));
cells.types.reserve(gridView_.size(0));
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_, Partitions::all)) {
for (auto const& c : elements(gridView_, partition)) {
Vtk::CellType cellType(c.type());
for (unsigned int j = 0; j < c.subEntities(dim); ++j)
cells.connectivity.push_back( std::int64_t(indexSet.subIndex(c,cellType.permutation(j),dim)) );
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());
}
......@@ -81,15 +113,15 @@ public:
template <class T, class GlobalFunction>
std::vector<T> pointDataImpl (GlobalFunction const& fct) const
{
std::vector<T> data(gridView_.size(dim) * fct.ncomps());
std::vector<T> data(numPoints_ * fct.ncomps());
auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::all)) {
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() * indexSet.subIndex(e,cellType.permutation(j),dim);
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)));
}
......@@ -100,6 +132,9 @@ public:
protected:
using Super::gridView_;
std::uint64_t numPoints_ = 0;
std::uint64_t numCells_ = 0;
std::vector<std::int64_t> indexMap_;
};
} // end namespace Dune
......@@ -6,14 +6,16 @@ namespace Dune
{
/// Implementation of \ref DataCollector for linear cells, with discontinuous data.
template <class GridView>
template <class GridView, class Partition>
class DiscontinuousDataCollector
: public UnstructuredDataCollectorInterface<GridView, DiscontinuousDataCollector<GridView>>
: public UnstructuredDataCollectorInterface<GridView, DiscontinuousDataCollector<GridView,Partition>, Partition>
{
enum { dim = GridView::dimension };
using Self = DiscontinuousDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self>;
using Super = UnstructuredDataCollectorInterface<GridView, Self, Partition>;
public:
using Super::dim;
using Super::partition;
public:
DiscontinuousDataCollector (GridView const& gridView)
......@@ -24,10 +26,12 @@ public:
void updateImpl ()
{
numPoints_ = 0;
numCells_ = 0;
indexMap_.resize(gridView_.size(dim));
std::int64_t vertex_idx = 0;
auto const& indexSet = gridView_.indexSet();
for (auto const& c : elements(gridView_, Partitions::interior)) {
for (auto const& c : elements(gridView_, partition)) {
numCells_++;
numPoints_ += c.subEntities(dim);
for (unsigned int i = 0; i < c.subEntities(dim); ++i)
indexMap_[indexSet.subIndex(c, i, dim)] = vertex_idx++;
......@@ -46,7 +50,7 @@ public:
{
std::vector<T> data(numPoints_ * 3);
auto const& indexSet = gridView_.indexSet();
for (auto const& element : elements(gridView_, Partitions::interior)) {
for (auto const& element : elements(gridView_, partition)) {
for (unsigned int i = 0; i < element.subEntities(dim); ++i) {
std::size_t idx = 3 * indexMap_[indexSet.subIndex(element, i, dim)];
auto v = element.geometry().corner(i);
......@@ -62,7 +66,7 @@ public:
/// Return number of grid cells
std::uint64_t numCellsImpl () const
{
return gridView_.size(0);
return numCells_;
}
/// Connect the corners of each cell. The leads to a global discontinuous grid
......@@ -70,12 +74,12 @@ public:
{
Cells cells;
cells.connectivity.reserve(numPoints_);
cells.offsets.reserve(gridView_.size(0));
cells.types.reserve(gridView_.size(0));
cells.offsets.reserve(numCells_);
cells.types.reserve(numCells_);
std::int64_t old_o = 0;
auto const& indexSet = gridView_.indexSet();
for (auto const& c : elements(gridView_, Partitions::interior)) {
for (auto const& c : elements(gridView_, partition)) {
Vtk::CellType cellType(c.type());
for (unsigned int j = 0; j < c.subEntities(dim); ++j) {
std::int64_t vertex_idx = indexMap_[indexSet.subIndex(c,cellType.permutation(j),dim)];
......@@ -95,7 +99,7 @@ public:
std::vector<T> data(numPoints_ * fct.ncomps());
auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::interior)) {
for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e);
Vtk::CellType cellType{e.type()};
auto refElem = referenceElement(e.geometry());
......@@ -111,6 +115,7 @@ public:
protected:
using Super::gridView_;
std::uint64_t numCells_ = 0;
std::uint64_t numPoints_ = 0;
std::vector<std::int64_t> indexMap_;
};
......
......@@ -8,12 +8,14 @@ namespace Dune
/// Implementation of \ref DataCollector for quadratic cells, with continuous data.
template <class GridView>
class QuadraticDataCollector
: public UnstructuredDataCollectorInterface<GridView, QuadraticDataCollector<GridView>>
: public UnstructuredDataCollectorInterface<GridView, QuadraticDataCollector<GridView>, Partitions::All>
{
enum { dim = GridView::dimension };
using Self = QuadraticDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self>;
using Super = UnstructuredDataCollectorInterface<GridView, Self, Partitions::All>;
public:
using Super::dim;
using Super::partition; // NOTE: quadratic data-collector currently implemented for the All partition only
public:
QuadraticDataCollector (GridView const& gridView)
......@@ -36,7 +38,7 @@ public:
{
std::vector<T> data(this->numPoints() * 3);
auto const& indexSet = gridView_.indexSet();
for (auto const& element : elements(gridView_, Partitions::interior)) {
for (auto const& element : elements(gridView_, partition)) {
auto geometry = element.geometry();
auto refElem = referenceElement<T,dim>(element.type());
......@@ -82,7 +84,7 @@ public:
std::int64_t old_o = 0;
auto const& indexSet = gridView_.indexSet();
for (auto const& c : elements(gridView_, Partitions::interior)) {
for (auto const& c : elements(gridView_, partition)) {
Vtk::CellType cellType(c.type(), Vtk::QUADRATIC);
for (unsigned int j = 0; j < c.subEntities(dim); ++j) {
int k = cellType.permutation(j);
......@@ -107,7 +109,7 @@ public:
std::vector<T> data(this->numPoints() * fct.ncomps());
auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::interior)) {
for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e);
Vtk::CellType cellType{e.type(), Vtk::QUADRATIC};
auto refElem = referenceElement(e.geometry());
......
......@@ -15,12 +15,14 @@ template <class GridView>
class SPDataCollector
: public StructuredDataCollectorInterface<GridView, SPDataCollector<GridView>>
{
enum { dim = GridView::dimension };
using Self = SPDataCollector;
using Super = StructuredDataCollectorInterface<GridView, Self>;
using ctype = typename GridView::ctype;
public:
using Super::dim;
using Super::partition;
public:
SPDataCollector (GridView const& gridView)
: Super(gridView)
......
......@@ -9,18 +9,6 @@
namespace Dune
{
namespace Impl
{
// Should be specialized for concrete structured grid
template <class GridView, class Grid>
struct StructuredDataCollectorImpl;
}
template <class GridView>
using StructuredDataCollector = typename Impl::StructuredDataCollectorImpl<GridView, typename GridView::Grid>::type;
/// The Interface for structured data-collectors
template <class GridView, class Derived>
class StructuredDataCollectorInterface
......@@ -31,6 +19,10 @@ protected:
using SubDataCollector = ContinuousDataCollector<GridView>;
using ctype = typename GridView::ctype;
public:
using Super::dim;
using Super::partition;
public:
StructuredDataCollectorInterface (GridView const& gridView)
: Super(gridView)
......@@ -115,6 +107,16 @@ public: // default implementation:
#endif
}
/// Return number of grid cells
std::uint64_t numCellsImpl () const
{
auto extent = this->extent();
std::uint64_t num = 1;
for (int d = 0; d < dim; ++d)
num *= extent[2*d+1] - extent[2*d];
return num;
}
/// Return number of grid vertices
std::uint64_t numPointsImpl () const
{
......@@ -204,14 +206,14 @@ public: // default implementation:
auto extent = this->extent();
std::array<std::vector<T>, 3> ordinates{};
for (int d = 0; d < GridView::dimension; ++d) {
for (int d = 0; d < dim; ++d) {
auto s = extent[2*d+1] - extent[2*d] + 1;
ordinates[d].resize(s);
for (int i = 0; i < s; ++i)
ordinates[d][i] = origin[d] + (extent[2*d] + i)*spacing[d];
}
for (int d = GridView::dimension; d < 3; ++d)
for (int d = dim; d < 3; ++d)
ordinates[d].resize(1, T(0));
return ordinates;
......
......@@ -14,29 +14,39 @@ struct Cells
std::vector<std::int64_t> connectivity;
};
template <class GridView, class Derived>
template <class GridView, class Derived, class Partition>
class UnstructuredDataCollectorInterface
: public DataCollectorInterface<GridView, Derived>
: public DataCollectorInterface<GridView, Derived, Partition>
{
using Super = DataCollectorInterface<GridView, Derived>;
using Super = DataCollectorInterface<GridView, Derived, Partition>;
public:
using Super::dim;
using Super::partition;
public:
UnstructuredDataCollectorInterface (GridView const& gridView)
: Super(gridView)
{}
/// \brief Return the number of cells in the grid
std::uint64_t numCells () const
{
return this->asDerived().numCellsImpl();
}
/// \brief Return cell types, offsets, and connectivity. \see Cells
Cells cells () const
{
return this->asDerived().cellsImpl();
}
std::vector<std::uint64_t> pointIds () const
{
return this->asDerived().pointIdsImpl();
}
protected:
// default implementation
std::vector<std::uint64_t> pointIdsImpl () const
{
return {};
}
protected:
using Super::gridView_;
};
......
......@@ -11,12 +11,14 @@ template <class GridView>
class YaspDataCollector
: public StructuredDataCollectorInterface<GridView, YaspDataCollector<GridView>>
{
enum { dim = GridView::dimension };
using Self = YaspDataCollector;
using Super = StructuredDataCollectorInterface<GridView, Self>;
using ctype = typename GridView::ctype;
public:
using Super::dim;
using Super::partition;
public:
YaspDataCollector (GridView const& gridView)