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

cleanup include files and add constructors for datacollector and gridcreators

parent 80c0ff52
#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 {
......
#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;
......
#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_;
......
#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
......
#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
......
#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
......
......@@ -3,6 +3,7 @@
#include <cstdint>
#include <vector>
#include <dune/vtk/forward.hh>
#include <dune/vtk/datacollectorinterface.hh>
namespace Dune {
......
#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
......
#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
......
#pragma once
#include <dune/grid/common/partitionset.hh>
namespace Dune
{
// forward declaration of all classes in dune-vtk
......
......@@ -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 */
}
......
......@@ -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)...}
{
......
#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);
}
......
......@@ -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_;
......
#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 ...>
......
#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
......
......@@ -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);
......
......@@ -2,6 +2,8 @@
#include <iostream>
#include <dune/common/exceptions.hh>
namespace Dune {
namespace Vtk {
......
......@@ -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_;
......
......@@ -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)));
}
}
......
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