main.cpp 3.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*!
 // \file
 //
 //
 // Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Fri, 26 Apr 2013 12:18:22 +0200
 // Copyright (c) Inria. All rights reserved.
 //
 */


#include <cstdlib>

#define BOOST_TEST_MODULE petsc_matrix_io
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "ThirdParty/Wrappers/Tclap/StringPair.hpp"

#include "Utilities/Numeric/Numeric.hpp"
#include "Utilities/Exceptions/PrintAndAbort.hpp"
#include "Utilities/Filesystem/File.hpp"

#include "Core/MoReFEMData/MoReFEMData.hpp"

#include "Test/Tools/Fixture/Model.hpp"
24
#include "Test/ThirdParty/PETSc/Matrix/ToyModel.hpp"
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46


using namespace MoReFEM;


namespace // anonymous
{


    struct LuaFile
    {


        static std::string GetPath();


    };


    using fixture_type =
    TestNS::FixtureNS::Model
    <
47
        TestNS::PetscNS::MatrixNS::ToyModel,
48 49 50 51 52
        LuaFile,
        TestNS::FixtureNS::call_run_method_at_first_call::no
    >;


53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    /*!
     * \brief Determines the path and name of the matrix on file and make sure it doesn't exist yet.
     */
    std::string PrepareFile(const TestNS::PetscNS::MatrixNS::ToyModel& model)
    {
        std::ostringstream oconv;
        oconv << model.GetOutputDirectory() << "/matrix_test_IO.bin";

        const auto filename = oconv.str();

        if (model.GetMpi().IsRootProcessor())
        {
            if (FilesystemNS::File::DoExist(filename))
                FilesystemNS::File::Remove(filename, __FILE__, __LINE__);
        }

        return filename;
    }



74 75 76 77 78 79 80 81 82
} // namespace anonymous


PRAGMA_DIAGNOSTIC(push)
#include "Utilities/Warnings/Internal/IgnoreWarning/disabled-macro-expansion.hpp"




83 84 85
BOOST_FIXTURE_TEST_CASE(creation, fixture_type)
{
    decltype(auto) model = GetModel();
86
    static_cast<void>(model);
87
}
88

89

90
BOOST_FIXTURE_TEST_CASE(load, fixture_type)
91 92 93 94 95 96
{
    decltype(auto) model = GetModel();
    decltype(auto) mpi = model.GetMpi();

    decltype(auto) matrix = model.GetMatrix();

97
    const auto matrix_file = PrepareFile(model);
98

99 100
    if (mpi.IsRootProcessor())
        BOOST_CHECK(FilesystemNS::File::DoExist(matrix_file) == false);
101 102

    matrix.View(mpi,
103
                matrix_file,
104
                __FILE__, __LINE__,
105
                PETSC_VIEWER_BINARY_MATLAB,
106
                FILE_MODE_WRITE);
107 108

    if (mpi.IsRootProcessor())
109
        BOOST_CHECK(FilesystemNS::File::DoExist(matrix_file) == true);
110

111 112
    GlobalMatrix loaded_matrix(matrix.GetRowNumberingSubset(),
                               matrix.GetColNumberingSubset());
113

114 115 116
    loaded_matrix.DuplicateLayout(matrix,
                                  MAT_DO_NOT_COPY_VALUES,
                                  __FILE__, __LINE__);
117

118
    loaded_matrix.LoadBinary(mpi, matrix_file, __FILE__, __LINE__);
119

120
    BOOST_CHECK(Wrappers::Petsc::AreStrictlyEqual(matrix, loaded_matrix, __FILE__, __LINE__));
121
}
122 123 124 125 126 127 128 129 130 131 132 133 134 135


PRAGMA_DIAGNOSTIC(pop)


namespace // anonymous
{


    std::string LuaFile::GetPath()
    {
        decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);

        return
136
            environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/ThirdParty/PETSc/Matrix/IO/demo.lua");
137 138 139 140 141
    }


} // namespace anonymous