MatrixOperations.hpp 7.11 KB
Newer Older
1 2
//! \file 
//
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
//
//  MatrixTOperations.hpp
//  HappyHeart
//
//  Created by Sebastien Gilles on 30/10/15.
//  Copyright © 2015 Inria. All rights reserved.
//

#ifndef HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_MATRIX_x_MATRIX_OPERATIONS_HPP_
# define HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_MATRIX_x_MATRIX_OPERATIONS_HPP_

# include <memory>
# include <vector>

# include "ThirdParty/IncludeWithoutWarning/Petsc/PetscSys.hpp"
# include "ThirdParty/IncludeWithoutWarning/Petsc/PetscMat.hpp"

# include "ThirdParty/Wrappers/Petsc/Vector/Vector.hpp"
# include "ThirdParty/Wrappers/Petsc/Matrix/Private/BaseMatrix.hpp"
# include "ThirdParty/Wrappers/Petsc/Exceptions/Petsc.hpp"


namespace HappyHeart
{
    
    
    namespace Wrappers
    {
        
        
        namespace Petsc
        {
35 36
            
            
37 38 39 40 41 42 43
            /*!
             * \brief Wrapper over MatAXPY, that performs Y = a * X + Y.
             *
             * \param[in] structure either SAME_NONZERO_PATTERN, DIFFERENT_NONZERO_PATTERN or SUBSET_NONZERO_PATTERN.
             * \param[in] invoking_file File that invoked the function or class; usually __FILE__.
             * \param[in] invoking_line File that invoked the function or class; usually __LINE__.
             */
44 45 46 47 48 49 50 51 52 53 54
            template
            <
                class MatrixT,
                class MatrixU
            >
            std::enable_if_t
            <
                std::is_base_of<Private::BaseMatrix, MatrixT>::value
             && std::is_base_of<Private::BaseMatrix, MatrixU>::value,
                void
            >
55 56
            AXPY(PetscScalar a,
                 const MatrixT& X,
57
                 MatrixU& Y,
58 59 60 61 62 63 64 65 66 67 68 69 70
                 const char* invoking_file, int invoking_line,
                 const MatStructure& structure = SAME_NONZERO_PATTERN);
            
            
            /*!
             * \brief Wrapper over MatMult, that performs v2 = matrix * v1.
             *
             * \param[in] invoking_file File that invoked the function or class; usually __FILE__.
             * \param[in] invoking_line File that invoked the function or class; usually __LINE__.
             */
            template<class MatrixT>
            std::enable_if_t<std::is_base_of<Private::BaseMatrix, MatrixT>::value, void>
            MatMult(const MatrixT& matrix, const Vector& v1, Vector& v2,
71
                    const char* invoking_file, int invoking_line);
72 73 74 75 76 77 78 79 80 81 82
            
            
            /*!
             * \brief Wrapper over MatMultAdd, that performs v3 = v2 + matrix * v1.
             *
             * \param[in] invoking_file File that invoked the function or class; usually __FILE__.
             * \param[in] invoking_line File that invoked the function or class; usually __LINE__.
             */
            template<class MatrixT>
            std::enable_if_t<std::is_base_of<Private::BaseMatrix, MatrixT>::value, void>
            MatMultAdd(const MatrixT& matrix, const Vector& v1, const Vector& v2, Vector& v3,
83
                       const char* invoking_file, int invoking_line);
84 85 86 87 88 89 90 91 92 93 94 95
            
            
            
            /*!
             * \brief Wrapper over MatMultTranspose, that performs v2 = transpose(matrix) * v1.
             *
             * \param[in] invoking_file File that invoked the function or class; usually __FILE__.
             * \param[in] invoking_line File that invoked the function or class; usually __LINE__.
             */
            template<class MatrixT>
            std::enable_if_t<std::is_base_of<Private::BaseMatrix, MatrixT>::value, void>
            MatMultTranspose(const MatrixT& matrix, const Vector& v1, Vector& v2,
96
                             const char* invoking_file, int invoking_line);
97 98 99 100 101 102 103 104 105 106 107
            
            
            /*!
             * \brief Wrapper over MatMultTransposeAdd, that performs v3 = v2 + transpose(matrix) * v1.
             *
             * \param[in] invoking_file File that invoked the function or class; usually __FILE__.
             * \param[in] invoking_line File that invoked the function or class; usually __LINE__.
             */
            template<class MatrixT>
            std::enable_if_t<std::is_base_of<Private::BaseMatrix, MatrixT>::value, void>
            MatMultTransposeAdd(const MatrixT& matrix, const Vector& v1, const Vector& v2, Vector& v3,
108
                                const char* invoking_file, int invoking_line);
109 110 111 112 113 114 115 116 117 118 119 120 121
            
            
            /*!
             * \brief Wrapper over MatMatMult, that performs C = A * B.
             *
             * \todo #684 Investigate to use the argument fill, which provides an estimation of the non zero of the
             * resulting matrix. Currently PETSC_DEFAULT is used.
             * One can also reuse a pattern for several matrices, but so far I do not need that in HappyHeart so
             * I equally use the default setting.
             *
             * \param[in] invoking_file File that invoked the function or class; usually __FILE__.
             * \param[in] invoking_line File that invoked the function or class; usually __LINE__.
             */
122 123 124 125 126 127 128 129 130 131 132
            template
            <
                class MatrixT,
                class MatrixU
            >
            std::enable_if_t
            <
                std::is_base_of<Private::BaseMatrix, MatrixT>::value
                && std::is_base_of<Private::BaseMatrix, MatrixU>::value,
                void
            >
133
            MatMatMult(const MatrixT& matrix1,
134 135 136
                       const MatrixT& matrix2,
                       MatrixU& matrix3,
                       const char* invoking_file, int invoking_line);
137 138 139 140 141 142 143 144 145 146 147 148 149
            
            
            /*!
             * \brief Wrapper over MatMatMatMult, that performs D = A * B * C.
             *
             * \todo #684 Investigate to use the argument fill, which provides an estimation of the non zero of the
             * resulting matrix. Currently PETSC_DEFAULT is used.
             * One can also reuse a pattern for several matrices, but so far I do not need that in HappyHeart so
             * I equally use the default setting.
             *
             * \param[in] invoking_file File that invoked the function or class; usually __FILE__.
             * \param[in] invoking_line File that invoked the function or class; usually __LINE__.
             */
150 151 152 153 154 155 156 157 158 159 160
            template
            <
                class MatrixT,
                class MatrixU
            >
            std::enable_if_t
            <
                std::is_base_of<Private::BaseMatrix, MatrixT>::value
                && std::is_base_of<Private::BaseMatrix, MatrixU>::value,
                void
            >
161
            MatMatMatMult(const MatrixT& matrix1,
162 163 164 165
                          const MatrixT& matrix2,
                          const MatrixT& matrix3,
                          MatrixU& matrix4,
                          const char* invoking_file, int invoking_line);
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
            
            
            
        } //namespace Petsc
        
        
    } //namespace Wrappers
    
    
} // namespace HappyHeart


# include "ThirdParty/Wrappers/Petsc/Matrix/MatrixOperations.hxx"


#endif // HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_MATRIX_x_MATRIX_OPERATIONS_HPP_