44 #ifndef MY_OPERATOR_HPP
45 #define MY_OPERATOR_HPP
47 #include "Tpetra_Operator.hpp"
48 #include "Tpetra_Vector.hpp"
49 #include "Tpetra_VectorSpace.hpp"
60 template <
class OrdinalType,
class ScalarType>
61 class MyOperator :
public Tpetra::Operator<OrdinalType,ScalarType>
67 MyOperator(
const Tpetra::VectorSpace<OrdinalType,ScalarType>& vs,
68 const int nrows,
const int *colptr,
69 const int nnz,
const int *rowin,
const ScalarType *vals)
72 std::copy<const int*,IntIter>(colptr,colptr+nrows+1,
_cptr.begin());
73 std::copy<const int*,IntIter>(rowin,rowin+nnz,
_rind.begin());
74 std::copy<const ScalarType*,STIter>(vals,vals+nnz,
_vals.begin());
86 Tpetra::VectorSpace<OrdinalType,ScalarType>
const&
getDomainDist()
const {
return _vs; };
89 Tpetra::VectorSpace<OrdinalType,ScalarType>
const&
getRangeDist()
const {
return _vs; };
92 void apply(Tpetra::Vector<OrdinalType,ScalarType>
const& x,
93 Tpetra::Vector<OrdinalType, ScalarType> & y,
94 bool transpose=
false)
const
97 const int numMyElements =
_vs.getNumMyEntries();
98 const std::vector<int> &myGlobalElements =
_vs.elementSpace().getMyGlobalElements();
103 assert (x.getNumGlobalEntries() == y.getNumGlobalEntries());
104 assert (x.getNumGlobalEntries() == y.getNumGlobalEntries());
109 for (
int myRow = 0; myRow < numMyElements; ++myRow ) {
112 const int rowIndex = myGlobalElements[myRow];
113 for (j=0; j<
_nr; j++) {
116 for (i=IA1; i<IA2; i++) {
119 y[rowIndex] +=
_vals[i]*x[j];
130 typedef typename std::vector<ScalarType>::iterator
STIter;
134 Tpetra::VectorSpace<OrdinalType,ScalarType>
_vs;
146 #endif //MY_OPERATOR_HPP
int _nr
Number of rows and columns.
void apply(Tpetra::Vector< OrdinalType, ScalarType > const &x, Tpetra::Vector< OrdinalType, ScalarType > &y, bool transpose=false) const
Computes the matrix-std::vector multiplication y = Ax.
std::vector< ScalarType >::iterator STIter
std::vector< int >::iterator IntIter
MyOperator(const Tpetra::VectorSpace< OrdinalType, ScalarType > &vs, const int nrows, const int *colptr, const int nnz, const int *rowin, const ScalarType *vals)
Constructor.
Tpetra::VectorSpace< OrdinalType, ScalarType > const & getDomainDist() const
Returns the VectorSpace associated with the domain of this linear operator.
std::vector< int > _rind
Row indices.
Tpetra::VectorSpace< OrdinalType, ScalarType > const & getRangeDist() const
Returns the VectorSpace associated with the range of this linear operator.
Tpetra::VectorSpace< OrdinalType, ScalarType > _vs
Tpetra std::vector space.
std::vector< int > _cptr
Column pointers.
Simple example of a user's defined Tpetra::Operator class.
std::vector< ScalarType > _vals
Values.
~MyOperator()
Deconstructor.