Loading tests/unit-tests/tnlApproximationError.h +32 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ #ifndef TNLAPPROXIMATIONERROR_H_ #define TNLAPPROXIMATIONERROR_H_ #include <mesh/tnlGrid.h> template< typename Mesh, typename ExactOperator, typename ApproximateOperator, Loading @@ -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, Loading @@ -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_ */ tests/unit-tests/tnlApproximationError_impl.h +52 −0 Original line number Diff line number Diff line Loading @@ -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_ */ Loading
tests/unit-tests/tnlApproximationError.h +32 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ #ifndef TNLAPPROXIMATIONERROR_H_ #define TNLAPPROXIMATIONERROR_H_ #include <mesh/tnlGrid.h> template< typename Mesh, typename ExactOperator, typename ApproximateOperator, Loading @@ -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, Loading @@ -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_ */
tests/unit-tests/tnlApproximationError_impl.h +52 −0 Original line number Diff line number Diff line Loading @@ -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_ */