diff --git a/src/operators/fdm/tnlCentralFiniteDifference.h b/src/operators/fdm/tnlCentralFiniteDifference.h index 2e563a23a0c43e07c8a98d5dcb3558e524d08c03..342113fa94625f1ce6b687f84f907aadab36e04f 100644 --- a/src/operators/fdm/tnlCentralFiniteDifference.h +++ b/src/operators/fdm/tnlCentralFiniteDifference.h @@ -49,7 +49,7 @@ class tnlCentralFiniteDifference< tnlGrid< Dimensions, MeshReal, MeshDevice, Mes typedef Real RealType; typedef MeshDevice DeviceType; typedef Index IndexType; - typedef tnlExactDifference< XDifference, YDifference, ZDifference > ExactOperatorType; + typedef tnlExactDifference< Dimensions, XDifference, YDifference, ZDifference > ExactOperatorType; //static constexpr int getMeshDimensions() { return Dimensions; } diff --git a/src/operators/fdm/tnlForwardFiniteDifference.h b/src/operators/fdm/tnlForwardFiniteDifference.h index 237e395716bcedc70d1c3c0d7eb81669a1de10ce..f687848a0ee6771bbd010b76063dff259f7af334 100644 --- a/src/operators/fdm/tnlForwardFiniteDifference.h +++ b/src/operators/fdm/tnlForwardFiniteDifference.h @@ -50,7 +50,7 @@ class tnlForwardFiniteDifference< tnlGrid< Dimensions, MeshReal, MeshDevice, Mes typedef Real RealType; typedef MeshDevice DeviceType; typedef Index IndexType; - typedef tnlExactDifference< XDifference, YDifference, ZDifference > ExactOperatorType; + typedef tnlExactDifference< Dimensions, XDifference, YDifference, ZDifference > ExactOperatorType; static constexpr int getMeshDimensions() { return Dimensions; } diff --git a/tests/unit-tests/operators/fdm/tnlFiniteDifferencesTest.h b/tests/unit-tests/operators/fdm/tnlFiniteDifferencesTest.h index cdba506d489697c1f28d0d0ce98683c2200aa4d3..ce49dc56006f669d3d8bfe27bddbbd17c367a727 100644 --- a/tests/unit-tests/operators/fdm/tnlFiniteDifferencesTest.h +++ b/tests/unit-tests/operators/fdm/tnlFiniteDifferencesTest.h @@ -30,70 +30,15 @@ #include "../tnlPDEOperatorEocTestResult.h" #include <functions/tnlExpBumpFunction.h> -template< typename MeshType, - typename RealType, - int XDifference, - int YDifference, - int ZDifference, - typename IndexType, - typename TestFunction > -class tnlPDEOperatorEocTestResult< - tnlForwardFiniteDifference< MeshType, XDifference, YDifference, ZDifference, RealType, IndexType >, TestFunction > -{ - public: - static RealType getL1Eoc() - { - if( XDifference < 2 && YDifference < 2 && ZDifference < 2 ) - return ( RealType ) 1.0; - }; - static RealType getL1Tolerance() { return ( RealType ) 0.05; }; - - static RealType getL2Eoc() - { - if( XDifference < 2 && YDifference < 2 && ZDifference < 2 ) - return ( RealType ) 1.0; - }; - static RealType getL2Tolerance() { return ( RealType ) 0.05; }; - - static RealType getMaxEoc() - { - if( XDifference < 2 && YDifference < 2 && ZDifference < 2 ) - return ( RealType ) 1.0; - }; - static RealType getMaxTolerance() { return ( RealType ) 0.05; }; -}; - -template< typename MeshType, - typename RealType, - int XDifference, - int YDifference, - int ZDifference, - typename IndexType, - typename TestFunction > -class tnlPDEOperatorEocTestResult< - tnlBackwardFiniteDifference< MeshType, XDifference, YDifference, ZDifference, RealType, IndexType >, TestFunction > +template< typename ApproximateOperator > +class tnlFinitDifferenceEocTestResults { public: - static RealType getL1Eoc() - { - if( XDifference < 2 && YDifference < 2 && ZDifference < 2 ) - return ( RealType ) 1.0; - }; - static RealType getL1Tolerance() { return ( RealType ) 0.05; }; - - static RealType getL2Eoc() - { - if( XDifference < 2 && YDifference < 2 && ZDifference < 2 ) - return ( RealType ) 1.0; - }; - static RealType getL2Tolerance() { return ( RealType ) 0.05; }; - - static RealType getMaxEoc() - { - if( XDifference < 2 && YDifference < 2 && ZDifference < 2 ) - return ( RealType ) 1.0; - }; - static RealType getMaxTolerance() { return ( RealType ) 0.05; }; + + typedef typename ApproximateOperator::RealType RealType; + + const RealType eoc[ 3 ] = { 1.0, 1.0, 1.0 }; + const RealType tolerance[ 3 ] = { 0.05, 0.05, 0.05 }; }; @@ -102,42 +47,22 @@ template< typename MeshType, int XDifference, int YDifference, int ZDifference, - typename IndexType, - typename TestFunction > -class tnlPDEOperatorEocTestResult< - tnlCentralFiniteDifference< MeshType, XDifference, YDifference, ZDifference, RealType, IndexType >, TestFunction > + typename IndexType > +class tnlFinitDifferenceEocTestResults< tnlCentralFiniteDifference< MeshType, XDifference, YDifference, ZDifference, RealType, IndexType > > { public: - static RealType getL1Eoc() - { - //if( XDifference < 2 && YDifference < 2 && ZDifference < 2 ) - return ( RealType ) 2.0; - }; - static RealType getL1Tolerance() { return ( RealType ) 0.05; }; - - static RealType getL2Eoc() - { - //if( XDifference < 2 && YDifference < 2 && ZDifference < 2 ) - return ( RealType ) 2.0; - }; - static RealType getL2Tolerance() { return ( RealType ) 0.05; }; - - static RealType getMaxEoc() - { - //if( XDifference < 2 && YDifference < 2 && ZDifference < 2 ) - return ( RealType ) 2.0; - }; - static RealType getMaxTolerance() { return ( RealType ) 0.05; }; - + + const RealType eoc[ 3 ] = { 2.0, 2.0, 2.0 }; + const RealType tolerance[ 3 ] = { 0.05, 0.05, 0.05 }; }; - template< typename ApproximateOperator, typename TestFunction, bool write = false, bool verbose = false > class tnlFiniteDifferenceTest - : public tnlPDEOperatorEocTest< ApproximateOperator, TestFunction > + : public tnlPDEOperatorEocTest< ApproximateOperator, TestFunction >, + public tnlFinitDifferenceEocTestResults< ApproximateOperator > { public: @@ -149,8 +74,6 @@ class tnlFiniteDifferenceTest const IndexType coarseMeshSize[ 3 ] = { 1024, 256, 64 }; - const RealType eoc[ 3 ] = { 2.0, 2.0, 2.0 }; - const RealType tolerance[ 3 ] = { 0.05, 0.05, 0.05 }; static tnlString getType() { @@ -181,7 +104,7 @@ class tnlFiniteDifferenceTest RealType coarseErrors[ 3 ], fineErrors[ 3 ]; this->getApproximationError( coarseMeshSize[ MeshType::getDimensionsCount() - 1 ], coarseErrors ); this->getApproximationError( 2 * coarseMeshSize[ MeshType::getDimensionsCount() - 1 ], fineErrors ); - this->checkEoc( coarseErrors, fineErrors, eoc, tolerance, verbose ); + this->checkEoc( coarseErrors, fineErrors, this->eoc, this->tolerance, verbose ); } protected: @@ -278,7 +201,7 @@ bool setDifferenceOrder() bool test() { const bool writeFunctions( false ); - const bool verbose( false ); + const bool verbose( true ); if( ! setDifferenceOrder< double, tnlHost, int, double, int, 64, writeFunctions, verbose >() ) return false; #ifdef HAVE_CUDA diff --git a/tests/unit-tests/operators/tnlPDEOperatorEocTest.h b/tests/unit-tests/operators/tnlPDEOperatorEocTest.h index 44484f3d80757c2b95b9212e03004685ddb006dd..acda81875e8de077deaa6cb0fe2db4358ddcd201 100644 --- a/tests/unit-tests/operators/tnlPDEOperatorEocTest.h +++ b/tests/unit-tests/operators/tnlPDEOperatorEocTest.h @@ -22,6 +22,14 @@ #include "tnlPDEOperatorEocTestFunctionSetter.h" #include "tnlApproximationError.h" +#ifdef HAVE_CPPUNIT +#include <cppunit/TestSuite.h> +#include <cppunit/TestResult.h> +#include <cppunit/TestCaller.h> +#include <cppunit/TestCase.h> +#endif + + template< typename ApproximateOperator, typename TestFunction > class tnlPDEOperatorEocTest @@ -79,7 +87,7 @@ class tnlPDEOperatorEocTest */ RealType maxEoc = log( coarse[ 0 ] / fine[ 0 ] ) / log( 2.0 ); if( verbose ) - std::cout << "Max error EOC = " << maxEoc << std::endl; + std::cout << "Max error EOC = " << maxEoc << " expected " << eoc[ 0 ] << std::endl; #ifdef HAVE_CPPUNIT CPPUNIT_ASSERT( fabs( maxEoc - eoc[ 0 ] ) < tolerance[ 0 ] ); #endif @@ -89,7 +97,7 @@ class tnlPDEOperatorEocTest */ RealType l1Eoc = log( coarse[ 1 ] / fine[ 1 ] ) / log( 2.0 ); if( verbose ) - std::cout << "L1 error EOC = " << l1Eoc << std::endl; + std::cout << "L1 error EOC = " << l1Eoc << " expected " << eoc[ 1 ] << std::endl; #ifdef HAVE_CPPUNIT CPPUNIT_ASSERT( fabs( l1Eoc - eoc[ 1 ] ) < tolerance[ 1 ] ); #endif @@ -99,7 +107,7 @@ class tnlPDEOperatorEocTest */ RealType l2Eoc = log( coarse[ 2 ] / fine[ 2 ] ) / log( 2.0 ); if( verbose ) - std::cout << "L2 error EOC = " << l2Eoc << std::endl; + std::cout << "L2 error EOC = " << l2Eoc << " expected " << eoc[ 2 ] << std::endl; #ifdef HAVE_CPPUNIT CPPUNIT_ASSERT( fabs( l2Eoc - eoc[ 2 ] ) < tolerance[ 2 ] ); #endif