From 32c9360ef4e6824f1ebcdea6cd585cd9f0900c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fritze?= <rene.fritze@wwu.de> Date: Tue, 4 Aug 2020 12:00:11 +0200 Subject: [PATCH] [functions.inverse] simplify helper --- dune/xt/functions/inverse.hh | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/dune/xt/functions/inverse.hh b/dune/xt/functions/inverse.hh index b79280d2d..7ff5f40d8 100644 --- a/dune/xt/functions/inverse.hh +++ b/dune/xt/functions/inverse.hh @@ -40,34 +40,18 @@ public: using DomainType = Dune::FieldVector<double, d>; using RangeReturnType = typename RangeTypeSelector<R, r, rC>::return_type; - template <size_t r_ = r, size_t rC_ = rC, bool anything = true> - struct dim_switch - { - static const constexpr bool available = false; - }; +public: + static const constexpr bool available = (FunctionType::rC == FunctionType::r); - template <bool anything> - struct dim_switch<1, 1, anything> + static RangeReturnType compute(const FunctionType& func, const DomainType& xx, const XT::Common::Parameter& param) { - static const constexpr bool available = true; - - static RangeReturnType compute(const FunctionType& func, const DomainType& xx, const XT::Common::Parameter& param) - { + if constexpr (FunctionType::rC == 1 && FunctionType::r == 1) { auto value_to_invert = func.evaluate(xx, param); DUNE_THROW_IF(XT::Common::FloatCmp::eq(value_to_invert, 0.), Exceptions::wrong_input_given, "Scalar function value was not invertible!\n\nvalue_to_invert = " << value_to_invert); return 1. / value_to_invert; - } - }; - - template <size_t r_, bool anything> - struct dim_switch<r_, r_, anything> - { - static const constexpr bool available = true; - - static RangeReturnType compute(const FunctionType& func, const DomainType& xx, const XT::Common::Parameter& param) - { + } else if constexpr (available) { auto matrix_to_invert = func.evaluate(xx, param); RangeReturnType inverse_matrix; try { @@ -78,15 +62,9 @@ public: << matrix_to_invert << "\n\nThis was the original error: " << ee.what()); } return inverse_matrix; + } else { + static_assert(false, "compute not available"); } - }; - -public: - static const constexpr bool available = dim_switch<>::available; - - static RangeReturnType compute(const FunctionType& func, const DomainType& xx, const XT::Common::Parameter& param) - { - return dim_switch<>::compute(func, xx, param); } }; // class InverseFunctionHelper -- GitLab