46 #ifndef MUELU_UTILITIES_KOKKOS_DECL_HPP 47 #define MUELU_UTILITIES_KOKKOS_DECL_HPP 50 #if defined(HAVE_MUELU_KOKKOS_REFACTOR) 54 #include <Teuchos_ScalarTraits.hpp> 55 #include <Teuchos_ParameterList.hpp> 57 #include <Xpetra_BlockedCrsMatrix_fwd.hpp> 58 #include <Xpetra_CrsMatrix_fwd.hpp> 59 #include <Xpetra_CrsMatrixWrap_fwd.hpp> 60 #include <Xpetra_ExportFactory.hpp> 61 #include <Xpetra_ImportFactory_fwd.hpp> 62 #include <Xpetra_MapFactory_fwd.hpp> 63 #include <Xpetra_Map_fwd.hpp> 64 #include <Xpetra_MatrixFactory_fwd.hpp> 65 #include <Xpetra_Matrix_fwd.hpp> 66 #include <Xpetra_MultiVectorFactory_fwd.hpp> 67 #include <Xpetra_MultiVector_fwd.hpp> 68 #include <Xpetra_Operator_fwd.hpp> 69 #include <Xpetra_VectorFactory_fwd.hpp> 70 #include <Xpetra_Vector_fwd.hpp> 72 #ifdef HAVE_MUELU_EPETRA 73 #include <Epetra_MultiVector.h> 74 #include <Epetra_CrsMatrix.h> 75 #include <Xpetra_EpetraCrsMatrix_fwd.hpp> 76 #include <Xpetra_EpetraMultiVector_fwd.hpp> 80 #include "MueLu_Utilities.hpp" 82 #ifdef HAVE_MUELU_TPETRA 83 #include <Tpetra_CrsMatrix.hpp> 84 #include <Tpetra_Map.hpp> 85 #include <Tpetra_MultiVector.hpp> 86 #include <Xpetra_TpetraCrsMatrix_fwd.hpp> 87 #include <Xpetra_TpetraMultiVector_fwd.hpp> 100 template <
class Scalar,
101 class LocalOrdinal = int,
102 class GlobalOrdinal = LocalOrdinal,
103 class Node = KokkosClassic::DefaultNode::DefaultNodeType>
105 #undef MUELU_UTILITIES_KOKKOS_SHORT 109 typedef typename Teuchos::ScalarTraits<SC>::magnitudeType Magnitude;
111 #ifdef HAVE_MUELU_EPETRA 114 static RCP<const Epetra_MultiVector> MV2EpetraMV(RCP<MultiVector>
const Vec) {
return Utils::MV2EpetraMV(Vec); }
117 static const Epetra_MultiVector& MV2EpetraMV(
const MultiVector& Vec) {
return Utils::MV2EpetraMV(Vec); }
120 static RCP<const Epetra_CrsMatrix> Op2EpetraCrs(RCP<const Matrix> Op) {
return Utils::Op2EpetraCrs(Op); }
123 static const Epetra_CrsMatrix& Op2EpetraCrs(
const Matrix& Op) {
return Utils::Op2EpetraCrs(Op); }
130 #ifdef HAVE_MUELU_TPETRA 133 static RCP<const Tpetra::MultiVector<SC,LO,GO,NO> > MV2TpetraMV(RCP<MultiVector>
const Vec) {
return Utils::MV2TpetraMV(Vec); }
134 static RCP< Tpetra::MultiVector<SC,LO,GO,NO> > MV2NonConstTpetraMV(RCP<MultiVector> Vec) {
return Utils::MV2NonConstTpetraMV(Vec); }
137 static const Tpetra::MultiVector<SC,LO,GO,NO>& MV2TpetraMV(
const MultiVector& Vec) {
return Utils::MV2TpetraMV(Vec); }
140 static RCP<const Tpetra::CrsMatrix<SC,LO,GO,NO> > Op2TpetraCrs(RCP<const Matrix> Op) {
return Utils::Op2TpetraCrs(Op); }
143 static const Tpetra::CrsMatrix<SC,LO,GO,NO>& Op2TpetraCrs(
const Matrix& Op) {
return Utils::Op2TpetraCrs(Op); }
146 static RCP<const Tpetra::RowMatrix<SC,LO,GO,NO> > Op2TpetraRow(RCP<const Matrix> Op) {
return Utils::Op2TpetraRow(Op); }
149 static const RCP<const Tpetra::Map<LO, GO, NO> > Map2TpetraMap(
const Map& map) {
return Utils::Map2TpetraMap(map); }
152 static RCP<Xpetra::Matrix<SC,LO,GO,NO> > Crs2Op(RCP<CrsMatrix> Op) {
return Utils::Crs2Op(Op); }
160 static Teuchos::ArrayRCP<SC> GetMatrixDiagonal(
const Matrix& A);
168 static RCP<Vector> GetMatrixDiagonalInverse(
const Matrix& A, Magnitude tol = Teuchos::ScalarTraits<SC>::eps()*100);
178 static Teuchos::ArrayRCP<SC> GetLumpedMatrixDiagonal(
const Matrix& A);
187 static RCP<Vector> GetMatrixOverlappedDiagonal(
const Matrix& A);
198 static void ScaleMatrix(Matrix& Op,
const Teuchos::ArrayRCP<SC>& scalingVector,
bool doInverse =
true);
205 static Teuchos::Array<Magnitude> ResidualNorm(
const Operator& Op,
const MultiVector& X,
const MultiVector& RHS) {
209 static RCP<MultiVector> Residual(
const Operator& Op,
const MultiVector& X,
const MultiVector& RHS) {
219 static void Write(
const std::string& fileName,
const Map& M) {
Utils::Write(fileName, M); }
222 static void Write(
const std::string& fileName,
const MultiVector& Vec) {
Utils::Write(fileName, Vec); }
225 static void Write(
const std::string& fileName,
const Matrix& Op) {
Utils::Write(fileName, Op); }
228 static Teuchos::RCP<Matrix> Read(
const std::string& fileName, Xpetra::UnderlyingLib lib,
const RCP<
const Teuchos::Comm<int> >& comm,
bool binary =
false) {
236 static Teuchos::RCP<Matrix> Read(
const std::string& fileName,
237 const RCP<const Map> rowMap,
238 RCP<const Map> colMap = Teuchos::null,
239 const RCP<const Map> domainMap = Teuchos::null,
240 const RCP<const Map> rangeMap = Teuchos::null,
241 const bool callFillComplete =
true,
242 const bool binary =
false,
243 const bool tolerant =
false,
244 const bool debug =
false)
245 {
return Utils::Read(fileName, rowMap, colMap, domainMap, rangeMap, callFillComplete, binary, tolerant, debug); }
248 static void PauseForDebugger();
265 static SC PowerMethod(
const Matrix& A,
bool scaleByDiag =
true,
266 LO niters = 10, Magnitude tolerance = 1e-2,
bool verbose =
false,
unsigned int seed = 123) {
270 static void MyOldScaleMatrix(Matrix& Op,
const Teuchos::ArrayRCP<const SC>& scalingVector,
bool doInverse =
true,
271 bool doFillComplete =
true,
bool doOptimizeStorage =
true);
273 static void MyOldScaleMatrix_Tpetra(Matrix& Op,
const Teuchos::ArrayRCP<SC>& scalingVector,
274 bool doFillComplete,
bool doOptimizeStorage);
276 static RCP<Teuchos::FancyOStream> MakeFancy(std::ostream& os) {
return Utils::MakeFancy(os); }
282 static typename Teuchos::ScalarTraits<Scalar>::magnitudeType Distance2(
const MultiVector& v, LocalOrdinal i0, LocalOrdinal i1) {
return Utils::Distance2(v, i0, i1); }
291 static Teuchos::ArrayRCP<const bool> DetectDirichletRows(
const Matrix& A,
const Magnitude& tol = Teuchos::ScalarTraits<SC>::zero());
304 static void findDirichletRows(Teuchos::RCP<Matrix> A,
305 std::vector<LO>& dirichletRows);
306 static void findDirichletCols(Teuchos::RCP<Matrix> A,
307 std::vector<LO>& dirichletRows,
308 std::vector<LO>& dirichletCols);
309 static void Apply_BCsToMatrixRows(Teuchos::RCP<Matrix>& A,
310 std::vector<LO>& dirichletRows);
311 static void Apply_BCsToMatrixCols(Teuchos::RCP<Matrix>& A,
312 std::vector<LO>& dirichletCols);
313 static void Remove_Zeroed_Rows(Teuchos::RCP<Matrix>& A,
double tol=1.0e-14);
323 template <
class Scalar,
324 class LocalOrdinal = int,
325 class GlobalOrdinal = LocalOrdinal,
326 class Node = KokkosClassic::DefaultNode::DefaultNodeType>
327 class Utils2_kokkos {
337 static RCP<Matrix> Transpose(Matrix& Op,
bool optimizeTranspose =
false,
const std::string & label = std::string()) {
341 static RCP<MultiVector> ReadMultiVector (
const std::string& fileName,
const RCP<const Map>& map) {
344 static RCP<const Map> ReadMap (
const std::string& fileName, Xpetra::UnderlyingLib lib,
const RCP<
const Teuchos::Comm<int> >& comm) {
352 #define MUELU_UTILITIES_KOKKOS_SHORT 354 #endif // #if defined(HAVE_MUELU_KOKKOS_REFACTOR) 356 #endif // MUELU_UTILITIES_KOKKOS_DECL_HPP static void SetRandomSeed(const Teuchos::Comm< int > &comm)
Set seed for random number generator.
static RCP< Epetra_MultiVector > MV2NonConstEpetraMV(RCP< MultiVector > Vec)
static void Write(const std::string &fileName, const Map &M)
Read/Write methods.
static RCP< Matrix > Transpose(Matrix &Op, bool optimizeTranspose=false, const std::string &label=std::string())
Transpose a Xpetra::Matrix.
static const Epetra_Map & Map2EpetraMap(const Map &map)
static RCP< const Tpetra::MultiVector< SC, LO, GO, NO > > MV2TpetraMV(RCP< MultiVector > const Vec)
Helper utility to pull out the underlying Tpetra objects from an Xpetra object.
static Teuchos::Array< Magnitude > ResidualNorm(const Operator &Op, const MultiVector &X, const MultiVector &RHS)
static const RCP< const Tpetra::Map< LO, GO, NO > > Map2TpetraMap(const Map &map)
Namespace for MueLu classes and methods.
static RCP< Tpetra::MultiVector< SC, LO, GO, NO > > MV2NonConstTpetraMV(RCP< MultiVector > Vec)
static RCP< Xpetra::Matrix< SC, LO, GO, NO > > Crs2Op(RCP< CrsMatrix > Op)
static RCP< Tpetra::MultiVector< SC, LO, GO, NO > > MV2NonConstTpetraMV2(MultiVector &Vec)
static RCP< const Epetra_MultiVector > MV2EpetraMV(RCP< MultiVector > const Vec)
Helper utility to pull out the underlying Epetra objects from an Xpetra object.
static RCP< const Tpetra::RowMatrix< SC, LO, GO, NO > > Op2TpetraRow(RCP< const Matrix > Op)
static Teuchos::RCP< Matrix > Read(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, bool binary=false)
Read matrix from file in Matrix Market or binary format.
static RCP< const Epetra_CrsMatrix > Op2EpetraCrs(RCP< const Matrix > Op)
static RCP< const Tpetra::CrsMatrix< SC, LO, GO, NO > > Op2TpetraCrs(RCP< const Matrix > Op)
static RCP< Teuchos::FancyOStream > MakeFancy(std::ostream &os)
static RCP< Tpetra::CrsMatrix< SC, LO, GO, NO > > Op2NonConstTpetraCrs(RCP< Matrix > Op)
static RCP< Tpetra::RowMatrix< SC, LO, GO, NO > > Op2NonConstTpetraRow(RCP< Matrix > Op)
static Teuchos::ScalarTraits< Scalar >::magnitudeType Distance2(const MultiVector &v, LocalOrdinal i0, LocalOrdinal i1)
Squared distance between two rows in a multivector.
static RCP< const Map > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
static RCP< MultiVector > ReadMultiVector(const std::string &fileName, const RCP< const Map > &map)
static Scalar PowerMethod(const Matrix &A, bool scaleByDiag=true, LO niters=10, Magnitude tolerance=1e-2, bool verbose=false, unsigned int seed=123)
Simple transpose for Tpetra::CrsMatrix types.
static RCP< Epetra_CrsMatrix > Op2NonConstEpetraCrs(RCP< Matrix > Op)
static RCP< MultiVector > Residual(const Operator &Op, const MultiVector &X, const MultiVector &RHS)