dune-vtk 2.12
Loading...
Searching...
No Matches
componentmapper.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 <cassert>
6#include <type_traits>
7
12
13namespace Dune::Vtk {
14
16{
17 // Evaluate a component of a vector valued data
18 template <class T, int N, int M>
19 static double map (int comp, FieldMatrix<T,N,M> const& mat)
20 {
21 int r = comp / M;
22 int c = comp % M;
23 return r < N && c < M ? double(mat[r][c]) : 0.0;
24 }
25
26 // Evaluate a component of a vector valued data
27 template <class T, int N>
28 static double map (int comp, FieldVector<T,N> const& vec)
29 {
30 return comp < N ? double(vec[comp]) : 0.0;
31 }
32
33 // Evaluate a component of a vector valued data
34 template <class T,
36 static double map (int comp, T const& value)
37 {
38 return value[comp];
39 }
40
41 // Return the scalar values
42 template <class T,
44 static double map (int comp, T const& value)
45 {
46 assert(comp == 0);
47 return value;
48 }
49
50
51 template <class D, class F>
52 static auto mapImpl (int comp, D const& x, F const& f, Dune::PriorityTag<2>)
53 -> decltype(f.evaluate(comp,x))
54 {
55 return f.evaluate(comp,x);
56 }
57
58 template <class D, class F>
59 static auto mapImpl (int comp, D const& x, F const& f, Dune::PriorityTag<1>)
60 -> decltype(map(comp, f(x)))
61 {
62 return map(comp, f(x));
63 }
64
65 template <class D, class F>
66 static double mapImpl (int comp, D const& x, F const& f, Dune::PriorityTag<0>)
67 {
68 DUNE_THROW(Dune::NotImplemented, "Evaluation of the grid function is not implemented");
69 return 0.0;
70 }
71
72 template <class D, class F>
73 static double map (int comp, D const& x, F const& f)
74 {
75 return mapImpl(comp,x,f,Dune::PriorityTag<3>{});
76 }
77};
78
79} // end namespace Dune::Vtk
Definition datacollector.hh:19
Matrix & mat
static constexpr size_type M()
static constexpr size_type N()
#define DUNE_THROW(E,...)
Implementation of DataCollector for cells, with continuous data.
Definition celltypedatacollector.hh:20
Definition componentmapper.hh:16
static auto mapImpl(int comp, D const &x, F const &f, Dune::PriorityTag< 1 >) -> decltype(map(comp, f(x)))
Definition componentmapper.hh:59
static auto mapImpl(int comp, D const &x, F const &f, Dune::PriorityTag< 2 >) -> decltype(f.evaluate(comp, x))
Definition componentmapper.hh:52
static double map(int comp, FieldMatrix< T, N, M > const &mat)
Definition componentmapper.hh:19
static double mapImpl(int comp, D const &x, F const &f, Dune::PriorityTag< 0 >)
Definition componentmapper.hh:66
static double map(int comp, D const &x, F const &f)
Definition componentmapper.hh:73
static double map(int comp, FieldVector< T, N > const &vec)
Definition componentmapper.hh:28
static double map(int comp, T const &value)
Definition componentmapper.hh:36