test_mesh.cpp 2.62 KB
Newer Older
1
2
3
#include <numeric>

#include "catch.hpp"
4
5
6
7
#include "common/config.h"
#include "common/globalconstants.h"
#include "common/io.h"
#include "common/mesh.h"
8
9

TEST_CASE( "unit mesh tests", "[mesh]" ) {
Steffen Schotthöfer's avatar
Steffen Schotthöfer committed
10
    std::string config_file_name = std::string( TESTS_PATH ) + "input/unit_tests/common/unit_mesh.cfg";
11
12
13
14
15
16
17
18
19
20
21
22
23

    Config* config = new Config( config_file_name );
    Mesh* mesh     = LoadSU2MeshFromFile( config );

    SECTION( "sum of all cell areas is equal to total domain volume" ) {
        double domainArea   = 1.0;
        double computedArea = 0.0;
        auto cellAreas      = mesh->GetCellAreas();
        for( auto area : cellAreas ) computedArea += area;
        REQUIRE( std::fabs( computedArea - domainArea ) < std::numeric_limits<double>::epsilon() );
    }

    SECTION( "neighbor and faces are sorted equally" ) {
24
25
26
27
        auto n                 = mesh->GetNormals();
        auto neighbors         = mesh->GetNeighbours();
        double eps             = 1e-7;
        bool errorWithinBounds = true;
28
29
30
31
32
33
34
35
        for( unsigned i = 0; i < mesh->GetNumCells(); ++i ) {
            for( unsigned j = 0; j < mesh->GetNumNodesPerCell(); ++j ) {
                unsigned pos;
                unsigned nID = neighbors[i][j];
                if( nID == mesh->GetNumCells() ) continue;
                for( unsigned k = 0; k < neighbors[nID].size(); ++k ) {
                    if( neighbors[nID][k] == i ) pos = k;
                }
36
                if( blaze::l2Norm( n[i][j] + n[nID][pos] ) > eps ) errorWithinBounds = false;
37
38
            }
        }
39
        REQUIRE( errorWithinBounds );
40
41
42
    }

    SECTION( "sum over all normals yields zero" ) {
43
44
45
        auto n                 = mesh->GetNormals();
        double eps             = 1e-7;
        bool errorWithinBounds = true;
46
47
48
49
50
        for( unsigned i = 0; i < mesh->GetNumCells(); ++i ) {
            Vector sum( 2, 0.0 );
            for( unsigned j = 0; j < mesh->GetNumNodesPerCell(); ++j ) {
                sum += n[i][j];
            }
51
            if( blaze::l2Norm( sum ) > eps ) errorWithinBounds = false;
52
        }
53
        REQUIRE( errorWithinBounds );
54
55
56
    }

    SECTION( "mesh does not have any unassigned faces" ) {
57
58
59
        auto neighbors         = mesh->GetNeighbours();
        auto boundaryType      = mesh->GetBoundaryTypes();
        bool noUnassignedFaces = true;
60
        for( unsigned i = 0; i < mesh->GetNumCells(); ++i ) {
61
62
63
            if( !( neighbors[i].size() == mesh->GetNumNodesPerCell() ||
                   ( neighbors[i].size() < mesh->GetNumNodesPerCell() && boundaryType[i] != BOUNDARY_TYPE::NONE ) ) )
                noUnassignedFaces = false;
64
        }
65
        REQUIRE( noUnassignedFaces );
66
67
    }
}