10 #ifndef MUELU_CONSTRAINT_DEF_HPP
11 #define MUELU_CONSTRAINT_DEF_HPP
20 #include <Xpetra_Map.hpp>
22 #include <Xpetra_MultiVectorFactory.hpp>
32 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
34 const size_t NSDim = Bc.getNumVectors();
38 size_t numRows = Ppattern_->getLocalNumRows();
39 XXtInv_.resize(numRows);
43 X_ = MultiVectorFactory::Build(Ppattern_->getColMap(), NSDim);
49 std::vector<const SC*> Xval(NSDim);
50 for (
size_t j = 0; j < NSDim; j++)
51 Xval[j] = X_->getData(j).get();
62 for (
size_t i = 0; i < numRows; i++) {
64 Ppattern_->getLocalRowView(i, indices);
66 size_t nnz = indices.
size();
73 for (
size_t j = 0; j < nnz; j++)
74 d += Xval[0][indices[j]] * Xval[0][indices[j]];
75 XXtInv(0, 0) = one / d;
79 for (
size_t j = 0; j < nnz; j++)
80 for (
size_t k = 0; k < NSDim; k++)
81 locX(k, j) = Xval[k][indices[j]];
99 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
103 "Row maps are incompatible");
104 const size_t NSDim = X_->getNumVectors();
105 const size_t numRows = P.getLocalNumRows();
107 const Map& colMap = *P.getColMap();
108 const Map& PColMap = *Projected.getColMap();
110 Projected.resumeFill();
121 std::vector<const SC*> Xval(NSDim);
122 for (
size_t j = 0; j < NSDim; j++)
123 Xval[j] = X_->getData(j).get();
125 for (
size_t i = 0; i < numRows; i++) {
126 P.getLocalRowView(i, indices, values);
127 Projected.getLocalRowView(i, pindices, pvalues);
129 size_t nnz = indices.
size();
130 size_t pnnz = pindices.
size();
132 newValues.resize(pnnz);
142 for (
size_t j = 0; j < nnz; j++)
143 valuesAll[indices[j]] = values[j];
144 for (
size_t j = 0; j < pnnz; j++) {
145 LO ind = colMap.getLocalElement(PColMap.getGlobalElement(pindices[j]));
148 newValues[j] = valuesAll[ind];
152 for (
size_t j = 0; j < nnz; j++)
153 valuesAll[indices[j]] = zero;
159 for (
size_t j = 0; j < pnnz; j++)
160 for (
size_t k = 0; k < NSDim; k++)
161 locX(k, j) = Xval[k][pindices[j]];
164 for (
size_t j = 0; j < pnnz; j++)
165 val[j] = newValues[j];
172 zero, val1.values(), oneLO);
176 val1.values(), oneLO,
177 zero, val2.
values(), oneLO);
182 zero, val.values(), oneLO);
184 for (
size_t j = 0; j < pnnz; j++)
185 newValues[j] -= val[j];
187 Projected.replaceLocalValues(i, pindices, newValues);
190 Projected.fillComplete(Projected.getDomainMap(), Projected.getRangeMap());
195 #endif // ifndef MUELU_CONSTRAINT_DEF_HPP
ScalarType * values() const
void GEMV(ETransp trans, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const x_type *x, const OrdinalType &incx, const beta_type beta, ScalarType *y, const OrdinalType &incy) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void Setup(const MultiVector &B, const MultiVector &Bc, RCP< const CrsGraph > Ppattern)
void GEMM(ETransp transa, ETransp transb, const OrdinalType &m, const OrdinalType &n, const OrdinalType &k, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const B_type *B, const OrdinalType &ldb, const beta_type beta, ScalarType *C, const OrdinalType &ldc) const
Exception throws to report incompatible objects (like maps).
void GETRF(const OrdinalType &m, const OrdinalType &n, ScalarType *A, const OrdinalType &lda, OrdinalType *IPIV, OrdinalType *info) const
void Apply(const Matrix &P, Matrix &Projected) const
Apply constraint.
void GETRI(const OrdinalType &n, ScalarType *A, const OrdinalType &lda, const OrdinalType *IPIV, ScalarType *WORK, const OrdinalType &lwork, OrdinalType *info) const
OrdinalType stride() const