Loading src/Tools/tnl-diff.h +210 −50 Original line number Diff line number Diff line Loading @@ -20,6 +20,163 @@ using namespace TNL; template< typename MeshFunction, typename Mesh = typename MeshFunction::MeshType, int EntitiesDimension = MeshFunction::getEntitiesDimension() > class ExactMatchTest { public: static void run( const MeshFunction& f1, const MeshFunction& f2, const String& f1Name, const String& f2Name, std::fstream& outputFile, bool verbose = false) { TNL_ASSERT( false, "Not implemented yet." ); } }; template< typename MeshFunction, typename Real, typename Device, typename Index > class ExactMatchTest< MeshFunction, Meshes::Grid< 1, Real, Device, Index >, 1 > { public: static void run( const MeshFunction& f1, const MeshFunction& f2, const String& f1Name, const String& f2Name, std::fstream& outputFile, bool verbose = false ) { const int Dimension = 1; const int EntityDimension = 1; using Grid = Meshes::Grid< Dimension, Real, Device, Index >; using Entity = typename Grid::template EntityType< EntityDimension >; if( f1.getMesh().getDimensions() != f2.getMesh().getDimensions() ) { outputFile << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; } Entity entity( f1.getMesh() ); for( entity.getCoordinates().x() = 0; entity.getCoordinates().x() < f1.getMesh().getDimensions().x(); entity.getCoordinates().x()++ ) { entity.refresh(); if( f1.getValue( entity ) != f2.getValue( entity ) ) { outputFile << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; } } } }; template< typename MeshFunction, typename Real, typename Device, typename Index > class ExactMatchTest< MeshFunction, Meshes::Grid< 2, Real, Device, Index >, 2 > { public: static void run( const MeshFunction& f1, const MeshFunction& f2, const String& f1Name, const String& f2Name, std::fstream& outputFile, bool verbose = false ) { const int Dimension = 2; const int EntityDimension = 2; using Grid = Meshes::Grid< Dimension, Real, Device, Index >; using Entity = typename Grid::template EntityType< EntityDimension >; if( f1.getMesh().getDimensions() != f2.getMesh().getDimensions() ) { outputFile << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; } Entity entity( f1.getMesh() ); for( entity.getCoordinates().y() = 0; entity.getCoordinates().y() < f1.getMesh().getDimensions().y(); entity.getCoordinates().y()++ ) for( entity.getCoordinates().x() = 0; entity.getCoordinates().x() < f1.getMesh().getDimensions().x(); entity.getCoordinates().x()++ ) { entity.refresh(); if( f1.getValue( entity ) != f2.getValue( entity ) ) { outputFile << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; } } } }; template< typename MeshFunction, typename Real, typename Device, typename Index > class ExactMatchTest< MeshFunction, Meshes::Grid< 3, Real, Device, Index >, 3 > { public: static void run( const MeshFunction& f1, const MeshFunction& f2, const String& f1Name, const String& f2Name, std::fstream& outputFile, bool verbose = false ) { const int Dimension = 3; const int EntityDimension = 3; using Grid = Meshes::Grid< Dimension, Real, Device, Index >; using Entity = typename Grid::template EntityType< EntityDimension >; if( f1.getMesh().getDimensions() != f2.getMesh().getDimensions() ) { outputFile << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; } Entity entity( f1.getMesh() ); for( entity.getCoordinates().z() = 0; entity.getCoordinates().z() < f1.getMesh().getDimensions().z(); entity.getCoordinates().z()++ ) for( entity.getCoordinates().y() = 0; entity.getCoordinates().y() < f1.getMesh().getDimensions().y(); entity.getCoordinates().y()++ ) for( entity.getCoordinates().x() = 0; entity.getCoordinates().x() < f1.getMesh().getDimensions().x(); entity.getCoordinates().x()++ ) { entity.refresh(); if( f1.getValue( entity ) != f2.getValue( entity ) ) { outputFile << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; } } } }; template< typename MeshPointer, typename Value, typename Real, typename Index > bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters ) { Loading @@ -38,6 +195,8 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con std::cerr << "Unable to open the file " << outputFileName << "." << std::endl; return false; } if( ! exactMatch ) { outputFile << "#"; outputFile << std::setw( 6 ) << "Time"; outputFile << std::setw( 18 ) << "L1 diff." Loading @@ -47,11 +206,13 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con << std::setw( 18 ) << "Total L2 diff." << std::setw( 18 ) << "Total Max. diff." << std::endl; } if( verbose ) std::cout << std::endl; typedef typename MeshPointer::ObjectType Mesh; Functions::MeshFunction< Mesh, Mesh::getMeshDimension(), Real > v1( meshPointer ), v2( meshPointer ), diff( meshPointer ); using MeshFunctionType = Functions::MeshFunction< Mesh, Mesh::getMeshDimension(), Real >; MeshFunctionType v1( meshPointer ), v2( meshPointer ), diff( meshPointer ); Real totalL1Diff( 0.0 ), totalL2Diff( 0.0 ), totalMaxDiff( 0.0 ); for( int i = 0; i < (int) inputFiles.size(); i ++ ) { Loading @@ -73,6 +234,7 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con outputFile.close(); return false; } if( ! exactMatch ) outputFile << std::setw( 6 ) << i/2 * snapshotPeriod << " "; file1 = inputFiles[ i ]; file2 = inputFiles[ i + 1 ]; Loading Loading @@ -100,6 +262,7 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con outputFile.close(); return false; } if( ! exactMatch ) outputFile << std::setw( 6 ) << ( i - 1 ) * snapshotPeriod << " "; file2 = inputFiles[ i ]; } Loading @@ -118,6 +281,7 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con return false; } //if( snapshotPeriod != 0.0 ) if( ! exactMatch ) outputFile << std::setw( 6 ) << ( i - half ) * snapshotPeriod << " "; file1 = inputFiles[ i - half ]; file2 = inputFiles[ i ]; Loading @@ -125,14 +289,9 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con diff = v1; diff -= v2; if( exactMatch ) ExactMatchTest< MeshFunctionType >::run( v1, v2, file1, file2, outputFile, verbose ); else { for( Index i = 0; i < diff.getData().getSize(); i++ ) if( diff[ i ] != 0 ) { outputFile << file1 << " and " << file2 << "differs at position " << i << std::endl; } } Real l1Diff = diff.getLpNorm( 1.0 ); Real l2Diff = diff.getLpNorm( 2.0 ); Real maxDiff = diff.getMaxNorm(); Loading Loading @@ -166,6 +325,7 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con diff.save( differenceFileName ); } } } outputFile.close(); if( verbose ) Loading Loading
src/Tools/tnl-diff.h +210 −50 Original line number Diff line number Diff line Loading @@ -20,6 +20,163 @@ using namespace TNL; template< typename MeshFunction, typename Mesh = typename MeshFunction::MeshType, int EntitiesDimension = MeshFunction::getEntitiesDimension() > class ExactMatchTest { public: static void run( const MeshFunction& f1, const MeshFunction& f2, const String& f1Name, const String& f2Name, std::fstream& outputFile, bool verbose = false) { TNL_ASSERT( false, "Not implemented yet." ); } }; template< typename MeshFunction, typename Real, typename Device, typename Index > class ExactMatchTest< MeshFunction, Meshes::Grid< 1, Real, Device, Index >, 1 > { public: static void run( const MeshFunction& f1, const MeshFunction& f2, const String& f1Name, const String& f2Name, std::fstream& outputFile, bool verbose = false ) { const int Dimension = 1; const int EntityDimension = 1; using Grid = Meshes::Grid< Dimension, Real, Device, Index >; using Entity = typename Grid::template EntityType< EntityDimension >; if( f1.getMesh().getDimensions() != f2.getMesh().getDimensions() ) { outputFile << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; } Entity entity( f1.getMesh() ); for( entity.getCoordinates().x() = 0; entity.getCoordinates().x() < f1.getMesh().getDimensions().x(); entity.getCoordinates().x()++ ) { entity.refresh(); if( f1.getValue( entity ) != f2.getValue( entity ) ) { outputFile << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; } } } }; template< typename MeshFunction, typename Real, typename Device, typename Index > class ExactMatchTest< MeshFunction, Meshes::Grid< 2, Real, Device, Index >, 2 > { public: static void run( const MeshFunction& f1, const MeshFunction& f2, const String& f1Name, const String& f2Name, std::fstream& outputFile, bool verbose = false ) { const int Dimension = 2; const int EntityDimension = 2; using Grid = Meshes::Grid< Dimension, Real, Device, Index >; using Entity = typename Grid::template EntityType< EntityDimension >; if( f1.getMesh().getDimensions() != f2.getMesh().getDimensions() ) { outputFile << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; } Entity entity( f1.getMesh() ); for( entity.getCoordinates().y() = 0; entity.getCoordinates().y() < f1.getMesh().getDimensions().y(); entity.getCoordinates().y()++ ) for( entity.getCoordinates().x() = 0; entity.getCoordinates().x() < f1.getMesh().getDimensions().x(); entity.getCoordinates().x()++ ) { entity.refresh(); if( f1.getValue( entity ) != f2.getValue( entity ) ) { outputFile << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; } } } }; template< typename MeshFunction, typename Real, typename Device, typename Index > class ExactMatchTest< MeshFunction, Meshes::Grid< 3, Real, Device, Index >, 3 > { public: static void run( const MeshFunction& f1, const MeshFunction& f2, const String& f1Name, const String& f2Name, std::fstream& outputFile, bool verbose = false ) { const int Dimension = 3; const int EntityDimension = 3; using Grid = Meshes::Grid< Dimension, Real, Device, Index >; using Entity = typename Grid::template EntityType< EntityDimension >; if( f1.getMesh().getDimensions() != f2.getMesh().getDimensions() ) { outputFile << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " are defined on different meshes. " << std::endl; } Entity entity( f1.getMesh() ); for( entity.getCoordinates().z() = 0; entity.getCoordinates().z() < f1.getMesh().getDimensions().z(); entity.getCoordinates().z()++ ) for( entity.getCoordinates().y() = 0; entity.getCoordinates().y() < f1.getMesh().getDimensions().y(); entity.getCoordinates().y()++ ) for( entity.getCoordinates().x() = 0; entity.getCoordinates().x() < f1.getMesh().getDimensions().x(); entity.getCoordinates().x()++ ) { entity.refresh(); if( f1.getValue( entity ) != f2.getValue( entity ) ) { outputFile << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; if( verbose ) std::cout << f1Name << " and " << f2Name << " differs at " << entity.getCoordinates() << " " << f1.getValue( entity ) << " != " << f2.getValue( entity ) <<std::endl; } } } }; template< typename MeshPointer, typename Value, typename Real, typename Index > bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters ) { Loading @@ -38,6 +195,8 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con std::cerr << "Unable to open the file " << outputFileName << "." << std::endl; return false; } if( ! exactMatch ) { outputFile << "#"; outputFile << std::setw( 6 ) << "Time"; outputFile << std::setw( 18 ) << "L1 diff." Loading @@ -47,11 +206,13 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con << std::setw( 18 ) << "Total L2 diff." << std::setw( 18 ) << "Total Max. diff." << std::endl; } if( verbose ) std::cout << std::endl; typedef typename MeshPointer::ObjectType Mesh; Functions::MeshFunction< Mesh, Mesh::getMeshDimension(), Real > v1( meshPointer ), v2( meshPointer ), diff( meshPointer ); using MeshFunctionType = Functions::MeshFunction< Mesh, Mesh::getMeshDimension(), Real >; MeshFunctionType v1( meshPointer ), v2( meshPointer ), diff( meshPointer ); Real totalL1Diff( 0.0 ), totalL2Diff( 0.0 ), totalMaxDiff( 0.0 ); for( int i = 0; i < (int) inputFiles.size(); i ++ ) { Loading @@ -73,6 +234,7 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con outputFile.close(); return false; } if( ! exactMatch ) outputFile << std::setw( 6 ) << i/2 * snapshotPeriod << " "; file1 = inputFiles[ i ]; file2 = inputFiles[ i + 1 ]; Loading Loading @@ -100,6 +262,7 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con outputFile.close(); return false; } if( ! exactMatch ) outputFile << std::setw( 6 ) << ( i - 1 ) * snapshotPeriod << " "; file2 = inputFiles[ i ]; } Loading @@ -118,6 +281,7 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con return false; } //if( snapshotPeriod != 0.0 ) if( ! exactMatch ) outputFile << std::setw( 6 ) << ( i - half ) * snapshotPeriod << " "; file1 = inputFiles[ i - half ]; file2 = inputFiles[ i ]; Loading @@ -125,14 +289,9 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con diff = v1; diff -= v2; if( exactMatch ) ExactMatchTest< MeshFunctionType >::run( v1, v2, file1, file2, outputFile, verbose ); else { for( Index i = 0; i < diff.getData().getSize(); i++ ) if( diff[ i ] != 0 ) { outputFile << file1 << " and " << file2 << "differs at position " << i << std::endl; } } Real l1Diff = diff.getLpNorm( 1.0 ); Real l2Diff = diff.getLpNorm( 2.0 ); Real maxDiff = diff.getMaxNorm(); Loading Loading @@ -166,6 +325,7 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con diff.save( differenceFileName ); } } } outputFile.close(); if( verbose ) Loading