Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
Invert.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Maikel Nadolski
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #ifndef FUB_GEOMETRY_INVERT_HPP
22 #define FUB_GEOMETRY_INVERT_HPP
23 
24 #include "fub/core/type_traits.hpp"
25 
26 #include <array>
27 
28 namespace fub {
29 namespace meta {
30 template <typename T, typename... Args>
32  decltype(std::declval<T>().ComputeDistanceTo(std::declval<Args>()...));
33 }
34 
35 template <typename Base> class Invert : private Base {
36 public:
37  Invert(const Base& base) : Base(base) {}
38 
39  [[nodiscard]] double ComputeDistanceTo(std::array<double, 3> x) const
40  noexcept {
41  if constexpr (is_detected<meta::ComputeDistanceTo, const Base&,
42  std::array<double, 3>>()) {
43  return -Base::ComputeDistanceTo(x);
44  } else if constexpr (is_detected<meta::ComputeDistanceTo, const Base&,
45  std::array<double, 2>>()) {
46  std::array<double, 2> proj{x[0], x[1]};
47  return -Base::ComputeDistanceTo(proj);
48  } else {
49  return -Base::ComputeDistanceTo(x[0]);
50  }
51  }
52 
53  [[nodiscard]] double ComputeDistanceTo(std::array<double, 2> x) const
54  noexcept {
55  if constexpr (is_detected<meta::ComputeDistanceTo, const Base&,
56  std::array<double, 2>>()) {
57  return -Base::ComputeDistanceTo(x);
58  } else if constexpr (is_detected<meta::ComputeDistanceTo, const Base&,
59  std::array<double, 3>>()) {
60  std::array<double, 3> proj{x[0], x[1]};
61  return -Base::ComputeDistanceTo(proj);
62  } else {
63  return -Base::ComputeDistanceTo(x[0]);
64  }
65  }
66 };
67 
68 } // namespace fub
69 
70 #endif
Definition: Invert.hpp:35
double ComputeDistanceTo(std::array< double, 2 > x) const noexcept
Definition: Invert.hpp:53
Invert(const Base &base)
Definition: Invert.hpp:37
double ComputeDistanceTo(std::array< double, 3 > x) const noexcept
Definition: Invert.hpp:39
decltype(std::declval< T >().ComputeDistanceTo(std::declval< Args >()...)) ComputeDistanceTo
Definition: Invert.hpp:32
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
This is std::true_type if Op<Args...> is a valid SFINAE expression.
Definition: type_traits.hpp:92
This file adds basic type traits utilities which are not yet implemented in all standard libraries.