diff --git a/dune/vtk/datacollectorinterface.impl.hh b/dune/vtk/datacollectorinterface.impl.hh index eedcfd35154eb6e5380fda8abb0fb9dc0bd683b6..6457dbe8d8c45f031e45357c74ff6ae4428bbdc6 100644 --- a/dune/vtk/datacollectorinterface.impl.hh +++ b/dune/vtk/datacollectorinterface.impl.hh @@ -1,8 +1,8 @@ #pragma once #include <dune/geometry/referenceelements.hh> -#include <dune/grid/common/gridenums.hh> -#include <dune/grid/common/mcmgmapper.hh> +// #include <dune/grid/common/gridenums.hh> +// #include <dune/grid/common/mcmgmapper.hh> namespace Dune { diff --git a/dune/vtk/datacollectors/continuousdatacollector.hh b/dune/vtk/datacollectors/continuousdatacollector.hh index 192af3871be2478cec4cff1df8fadd48c90d24c2..6b9c9dcce83c756b33c577f90e7ce421726d61b0 100644 --- a/dune/vtk/datacollectors/continuousdatacollector.hh +++ b/dune/vtk/datacollectors/continuousdatacollector.hh @@ -1,10 +1,16 @@ #pragma once #include <numeric> -#include "unstructureddatacollector.hh" +#include <vector> +#include <dune/geometry/referenceelements.hh> #include <dune/grid/utility/globalindexset.hh> +#include <dune/vtk/forward.hh> +#include <dune/vtk/vtktypes.hh> + +#include "unstructureddatacollector.hh" + namespace Dune { @@ -130,7 +136,7 @@ public: return data; } -protected: +public: // protected: using Super::gridView_; std::uint64_t numPoints_ = 0; std::uint64_t numCells_ = 0; diff --git a/dune/vtk/datacollectors/discontinuousdatacollector.hh b/dune/vtk/datacollectors/discontinuousdatacollector.hh index 25089a77b33e595a5afc09df8ec54ffb664b95b7..eab3952372315889a5a226ad892a65c3a9c96c8a 100644 --- a/dune/vtk/datacollectors/discontinuousdatacollector.hh +++ b/dune/vtk/datacollectors/discontinuousdatacollector.hh @@ -1,5 +1,10 @@ #pragma once +#include <vector> + +#include <dune/vtk/forward.hh> +#include <dune/vtk/vtktypes.hh> + #include "unstructureddatacollector.hh" namespace Dune @@ -22,7 +27,7 @@ public: : Super(gridView) {} - /// Create an index map the uniquely assignes an index to each pair (element,corner) + /// Create an index map the uniquely assigns an index to each pair (element,corner) void updateImpl () { numPoints_ = 0; @@ -38,7 +43,7 @@ public: } } - /// The number of pointsi approx. #cell * #corners-per-cell + /// The number of points approx. #cell * #corners-per-cell std::uint64_t numPointsImpl () const { return numPoints_; diff --git a/dune/vtk/datacollectors/quadraticdatacollector.hh b/dune/vtk/datacollectors/quadraticdatacollector.hh index 62a1497efc340bd5a8fc92cdc68c7e638829807f..0ddee00b9028c156d017ca9f430681439b4bbb8b 100644 --- a/dune/vtk/datacollectors/quadraticdatacollector.hh +++ b/dune/vtk/datacollectors/quadraticdatacollector.hh @@ -1,5 +1,13 @@ #pragma once +#include <vector> + +#include <dune/geometry/referenceelements.hh> +#include <dune/grid/common/partitionset.hh> + +#include <dune/vtk/forward.hh> +#include <dune/vtk/vtktypes.hh> + #include "unstructureddatacollector.hh" namespace Dune diff --git a/dune/vtk/datacollectors/spdatacollector.hh b/dune/vtk/datacollectors/spdatacollector.hh index 2af97ec09badbe325ce110c61d0a132dce69e51a..25ab8be2ab1d222f8db359ac122e819ff712a010 100644 --- a/dune/vtk/datacollectors/spdatacollector.hh +++ b/dune/vtk/datacollectors/spdatacollector.hh @@ -1,9 +1,17 @@ #pragma once +#include <array> +#include <vector> + +#include <dune/common/filledarray.hh> +#include <dune/common/fvector.hh> + #if HAVE_DUNE_SPGRID #include <dune/grid/spgrid.hh> #endif +#include <dune/vtk/forward.hh> + #include "structureddatacollector.hh" namespace Dune diff --git a/dune/vtk/datacollectors/structureddatacollector.hh b/dune/vtk/datacollectors/structureddatacollector.hh index 05a9f07f9370bede3cb37a2a622ed8161c29052f..0b1d5ab5d56f42f7a5aaa932a192c1eb0cb44e6d 100644 --- a/dune/vtk/datacollectors/structureddatacollector.hh +++ b/dune/vtk/datacollectors/structureddatacollector.hh @@ -1,10 +1,13 @@ #pragma once #include <array> -#include <dune/common/filledarray.hh> +#include <vector> + #include <dune/common/fvector.hh> +#include <dune/vtk/forward.hh> #include <dune/vtk/datacollectorinterface.hh> + #include "continuousdatacollector.hh" namespace Dune diff --git a/dune/vtk/datacollectors/unstructureddatacollector.hh b/dune/vtk/datacollectors/unstructureddatacollector.hh index 802cf7c5c107f9bcf35d21c381d5bf119f71b62d..b5ff27a5dc786649ecb719887e3d08025b369405 100644 --- a/dune/vtk/datacollectors/unstructureddatacollector.hh +++ b/dune/vtk/datacollectors/unstructureddatacollector.hh @@ -3,6 +3,7 @@ #include <cstdint> #include <vector> +#include <dune/vtk/forward.hh> #include <dune/vtk/datacollectorinterface.hh> namespace Dune { diff --git a/dune/vtk/datacollectors/yaspdatacollector.hh b/dune/vtk/datacollectors/yaspdatacollector.hh index fbfe881d07181081871e80613313e553893d2757..b1f778d9df524643ac08462f6e84bf19acf4187a 100644 --- a/dune/vtk/datacollectors/yaspdatacollector.hh +++ b/dune/vtk/datacollectors/yaspdatacollector.hh @@ -1,7 +1,18 @@ #pragma once +#include <array> +#include <type_traits> +#include <vector> + +#include <dune/common/filledarray.hh> +#include <dune/common/fvector.hh> +#include <dune/common/std/type_traits.hh> + +#include <dune/grid/common/gridenums.hh> #include <dune/grid/yaspgrid.hh> +#include <dune/vtk/forward.hh> + #include "structureddatacollector.hh" namespace Dune diff --git a/dune/vtk/defaultvtkfunction.hh b/dune/vtk/defaultvtkfunction.hh index 3be31ea7f8f2802a6d8e9df7c533b96d0859da87..bb6351a857db93737327ee762ec30e501247ceed 100644 --- a/dune/vtk/defaultvtkfunction.hh +++ b/dune/vtk/defaultvtkfunction.hh @@ -1,16 +1,14 @@ #pragma once +#include <type_traits> + +#include <dune/common/fmatrix.hh> +#include <dune/common/fvector.hh> + #include "vtklocalfunctioninterface.hh" namespace Dune { - template <class T, int N> - class FieldVector; - - template <class T, int N, int M> - class FieldMatrix; - - /// Type erasure for dune-functions LocalFunction interface template <class GridView, class LocalFunction> class LocalFunctionWrapper final diff --git a/dune/vtk/forward.hh b/dune/vtk/forward.hh index 3ade39f6b098dad6e5c9df4f7363571b6a2dc2d7..3b6ac80781c03c4464ee3cf49459b15376ea8557 100644 --- a/dune/vtk/forward.hh +++ b/dune/vtk/forward.hh @@ -1,5 +1,7 @@ #pragma once +#include <dune/grid/common/partitionset.hh> + namespace Dune { // forward declaration of all classes in dune-vtk diff --git a/dune/vtk/gridcreatorinterface.hh b/dune/vtk/gridcreatorinterface.hh index e1420e504fd94a09d40fccf53d789e1a62d44b30..c8c8fb467017765aaa31722c5e46cadd0f848289 100644 --- a/dune/vtk/gridcreatorinterface.hh +++ b/dune/vtk/gridcreatorinterface.hh @@ -5,6 +5,7 @@ #include <vector> #include <dune/common/version.hh> +#include <dune/common/parallel/mpihelper.hh> #include <dune/grid/common/gridfactory.hh> #include <dune/vtk/forward.hh> @@ -34,15 +35,15 @@ namespace Dune /// Insert all points as vertices into the factory void insertVertices (std::vector<GlobalCoordinate> const& points, - std::vector<std::uint64_t> const& point_ids) + std::vector<std::uint64_t> const& point_ids) { asDerived().insertVerticesImpl(points, point_ids); } /// Create elements based on type and connectivity description void insertElements (std::vector<std::uint8_t> const& types, - std::vector<std::int64_t> const& offsets, - std::vector<std::int64_t> const& connectivity) + std::vector<std::int64_t> const& offsets, + std::vector<std::int64_t> const& connectivity) { asDerived().insertElementsImpl(types, offsets, connectivity); } @@ -80,14 +81,14 @@ namespace Dune public: // default implementations void insertVerticesImpl (std::vector<GlobalCoordinate> const&, - std::vector<std::uint64_t> const&) + std::vector<std::uint64_t> const&) { /* do nothing */ } void insertElementsImpl (std::vector<std::uint8_t> const&, - std::vector<std::int64_t> const&, - std::vector<std::int64_t> const&) + std::vector<std::int64_t> const&, + std::vector<std::int64_t> const&) { /* do nothing */ } diff --git a/dune/vtk/pvdwriter.hh b/dune/vtk/pvdwriter.hh index feef1572c989900e73002c963487bb6afd5b1158..3faec46272554844efa38672007df182a3616b8e 100644 --- a/dune/vtk/pvdwriter.hh +++ b/dune/vtk/pvdwriter.hh @@ -5,6 +5,8 @@ #include <vector> #include <tuple> +#include <dune/common/std/optional.hh> + #include <dune/vtk/vtktypes.hh> #include <dune/vtk/filewriter.hh> #include <dune/vtk/forward.hh> @@ -20,7 +22,8 @@ namespace Dune public: /// Constructor, creates a VtkWriter with constructor arguments forwarded - template <class... Args, disableCopyMove<Self,Args...> = 0> + template <class... Args, + disableCopyMove<Self,Args...> = 0> explicit PvdWriter (Args&&... args) : vtkWriter_{std::forward<Args>(args)...} { diff --git a/dune/vtk/pvdwriter.impl.hh b/dune/vtk/pvdwriter.impl.hh index 64d5ca6de3a8644df86f32dad93c8ce8d349cd32..26ff028ea050bbefc17b30b39420f1daed41c30d 100644 --- a/dune/vtk/pvdwriter.impl.hh +++ b/dune/vtk/pvdwriter.impl.hh @@ -1,6 +1,7 @@ #pragma once #include <iomanip> +#include <limits> #include <dune/vtk/utility/filesystem.hh> #include <dune/vtk/utility/string.hh> @@ -39,8 +40,8 @@ void PvdWriter<W> out.imbue(std::locale::classic()); out << std::setprecision(datatype_ == Vtk::FLOAT32 - ? std::numeric_limits<float>::digits10+2 - : std::numeric_limits<double>::digits10+2); + ? std::numeric_limits<float>::max_digits10 + : std::numeric_limits<double>::max_digits10); writeFile(out); } @@ -63,8 +64,8 @@ void PvdWriter<W> out.imbue(std::locale::classic()); out << std::setprecision(datatype_ == Vtk::FLOAT32 - ? std::numeric_limits<float>::digits10+2 - : std::numeric_limits<double>::digits10+2); + ? std::numeric_limits<float>::max_digits10 + : std::numeric_limits<double>::max_digits10); writeFile(out); } diff --git a/dune/vtk/vtkreader.hh b/dune/vtk/vtkreader.hh index b9a1b78a807449bad47434ffa66e737da2bc9f45..92aefb084590fc8033c61d0120ffa1e0888e24d5 100644 --- a/dune/vtk/vtkreader.hh +++ b/dune/vtk/vtkreader.hh @@ -2,6 +2,10 @@ #include <iosfwd> #include <map> +#include <memory> +#include <vector> + +#include <dune/common/typeutilities.hh> #include <dune/vtk/filereader.hh> #include <dune/vtk/forward.hh> @@ -41,22 +45,21 @@ namespace Dune public: /// Constructor. Creates a new GridCreator with the passed factory - template <class... Args> + template <class... Args, + disableCopyMove<VtkReader, Args...> = 0> explicit VtkReader (Args&&... args) - : creatorStorage_(std::make_unique<GridCreator>(std::forward<Args>(args)...)) - , creator_(*creatorStorage_) + : VtkReader(std::make_shared<GridCreator>(std::forward<Args>(args)...)) {} - /// Constructor. Stores a references to the passed creator - VtkReader (GridCreator& creator) - : creator_(creator) + /// Constructor. Stores the references in a non-destroying shared_ptr + explicit VtkReader (GridCreator& creator) + : VtkReader(stackobject_to_shared_ptr(creator)) {} - // disable copy and move operations - VtkReader(VtkReader const&) = delete; - VtkReader(VtkReader&&) = delete; - VtkReader& operator=(VtkReader const&) = delete; - VtkReader& operator=(VtkReader&&) = delete; + /// Constructor. Stores the shared_ptr + explicit VtkReader (std::shared_ptr<GridCreator> creator) + : creator_(std::move(creator)) + {} /// Read the grid from file with `filename` into the GridFactory \ref factory_ /** @@ -159,8 +162,7 @@ namespace Dune } private: - std::unique_ptr<GridCreator> creatorStorage_ = nullptr; - GridCreator& creator_; + std::shared_ptr<GridCreator> creator_; /// Data format, i.e. ASCII, BINARY or COMPRESSED. Read from xml attributes. Vtk::FormatTypes format_; diff --git a/dune/vtk/vtkreader.impl.hh b/dune/vtk/vtkreader.impl.hh index 3fd29ba1c1503ab5d882f9b302416ee44166a27d..9427cde1bcbad14ccd1d73b2b0597e090a60df3b 100644 --- a/dune/vtk/vtkreader.impl.hh +++ b/dune/vtk/vtkreader.impl.hh @@ -1,6 +1,6 @@ -#include <sstream> #include <fstream> #include <iterator> +#include <sstream> #include <string> #if HAVE_VTK_ZLIB @@ -518,11 +518,11 @@ void VtkReader<Grid,Creator>::createGrid (bool insertPieces) assert(vec_offsets.size() == numberOfCells_); if (!vec_points.empty()) - creator_.insertVertices(vec_points, vec_point_ids); + creator_->insertVertices(vec_points, vec_point_ids); if (!vec_types.empty()) - creator_.insertElements(vec_types, vec_offsets, vec_connectivity); + creator_->insertElements(vec_types, vec_offsets, vec_connectivity); if (insertPieces) - creator_.insertPieces(pieces_); + creator_->insertPieces(pieces_); } // Assume input already read the line <AppendedData ...> diff --git a/dune/vtk/vtktimeserieswriter.hh b/dune/vtk/vtktimeserieswriter.hh index 676ca69e0b6abc45fbefeca95f3bd73d99464166..d3f881ea599d5bdd15e1b46432d851d06473b44d 100644 --- a/dune/vtk/vtktimeserieswriter.hh +++ b/dune/vtk/vtktimeserieswriter.hh @@ -1,9 +1,12 @@ #pragma once +#include <cassert> #include <string> #include <tuple> #include <vector> +#include <dune/common/std/optional.hh> + #include <dune/vtk/filewriter.hh> #include <dune/vtk/forward.hh> #include <dune/vtk/vtktypes.hh> @@ -42,10 +45,9 @@ namespace Dune { assert(vtkWriter_.format_ != Vtk::ASCII && "Timeseries writer requires APPENDED mode"); std::srand(std::time(nullptr)); + // put temporary file to /tmp directory tmpDir_ = filesystem::path("/tmp/vtktimeserieswriter_" + uid(10) + "/"); - assert( filesystem::exists("/tmp") ); - filesystem::create_directories(tmpDir_); } /// Remove all written intermediate files and remove temporary directory diff --git a/dune/vtk/vtktimeserieswriter.impl.hh b/dune/vtk/vtktimeserieswriter.impl.hh index 1255a4f560412bbbd5ad3363f3bcfdfd8b17efac..52abdec86b63be238d209aa7a0482f903e75790d 100644 --- a/dune/vtk/vtktimeserieswriter.impl.hh +++ b/dune/vtk/vtktimeserieswriter.impl.hh @@ -42,10 +42,11 @@ void VtkTimeseriesWriter<W> ::writeTimestep (double time, std::string const& fn, Std::optional<std::string> tmpDir, bool writeCollection) const { auto name = filesystem::path(fn).stem(); - auto tmp = tmpDir ? filesystem::path(*tmpDir) : tmpDir_; + auto tmpBase = tmpDir ? filesystem::path(*tmpDir) : tmpDir_; + auto tmp = tmpBase; tmp /= name.string(); - vtkWriter_.dataCollector_.update(); + vtkWriter_.dataCollector_->update(); std::string filenameBase = tmp.string(); @@ -53,6 +54,8 @@ void VtkTimeseriesWriter<W> filenameBase = tmp.string() + "_p" + std::to_string(vtkWriter_.comm().rank()); if (!initialized_) { + filesystem::create_directories(tmpBase); + // write points and cells only once filenameMesh_ = filenameBase + ".mesh.vtkdata"; std::ofstream out(filenameMesh_, std::ios_base::ate | std::ios::binary); diff --git a/dune/vtk/vtktypes.cc b/dune/vtk/vtktypes.cc index d8becf47f686de4c69d336e4b3420121ffa16a30..3ea7b9a17cd6af3dfc3ca5108342748bbf2c4649 100644 --- a/dune/vtk/vtktypes.cc +++ b/dune/vtk/vtktypes.cc @@ -2,6 +2,8 @@ #include <iostream> +#include <dune/common/exceptions.hh> + namespace Dune { namespace Vtk { diff --git a/dune/vtk/vtkwriterinterface.hh b/dune/vtk/vtkwriterinterface.hh index 297fb3cec388025070d8f5071fa6e0a351ef318c..5f1ad2b516e5ec0302e17caa92401b791ad8823c 100644 --- a/dune/vtk/vtkwriterinterface.hh +++ b/dune/vtk/vtkwriterinterface.hh @@ -2,9 +2,11 @@ #include <iosfwd> #include <map> +#include <memory> #include <string> #include <vector> +#include <dune/common/parallel/mpihelper.hh> #include <dune/common/std/optional.hh> #include <dune/vtk/filewriter.hh> #include <dune/vtk/forward.hh> @@ -51,7 +53,14 @@ namespace Dune VtkWriterInterface (GridView const& gridView, Vtk::FormatTypes format = Vtk::BINARY, Vtk::DataTypes datatype = Vtk::FLOAT32) - : dataCollector_(gridView) + : VtkWriterInterface(std::make_shared<DataCollector>(gridView), format, datatype) + {} + + /// \brief Constructor, stores the passed DataCollector + VtkWriterInterface (std::shared_ptr<DataCollector> dataCollector, + Vtk::FormatTypes format = Vtk::BINARY, + Vtk::DataTypes datatype = Vtk::FLOAT32) + : dataCollector_(std::move(dataCollector)) , format_(format) , datatype_(datatype) { @@ -63,6 +72,7 @@ namespace Dune #endif } + /// \brief Write the attached data to the file /** * \param fn Filename of the VTK file. May contain a directory and any file extension. @@ -185,7 +195,7 @@ namespace Dune } protected: - mutable DataCollector dataCollector_; + std::shared_ptr<DataCollector> dataCollector_; Vtk::FormatTypes format_; Vtk::DataTypes datatype_; diff --git a/dune/vtk/vtkwriterinterface.impl.hh b/dune/vtk/vtkwriterinterface.impl.hh index 0a4a9bfe14814a99eeb386ea038ffc51e4d169d8..249108e6f08e6d91afc7708c6e7e628d7f08497d 100644 --- a/dune/vtk/vtkwriterinterface.impl.hh +++ b/dune/vtk/vtkwriterinterface.impl.hh @@ -5,6 +5,7 @@ #include <iostream> #include <iterator> #include <fstream> +#include <limits> #include <sstream> #include <string> @@ -25,7 +26,7 @@ template <class GV, class DC> void VtkWriterInterface<GV,DC> ::write (std::string const& fn, Std::optional<std::string> dir) const { - dataCollector_.update(); + dataCollector_->update(); auto p = filesystem::path(fn); auto name = p.stem(); @@ -48,8 +49,8 @@ void VtkWriterInterface<GV,DC> serial_out.imbue(std::locale::classic()); serial_out << std::setprecision(datatype_ == Vtk::FLOAT32 - ? std::numeric_limits<float>::digits10+2 - : std::numeric_limits<double>::digits10+2); + ? std::numeric_limits<float>::max_digits10 + : std::numeric_limits<double>::max_digits10); writeSerialFile(serial_out); } @@ -61,8 +62,8 @@ void VtkWriterInterface<GV,DC> parallel_out.imbue(std::locale::classic()); parallel_out << std::setprecision(datatype_ == Vtk::FLOAT32 - ? std::numeric_limits<float>::digits10+2 - : std::numeric_limits<double>::digits10+2); + ? std::numeric_limits<float>::max_digits10 + : std::numeric_limits<double>::max_digits10); writeParallelFile(parallel_out, rel_fn, comm().size()); } @@ -83,9 +84,9 @@ void VtkWriterInterface<GV,DC> if (format_ == Vtk::ASCII) { out << ">\n"; if (type == POINT_DATA) - writeValuesAscii(out, dataCollector_.template pointData<double>(fct)); + writeValuesAscii(out, dataCollector_->template pointData<double>(fct)); else - writeValuesAscii(out, dataCollector_.template cellData<double>(fct)); + writeValuesAscii(out, dataCollector_->template cellData<double>(fct)); out << "</DataArray>\n"; } else { out << " offset="; @@ -108,7 +109,7 @@ void VtkWriterInterface<GV,DC> if (format_ == Vtk::ASCII) { out << ">\n"; - writeValuesAscii(out, dataCollector_.template points<double>()); + writeValuesAscii(out, dataCollector_->template points<double>()); out << "</DataArray>\n"; } else { out << " offset="; @@ -124,13 +125,13 @@ void VtkWriterInterface<GV,DC> { for (auto const& v : pointData_) { blocks.push_back( v.type() == Vtk::FLOAT32 - ? this->writeValuesAppended(out, dataCollector_.template pointData<float>(v)) - : this->writeValuesAppended(out, dataCollector_.template pointData<double>(v))); + ? this->writeValuesAppended(out, dataCollector_->template pointData<float>(v)) + : this->writeValuesAppended(out, dataCollector_->template pointData<double>(v))); } for (auto const& v : cellData_) { blocks.push_back( v.type() == Vtk::FLOAT32 - ? this->writeValuesAppended(out, dataCollector_.template cellData<float>(v)) - : this->writeValuesAppended(out, dataCollector_.template cellData<double>(v))); + ? this->writeValuesAppended(out, dataCollector_->template cellData<float>(v)) + : this->writeValuesAppended(out, dataCollector_->template cellData<double>(v))); } } diff --git a/dune/vtk/writers/vtkimagedatawriter.hh b/dune/vtk/writers/vtkimagedatawriter.hh index e5260e3c512b037858529a4ca5353982f4628416..a3de09474509633b7ce6dced77d3674d8c460401 100644 --- a/dune/vtk/writers/vtkimagedatawriter.hh +++ b/dune/vtk/writers/vtkimagedatawriter.hh @@ -29,12 +29,8 @@ namespace Dune using pos_type = typename Super::pos_type; public: - /// Constructor, stores the gridView - VtkImageDataWriter (GridView const& gridView, - Vtk::FormatTypes format = Vtk::BINARY, - Vtk::DataTypes datatype = Vtk::FLOAT32) - : Super(gridView, format, datatype) - {} + /// forwarding constructor to \ref VtkWriterInterface + using Super::Super; private: /// Write a serial VTK file in Unstructured format diff --git a/dune/vtk/writers/vtkimagedatawriter.impl.hh b/dune/vtk/writers/vtkimagedatawriter.impl.hh index 0eb3c389ccf1f9c5bf087585c9f69d0b287d118d..898b076ca5fdfc0d43988cf5057b9b854a111cc8 100644 --- a/dune/vtk/writers/vtkimagedatawriter.impl.hh +++ b/dune/vtk/writers/vtkimagedatawriter.impl.hh @@ -23,16 +23,16 @@ void VtkImageDataWriter<GV,DC> std::vector<pos_type> offsets; // pos => offset this->writeHeader(out, "ImageData"); - auto const& wholeExtent = dataCollector_.wholeExtent(); - auto const& origin = dataCollector_.origin(); - auto const& spacing = dataCollector_.spacing(); + auto const& wholeExtent = dataCollector_->wholeExtent(); + auto const& origin = dataCollector_->origin(); + auto const& spacing = dataCollector_->spacing(); out << "<ImageData" << " WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\"" << " Origin=\"" << join(origin.begin(), origin.end()) << "\"" << " Spacing=\"" << join(spacing.begin(), spacing.end()) << "\"" << ">\n"; - dataCollector_.writeLocalPiece([&out](auto const& extent) { + dataCollector_->writeLocalPiece([&out](auto const& extent) { out << "<Piece Extent=\"" << join(extent.begin(), extent.end()) << "\">\n"; }); @@ -62,11 +62,11 @@ void VtkImageDataWriter<GV,DC> { this->writeHeader(out, "PImageData"); - auto const& wholeExtent = dataCollector_.wholeExtent(); - auto const& origin = dataCollector_.origin(); - auto const& spacing = dataCollector_.spacing(); + auto const& wholeExtent = dataCollector_->wholeExtent(); + auto const& origin = dataCollector_->origin(); + auto const& spacing = dataCollector_->spacing(); out << "<PImageData" - << " GhostLevel=\"" << dataCollector_.ghostLevel() << "\"" + << " GhostLevel=\"" << dataCollector_->ghostLevel() << "\"" << " WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\"" << " Origin=\"" << join(origin.begin(), origin.end()) << "\"" << " Spacing=\"" << join(spacing.begin(), spacing.end()) << "\"" @@ -95,7 +95,7 @@ void VtkImageDataWriter<GV,DC> out << "</PCellData>\n"; // Write piece file references - dataCollector_.writePieces([&out,pfilename,ext=this->fileExtension()](int p, auto const& extent, bool write_extent) + dataCollector_->writePieces([&out,pfilename,ext=this->fileExtension()](int p, auto const& extent, bool write_extent) { std::string piece_source = pfilename + "_p" + std::to_string(p) + "." + ext; out << "<Piece Source=\"" << piece_source << "\""; diff --git a/dune/vtk/writers/vtkrectilineargridwriter.hh b/dune/vtk/writers/vtkrectilineargridwriter.hh index 5bb2da2864496d65f8c4c02facbac20f187c9125..b55f2efeb2d534e41e740b37a47a6174033479be 100644 --- a/dune/vtk/writers/vtkrectilineargridwriter.hh +++ b/dune/vtk/writers/vtkrectilineargridwriter.hh @@ -29,12 +29,8 @@ namespace Dune using pos_type = typename Super::pos_type; public: - /// Constructor, stores the gridView - VtkRectilinearGridWriter (GridView const& gridView, - Vtk::FormatTypes format = Vtk::BINARY, - Vtk::DataTypes datatype = Vtk::FLOAT32) - : Super(gridView, format, datatype) - {} + /// forwarding constructor to \ref VtkWriterInterface + using Super::Super; private: /// Write a serial VTK file in Unstructured format diff --git a/dune/vtk/writers/vtkrectilineargridwriter.impl.hh b/dune/vtk/writers/vtkrectilineargridwriter.impl.hh index 8bad8f40871ef0d681d914b6bbda9b4d1280f4ea..d7be66f27493a2a9e93fe603ded13815f0e5f19c 100644 --- a/dune/vtk/writers/vtkrectilineargridwriter.impl.hh +++ b/dune/vtk/writers/vtkrectilineargridwriter.impl.hh @@ -23,12 +23,12 @@ void VtkRectilinearGridWriter<GV,DC> std::vector<pos_type> offsets; // pos => offset this->writeHeader(out, "RectilinearGrid"); - auto const& wholeExtent = dataCollector_.wholeExtent(); + auto const& wholeExtent = dataCollector_->wholeExtent(); out << "<RectilinearGrid" << " WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\"" << ">\n"; - dataCollector_.writeLocalPiece([&out](auto const& extent) { + dataCollector_->writeLocalPiece([&out](auto const& extent) { out << "<Piece Extent=\"" << join(extent.begin(), extent.end()) << "\">\n"; }); @@ -63,9 +63,9 @@ void VtkRectilinearGridWriter<GV,DC> { this->writeHeader(out, "PRectilinearGrid"); - auto const& wholeExtent = dataCollector_.wholeExtent(); + auto const& wholeExtent = dataCollector_->wholeExtent(); out << "<PRectilinearGrid" - << " GhostLevel=\"" << dataCollector_.ghostLevel() << "\"" + << " GhostLevel=\"" << dataCollector_->ghostLevel() << "\"" << " WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\"" << ">\n"; @@ -99,7 +99,7 @@ void VtkRectilinearGridWriter<GV,DC> out << "</PCellData>\n"; // Write piece file references - dataCollector_.writePieces([&out,pfilename,ext=this->fileExtension()](int p, auto const& extent, bool write_extent) + dataCollector_->writePieces([&out,pfilename,ext=this->fileExtension()](int p, auto const& extent, bool write_extent) { std::string piece_source = pfilename + "_p" + std::to_string(p) + "." + ext; out << "<Piece Source=\"" << piece_source << "\""; @@ -120,7 +120,7 @@ void VtkRectilinearGridWriter<GV,DC> { std::string names = "xyz"; if (format_ == Vtk::ASCII) { - auto coordinates = dataCollector_.template coordinates<double>(); + auto coordinates = dataCollector_->template coordinates<double>(); for (std::size_t d = 0; d < 3; ++d) { out << "<DataArray type=\"" << to_string(datatype_) << "\" Name=\"" << names[d] << "\" format=\"ascii\""; if (timestep) @@ -152,12 +152,12 @@ void VtkRectilinearGridWriter<GV,DC> // write coordinates along axis if (datatype_ == Vtk::FLOAT32) { - auto coordinates = dataCollector_.template coordinates<float>(); + auto coordinates = dataCollector_->template coordinates<float>(); blocks.push_back(this->writeValuesAppended(out, coordinates[0])); blocks.push_back(this->writeValuesAppended(out, coordinates[1])); blocks.push_back(this->writeValuesAppended(out, coordinates[2])); } else { - auto coordinates = dataCollector_.template coordinates<double>(); + auto coordinates = dataCollector_->template coordinates<double>(); blocks.push_back(this->writeValuesAppended(out, coordinates[0])); blocks.push_back(this->writeValuesAppended(out, coordinates[1])); blocks.push_back(this->writeValuesAppended(out, coordinates[2])); diff --git a/dune/vtk/writers/vtkstructuredgridwriter.hh b/dune/vtk/writers/vtkstructuredgridwriter.hh index d5c240f1926c413cbc7b7df4c979dc7a4b389db2..0089aaca63449541b70b2b369c000960c40c6878 100644 --- a/dune/vtk/writers/vtkstructuredgridwriter.hh +++ b/dune/vtk/writers/vtkstructuredgridwriter.hh @@ -29,12 +29,8 @@ namespace Dune using pos_type = typename Super::pos_type; public: - /// Constructor, stores the gridView - VtkStructuredGridWriter (GridView const& gridView, - Vtk::FormatTypes format = Vtk::BINARY, - Vtk::DataTypes datatype = Vtk::FLOAT32) - : Super(gridView, format, datatype) - {} + /// forwarding constructor to \ref VtkWriterInterface + using Super::Super; private: /// Write a serial VTK file in Unstructured format diff --git a/dune/vtk/writers/vtkstructuredgridwriter.impl.hh b/dune/vtk/writers/vtkstructuredgridwriter.impl.hh index baf7d7e083c599b901d2a10606165074f72c67dd..ec8707990614f24175c6248950d65d0d7148686e 100644 --- a/dune/vtk/writers/vtkstructuredgridwriter.impl.hh +++ b/dune/vtk/writers/vtkstructuredgridwriter.impl.hh @@ -23,10 +23,10 @@ void VtkStructuredGridWriter<GV,DC> std::vector<pos_type> offsets; // pos => offset this->writeHeader(out, "StructuredGrid"); - auto const& wholeExtent = dataCollector_.wholeExtent(); + auto const& wholeExtent = dataCollector_->wholeExtent(); out << "<StructuredGrid WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\">\n"; - dataCollector_.writeLocalPiece([&out](auto const& extent) { + dataCollector_->writeLocalPiece([&out](auto const& extent) { out << "<Piece Extent=\"" << join(extent.begin(), extent.end()) << "\">\n"; }); @@ -61,9 +61,9 @@ void VtkStructuredGridWriter<GV,DC> { this->writeHeader(out, "PStructuredGrid"); - auto const& wholeExtent = dataCollector_.wholeExtent(); + auto const& wholeExtent = dataCollector_->wholeExtent(); out << "<PStructuredGrid" - << " GhostLevel=\"" << dataCollector_.ghostLevel() << "\"" + << " GhostLevel=\"" << dataCollector_->ghostLevel() << "\"" << " WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\"" << ">\n"; @@ -98,7 +98,7 @@ void VtkStructuredGridWriter<GV,DC> out << "</PCellData>\n"; // Write piece file references - dataCollector_.writePieces([&out,pfilename,ext=this->fileExtension()](int p, auto const& extent, bool write_extent) + dataCollector_->writePieces([&out,pfilename,ext=this->fileExtension()](int p, auto const& extent, bool write_extent) { std::string piece_source = pfilename + "_p" + std::to_string(p) + "." + ext; out << "<Piece Source=\"" << piece_source << "\""; @@ -120,8 +120,8 @@ void VtkStructuredGridWriter<GV,DC> // write points blocks.push_back( datatype_ == Vtk::FLOAT32 - ? this->writeValuesAppended(out, dataCollector_.template points<float>()) - : this->writeValuesAppended(out, dataCollector_.template points<double>()) ); + ? this->writeValuesAppended(out, dataCollector_->template points<float>()) + : this->writeValuesAppended(out, dataCollector_->template points<double>()) ); } } // end namespace Dune diff --git a/dune/vtk/writers/vtkunstructuredgridwriter.hh b/dune/vtk/writers/vtkunstructuredgridwriter.hh index ee88bf7552ef1f44f005435a6c7523c2b84cc6b9..60cb9140aacc653477d60c0e063a6bb8175805ae 100644 --- a/dune/vtk/writers/vtkunstructuredgridwriter.hh +++ b/dune/vtk/writers/vtkunstructuredgridwriter.hh @@ -31,12 +31,8 @@ namespace Dune using pos_type = typename Super::pos_type; public: - /// Constructor, stores the gridView - VtkUnstructuredGridWriter (GridView const& gridView, - Vtk::FormatTypes format = Vtk::BINARY, - Vtk::DataTypes datatype = Vtk::FLOAT32) - : Super(gridView, format, datatype) - {} + /// forwarding constructor to \ref VtkWriterInterface + using Super::Super; private: /// Write a serial VTK file in Unstructured format diff --git a/dune/vtk/writers/vtkunstructuredgridwriter.impl.hh b/dune/vtk/writers/vtkunstructuredgridwriter.impl.hh index 4c4b36e5155be11cd4af1c3cc50f259fd0f67f4d..8819e22c8a73da8b5b889f9874db71ab2f028151 100644 --- a/dune/vtk/writers/vtkunstructuredgridwriter.impl.hh +++ b/dune/vtk/writers/vtkunstructuredgridwriter.impl.hh @@ -25,8 +25,8 @@ void VtkUnstructuredGridWriter<GV,DC> out << "<UnstructuredGrid>\n"; out << "<Piece" - << " NumberOfPoints=\"" << dataCollector_.numPoints() << "\"" - << " NumberOfCells=\"" << dataCollector_.numCells() << "\"" + << " NumberOfPoints=\"" << dataCollector_->numPoints() << "\"" + << " NumberOfCells=\"" << dataCollector_->numCells() << "\"" << ">\n"; // Write point coordinates @@ -129,8 +129,8 @@ void VtkUnstructuredGridWriter<GV,DC> out << "\">\n"; out << "<Piece" - << " NumberOfPoints=\"" << dataCollector_.numPoints() << "\"" - << " NumberOfCells=\"" << dataCollector_.numCells() << "\"" + << " NumberOfPoints=\"" << dataCollector_->numPoints() << "\"" + << " NumberOfCells=\"" << dataCollector_->numCells() << "\"" << ">\n"; // Write point coordinates @@ -284,7 +284,7 @@ void VtkUnstructuredGridWriter<GV,DC> Std::optional<std::size_t> timestep) const { if (format_ == Vtk::ASCII) { - auto cells = dataCollector_.cells(); + auto cells = dataCollector_->cells(); out << "<DataArray type=\"Int64\" Name=\"connectivity\" format=\"ascii\""; if (timestep) out << " TimeStep=\"" << *timestep << "\""; @@ -339,7 +339,7 @@ void VtkUnstructuredGridWriter<GV,DC> std::vector<pos_type>& offsets, Std::optional<std::size_t> timestep) const { - auto ids = dataCollector_.pointIds(); + auto ids = dataCollector_->pointIds(); if (ids.empty()) return; @@ -370,16 +370,16 @@ void VtkUnstructuredGridWriter<GV,DC> // write points blocks.push_back( datatype_ == Vtk::FLOAT32 - ? this->writeValuesAppended(out, dataCollector_.template points<float>()) - : this->writeValuesAppended(out, dataCollector_.template points<double>()) ); + ? this->writeValuesAppended(out, dataCollector_->template points<float>()) + : this->writeValuesAppended(out, dataCollector_->template points<double>()) ); // write conncetivity, offsets, and types - auto cells = dataCollector_.cells(); + auto cells = dataCollector_->cells(); blocks.push_back(this->writeValuesAppended(out, cells.connectivity)); blocks.push_back(this->writeValuesAppended(out, cells.offsets)); blocks.push_back(this->writeValuesAppended(out, cells.types)); - auto ids = dataCollector_.pointIds(); + auto ids = dataCollector_->pointIds(); if (!ids.empty()) blocks.push_back(this->writeValuesAppended(out, ids)); } diff --git a/src/vtkreader.cc b/src/vtkreader.cc index 277e47a0b81b6d5ea77b82d3e25e1c3aafb41064..5ac2fd7b0ca3e47fce50393bad1ea80887fc7959 100644 --- a/src/vtkreader.cc +++ b/src/vtkreader.cc @@ -50,6 +50,7 @@ int main(int argc, char** argv) } { + std::cout << "read 'test_ascii_float32.vtu'..." << std::endl; auto gridPtr = VtkReader<GridType>::read("test_ascii_float32.vtu"); auto& grid = *gridPtr; @@ -58,6 +59,7 @@ int main(int argc, char** argv) } { + std::cout << "read 'test_binary_float32.vtu'..." << std::endl; auto gridPtr = VtkReader<GridType>::read("test_binary_float32.vtu"); auto& grid = *gridPtr; @@ -66,6 +68,7 @@ int main(int argc, char** argv) } { + std::cout << "read 'test_compressed_float64.vtu'..." << std::endl; auto gridPtr = VtkReader<GridType>::read("test_compressed_float64.vtu"); auto& grid = *gridPtr; @@ -74,6 +77,7 @@ int main(int argc, char** argv) } { + std::cout << "read 'test_ascii_float32.vtu'..." << std::endl; auto gridPtr = VtkReader<GridType,DiscontinuousGridCreator<GridType>>::read("test_ascii_float32.vtu"); auto& grid = *gridPtr; @@ -84,6 +88,8 @@ int main(int argc, char** argv) if (filesystem::exists("paraview_3d.vtu")) { using GridType3d = UGGrid<3>; using GridView3d = typename GridType3d::LeafGridView; + + std::cout << "read 'paraview_3d.vtu'..." << std::endl; auto gridPtr = VtkReader<GridType3d>::read("paraview_3d.vtu"); auto& grid = *gridPtr; @@ -95,6 +101,7 @@ int main(int argc, char** argv) std::cout << "paraview_2d_ascii...\n"; using GridType2d = UGGrid<2>; using GridView2d = typename GridType2d::LeafGridView; + std::cout << "read 'paraview_2d.vtu'..." << std::endl; auto gridPtr = VtkReader<GridType2d>::read("paraview_2d.vtu"); auto& grid = *gridPtr;