Commit 5d07110f authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

writers for general gridfunction

parent 81bcc9de
...@@ -15,20 +15,24 @@ ...@@ -15,20 +15,24 @@
namespace AMDiS namespace AMDiS
{ {
/// Adapter for the dune-vtk writer /// Adapter for the dune-vtk writer
template <class GB, class VT, class TP> /**
* \tparam GV GridView describing the grid to write
* \tparam GF GridFunction defined on that GridView
**/
template <class GV, class GF>
class DuneVtkWriter class DuneVtkWriter
: public FileWriterBase : public FileWriterBase
{ {
using GridView = typename GB::GridView; using GridView = GV;
using Writer = Dune::VtkWriter<GridView>; using Writer = Dune::VtkWriter<GridView>;
using SeqWriter = Dune::PvdWriter<Writer>; using SeqWriter = Dune::PvdWriter<Writer>;
using Function = DiscreteFunction<GB,VT,TP,true>; using GridFunction = GF;
public: public:
/// Constructor. /// Constructor.
DuneVtkWriter(std::string const& name, Function const& discreteFct) DuneVtkWriter(std::string const& name, GridView const& gridView, GridFunction const& gridFunction)
: FileWriterBase(name) : FileWriterBase(name)
, discreteFct_(discreteFct) , gridFunction_(gridFunction)
{ {
int m = 0, p = 0; int m = 0, p = 0;
Parameters::get(name + "->animation", animation_); Parameters::get(name + "->animation", animation_);
...@@ -45,11 +49,11 @@ namespace AMDiS ...@@ -45,11 +49,11 @@ namespace AMDiS
Dune::Vtk::FLOAT64; Dune::Vtk::FLOAT64;
if (animation_) { if (animation_) {
vtkSeqWriter_ = std::make_shared<SeqWriter>(gridView(), mode, precision); vtkSeqWriter_ = std::make_shared<SeqWriter>(gridView, mode, precision);
vtkSeqWriter_->addPointData(discreteFct_, this->name()); vtkSeqWriter_->addPointData(gridFunction_, this->name());
} else { } else {
vtkWriter_ = std::make_shared<Writer>(gridView(), mode, precision); vtkWriter_ = std::make_shared<Writer>(gridView, mode, precision);
vtkWriter_->addPointData(discreteFct_, this->name()); vtkWriter_->addPointData(gridFunction_, this->name());
} }
} }
...@@ -69,14 +73,7 @@ namespace AMDiS ...@@ -69,14 +73,7 @@ namespace AMDiS
} }
private: private:
/// The Gridview this writer lives on. Given by the discrete function. GridFunction gridFunction_;
GridView const& gridView() const
{
return discreteFct_.basis()->gridView();
}
private:
Function discreteFct_;
std::shared_ptr<Writer> vtkWriter_; std::shared_ptr<Writer> vtkWriter_;
std::shared_ptr<SeqWriter> vtkSeqWriter_; std::shared_ptr<SeqWriter> vtkSeqWriter_;
...@@ -85,6 +82,14 @@ namespace AMDiS ...@@ -85,6 +82,14 @@ namespace AMDiS
bool animation_ = false; bool animation_ = false;
}; };
/// Generator function for \ref DuneVtkWriter
template <class GridView, class GridFunction>
DuneVtkWriter<GridView, GridFunction> makeDuneVtkWriter(std::string const& name, GridView const& gridView, GridFunction const& gridFunction)
{
return {name, gridView, gridFunction};
}
} // end namespace AMDiS } // end namespace AMDiS
#endif // HAVE_DUNE_VTK #endif // HAVE_DUNE_VTK
...@@ -51,31 +51,32 @@ namespace AMDiS ...@@ -51,31 +51,32 @@ namespace AMDiS
} }
private: private:
template <class GB, class VT, class TP, class ValCat> template <class Data, class ValCat>
std::unique_ptr<FileWriterInterface> std::unique_ptr<FileWriterInterface>
create_impl(std::string type, std::string prefix, DiscreteFunction<GB,VT,TP,true> 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 // ParaView VTK format, writer from dune-grid
if (type == "vtk") if (type == "vtk")
{ {
return std::make_unique<VTKWriter<GB,VT,TP>>(prefix, data); return std::make_unique<VTKWriter<GridView,Data>>(prefix, gridView, data);
} }
#if HAVE_DUNE_VTK #if HAVE_DUNE_VTK
// ParaView VTK format, writer from dune-vtk // ParaView VTK format, writer from dune-vtk
else if (type == "dune-vtk") else if (type == "dune-vtk")
{ {
return std::make_unique<DuneVtkWriter<GB,VT,TP>>(prefix, data); return std::make_unique<DuneVtkWriter<GridView,Data>>(prefix, gridView, data);
} }
#endif #endif
// GMsh file format, writing just the grid and optionally boundary ids // GMsh file format, writing just the grid and optionally boundary ids
else if (type == "gmsh") else if (type == "gmsh")
{ {
GridView const& gridView = systemVector_->basis()->gridView();
if (!!boundaryManager_) if (!!boundaryManager_)
return std::make_unique<GmshWriter<typename GB::GridView>>(prefix, gridView, return std::make_unique<GmshWriter<GridView>>(prefix, gridView,
std::vector<int>{}, boundaryManager_->boundaryIds()); std::vector<int>{}, boundaryManager_->boundaryIds());
else else
return std::make_unique<GmshWriter<typename GB::GridView>>(prefix, gridView); return std::make_unique<GmshWriter<GridView>>(prefix, gridView);
} }
// Backup writer, writing the grid and the solution vector // Backup writer, writing the grid and the solution vector
else if (type == "backup") else if (type == "backup")
...@@ -90,9 +91,9 @@ namespace AMDiS ...@@ -90,9 +91,9 @@ namespace AMDiS
} }
// The value-category is unknown, like a composite/hierarchic vector or any unknown type. // The value-category is unknown, like a composite/hierarchic vector or any unknown type.
template <class GB, class VT, class TP> template <class Data>
std::unique_ptr<FileWriterInterface> std::unique_ptr<FileWriterInterface>
create_impl(std::string type, std::string prefix, DiscreteFunction<GB,VT,TP,true> 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 // Backup writer, writing the grid and the solution vector
if (type == "backup") if (type == "backup")
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
namespace AMDiS namespace AMDiS
{ {
/// The GmshWriter just writes the grid of a given gridView to a gmsh compatible .msh file /// 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 GV> template <class GV>
class GmshWriter class GmshWriter
: public FileWriterBase : public FileWriterBase
...@@ -28,7 +31,6 @@ namespace AMDiS ...@@ -28,7 +31,6 @@ namespace AMDiS
std::vector<int> const& physicalEntities = std::vector<int>(), std::vector<int> const& physicalEntities = std::vector<int>(),
std::vector<int> const& physicalBoundaries = std::vector<int>()) std::vector<int> const& physicalBoundaries = std::vector<int>())
: FileWriterBase(name) : FileWriterBase(name)
, gridView_(gridView)
, physicalEntities_(physicalEntities) , physicalEntities_(physicalEntities)
, physicalBoundaries_(physicalBoundaries) , physicalBoundaries_(physicalBoundaries)
{ {
...@@ -40,7 +42,7 @@ namespace AMDiS ...@@ -40,7 +42,7 @@ namespace AMDiS
? std::numeric_limits<float>::max_digits10 ? std::numeric_limits<float>::max_digits10
: std::numeric_limits<double>::max_digits10; : std::numeric_limits<double>::max_digits10;
writer_ = std::make_shared<Writer>(gridView_, precision); writer_ = std::make_shared<Writer>(gridView, precision);
} }
/// Implements \ref FileWriterBase::write /// Implements \ref FileWriterBase::write
...@@ -59,7 +61,6 @@ namespace AMDiS ...@@ -59,7 +61,6 @@ namespace AMDiS
} }
private: private:
GridView gridView_;
std::vector<int> const& physicalEntities_; std::vector<int> const& physicalEntities_;
std::vector<int> const& physicalBoundaries_; std::vector<int> const& physicalBoundaries_;
......
...@@ -36,16 +36,20 @@ namespace AMDiS ...@@ -36,16 +36,20 @@ namespace AMDiS
/// Adapter for the dune-grid VTKWriter /// Adapter for the dune-grid VTKWriter
template <class GB, class VT, class TP> /**
* \tparam GV GridView describing the grid to write
* \tparam GF GridFunction defined on that GridView
**/
template <class GV, class GF>
class VTKWriter class VTKWriter
: public FileWriterBase : public FileWriterBase
{ {
using GridView = typename GB::GridView; using GridView = GV;
using Writer = Dune::VTKWriter<GridView>; using Writer = Dune::VTKWriter<GridView>;
using SeqWriter = VTKSequenceWriter<GridView>; using SeqWriter = VTKSequenceWriter<GridView>;
using Function = DiscreteFunction<GB,VT,TP,true>; using GridFunction = GF;
using Range = typename Function::Range; using Range = typename GridFunction::Range;
template <class R> template <class R>
static constexpr Dune::VTK::FieldInfo::Type VTKFieldType() { static constexpr Dune::VTK::FieldInfo::Type VTKFieldType() {
...@@ -59,9 +63,9 @@ namespace AMDiS ...@@ -59,9 +63,9 @@ namespace AMDiS
public: public:
/// Constructor. /// Constructor.
VTKWriter(std::string const& name, Function const& discreteFct) VTKWriter(std::string const& name, GridView const& gridView, GridFunction const& gridFunction)
: FileWriterBase(name) : FileWriterBase(name)
, discreteFct_(discreteFct) , gridFunction_(gridFunction)
{ {
int m = 0; int m = 0;
Parameters::get(name + "->animation", animation_); Parameters::get(name + "->animation", animation_);
...@@ -74,15 +78,15 @@ namespace AMDiS ...@@ -74,15 +78,15 @@ namespace AMDiS
auto subSampling = Parameters::get<int>(name + "->subsampling"); auto subSampling = Parameters::get<int>(name + "->subsampling");
if (subSampling) { if (subSampling) {
using SubsamplingWriter = Dune::SubsamplingVTKWriter<GridView>; using SubsamplingWriter = Dune::SubsamplingVTKWriter<GridView>;
vtkWriter_ = std::make_shared<SubsamplingWriter>(gridView(), subSampling.value()); vtkWriter_ = std::make_shared<SubsamplingWriter>(gridView, subSampling.value());
} else { } else {
vtkWriter_ = std::make_shared<Writer>(gridView()); vtkWriter_ = std::make_shared<Writer>(gridView);
} }
if (animation_) if (animation_)
vtkSeqWriter_ = std::make_shared<SeqWriter>(vtkWriter_); vtkSeqWriter_ = std::make_shared<SeqWriter>(vtkWriter_);
vtkWriter_->addVertexData(discreteFct_, vtkWriter_->addVertexData(gridFunction_,
Dune::VTK::FieldInfo(name_, VTKFieldType<Range>(), VTKFieldSize<Range>())); Dune::VTK::FieldInfo(name_, VTKFieldType<Range>(), VTKFieldSize<Range>()));
} }
...@@ -99,14 +103,7 @@ namespace AMDiS ...@@ -99,14 +103,7 @@ namespace AMDiS
} }
private: private:
/// The Gridview this writer lives on. Given by the discrete function. GridFunction gridFunction_;
GridView const& gridView() const
{
return discreteFct_.basis()->gridView();
}
private:
Function discreteFct_;
std::shared_ptr<Writer> vtkWriter_; std::shared_ptr<Writer> vtkWriter_;
std::shared_ptr<SeqWriter> vtkSeqWriter_; std::shared_ptr<SeqWriter> vtkSeqWriter_;
...@@ -117,4 +114,12 @@ namespace AMDiS ...@@ -117,4 +114,12 @@ namespace AMDiS
Dune::VTK::OutputType mode_ = Dune::VTK::ascii; Dune::VTK::OutputType mode_ = Dune::VTK::ascii;
}; };
/// Generator function for \ref VTKWriter
template <class GridView, class GridFunction>
VTKWriter<GridView, GridFunction> makeVTKWriter(std::string const& name, GridView const& gridView, GridFunction const& gridFunction)
{
return {name, gridView, gridFunction};
}
} // end namespace AMDiS } // end namespace AMDiS
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment