From bae3091e65c552c24f09e3c5bf8cf6ecfb0ef1c8 Mon Sep 17 00:00:00 2001 From: Tobias Leibner <tobias.leibner@googlemail.com> Date: Mon, 21 May 2018 21:48:25 +0200 Subject: [PATCH] [math/test.main] fix for compilation with gcc 7 - see https://gcc.gnu.org/gcc-6/porting_to.html#overloaded-abs --- dune/xt/common/coordinates.hh | 68 +++++++++++++++++++++++++++++++++++ dune/xt/common/math.cc | 5 +++ dune/xt/common/math.hh | 37 +------------------ dune/xt/common/test/main.hxx | 1 + 4 files changed, 75 insertions(+), 36 deletions(-) create mode 100644 dune/xt/common/coordinates.hh diff --git a/dune/xt/common/coordinates.hh b/dune/xt/common/coordinates.hh new file mode 100644 index 000000000..afb2624f5 --- /dev/null +++ b/dune/xt/common/coordinates.hh @@ -0,0 +1,68 @@ +// This file is part of the dune-xt-common project: +// https://github.com/dune-community/dune-xt-common +// Copyright 2009-2018 dune-xt-common developers and contributors. All rights reserved. +// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause) +// or GPL-2.0+ (http://opensource.org/licenses/gpl-license) +// with "runtime exception" (http://www.dune-project.org/license.html) +// Authors: +// Andreas Buhr (2014) +// Felix Schindler (2012 - 2018) +// Rene Milk (2010 - 2018) +// Sven Kaulmann (2013) +// Tobias Leibner (2014, 2017) + +#ifndef DUNE_XT_COMMON_COORDINATES_HH +#define DUNE_XT_COMMON_COORDINATES_HH + + +#include <dune/xt/common/disable_warnings.hh> +#include <boost/geometry.hpp> +#include <dune/xt/common/reenable_warnings.hh> + +#include <dune/xt/common/fvector.hh> + +namespace Dune { +namespace XT { +namespace Common { + + +/** Converts from (x, y, z) to (theta, phi) on the unit sphere s.t. + * (x, y, z) = (sin(theta) cos(phi), sin(theta) sin(phi), cos(theta)) + * with 0 \leq \theta \leq \pi and 0 \leq \varphi < 2\pi. **/ +template <class DomainFieldType> +class CoordinateConverter +{ + typedef typename boost::geometry::model::point<DomainFieldType, 3, typename boost::geometry::cs::cartesian> + BoostCartesianCoordType; + typedef typename boost::geometry::model:: + point<DomainFieldType, 2, typename boost::geometry::cs::spherical<boost::geometry::radian>> + BoostSphericalCoordType; + +public: + typedef FieldVector<DomainFieldType, 3> CartesianCoordType; + typedef FieldVector<DomainFieldType, 2> SphericalCoordType; + + static SphericalCoordType to_spherical(const CartesianCoordType& x) + { + BoostCartesianCoordType x_boost(x[0], x[1], x[2]); + BoostSphericalCoordType x_spherical_boost; + boost::geometry::transform(x_boost, x_spherical_boost); + return SphericalCoordType{boost::geometry::get<1>(x_spherical_boost), boost::geometry::get<0>(x_spherical_boost)}; + } + + static CartesianCoordType to_cartesian(const SphericalCoordType& x_spherical) + { + BoostSphericalCoordType x_spherical_boost(x_spherical[1], x_spherical[0]); + BoostCartesianCoordType x_boost; + boost::geometry::transform(x_spherical_boost, x_boost); + return CartesianCoordType{ + boost::geometry::get<0>(x_boost), boost::geometry::get<1>(x_boost), boost::geometry::get<2>(x_boost)}; + } +}; + + +} // namespace Common +} // namespace XT +} // namespace Dune + +#endif // DUNE_XT_COMMON_COORDINATES_HH diff --git a/dune/xt/common/math.cc b/dune/xt/common/math.cc index e0a5a4019..8169035ed 100644 --- a/dune/xt/common/math.cc +++ b/dune/xt/common/math.cc @@ -33,5 +33,10 @@ long unsigned int abs(const long unsigned int& value) return value; } +unsigned char abs(unsigned char value) +{ + return value; +} + } // namespace std diff --git a/dune/xt/common/math.hh b/dune/xt/common/math.hh index e437bc210..8b21adf7d 100644 --- a/dune/xt/common/math.hh +++ b/dune/xt/common/math.hh @@ -39,7 +39,6 @@ #include <dune/common/promotiontraits.hh> #include <dune/xt/common/type_traits.hh> -#include <dune/xt/common/vector.hh> namespace Dune { namespace XT { @@ -298,41 +297,6 @@ inline double binomial_coefficient(const double n, const size_t k) } -/** Converts from (x, y, z) to (theta, phi) on the unit sphere s.t. - * (x, y, z) = (sin(theta) cos(phi), sin(theta) sin(phi), cos(theta)) - * with 0 \leq \theta \leq \pi and 0 \leq \varphi < 2\pi. **/ -template <class DomainFieldType> -class CoordinateConverter -{ - typedef typename boost::geometry::model::point<DomainFieldType, 3, typename boost::geometry::cs::cartesian> - BoostCartesianCoordType; - typedef typename boost::geometry::model:: - point<DomainFieldType, 2, typename boost::geometry::cs::spherical<boost::geometry::radian>> - BoostSphericalCoordType; - -public: - typedef FieldVector<DomainFieldType, 3> CartesianCoordType; - typedef FieldVector<DomainFieldType, 2> SphericalCoordType; - - static SphericalCoordType to_spherical(const CartesianCoordType& x) - { - BoostCartesianCoordType x_boost(x[0], x[1], x[2]); - BoostSphericalCoordType x_spherical_boost; - boost::geometry::transform(x_boost, x_spherical_boost); - return SphericalCoordType{boost::geometry::get<1>(x_spherical_boost), boost::geometry::get<0>(x_spherical_boost)}; - } - - static CartesianCoordType to_cartesian(const SphericalCoordType& x_spherical) - { - BoostSphericalCoordType x_spherical_boost(x_spherical[1], x_spherical[0]); - BoostCartesianCoordType x_boost; - boost::geometry::transform(x_spherical_boost, x_boost); - return CartesianCoordType{ - boost::geometry::get<0>(x_boost), boost::geometry::get<1>(x_boost), boost::geometry::get<2>(x_boost)}; - } -}; - - template <class T> T max(const T& left, const T& right) { @@ -381,6 +345,7 @@ abs(value) * we want to use in our FloatCmp. */ long unsigned int abs(const long unsigned int& value); +unsigned char abs(unsigned char value); template <int k> diff --git a/dune/xt/common/test/main.hxx b/dune/xt/common/test/main.hxx index 0f2baa092..8e06978b0 100644 --- a/dune/xt/common/test/main.hxx +++ b/dune/xt/common/test/main.hxx @@ -35,6 +35,7 @@ #include <boost/numeric/conversion/cast.hpp> +#include <dune/xt/common/math.hh> #include <dune/common/fvector.hh> #include <dune/common/fmatrix.hh> #include <dune/common/parallel/mpihelper.hh> -- GitLab