Commit 003245ef authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Refactoring operators unit tests.

parent 01725bae
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
ADD_SUBDIRECTORY( diffusion )
ADD_SUBDIRECTORY( fdm )
ADD_SUBDIRECTORY( geometric )
 No newline at end of file
#ADD_SUBDIRECTORY( fdm )
#ADD_SUBDIRECTORY( geometric )
 No newline at end of file
+1 −96
Original line number Diff line number Diff line
@@ -15,99 +15,4 @@
 *                                                                         *
 ***************************************************************************/

#include <tnlConfig.h>
#include <core/tnlHost.h>
#include <cstdlib>

#include "../tnlPDEOperatorEocTester.h"
#include "../../tnlUnitTestStarter.h"
#include <mesh/tnlGrid.h>
#include <operators/diffusion/tnlLinearDiffusion.h>
#include <operators/diffusion/tnlExactLinearDiffusion.h>
#include "../tnlPDEOperatorEocTestResult.h"
#include <functions/tnlExpBumpFunction.h>

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index,
          typename TestFunction >
class tnlPDEOperatorEocTestResult< tnlLinearDiffusion< tnlGrid< Dimensions, Real, Device, Index >, Real, Index >,
                                   TestFunction >
{
   public:
      static Real getL1Eoc() { return ( Real ) 2.0; };
      static Real getL1Tolerance() { return ( Real ) 0.05; };

      static Real getL2Eoc() { return ( Real ) 2.0; };
      static Real getL2Tolerance() { return ( Real ) 0.05; };

      static Real getMaxEoc() { return ( Real ) 2.0; };
      static Real getMaxTolerance() { return ( Real ) 0.05; };

};

int main( int argc, char* argv[] )
{
   const bool writeFunctions( false );
   const bool verbose( false );
   const int MeshSize( 64 );
#ifdef HAVE_CPPUNIT
   /****
    * Explicit approximation
    */
   if( ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 1, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 1 >,
                                                             tnlExpBumpFunction< 1, double >,
                                                             typename tnlGrid< 1, double, tnlHost, int >::Cell,
                                                             MeshSize,
                                                             writeFunctions,
                                                             verbose > >() ||
       ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 2, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 2 >,
                                                             tnlExpBumpFunction< 2, double >,
                                                             typename tnlGrid< 2, double, tnlHost, int >::Cell,
                                                             MeshSize,
                                                             writeFunctions,
                                                             verbose > >() ||
       ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 3, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 3 >,
                                                             tnlExpBumpFunction< 3, double >,
                                                             typename tnlGrid< 3, double, tnlHost, int >::Cell,
                                                             MeshSize,
                                                             writeFunctions,
                                                             verbose > >()
                                                              )
      return EXIT_FAILURE;
   /****
    * Implicit (matrix) approximation
    */
   if( ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 1, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 1 >,
                                                             tnlExpBumpFunction< 1, double >,
                                                             typename tnlGrid< 1, double, tnlHost, int >::Cell,
                                                             MeshSize,
                                                             writeFunctions,
                                                             verbose > >() ||
       ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 2, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 2 >,
                                                             tnlExpBumpFunction< 2, double >,
                                                             typename tnlGrid< 2, double, tnlHost, int >::Cell,
                                                             MeshSize,
                                                             writeFunctions,
                                                             verbose > >() ||
       ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 3, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 3 >,
                                                             tnlExpBumpFunction< 3, double >,
                                                             typename tnlGrid< 3, double, tnlHost, int >::Cell,
                                                             MeshSize,
                                                             writeFunctions,
                                                             verbose > >()
       )
     return EXIT_FAILURE;
   return EXIT_SUCCESS;
#else
   return EXIT_FAILURE;
#endif
}
#include "tnlLinearDiffusionTest.h"
+1 −91
Original line number Diff line number Diff line
@@ -15,94 +15,4 @@
 *                                                                         *
 ***************************************************************************/

#include <tnlConfig.h>
#include <core/tnlHost.h>
#include <cstdlib>

#include "../tnlPDEOperatorEocTester.h"
#include "../../tnlUnitTestStarter.h"
#include <mesh/tnlGrid.h>
#include <operators/diffusion/tnlLinearDiffusion.h>
#include <operators/diffusion/tnlExactLinearDiffusion.h>
#include "../tnlPDEOperatorEocTestResult.h"
#include <functions/tnlExpBumpFunction.h>

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index,
          typename TestFunction,
          typename ApproximationMethod >
class tnlPDEOperatorEocTestResult< tnlLinearDiffusion< tnlGrid< Dimensions, Real, Device, Index >, Real, Index >,
                                   ApproximationMethod,
                                   TestFunction >
{
   public:
      static Real getL1Eoc() { return ( Real ) 2.0; };
      static Real getL1Tolerance() { return ( Real ) 0.05; };

      static Real getL2Eoc() { return ( Real ) 2.0; };
      static Real getL2Tolerance() { return ( Real ) 0.05; };

      static Real getMaxEoc() { return ( Real ) 2.0; };
      static Real getMaxTolerance() { return ( Real ) 0.05; };

};

