diff --git a/src/amdis/io/DuneVtkWriter.hpp b/src/amdis/io/DuneVtkWriter.hpp index e6164c35d8efec4441c920e2b4bdf702d78c7bae..11fe4abfed182781a9dc96c9d26cbf8ea36746dd 100644 --- a/src/amdis/io/DuneVtkWriter.hpp +++ b/src/amdis/io/DuneVtkWriter.hpp @@ -15,20 +15,24 @@ namespace AMDiS { /// Adapter for the dune-vtk writer - template + /** + * \tparam GV GridView describing the grid to write + * \tparam GF GridFunction defined on that GridView + **/ + template class DuneVtkWriter : public FileWriterBase { - using GridView = typename GB::GridView; + using GridView = GV; using Writer = Dune::VtkWriter; using SeqWriter = Dune::PvdWriter; - using Function = DiscreteFunction; + using GridFunction = GF; public: /// Constructor. - DuneVtkWriter(std::string const& name, Function const& discreteFct) + DuneVtkWriter(std::string const& name, GridView const& gridView, GridFunction const& gridFunction) : FileWriterBase(name) - , discreteFct_(discreteFct) + , gridFunction_(gridFunction) { int m = 0, p = 0; Parameters::get(name + "->animation", animation_); @@ -45,11 +49,11 @@ namespace AMDiS Dune::Vtk::FLOAT64; if (animation_) { - vtkSeqWriter_ = std::make_shared(gridView(), mode, precision); - vtkSeqWriter_->addPointData(discreteFct_, this->name()); + vtkSeqWriter_ = std::make_shared(gridView, mode, precision); + vtkSeqWriter_->addPointData(gridFunction_, this->name()); } else { - vtkWriter_ = std::make_shared(gridView(), mode, precision); - vtkWriter_->addPointData(discreteFct_, this->name()); + vtkWriter_ = std::make_shared(gridView, mode, precision); + vtkWriter_->addPointData(gridFunction_, this->name()); } } @@ -69,14 +73,7 @@ namespace AMDiS } private: - /// The Gridview this writer lives on. Given by the discrete function. - GridView const& gridView() const - { - return discreteFct_.basis()->gridView(); - } - - private: - Function discreteFct_; + GridFunction gridFunction_; std::shared_ptr vtkWriter_; std::shared_ptr vtkSeqWriter_; @@ -85,6 +82,14 @@ namespace AMDiS bool animation_ = false; }; + + /// Generator function for \ref DuneVtkWriter + template + DuneVtkWriter makeDuneVtkWriter(std::string const& name, GridView const& gridView, GridFunction const& gridFunction) + { + return {name, gridView, gridFunction}; + } + } // end namespace AMDiS #endif // HAVE_DUNE_VTK diff --git a/src/amdis/io/FileWriterCreator.hpp b/src/amdis/io/FileWriterCreator.hpp index fe46c7306224165adc22fa5ee84264f5b56045af..2c74bb158a95b1da77134a3ecb984cbaec92b1be 100644 --- a/src/amdis/io/FileWriterCreator.hpp +++ b/src/amdis/io/FileWriterCreator.hpp @@ -51,31 +51,32 @@ namespace AMDiS } private: - template + template std::unique_ptr - create_impl(std::string type, std::string prefix, DiscreteFunction const& data, ValCat) const + create_impl(std::string type, std::string prefix, Data const& data, ValCat) const { + GridView const& gridView = systemVector_->basis()->gridView(); + // ParaView VTK format, writer from dune-grid if (type == "vtk") { - return std::make_unique>(prefix, data); + return std::make_unique>(prefix, gridView, data); } #if HAVE_DUNE_VTK // ParaView VTK format, writer from dune-vtk else if (type == "dune-vtk") { - return std::make_unique>(prefix, data); + return std::make_unique>(prefix, gridView, data); } #endif // GMsh file format, writing just the grid and optionally boundary ids else if (type == "gmsh") { - GridView const& gridView = systemVector_->basis()->gridView(); if (!!boundaryManager_) - return std::make_unique>(prefix, gridView, + return std::make_unique>(prefix, gridView, std::vector{}, boundaryManager_->boundaryIds()); else - return std::make_unique>(prefix, gridView); + return std::make_unique>(prefix, gridView); } // Backup writer, writing the grid and the solution vector else if (type == "backup") @@ -90,9 +91,9 @@ namespace AMDiS } // The value-category is unknown, like a composite/hierarchic vector or any unknown type. - template + template std::unique_ptr - create_impl(std::string type, std::string prefix, DiscreteFunction const& /*data*/, tag::unknown) const + create_impl(std::string type, std::string prefix, Data const& /*data*/, tag::unknown) const { // Backup writer, writing the grid and the solution vector if (type == "backup") diff --git a/src/amdis/io/GmshWriter.hpp b/src/amdis/io/GmshWriter.hpp index 0082680c87b1e590a8e8d639b5399f85c679a850..4ba79d534d84fd782d5e96e99bd6c2a63506ee18 100644 --- a/src/amdis/io/GmshWriter.hpp +++ b/src/amdis/io/GmshWriter.hpp @@ -15,6 +15,9 @@ namespace AMDiS { /// The GmshWriter just writes the grid of a given gridView to a gmsh compatible .msh file + /** + * \tparam GV GridView describing the grid to write + **/ template class GmshWriter : public FileWriterBase @@ -28,7 +31,6 @@ namespace AMDiS std::vector const& physicalEntities = std::vector(), std::vector const& physicalBoundaries = std::vector()) : FileWriterBase(name) - , gridView_(gridView) , physicalEntities_(physicalEntities) , physicalBoundaries_(physicalBoundaries) { @@ -40,7 +42,7 @@ namespace AMDiS ? std::numeric_limits::max_digits10 : std::numeric_limits::max_digits10; - writer_ = std::make_shared(gridView_, precision); + writer_ = std::make_shared(gridView, precision); } /// Implements \ref FileWriterBase::write @@ -59,7 +61,6 @@ namespace AMDiS } private: - GridView gridView_; std::vector const& physicalEntities_; std::vector const& physicalBoundaries_; diff --git a/src/amdis/io/VTKWriter.hpp b/src/amdis/io/VTKWriter.hpp index b85ff48c3fa31e0a2cb557875a363af3656e29f9..ee504c67fb50784db3980bb15a4e4cddcf6c4766 100644 --- a/src/amdis/io/VTKWriter.hpp +++ b/src/amdis/io/VTKWriter.hpp @@ -36,16 +36,20 @@ namespace AMDiS /// Adapter for the dune-grid VTKWriter - template + /** + * \tparam GV GridView describing the grid to write + * \tparam GF GridFunction defined on that GridView + **/ + template class VTKWriter : public FileWriterBase { - using GridView = typename GB::GridView; + using GridView = GV; using Writer = Dune::VTKWriter; using SeqWriter = VTKSequenceWriter; - using Function = DiscreteFunction; - using Range = typename Function::Range; + using GridFunction = GF; + using Range = typename GridFunction::Range; template static constexpr Dune::VTK::FieldInfo::Type VTKFieldType() { @@ -59,9 +63,9 @@ namespace AMDiS public: /// Constructor. - VTKWriter(std::string const& name, Function const& discreteFct) + VTKWriter(std::string const& name, GridView const& gridView, GridFunction const& gridFunction) : FileWriterBase(name) - , discreteFct_(discreteFct) + , gridFunction_(gridFunction) { int m = 0; Parameters::get(name + "->animation", animation_); @@ -74,15 +78,15 @@ namespace AMDiS auto subSampling = Parameters::get(name + "->subsampling"); if (subSampling) { using SubsamplingWriter = Dune::SubsamplingVTKWriter; - vtkWriter_ = std::make_shared(gridView(), subSampling.value()); + vtkWriter_ = std::make_shared(gridView, subSampling.value()); } else { - vtkWriter_ = std::make_shared(gridView()); + vtkWriter_ = std::make_shared(gridView); } if (animation_) vtkSeqWriter_ = std::make_shared(vtkWriter_); - vtkWriter_->addVertexData(discreteFct_, + vtkWriter_->addVertexData(gridFunction_, Dune::VTK::FieldInfo(name_, VTKFieldType(), VTKFieldSize())); } @@ -99,14 +103,7 @@ namespace AMDiS } private: - /// The Gridview this writer lives on. Given by the discrete function. - GridView const& gridView() const - { - return discreteFct_.basis()->gridView(); - } - - private: - Function discreteFct_; + GridFunction gridFunction_; std::shared_ptr vtkWriter_; std::shared_ptr vtkSeqWriter_; @@ -117,4 +114,12 @@ namespace AMDiS Dune::VTK::OutputType mode_ = Dune::VTK::ascii; }; + + /// Generator function for \ref VTKWriter + template + VTKWriter makeVTKWriter(std::string const& name, GridView const& gridView, GridFunction const& gridFunction) + { + return {name, gridView, gridFunction}; + } + } // end namespace AMDiS