1 /*
2 XLiFE++ is an extended library of finite elements written in C++
3     Copyright (C) 2014  Lunéville, Eric; Kielbasiewicz, Nicolas; Lafranche, Yvon; Nguyen, Manh-Ha; Chambeyron, Colin
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13     You should have received a copy of the GNU General Public License
14     along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 /*!
18   \file LargeMatrixAdapter.hpp
19   \author Manh Ha NGUYEN
20   \since 05 April 2013
21   \date  03 April 2014
22 
23   \brief Definition of the xlifepp::LargeMatrixAdapter class
24 
25   xlifepp::LargeMatrixAdapter which is used in xlifepp::EigenSolver. This class is inherited from the virtual class xlifepp::Operator.
26   This class, in fact, is an interface between the class xlifepp::LargeMatrix and the class xlifepp::Operator
27 */
28 
29 #ifndef LARGEMATRIX_ADAPTER_HPP
30 #define LARGEMATRIX_ADAPTER_HPP
31 
32 #include "utils.h"
33 #include "MultiVectorAdapter.hpp"
34 #include "../../eigenSolvers/eigenSparse/XlifeppMultiVec.hpp"
35 #include "../../eigenSolvers/eigenSparse/XlifeppOperator.hpp"
36 
37 namespace xlifepp {
38 
39   /*!
40     \class LargeMatrixAdapter
41     \brief Template specialization of Operator class using the Operator virtual base class and
42     LargeMatrix class.
43 
44     This interface will ensure that any Operator and MultVec will be accepted by the templated solvers.
45   */
46   template<typename MatrixType, typename ScalarType>
47   class LargeMatrixAdapter : public Operator<ScalarType>
48   {
49   private:
50       typedef const MatrixType LMatrix;
51   public:
52 //      LargeMatrixAdapter() { lMatrix_p = NULL; }
LargeMatrixAdapter(LMatrix * p)53       LargeMatrixAdapter(LMatrix* p) { lMatrix_p = p; }
54 
operator =(LMatrix matrix)55       LargeMatrixAdapter& operator=(LMatrix matrix) { lMatrix_p = &matrix; return (*this); }
56 
57 
58       //! Destructor.
~LargeMatrixAdapter()59       virtual ~LargeMatrixAdapter() {}
60 
apply(const MultiVec<ScalarType> & x,MultiVec<ScalarType> & y) const61       void apply(const MultiVec<ScalarType>& x, MultiVec<ScalarType>& y) const
62       {
63           for (int i = 0; i< x.getNumberVecs(); ++i) {
64               //multMatrixVector(*lMatrix_p, *(x[i]), *(y[i]));
65               *(y[i]) = *lMatrix_p * *(x[i]);
66           }
67       }
68 
69       // This function exists for the testing purpose
70       template<typename Scalar,typename ScalarTypeX, typename MatrixTypeX>
71       friend void multMatVecLargeMatrixAdapter(const LargeMatrixAdapter<MatrixTypeX, Scalar>& m,
72               const MultiVec<ScalarTypeX>& x,
73               MultiVec<typename Conditional<NumTraits<Scalar>::IsComplex, Scalar, ScalarTypeX>::type >& y);
74 
75   private:
76       LMatrix*  lMatrix_p;
77   };
78 
79   template<typename Scalar,typename ScalarTypeX, typename MatrixType>
multMatVecLargeMatrixAdapter(const LargeMatrixAdapter<MatrixType,Scalar> & m,const MultiVec<ScalarTypeX> & x,MultiVec<typename Conditional<NumTraits<Scalar>::IsComplex,Scalar,ScalarTypeX>::type> & y)80   void multMatVecLargeMatrixAdapter(const LargeMatrixAdapter<MatrixType, Scalar>& m,
81                                     const MultiVec<ScalarTypeX>& x,
82                                     MultiVec<typename Conditional<NumTraits<Scalar>::IsComplex, Scalar, ScalarTypeX>::type >& y)
83   {
84       for (int i = 0; i< x.getNumberVecs(); ++i) {
85 //          multMatrixVector(*(m.lMatrix_p), *(x[i]), *(y[i]));
86           *(y[i]) = *(m.lMatrix_p) * *(x[i]);
87       }
88   }
89 
90 } // end of xlifepp namespace
91 
92 #endif /* LARGEMATRIX_ADAPTER_HPP */
93 
94