#pragma once #include #include #include #include #include #include #include #include #include #include namespace Dune { namespace Vtk { // Create a grid where the input points and connectivity is already // connected correctly. template struct ContinuousGridCreator : public GridCreatorInterface> { using Self = ContinuousGridCreator; using Super = GridCreatorInterface; using GlobalCoordinate = typename Super::GlobalCoordinate; using Super::Super; using Super::factory; void insertVerticesImpl (std::vector const& points, std::vector const& /*point_ids*/) { for (auto const& p : points) factory().insertVertex(p); } void insertElementsImpl (std::vector const& types, std::vector const& offsets, std::vector const& connectivity) { std::size_t idx = 0; for (std::size_t i = 0; i < types.size(); ++i) { auto type = Vtk::to_geometry(types[i]); Vtk::CellType cellType{type}; [[maybe_unused]] auto refElem = referenceElement(type); int nNodes = offsets[i] - (i == 0 ? 0 : offsets[i-1]); assert(nNodes == refElem.size(Grid::dimension)); std::vector vtk_cell; vtk_cell.reserve(nNodes); for (int j = 0; j < nNodes; ++j) vtk_cell.push_back( connectivity[idx++] ); if (cellType.noPermutation()) factory().insertElement(type,vtk_cell); else { // apply index permutation std::vector cell(nNodes); for (int j = 0; j < nNodes; ++j) cell[j] = vtk_cell[cellType.permutation(j)]; factory().insertElement(type,cell); } } } }; // deduction guides template ContinuousGridCreator(GridFactory&) -> ContinuousGridCreator; template struct AssociatedGridFunction, FieldType, Context> { using type = ContinuousGridFunction; }; } // end namespace Vtk } // end namespace Dune