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

restructuring of structureddatacollector

parent 45d5d9a8
No related branches found
No related tags found
No related merge requests found
...@@ -97,6 +97,14 @@ private: ...@@ -97,6 +97,14 @@ private:
std::vector<std::size_t> indexMap_; std::vector<std::size_t> indexMap_;
}; };
#endif namespace Impl
{
template<class GridView, class ct, int dim, template< int > class Ref, class Comm>
struct StructuredDataCollector<GridView, SPGrid<ct,dim,Ref,Comm>>
{
using type = SPDataCollector<GridView>;
};
}
#endif // HAVE_DUNE_SPGRID
}} // end namespace Dune::experimental }} // end namespace Dune::experimental
...@@ -4,6 +4,19 @@ ...@@ -4,6 +4,19 @@
namespace Dune { namespace experimental namespace Dune { namespace experimental
{ {
namespace Impl
{
// Should be specialized for concrete structured grid
template <class GridView, class Grid>
struct StructuredDataCollector;
}
template <class GridView>
using StructuredDataCollector = typename Impl::StructuredDataCollector<GridView, typename GridView::Grid>::type;
/// The Interface for structured data-collectors
template <class GridView, class Derived> template <class GridView, class Derived>
class StructuredDataCollectorInterface class StructuredDataCollectorInterface
: public DataCollectorInterface<GridView, Derived> : public DataCollectorInterface<GridView, Derived>
......
...@@ -121,4 +121,13 @@ private: ...@@ -121,4 +121,13 @@ private:
int level_; int level_;
}; };
namespace Impl
{
template<class GridView, int dim, class Coordinates>
struct StructuredDataCollector<GridView, YaspGrid<dim,Coordinates>>
{
using type = YaspDataCollector<GridView>;
};
}
}} // end namespace Dune::experimental }} // end namespace Dune::experimental
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
namespace Dune { namespace experimental namespace Dune { namespace experimental
{ {
/// File-Writer for VTK .vtu files /// File-Writer for VTK .vtu files
template <class GridView, class DataCollector> template <class GridView, class DataCollector = StructuredDataCollector<GridView>>
class VtkImageDataWriter class VtkImageDataWriter
: public VtkWriter<GridView, DataCollector> : public VtkWriter<GridView, DataCollector>
{ {
......
...@@ -9,11 +9,12 @@ ...@@ -9,11 +9,12 @@
#include "vtkfunction.hh" #include "vtkfunction.hh"
#include "vtktypes.hh" #include "vtktypes.hh"
#include "vtkwriter.hh" #include "vtkwriter.hh"
#include "datacollectors/structureddatacollector.hh"
namespace Dune { namespace experimental namespace Dune { namespace experimental
{ {
/// File-Writer for VTK .vtu files /// File-Writer for VTK .vtu files
template <class GridView, class DataCollector> template <class GridView, class DataCollector = StructuredDataCollector<GridView>>
class VtkStructuredGridWriter class VtkStructuredGridWriter
: public VtkWriter<GridView, DataCollector> : public VtkWriter<GridView, DataCollector>
{ {
......
...@@ -29,63 +29,26 @@ using namespace Dune; ...@@ -29,63 +29,26 @@ using namespace Dune;
using namespace Dune::experimental; using namespace Dune::experimental;
using namespace Dune::Functions; using namespace Dune::Functions;
namespace Impl_
{
template <class GridView, class Grid>
struct StructuredDataCollector;
#if HAVE_DUNE_SPGRID
template<class GridView, class ct, int dim, template< int > class Ref, class Comm>
struct StructuredDataCollector<GridView, SPGrid<ct,dim,Ref,Comm>>
{
using type = SPDataCollector<GridView>;
};
#endif
template<class GridView, int dim, class Coordinates>
struct StructuredDataCollector<GridView, YaspGrid<dim,Coordinates>>
{
using type = YaspDataCollector<GridView>;
};
}
template <class GridView>
using StructuredDataCollector = typename Impl_::StructuredDataCollector<GridView, typename GridView::Grid>::type;
template <int dim> template <int dim>
using int_ = std::integral_constant<int,dim>; using int_ = std::integral_constant<int,dim>;
template <class GridView> template <class GridView>
void write(std::string prefix, GridView const& gridView) void write(std::string prefix, GridView const& gridView)
{ {
using namespace BasisFactory;
auto basis = makeBasis(gridView, lagrange<1>());
std::vector<double> p1function(basis.dimension());
interpolate(basis, p1function, [](auto const& x) {
return 100*x[0] + 10*x[1] + 1*x[2];
});
auto fct1 = makeDiscreteGlobalBasisFunction<double>(basis, p1function);
auto fct2 = makeAnalyticGridViewFunction([](auto const& x) { auto fct2 = makeAnalyticGridViewFunction([](auto const& x) {
return std::sin(10*x[0])*std::cos(10*x[1])+std::sin(10*x[2]); return std::sin(10*x[0])*std::cos(10*x[1])+std::sin(10*x[2]);
}, gridView); }, gridView);
{ {
using Writer = VtkStructuredGridWriter<GridView, StructuredDataCollector<GridView>>; using Writer = VtkStructuredGridWriter<GridView>;
Writer vtkWriter(gridView); Writer vtkWriter(gridView);
vtkWriter.addPointData(fct1, "p1");
vtkWriter.addCellData(fct1, "p0");
vtkWriter.addPointData(fct2, "analytic"); vtkWriter.addPointData(fct2, "analytic");
vtkWriter.write(prefix + "sg_ascii_float32.vts", Vtk::ASCII); vtkWriter.write(prefix + "sg_ascii_float32.vts", Vtk::ASCII);
} }
{ {
using Writer = VtkImageDataWriter<GridView, StructuredDataCollector<GridView>>; using Writer = VtkImageDataWriter<GridView>;
Writer vtkWriter(gridView); Writer vtkWriter(gridView);
vtkWriter.addPointData(fct1, "p1");
vtkWriter.addCellData(fct1, "p0");
vtkWriter.addPointData(fct2, "analytic"); vtkWriter.addPointData(fct2, "analytic");
vtkWriter.write(prefix + "id_ascii_float32.vti", Vtk::ASCII); vtkWriter.write(prefix + "id_ascii_float32.vti", Vtk::ASCII);
} }
...@@ -98,6 +61,7 @@ void write_yaspgrid(std::integral_constant<int,dim>) ...@@ -98,6 +61,7 @@ void write_yaspgrid(std::integral_constant<int,dim>)
FieldVector<double,dim> upperRight; upperRight = 1.0; FieldVector<double,dim> upperRight; upperRight = 1.0;
auto numElements = filledArray<dim,int>(8); auto numElements = filledArray<dim,int>(8);
GridType grid(upperRight,numElements,0,0); GridType grid(upperRight,numElements,0,0);
grid.globalRefine(1);
write("yasp_" + std::to_string(dim) + "d_", grid.leafGridView()); write("yasp_" + std::to_string(dim) + "d_", grid.leafGridView());
} }
...@@ -110,6 +74,7 @@ void write_spgrid(std::integral_constant<int,dim>) ...@@ -110,6 +74,7 @@ void write_spgrid(std::integral_constant<int,dim>)
FieldVector<double,dim> upperRight; upperRight = 1.0; FieldVector<double,dim> upperRight; upperRight = 1.0;
auto numElements = filledArray<dim,int>(8); auto numElements = filledArray<dim,int>(8);
GridType grid(SPDomain<double,dim>::unitCube(),numElements); GridType grid(SPDomain<double,dim>::unitCube(),numElements);
grid.globalRefine(1);
write("sp_" + std::to_string(dim) + "d_", grid.leafGridView()); write("sp_" + std::to_string(dim) + "d_", grid.leafGridView());
#endif #endif
......
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