Commit 845b91de authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Fixing the approximation test.

parent bce97df1
Loading
Loading
Loading
Loading
+32 −2
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
#ifndef TNLAPPROXIMATIONERROR_H_
#define TNLAPPROXIMATIONERROR_H_

#include <mesh/tnlGrid.h>

template< typename Mesh,
          typename ExactOperator,
          typename ApproximateOperator,
@@ -30,7 +32,6 @@ class tnlApproximationError
      typedef Mesh MeshType;
      typedef typename MeshType::DeviceType DeviceType;
      typedef typename MeshType::IndexType IndexType;
      typedef typename MeshType::CoordinatesType CoordinatesType;
      typedef typename MeshType::VertexType VertexType;

      static void getError( const Mesh& mesh,
@@ -42,6 +43,35 @@ class tnlApproximationError
                            RealType& maxErr );
};

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index,
          typename ExactOperator,
          typename ApproximateOperator,
          typename Function >
class tnlApproximationError< tnlGrid< Dimensions, Real, Device, Index >, ExactOperator, ApproximateOperator, Function >
{
   public:

      typedef typename ApproximateOperator::RealType RealType;
      typedef tnlGrid< Dimensions, Real, Device, Index > MeshType;
      typedef typename MeshType::DeviceType DeviceType;
      typedef typename MeshType::IndexType IndexType;
      typedef typename MeshType::CoordinatesType CoordinatesType;
      typedef typename MeshType::VertexType VertexType;

      static void getError( const MeshType& mesh,
                            const ExactOperator& exactOperator,
                            const ApproximateOperator& approximateOperator,
                            const Function& function,
                            RealType& l1Err,
                            RealType& l2Err,
                            RealType& maxErr );
};



#include "tnlApproximationError_impl.h"

#endif /* TNLAPPROXIMATIONERROR_H_ */
+52 −0
Original line number Diff line number Diff line
@@ -69,4 +69,56 @@ getError( const Mesh& mesh,
   maxErr = mesh.getDifferenceAbsMax( exactData, approximateData );
}

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index,
          typename ExactOperator,
          typename ApproximateOperator,
          typename Function >
void
tnlApproximationError< tnlGrid< Dimensions, Real, Device, Index >, ExactOperator, ApproximateOperator, Function >::
getError( const MeshType& mesh,
          const ExactOperator& exactOperator,
          const ApproximateOperator& approximateOperator,
          const Function& function,
          RealType& l1Err,
          RealType& l2Err,
          RealType& maxErr )
{
   typedef tnlVector< RealType, DeviceType, IndexType > Vector;
   Vector functionData, exactData, approximateData;
   const IndexType entities = mesh.getNumberOfCells();

   if( ! functionData.setSize( entities ) ||
       ! exactData.setSize( entities ) ||
       ! approximateData.setSize( entities )  )
      return;

   tnlFunctionDiscretizer< MeshType, Function, Vector >::template discretize< 0, 0, 0 >( mesh, function, functionData );

   if( DeviceType::DeviceType == ( int ) tnlHostDevice )
   {
      for( IndexType i = 0; i < entities; i++ )
      {
         if( ! mesh.isBoundaryCell( i ) )
         {
            VertexType v = mesh.getCellCenter( i );
            CoordinatesType c = mesh.getCellCoordinates( i );
            exactData[ i ] = exactOperator.getValue( function, v );
            approximateData[ i ] = approximateOperator.getValue( mesh, i, c, functionData, 0.0 );
         }
         else exactData[ i ] = approximateData[ i ];
      }
   }
   if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
   {
      // TODO
   }
   l1Err = mesh.getDifferenceLpNorm( exactData, approximateData, ( RealType ) 1.0 );
   l2Err = mesh.getDifferenceLpNorm( exactData, approximateData, ( RealType ) 2.0 );
   maxErr = mesh.getDifferenceAbsMax( exactData, approximateData );
}


#endif /* TNLAPPROXIMATIONERROR_IMPL_H_ */