MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_Utilities_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_UTILITIES_DECL_HPP
11 #define MUELU_UTILITIES_DECL_HPP
12 
13 #include <string>
14 
15 #include "MueLu_ConfigDefs.hpp"
16 
17 #include <Teuchos_DefaultComm.hpp>
18 #include <Teuchos_ScalarTraits.hpp>
20 
21 #include <Xpetra_TpetraBlockCrsMatrix_fwd.hpp>
23 #include <Xpetra_CrsMatrix_fwd.hpp>
24 #include <Xpetra_CrsMatrixWrap.hpp>
25 #include <Xpetra_Map_fwd.hpp>
26 #include <Xpetra_Matrix_fwd.hpp>
29 #include <Xpetra_Operator_fwd.hpp>
30 #include <Xpetra_Vector_fwd.hpp>
32 
33 #include <Xpetra_MatrixMatrix.hpp>
34 
35 #ifdef HAVE_MUELU_EPETRA
37 
38 // needed because of inlined function
39 // TODO: remove inline function?
42 
43 #endif
44 
45 #include "MueLu_Exceptions.hpp"
46 
47 #ifdef HAVE_MUELU_EPETRAEXT
48 class Epetra_CrsMatrix;
49 class Epetra_MultiVector;
50 class Epetra_Vector;
52 #endif
53 
54 #include <Tpetra_CrsMatrix.hpp>
55 #include <Tpetra_BlockCrsMatrix.hpp>
56 #include <Tpetra_BlockCrsMatrix_Helpers.hpp>
57 #include <Tpetra_FECrsMatrix.hpp>
58 #include <Tpetra_RowMatrixTransposer.hpp>
59 #include <Tpetra_Map.hpp>
60 #include <Tpetra_MultiVector.hpp>
61 #include <Tpetra_FEMultiVector.hpp>
65 
66 #include <MueLu_UtilitiesBase.hpp>
67 
68 namespace MueLu {
69 
70 #ifdef HAVE_MUELU_EPETRA
71 // defined after Utilities class
72 template <typename SC, typename LO, typename GO, typename NO>
73 RCP<Xpetra::CrsMatrixWrap<SC, LO, GO, NO>>
74 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP<Epetra_CrsMatrix>& epAB);
75 
76 template <typename SC, typename LO, typename GO, typename NO>
77 RCP<Xpetra::Matrix<SC, LO, GO, NO>>
79 
80 template <typename SC, typename LO, typename GO, typename NO>
81 RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
83 #endif
84 
85 template <typename SC, typename LO, typename GO, typename NO>
86 RCP<Xpetra::Matrix<SC, LO, GO, NO>>
88 
89 template <typename SC, typename LO, typename GO, typename NO>
90 RCP<Xpetra::Matrix<SC, LO, GO, NO>>
92 
93 template <typename SC, typename LO, typename GO, typename NO>
94 RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
96 
97 template <typename SC, typename LO, typename GO, typename NO>
98 RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
99 TpetraFEMultiVector_To_XpetraMultiVector(const Teuchos::RCP<Tpetra::FEMultiVector<SC, LO, GO, NO>>& Vtpetra);
100 
101 template <typename SC, typename LO, typename GO, typename NO>
102 void leftRghtDofScalingWithinNode(const Xpetra::Matrix<SC, LO, GO, NO>& Atpetra, size_t blkSize, size_t nSweeps, Teuchos::ArrayRCP<SC>& rowScaling, Teuchos::ArrayRCP<SC>& colScaling);
103 
104 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
108 
116 template <class Scalar,
119  class Node = DefaultNode>
120 class Utilities : public UtilitiesBase<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
121 #undef MUELU_UTILITIES_SHORT
122 #include "MueLu_UseShortNames.hpp"
123 
124  public:
126 
127 #ifdef HAVE_MUELU_EPETRA
128  // @{
132 
135 
138 
141 
143  // @}
144 #endif
145 
150 
153 
156 
159 
162 
165 
168 
170 
171  static void MyOldScaleMatrix(Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Op, const Teuchos::ArrayRCP<const Scalar>& scalingVector, bool doInverse = true,
172  bool doFillComplete = true, bool doOptimizeStorage = true);
173 
175  bool doFillComplete, bool doOptimizeStorage);
177  bool doFillComplete, bool doOptimizeStorage);
178 
179  static RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> Transpose(Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Op, bool optimizeTranspose = false, const std::string& label = std::string(), const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
180 
182 
184 
185 }; // class Utilities
186 
188 
189 #ifdef HAVE_MUELU_EPETRA
190 
199 template <>
200 class Utilities<double, int, int, Xpetra::EpetraNode> : public UtilitiesBase<double, int, int, Xpetra::EpetraNode> {
201  public:
202  typedef double Scalar;
203  typedef int LocalOrdinal;
204  typedef int GlobalOrdinal;
207 #undef MUELU_UTILITIES_SHORT
208 #include "MueLu_UseShortNames.hpp"
209 
210  private:
213  // using EpetraCrsMatrix = Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node>;
214  public:
216  // @{
218  RCP<const EpetraMultiVector> tmpVec = rcp_dynamic_cast<EpetraMultiVector>(vec);
219  if (tmpVec == Teuchos::null)
220  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
221  return tmpVec->getEpetra_MultiVector();
222  }
224  RCP<const EpetraMultiVector> tmpVec = rcp_dynamic_cast<EpetraMultiVector>(vec);
225  if (tmpVec == Teuchos::null)
226  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
227  return tmpVec->getEpetra_MultiVector();
228  }
229 
230  static const Epetra_MultiVector& MV2EpetraMV(const MultiVector& vec) {
231  const EpetraMultiVector& tmpVec = dynamic_cast<const EpetraMultiVector&>(vec);
232  return *(tmpVec.getEpetra_MultiVector());
233  }
234  static Epetra_MultiVector& MV2NonConstEpetraMV(MultiVector& vec) {
235  const EpetraMultiVector& tmpVec = dynamic_cast<const EpetraMultiVector&>(vec);
236  return *(tmpVec.getEpetra_MultiVector());
237  }
238 
240  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
241  if (crsOp == Teuchos::null)
242  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
243  const RCP<const EpetraCrsMatrix>& tmp_ECrsMtx = rcp_dynamic_cast<const EpetraCrsMatrix>(crsOp->getCrsMatrix());
244  if (tmp_ECrsMtx == Teuchos::null)
245  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
246  return tmp_ECrsMtx->getEpetra_CrsMatrix();
247  }
249  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
250  if (crsOp == Teuchos::null)
251  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
252  const RCP<const EpetraCrsMatrix>& tmp_ECrsMtx = rcp_dynamic_cast<const EpetraCrsMatrix>(crsOp->getCrsMatrix());
253  if (tmp_ECrsMtx == Teuchos::null)
254  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
255  return tmp_ECrsMtx->getEpetra_CrsMatrixNonConst();
256  }
257 
258  static const Epetra_CrsMatrix& Op2EpetraCrs(const Matrix& Op) {
259  try {
260  const CrsMatrixWrap& crsOp = dynamic_cast<const CrsMatrixWrap&>(Op);
261  try {
262  const EpetraCrsMatrix& tmp_ECrsMtx = dynamic_cast<const EpetraCrsMatrix&>(*crsOp.getCrsMatrix());
263  return *tmp_ECrsMtx.getEpetra_CrsMatrix();
264  } catch (std::bad_cast&) {
265  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
266  }
267  } catch (std::bad_cast&) {
268  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
269  }
270  }
272  try {
273  CrsMatrixWrap& crsOp = dynamic_cast<CrsMatrixWrap&>(Op);
274  try {
275  EpetraCrsMatrix& tmp_ECrsMtx = dynamic_cast<EpetraCrsMatrix&>(*crsOp.getCrsMatrix());
276  return *tmp_ECrsMtx.getEpetra_CrsMatrixNonConst();
277  } catch (std::bad_cast&) {
278  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
279  }
280  } catch (std::bad_cast&) {
281  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
282  }
283  }
284 
285  static const Epetra_Map& Map2EpetraMap(const Map& map) {
286  RCP<const EpetraMap> xeMap = rcp_dynamic_cast<const EpetraMap>(rcpFromRef(map));
287  if (xeMap == Teuchos::null)
288  throw Exceptions::BadCast("Utilities::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
289  return xeMap->getEpetra_Map();
290  }
291  // @}
292 
295 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
296  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
297  throw Exceptions::RuntimeError("MV2TpetraMV: Tpetra has not been compiled with support for LO=GO=int.");
298 #else
300  if (tmpVec == Teuchos::null)
301  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::TpetraMultiVector failed");
302  return tmpVec->getTpetra_MultiVector();
303 #endif
304  }
306 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
307  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
308  throw Exceptions::RuntimeError("MV2NonConstTpetraMV: Tpetra has not been compiled with support for LO=GO=int.");
309 #else
311  if (tmpVec == Teuchos::null)
312  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::TpetraMultiVector failed");
313  return tmpVec->getTpetra_MultiVector();
314 #endif
315  }
317 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
318  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
319  throw Exceptions::RuntimeError("MV2NonConstTpetraMV2: Tpetra has not been compiled with support for LO=GO=int.");
320 #else
322  return tmpVec.getTpetra_MultiVector();
323 #endif
324  }
325 
327 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
328  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
329  throw Exceptions::RuntimeError("MV2TpetraMV: Tpetra has not been compiled with support for LO=GO=int.");
330 #else
332  return *(tmpVec.getTpetra_MultiVector());
333 #endif
334  }
336 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
337  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
338  throw Exceptions::RuntimeError("MV2NonConstTpetraMV: Tpetra has not been compiled with support for LO=GO=int.");
339 #else
341  return *(tmpVec.getTpetra_MultiVector());
342 #endif
343  }
344 
346 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
347  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
348  throw Exceptions::RuntimeError("Op2TpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
349 #else
350  // Get the underlying Tpetra Mtx
351  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
352  if (crsOp == Teuchos::null)
353  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
355  if (tmp_ECrsMtx == Teuchos::null)
356  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
357  return tmp_ECrsMtx->getTpetra_CrsMatrix();
358 #endif
359  }
361 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
362  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
363  throw Exceptions::RuntimeError("Op2NonConstTpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
364 #else
365  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
366  if (crsOp == Teuchos::null)
367  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
369  if (tmp_ECrsMtx == Teuchos::null)
370  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
371  return tmp_ECrsMtx->getTpetra_CrsMatrixNonConst();
372 #endif
373  };
374 
376 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
377  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
378  throw Exceptions::RuntimeError("Op2TpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
379 #else
380  try {
381  const CrsMatrixWrap& crsOp = dynamic_cast<const CrsMatrixWrap&>(Op);
382  try {
384  return *tmp_ECrsMtx.getTpetra_CrsMatrix();
385  } catch (std::bad_cast&) {
386  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
387  }
388  } catch (std::bad_cast&) {
389  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
390  }
391 #endif
392  }
394 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
395  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
396  throw Exceptions::RuntimeError("Op2NonConstTpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
397 #else
398  try {
399  CrsMatrixWrap& crsOp = dynamic_cast<CrsMatrixWrap&>(Op);
400  try {
402  return *tmp_ECrsMtx.getTpetra_CrsMatrixNonConst();
403  } catch (std::bad_cast&) {
404  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
405  }
406  } catch (std::bad_cast&) {
407  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
408  }
409 #endif
410  }
411 
413 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
414  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
415  throw Exceptions::RuntimeError("Op2TpetraBlockCrs: Tpetra has not been compiled with support for LO=GO=int.");
416 #else
417  // Get the underlying Tpetra Mtx
418  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
419  if (crsOp == Teuchos::null)
420  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
422  if (tmp_ECrsMtx == Teuchos::null)
423  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraBlockCrsMatrix failed");
424  return tmp_ECrsMtx->getTpetra_BlockCrsMatrix();
425 #endif
426  }
427 
429 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
430  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
431  throw Exceptions::RuntimeError("Op2NonConstTpetraBlockCrs: Tpetra has not been compiled with support for LO=GO=int.");
432 #else
433  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
434  if (crsOp == Teuchos::null)
435  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
437  if (tmp_ECrsMtx == Teuchos::null)
438  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraBlockCrsMatrix failed");
439  return tmp_ECrsMtx->getTpetra_BlockCrsMatrixNonConst();
440 #endif
441  };
442 
444 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
445  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
446  throw Exceptions::RuntimeError("Op2TpetraBlockCrs: Tpetra has not been compiled with support for LO=GO=int.");
447 #else
448  try {
449  const CrsMatrixWrap& crsOp = dynamic_cast<const CrsMatrixWrap&>(Op);
450  try {
452  return *tmp_ECrsMtx.getTpetra_BlockCrsMatrix();
453  } catch (std::bad_cast&) {
454  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraBlockCrsMatrix failed");
455  }
456  } catch (std::bad_cast&) {
457  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
458  }
459 #endif
460  }
462 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
463  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
464  throw Exceptions::RuntimeError("Op2NonConstTpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
465 #else
466  try {
467  CrsMatrixWrap& crsOp = dynamic_cast<CrsMatrixWrap&>(Op);
468  try {
470  return *tmp_ECrsMtx.getTpetra_BlockCrsMatrixNonConst();
471  } catch (std::bad_cast&) {
472  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraBlockCrsMatrix failed");
473  }
474  } catch (std::bad_cast&) {
475  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
476  }
477 #endif
478  }
479 
481 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
482  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
483  throw Exceptions::RuntimeError("Op2TpetraRow: Tpetra has not been compiled with support for LO=GO=int.");
484 #else
485  RCP<const Matrix> mat = rcp_dynamic_cast<const Matrix>(Op);
487  if (!mat.is_null()) {
488  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(mat);
489  if (crsOp == Teuchos::null)
490  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
491 
492  RCP<const CrsMatrix> crsMat = crsOp->getCrsMatrix();
495  if (!tmp_Crs.is_null()) {
496  return tmp_Crs->getTpetra_CrsMatrixNonConst();
497  } else {
498  tmp_BlockCrs = rcp_dynamic_cast<const Xpetra::TpetraBlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(crsMat);
499  if (tmp_BlockCrs.is_null())
500  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix and Xpetra::TpetraBlockCrsMatrix failed");
501  return tmp_BlockCrs->getTpetra_BlockCrsMatrixNonConst();
502  }
503  } else if (!rmat.is_null()) {
504  return rmat->getTpetra_RowMatrix();
505  } else {
506  RCP<const TpetraOperator> tpOp = rcp_dynamic_cast<const TpetraOperator>(Op, true);
509  return tRow;
510  }
511 #endif
512  }
513 
515 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
516  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
517  throw Exceptions::RuntimeError("Op2NonConstTpetraRow: Tpetra has not been compiled with support for LO=GO=int.");
518 #else
519  RCP<Matrix> mat = rcp_dynamic_cast<Matrix>(Op);
521  if (!mat.is_null()) {
522  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(mat);
523  if (crsOp == Teuchos::null)
524  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
525 
526  RCP<const CrsMatrix> crsMat = crsOp->getCrsMatrix();
529  if (!tmp_Crs.is_null()) {
530  return tmp_Crs->getTpetra_CrsMatrixNonConst();
531  } else {
532  tmp_BlockCrs = rcp_dynamic_cast<const Xpetra::TpetraBlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(crsMat);
533  if (tmp_BlockCrs.is_null())
534  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix and Xpetra::TpetraBlockCrsMatrix failed");
535  return tmp_BlockCrs->getTpetra_BlockCrsMatrixNonConst();
536  }
537  } else if (!rmat.is_null()) {
538  return rmat->getTpetra_RowMatrixNonConst();
539  } else {
540  RCP<TpetraOperator> tpOp = rcp_dynamic_cast<TpetraOperator>(Op, true);
543  return tRow;
544  }
545 #endif
546  };
547 
549 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
550  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
551  throw Exceptions::RuntimeError("Map2TpetraMap: Tpetra has not been compiled with support for LO=GO=int.");
552 #else
554  if (tmp_TMap == Teuchos::null)
555  throw Exceptions::BadCast("Utilities::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
556  return tmp_TMap->getTpetra_Map();
557 #endif
558  };
559 
560  static void MyOldScaleMatrix(Matrix& Op, const Teuchos::ArrayRCP<const Scalar>& scalingVector, bool doInverse = true,
561  bool doFillComplete = true, bool doOptimizeStorage = true) {
563  Teuchos::ArrayRCP<Scalar> sv(scalingVector.size());
564  if (doInverse) {
565  for (int i = 0; i < scalingVector.size(); ++i)
566  sv[i] = one / scalingVector[i];
567  } else {
568  for (int i = 0; i < scalingVector.size(); ++i)
569  sv[i] = scalingVector[i];
570  }
571 
572  switch (Op.getRowMap()->lib()) {
573  case Xpetra::UseTpetra:
574  MyOldScaleMatrix_Tpetra(Op, sv, doFillComplete, doOptimizeStorage);
575  break;
576 
577  case Xpetra::UseEpetra:
578  MyOldScaleMatrix_Epetra(Op, sv, doFillComplete, doOptimizeStorage);
579  break;
580 
581  default:
582  throw Exceptions::RuntimeError("Only Epetra and Tpetra matrices can be scaled.");
583  }
584  }
585 
586  // TODO This is the <double,int,int> specialization
587  static void MyOldScaleMatrix_Tpetra(Matrix& Op, const Teuchos::ArrayRCP<Scalar>& scalingVector,
588  bool doFillComplete, bool doOptimizeStorage) {
589 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
590  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
591  throw Exceptions::RuntimeError("Matrix scaling is not possible because Tpetra has not been compiled with support for LO=GO=int.");
592 #else
593  try {
595 
599 
600  size_t maxRowSize = tpOp.getLocalMaxNumRowEntries();
601  if (maxRowSize == Teuchos::as<size_t>(-1)) // hasn't been determined yet
602  maxRowSize = 20;
603 
604  std::vector<Scalar> scaledVals(maxRowSize);
605  if (tpOp.isFillComplete())
606  tpOp.resumeFill();
607 
608  if (Op.isLocallyIndexed() == true) {
611  for (size_t i = 0; i < rowMap->getLocalNumElements(); ++i) {
612  tpOp.getLocalRowView(i, cols, vals);
613  size_t nnz = tpOp.getNumEntriesInLocalRow(i);
614  if (nnz > maxRowSize) {
615  maxRowSize = nnz;
616  scaledVals.resize(maxRowSize);
617  }
618  for (size_t j = 0; j < nnz; ++j)
619  scaledVals[j] = vals[j] * scalingVector[i];
620 
621  if (nnz > 0) {
622  Teuchos::ArrayView<const LocalOrdinal> cols_view(cols.data(), nnz);
623  Teuchos::ArrayView<const Scalar> valview(&scaledVals[0], nnz);
624  tpOp.replaceLocalValues(i, cols_view, valview);
625  }
626  } // for (size_t i=0; ...
627 
628  } else {
631 
632  for (size_t i = 0; i < rowMap->getLocalNumElements(); ++i) {
633  GlobalOrdinal gid = rowMap->getGlobalElement(i);
634  tpOp.getGlobalRowView(gid, cols, vals);
635  size_t nnz = tpOp.getNumEntriesInGlobalRow(gid);
636  if (nnz > maxRowSize) {
637  maxRowSize = nnz;
638  scaledVals.resize(maxRowSize);
639  }
640  // FIXME FIXME FIXME FIXME FIXME FIXME
641  for (size_t j = 0; j < nnz; ++j)
642  scaledVals[j] = vals[j] * scalingVector[i]; // FIXME i or gid?
643 
644  if (nnz > 0) {
645  Teuchos::ArrayView<const LocalOrdinal> cols_view(cols.data(), nnz);
646  Teuchos::ArrayView<const Scalar> valview(&scaledVals[0], nnz);
647  tpOp.replaceGlobalValues(gid, cols_view, valview);
648  }
649  } // for (size_t i=0; ...
650  }
651 
652  if (doFillComplete) {
653  if (domainMap == Teuchos::null || rangeMap == Teuchos::null)
654  throw Exceptions::RuntimeError("In Utilities::Scaling: cannot fillComplete because the domain and/or range map hasn't been defined");
655 
657  params->set("Optimize Storage", doOptimizeStorage);
658  params->set("No Nonlocal Changes", true);
659  Op.fillComplete(Op.getDomainMap(), Op.getRangeMap(), params);
660  }
661  } catch (...) {
662  throw Exceptions::RuntimeError("Only Tpetra::CrsMatrix types can be scaled (Err.1)");
663  }
664 #endif
665  }
666 
667  static void MyOldScaleMatrix_Epetra(Matrix& Op, const Teuchos::ArrayRCP<Scalar>& scalingVector, bool /* doFillComplete */, bool /* doOptimizeStorage */) {
668 #ifdef HAVE_MUELU_EPETRA
669  try {
670  // const Epetra_CrsMatrix& epOp = Utilities<double,int,int>::Op2NonConstEpetraCrs(Op);
671  const Epetra_CrsMatrix& epOp = Op2NonConstEpetraCrs(Op);
672 
673  Epetra_Map const& rowMap = epOp.RowMap();
674  int nnz;
675  double* vals;
676  int* cols;
677 
678  for (int i = 0; i < rowMap.NumMyElements(); ++i) {
679  epOp.ExtractMyRowView(i, nnz, vals, cols);
680  for (int j = 0; j < nnz; ++j)
681  vals[j] *= scalingVector[i];
682  }
683 
684  } catch (...) {
685  throw Exceptions::RuntimeError("Only Epetra_CrsMatrix types can be scaled");
686  }
687 #else
688  throw Exceptions::RuntimeError("Matrix scaling is not possible because Epetra has not been enabled.");
689 #endif // HAVE_MUELU_EPETRA
690  }
691 
697  static RCP<Matrix> Transpose(Matrix& Op, bool /* optimizeTranspose */ = false, const std::string& label = std::string(), const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
698  switch (Op.getRowMap()->lib()) {
699  case Xpetra::UseTpetra: {
700 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
701  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
702  throw Exceptions::RuntimeError("Utilities::Transpose: Tpetra is not compiled with LO=GO=int. Add TPETRA_INST_INT_INT:BOOL=ON to your configuration!");
703 #else
705  /***************************************************************/
706  if (Helpers::isTpetraCrs(Op)) {
708 
709  // Compute the transpose A of the Tpetra matrix tpetraOp.
711  Tpetra::RowMatrixTransposer<Scalar, LocalOrdinal, GlobalOrdinal, Node> transposer(rcpFromRef(tpetraOp), label);
712 
713  {
715  using Teuchos::rcp;
716  RCP<ParameterList> transposeParams = params.is_null() ? rcp(new ParameterList) : rcp(new ParameterList(*params));
717  transposeParams->set("sort", false);
718  A = transposer.createTranspose(transposeParams);
719  }
720 
722  RCP<CrsMatrix> AAA = rcp_implicit_cast<CrsMatrix>(AA);
723  RCP<Matrix> AAAA = rcp(new CrsMatrixWrap(AAA));
724 
725  if (Op.IsView("stridedMaps"))
726  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true /*doTranspose*/);
727 
728  return AAAA;
729  }
730  /***************************************************************/
731  else if (Helpers::isTpetraBlockCrs(Op)) {
733  // using CRS = Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
735  RCP<BCRS> At;
736  {
738 
740  using Teuchos::rcp;
741  RCP<ParameterList> transposeParams = params.is_null() ? rcp(new ParameterList) : rcp(new ParameterList(*params));
742  transposeParams->set("sort", false);
743  At = transposer.createTranspose(transposeParams);
744  }
745 
747  RCP<CrsMatrix> AAA = rcp_implicit_cast<CrsMatrix>(AA);
748  RCP<Matrix> AAAA = rcp(new CrsMatrixWrap(AAA));
749 
750  if (Op.IsView("stridedMaps"))
751  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true /*doTranspose*/);
752 
753  return AAAA;
754 
755  }
756  /***************************************************************/
757  else {
758  throw Exceptions::RuntimeError("Utilities::Transpose failed, perhaps because matrix is not a Crs or BlockCrs matrix");
759  }
760 #endif
761  }
762  case Xpetra::UseEpetra: {
763 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT)
764  Teuchos::TimeMonitor tm(*Teuchos::TimeMonitor::getNewTimer("ZZ Entire Transpose"));
765  // Epetra case
768  Epetra_CrsMatrix* A = dynamic_cast<Epetra_CrsMatrix*>(&transposer(epetraOp));
769  transposer.ReleaseTranspose(); // So we can keep A in Muelu...
770 
771  RCP<Epetra_CrsMatrix> rcpA(A);
772  RCP<EpetraCrsMatrix> AA = rcp(new EpetraCrsMatrix(rcpA));
773  RCP<CrsMatrix> AAA = rcp_implicit_cast<CrsMatrix>(AA);
774  RCP<Matrix> AAAA = rcp(new CrsMatrixWrap(AAA));
775 
776  if (Op.IsView("stridedMaps"))
777  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true /*doTranspose*/);
778 
779  return AAAA;
780 #else
781  throw Exceptions::RuntimeError("Epetra (Err. 2)");
782 #endif
783  }
784  default:
785  throw Exceptions::RuntimeError("Only Epetra and Tpetra matrices can be transposed.");
786  }
787 
788  TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
789  }
790 
794  return Xscalar;
795  }
796 
801 
802  // check whether coordinates are contained in parameter list
803  if (paramList.isParameter("Coordinates") == false)
804  return coordinates;
805 
806 #if (defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT)) || \
807  (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))
808 
809  // define Tpetra::MultiVector type with Scalar=float only if
810  // * ETI is turned off, since then the compiler will instantiate it automatically OR
811  // * Tpetra is instantiated on Scalar=float
812 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
814  RCP<tfMV> floatCoords = Teuchos::null;
815 #endif
816 
817  // define Tpetra::MultiVector type with Scalar=double only if
818  // * ETI is turned off, since then the compiler will instantiate it automatically OR
819  // * Tpetra is instantiated on Scalar=double
821  RCP<tdMV> doubleCoords = Teuchos::null;
822  if (paramList.isType<RCP<tdMV>>("Coordinates")) {
823  // Coordinates are stored as a double vector
824  doubleCoords = paramList.get<RCP<tdMV>>("Coordinates");
825  paramList.remove("Coordinates");
826  }
827 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
828  else if (paramList.isType<RCP<tfMV>>("Coordinates")) {
829  // check if coordinates are stored as a float vector
830  floatCoords = paramList.get<RCP<tfMV>>("Coordinates");
831  paramList.remove("Coordinates");
832  doubleCoords = rcp(new tdMV(floatCoords->getMap(), floatCoords->getNumVectors()));
833  deep_copy(*doubleCoords, *floatCoords);
834  }
835 #endif
836  // We have the coordinates in a Tpetra double vector
837  if (doubleCoords != Teuchos::null) {
838  coordinates = Teuchos::rcp(new Xpetra::TpetraMultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LocalOrdinal, GlobalOrdinal, Node>(doubleCoords));
839  TEUCHOS_TEST_FOR_EXCEPT(doubleCoords->getNumVectors() != coordinates->getNumVectors());
840  }
841 #endif // Tpetra instantiated on GO=int and EpetraNode
842 
843 #if defined(HAVE_MUELU_EPETRA)
844  RCP<Epetra_MultiVector> doubleEpCoords;
845  if (paramList.isType<RCP<Epetra_MultiVector>>("Coordinates")) {
846  doubleEpCoords = paramList.get<RCP<Epetra_MultiVector>>("Coordinates");
847  paramList.remove("Coordinates");
850  TEUCHOS_TEST_FOR_EXCEPT(doubleEpCoords->NumVectors() != Teuchos::as<int>(coordinates->getNumVectors()));
851  }
852 #endif
853 
854  // check for Xpetra coordinates vector
855  if (paramList.isType<decltype(coordinates)>("Coordinates")) {
856  coordinates = paramList.get<decltype(coordinates)>("Coordinates");
857  }
858 
860  return coordinates;
861  }
862 
863 }; // class Utilities (specialization SC=double LO=GO=int)
864 
865 #endif // HAVE_MUELU_EPETRA
866 
897 
901 void TokenizeStringAndStripWhiteSpace(const std::string& stream, std::vector<std::string>& tokenList, const char* token = ",");
902 
905 bool IsParamMuemexVariable(const std::string& name);
906 
909 bool IsParamValidVariable(const std::string& name);
910 
911 #ifdef HAVE_MUELU_EPETRA
912 
916 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
917 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
922 
923  RCP<XCrsMatrix> Atmp = rcp(new XECrsMatrix(A));
924  return rcp(new XCrsMatrixWrap(Atmp));
925 }
926 
931 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
932 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
935 }
936 #endif
937 
942 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
943 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
948 
949  RCP<XCrsMatrix> Atmp = rcp(new XTCrsMatrix(Atpetra));
950  return rcp(new XCrsMatrixWrap(Atmp));
951 }
952 
980 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
982  LocalOrdinal nBlks = (Amat.getRowMap()->getLocalNumElements()) / blkSize;
983 
984  Teuchos::ArrayRCP<Scalar> rowScaleUpdate(blkSize);
985  Teuchos::ArrayRCP<Scalar> colScaleUpdate(blkSize);
986 
987  for (size_t i = 0; i < blkSize; i++) rowScaling[i] = 1.0;
988  for (size_t i = 0; i < blkSize; i++) colScaling[i] = 1.0;
989 
990  for (size_t k = 0; k < nSweeps; k++) {
991  LocalOrdinal row = 0;
992  for (size_t i = 0; i < blkSize; i++) rowScaleUpdate[i] = 0.0;
993 
994  for (LocalOrdinal i = 0; i < nBlks; i++) {
995  for (size_t j = 0; j < blkSize; j++) {
998  Amat.getLocalRowView(row, cols, vals);
999 
1000  for (size_t kk = 0; kk < Teuchos::as<size_t>(vals.size()); kk++) {
1001  size_t modGuy = (cols[kk] + 1) % blkSize;
1002  if (modGuy == 0) modGuy = blkSize;
1003  modGuy--;
1004  rowScaleUpdate[j] += rowScaling[j] * (Teuchos::ScalarTraits<Scalar>::magnitude(vals[kk])) * colScaling[modGuy];
1005  }
1006  row++;
1007  }
1008  }
1009  // combine information across processors
1010  Teuchos::ArrayRCP<Scalar> tempUpdate(blkSize);
1011  Teuchos::reduceAll(*(Amat.getRowMap()->getComm()), Teuchos::REDUCE_SUM, (LocalOrdinal)blkSize, rowScaleUpdate.getRawPtr(), tempUpdate.getRawPtr());
1012  for (size_t i = 0; i < blkSize; i++) rowScaleUpdate[i] = tempUpdate[i];
1013 
1014  /* We want to scale by sqrt(1/rowScaleUpdate), but we'll */
1015  /* normalize things by the minimum rowScaleUpdate. That is, the */
1016  /* largest scaling is always one (as normalization is arbitrary).*/
1017 
1018  Scalar minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude((rowScaleUpdate[0] / rowScaling[0]) / rowScaling[0]);
1019 
1020  for (size_t i = 1; i < blkSize; i++) {
1021  Scalar temp = (rowScaleUpdate[i] / rowScaling[i]) / rowScaling[i];
1023  minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude(temp);
1024  }
1025  for (size_t i = 0; i < blkSize; i++) rowScaling[i] *= sqrt(minUpdate / rowScaleUpdate[i]);
1026 
1027  row = 0;
1028  for (size_t i = 0; i < blkSize; i++) colScaleUpdate[i] = 0.0;
1029 
1030  for (LocalOrdinal i = 0; i < nBlks; i++) {
1031  for (size_t j = 0; j < blkSize; j++) {
1034  Amat.getLocalRowView(row, cols, vals);
1035  for (size_t kk = 0; kk < Teuchos::as<size_t>(vals.size()); kk++) {
1036  size_t modGuy = (cols[kk] + 1) % blkSize;
1037  if (modGuy == 0) modGuy = blkSize;
1038  modGuy--;
1039  colScaleUpdate[modGuy] += colScaling[modGuy] * (Teuchos::ScalarTraits<Scalar>::magnitude(vals[kk])) * rowScaling[j];
1040  }
1041  row++;
1042  }
1043  }
1044  Teuchos::reduceAll(*(Amat.getRowMap()->getComm()), Teuchos::REDUCE_SUM, (LocalOrdinal)blkSize, colScaleUpdate.getRawPtr(), tempUpdate.getRawPtr());
1045  for (size_t i = 0; i < blkSize; i++) colScaleUpdate[i] = tempUpdate[i];
1046 
1047  /* We want to scale by sqrt(1/colScaleUpdate), but we'll */
1048  /* normalize things by the minimum colScaleUpdate. That is, the */
1049  /* largest scaling is always one (as normalization is arbitrary).*/
1050 
1051  minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude((colScaleUpdate[0] / colScaling[0]) / colScaling[0]);
1052 
1053  for (size_t i = 1; i < blkSize; i++) {
1054  Scalar temp = (colScaleUpdate[i] / colScaling[i]) / colScaling[i];
1056  minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude(temp);
1057  }
1058  for (size_t i = 0; i < blkSize; i++) colScaling[i] *= sqrt(minUpdate / colScaleUpdate[i]);
1059  }
1060 }
1061 
1066 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1067 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1073 
1074  RCP<XCrsMatrix> Atmp = rcp(new XTCrsMatrix(rcp_dynamic_cast<tpetra_crs_matrix_type>(Atpetra)));
1075  return rcp(new XCrsMatrixWrap(Atmp));
1076 }
1077 
1082 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1083 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1086 }
1087 
1092 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1093 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1094 TpetraFEMultiVector_To_XpetraMultiVector(const Teuchos::RCP<Tpetra::FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& Vtpetra) {
1096  RCP<const MV> Vmv = Teuchos::rcp_dynamic_cast<const MV>(Vtpetra);
1098 }
1099 
1101 template <class T>
1102 std::string toString(const T& what) {
1103  std::ostringstream buf;
1104  buf << what;
1105  return buf.str();
1106 }
1107 
1108 #ifdef HAVE_MUELU_EPETRA
1109 
1113 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1114 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1116 
1121 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1122 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1124 #endif
1125 
1130 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1131 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1133 
1138 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1139 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1141 
1142 // Generates a communicator whose only members are other ranks of the baseComm on my node
1143 Teuchos::RCP<const Teuchos::Comm<int>> GenerateNodeComm(RCP<const Teuchos::Comm<int>>& baseComm, int& NodeId, const int reductionFactor);
1144 
1145 // Lower case string
1146 std::string lowerCase(const std::string& s);
1147 
1148 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1152  using SC = Scalar;
1153  using LO = LocalOrdinal;
1154  using GO = GlobalOrdinal;
1155  using NO = Node;
1156  using MT = typename Teuchos::ScalarTraits<SC>::magnitudeType;
1157 
1158  Teuchos::RCP<const Teuchos::Comm<int>> comm = localDropMap->getComm();
1159 
1161  toggleVec->putScalar(1);
1162 
1164  Teuchos::RCP<Xpetra::Import<LO, GO, NO>> importer = Xpetra::ImportFactory<LO, GO, NO>::Build(localDropMap, Ain->getColMap());
1165  finalVec->doImport(*toggleVec, *importer, Xpetra::ABSMAX);
1166 
1167  std::vector<GO> finalDropMapEntries = {};
1168  auto finalVec_h_2D = finalVec->getHostLocalView(Xpetra::Access::ReadOnly);
1169  auto finalVec_h_1D = Kokkos::subview(finalVec_h_2D, Kokkos::ALL(), 0);
1170  const size_t localLength = finalVec->getLocalLength();
1171 
1172  for (size_t k = 0; k < localLength; ++k) {
1174  finalDropMapEntries.push_back(finalVec->getMap()->getGlobalElement(k));
1175  }
1176  }
1177 
1179  localDropMap->lib(), Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(), finalDropMapEntries, 0, comm);
1180  return finalDropMap;
1181 } // importOffRankDroppingInfo
1182 
1183 } // namespace MueLu
1184 
1185 #define MUELU_UTILITIES_SHORT
1186 #endif // MUELU_UTILITIES_DECL_HPP
Exception indicating invalid cast attempted.
static const Tpetra::BlockCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > & Op2TpetraBlockCrs(const Matrix &Op)
static const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > Map2TpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
static const Epetra_MultiVector & MV2EpetraMV(const MultiVector &vec)
MueLu::DefaultLocalOrdinal LocalOrdinal
static Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > & Op2NonConstTpetraCrs(Matrix &Op)
static RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2TpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >> const vec)
Helper utility to pull out the underlying Tpetra objects from an Xpetra object.
RCP< Xpetra::Matrix< SC, LO, GO, NO > > EpetraCrs_To_XpetraMatrix(const Teuchos::RCP< Epetra_CrsMatrix > &A)
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
static RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2NonConstTpetraMV2(MultiVector &vec)
static void MyOldScaleMatrix(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const Teuchos::ArrayRCP< const Scalar > &scalingVector, bool doInverse=true, bool doFillComplete=true, bool doOptimizeStorage=true)
static RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > RealValuedToScalarMultiVector(RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::coordinateType, LocalOrdinal, GlobalOrdinal, Node >> X)
static const Epetra_Map & Map2EpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
Teuchos::RCP< const map_type > getRangeMap() const override
RCP< Tpetra::BlockCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_BlockCrsMatrixNonConst() const
GlobalOrdinal GO
T & get(const std::string &name, T def_value)
static RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LocalOrdinal, GlobalOrdinal, Node > > ExtractCoordinatesFromParameterList(ParameterList &paramList)
static RCP< Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraRow(RCP< Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
bool is_null(const std::shared_ptr< T > &p)
static RCP< Epetra_CrsMatrix > Op2NonConstEpetraCrs(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
Teuchos::ScalarTraits< Scalar >::magnitudeType Magnitude
static RCP< const Epetra_CrsMatrix > Op2EpetraCrs(RCP< const Matrix > Op)
T * getRawPtr() const
static RCP< const Tpetra::BlockCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2TpetraBlockCrs(RCP< const Matrix > Op)
RCP< Xpetra::MultiVector< SC, LO, GO, NO > > TpetraMultiVector_To_XpetraMultiVector(const Teuchos::RCP< Tpetra::MultiVector< SC, LO, GO, NO >> &Vtpetra)
size_type size() const
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
RCP< Xpetra::Matrix< SC, LO, GO, NO > > TpetraFECrs_To_XpetraMatrix(const Teuchos::RCP< Tpetra::FECrsMatrix< SC, LO, GO, NO >> &Atpetra)
static RCP< Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraRow(RCP< Operator > Op)
LocalOrdinal LO
static RCP< const Epetra_MultiVector > MV2EpetraMV(RCP< MultiVector > const vec)
Helper utility to pull out the underlying Epetra objects from an Xpetra object.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2TpetraCrs(RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
bool IsParamMuemexVariable(const std::string &name)
static RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2TpetraMV(RCP< MultiVector > const vec)
Helper utility to pull out the underlying Tpetra objects from an Xpetra object.
static const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > Map2TpetraMap(const Map &map)
size_type size() const
MueLu::DefaultNode Node
static void MyOldScaleMatrix_Tpetra(Matrix &Op, const Teuchos::ArrayRCP< Scalar > &scalingVector, bool doFillComplete, bool doOptimizeStorage)
static RCP< Time > getNewTimer(const std::string &name)
int ExtractMyRowView(int MyRow, int &NumEntries, double *&Values, int *&Indices) const
static RCP< Tpetra::BlockCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraBlockCrs(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
RCP< Xpetra::MultiVector< SC, LO, GO, NO > > TpetraFEMultiVector_To_XpetraMultiVector(const Teuchos::RCP< Tpetra::FEMultiVector< SC, LO, GO, NO >> &Vtpetra)
const Epetra_Map & RowMap() const
bool isParameter(const std::string &name) const
int NumMyElements() const
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
bool remove(std::string const &name, bool throwIfNotExists=true)
size_t getLocalMaxNumRowEntries() const override
virtual void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const =0
static RCP< Epetra_CrsMatrix > Op2NonConstEpetraCrs(RCP< Matrix > Op)
bool isFillComplete() const override
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static RCP< Epetra_MultiVector > MV2NonConstEpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >> vec)
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalGlobal lg=Xpetra::GloballyDistributed)
RCP< const Tpetra::BlockCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_BlockCrsMatrix() const
static Epetra_MultiVector & MV2NonConstEpetraMV(MultiVector &vec)
static RCP< Epetra_MultiVector > MV2NonConstEpetraMV(RCP< MultiVector > vec)
void leftRghtDofScalingWithinNode(const Xpetra::Matrix< SC, LO, GO, NO > &Atpetra, size_t blkSize, size_t nSweeps, Teuchos::ArrayRCP< SC > &rowScaling, Teuchos::ArrayRCP< SC > &colScaling)
RCP< Xpetra::Matrix< SC, LO, GO, NO > > TpetraCrs_To_XpetraMatrix(const Teuchos::RCP< Tpetra::CrsMatrix< SC, LO, GO, NO >> &Atpetra)
static const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & MV2TpetraMV(const MultiVector &vec)
static RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2NonConstTpetraMV2(Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec)
static RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2TpetraCrs(RCP< const Matrix > Op)
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Transpose(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, bool optimizeTranspose=false, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
static RCP< Matrix > Transpose(Matrix &Op, bool=false, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Transpose a Xpetra::Matrix.
local_ordinal_type replaceGlobalValues(const global_ordinal_type globalRow, const Kokkos::View< const global_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals)
RCP< Xpetra::CrsMatrixWrap< SC, LO, GO, NO > > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP< Epetra_CrsMatrix > &epAB)
size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override
bool IsParamValidVariable(const std::string &name)
static RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2NonConstTpetraMV(RCP< MultiVector > vec)
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
static RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LocalOrdinal, GlobalOrdinal, Node > > RealValuedToScalarMultiVector(RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::coordinateType, LocalOrdinal, GlobalOrdinal, Node >> X)
Teuchos::RCP< bcrs_matrix_type > createTranspose(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
static magnitudeType magnitude(T a)
std::string lowerCase(const std::string &s)
Teuchos::RCP< crs_matrix_type > createTranspose(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
static RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2TpetraRow(RCP< const Operator > Op)
static void MyOldScaleMatrix_Epetra(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const Teuchos::ArrayRCP< Scalar > &scalingVector, bool doFillComplete, bool doOptimizeStorage)
static const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > & Op2TpetraCrs(const Matrix &Op)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
Teuchos::RCP< const map_type > getDomainMap() const override
RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrix() const
RCP< Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrixNonConst() const
Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > importOffRankDroppingInfo(Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node >> &localDropMap, Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &Ain)
Scalar SC
bool isType(const std::string &name) const
static RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2TpetraRow(RCP< const Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
virtual void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const =0
Wraps an existing MueLu::Hierarchy as a Tpetra::Operator.
EpetraCrsMatrixT< int, EpetraNode > EpetraCrsMatrix
static RCP< const Epetra_MultiVector > MV2EpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >> const vec)
Helper utility to pull out the underlying Epetra objects from an Xpetra object.
RCP< Epetra_MultiVector > getEpetra_MultiVector() const
Node NO
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_MultiVector() const
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const override
Exception throws to report errors in the internal logical of the program.
virtual void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const =0
static Tpetra::BlockCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > & Op2NonConstTpetraBlockCrs(Matrix &Op)
static Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & MV2NonConstTpetraMV(MultiVector &vec)
local_ordinal_type replaceLocalValues(const local_ordinal_type localRow, const Kokkos::View< const local_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals)
static const Epetra_Map & Map2EpetraMap(const Map &map)
void TokenizeStringAndStripWhiteSpace(const std::string &stream, std::vector< std::string > &tokenList, const char *delimChars)
static RCP< const Tpetra::BlockCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2TpetraBlockCrs(RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
static void MyOldScaleMatrix(Matrix &Op, const Teuchos::ArrayRCP< const Scalar > &scalingVector, bool doInverse=true, bool doFillComplete=true, bool doOptimizeStorage=true)
static void MyOldScaleMatrix_Epetra(Matrix &Op, const Teuchos::ArrayRCP< Scalar > &scalingVector, bool, bool)
static void MyOldScaleMatrix_Tpetra(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const Teuchos::ArrayRCP< Scalar > &scalingVector, bool doFillComplete, bool doOptimizeStorage)
Teuchos::RCP< const Teuchos::Comm< int > > GenerateNodeComm(RCP< const Teuchos::Comm< int > > &baseComm, int &NodeId, const int reductionFactor)
RCP< Xpetra::MultiVector< SC, LO, GO, NO > > EpetraMultiVector_To_XpetraMultiVector(const Teuchos::RCP< Epetra_MultiVector > &V)
static const Epetra_CrsMatrix & Op2EpetraCrs(const Matrix &Op)
Teuchos::ScalarTraits< Scalar >::magnitudeType Magnitude
static RCP< const Epetra_CrsMatrix > Op2EpetraCrs(RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
static RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LocalOrdinal, GlobalOrdinal, Node > > ExtractCoordinatesFromParameterList(ParameterList &paramList)
Extract coordinates from parameter list and return them in a Xpetra::MultiVector. ...
MueLu utility class.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
static RCP< Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraCrs(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
static RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2NonConstTpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >> vec)
static RCP< Import< LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &source, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &target, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
static RCP< Tpetra::BlockCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraBlockCrs(RCP< Matrix > Op)
long ExtractNonSerializableData(const Teuchos::ParameterList &inList, Teuchos::ParameterList &serialList, Teuchos::ParameterList &nonSerialList)
Extract non-serializable data from level-specific sublists and move it to a separate parameter list...
Teuchos::RCP< const map_type > getRowMap() const override
bool is_null() const
static RCP< Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraCrs(RCP< Matrix > Op)