From cf103435084dbfba0724d5511231f71e49710e69 Mon Sep 17 00:00:00 2001 From: Sebastian Eibl <sebastian.eibl@fau.de> Date: Tue, 23 May 2017 14:25:58 +0200 Subject: [PATCH] readded VectorTrait and check_float_equal_eps which were removed in last commit --- src/core/math/Matrix3.h | 32 +++++++++++++++++++++++++++++++- tests/core/math/Matrix3Test.cpp | 5 +++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/core/math/Matrix3.h b/src/core/math/Matrix3.h index 920795ac9..37a8afb79 100644 --- a/src/core/math/Matrix3.h +++ b/src/core/math/Matrix3.h @@ -1712,7 +1712,28 @@ using math::Matrix3; //====================================================================================================================== // -// comparison backend for Vector3<real_t> +// Vector Trait Specialization +// +//====================================================================================================================== + +namespace walberla { + +// Specialization of VectorTrait for Matrix3s +template<typename T> +struct VectorTrait< Matrix3<T> > +{ + typedef T OutputType; + + static const uint_t F_SIZE = 9u; + static T get( const Matrix3<T> & v, uint_t f ) { return v[f]; } + static void set( Matrix3<T> & v, uint_t f, T val) { v[f] = val; } +}; + +} // namespace walberla + +//====================================================================================================================== +// +// comparison backend for Matrix3<real_t> // //====================================================================================================================== @@ -1728,10 +1749,19 @@ inline bool check_float_equal( const math::Matrix3<real_t> & lhs, const math::Ma && floatIsEqual( lhs[6], rhs[6] ) && floatIsEqual( lhs[7], rhs[7] ) && floatIsEqual( lhs[8], rhs[8] ); } +template< > +inline bool check_float_equal_eps( const math::Matrix3<real_t> & lhs, const math::Matrix3<real_t> & rhs, const real_t epsilon ) +{ + return floatIsEqual( lhs[0], rhs[0], epsilon ) && floatIsEqual( lhs[1], rhs[1], epsilon ) && floatIsEqual( lhs[2], rhs[2], epsilon ) + && floatIsEqual( lhs[3], rhs[3], epsilon ) && floatIsEqual( lhs[4], rhs[4], epsilon ) && floatIsEqual( lhs[5], rhs[5], epsilon ) + && floatIsEqual( lhs[6], rhs[6], epsilon ) && floatIsEqual( lhs[7], rhs[7], epsilon ) && floatIsEqual( lhs[8], rhs[8], epsilon ); +} + } } } + #undef HIGH //====================================================================================================================== diff --git a/tests/core/math/Matrix3Test.cpp b/tests/core/math/Matrix3Test.cpp index d340db3d0..1cfbb83a2 100644 --- a/tests/core/math/Matrix3Test.cpp +++ b/tests/core/math/Matrix3Test.cpp @@ -55,6 +55,11 @@ void rotationTest() for( uint_t j = 0; j < 3; ++j ) if ( i != j) WALBERLA_CHECK_FLOAT_EQUAL( result(i,j), 0.0 ); + + //also checking WALBERLA_CHECK_FLOAT_EQUAL for matrices + Matrix3<real_t> cmp(2,0,0,0,4,0,0,0,6); + WALBERLA_CHECK_FLOAT_EQUAL( result, cmp ); + WALBERLA_CHECK_FLOAT_EQUAL_EPSILON( result, cmp, real_t(1e-5) ); } int main() -- GitLab