dune-vtk 2.12
Loading...
Searching...
No Matches
spdatacollector.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3#pragma once
4
5#include <array>
6#include <vector>
7
10
12
13#if HAVE_DUNE_SPGRID
14#include <dune/grid/spgrid.hh>
15
16namespace Dune::Vtk
17{
18 // Specialization for SPGrid
19 template <class GridView>
20 class SPDataCollector
21 : public StructuredDataCollectorInterface<GridView, SPDataCollector<GridView>>
22 {
23 using Self = SPDataCollector;
24 using Super = StructuredDataCollectorInterface<GridView, Self>;
25 using ctype = typename GridView::ctype;
26
27 public:
28 using Super::dim;
29 using Super::partition;
30 using Super::gridView;
31
32 public:
33 SPDataCollector (GridView const& gridView)
34 : Super(gridView)
35 , wholeExtent_(filledArray<6,int>(0))
36 , extent_(filledArray<6,int>(0))
37 , origin_(0.0)
38 , spacing_(0.0)
39 {}
40
41 std::array<int, 6> const& wholeExtentImpl () const
42 {
43 return wholeExtent_;
44 }
45
46 std::array<int, 6> const& extentImpl () const
47 {
48 return extent_;
49 }
50
51 auto const& originImpl () const
52 {
53 return origin_;
54 }
55
56 auto const& spacingImpl () const
57 {
58 return spacing_;
59 }
60
61 void updateImpl ()
62 {
64
65 auto const& localMesh = gridView().impl().gridLevel().localMesh();
66 auto const& begin = gridView().impl().gridLevel().globalMesh().begin();
67 auto const& end = gridView().impl().gridLevel().globalMesh().end();
68 auto const& cube = gridView().grid().domain().cube();
69
70 for (int i = 0; i < dim; ++i) {
71 wholeExtent_[2*i] = begin[i];
72 wholeExtent_[2*i+1] = end[i];
73 extent_[2*i] = localMesh.begin()[i];
74 extent_[2*i+1] = localMesh.end()[i];
75 spacing_[i] = cube.width()[i] / (end[i] - begin[i]);
76 origin_[i] = cube.origin()[i];
77 }
78 }
79
80 private:
81 std::array<int, 6> wholeExtent_;
82 std::array<int, 6> extent_;
83 FieldVector<ctype,3> origin_;
84 FieldVector<ctype,3> spacing_;
86 };
87
88 namespace Impl
89 {
90 template <class GridView, class ct, int dim, template< int > class Ref, class Comm>
91 struct StructuredDataCollectorImpl<GridView, SPGrid<ct,dim,Ref,Comm>>
92 {
93 using type = SPDataCollector<GridView>;
94 };
95 }
96
97} // end namespace Dune::Vtk
98
99#endif // HAVE_DUNE_SPGRID
Definition datacollector.hh:19
constexpr std::array< T, n > filledArray(const T &t)
iterator end()
iterator begin()
size_type dim() const
GridView(const Implementation &imp)
GV GridView
Type of the bound grid view.
Definition datacollectorinterface.hh:23
GridView const & gridView() const
Return the bound grid view.
Definition datacollectorinterface.hh:41
void updateImpl()
Definition datacollectorinterface.hh:131
void updateImpl()
Update the mapper.
Definition celltypedatacollector.hh:49
@ dim
Definition datacollectorinterface.hh:29
static constexpr auto partition
The partitionset to collect data from.
Definition datacollectorinterface.hh:26