Skip to content
Snippets Groups Projects
Commit cecca335 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

moved some interface files to root directory

parent 2424e28b
No related branches found
No related tags found
No related merge requests found
Showing
with 91 additions and 53 deletions
...@@ -3,6 +3,7 @@ dune_add_library("vtktypes" OBJECT ...@@ -3,6 +3,7 @@ dune_add_library("vtktypes" OBJECT
#install headers #install headers
install(FILES install(FILES
datacollectorinterface.hh
defaultvtkfunction.hh defaultvtkfunction.hh
filereader.hh filereader.hh
filewriter.hh filewriter.hh
...@@ -15,6 +16,8 @@ install(FILES ...@@ -15,6 +16,8 @@ install(FILES
vtkreader.impl.hh vtkreader.impl.hh
vtktypes.hh vtktypes.hh
vtkwriter.hh vtkwriter.hh
vtkwriterinterface.hh
vtkwriterinterface.impl.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter)
add_subdirectory(datacollectors) add_subdirectory(datacollectors)
......
#pragma once #pragma once
#include <dune/vtk/vtktypes.hh> #include <cstdint>
#include <vector>
namespace Dune { namespace Dune {
...@@ -24,13 +25,13 @@ public: ...@@ -24,13 +25,13 @@ public:
return asDerived().ghostLevelImpl(); return asDerived().ghostLevelImpl();
} }
/// \brief Return the number of points in the grid /// Return the number of points in the grid
std::uint64_t numPoints () const std::uint64_t numPoints () const
{ {
return asDerived().numPointsImpl(); return asDerived().numPointsImpl();
} }
/// \brief Return a flat vector of point coordinates /// Return a flat vector of point coordinates
/** /**
* All coordinates are extended to 3 components and concatenated. * All coordinates are extended to 3 components and concatenated.
* [p0_x, p0_y, p0_z, p1_x, p1_y, p1_z, ...] * [p0_x, p0_y, p0_z, p1_x, p1_y, p1_z, ...]
...@@ -43,7 +44,7 @@ public: ...@@ -43,7 +44,7 @@ public:
return asDerived().template pointsImpl<T>(); return asDerived().template pointsImpl<T>();
} }
/// \brief Return a flat vector of function values evaluated at the grid points. /// Return a flat vector of function values evaluated at the points.
/** /**
* In case of a vector valued function, flat the vector entries: * In case of a vector valued function, flat the vector entries:
* [fct(p0)_0, fct(p0)_1, fct(p0)_2, fct(p1)_0, ...] * [fct(p0)_0, fct(p0)_1, fct(p0)_2, fct(p1)_0, ...]
...@@ -58,7 +59,12 @@ public: ...@@ -58,7 +59,12 @@ public:
return asDerived().template pointDataImpl<T>(fct); return asDerived().template pointDataImpl<T>(fct);
} }
/// \brief Return a flat vector of function values evaluated at the grid cells. \see pointData. /// Return a flat vector of function values evaluated at the cells. \see pointData.
/**
* Note: Cells might be descibred explicitly by connectivity, offsets, and types, e.g. in
* an UnstructuredGrid, or might be described implicitly by the grid type, e.g. in
* StructuredGrid.
*/
template <class T, class VtkFunction> template <class T, class VtkFunction>
std::vector<T> cellData (VtkFunction const& fct) const std::vector<T> cellData (VtkFunction const& fct) const
{ {
...@@ -91,24 +97,12 @@ public: // default implementations ...@@ -91,24 +97,12 @@ public: // default implementations
// Evaluate `fct` in center of cell // Evaluate `fct` in center of cell
template <class T, class VtkFunction> template <class T, class VtkFunction>
std::vector<T> cellDataImpl (VtkFunction const& fct) const std::vector<T> cellDataImpl (VtkFunction const& fct) const;
{
std::vector<T> data(gridView_.size(0) * fct.ncomps());
auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::all)) {
localFct.bind(e);
auto refElem = referenceElement<T,GridView::dimension>(e.type());
std::size_t idx = fct.ncomps() * indexSet.index(e);
for (int comp = 0; comp < fct.ncomps(); ++comp)
data[idx + comp] = T(localFct.evaluate(comp, refElem.position(0,0)));
localFct.unbind();
}
return data;
}
protected: protected:
GridView gridView_; GridView gridView_;
}; };
} // end namespace Dune } // end namespace Dune
#include "datacollectorinterface.impl.hh"
#pragma once
#include <dune/geometry/referenceelements.hh>
#include <dune/grid/common/gridenums.hh>
namespace Dune {
template <class GridView, class Derived>
template <class T, class VtkFunction>
std::vector<T> DataCollectorInterface<GridView, Derived>
::cellDataImpl (VtkFunction const& fct) const
{
std::vector<T> data(gridView_.size(0) * fct.ncomps());
auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::all)) {
localFct.bind(e);
auto refElem = referenceElement<T,GridView::dimension>(e.type());
std::size_t idx = fct.ncomps() * indexSet.index(e);
for (int comp = 0; comp < fct.ncomps(); ++comp)
data[idx + comp] = T(localFct.evaluate(comp, refElem.position(0,0)));
localFct.unbind();
}
return data;
}
} // end namespace Dune
#install headers #install headers
install(FILES install(FILES
continuousdatacollector.hh continuousdatacollector.hh
datacollectorinterface.hh
discontinuousdatacollector.hh discontinuousdatacollector.hh
quadraticdatacollector.hh quadraticdatacollector.hh
spdatacollector.hh spdatacollector.hh
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <dune/common/filledarray.hh> #include <dune/common/filledarray.hh>
#include <dune/common/fvector.hh> #include <dune/common/fvector.hh>
#include <dune/vtk/datacollectorinterface.hh>
#include "continuousdatacollector.hh" #include "continuousdatacollector.hh"
namespace Dune namespace Dune
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
#include "datacollectorinterface.hh" #include <dune/vtk/datacollectorinterface.hh>
namespace Dune { namespace Dune {
......
...@@ -24,6 +24,28 @@ namespace Dune ...@@ -24,6 +24,28 @@ namespace Dune
{ {
using type = VtkUnstructuredGridWriter<GridView>; using type = VtkUnstructuredGridWriter<GridView>;
}; };
}
/// \brief Default choice of VTK Writer for several grid types.
/**
* Choose a VTK writer depending on the grid type. Some specialization for standard dune-grid grids
* are provided, like YaspGrid and GeometrGrid.
*
* Note: Uses the default data-collector. If you want to choose a special data-collector, use
* the concrete write Implementation instead.
**/
template <class GridView>
using VtkWriter = typename Impl::VtkWriterImpl<GridView, typename GridView::Grid>::type;
namespace Impl
{
// A structured grid with constant spacing in x, y, and z direction.
template <class GridView, int dim, class Coordinates>
struct VtkWriterImpl<GridView, YaspGrid<dim,Coordinates>>
{
using type = VtkImageDataWriter<GridView, YaspDataCollector<GridView>>;
};
#if HAVE_DUNE_SPGRID #if HAVE_DUNE_SPGRID
// A structured grid with constant spacing in x, y, and z direction. // A structured grid with constant spacing in x, y, and z direction.
...@@ -34,13 +56,6 @@ namespace Dune ...@@ -34,13 +56,6 @@ namespace Dune
}; };
#endif #endif
// A structured grid with constant spacing in x, y, and z direction.
template <class GridView, int dim, class Coordinates>
struct VtkWriterImpl<GridView, YaspGrid<dim,Coordinates>>
{
using type = VtkImageDataWriter<GridView, YaspDataCollector<GridView>>;
};
// A structured grid with coordinates in x, y, and z direction with arbitrary spacing // A structured grid with coordinates in x, y, and z direction with arbitrary spacing
template <class GridView, int dim, class ct> template <class GridView, int dim, class ct>
struct VtkWriterImpl<GridView, YaspGrid<dim,TensorProductCoordinates<ct,dim>>> struct VtkWriterImpl<GridView, YaspGrid<dim,TensorProductCoordinates<ct,dim>>>
...@@ -57,10 +72,4 @@ namespace Dune ...@@ -57,10 +72,4 @@ namespace Dune
}; };
} // end namespace Impl } // end namespace Impl
/// Default choice for several grid types, uses the default data-collector.
template <class GridView>
using VtkWriter = typename Impl::VtkWriterImpl<GridView, typename GridView::Grid>::type;
} // end namespace Dune } // end namespace Dune
#pragma once #pragma once
#include <array>
#include <iosfwd> #include <iosfwd>
#include <map> #include <map>
#include <string>
#include <vector>
#include <dune/common/std/optional.hh> #include <dune/common/std/optional.hh>
...@@ -104,15 +105,7 @@ namespace Dune ...@@ -104,15 +105,7 @@ namespace Dune
std::uint64_t writeAppended (std::ofstream& out, std::vector<T> const& values) const; std::uint64_t writeAppended (std::ofstream& out, std::vector<T> const& values) const;
/// Return PointData/CellData attributes for the name of the first scalar/vector/tensor DataArray /// Return PointData/CellData attributes for the name of the first scalar/vector/tensor DataArray
std::string getNames (std::vector<VtkFunction> const& data) const std::string getNames (std::vector<VtkFunction> const& data) const;
{
auto scalar = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 1; });
auto vector = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 3; });
auto tensor = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 9; });
return (scalar != data.end() ? " Scalars=\"" + scalar->name() + "\"" : "")
+ (vector != data.end() ? " Vectors=\"" + vector->name() + "\"" : "")
+ (tensor != data.end() ? " Tensors=\"" + tensor->name() + "\"" : "");
}
// Returns endianness // Returns endianness
std::string getEndian () const std::string getEndian () const
......
#pragma once #pragma once
#include <algorithm>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
...@@ -236,4 +237,17 @@ std::uint64_t VtkWriterInterface<GV,DC> ...@@ -236,4 +237,17 @@ std::uint64_t VtkWriterInterface<GV,DC>
return std::uint64_t(end_pos - begin_pos); return std::uint64_t(end_pos - begin_pos);
} }
template <class GV, class DC>
std::string VtkWriterInterface<GV,DC>
::getNames (std::vector<VtkFunction> const& data) const
{
auto scalar = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 1; });
auto vector = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 3; });
auto tensor = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 9; });
return (scalar != data.end() ? " Scalars=\"" + scalar->name() + "\"" : "")
+ (vector != data.end() ? " Vectors=\"" + vector->name() + "\"" : "")
+ (tensor != data.end() ? " Tensors=\"" + tensor->name() + "\"" : "");
}
} // end namespace Dune } // end namespace Dune
...@@ -8,6 +8,4 @@ install(FILES ...@@ -8,6 +8,4 @@ install(FILES
vtkstructuredgridwriter.impl.hh vtkstructuredgridwriter.impl.hh
vtkunstructuredgridwriter.hh vtkunstructuredgridwriter.hh
vtkunstructuredgridwriter.impl.hh vtkunstructuredgridwriter.impl.hh
vtkwriterinterface.hh
vtkwriterinterface.impl.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter/writers) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter/writers)
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <dune/vtk/vtktypes.hh> #include <dune/vtk/vtktypes.hh>
#include <dune/vtk/datacollectors/structureddatacollector.hh> #include <dune/vtk/datacollectors/structureddatacollector.hh>
#include "vtkwriterinterface.hh" #include <dune/vtk/vtkwriterinterface.hh>
namespace Dune namespace Dune
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <dune/vtk/vtktypes.hh> #include <dune/vtk/vtktypes.hh>
#include <dune/vtk/datacollectors/structureddatacollector.hh> #include <dune/vtk/datacollectors/structureddatacollector.hh>
#include "vtkwriterinterface.hh" #include <dune/vtk/vtkwriterinterface.hh>
namespace Dune namespace Dune
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <dune/vtk/vtktypes.hh> #include <dune/vtk/vtktypes.hh>
#include <dune/vtk/datacollectors/structureddatacollector.hh> #include <dune/vtk/datacollectors/structureddatacollector.hh>
#include "vtkwriterinterface.hh" #include <dune/vtk/vtkwriterinterface.hh>
namespace Dune namespace Dune
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <dune/vtk/vtktypes.hh> #include <dune/vtk/vtktypes.hh>
#include <dune/vtk/datacollectors/continuousdatacollector.hh> #include <dune/vtk/datacollectors/continuousdatacollector.hh>
#include "vtkwriterinterface.hh" #include <dune/vtk/vtkwriterinterface.hh>
namespace Dune namespace Dune
{ {
......
...@@ -77,9 +77,9 @@ void write_yaspgrid(std::integral_constant<int,dim>) ...@@ -77,9 +77,9 @@ void write_yaspgrid(std::integral_constant<int,dim>)
{ {
using GridType = YaspGrid<dim>; using GridType = YaspGrid<dim>;
FieldVector<double,dim> upperRight; upperRight = 1.0; FieldVector<double,dim> upperRight; upperRight = 1.0;
auto numElements = filledArray<dim,int>(16); auto numElements = filledArray<dim,int>(12);
GridType grid(upperRight,numElements,0,0); GridType grid(upperRight,numElements,0,0);
grid.globalRefine(3); grid.globalRefine(1);
write("yasp_" + std::to_string(dim) + "d_", grid.leafGridView()); write("yasp_" + std::to_string(dim) + "d_", grid.leafGridView());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment