dune-vtk 2.12
Loading...
Searching...
No Matches
gridfunctions/common.hh
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4
8
9namespace Dune::Vtk
10{
12 struct PointContext {};
13
15 struct CellContext {};
16
18
28 template <class GridCreator, class Range, class Context>
30 {
31 using type = void;
32 };
33
34
35 template <class Element, class Range, class Domain>
37 {
38 using DerivativeRange = typename Functions::DefaultDerivativeTraits<Range(Domain)>::Range;
39 void bind (Element const& element) { /* do nothing */ };
40 void unbind () { /* do nothing */ }
41 DerivativeRange operator() (Domain const& local) const
42 {
44 "The derivative is not implemented.");
45 }
46 };
47
48 namespace Impl
49 {
50 template <class Range>
51 struct ConstructRange
52 {
53 template <class Field>
54 static Range apply (int size, Field const& value);
55 };
56
57
58 template <class Range, class Field>
59 Range constructRange (int size, Field const& value)
60 {
61 return ConstructRange<Range>::apply (size,value);
62 }
63
64 template <class T, int n>
65 struct ConstructRange<Dune::FieldVector<T,n>>
66 {
67 template <class Field>
68 static Dune::FieldVector<T,n> apply ([[maybe_unused]] int size, Field const& value)
69 {
70 assert(size == n);
71 return Dune::FieldVector<T,n>(value);
72 }
73 };
74
75 template <class T>
76 struct ConstructRange<Dune::DynamicVector<T>>
77 {
78 template <class Field>
79 static Dune::DynamicVector<T> apply (int size, Field const& value)
80 {
81 return Dune::DynamicVector<T>(size,T(value));
82 }
83 };
84
85
87 template <class Range, class Wrapper>
88 Range unwrapRange (Wrapper const& wrapper)
89 {
90 if constexpr (std::is_arithmetic_v<Range>)
91 return wrapper[0];
92 else
93 return Range(wrapper);
94 }
95
96
97 template <class Range>
98 struct ResizeRange
99 {
100 static void apply (Range& range, int size);
101 };
102
103
104 template <class Range>
105 void resizeRange (Range& range, int size)
106 {
107 ResizeRange<Range>::apply(range,size);
108 }
109
110 template <class T, int n>
111 struct ResizeRange<Dune::FieldVector<T,n>>
112 {
113 static void apply ([[maybe_unused]] Dune::FieldVector<T,n>& range, [[maybe_unused]] int size)
114 {
115 assert(n == size);
116 }
117 };
118
119 template <class T>
120 struct ResizeRange<Dune::DynamicVector<T>>
121 {
122 static void apply (Dune::DynamicVector<T>& range, int size)
123 {
124 range.resize(size);
125 }
126 };
127
128 } // end namespace Impl
129
130} // end namespace Dune::Vtk
Definition writer.hh:16
int size() const
static constexpr IntegralRange< T > range(T from, T to) noexcept
virtual void operator()()=0
#define DUNE_THROW(E,...)
LocalIndex & local()
Context indicating that a GridFunction generates a local-function from point data.
Definition gridfunctions/common.hh:12
Context indicating that a GridFunction generates a local-function from cell data.
Definition gridfunctions/common.hh:15
Type-Traits to associate a GridFunction to a GridCreator.
Definition gridfunctions/common.hh:30
void type
Definition gridfunctions/common.hh:31
Definition gridfunctions/common.hh:37
void unbind()
Definition gridfunctions/common.hh:40
void bind(Element const &element)
Definition gridfunctions/common.hh:39
typename Functions::DefaultDerivativeTraits< Range(Domain)>::Range DerivativeRange
Definition gridfunctions/common.hh:38
T apply(T... args)