int main( int argc, char* argv[] )
{
#ifdef HAVE_CPPUNIT
   const bool verbose( true );
   const int MeshSize( 64 );
   /****
    * Explicit approximation
    */
   if( ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 1, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 1 >,
                                                             tnlExpBumpFunction< 1, double >,
                                                             tnlExplicitApproximation,
                                                             MeshSize,
                                                             verbose > >()
       /*! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 2, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 2 >,
                                                             tnlExpBumpFunction< 2, double >,
                                                             tnlExplicitApproximation,
                                                             MeshSize,
                                                             verbose > >() ||
       ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 3, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 3 >,
                                                             tnlExpBumpFunction< 3, double >,
                                                             tnlExplicitApproximation,
                                                             MeshSize,
                                                             verbose > >() */
                                                              );
      //return EXIT_FAILURE;
   /****
    * Implicit (matrix) approximation
    */
   if( ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 1, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 1 >,
                                                             tnlExpBumpFunction< 1, double >,
                                                             tnlImplicitApproximation,
                                                             MeshSize,
                                                             verbose > >()
       /*! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 2, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 2 >,
                                                             tnlExpBumpFunction< 2, double >,
                                                             tnlImplicitApproximation,
                                                             MeshSize,
                                                             verbose > >() ||
       ! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 3, double, tnlHost, int >, double, int >,
                                                             tnlExactLinearDiffusion< 3 >,
                                                             tnlExpBumpFunction< 3, double >,
                                                             tnlImplicitApproximation,
                                                             MeshSize,
                                                             verbose > >() */
       )
     return EXIT_FAILURE;
   return EXIT_SUCCESS;
#else
   return EXIT_FAILURE;
#endif
}
#include "tnlLinearDiffusionTest.h"
+101 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlLinearDiffusionTest.h  -  description
                             -------------------
    begin                : Feb 1, 2016
    copyright            : (C) 2016 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 TNLLINEARDIFFUSIONTEST_H
#define	TNLLINEARDIFFUSIONTEST_H

#include <operators/diffusion/tnlLinearDiffusion.h>
#include <operators/diffusion/tnlExactLinearDiffusion.h>
#include <mesh/tnlGrid.h>
#include "../tnlPDEOperatorEocUnitTest.h"

/*template< int Dimensions,
          typedef Real,
          typedef Device,
          typedef Index,
          typedef Function >
class tnlPDEOperatorEocTest< tnlLinearDiffusion< tnlGrid< Dimensions, Real, Device, Index >, Function >
{
   public:
      typedef tnlGrid< Dimensions, Real, Device, Index > MeshType;
      typedef tnlLinearDiffusion< MeshType > ApproximateOperator;
      typedef tnlExactLinearDiffusion< Dimensions > ExactOperator;
      
      void setupTest() {};
      
      void runUnitTest()
      {
         
      }
      
      protected:
         
         MeshType mesh;
         FunctionType function;
};
 * */

template< typename ApproximateOperator,
          typename TestFunction >
class tnlLinearDiffusionTest
   : public tnlPDEOperatorEocTest< ApproximateOperator, TestFunction > 
{
   public:
      
};


template< typename Mesh,
          typename Function >
bool runTest()
{
   typedef tnlLinearDiffusion< Mesh > ApproximateOperator;
   typedef tnlLinearDiffusionTest< ApproximateOperator, Function > OperatorTest;
#ifdef HAVE_CPPUNIT   
   if( ! tnlUnitTestStarter::run< OperatorTest >() )
      return false;
   return true;
#endif      
}

template< typename Mesh >
bool setTestFunction()
{
   return runTest< Mesh, tnlExpBumpFunction< Mesh::getDimensionsCount(), double >();
}

template< typename Device >
bool setMesh()
{
   return ( setTestFunction< tnlGrid< 1, double, Device, int >() &&
      setTestFunction< tnlGrid< 2, double, Device, int >() &&
      setTestFunction< tnlGrid< 3, double, Device, int >() );
}

int main( int argc, char* argv[] )
{
   if( ! setMesh< tnlHost >() )
      return EXIT_FAILURE;
#ifdef HAVE_CUDA
   if( ! setMesh< tnlCuda >() )
      return EXIT_FAILURE;
#endif   
   return EXIT_SUCCESS;
}

#endif	/* TNLLINEARDIFFUSIONTEST_H */
+2 −2
Original line number Diff line number Diff line
@@ -80,8 +80,8 @@ bool setDifferenceOperator()
   typedef tnlCoFVMGradientNorm< Mesh > GradientNormOnFaces;
   typedef tnlMeshEntitiesInterpolants< Mesh, Mesh::getDimensionsCount() - 1, Mesh::getDimensionsCount() > Interpolant;
   typedef tnlOperatorComposition< Interpolant, GradientNormOnFaces > GradientNormOnCells;
   return ( testDifferenceOperator< Mesh, Function, GradientNormOnFaces, MeshSize, WriteFunctions, Verbose >() &&
            testDifferenceOperator< Mesh, Function, GradientNormOnCells, MeshSize, WriteFunctions, Verbose >() );
   return ( testDifferenceOperator< Mesh, Function, GradientNormOnFaces, MeshSize, WriteFunctions, Verbose >() );//&&
            //testDifferenceOperator< Mesh, Function, GradientNormOnCells, MeshSize, WriteFunctions, Verbose >() );
}

template< typename Mesh,
Loading