26#include <boost/fusion/container/vector.hpp>
27#include <boost/fusion/include/zip_view.hpp>
29#include <dune/grid/config.h>
30#include <dune/grid/common/gridfactory.hh>
40 namespace VTKReaderDetail
42 enum CoefficientDataType
48 struct CoefficientData
50 CoefficientDataType type;
51 std::size_t numComponents = 0;
52 std::vector<double> data;
57 bool reverseByteOrder =
false;
58 std::string headerType =
"UInt32";
59 std::string compressor;
61 std::size_t dimVertex = 0, numPoints = 0, numCells = 0;
62 std::vector<double> coordinates;
63 std::vector<std::size_t> connectivity, offsets, types;
64 std::map<std::string, CoefficientData> coefficientData;
70 std::vector<std::size_t> corners, edges;
136 void load(std::string
const& filename);
156 template<
class Gr
id,
class Deformation>
157 std::unique_ptr<Grid>
createGrid(Deformation
const& deformation);
177 template<
class VariableSet>
219 loadOptionEverything,
223 enum CoefficientMapping
229 template<
class VariableSet,
class FSEVarDescPair>
230 void copyCoefficientsByName(VariableSet
const& varSet, FSEVarDescPair& pair,
int interpolationFlags)
const;
233 void copyCoefficients(std::string
const& functionName, VTKReaderDetail::CoefficientData
const& coefficientData, FSE& fse,
int interpolationFlags)
const;
236 void copyCoefficientsInterpolated(std::string
const& functionName,
237 VTKReaderDetail::CoefficientData
const& coefficientData,
241 void copyCoefficientsDirectly(std::string
const& functionName,
242 VTKReaderDetail::CoefficientData
const& coefficientData,
245 void loadVTKInternal(std::string
const& filename, LoadOption option);
246 void prepareGridCreation(std::vector<VTKReaderDetail::VTKCell>& vtkCells, std::vector<char>& isCorner);
248 void clearCoefficientData();
251 VTKReaderDetail::VTKData vtk;
253 bool gridWasLoaded =
false,
254 gridWasCreated =
false;
257 CoefficientMapping coefficientMapping = continuous;
258 int polynomialOrder = 0;
261 std::vector<std::size_t> pointDataIndices, cellDataIndices;
271 namespace VTKReaderDetail
276 std::size_t vtkIdx = 0, numComponents = 0;
277 std::vector<double>::const_iterator coordinates;
279 bool operator<(IndexedPoint
const& other)
const;
280 bool operator==(IndexedPoint
const& other)
const;
285 class VTKFactoryHelper
288 template<
class Deformation>
void insertVertices(std::vector<char>
const& isCorner, VTKData
const& vtk, Deformation
const& deformation);
289 void insertVertices(std::vector<char>
const& isCorner, VTKData
const& vtk);
290 void insertCells(std::vector<VTKCell>
const& vtkCells);
291 std::unique_ptr<Grid> createGrid();
292 void setIndicesForDuplicatePoints(std::vector<IndexedPoint>
const& indexedPoints, std::vector<std::size_t>
const& vertexVTKToMerged);
293 void getDataIndicesContinuous(
typename Grid::LeafGridView
const& leafView, std::vector<VTKCell>
const& vtkCells, std::vector<std::size_t>& dataIndicesOut)
const;
294 void getDataIndicesDiscontinuous(
typename Grid::LeafGridView
const& leafView, std::vector<VTKCell>
const& vtkCells, std::vector<std::size_t>& dataIndicesOut)
const;
295 void getCellDataIndices(
typename Grid::LeafGridView
const& leafView, std::vector<std::size_t>& dataIndicesOut)
const;
299 template<
class ElementEntity>
300 void getIndicesLocalToVTK(VTKCell
const& vtkCell, ElementEntity
const& element, std::vector<std::size_t>& vertexLocalToVTK, std::vector<std::size_t>& edgeLocalToVTK)
const;
302 Dune::GridFactory<Grid> factory;
303 std::vector<std::size_t> vertexVTKToInsertion, vertexInsertionToVTK;
304 std::size_t totalCorners = 0, totalEdges = 0;
307 std::string formatWarning(std::string
const& filename, std::string
const& message);
309 Dune::GeometryType getDuneGeomType(
int vtkGeomType);
310 std::size_t getDuneCorner(
int vtkGeomType, std::size_t corner);
311 void countCornersAndEdges(
int vtkGeomType, std::size_t& numCorners, std::size_t& numEdges);
312 int countCellDim(
int vtkGeomType);
316 bool operator()(std::pair<std::size_t, std::size_t>
const& p1, std::pair<std::size_t, std::size_t>
const& p2)
const;
318 using EdgeTable = std::map<std::pair<std::size_t, std::size_t>, std::size_t, CompareTwoSet>;
320 std::size_t findEdgeIndex(EdgeTable
const& edgeTable, std::size_t a, std::size_t b);
321 std::pair<std::size_t, std::size_t> getVTKLocalCorners(
int vtkGeomType, std::size_t edge);
322 std::vector<std::size_t> getIndicesPerCell(std::vector<std::size_t>
const& corners, std::vector<std::size_t>
const& edges,
int vtkGeomType);
324 template<
class ElementEntity,
class IndexSet>
325 EdgeTable createEdgeTable(ElementEntity
const& element, IndexSet
const& indexSet, std::vector<std::size_t>
const& vertexGridToVTK)
330 constexpr int dim = IndexSet::dimension;
331 constexpr int codimEdge = dim - 1, codimVertex = dim;
333 auto refElement = Dune::ReferenceElements<double, dim>::general(element.type());
335 unsigned numEdges = refElement.size(codimEdge);
336 for(
unsigned i = 0; i < numEdges; ++i)
339 std::size_t c0 = refElement.subEntity(i, codimEdge, 0, codimVertex);
340 std::size_t c1 = refElement.subEntity(i, codimEdge, 1, codimVertex);
343 c0 = indexSet.subIndex(element, c0, codimVertex);
344 c1 = indexSet.subIndex(element, c1, codimVertex);
345 std::size_t e = indexSet.subIndex(element, i, codimEdge);
348 c0 = vertexGridToVTK[c0];
349 c1 = vertexGridToVTK[c1];
352 edgeTable[std::make_pair(c0, c1)] = e;
358 template<
class DataSequence,
class VariableDescriptionSequence>
359 boost::fusion::zip_view<boost::fusion::vector<DataSequence&, VariableDescriptionSequence const&>>
360 makeZipView(DataSequence& data, VariableDescriptionSequence
const& descriptions)
362 using Sequences = boost::fusion::vector<DataSequence&, VariableDescriptionSequence const&>;
363 return boost::fusion::zip_view<Sequences>(Sequences(data, descriptions));
369 template<
class Deformation>
370 void VTKFactoryHelper<Grid>::insertVertices(std::vector<char>
const& isCorner, VTKData
const& vtk, Deformation
const& deformation)
374 constexpr int dim = Grid::dimension;
375 using Vertex = Dune::FieldVector<double, dim>;
376 std::size_t numComponentsToRead = std::min((std::size_t)dim, vtk.dimVertex);
377 vertexVTKToInsertion.resize(vtk.numPoints, 0);
378 std::size_t countInsertion = 0;
380 for(std::size_t i = 0; i < vtk.numPoints; ++i)
385 std::size_t offs = i * vtk.dimVertex;
387 auto it = vtk.coordinates.begin() + offs;
388 std::copy(it, it + numComponentsToRead, vertex.begin());
389 factory.insertVertex(deformation(vertex));
391 vertexInsertionToVTK.push_back(i);
392 vertexVTKToInsertion[i] = countInsertion;
396 totalCorners = countInsertion;
399 totalEdges = vtk.numPoints - totalCorners;
403 void VTKFactoryHelper<Grid>::insertVertices(std::vector<char>
const& isCorner, VTKData
const& vtk)
405 auto identity = [] (
auto x) {
return x;};
406 insertVertices(isCorner, vtk, identity);
410 void VTKFactoryHelper<Grid>::insertCells(std::vector<VTKCell>
const& vtkCells)
412 int dim = Grid::dimension;
414 for(VTKCell
const& vtkCell : vtkCells)
416 int geoType = vtkCell.vtkGeomType;
417 int cellDim = countCellDim(geoType);
423 std::vector<unsigned int> corners(vtkCell.corners.size());
424 for(std::size_t k = 0; k < corners.size(); ++k)
426 std::size_t corner = getDuneCorner(vtkCell.vtkGeomType, k);
427 std::size_t vtkCornerIdx = vtkCell.corners[corner];
428 corners[k] = (
unsigned int) vertexVTKToInsertion[vtkCornerIdx];
430 factory.insertElement(getDuneGeomType(vtkCell.vtkGeomType), corners);
435 std::unique_ptr<Grid> VTKFactoryHelper<Grid>::createGrid()
437 return std::unique_ptr<Grid>(factory.createGrid());
441 void VTKFactoryHelper<Grid>::setIndicesForDuplicatePoints(std::vector<IndexedPoint>
const& indexedPoints, std::vector<std::size_t>
const& vertexVTKToMerged)
444 for(IndexedPoint
const& p : indexedPoints)
446 std::size_t mergedIdx = vertexVTKToMerged[p.vtkIdx];
447 std::size_t insertionIdx = vertexVTKToInsertion[mergedIdx];
448 vertexVTKToInsertion[p.vtkIdx] = insertionIdx;
453 void VTKFactoryHelper<Grid>::getDataIndicesContinuous(
typename Grid::LeafGridView
const& leafView, std::vector<VTKCell>
const& vtkCells, std::vector<std::size_t>& dataIndicesOut)
const
455 std::vector<std::size_t> vertexGridToVTK(totalCorners), edgeGridToVTK(totalEdges);
458 auto const& indexSet = leafView.indexSet();
459 for(
auto const& vertexEntity : vertices(leafView))
461 std::size_t insertionIdx = factory.insertionIndex(vertexEntity);
462 std::size_t gridIdx = indexSet.index(vertexEntity);
464 if(insertionIdx >= vertexInsertionToVTK.size() || gridIdx >= vertexGridToVTK.size())
467 throw Kaskade::GridException(
"Vertex index is out of bounds.", __FILE__, __LINE__);
470 std::size_t vtkIdx = vertexInsertionToVTK[insertionIdx];
471 vertexGridToVTK[gridIdx] = vtkIdx;
475 for(
auto const& elementEntity : elements(leafView))
478 std::size_t insertionIdx = factory.insertionIndex(elementEntity);
480 if(insertionIdx >= vtkCells.size())
483 throw Kaskade::GridException(
"Cell insertion index is out of bounds.", __FILE__, __LINE__);
486 VTKCell
const& vtkCell = vtkCells[insertionIdx];
490 EdgeTable edgeTable = createEdgeTable(elementEntity, indexSet, vertexGridToVTK);
491 for(std::size_t i = 0; i < vtkCell.edges.size(); ++i)
494 std::size_t vtkIdx = vtkCell.edges[i];
497 std::pair<int, int> vtkLocalCorners = getVTKLocalCorners(vtkCell.vtkGeomType, i);
501 std::size_t gridIdx = findEdgeIndex(edgeTable, vtkCell.corners[vtkLocalCorners.first], vtkCell.corners[vtkLocalCorners.second]);
503 if(gridIdx >= edgeGridToVTK.size())
506 throw Kaskade::GridException(
"Edge index is out of bounds.", __FILE__, __LINE__);
508 edgeGridToVTK[gridIdx]= vtkIdx;
512 dataIndicesOut.resize(totalCorners + totalEdges);
513 std::copy(edgeGridToVTK.begin(), edgeGridToVTK.end(), dataIndicesOut.begin());
514 std::copy(vertexGridToVTK.begin(), vertexGridToVTK.end(), dataIndicesOut.begin() + totalEdges);
518 void VTKFactoryHelper<Grid>::getDataIndicesDiscontinuous(
typename Grid::LeafGridView
const& leafView, std::vector<VTKCell>
const& vtkCells, std::vector<std::size_t>& dataIndicesOut)
const
521 std::vector<std::vector<std::size_t>> dataIndicesPerCell(vtkCells.size());
523 for(
auto const& elementEntity : elements(leafView))
526 std::size_t insertionIdx = factory.insertionIndex(elementEntity);
527 if(insertionIdx >= vtkCells.size())
530 throw Kaskade::GridException(
"Cell insertion index is out of bounds.", __FILE__, __LINE__);
532 VTKCell
const& vtkCell = vtkCells[insertionIdx];
535 std::vector<std::size_t> vertexLocalToVTK, edgeLocalToVTK;
536 getIndicesLocalToVTK(vtkCell, elementEntity, vertexLocalToVTK, edgeLocalToVTK);
537 std::vector<std::size_t> cellIndices = getIndicesPerCell(vertexLocalToVTK, edgeLocalToVTK, vtkCell.vtkGeomType);
540 std::size_t gridIdx = leafView.indexSet().index(elementEntity);
542 if(gridIdx >= dataIndicesPerCell.size())
545 throw Kaskade::GridException(
"Cell index is out of bounds.", __FILE__, __LINE__);
547 dataIndicesPerCell[gridIdx] = cellIndices;
551 for(std::vector<std::size_t>
const& cellIndices : dataIndicesPerCell)
553 for(std::size_t idx : cellIndices)
555 dataIndicesOut.push_back(idx);
561 void VTKFactoryHelper<Grid>::getCellDataIndices(
typename Grid::LeafGridView
const& leafView, std::vector<std::size_t>& dataIndicesOut)
const
563 std::size_t numCells = leafView.size(0);
564 dataIndicesOut.resize(numCells);
566 for(
auto const& elementEntity : elements(leafView))
569 std::size_t vtkIdx = factory.insertionIndex(elementEntity);
570 std::size_t gridIdx = leafView.indexSet().index(elementEntity);
571 if(gridIdx >= dataIndicesOut.size())
574 throw Kaskade::GridException(
"Cell index is out of bounds.", __FILE__, __LINE__);
576 dataIndicesOut[gridIdx] = vtkIdx;
581 template<
class ElementEntity>
582 void VTKFactoryHelper<Grid>::getIndicesLocalToVTK(VTKCell
const& vtkCell, ElementEntity
const& element, std::vector<std::size_t>& vertexLocalToVTK, std::vector<std::size_t>& edgeLocalToVTK)
const
588 using IndexPair = std::pair<std::size_t, std::size_t>;
591 std::map<std::size_t, IndexPair> cornerLookup;
592 std::map<IndexPair, IndexPair, CompareTwoSet> edgeLookup;
594 std::size_t numCorners = vtkCell.corners.size(), numEdges = vtkCell.edges.size();
595 constexpr int dim = Grid::dimension;
596 constexpr int codimVertex = dim, codimEdge = dim - 1;
598 assert(element.subEntities(codimVertex) == numCorners);
599 assert(numEdges == 0 || element.subEntities(codimEdge) == numEdges);
602 std::vector<std::size_t> vertexLocalToInsertion(numCorners);
604 for(std::size_t i = 0; i < numCorners; ++i)
607 auto vertexEntity = element.template subEntity<codimVertex>(i);
608 std::size_t insertionIndex = factory.insertionIndex(vertexEntity);
609 cornerLookup[insertionIndex].first = i;
610 vertexLocalToInsertion[i] = insertionIndex;
613 std::size_t vtkIndex = vtkCell.corners[i];
614 insertionIndex = vertexVTKToInsertion[vtkIndex];
615 cornerLookup[insertionIndex].second = vtkIndex;
619 auto refElement = Dune::ReferenceElements<double, dim>::general(element.type());
621 for(std::size_t i = 0; i < numEdges; ++i)
624 std::size_t c0 = refElement.subEntity(i, codimEdge, 0, codimVertex);
625 std::size_t c1 = refElement.subEntity(i, codimEdge, 1, codimVertex);
626 c0 = vertexLocalToInsertion[c0];
627 c1 = vertexLocalToInsertion[c1];
628 edgeLookup[std::make_pair(c0, c1)].first = i;
631 IndexPair p = getVTKLocalCorners(vtkCell.vtkGeomType, i);
632 c0 = vtkCell.corners[p.first];
633 c1 = vtkCell.corners[p.second];
634 c0 = vertexVTKToInsertion[c0];
635 c1 = vertexVTKToInsertion[c1];
636 std::size_t edgeDataIdx = vtkCell.edges[i];
637 edgeLookup[std::make_pair(c0, c1)].second = edgeDataIdx;
640 assert(cornerLookup.size() == numCorners);
641 assert(edgeLookup.size() == numEdges);
644 vertexLocalToVTK.resize(numCorners);
646 for(
auto const& p : cornerLookup)
648 IndexPair
const& ip = p.second;
649 vertexLocalToVTK[ip.first] = ip.second;
652 edgeLocalToVTK.resize(numEdges);
654 for(
auto const& p : edgeLookup)
656 IndexPair
const& ip = p.second;
657 edgeLocalToVTK[ip.first] = ip.second;
671 auto identity = [] (
auto x) {
return x;};
675 template<
class Gr
id,
class Deformation>
678 using namespace VTKReaderDetail;
686 std::vector<char> isCorner(vtk.numPoints, 0);
687 std::vector<VTKCell> vtkCells(vtk.numCells);
690 prepareGridCreation(vtkCells, isCorner);
692 std::vector<IndexedPoint> indexedPoints;
693 std::vector<std::size_t> vertexVTKToMerged;
696 for(std::size_t i = 0; i < vtk.numPoints; ++i)
700 std::size_t offs = i * vtk.dimVertex;
703 p.numComponents = vtk.dimVertex;
704 p.coordinates = vtk.coordinates.begin() + offs;
705 indexedPoints.push_back(p);
709 std::sort(indexedPoints.begin(), indexedPoints.end());
713 bool hasDuplicatePoints = std::adjacent_find(indexedPoints.begin(), indexedPoints.end())
714 != indexedPoints.end();
715 coefficientMapping = hasDuplicatePoints? discontinuous : continuous;
717 if (hasDuplicatePoints)
720 vertexVTKToMerged.resize(vtk.numPoints, 0);
722 std::fill(isCorner.begin(), isCorner.end(), 0);
724 auto P = indexedPoints.begin();
725 while(P != indexedPoints.end())
728 isCorner[P->vtkIdx] = 1;
730 std::size_t currentRepresentativeIdx = P->vtkIdx;
731 auto range = std::equal_range(P, indexedPoints.end(), *P);
732 for(
auto it = range.first; it != range.second; ++it)
734 vertexVTKToMerged[it->vtkIdx] = currentRepresentativeIdx;
742 VTKFactoryHelper<Grid> factoryHelper;
743 std::unique_ptr<Grid> grid;
748 factoryHelper.insertVertices(isCorner, vtk, deformation);
751 if (coefficientMapping == discontinuous)
752 factoryHelper.setIndicesForDuplicatePoints(indexedPoints, vertexVTKToMerged);
754 factoryHelper.insertCells(vtkCells);
755 grid = factoryHelper.createGrid();
757 catch(Dune::GridError
const& e)
763 auto leafView = grid->leafGridView();
765 if (coefficientMapping == continuous)
767 factoryHelper.getDataIndicesContinuous(leafView, vtkCells, pointDataIndices);
771 factoryHelper.getDataIndicesDiscontinuous(leafView, vtkCells, pointDataIndices);
774 factoryHelper.getCellDataIndices(leafView, cellDataIndices);
776 gridWasCreated =
true;
780 template<
class VariableSet>
783 using namespace VTKReaderDetail;
791 auto functions = makeZipView(varSet.
data,
typename VariableSet::Descriptions::Variables());
792 boost::fusion::for_each(functions, [&](
auto const& f){this->copyCoefficientsByName(varSet, f, interpolationFlags);});
797 int interpolationFlags)
const
799 using namespace VTKReaderDetail;
806 auto it = vtk.coefficientData.find(functionName);
807 if (it == vtk.coefficientData.end())
811 copyCoefficients(functionName, it->second, fse, interpolationFlags);
814 template<
class VariableSet,
class FSEVarDescPair>
815 void VTKReader::copyCoefficientsByName(
VariableSet const& varSet, FSEVarDescPair& pair,
int interpolationFlags)
const
818 using namespace VTKReaderDetail;
820 auto& fse = at_c<0>(pair);
821 auto const& desc = at_c<1>(pair);
822 std::string functionName = varSet.
descriptions->names[desc.id];
825 auto it = vtk.coefficientData.find(functionName);
826 if(it != vtk.coefficientData.end())
828 copyCoefficients(functionName, it->second, fse, interpolationFlags);
833 std::ostringstream out;
834 out <<
"No data provided for " << functionName <<
".";
835 std::cout << formatWarning(vtk.filename, out.str()) <<
'\n';
840 void VTKReader::copyCoefficients(std::string
const& functionName,
841 VTKReaderDetail::CoefficientData
const& coefficientData,
843 int interpolationFlags)
const
845 using namespace VTKReaderDetail;
847 constexpr int fseCoefficientDim = FSE::StorageValueType::dimension;
848 int fseMaxOrder = fse.space().mapper().maxOrder(), fseContinuity = FSE::Space::continuity;
850 bool interpolationNeeded =
false;
852 if ((std::size_t)fseCoefficientDim != coefficientData.numComponents)
856 std::ostringstream out;
857 out <<
"\"" << functionName <<
"\": Coefficient dimension mismatch.\nfunction info: "
859 throw Kaskade::FileIOException(out.str(), vtk.filename, __FILE__, __LINE__);
864 int order = coefficientData.type==cellData? 0: polynomialOrder;
866 if (fseMaxOrder !=
order)
869 interpolationNeeded =
true;
872 std::ostringstream out;
873 out <<
"\"" << functionName <<
"\": Order mismatch.\nfunction info: "
875 throw Kaskade::FileIOException(out.str(), vtk.filename, __FILE__, __LINE__);
880 CoefficientMapping continuity = coefficientData.type==cellData? discontinuous: coefficientMapping;
882 if ( (fseContinuity < 0 && continuity == continuous)
883 || (fseContinuity >= 0 && continuity == discontinuous))
886 interpolationNeeded =
true;
889 std::ostringstream out;
890 out <<
"\"" << functionName <<
"\": Continuity mismatch.\nfunction info: "
892 throw Kaskade::FileIOException(out.str(), vtk.filename, __FILE__, __LINE__);
896 if (interpolationNeeded)
897 copyCoefficientsInterpolated(functionName, coefficientData, fse);
899 copyCoefficientsDirectly(functionName, coefficientData, fse);
903 void VTKReader::copyCoefficientsInterpolated(std::string
const& functionName,
904 VTKReaderDetail::CoefficientData
const& coefficientData,
907 using namespace Kaskade;
908 using namespace VTKReaderDetail;
910 using Mapper =
typename FSE::Space::Mapper;
911 using Scalar =
typename FSE::Space::Scalar;
912 using LeafView =
typename Mapper::Grid::LeafGridView;
913 constexpr int fseCoefficientDim = FSE::StorageValueType::dimension;
919 if (coefficientData.type == pointData)
921 if (coefficientMapping == continuous)
923 using Space = FEFunctionSpace<ContinuousLagrangeMapper<Scalar, LeafView>>;
925 Space space(fse.space().gridManager(), fse.space().grid().leafGridView(), polynomialOrder);
926 auto otherFSE = space.template element<fseCoefficientDim>();
927 copyCoefficientsDirectly(functionName, coefficientData, otherFSE);
932 using Space = FEFunctionSpace<DiscontinuousLagrangeMapper<Scalar, LeafView>>;
934 Space space(fse.space().gridManager(), fse.space().grid().leafGridView(), polynomialOrder);
935 auto otherFSE = space.template element<fseCoefficientDim>();
936 copyCoefficientsDirectly(functionName, coefficientData, otherFSE);
940 else if (coefficientData.type == cellData)
943 using Space = FEFunctionSpace<DiscontinuousLagrangeMapper<Scalar, LeafView>>;
945 Space space(fse.space().gridManager(), fse.space().grid().leafGridView(), 0);
946 auto otherFSE = space.template element<fseCoefficientDim>();
947 copyCoefficientsDirectly(functionName, coefficientData, otherFSE);
953 void VTKReader::copyCoefficientsDirectly(std::string
const& functionName,
954 VTKReaderDetail::CoefficientData
const& coefficientData,
957 using namespace VTKReaderDetail;
959 constexpr int fseCoefficientDim = FSE::StorageValueType::dimension;
960 std::size_t numComponentsToCopy = std::min(std::size_t(fseCoefficientDim), coefficientData.numComponents);
961 std::vector<std::size_t>
const& indices = coefficientData.type == pointData? pointDataIndices : cellDataIndices;
963 if(indices.size() != fse.coefficients().size())
965 std::ostringstream out;
966 out <<
"\"" << functionName <<
"\": Number of coefficients doesn't match number of data points.\nfunction info: " <<
getFunctionInfo(functionName);
967 throw Kaskade::FileIOException(out.str(), vtk.filename, __FILE__, __LINE__);
969 for(std::size_t i = 0; i < indices.size(); ++i)
971 std::size_t dataIdx = indices[i];
972 auto& block = fse.coefficients()[i];
973 auto itData = coefficientData.data.begin() + dataIdx * coefficientData.numComponents;
974 std::copy(itData, itData + numComponentsToCopy, block.begin());
An exception class for file IO errors.
An exception that can be thrown whenever a key lookup fails.
A scope guard object that automatically closes a timing section on destruction.
void restart(std::string const &name)
Start new section.
FunctionInfo getFunctionInfo(std::string const &functionName) const
Information about the expected type of function. Meet these criteria to copy values into your variabl...
std::unique_ptr< Grid > createGrid()
Create a grid from a previously loaded VTK file.
VTKReader()=default
Default constructor.
Flags
Options for getCoefficients().
@ allowCoefficientDimensionMismatch
@ allowContinuityMismatch
VTKReader(std::string const &filename)
Constructor that loads a VTK file.
void loadOnlyData(std::string const &filename)
Loads only coefficient data, omitting the grid. This can be used for time series.
void getCoefficients(VariableSet &varSet, int interpolationFlags=noInterpolation) const
Copy the data from the current VTK file into the coefficients of your FEFunctions.
std::vector< std::string > functionNames() const
Lists the functions stored in the file by their name.
void load(std::string const &filename)
Loads a VTK file.
A class for storing a heterogeneous collection of FunctionSpaceElement s.
Descriptions const * descriptions
Descriptions of variable set, of type VariableSetDescription (lots of useful infos)
FEFunctionSpace and FunctionSpaceElement and the like.
Lagrange Finite Elements.
int const LagrangeCubeShapeFunction< ctype, dimension, Scalar, O >::order
std::ostream & operator<<(std::ostream &stream, VTKReader::FunctionInfo const &info)
Information about a data set loaded from a file.