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