dune-vtk 2.12
Loading...
Searching...
No Matches
continuousgridfunction.hh
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4#include <vector>
5
10
11namespace Dune::Vtk
12{
14 template <class GridType, class RangeType, class Context>
16 {
17 using Grid = GridType;
18 using Field = typename Dune::FieldTraits<RangeType>::field_type;
20
21 // The range must fulfill the DenseVector interface. Scalar types
22 // are simply wrapped into a FieldVector<T,1> on extraction. This
23 // can then be converted into the type `T` on evaluation.
26
27 public:
28 struct EntitySet
29 {
30 using Grid = GridType;
31 using Element = typename GridType::template Codim<0>::Entity;
32 using LocalCoordinate = typename Element::Geometry::LocalCoordinate;
33 using GlobalCoordinate = typename Element::Geometry::GlobalCoordinate;
34 };
35
39
40 private:
41 template <class LC>
42 class PointDataLocalFunction
43 {
44 // NOTE: local finite-element fixed to Lagrange P1/Q1
45 using LFECache = LagrangeLocalFiniteElementCache<Field,Field,LC::mydimension,1>;
46 using LFE = typename LFECache::FiniteElementType;
47 using LB = typename LFE::Traits::LocalBasisType;
48
49 public:
50 using LocalContext = LC;
51 using Domain = typename LC::Geometry::LocalCoordinate;
52 using Range = RangeType;
53 using Signature = Range(Domain);
54
55 public:
56 PointDataLocalFunction (Factory const* factory, std::vector<Field> const* values, unsigned int comp)
57 : factory_(factory)
58 , values_(values)
59 , comp_(comp)
60 {}
61
62 PointDataLocalFunction () = default;
63
64 void bind (LocalContext const& element)
65 {
66 lfe_ = &cache_.get(element.type());
67
68 // collect values on vertices
69 // NOTE: assumes, that Lagrange nodes are ordered like element vertices
70 localValues_.resize(element.subEntities(Grid::dimension));
71 for (unsigned int i = 0; i < element.subEntities(Grid::dimension); ++i) {
72 unsigned int idx = factory_->insertionIndex(element.template subEntity<Grid::dimension>(i));
73 auto& v = localValues_[i];
74 Impl::resizeRange(v, comp_);
75 for (unsigned int j = 0; j < comp_; ++j)
76 v[j] = (*values_)[comp_*idx + j];
77 }
78 }
79
80 void unbind ()
81 {
82 lfe_ = nullptr;
83 }
84
85 Range operator() (Domain const& local) const
86 {
87 assert(!!lfe_);
88 auto const& lb = lfe_->localBasis();
89 lb.evaluateFunction(local, shapeValues_);
90 assert(shapeValues_.size() == localValues_.size());
91
92 auto y = Impl::constructRange<RangeWrapperType>(comp_, 0);
93 for (std::size_t i = 0; i < shapeValues_.size(); ++i)
94 y.axpy(shapeValues_[i], localValues_[i]);
95
96 return Range(y);
97 }
98
99 friend DummyLocalFunctionDerivative<LocalContext,Range,Domain> derivative (PointDataLocalFunction const&) { return {}; }
100
101 private:
102 Factory const* factory_ = nullptr;
103 std::vector<Field> const* values_ = nullptr;
104 unsigned int comp_;
105
106 // Local Finite-Element
107 LFECache cache_;
108 LFE const* lfe_ = nullptr;
109
110 // cache of local values
113 };
114
115 template <class LC>
116 class CellDataLocalFunction
117 {
118 public:
119 using LocalContext = LC;
120 using Domain = typename LC::Geometry::LocalCoordinate;
121 using Range = RangeType;
122 using Signature = Range(Domain);
123
124 public:
125 CellDataLocalFunction (Factory const* factory, std::vector<Field> const* values, unsigned int comp)
126 : factory_(factory)
127 , values_(values)
128 , comp_(comp)
129 {}
130
131 CellDataLocalFunction () = default;
132
133 void bind (LocalContext const& element)
134 {
135 unsigned int idx = factory_->insertionIndex(element);
136
137 // collect values on cells
138 auto& v = localValue_;
139 Impl::resizeRange(v,comp_);
140 for (unsigned int j = 0; j < comp_; ++j)
141 v[j] = (*values_)[comp_*idx + j];
142 }
143
144 void unbind ()
145 {}
146
147 Range operator() (Domain const& local) const
148 {
149 return Range(localValue_);
150 }
151
152 private:
153 Factory const* factory_ = nullptr;
154 std::vector<Field> const* values_ = nullptr;
155 unsigned int comp_;
156
157 // cache of local values
158 RangeWrapperType localValue_;
159 };
160
161 template <class LC>
163 PointDataLocalFunction<LC>,
164 CellDataLocalFunction<LC>>;
165
166 public:
167 template <class GridCreator>
168 ContinuousGridFunction (GridCreator const& creator, std::vector<Field> const& values,
169 std::string name, unsigned int ncomps, Vtk::DataTypes dataType,
170 std::vector<std::uint8_t> const& /*types*/,
171 std::vector<std::int64_t> const& /*offsets*/,
172 std::vector<std::int64_t> const& /*connectivity*/)
173 : factory_(&creator.factory())
174 , values_(&values)
175 , name_(std::move(name))
176 , ncomps_(ncomps)
177 , dataType_(dataType)
178 {}
179
181
183 {
184 DUNE_THROW(Dune::NotImplemented, "Evaluation in global coordinates not implemented.");
185 return Impl::constructRange<Range>(ncomps_, 0);
186 }
187
188 EntitySet const& entitySet () const
189 {
190 return entitySet_;
191 }
192
193 std::string const& name () const
194 {
195 return name_;
196 }
197
198 int numComponents () const
199 {
200 return ncomps_;
201 }
202
204 {
205 return dataType_;
206 }
207
209 {
210 return {gf.factory_, gf.values_, gf.ncomps_};
211 }
212
213 private:
214 Factory const* factory_;
215 std::vector<Field> const* values_ = nullptr;
216 std::string name_ = "GridFunction";
217 unsigned int ncomps_ = 0;
219
220 EntitySet entitySet_;
221 };
222
223} // end namespace Dune::Vtk
STL namespace.
Definition writer.hh:16
std::decay_t< std::invoke_result_t< F, D > > RangeType
Result type of the function F when called with an argument of type D.
Definition rangetype.hh:21
DataTypes
Definition types.hh:51
virtual void operator()()=0
#define DUNE_THROW(E,...)
const GlobalIndex & global() const
LocalIndex & local()
A GridFunction representing data stored on the grid vertices in a continuous manner.
Definition continuousgridfunction.hh:16
typename EntitySet::GlobalCoordinate Domain
Definition continuousgridfunction.hh:36
std::string const & name() const
Definition continuousgridfunction.hh:193
RangeType Range
Definition continuousgridfunction.hh:37
int numComponents() const
Definition continuousgridfunction.hh:198
ContinuousGridFunction(GridCreator const &creator, std::vector< Field > const &values, std::string name, unsigned int ncomps, Vtk::DataTypes dataType, std::vector< std::uint8_t > const &, std::vector< std::int64_t > const &, std::vector< std::int64_t > const &)
Definition continuousgridfunction.hh:168
Range(Domain) Signature
Definition continuousgridfunction.hh:38
friend LocalFunction< typename EntitySet::Element > localFunction(ContinuousGridFunction const &gf)
Definition continuousgridfunction.hh:208
Vtk::DataTypes dataType() const
Definition continuousgridfunction.hh:203
EntitySet const & entitySet() const
Definition continuousgridfunction.hh:188
Definition continuousgridfunction.hh:29
GridType Grid
Definition continuousgridfunction.hh:30
typename Element::Geometry::GlobalCoordinate GlobalCoordinate
Definition continuousgridfunction.hh:33
typename Element::Geometry::LocalCoordinate LocalCoordinate
Definition continuousgridfunction.hh:32
typename GridType::template Codim< 0 >::Entity Element
Definition continuousgridfunction.hh:31
T bind(T... args)