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

Implementing the approximation test.

parent 8e21cc93
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ setBoundaryConditions( const RealType& time,
const IndexType index,
const CoordinatesType& coordinates,
DofVectorType& u,
DofVectorType& fu )
DofVectorType& fu ) const
{
fu[ index ] = 0;
u[ index ] = function.getValue( mesh.getCellCenter( coordinates ), time );
......@@ -115,7 +115,7 @@ setBoundaryConditions( const RealType& time,
const IndexType index,
const CoordinatesType& coordinates,
DofVectorType& u,
DofVectorType& fu )
DofVectorType& fu ) const
{
fu[ index ] = 0;
u[ index ] = function.getValue( mesh.getCellCenter( coordinates ), time );
......@@ -198,7 +198,7 @@ setBoundaryConditions( const RealType& time,
const IndexType index,
const CoordinatesType& coordinates,
DofVectorType& u,
DofVectorType& fu )
DofVectorType& fu ) const
{
fu[ index ] = 0;
u[ index ] = function.getValue( mesh.getCellCenter( coordinates ), time );;
......
......@@ -64,9 +64,9 @@ void
tnlExplicitUpdater< tnlGrid< Dimensions, Real, Device, Index >, DofVector, DifferentialOperator, BoundaryConditions, RightHandSide >::
update( const RealType& time,
const tnlGrid< Dimensions, Real, Device, Index >& mesh,
DifferentialOperator& differentialOperator,
BoundaryConditions& boundaryConditions,
RightHandSide& rightHandSide,
const DifferentialOperator& differentialOperator,
const BoundaryConditions& boundaryConditions,
const RightHandSide& rightHandSide,
DofVector& u,
DofVector& fu ) const
{
......
......@@ -47,7 +47,7 @@ class tnlDirichletBoundaryConditions< tnlGrid< 1, MeshReal, Device, MeshIndex >,
const IndexType index,
const CoordinatesType& coordinates,
DofVectorType& u,
DofVectorType& fu );
DofVectorType& fu ) const;
#ifdef HAVE_CUDA
__device__ __host__
......@@ -105,7 +105,7 @@ class tnlDirichletBoundaryConditions< tnlGrid< 2, MeshReal, Device, MeshIndex >,
const IndexType index,
const CoordinatesType& coordinates,
DofVectorType& u,
DofVectorType& fu );
DofVectorType& fu ) const;
#ifdef HAVE_CUDA
__device__ __host__
......@@ -164,7 +164,7 @@ class tnlDirichletBoundaryConditions< tnlGrid< 3, MeshReal, Device, MeshIndex >,
const IndexType index,
const CoordinatesType& coordinates,
DofVectorType& u,
DofVectorType& fu );
DofVectorType& fu ) const;
#ifdef HAVE_CUDA
__device__ __host__
......
......@@ -29,18 +29,18 @@ class tnlExplicitUpdaterTraversalUserData
const Real &time;
DifferentialOperator& differentialOperator;
const DifferentialOperator& differentialOperator;
BoundaryConditions& boundaryConditions;
const BoundaryConditions& boundaryConditions;
RightHandSide& rightHandSide;
const RightHandSide& rightHandSide;
DofVector &u, &fu;
tnlExplicitUpdaterTraversalUserData( const Real& time,
DifferentialOperator& differentialOperator,
BoundaryConditions& boundaryConditions,
RightHandSide& rightHandSide,
const DifferentialOperator& differentialOperator,
const BoundaryConditions& boundaryConditions,
const RightHandSide& rightHandSide,
DofVector& u,
DofVector& fu )
: time( time ),
......@@ -154,9 +154,9 @@ class tnlExplicitUpdater< tnlGrid< Dimensions, Real, Device, Index >,
template< int EntityDimensions >
void update( const RealType& time,
const MeshType& mesh,
DifferentialOperator& differentialOperator,
BoundaryConditions& boundaryConditions,
RightHandSide& rightHandSide,
const DifferentialOperator& differentialOperator,
const BoundaryConditions& boundaryConditions,
const RightHandSide& rightHandSide,
DofVector& u,
DofVector& fu ) const;
......
......@@ -52,7 +52,7 @@ class tnlPDEOperatorEocTestResult< tnlLinearDiffusion< tnlGrid< Dimensions, Real
int main( int argc, char* argv[] )
{
const bool verbose( true );
const int MeshSize( 32 );
const int MeshSize( 8 );
#ifdef HAVE_CPPUNIT
/****
* Explicit approximation
......@@ -62,8 +62,8 @@ int main( int argc, char* argv[] )
tnlExpBumpFunction< 1, double >,
tnlExplicitApproximation,
MeshSize,
verbose > >() ||
! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 2, double, tnlHost, int >, double, int >,
verbose > >()
/*! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 2, double, tnlHost, int >, double, int >,
tnlExactLinearDiffusion< 2 >,
tnlExpBumpFunction< 2, double >,
tnlExplicitApproximation,
......@@ -74,8 +74,9 @@ int main( int argc, char* argv[] )
tnlExpBumpFunction< 3, double >,
tnlExplicitApproximation,
MeshSize,
verbose > >() )
return EXIT_FAILURE;
verbose > >() */
);
//return EXIT_FAILURE;
/****
* Implicit (matrix) approximation
*/
......@@ -84,8 +85,8 @@ int main( int argc, char* argv[] )
tnlExpBumpFunction< 1, double >,
tnlImplicitApproximation,
MeshSize,
verbose > >() ||
! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 2, double, tnlHost, int >, double, int >,
verbose > >()
/*! tnlUnitTestStarter :: run< tnlPDEOperatorEocTester< tnlLinearDiffusion< tnlGrid< 2, double, tnlHost, int >, double, int >,
tnlExactLinearDiffusion< 2 >,
tnlExpBumpFunction< 2, double >,
tnlImplicitApproximation,
......@@ -96,7 +97,7 @@ int main( int argc, char* argv[] )
tnlExpBumpFunction< 3, double >,
tnlImplicitApproximation,
MeshSize,
verbose > >()
verbose > >() */
)
return EXIT_FAILURE;
return EXIT_SUCCESS;
......
......@@ -21,6 +21,7 @@
#include <mesh/tnlGrid.h>
#include <functions/tnlConstantFunction.h>
#include <operators/tnlDirichletBoundaryConditions.h>
#include <solvers/pde/tnlExplicitUpdater.h>
class tnlExplicitApproximation
{
......@@ -76,7 +77,7 @@ class tnlApproximationError< Mesh, ExactOperator, ApproximateOperator, Function,
RealType& maxErr );
};
template< int Dimensions,
/*template< int Dimensions,
typename Real,
typename Device,
typename Index,
......@@ -101,7 +102,7 @@ class tnlApproximationError< tnlGrid< Dimensions, Real, Device, Index >, ExactOp
RealType& l1Err,
RealType& l2Err,
RealType& maxErr );
};
};*/
template< typename Mesh,
typename ExactOperator,
......
......@@ -42,6 +42,8 @@ getError( const Mesh& mesh,
typedef tnlVector< RealType, DeviceType, IndexType > Vector;
Vector functionData, exactData, approximateData;
const IndexType entities = mesh.getNumberOfCells();
BoundaryConditionsType boundaryConditions;
ConstantFunctionType zeroFunction;
if( ! functionData.setSize( entities ) ||
! exactData.setSize( entities ) ||
......@@ -50,29 +52,25 @@ getError( const Mesh& mesh,
tnlFunctionDiscretizer< Mesh, 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 );
exactData[ i ] = exactOperator.getValue( function, v );
approximateData[ i ] = approximateOperator.getValue( mesh, i, functionData );
}
else exactData[ i ] = approximateData[ i ];
}
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
// TODO
}
tnlExplicitUpdater< Mesh, Vector, ApproximateOperator, BoundaryConditionsType, ConstantFunctionType > explicitUpdater;
explicitUpdater.template update< Mesh::Dimensions >( 0.0,
mesh,
approximateOperator,
boundaryConditions,
zeroFunction,
functionData,
approximateData );
cout << "Function = " << functionData << endl;
cout << "Approximation = " << approximateData << endl;
cout << "Exact = " << exactData << endl;
l1Err = mesh.getDifferenceLpNorm( exactData, approximateData, ( RealType ) 1.0 );
l2Err = mesh.getDifferenceLpNorm( exactData, approximateData, ( RealType ) 2.0 );
maxErr = mesh.getDifferenceAbsMax( exactData, approximateData );
}
template< int Dimensions,
/*template< int Dimensions,
typename Real,
typename Device,
typename Index,
......@@ -118,10 +116,14 @@ getError( const MeshType& mesh,
{
// TODO
}
cout << "Function = " << functionData << endl;
cout << "Approximation = " << approximateData << endl;
cout << "Exact = " << exactData << endl;
l1Err = mesh.getDifferenceLpNorm( exactData, approximateData, ( RealType ) 1.0 );
l2Err = mesh.getDifferenceLpNorm( exactData, approximateData, ( RealType ) 2.0 );
maxErr = mesh.getDifferenceAbsMax( exactData, approximateData );
}
}*/
/****
* Implicit (matrix) approximation
......@@ -152,6 +154,8 @@ getError( const Mesh& mesh,
const IndexType entities = mesh.getNumberOfCells();
cerr << "Semi-implicit test " << endl;
if( ! functionData.setSize( entities ) ||
! exactData.setSize( entities ) ||
! approximateData.setSize( entities ) ||
......@@ -181,7 +185,11 @@ getError( const Mesh& mesh,
approximateData // this has no meaning here
);
cout << "Matrix = " << matrix << endl;
matrix.vectorProduct( functionData, approximateData );
cout << "Function = " << functionData << endl;
cout << "Approximation = " << approximateData << endl;
cout << "Exact = " << exactData << endl;
for( IndexType i = 0; i < entities; i++ )
if( mesh.isBoundaryCell( i ) )
approximateData.setElement( i, exactData.getElement( i ) );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment