test_cases.cpp 3.22 KB
Newer Older
1
2
3
4
5
6
#include <vtkSmartPointer.h>
#include <vtkUnstructuredGridReader.h>

#include "catch.hpp"
#include "mesh.h"
#include "settings/config.h"
7
#include "solvers/solverbase.h"
8
9
10
11
12
13
14
15
16
17

using vtkUnstructuredGridReaderSP = vtkSmartPointer<vtkUnstructuredGridReader>;

std::vector<double> readVTKFile( std::string filename ) {
    auto reader = vtkUnstructuredGridReaderSP::New();
    reader->SetFileName( filename.c_str() );
    reader->ReadAllScalarsOn();
    reader->ReadAllVectorsOn();
    reader->Update();

18
19
20
    auto grid         = reader->GetOutput();
    unsigned numCells = grid->GetNumberOfCells();
    auto cellData     = grid->GetCellData()->GetArray( 0 );
21

22
    std::vector<double> data( numCells, 0.0 );
23

24
    for( unsigned i = 0; i < numCells; ++i ) {
25
26
27
28
29
30
        data[i] = cellData->GetTuple1( static_cast<int>( i ) );
    }

    return data;
}

31
TEST_CASE( "checkerboard_SN", "[testcases]" ) {
32
    std::string config_file_name = "../tests/input/checkerboard.cfg";
33
34
35
36
37
38
39
40
41
42
43

    Config* config = new Config( config_file_name );
    Solver* solver = Solver::Create( config );
    solver->Solve();
    solver->Save();

    auto test      = readVTKFile( "../result/rtsn_test_checkerboard.vtk" );
    auto reference = readVTKFile( "../tests/input/checkerboard_reference.vtk" );

    double eps = 1e-3;
    REQUIRE( test.size() == reference.size() );
44
    for( unsigned i = 0; i < test.size(); ++i ) {
45
46
47
48
        REQUIRE( std::fabs( test[i] - reference[i] ) < eps );
    }
}

49
TEST_CASE( "linesource_SN", "[testcases]" ) {
50
    std::string config_file_name = "../tests/input/linesource.cfg";
51
52
53
54
55
56
57

    Config* config = new Config( config_file_name );
    Solver* solver = Solver::Create( config );
    solver->Solve();
    solver->Save();

    auto test      = readVTKFile( "../result/rtsn_test_linesource.vtk" );
58
    auto reference = readVTKFile( "../tests/input/linesource_SN_reference.vtk" );
59
60
61
62
63
64
65

    double eps = 1e-3;
    REQUIRE( test.size() == reference.size() );
    for( unsigned i = 0; i < test.size(); ++i ) {
        REQUIRE( std::fabs( test[i] - reference[i] ) < eps );
    }
}
66

67
68
69
70
71
72
73
74
75
TEST_CASE( "linesource_PN", "[testcases]" ) {
    char config_file_name[MAX_STRING_SIZE] = "../tests/input/linesource_PN.cfg";

    Config* config = new Config( config_file_name );
    Solver* solver = Solver::Create( config );
    solver->Solve();
    solver->Save();

    auto test      = readVTKFile( "../result/rtsn_test_linesource_PN.vtk" );
76
    auto reference = readVTKFile( "../tests/input/linesource_PN_reference.vtk" );
77
78
79
80
81
82
83

    double eps = 1e-3;
    REQUIRE( test.size() == reference.size() );
    for( unsigned i = 0; i < test.size(); ++i ) {
        REQUIRE( std::fabs( test[i] - reference[i] ) < eps );
    }
}
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

TEST_CASE( "linesource_MN", "[testcases]" ) {
    char config_file_name[MAX_STRING_SIZE] = "../tests/input/linesource_MN.cfg";

    Config* config = new Config( config_file_name );
    Solver* solver = Solver::Create( config );
    solver->Solve();
    solver->Save();

    auto test      = readVTKFile( "../result/rtsn_test_linesource_PN.vtk" );
    auto reference = readVTKFile( "../tests/input/linesource_MN_reference.vtk" );

    double eps = 1e-3;
    REQUIRE( test.size() == reference.size() );
    for( unsigned i = 0; i < test.size(); ++i ) {
        REQUIRE( std::fabs( test[i] - reference[i] ) < eps );
    }
}