Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
baseclass.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUFEM_FORMS_BASECLASS_HH
8#define DUNE_FUFEM_FORMS_BASECLASS_HH
9
10#include <array>
11#include <cstddef>
12#include <type_traits>
13#include <tuple>
14#include <utility>
15
19
20
21
22namespace Dune::Fufem::Forms::Impl {
23
24 template<class Tuple, class F>
25 void forEachTupleEntry(Tuple&& tuple, F&& f){
26 std::apply([&](auto&&... entry){
27 (f(std::forward<decltype(entry)>(entry)), ...);
28 }, tuple);
29 }
30
31
32
33} // namespace Dune::Fufem::Forms::Impl
34
35
36
37namespace Dune::Fufem::Forms {
38
39
40
72 template<std::size_t k>
74 public:
75 static constexpr std::size_t arity = k;
76 };
77
89 template<std::size_t k>
91 {
92 public:
93 static constexpr std::size_t argIndex = k;
94 };
95
96 // Forward declaration
97 template<class Operator, class... Operators>
98 class SumOperator;
99
100
101
102namespace Impl {
103
104
105 std::false_type isOperatorHelper(const void*)
106 {
107 return {};
108 }
109
110 template<std::size_t k>
111 std::true_type isOperatorHelper(const MultilinearOperator<k>*)
112 {
113 return {};
114 }
115
116 template<class T>
117 struct IsSumOperatorHelper : std::false_type {};
118
119 template<class... Op>
120 struct IsSumOperatorHelper<SumOperator<Op...>> : std::true_type {};
121
122}
123
124
125
131 template<class Op>
132 using IsOperator = decltype(Impl::isOperatorHelper(std::declval<const std::decay_t<Op>*>()));
133
139 template<class Op>
140 inline constexpr bool isOperator_v = IsOperator<Op>::value;
141
142
143
149 template<class Op>
150 using IsSumOperator = Impl::IsSumOperatorHelper<std::decay_t<Op>>;
151
157 template<class Op>
159
160
161
167 template<class Op>
169
175 template<class Op>
177
178} // namespace Dune::Fufem::Forms
179
180
181
182
183namespace Dune::Fufem::Forms::Impl {
184
185 // Execute callback on first LocalView in list, that belongs to the basis
186 // and return true if any matching LocalView was found.
187 template<class F, class Basis, class... LocalViews>
188 bool visitMatchingLocalView(F&& f, const Basis& basis, LocalViews&&... localViews)
189 {
190 auto visitIfMatching = [&](const auto& localView) {
191 if constexpr (std::is_same_v<Basis, typename std::decay_t<decltype(localView)>::GlobalBasis>)
192 if (&localView.globalBasis() == &basis)
193 {
194 f(localView);
195 return true;
196 }
197 return false;
198 };
199 return (false || ... || visitIfMatching(localViews));
200 }
201
202} // namespace Dune::Fufem::Forms::Impl
203
204
205
206#endif // DUNE_FUFEM_FORMS_BASECLASS_HH
Impl::IsSumOperatorHelper< std::decay_t< Op > > IsSumOperator
Traits class for checking if Op is a SumOperator.
Definition baseclass.hh:150
decltype(Impl::isOperatorHelper(std::declval< const std::decay_t< Op > * >())) IsOperator
Traits class for checking if Op is derived from MultilinearOperator<k>
Definition baseclass.hh:132
constexpr bool isOperator_v
Short cut for IsOperator<Op>::value.
Definition baseclass.hh:140
constexpr bool isOperatorOrSumOperator_v
Short cut for IsOperatorOrSumOperator<Op>::value.
Definition baseclass.hh:176
constexpr bool isSumOperator_v
Short cut for IsSumOperator<Op>::value.
Definition baseclass.hh:158
Definition baseclass.hh:22
Base class for multilinear operator implementations.
Definition baseclass.hh:73
static constexpr std::size_t arity
Definition baseclass.hh:75
Base class for unary multilinear operator implementations.
Definition baseclass.hh:91
static constexpr std::size_t argIndex
Definition baseclass.hh:93
Sum of several multilinear operators.
Definition sumoperator.hh:38
T apply(T... args)
T declval(T... args)
T forward(T... args)
T is_same_v