Commit bd80ca32 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

resolved some errors after merge of pvdwriter

parent 69a0e464
......@@ -11,7 +11,7 @@ namespace Dune
virtual ~FileWriter () = default;
/// Write to file given by `filename`
virtual void write (std::string const& filename) = 0;
virtual void write (std::string const& filename) const = 0;
};
} // end namespace Dune
......@@ -6,7 +6,7 @@
#include <tuple>
#include <dune/vtk/vtktypes.hh>
#include <dune/vtk/vtkwriterinterface.hh>
// #include <dune/vtk/vtkwriterinterface.hh>
namespace Dune
{
......@@ -16,26 +16,20 @@ namespace Dune
{
using Self = PvdWriter;
static_assert(IsVtkWriter<VtkWriter>::value, "Writer must implement the VtkWriterInterface.");
// static_assert(IsVtkWriter<VtkWriter>::value, "Writer must implement the VtkWriterInterface.");
public:
/// Constructor, creates a VtkWriter with constructor arguments forwarded
template <class... Args, disableCopyMove<Self,Args...> = 0>
explicit PvdWriter (Args&&... args)
: vtkWriter_{std::forward<Args>(args)...}
{}
/// Write the attached data to the file
void write (double time, std::string const& fn)
{
write(time, fn, Vtk::BINARY);
format_ = vtkWriter_.getFormat();
datatype_ = vtkWriter_.getDatatype();
}
/// Write the attached data to the file with \ref Vtk::FormatTypes and \ref Vtk::DataTypes
void write (double time,
std::string const& fn,
Vtk::FormatTypes format,
Vtk::DataTypes datatype = Vtk::FLOAT32);
/// Write the attached data to the file
void write (double time, std::string const& fn) const;
/// Attach point data to the writer, \see VtkFunction for possible arguments
template <class Function, class... Args>
......@@ -59,9 +53,10 @@ namespace Dune
protected:
VtkWriter vtkWriter_;
std::vector<std::pair<double, std::string>> timeSeries_;
Vtk::FormatTypes format_;
Vtk::DataTypes datatype_;
mutable std::vector<std::pair<double, std::string>> timesteps_;
};
} // end namespace Dune
......
......@@ -9,23 +9,15 @@ namespace Dune {
template <class W>
void PvdWriter<W>
::write (double time, std::string const& fn, Vtk::FormatTypes format, Vtk::DataTypes datatype)
::write (double time, std::string const& fn) const
{
format_ = format;
datatype_ = datatype;
#ifndef HAVE_ZLIB
if (format_ == Vtk::COMPRESSED)
format_ = Vtk::BINARY;
#endif
auto p = filesystem::path(fn);
auto name = p.stem();
p.remove_filename();
p /= name.string();
std::string ext = "." + vtkWriter_.getFileExtension();
std::string filename = p.string() + "_t" + std::to_string(timeSeries_.size());
std::string filename = p.string() + "_t" + std::to_string(timesteps_.size());
int rank = 0;
int num_ranks = 1;
......@@ -36,8 +28,8 @@ void PvdWriter<W>
ext = ".p" + vtkWriter_.getFileExtension();
#endif
timeSeries_.emplace_back(time, filename + ext);
vtkWriter_.write(filename + ext, format_, datatype_);
timesteps_.emplace_back(time, filename + ext);
vtkWriter_.write(filename + ext);
if (rank == 0)
writeFile(time, p.string() + ".pvd");
......@@ -67,7 +59,7 @@ void PvdWriter<W>
out << "<Collection>\n";
// Write all timesteps
for (auto const& timestep : timeSeries_) {
for (auto const& timestep : timesteps_) {
out << "<DataSet"
<< " timestep=\"" << timestep.first << "\""
<< " part=\"0\""
......
......@@ -57,7 +57,7 @@ namespace Dune
/// Writes all timesteps to single timeseries file.
// NOTE: requires an aforging call to \ref writeTimestep
virtual void write (std::string const& fn) override;
virtual void write (std::string const& fn) const override;
/// Attach point data to the writer, \see VtkFunction for possible arguments
template <class Function, class... Args>
......@@ -84,8 +84,8 @@ namespace Dune
// block size of attached data
std::vector<std::uint64_t> blocks_;
std::string filenameMesh_;
std::vector<std::pair<double, std::string>> timesteps_;
mutable std::string filenameMesh_;
mutable std::vector<std::pair<double, std::string>> timesteps_;
};
} // end namespace Dune
......
......@@ -30,7 +30,7 @@ void VtkTimeseriesWriter<W>
auto tmp = tmpDir_;
tmp /= name.string();
vtkWriter_.dataCollector_.update();
vtkWriter_.update();
std::string filenameBase = tmp.string();
......@@ -60,7 +60,7 @@ void VtkTimeseriesWriter<W>
template <class W>
void VtkTimeseriesWriter<W>
::write (std::string const& fn)
::write (std::string const& fn) const
{
assert( initialized_ );
assert( timesteps_.size() < 1000 ); // maximal number of allowed timesteps in timeseries file
......@@ -96,6 +96,7 @@ void VtkTimeseriesWriter<W>
ec = std::remove(timestep.second.c_str());
assert(ec == 0);
}
timesteps_.clear();
}
} // end namespace Dune
......@@ -5,15 +5,11 @@
#include <string>
#include <vector>
<<<<<<< HEAD
#ifdef HAVE_ZLIB
#include <zlib.h>
#endif
#include <dune/common/std/optional.hh>
=======
>>>>>>> feature/pvdwriter
#include <dune/vtk/filewriter.hh>
#include <dune/vtk/vtkfunction.hh>
#include <dune/vtk/vtktypes.hh>
......@@ -64,7 +60,7 @@ namespace Dune
}
/// Write the attached data to the file
virtual void write (std::string const& fn) override;
virtual void write (std::string const& fn) const override;
/// Attach point data to the writer, \see VtkFunction for possible arguments
template <class Function, class... Args>
......@@ -141,6 +137,21 @@ namespace Dune
return fileExtension();
}
Vtk::FormatTypes getFormat () const
{
return format_;
}
Vtk::DataTypes getDatatype () const
{
return datatype_;
}
void update ()
{
dataCollector_.update();
}
protected:
mutable DataCollector dataCollector_;
......
......@@ -19,7 +19,7 @@ namespace Dune {
template <class GV, class DC>
void VtkWriterInterface<GV,DC>
::write (std::string const& fn)
::write (std::string const& fn) const
{
dataCollector_.update();
......
......@@ -18,8 +18,8 @@
#include <dune/grid/yaspgrid.hh>
#include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
#include <dune/vtk/pvdwriter.hh>
#include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
using namespace Dune;
using namespace Dune::Functions;
......@@ -39,13 +39,12 @@ void write (std::string prefix, GridView const& gridView)
auto p1Analytic = makeAnalyticGridViewFunction([&c](auto const& x) { return c.dot(x); }, gridView);
using Writer = VtkUnstructuredGridWriter<GridView>;
PvdWriter<Writer> pvdWriter(gridView);
PvdWriter<Writer> pvdWriter(gridView, Vtk::ASCII, Vtk::FLOAT32);
pvdWriter.addPointData(p1Analytic, "p1");
pvdWriter.addCellData(p1Analytic, "p0");
for (double t = 0.0; t < 10.0; t += 1.0) {
pvdWriter.write(t, prefix + "_" + std::to_string(GridView::dimension) + "d_ascii.vtu",
Vtk::ASCII, Vtk::FLOAT32);
pvdWriter.write(t, prefix + "_" + std::to_string(GridView::dimension) + "d_ascii.vtu");
}
}
......
Markdown is supported
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