GlobalMatrix.cpp 2.06 KB
Newer Older
1 2
//! \file 
//
3 4 5 6 7 8 9 10
//
//  GlobalMatrix.cpp
//  HappyHeart
//
//  Created by Sebastien Gilles on 27/04/15.
//  Copyright (c) 2015 Inria. All rights reserved.
//

11 12 13 14 15 16 17
#include <algorithm>

#include "Utilities/Containers/Print.hpp" //\todo #820 DEV
#include "Utilities/Exceptions/Exception.hpp"
#include "Utilities/Exceptions/PrintAndAbort.hpp"

#include "ThirdParty/Wrappers/Petsc/Matrix/MatrixPattern.hpp"
18

19
#include "Core/LinearAlgebra/GlobalMatrix.hpp"
20
#include "Core/NumberingSubset/NumberingSubset.hpp"
21 22 23 24 25 26


namespace HappyHeart
{
    
    
27 28
    GlobalMatrix::GlobalMatrix(const NumberingSubset& row_numbering_subset,
                               const NumberingSubset& col_numbering_subset)
29
    : Crtp::NumberingSubsetForMatrix<GlobalMatrix>(row_numbering_subset, col_numbering_subset)
30 31 32
    { }
    
    
33
    GlobalMatrix::GlobalMatrix(const GlobalMatrix& rhs)
34 35
    : petsc_parent(rhs),
    numbering_subset_parent(rhs)
36 37 38 39 40
    { }
    
    
    void Swap(GlobalMatrix& A, GlobalMatrix& B)
    {
41
        // We swap the content of two matrices that share the same numbering subsets.
42 43
        assert(A.GetColNumberingSubset() == B.GetColNumberingSubset());
        assert(A.GetRowNumberingSubset() == B.GetRowNumberingSubset());
44
        
45
        using parent = GlobalMatrix::petsc_parent;
46
        
47
        Swap(static_cast<parent&>(A), static_cast<parent&>(B));
48
    }
49 50
    
    
51
    # ifndef NDEBUG
52 53 54 55 56 57
    void AssertSameNumberingSubset(const GlobalMatrix& matrix1,
                                   const GlobalMatrix& matrix2)
    {
        assert(matrix1.GetRowNumberingSubset() == matrix2.GetRowNumberingSubset());
        assert(matrix1.GetColNumberingSubset() == matrix2.GetColNumberingSubset());
    }
58 59 60 61 62 63 64 65 66
    
    
    void PrintNumberingSubset(std::string&& matrix_name,
                              const GlobalMatrix& matrix)
    {
        std::cout << "Numbering subsets for matrix '" << matrix_name << "': row -> "
        << matrix.GetRowNumberingSubset().GetUniqueId() << " and col -> "
        << matrix.GetColNumberingSubset().GetUniqueId() << std::endl;
    }
67
    # endif // NDEBUG
68

69
    
70
} // namespace HappyHeart