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