Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
integrator_traits.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2025 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Matteo Caldana <matteo.caldana@polimi.it>
22
23#ifndef VULPES_ASSEMBLE_INTEGRATOR_TRAITS_HPP_
24#define VULPES_ASSEMBLE_INTEGRATOR_TRAITS_HPP_
25
26#include <tuple>
27#include <type_traits>
28#include <utility>
29
33
34namespace vulpes {
35namespace assemble {
36
37namespace internal {
38
40// check if type is a tuple
42
43// Primary template: Default case, assumes T is NOT a tuple
44template <typename T>
45struct is_tuple : std::false_type {};
46
47// Specialization: If T is a std::tuple with any types, it is a tuple
48template <typename... Args>
49struct is_tuple<std::tuple<Args...>> : std::true_type {};
50
51template <typename T>
52inline constexpr bool is_tuple_v = is_tuple<T>::value;
53
55// check if type is fe::FeExpressionBase derived
57
58// Type trait to check if a type is derived from FeExpressionBase
59template <typename T, typename = void>
60struct is_fe_expression_derived : std::false_type {};
61
62// Helper to check any dimension
63template <typename T, size_t Dim>
65 : std::bool_constant<
66 std::is_convertible_v<T*, fe::FeExpressionBase<Dim, T>*>> {};
67
68// Specialization that checks if T derives from FeExpressionBase of any
69// supported dimension
70template <typename T>
71struct is_fe_expression_derived<T, std::void_t<>>
72 : std::bool_constant<
73 is_fe_expression_derived_dim<T, 1>::value ||
74 is_fe_expression_derived_dim<T, 2>::value ||
75 is_fe_expression_derived_dim<T, 3>::value> {};
76
77// Helper variable template
78template <typename T>
79inline constexpr bool is_fe_expression_derived_v =
81
83// check if type is a tuple of fe::FeExpressionBase pointers
85
86// Check if all types inside a tuple are trivially copyable
87template <typename T, typename = void>
88struct is_tuple_of_fe_expr_pointers : std::false_type {
89}; // Default case: false
90
91// Specialization for std::tuple
92template <typename... Args>
94 std::tuple<Args...>,
95 std::enable_if_t<
96 (std::conjunction_v<std::is_pointer<Args>...>) &&
97 (std::conjunction_v<
98 is_fe_expression_derived<std::remove_pointer_t<Args>>...>)>>
99 : std::true_type {};
100
101template <typename T>
102inline constexpr bool is_tuple_of_fe_expr_pointers_v =
104
106// split a tuple in fe::Expression that are linear-bilinear
108
109// Helper: if the I-th element's type has is_bilinear==true, wrap it in a tuple;
110// otherwise, return an empty tuple.
111template <typename Tuple, std::size_t I>
112constexpr auto extract_true(Tuple&& t) {
113 if constexpr (
114 std::remove_pointer_t<
115 std::tuple_element_t<I, std::decay_t<Tuple>>>::is_bilinear ==
117 return std::make_tuple(std::get<I>(std::forward<Tuple>(t)));
118 } else {
119 return std::tuple<>{};
120 }
121}
122
123// Similarly, for false:
124template <typename Tuple, std::size_t I>
125constexpr auto extract_false(Tuple&& t) {
126 if constexpr (!(std::remove_pointer_t<std::tuple_element_t<
127 I, std::decay_t<Tuple>>>::is_bilinear ==
129 return std::make_tuple(std::get<I>(std::forward<Tuple>(t)));
130 } else {
131 return std::tuple<>{};
132 }
133}
134
135// Main implementation: iterate over all indices of the tuple.
136template <typename Tuple, std::size_t... Is>
137constexpr auto split_tuple_impl(Tuple&& t, std::index_sequence<Is...>) {
138 auto true_tuple = std::tuple_cat(extract_true<Tuple, Is>(t)...);
139 auto false_tuple = std::tuple_cat(extract_false<Tuple, Is>(t)...);
140 return std::make_pair(true_tuple, false_tuple);
141}
142
143// Convenience wrapper that deduces the tuple size.
144template <typename... Ts>
145constexpr auto split_expression_tuple(std::tuple<Ts...> t) {
146 return split_tuple_impl(t, std::index_sequence_for<Ts...>{});
147}
148} // namespace internal
149
150} // namespace assemble
151} // namespace vulpes
152
153#endif // VULPES_ASSEMBLE_INTEGRATOR_TRAITS_HPP_
Definition integrator_traits.hpp:37
constexpr bool is_tuple_v
Definition integrator_traits.hpp:52
constexpr auto split_expression_tuple(std::tuple< Ts... > t)
Definition integrator_traits.hpp:145
constexpr bool is_tuple_of_fe_expr_pointers_v
Definition integrator_traits.hpp:102
constexpr auto extract_false(Tuple &&t)
Definition integrator_traits.hpp:125
constexpr auto split_tuple_impl(Tuple &&t, std::index_sequence< Is... >)
Definition integrator_traits.hpp:137
constexpr auto extract_true(Tuple &&t)
Definition integrator_traits.hpp:112
constexpr bool is_fe_expression_derived_v
Definition integrator_traits.hpp:79
Definition cell_manager.hpp:39
@ IsBilinear
Definition fe_expr_base.hpp:55
Definition cell_manager.hpp:38
Definition integrator_traits.hpp:60
Definition integrator_traits.hpp:45