diff --git a/dune/xt/common/coordinates.hh b/dune/xt/common/coordinates.hh new file mode 100644 index 0000000000000000000000000000000000000000..afb2624f52004d5b6c1a25feef2410a8d857b3ed --- /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 e0a5a40199bb19ed2140042e54f5abbbe061f4c6..8169035edd84e6c738ba25fb2bf313013532da7f 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 e437bc21002dea443d2b0001fb5360d201a20f09..8b21adf7dcce43ab6d20af0a30fcc5ff62f61f53 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 0f2baa09259a38e25069b1b6c76dc2c0825b41e4..8e06978b01668d28ab272e6bf12ce479b0d60ebc 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>