diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2faf4c8966b68ddb94975317b081406b2052b8b9..6282468632b6b7270d46c26ce54a854dfcb9b57a 100755 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,6 @@ set( ENABLE_CODECOVERAGE ) ADD_SUBDIRECTORY( data ) ADD_SUBDIRECTORY( benchmarks ) -ADD_SUBDIRECTORY( approximation-tests ) ADD_SUBDIRECTORY( unit-tests ) ADD_SUBDIRECTORY( long-time-unit-tests ) diff --git a/tests/approximation-tests/CMakeLists.txt b/tests/approximation-tests/CMakeLists.txt deleted file mode 100755 index 25a0ff22ab1cbfe65172878b660d7d1bc7873b89..0000000000000000000000000000000000000000 --- a/tests/approximation-tests/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -INSTALL( FILES tnl-functions-test - DESTINATION share/tnl-${tnlVersion} ) - -set( common_headers tnlApproximationTest.h - tnlApproximationTest_impl.h ) diff --git a/tests/approximation-tests/tnl-functions-test b/tests/approximation-tests/tnl-functions-test deleted file mode 100644 index 6fa88ae2bf6883f81ef51b5e01aca29cd2eb4b30..0000000000000000000000000000000000000000 --- a/tests/approximation-tests/tnl-functions-test +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -FUNCTIONS="sin-wave" -GRID_DIMS="16 32 64 128 256 512" -for function in $FUNCTIONS; -do - mkdir ${function} - cd ${function} - - for grid_dim in $GRID_DIMS; - do - mkdir ${grid_dim} - cd ${grid_dim} - - tnl-grid-setup --output-file mesh.tnl \ - --dimensions 1 \ - --size-x ${grid_dim} - - tnl-discrete --mesh mesh.tnl \ - --function ${function} \ - --wave-length 1 \ - --output-file u.tnl - - tnl-discrete --mesh mesh.tnl \ - --function ${function} \ - --wave-length 1 \ - --x-derivative 1 \ - --output-file u-x-exact.tnl - - tnl-discrete --mesh mesh.tnl \ - --function ${function} \ - --wave-length 1 \ - --x-derivative 1 \ - --approximate-derivatives yes \ - --output-file u-x-approx.tnl - - tnl-view --mesh mesh.tnl \ - --check-output-file yes \ - --input-files u*.tnl - cd .. - done - - cd .. -done diff --git a/tests/approximation-tests/tnlApproximationTest_impl.h b/tests/approximation-tests/tnlApproximationTest_impl.h deleted file mode 100644 index 713755bab511fdd0be666d277e54f9d1349138c3..0000000000000000000000000000000000000000 --- a/tests/approximation-tests/tnlApproximationTest_impl.h +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - tnlApproximationTest_impl.h - description - ------------------- - begin : Aug 8, 2014 - copyright : (C) 2014 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef TNLAPPROXIMATIONTEST_IMPL_H_ -#define TNLAPPROXIMATIONTEST_IMPL_H_ - -#include <mesh/tnlTraversal.h> -#include <core/vectors/tnlVector.h> - -template< typename Mesh, - typename ExactOperator, - typename ApproximateOperator, - typename Function > -void -tnlApproximationTest< Mesh, ExactOperator, ApproximateOperator, Function >:: -getEoc( const Mesh& coarserMesh, - const Mesh& finerMesh, - const RealType& refinement, - const ExactOperator& exactOperator, - const ApproximateOperator& approximateOperator, - const Function& function, - RealType& l1Eoc, - RealType& l2Eoc, - RealType& maxEoc ) -{ - tnlVector< RealType, DeviceType, IndexType > coarserExactOperator, coarserApproximateOperator, - finerExactOperator, finerApproximateOperator; - const IndexType coarserEntities = coarserMesh.getNumberOfCells(); - const IndexType finerEntities = finerMesh.getNumberOfCells(); - - if( ! coarserExactOperator.setSize( coarserEntities ) || - ! coarserApproximateOperator.setSize( coarserEntities ) || - ! finerExactOperator.setSize( finerEntities ) || - ! finerApproximateOperator.setSize( finerEntities ) ) - return false; - - if( DeviceType::DeviceType == ( int ) tnlHostDevice ) - { - for( IndexType i = 0; i < coarserEntities; i++ ) - { - if( ! coarserMesh.isBoundaryCell( i ) ) - { - VertexType v = coarserMesh.getCellCenter( i ); - coarserExactOperator[ i ] = exactOperator.getValue( function, v ); - coarserApproximateOperator[ i ] = approximateOperator.getValue( coarserMesh, function, i ); - } - else coarserExactOperator[ i ] = coarserApproximateOperator[ i ]; - } - for( IndexType i = 0; i < finerEntities; i++ ) - { - if( ! coarserMesh.isBoundaryCell( i ) ) - { - VertexType v = finerMesh.getCellCenter( i ); - finerExactOperator[ i ] = exactOperator.getValue( function, v ); - finerApproximateOperator[ i ] = approximateOperator.getValue( finerMesh, function, i ); - } - else finerExactOperator[ i ] = finerApproximateOperator[ i ]; - } - } - if( DeviceType::DeviceType == ( int ) tnlCudaDevice ) - { - // TODO - } - const RealType& coarserL1Error = coarserMesh.getDifferenceLpNorm( coarserExactOperator, coarserApproximateOperator, ( RealType ) 1.0 ); - const RealType& coarserL2Error = coarserMesh.getDifferenceLpNorm( coarserExactOperator, coarserApproximateOperator, ( RealType ) 2.0 ); - const RealType& coarserMaxError = coarserMesh.getDifferenceAbsMax( coarserExactOperator, coarserApproximateOperator, ( RealType ) ); - - const RealType& finerL1Error = finerMesh.getDifferenceLpNorm( finerExactOperator, finerApproximateOperator, ( RealType ) 1.0 ); - const RealType& finerL2Error = finerMesh.getDifferenceLpNorm( finerExactOperator, finerApproximateOperator, ( RealType ) 2.0 ); - const RealType& finerMaxError = finerMesh.getDifferenceAbsMax( finerExactOperator, finerApproximateOperator, ( RealType ) ); - - l1Eoc = ln( coarserL1Error / finerL1Error ) / ln( refinement ); - l2Eoc = ln( coarserL2Error / finerL2Error ) / ln( refinement ); - maxEoc = ln( coarserMaxError / finerMaxError ) / ln( refinement ); -} - -#endif /* TNLAPPROXIMATIONTEST_IMPL_H_ */ diff --git a/tests/unit-tests/CMakeLists.txt b/tests/unit-tests/CMakeLists.txt index d21da8ea986a6b649b8e9bb86dc3caba925de739..260288102a8d1ab16a1fb7b9dad4efa2d3b0f745 100755 --- a/tests/unit-tests/CMakeLists.txt +++ b/tests/unit-tests/CMakeLists.txt @@ -1,6 +1,7 @@ ADD_SUBDIRECTORY( core ) ADD_SUBDIRECTORY( matrices ) ADD_SUBDIRECTORY( mesh ) +ADD_SUBDIRECTORY( schemes ) ADD_SUBDIRECTORY( solver ) set( headers tnlUnitTestStarter.h diff --git a/tests/unit-tests/schemes/diffusion/tnlLinearDiffusionTester.h b/tests/unit-tests/schemes/diffusion/tnlLinearDiffusionTester.h new file mode 100644 index 0000000000000000000000000000000000000000..478829fd23c6683e5cac7e3cf3253bcd2484bdf6 --- /dev/null +++ b/tests/unit-tests/schemes/diffusion/tnlLinearDiffusionTester.h @@ -0,0 +1,86 @@ +/*************************************************************************** + tnlLinearDiffusionTester.h - description + ------------------- + begin : Aug 30, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef TNLLINEARDIFFUSIONTESTER_H_ +#define TNLLINEARDIFFUSIONTESTER_H_ + +#ifdef HAVE_CPPUNIT +#include <cppunit/TestSuite.h> +#include <cppunit/TestResult.h> +#include <cppunit/TestCaller.h> +#include <cppunit/TestCase.h> +#include <cppunit/Message.h> +#include <schemes/diffusion/tnlLinearDiffusion.h> +#include <functions/tnlExpBumpFunction.h> +#include <tnlApproximationError.h> + +template< typename MeshType, + typename TestFunction > +class tnlLinearDiffusionTester{} + +template< int Dimensions, + typename Real, + typename Device, + typename Index, + typename TestFunction > +class tnlLinearDiffusionTester< tnlGrid< Dimensions, Real, Device, Index >, + TestFunction > : public CppUnit :: TestCase +{ + public: + typedef tnlGrid< Dimensions, Real, Device, Index > MeshType; + typedef tnlLinearDiffusionTester< MeshType > TesterType; + typedef typename CppUnit::TestCaller< TesterType > TestCallerType; + typedef tnlLinearDiffusionTestSetter< MeshType, FunctionType > TestSetter; + typedef tnlExactLinearDiffusion< Dimensions > ExactOperator; + typedef tnlLinearDiffusion< MeshType, Real, Index > ApproximateOperator; + + tnlLinearDiffusionTester(){}; + + virtual + ~tnlLinearDiffusionTester(){}; + + static CppUnit :: Test* suite() + { + CppUnit :: TestSuite* suiteOfTests = new CppUnit :: TestSuite( "tnlLinearDiffusionTester" ); + CppUnit :: TestResult result; + + suiteOfTests -> addTest( new TestCallerType( "approximationTest", &TesterType::approximationTest ) ); + + return suiteOfTests; + } + + void expBumpApproximationTest() + { + TestFunction testFunction; + TestFunctionSetter::setTestFunction( testFunction ); + + MeshType mesh; + TestSetter::setMesh( mesh, coarseMeshSize ); + + Real l1Err, l2Err, maxErr; + tnlApproximationError( mesh, + exactOperator, + approximateOperator, + testFunction, + l1Err, + l2Err, + maxErr ); + + } + + +#endif /* TNLLINEARDIFFUSIONTESTER_H_ */ diff --git a/tests/approximation-tests/tnlApproximationTest.h b/tests/unit-tests/tnlApproximationError.h similarity index 65% rename from tests/approximation-tests/tnlApproximationTest.h rename to tests/unit-tests/tnlApproximationError.h index 7a7e0ee3d8083dd0ea99dc8f97c3f9c72f96d2a8..0b4b8b562a2c9933cb11acbc6651f8dc04328221 100644 --- a/tests/approximation-tests/tnlApproximationTest.h +++ b/tests/unit-tests/tnlApproximationError.h @@ -1,5 +1,5 @@ /*************************************************************************** - tnlApproximationTest.h - description + tnlApproximationError.h - description ------------------- begin : Aug 7, 2014 copyright : (C) 2014 by Tomas Oberhuber @@ -15,14 +15,14 @@ * * ***************************************************************************/ -#ifndef TNLAPPROXIMATIONTEST_H_ -#define TNLAPPROXIMATIONTEST_H_ +#ifndef TNLAPPROXIMATIONERROR_H_ +#define TNLAPPROXIMATIONERROR_H_ template< typename Mesh, typename ExactOperator, typename ApproximateOperator, typename Function > -class tnlApproximationTest +class tnlApproximationError { public: @@ -32,17 +32,15 @@ class tnlApproximationTest typedef typename MeshType::CoordinatesType CoordinatesType; typedef typename MeshType::VertexType VertexType; - static void getEoc( const Mesh& coarserMesh, - const Mesh& finerMesh, - const RealType& refinement, - const ExactOperator& exactOperator, - const ApproximateOperator& approximateOperator, - const Function& function, - RealType& l1Eoc, - RealType& l2Eoc, - RealType& maxEoc ); + static void getError( const Mesh& mesh, + const ExactOperator& exactOperator, + const ApproximateOperator& approximateOperator, + const Function& function, + RealType& l1Err, + RealType& l2Err, + RealType& maxErr ); }; -#include <tests/approximation-tests/tnlApproximationTest_impl.h> +#include <tests/tnlApproximationError_impl.h> -#endif /* TNLAPPROXIMATIONTEST_H_ */ +#endif /* TNLAPPROXIMATIONERROR_H_ */ diff --git a/tests/unit-tests/tnlApproximationError_impl.h b/tests/unit-tests/tnlApproximationError_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..301e573a1ee01321158d148caa3859b4f6b231c2 --- /dev/null +++ b/tests/unit-tests/tnlApproximationError_impl.h @@ -0,0 +1,67 @@ +/*************************************************************************** + tnlApproximationError_impl.h - description + ------------------- + begin : Aug 8, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef TNLAPPROXIMATIONERROR_IMPL_H_ +#define TNLAPPROXIMATIONERROR_IMPL_H_ + +#include <mesh/tnlTraversal.h> +#include <core/vectors/tnlVector.h> + +template< typename Mesh, + typename ExactOperator, + typename ApproximateOperator, + typename Function > +void +tnlApproximationError< Mesh, ExactOperator, ApproximateOperator, Function >:: +getErrc( const Mesh& mesh, + const ExactOperator& exactOperator, + const ApproximateOperator& approximateOperator, + const Function& function, + RealType& l1Err, + RealType& l2Err, + RealType& maxErr ) +{ + tnlVector< RealType, DeviceType, IndexType > exactOperator, approximateOperator; + const IndexType entities = mesh.getNumberOfCells(); + + if( ! exactOperator.setSize( entities ) || + ! approximateOperator.setSize( entities ) ) + return false; + + if( DeviceType::DeviceType == ( int ) tnlHostDevice ) + { + for( IndexType i = 0; i < coarserEntities; i++ ) + { + if( ! mesh.isBoundaryCell( i ) ) + { + VertexType v = mesh.getCellCenter( i ); + coarserExactOperator[ i ] = exactOperator.getValue( function, v ); + coarserApproximateOperator[ i ] = approximateOperator.getValue( mesh, function, i ); + } + else exactOperator[ i ] = approximateOperator[ i ]; + } + } + if( DeviceType::DeviceType == ( int ) tnlCudaDevice ) + { + // TODO + } + L1Err = mesh.getDifferenceLpNorm( exactOperator, approximateOperator, ( RealType ) 1.0 ); + L2Errr = mesh.getDifferenceLpNorm( exactOperator, approximateOperator, ( RealType ) 2.0 ); + MaxErrr = mesh.getDifferenceAbsMax( exactOperator, approximateOperator ); +} + +#endif /* TNLAPPROXIMATIONERROR_IMPL_H_ */