LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
mesh_function_traits.h
1
11#ifndef INCG7e4ffaa81e244723acbfbbaea68e03b1
12#define INCG7e4ffaa81e244723acbfbbaea68e03b1
13
14#include <lf/mesh/mesh.h>
15
16#include <concepts>
17#include <type_traits>
18
19namespace lf::mesh::utils {
20namespace internal {
21
22// TODO(craffael): Replace this with std::invoke_result_t once issue in msvc is
23// fixed: https://github.com/microsoft/STL/issues/1288
24template <class T>
25using MeshFunctionReturnType_t = decltype(std::declval<T>()(
26 std::declval<const Entity>(), std::declval<const Eigen::MatrixXd>()));
27
28template <typename>
29struct VectorElementType {
30 using type = void;
31};
32
33template <typename T, typename A>
34struct VectorElementType<std::vector<T, A>> {
35 using type = T;
36};
37
38template <class T>
39using VectorElement_t = typename VectorElementType<T>::type;
40
41template <class T, class RETURN_TYPE>
42 requires(!std::is_same_v<VectorElement_t<MeshFunctionReturnType_t<T>>, void>)
43constexpr bool IsMeshFunctionCallable(int /*unused*/) {
44 if constexpr (std::is_same_v<RETURN_TYPE, void>) {
45 // user didn't want us to check whether the return type is something
46 // particular
47 return true;
48 }
49 // user specified a RETURN_TYPE -> Check that std::vector<RETURN_TYPE> is
50 // returned.
51 return std::is_same_v<VectorElement_t<MeshFunctionReturnType_t<T>>,
52 RETURN_TYPE>;
53}
54
55template <class T, class RETURN_TYPE>
56constexpr bool IsMeshFunctionCallable(long /*unused*/) {
57 return false;
58}
59
60} // namespace internal
61
148template <class MF, class R = void>
150 // @note We use IsMeshFunctionCallable here because otherwise e.g.
151 // Eigen::Matrix also fulfills the concept of a MeshFunction (even though it
152 // leads to compile errors during instantiation)
153 std::is_object_v<MF> && std::copy_constructible<MF> &&
154 internal::IsMeshFunctionCallable<MF, R>(0);
155
163template <class R>
166 MeshFunctionAT(const MeshFunctionAT&) noexcept = default;
167
169 MeshFunctionAT(MeshFunctionAT&&) noexcept = default;
170
172 auto operator=(const MeshFunctionAT&) noexcept -> MeshFunctionAT& = delete;
173
175 auto operator=(MeshFunctionAT&&) noexcept -> MeshFunctionAT& = delete;
176
178 ~MeshFunctionAT() noexcept = default;
179
188 // NOLINTBEGIN(misc-unused-parameters)
189 std::vector<R> operator()(const Entity& e,
190 const Eigen::MatrixXd& local) const {
191 // NOLINTEND(misc-unused-parameters)
192 LF_VERIFY_MSG(false, "Should never be called, this is an archetype");
193 return {};
194 }
195};
196
201template <class R>
203 internal::VectorElement_t<internal::MeshFunctionReturnType_t<R>>;
204
205} // namespace lf::mesh::utils
206
207#endif // INCG7e4ffaa81e244723acbfbbaea68e03b1
Interface class representing a topological entity in a cellular complex
Definition entity.h:42
A MeshFunction is a function object that can be evaluated at any point on the mesh.
Contains helper functions and classes that all operate on the interface classes defined in lf::mesh.
internal::VectorElement_t< internal::MeshFunctionReturnType_t< R > > MeshFunctionReturnType
Determine the type of objects returned by a MeshFunction.
Archetype for the MeshFunction concept.
MeshFunctionAT(MeshFunctionAT &&) noexcept=default
Move constructor.
MeshFunctionAT(const MeshFunctionAT &) noexcept=default
Copy constructor.