Skip to content
Snippets Groups Projects
Commit 845b91de authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Fixing the approximation test.

parent bce97df1
No related branches found
No related tags found
No related merge requests found
...@@ -18,19 +18,20 @@ ...@@ -18,19 +18,20 @@
#ifndef TNLAPPROXIMATIONERROR_H_ #ifndef TNLAPPROXIMATIONERROR_H_
#define TNLAPPROXIMATIONERROR_H_ #define TNLAPPROXIMATIONERROR_H_
#include <mesh/tnlGrid.h>
template< typename Mesh, template< typename Mesh,
typename ExactOperator, typename ExactOperator,
typename ApproximateOperator, typename ApproximateOperator,
typename Function > typename Function >
class tnlApproximationError class tnlApproximationError
{ {
public: public:
typedef typename ApproximateOperator::RealType RealType; typedef typename ApproximateOperator::RealType RealType;
typedef Mesh MeshType; typedef Mesh MeshType;
typedef typename MeshType::DeviceType DeviceType; typedef typename MeshType::DeviceType DeviceType;
typedef typename MeshType::IndexType IndexType; typedef typename MeshType::IndexType IndexType;
typedef typename MeshType::CoordinatesType CoordinatesType;
typedef typename MeshType::VertexType VertexType; typedef typename MeshType::VertexType VertexType;
static void getError( const Mesh& mesh, static void getError( const Mesh& mesh,
...@@ -42,6 +43,35 @@ class tnlApproximationError ...@@ -42,6 +43,35 @@ class tnlApproximationError
RealType& maxErr ); 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" #include "tnlApproximationError_impl.h"
#endif /* TNLAPPROXIMATIONERROR_H_ */ #endif /* TNLAPPROXIMATIONERROR_H_ */
...@@ -69,4 +69,56 @@ getError( const Mesh& mesh, ...@@ -69,4 +69,56 @@ getError( const Mesh& mesh,
maxErr = mesh.getDifferenceAbsMax( exactData, approximateData ); 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_ */ #endif /* TNLAPPROXIMATIONERROR_IMPL_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment