From ff43bb2c51a50024395563f3c53b581f710a77f2 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 2 Sep 2019 14:59:56 +0200 Subject: [PATCH 1/5] removed explicit use of std:: namespace in favor of using std:: function --- src/amdis/DataTransfer.inc.hpp | 2 +- src/amdis/common/FieldMatVec.inc.hpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/amdis/DataTransfer.inc.hpp b/src/amdis/DataTransfer.inc.hpp index 2e52110d..64319984 100644 --- a/src/amdis/DataTransfer.inc.hpp +++ b/src/amdis/DataTransfer.inc.hpp @@ -365,7 +365,7 @@ restrictLocal(Element const& father, NodeElementData& fatherDOFs, Trafo const& t for (std::size_t i = 0; i < shapeValues.size(); ++i) y += shapeValues[i] * childDOFs[i]; - fatherDOFsTemp_[currentDOF] = y; + fatherDOFsTemp_[currentDOF] = T(y); finishedDOFs_[currentDOF++] = true; return y; } diff --git a/src/amdis/common/FieldMatVec.inc.hpp b/src/amdis/common/FieldMatVec.inc.hpp index dc4fe7fb..dc68bebf 100644 --- a/src/amdis/common/FieldMatVec.inc.hpp +++ b/src/amdis/common/FieldMatVec.inc.hpp @@ -346,13 +346,15 @@ auto two_norm(T const& x) template auto two_norm(FieldVector const& x) { - return std::sqrt(unary_dot(x)); + using std::sqrt; + return sqrt(unary_dot(x)); } template auto two_norm(FieldMatrix const& x) { - return std::sqrt(unary_dot(x)); + using std::sqrt; + return sqrt(unary_dot(x)); } /** \ingroup vector_norms -- GitLab From ab38c049d4a53190e963303755a1708ba7e2011b Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 2 Sep 2019 15:05:10 +0200 Subject: [PATCH 2/5] added specialization and definitions for Float128 type --- src/amdis/common/QuadMath.hpp | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/amdis/common/QuadMath.hpp diff --git a/src/amdis/common/QuadMath.hpp b/src/amdis/common/QuadMath.hpp new file mode 100644 index 00000000..f80cdfad --- /dev/null +++ b/src/amdis/common/QuadMath.hpp @@ -0,0 +1,75 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include + +namespace std +{ + template + struct common_type + { + using type = Dune::Float128; + }; + + template + struct common_type + { + using type = Dune::Float128; + }; + + template <> + struct common_type + { + using type = Dune::Float128; + }; + +} // end namespace std + + +namespace AMDiS +{ + namespace Concepts + { + namespace Definition + { + template <> + struct ConstantToGridFunction + : std::true_type {}; + + } // end namespace Definition + } // end namespace Concepts + + namespace Impl + { + template <> + struct SizeImpl + : std::integral_constant {}; + + template <> + struct RowsImpl + : std::integral_constant {}; + + template <> + struct ColsImpl + : std::integral_constant {}; + + } // end namespace Impl + + template + struct DerivativeTraits), tag::gradient> + { + using Range = Dune::FieldVector; + }; + + template <> + struct ValueCategory + { + using type = tag::scalar; + }; + +} // end namespace AMDiS -- GitLab From 371fa900db60ce5f0d442050539f82e9aa122d1b Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Tue, 3 Sep 2019 12:57:48 +0200 Subject: [PATCH 3/5] added hash function to quadmath --- src/amdis/common/QuadMath.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/amdis/common/QuadMath.hpp b/src/amdis/common/QuadMath.hpp index f80cdfad..d8da20bc 100644 --- a/src/amdis/common/QuadMath.hpp +++ b/src/amdis/common/QuadMath.hpp @@ -1,6 +1,8 @@ #pragma once +#include #include +#include #include #include @@ -28,6 +30,32 @@ namespace std using type = Dune::Float128; }; + template <> + struct hash + { + typedef Dune::Float128 argument_type; + typedef std::size_t result_type; + + std::size_t operator()(const Dune::Float128& arg) const + { + hash hasher_ld; + return hasher_ld((long double)(arg)); + } + }; + + template <> + struct hash + { + typedef Dune::Float128 argument_type; + typedef std::size_t result_type; + + std::size_t operator()(const Dune::Float128& arg) const + { + hash hasher_ld; + return hasher_ld((long double)(arg)); + } + }; + } // end namespace std -- GitLab From d1482a988f1d90e0c37d460ae493dd1c2cdf481c Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Sat, 28 Sep 2019 11:48:06 +0200 Subject: [PATCH 4/5] Add Float128 to ProblemStatTest --- src/amdis/common/CMakeLists.txt | 1 + src/amdis/common/QuadMath.hpp | 16 ++++++---------- test/ProblemStatTest.cpp | 33 +++++++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/amdis/common/CMakeLists.txt b/src/amdis/common/CMakeLists.txt index 006a5bc0..f14c1c24 100644 --- a/src/amdis/common/CMakeLists.txt +++ b/src/amdis/common/CMakeLists.txt @@ -27,6 +27,7 @@ install(FILES MultiTypeVector.hpp Range.hpp Resize.hpp + QuadMath.hpp StaticSize.hpp String.hpp SwitchCases.hpp diff --git a/src/amdis/common/QuadMath.hpp b/src/amdis/common/QuadMath.hpp index d8da20bc..bbd0c706 100644 --- a/src/amdis/common/QuadMath.hpp +++ b/src/amdis/common/QuadMath.hpp @@ -1,7 +1,9 @@ #pragma once +#if HAVE_QUADMATH #include #include + #include #include @@ -45,16 +47,8 @@ namespace std template <> struct hash - { - typedef Dune::Float128 argument_type; - typedef std::size_t result_type; - - std::size_t operator()(const Dune::Float128& arg) const - { - hash hasher_ld; - return hasher_ld((long double)(arg)); - } - }; + : public hash + {}; } // end namespace std @@ -101,3 +95,5 @@ namespace AMDiS }; } // end namespace AMDiS + +#endif // HAVE_QUADMATH diff --git a/test/ProblemStatTest.cpp b/test/ProblemStatTest.cpp index 8c6b36db..136cc318 100644 --- a/test/ProblemStatTest.cpp +++ b/test/ProblemStatTest.cpp @@ -2,20 +2,33 @@ #include #include #include +#include -using namespace AMDiS; - -using Grid = Dune::YaspGrid<2>; +#include +#include -template -struct Param - : DefaultBasisCreator, T> -{}; +using namespace AMDiS; template void test() { - ProblemStat> prob("ellipt"); + // use T as coordinate type + using Grid = Dune::YaspGrid<2, Dune::EquidistantCoordinates>; + Grid grid({T(1), T(1)}, {8,8}); + + // use T as range type for basis + using namespace Dune::Functions::BasisFactory; +#if DUNE_VERSION_GTE(DUNE_FUNCTIONS,2,7) + auto basis = makeBasis(grid.leafGridView(), power<1>(lagrange<1,T>(), flatLexicographic())); +#else + auto basis = makeBasis(grid.leafGridView(), power<1>(lagrange<1>(), flatLexicographic())); +#endif + using Basis = decltype(basis); + + // use T as coefficient type + using Param = DefaultProblemTraits; + + ProblemStat prob("ellipt"); prob.initialize(INIT_ALL); prob.boundaryManager()->setBoxBoundary({1,1,2,2}); @@ -45,5 +58,9 @@ int main(int argc, char** argv) test(); test(); +#if HAVE_QUADMATH + test(); +#endif + return 0; } -- GitLab From 01d002bdf87e6ef2cbadf1e283fa99e2b0eabfb0 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Sat, 28 Sep 2019 14:32:38 +0200 Subject: [PATCH 5/5] Add specialization of pow function for mixed argument types --- src/amdis/common/QuadMath.hpp | 16 ++++++++++++++++ src/amdis/functions/GlobalIdSet.hpp | 3 --- src/amdis/linearalgebra/petsc/Traits.hpp | 2 +- test/ProblemStatTest.cpp | 8 ++++---- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/amdis/common/QuadMath.hpp b/src/amdis/common/QuadMath.hpp index bbd0c706..1c0ba7e0 100644 --- a/src/amdis/common/QuadMath.hpp +++ b/src/amdis/common/QuadMath.hpp @@ -53,6 +53,22 @@ namespace std } // end namespace std +namespace Dune +{ + namespace Impl + { + // specialization for float arguments due to ambiguity + template ::value && std::is_arithmetic::value, int> = 0> + inline Float128 pow(const Float128& x, const T& p) + { + return powq(float128_t(x), float128_t(p)); + } + + } // end namespace Impl +} // end namespace Dune + + namespace AMDiS { namespace Concepts diff --git a/src/amdis/functions/GlobalIdSet.hpp b/src/amdis/functions/GlobalIdSet.hpp index 29f56a69..ed3e7a8b 100644 --- a/src/amdis/functions/GlobalIdSet.hpp +++ b/src/amdis/functions/GlobalIdSet.hpp @@ -29,9 +29,6 @@ namespace Dune template class CompositePreBasis; - template - class LagrangePreBasis; - template class PowerPreBasis; diff --git a/src/amdis/linearalgebra/petsc/Traits.hpp b/src/amdis/linearalgebra/petsc/Traits.hpp index bba67a93..fb5e1598 100644 --- a/src/amdis/linearalgebra/petsc/Traits.hpp +++ b/src/amdis/linearalgebra/petsc/Traits.hpp @@ -16,7 +16,7 @@ namespace AMDiS template struct BackendTraits { - static_assert(std::is_convertible::value, ""); + static_assert(std::is_same::value, ""); using Mat = ::Mat; using Vec = ::Vec; diff --git a/test/ProblemStatTest.cpp b/test/ProblemStatTest.cpp index 136cc318..b44b52f4 100644 --- a/test/ProblemStatTest.cpp +++ b/test/ProblemStatTest.cpp @@ -18,17 +18,17 @@ void test() // use T as range type for basis using namespace Dune::Functions::BasisFactory; -#if DUNE_VERSION_GTE(DUNE_FUNCTIONS,2,7) - auto basis = makeBasis(grid.leafGridView(), power<1>(lagrange<1,T>(), flatLexicographic())); -#else +#if DUNE_VERSION_LT(DUNE_FUNCTIONS,2,7) auto basis = makeBasis(grid.leafGridView(), power<1>(lagrange<1>(), flatLexicographic())); +#else + auto basis = makeBasis(grid.leafGridView(), power<1>(lagrange<1,T>(), flatLexicographic())); #endif using Basis = decltype(basis); // use T as coefficient type using Param = DefaultProblemTraits; - ProblemStat prob("ellipt"); + ProblemStat prob("ellipt", grid, basis); prob.initialize(INIT_ALL); prob.boundaryManager()->setBoxBoundary({1,1,2,2}); -- GitLab