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 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_UTILITIES_DECL_HPP
47 #define MUELU_UTILITIES_DECL_HPP
48 
49 #include <string>
50 
51 #include "MueLu_ConfigDefs.hpp"
52 
53 #include <Teuchos_DefaultComm.hpp>
54 #include <Teuchos_ScalarTraits.hpp>
56 
57 #include <Xpetra_TpetraBlockCrsMatrix_fwd.hpp>
59 #include <Xpetra_CrsMatrix_fwd.hpp>
60 #include <Xpetra_CrsMatrixWrap.hpp>
61 #include <Xpetra_Map_fwd.hpp>
62 #include <Xpetra_Matrix_fwd.hpp>
65 #include <Xpetra_Operator_fwd.hpp>
66 #include <Xpetra_Vector_fwd.hpp>
68 
69 #include <Xpetra_MatrixMatrix.hpp>
70 
71 #ifdef HAVE_MUELU_EPETRA
73 
74 // needed because of inlined function
75 // TODO: remove inline function?
78 
79 #endif
80 
81 #include "MueLu_Exceptions.hpp"
82 
83 #ifdef HAVE_MUELU_EPETRAEXT
84 class Epetra_CrsMatrix;
85 class Epetra_MultiVector;
86 class Epetra_Vector;
88 #endif
89 
90 #include <Tpetra_CrsMatrix.hpp>
91 #include <Tpetra_BlockCrsMatrix.hpp>
92 #include <Tpetra_BlockCrsMatrix_Helpers.hpp>
93 #include <Tpetra_FECrsMatrix.hpp>
94 #include <Tpetra_RowMatrixTransposer.hpp>
95 #include <Tpetra_Map.hpp>
96 #include <Tpetra_MultiVector.hpp>
97 #include <Tpetra_FEMultiVector.hpp>
101 
102 #include <MueLu_UtilitiesBase.hpp>
103 
104 namespace MueLu {
105 
106 #ifdef HAVE_MUELU_EPETRA
107 // defined after Utilities class
108 template <typename SC, typename LO, typename GO, typename NO>
109 RCP<Xpetra::CrsMatrixWrap<SC, LO, GO, NO>>
110 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP<Epetra_CrsMatrix>& epAB);
111 
112 template <typename SC, typename LO, typename GO, typename NO>
113 RCP<Xpetra::Matrix<SC, LO, GO, NO>>
115 
116 template <typename SC, typename LO, typename GO, typename NO>
117 RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
119 #endif
120 
121 template <typename SC, typename LO, typename GO, typename NO>
122 RCP<Xpetra::Matrix<SC, LO, GO, NO>>
124 
125 template <typename SC, typename LO, typename GO, typename NO>
126 RCP<Xpetra::Matrix<SC, LO, GO, NO>>
127 TpetraFECrs_To_XpetraMatrix(const Teuchos::RCP<Tpetra::FECrsMatrix<SC, LO, GO, NO>>& Atpetra);
128 
129 template <typename SC, typename LO, typename GO, typename NO>
130 RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
132 
133 template <typename SC, typename LO, typename GO, typename NO>
134 RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
135 TpetraFEMultiVector_To_XpetraMultiVector(const Teuchos::RCP<Tpetra::FEMultiVector<SC, LO, GO, NO>>& Vtpetra);
136 
137 template <typename SC, typename LO, typename GO, typename NO>
138 void leftRghtDofScalingWithinNode(const Xpetra::Matrix<SC, LO, GO, NO>& Atpetra, size_t blkSize, size_t nSweeps, Teuchos::ArrayRCP<SC>& rowScaling, Teuchos::ArrayRCP<SC>& colScaling);
139 
140 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
144 
152 template <class Scalar,
155  class Node = DefaultNode>
156 class Utilities : public UtilitiesBase<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
157 #undef MUELU_UTILITIES_SHORT
158 #include "MueLu_UseShortNames.hpp"
159 
160  public:
162 
163 #ifdef HAVE_MUELU_EPETRA
164  // @{
168 
171 
174 
177 
179  // @}
180 #endif
181 
186 
189 
192 
195 
198 
201 
204 
206 
207  static void MyOldScaleMatrix(Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Op, const Teuchos::ArrayRCP<const Scalar>& scalingVector, bool doInverse = true,
208  bool doFillComplete = true, bool doOptimizeStorage = true);
209 
211  bool doFillComplete, bool doOptimizeStorage);
213  bool doFillComplete, bool doOptimizeStorage);
214 
215  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);
216 
218 
220 
221 }; // class Utilities
222 
224 
225 #ifdef HAVE_MUELU_EPETRA
226 
235 template <>
236 class Utilities<double, int, int, Xpetra::EpetraNode> : public UtilitiesBase<double, int, int, Xpetra::EpetraNode> {
237  public:
238  typedef double Scalar;
239  typedef int LocalOrdinal;
240  typedef int GlobalOrdinal;
243 #undef MUELU_UTILITIES_SHORT
244 #include "MueLu_UseShortNames.hpp"
245 
246  private:
249  // using EpetraCrsMatrix = Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node>;
250  public:
252  // @{
254  RCP<const EpetraMultiVector> tmpVec = rcp_dynamic_cast<EpetraMultiVector>(vec);
255  if (tmpVec == Teuchos::null)
256  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
257  return tmpVec->getEpetra_MultiVector();
258  }
260  RCP<const EpetraMultiVector> tmpVec = rcp_dynamic_cast<EpetraMultiVector>(vec);
261  if (tmpVec == Teuchos::null)
262  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
263  return tmpVec->getEpetra_MultiVector();
264  }
265 
266  static const Epetra_MultiVector& MV2EpetraMV(const MultiVector& vec) {
267  const EpetraMultiVector& tmpVec = dynamic_cast<const EpetraMultiVector&>(vec);
268  return *(tmpVec.getEpetra_MultiVector());
269  }
270  static Epetra_MultiVector& MV2NonConstEpetraMV(MultiVector& vec) {
271  const EpetraMultiVector& tmpVec = dynamic_cast<const EpetraMultiVector&>(vec);
272  return *(tmpVec.getEpetra_MultiVector());
273  }
274 
276  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
277  if (crsOp == Teuchos::null)
278  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
279  const RCP<const EpetraCrsMatrix>& tmp_ECrsMtx = rcp_dynamic_cast<const EpetraCrsMatrix>(crsOp->getCrsMatrix());
280  if (tmp_ECrsMtx == Teuchos::null)
281  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
282  return tmp_ECrsMtx->getEpetra_CrsMatrix();
283  }
285  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
286  if (crsOp == Teuchos::null)
287  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
288  const RCP<const EpetraCrsMatrix>& tmp_ECrsMtx = rcp_dynamic_cast<const EpetraCrsMatrix>(crsOp->getCrsMatrix());
289  if (tmp_ECrsMtx == Teuchos::null)
290  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
291  return tmp_ECrsMtx->getEpetra_CrsMatrixNonConst();
292  }
293 
294  static const Epetra_CrsMatrix& Op2EpetraCrs(const Matrix& Op) {
295  try {
296  const CrsMatrixWrap& crsOp = dynamic_cast<const CrsMatrixWrap&>(Op);
297  try {
298  const EpetraCrsMatrix& tmp_ECrsMtx = dynamic_cast<const EpetraCrsMatrix&>(*crsOp.getCrsMatrix());
299  return *tmp_ECrsMtx.getEpetra_CrsMatrix();
300  } catch (std::bad_cast&) {
301  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
302  }
303  } catch (std::bad_cast&) {
304  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
305  }
306  }
308  try {
309  CrsMatrixWrap& crsOp = dynamic_cast<CrsMatrixWrap&>(Op);
310  try {
311  EpetraCrsMatrix& tmp_ECrsMtx = dynamic_cast<EpetraCrsMatrix&>(*crsOp.getCrsMatrix());
312  return *tmp_ECrsMtx.getEpetra_CrsMatrixNonConst();
313  } catch (std::bad_cast&) {
314  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
315  }
316  } catch (std::bad_cast&) {
317  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
318  }
319  }
320 
321  static const Epetra_Map& Map2EpetraMap(const Map& map) {
322  RCP<const EpetraMap> xeMap = rcp_dynamic_cast<const EpetraMap>(rcpFromRef(map));
323  if (xeMap == Teuchos::null)
324  throw Exceptions::BadCast("Utilities::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
325  return xeMap->getEpetra_Map();
326  }
327  // @}
328 
331 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
332  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
333  throw Exceptions::RuntimeError("MV2TpetraMV: Tpetra has not been compiled with support for LO=GO=int.");
334 #else
336  if (tmpVec == Teuchos::null)
337  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::TpetraMultiVector failed");
338  return tmpVec->getTpetra_MultiVector();
339 #endif
340  }
342 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
343  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
344  throw Exceptions::RuntimeError("MV2NonConstTpetraMV: Tpetra has not been compiled with support for LO=GO=int.");
345 #else
347  if (tmpVec == Teuchos::null)
348  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::TpetraMultiVector failed");
349  return tmpVec->getTpetra_MultiVector();
350 #endif
351  }
353 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
354  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
355  throw Exceptions::RuntimeError("MV2NonConstTpetraMV2: Tpetra has not been compiled with support for LO=GO=int.");
356 #else
358  return tmpVec.getTpetra_MultiVector();
359 #endif
360  }
361 
363 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
364  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
365  throw Exceptions::RuntimeError("MV2TpetraMV: Tpetra has not been compiled with support for LO=GO=int.");
366 #else
368  return *(tmpVec.getTpetra_MultiVector());
369 #endif
370  }
372 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
373  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
374  throw Exceptions::RuntimeError("MV2NonConstTpetraMV: Tpetra has not been compiled with support for LO=GO=int.");
375 #else
377  return *(tmpVec.getTpetra_MultiVector());
378 #endif
379  }
380 
382 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
383  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
384  throw Exceptions::RuntimeError("Op2TpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
385 #else
386  // Get the underlying Tpetra Mtx
387  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
388  if (crsOp == Teuchos::null)
389  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
391  if (tmp_ECrsMtx == Teuchos::null)
392  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
393  return tmp_ECrsMtx->getTpetra_CrsMatrix();
394 #endif
395  }
397 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
398  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
399  throw Exceptions::RuntimeError("Op2NonConstTpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
400 #else
401  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
402  if (crsOp == Teuchos::null)
403  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
405  if (tmp_ECrsMtx == Teuchos::null)
406  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
407  return tmp_ECrsMtx->getTpetra_CrsMatrixNonConst();
408 #endif
409  };
410 
412 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
413  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
414  throw Exceptions::RuntimeError("Op2TpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
415 #else
416  try {
417  const CrsMatrixWrap& crsOp = dynamic_cast<const CrsMatrixWrap&>(Op);
418  try {
420  return *tmp_ECrsMtx.getTpetra_CrsMatrix();
421  } catch (std::bad_cast&) {
422  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
423  }
424  } catch (std::bad_cast&) {
425  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
426  }
427 #endif
428  }
430 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
431  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
432  throw Exceptions::RuntimeError("Op2NonConstTpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
433 #else
434  try {
435  CrsMatrixWrap& crsOp = dynamic_cast<CrsMatrixWrap&>(Op);
436  try {
438  return *tmp_ECrsMtx.getTpetra_CrsMatrixNonConst();
439  } catch (std::bad_cast&) {
440  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
441  }
442  } catch (std::bad_cast&) {
443  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
444  }
445 #endif
446  }
447 
449 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
450  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
451  throw Exceptions::RuntimeError("Op2TpetraBlockCrs: Tpetra has not been compiled with support for LO=GO=int.");
452 #else
453  // Get the underlying Tpetra Mtx
454  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
455  if (crsOp == Teuchos::null)
456  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
458  if (tmp_ECrsMtx == Teuchos::null)
459  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraBlockCrsMatrix failed");
460  return tmp_ECrsMtx->getTpetra_BlockCrsMatrix();
461 #endif
462  }
463 
465 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
466  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
467  throw Exceptions::RuntimeError("Op2NonConstTpetraBlockCrs: Tpetra has not been compiled with support for LO=GO=int.");
468 #else
469  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
470  if (crsOp == Teuchos::null)
471  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
473  if (tmp_ECrsMtx == Teuchos::null)
474  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraBlockCrsMatrix failed");
475  return tmp_ECrsMtx->getTpetra_BlockCrsMatrixNonConst();
476 #endif
477  };
478 
480 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
481  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
482  throw Exceptions::RuntimeError("Op2TpetraBlockCrs: Tpetra has not been compiled with support for LO=GO=int.");
483 #else
484  try {
485  const CrsMatrixWrap& crsOp = dynamic_cast<const CrsMatrixWrap&>(Op);
486  try {
488  return *tmp_ECrsMtx.getTpetra_BlockCrsMatrix();
489  } catch (std::bad_cast&) {
490  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraBlockCrsMatrix failed");
491  }
492  } catch (std::bad_cast&) {
493  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
494  }
495 #endif
496  }
498 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
499  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
500  throw Exceptions::RuntimeError("Op2NonConstTpetraCrs: Tpetra has not been compiled with support for LO=GO=int.");
501 #else
502  try {
503  CrsMatrixWrap& crsOp = dynamic_cast<CrsMatrixWrap&>(Op);
504  try {
506  return *tmp_ECrsMtx.getTpetra_BlockCrsMatrixNonConst();
507  } catch (std::bad_cast&) {
508  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraBlockCrsMatrix failed");
509  }
510  } catch (std::bad_cast&) {
511  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
512  }
513 #endif
514  }
515 
517 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
518  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
519  throw Exceptions::RuntimeError("Op2TpetraRow: Tpetra has not been compiled with support for LO=GO=int.");
520 #else
521  RCP<const Matrix> mat = rcp_dynamic_cast<const Matrix>(Op);
523  if (!mat.is_null()) {
524  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(mat);
525  if (crsOp == Teuchos::null)
526  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
527 
528  RCP<const CrsMatrix> crsMat = crsOp->getCrsMatrix();
531  if (!tmp_Crs.is_null()) {
532  return tmp_Crs->getTpetra_CrsMatrixNonConst();
533  } else {
534  tmp_BlockCrs = rcp_dynamic_cast<const Xpetra::TpetraBlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(crsMat);
535  if (tmp_BlockCrs.is_null())
536  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix and Xpetra::TpetraBlockCrsMatrix failed");
537  return tmp_BlockCrs->getTpetra_BlockCrsMatrixNonConst();
538  }
539  } else if (!rmat.is_null()) {
540  return rmat->getTpetra_RowMatrix();
541  } else {
542  RCP<const TpetraOperator> tpOp = rcp_dynamic_cast<const TpetraOperator>(Op, true);
545  return tRow;
546  }
547 #endif
548  }
549 
551 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
552  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
553  throw Exceptions::RuntimeError("Op2NonConstTpetraRow: Tpetra has not been compiled with support for LO=GO=int.");
554 #else
555  RCP<Matrix> mat = rcp_dynamic_cast<Matrix>(Op);
557  if (!mat.is_null()) {
558  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(mat);
559  if (crsOp == Teuchos::null)
560  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
561 
562  RCP<const CrsMatrix> crsMat = crsOp->getCrsMatrix();
565  if (!tmp_Crs.is_null()) {
566  return tmp_Crs->getTpetra_CrsMatrixNonConst();
567  } else {
568  tmp_BlockCrs = rcp_dynamic_cast<const Xpetra::TpetraBlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(crsMat);
569  if (tmp_BlockCrs.is_null())
570  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix and Xpetra::TpetraBlockCrsMatrix failed");
571  return tmp_BlockCrs->getTpetra_BlockCrsMatrixNonConst();
572  }
573  } else if (!rmat.is_null()) {
574  return rmat->getTpetra_RowMatrixNonConst();
575  } else {
576  RCP<TpetraOperator> tpOp = rcp_dynamic_cast<TpetraOperator>(Op, true);
579  return tRow;
580  }
581 #endif
582  };
583 
585 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
586  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
587  throw Exceptions::RuntimeError("Map2TpetraMap: Tpetra has not been compiled with support for LO=GO=int.");
588 #else
590  if (tmp_TMap == Teuchos::null)
591  throw Exceptions::BadCast("Utilities::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
592  return tmp_TMap->getTpetra_Map();
593 #endif
594  };
595 
596  static void MyOldScaleMatrix(Matrix& Op, const Teuchos::ArrayRCP<const Scalar>& scalingVector, bool doInverse = true,
597  bool doFillComplete = true, bool doOptimizeStorage = true) {
599  Teuchos::ArrayRCP<Scalar> sv(scalingVector.size());
600  if (doInverse) {
601  for (int i = 0; i < scalingVector.size(); ++i)
602  sv[i] = one / scalingVector[i];
603  } else {
604  for (int i = 0; i < scalingVector.size(); ++i)
605  sv[i] = scalingVector[i];
606  }
607 
608  switch (Op.getRowMap()->lib()) {
609  case Xpetra::UseTpetra:
610  MyOldScaleMatrix_Tpetra(Op, sv, doFillComplete, doOptimizeStorage);
611  break;
612 
613  case Xpetra::UseEpetra:
614  MyOldScaleMatrix_Epetra(Op, sv, doFillComplete, doOptimizeStorage);
615  break;
616 
617  default:
618  throw Exceptions::RuntimeError("Only Epetra and Tpetra matrices can be scaled.");
619  }
620  }
621 
622  // TODO This is the <double,int,int> specialization
623  static void MyOldScaleMatrix_Tpetra(Matrix& Op, const Teuchos::ArrayRCP<Scalar>& scalingVector,
624  bool doFillComplete, bool doOptimizeStorage) {
625 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
626  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
627  throw Exceptions::RuntimeError("Matrix scaling is not possible because Tpetra has not been compiled with support for LO=GO=int.");
628 #else
629  try {
631 
635 
636  size_t maxRowSize = tpOp.getLocalMaxNumRowEntries();
637  if (maxRowSize == Teuchos::as<size_t>(-1)) // hasn't been determined yet
638  maxRowSize = 20;
639 
640  std::vector<Scalar> scaledVals(maxRowSize);
641  if (tpOp.isFillComplete())
642  tpOp.resumeFill();
643 
644  if (Op.isLocallyIndexed() == true) {
647  for (size_t i = 0; i < rowMap->getLocalNumElements(); ++i) {
648  tpOp.getLocalRowView(i, cols, vals);
649  size_t nnz = tpOp.getNumEntriesInLocalRow(i);
650  if (nnz > maxRowSize) {
651  maxRowSize = nnz;
652  scaledVals.resize(maxRowSize);
653  }
654  for (size_t j = 0; j < nnz; ++j)
655  scaledVals[j] = vals[j] * scalingVector[i];
656 
657  if (nnz > 0) {
658  Teuchos::ArrayView<const LocalOrdinal> cols_view(cols.data(), nnz);
659  Teuchos::ArrayView<const Scalar> valview(&scaledVals[0], nnz);
660  tpOp.replaceLocalValues(i, cols_view, valview);
661  }
662  } // for (size_t i=0; ...
663 
664  } else {
667 
668  for (size_t i = 0; i < rowMap->getLocalNumElements(); ++i) {
669  GlobalOrdinal gid = rowMap->getGlobalElement(i);
670  tpOp.getGlobalRowView(gid, cols, vals);
671  size_t nnz = tpOp.getNumEntriesInGlobalRow(gid);
672  if (nnz > maxRowSize) {
673  maxRowSize = nnz;
674  scaledVals.resize(maxRowSize);
675  }
676  // FIXME FIXME FIXME FIXME FIXME FIXME
677  for (size_t j = 0; j < nnz; ++j)
678  scaledVals[j] = vals[j] * scalingVector[i]; // FIXME i or gid?
679 
680  if (nnz > 0) {
681  Teuchos::ArrayView<const LocalOrdinal> cols_view(cols.data(), nnz);
682  Teuchos::ArrayView<const Scalar> valview(&scaledVals[0], nnz);
683  tpOp.replaceGlobalValues(gid, cols_view, valview);
684  }
685  } // for (size_t i=0; ...
686  }
687 
688  if (doFillComplete) {
689  if (domainMap == Teuchos::null || rangeMap == Teuchos::null)
690  throw Exceptions::RuntimeError("In Utilities::Scaling: cannot fillComplete because the domain and/or range map hasn't been defined");
691 
693  params->set("Optimize Storage", doOptimizeStorage);
694  params->set("No Nonlocal Changes", true);
695  Op.fillComplete(Op.getDomainMap(), Op.getRangeMap(), params);
696  }
697  } catch (...) {
698  throw Exceptions::RuntimeError("Only Tpetra::CrsMatrix types can be scaled (Err.1)");
699  }
700 #endif
701  }
702 
703  static void MyOldScaleMatrix_Epetra(Matrix& Op, const Teuchos::ArrayRCP<Scalar>& scalingVector, bool /* doFillComplete */, bool /* doOptimizeStorage */) {
704 #ifdef HAVE_MUELU_EPETRA
705  try {
706  // const Epetra_CrsMatrix& epOp = Utilities<double,int,int>::Op2NonConstEpetraCrs(Op);
707  const Epetra_CrsMatrix& epOp = Op2NonConstEpetraCrs(Op);
708 
709  Epetra_Map const& rowMap = epOp.RowMap();
710  int nnz;
711  double* vals;
712  int* cols;
713 
714  for (int i = 0; i < rowMap.NumMyElements(); ++i) {
715  epOp.ExtractMyRowView(i, nnz, vals, cols);
716  for (int j = 0; j < nnz; ++j)
717  vals[j] *= scalingVector[i];
718  }
719 
720  } catch (...) {
721  throw Exceptions::RuntimeError("Only Epetra_CrsMatrix types can be scaled");
722  }
723 #else
724  throw Exceptions::RuntimeError("Matrix scaling is not possible because Epetra has not been enabled.");
725 #endif // HAVE_MUELU_EPETRA
726  }
727 
733  static RCP<Matrix> Transpose(Matrix& Op, bool /* optimizeTranspose */ = false, const std::string& label = std::string(), const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
734  switch (Op.getRowMap()->lib()) {
735  case Xpetra::UseTpetra: {
736 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
737  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
738  throw Exceptions::RuntimeError("Utilities::Transpose: Tpetra is not compiled with LO=GO=int. Add TPETRA_INST_INT_INT:BOOL=ON to your configuration!");
739 #else
741  /***************************************************************/
742  if (Helpers::isTpetraCrs(Op)) {
744 
745  // Compute the transpose A of the Tpetra matrix tpetraOp.
747  Tpetra::RowMatrixTransposer<Scalar, LocalOrdinal, GlobalOrdinal, Node> transposer(rcpFromRef(tpetraOp), label);
748 
749  {
751  using Teuchos::rcp;
752  RCP<ParameterList> transposeParams = params.is_null() ? rcp(new ParameterList) : rcp(new ParameterList(*params));
753  transposeParams->set("sort", false);
754  A = transposer.createTranspose(transposeParams);
755  }
756 
758  RCP<CrsMatrix> AAA = rcp_implicit_cast<CrsMatrix>(AA);
759  RCP<Matrix> AAAA = rcp(new CrsMatrixWrap(AAA));
760 
761  if (Op.IsView("stridedMaps"))
762  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true /*doTranspose*/);
763 
764  return AAAA;
765  }
766  /***************************************************************/
767  else if (Helpers::isTpetraBlockCrs(Op)) {
769  // using CRS = Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
771  RCP<BCRS> At;
772  {
774 
776  using Teuchos::rcp;
777  RCP<ParameterList> transposeParams = params.is_null() ? rcp(new ParameterList) : rcp(new ParameterList(*params));
778  transposeParams->set("sort", false);
779  At = transposer.createTranspose(transposeParams);
780  }
781 
783  RCP<CrsMatrix> AAA = rcp_implicit_cast<CrsMatrix>(AA);
784  RCP<Matrix> AAAA = rcp(new CrsMatrixWrap(AAA));
785 
786  if (Op.IsView("stridedMaps"))
787  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true /*doTranspose*/);
788 
789  return AAAA;
790 
791  }
792  /***************************************************************/
793  else {
794  throw Exceptions::RuntimeError("Utilities::Transpose failed, perhaps because matrix is not a Crs or BlockCrs matrix");
795  }
796 #endif
797  }
798  case Xpetra::UseEpetra: {
799 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT)
800  Teuchos::TimeMonitor tm(*Teuchos::TimeMonitor::getNewTimer("ZZ Entire Transpose"));
801  // Epetra case
804  Epetra_CrsMatrix* A = dynamic_cast<Epetra_CrsMatrix*>(&transposer(epetraOp));
805  transposer.ReleaseTranspose(); // So we can keep A in Muelu...
806 
807  RCP<Epetra_CrsMatrix> rcpA(A);
808  RCP<EpetraCrsMatrix> AA = rcp(new EpetraCrsMatrix(rcpA));
809  RCP<CrsMatrix> AAA = rcp_implicit_cast<CrsMatrix>(AA);
810  RCP<Matrix> AAAA = rcp(new CrsMatrixWrap(AAA));
811 
812  if (Op.IsView("stridedMaps"))
813  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true /*doTranspose*/);
814 
815  return AAAA;
816 #else
817  throw Exceptions::RuntimeError("Epetra (Err. 2)");
818 #endif
819  }
820  default:
821  throw Exceptions::RuntimeError("Only Epetra and Tpetra matrices can be transposed.");
822  }
823 
824  TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
825  }
826 
830  return Xscalar;
831  }
832 
837 
838  // check whether coordinates are contained in parameter list
839  if (paramList.isParameter("Coordinates") == false)
840  return coordinates;
841 
842 #if (defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT)) || \
843  (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))
844 
845  // define Tpetra::MultiVector type with Scalar=float only if
846  // * ETI is turned off, since then the compiler will instantiate it automatically OR
847  // * Tpetra is instantiated on Scalar=float
848 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
850  RCP<tfMV> floatCoords = Teuchos::null;
851 #endif
852 
853  // define Tpetra::MultiVector type with Scalar=double only if
854  // * ETI is turned off, since then the compiler will instantiate it automatically OR
855  // * Tpetra is instantiated on Scalar=double
857  RCP<tdMV> doubleCoords = Teuchos::null;
858  if (paramList.isType<RCP<tdMV>>("Coordinates")) {
859  // Coordinates are stored as a double vector
860  doubleCoords = paramList.get<RCP<tdMV>>("Coordinates");
861  paramList.remove("Coordinates");
862  }
863 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
864  else if (paramList.isType<RCP<tfMV>>("Coordinates")) {
865  // check if coordinates are stored as a float vector
866  floatCoords = paramList.get<RCP<tfMV>>("Coordinates");
867  paramList.remove("Coordinates");
868  doubleCoords = rcp(new tdMV(floatCoords->getMap(), floatCoords->getNumVectors()));
869  deep_copy(*doubleCoords, *floatCoords);
870  }
871 #endif
872  // We have the coordinates in a Tpetra double vector
873  if (doubleCoords != Teuchos::null) {
874  coordinates = Teuchos::rcp(new Xpetra::TpetraMultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LocalOrdinal, GlobalOrdinal, Node>(doubleCoords));
875  TEUCHOS_TEST_FOR_EXCEPT(doubleCoords->getNumVectors() != coordinates->getNumVectors());
876  }
877 #endif // Tpetra instantiated on GO=int and EpetraNode
878 
879 #if defined(HAVE_MUELU_EPETRA)
880  RCP<Epetra_MultiVector> doubleEpCoords;
881  if (paramList.isType<RCP<Epetra_MultiVector>>("Coordinates")) {
882  doubleEpCoords = paramList.get<RCP<Epetra_MultiVector>>("Coordinates");
883  paramList.remove("Coordinates");
886  TEUCHOS_TEST_FOR_EXCEPT(doubleEpCoords->NumVectors() != Teuchos::as<int>(coordinates->getNumVectors()));
887  }
888 #endif
889 
890  // check for Xpetra coordinates vector
891  if (paramList.isType<decltype(coordinates)>("Coordinates")) {
892  coordinates = paramList.get<decltype(coordinates)>("Coordinates");
893  }
894 
896  return coordinates;
897  }
898 
899 }; // class Utilities (specialization SC=double LO=GO=int)
900 
901 #endif // HAVE_MUELU_EPETRA
902 
933 
937 void TokenizeStringAndStripWhiteSpace(const std::string& stream, std::vector<std::string>& tokenList, const char* token = ",");
938 
941 bool IsParamMuemexVariable(const std::string& name);
942 
945 bool IsParamValidVariable(const std::string& name);
946 
947 #ifdef HAVE_MUELU_EPETRA
948 
952 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
953 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
958 
959  RCP<XCrsMatrix> Atmp = rcp(new XECrsMatrix(A));
960  return rcp(new XCrsMatrixWrap(Atmp));
961 }
962 
967 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
968 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
971 }
972 #endif
973 
978 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
979 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
984 
985  RCP<XCrsMatrix> Atmp = rcp(new XTCrsMatrix(Atpetra));
986  return rcp(new XCrsMatrixWrap(Atmp));
987 }
988 
1016 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1018  LocalOrdinal nBlks = (Amat.getRowMap()->getLocalNumElements()) / blkSize;
1019 
1020  Teuchos::ArrayRCP<Scalar> rowScaleUpdate(blkSize);
1021  Teuchos::ArrayRCP<Scalar> colScaleUpdate(blkSize);
1022 
1023  for (size_t i = 0; i < blkSize; i++) rowScaling[i] = 1.0;
1024  for (size_t i = 0; i < blkSize; i++) colScaling[i] = 1.0;
1025 
1026  for (size_t k = 0; k < nSweeps; k++) {
1027  LocalOrdinal row = 0;
1028  for (size_t i = 0; i < blkSize; i++) rowScaleUpdate[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 
1036  for (size_t kk = 0; kk < Teuchos::as<size_t>(vals.size()); kk++) {
1037  size_t modGuy = (cols[kk] + 1) % blkSize;
1038  if (modGuy == 0) modGuy = blkSize;
1039  modGuy--;
1040  rowScaleUpdate[j] += rowScaling[j] * (Teuchos::ScalarTraits<Scalar>::magnitude(vals[kk])) * colScaling[modGuy];
1041  }
1042  row++;
1043  }
1044  }
1045  // combine information across processors
1046  Teuchos::ArrayRCP<Scalar> tempUpdate(blkSize);
1047  Teuchos::reduceAll(*(Amat.getRowMap()->getComm()), Teuchos::REDUCE_SUM, (LocalOrdinal)blkSize, rowScaleUpdate.getRawPtr(), tempUpdate.getRawPtr());
1048  for (size_t i = 0; i < blkSize; i++) rowScaleUpdate[i] = tempUpdate[i];
1049 
1050  /* We want to scale by sqrt(1/rowScaleUpdate), but we'll */
1051  /* normalize things by the minimum rowScaleUpdate. That is, the */
1052  /* largest scaling is always one (as normalization is arbitrary).*/
1053 
1054  Scalar minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude((rowScaleUpdate[0] / rowScaling[0]) / rowScaling[0]);
1055 
1056  for (size_t i = 1; i < blkSize; i++) {
1057  Scalar temp = (rowScaleUpdate[i] / rowScaling[i]) / rowScaling[i];
1059  minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude(temp);
1060  }
1061  for (size_t i = 0; i < blkSize; i++) rowScaling[i] *= sqrt(minUpdate / rowScaleUpdate[i]);
1062 
1063  row = 0;
1064  for (size_t i = 0; i < blkSize; i++) colScaleUpdate[i] = 0.0;
1065 
1066  for (LocalOrdinal i = 0; i < nBlks; i++) {
1067  for (size_t j = 0; j < blkSize; j++) {
1070  Amat.getLocalRowView(row, cols, vals);
1071  for (size_t kk = 0; kk < Teuchos::as<size_t>(vals.size()); kk++) {
1072  size_t modGuy = (cols[kk] + 1) % blkSize;
1073  if (modGuy == 0) modGuy = blkSize;
1074  modGuy--;
1075  colScaleUpdate[modGuy] += colScaling[modGuy] * (Teuchos::ScalarTraits<Scalar>::magnitude(vals[kk])) * rowScaling[j];
1076  }
1077  row++;
1078  }
1079  }
1080  Teuchos::reduceAll(*(Amat.getRowMap()->getComm()), Teuchos::REDUCE_SUM, (LocalOrdinal)blkSize, colScaleUpdate.getRawPtr(), tempUpdate.getRawPtr());
1081  for (size_t i = 0; i < blkSize; i++) colScaleUpdate[i] = tempUpdate[i];
1082 
1083  /* We want to scale by sqrt(1/colScaleUpdate), but we'll */
1084  /* normalize things by the minimum colScaleUpdate. That is, the */
1085  /* largest scaling is always one (as normalization is arbitrary).*/
1086 
1087  minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude((colScaleUpdate[0] / colScaling[0]) / colScaling[0]);
1088 
1089  for (size_t i = 1; i < blkSize; i++) {
1090  Scalar temp = (colScaleUpdate[i] / colScaling[i]) / colScaling[i];
1092  minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude(temp);
1093  }
1094  for (size_t i = 0; i < blkSize; i++) colScaling[i] *= sqrt(minUpdate / colScaleUpdate[i]);
1095  }
1096 }
1097 
1102 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1103 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1104 TpetraFECrs_To_XpetraMatrix(const Teuchos::RCP<Tpetra::FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& Atpetra) {
1105  typedef typename Tpetra::FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::crs_matrix_type tpetra_crs_matrix_type;
1109 
1110  RCP<XCrsMatrix> Atmp = rcp(new XTCrsMatrix(rcp_dynamic_cast<tpetra_crs_matrix_type>(Atpetra)));
1111  return rcp(new XCrsMatrixWrap(Atmp));
1112 }
1113 
1118 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1119 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1122 }
1123 
1128 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1129 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1130 TpetraFEMultiVector_To_XpetraMultiVector(const Teuchos::RCP<Tpetra::FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& Vtpetra) {
1132  RCP<const MV> Vmv = Teuchos::rcp_dynamic_cast<const MV>(Vtpetra);
1134 }
1135 
1137 template <class T>
1138 std::string toString(const T& what) {
1139  std::ostringstream buf;
1140  buf << what;
1141  return buf.str();
1142 }
1143 
1144 #ifdef HAVE_MUELU_EPETRA
1145 
1149 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1150 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1152 
1157 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1158 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1160 #endif
1161 
1166 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1167 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1169 
1174 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1175 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1177 
1178 // Generates a communicator whose only members are other ranks of the baseComm on my node
1179 Teuchos::RCP<const Teuchos::Comm<int>> GenerateNodeComm(RCP<const Teuchos::Comm<int>>& baseComm, int& NodeId, const int reductionFactor);
1180 
1181 // Lower case string
1182 std::string lowerCase(const std::string& s);
1183 
1184 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1188  using SC = Scalar;
1189  using LO = LocalOrdinal;
1190  using GO = GlobalOrdinal;
1191  using NO = Node;
1192  using MT = typename Teuchos::ScalarTraits<SC>::magnitudeType;
1193 
1194  Teuchos::RCP<const Teuchos::Comm<int>> comm = localDropMap->getComm();
1195 
1197  toggleVec->putScalar(1);
1198 
1200  Teuchos::RCP<Xpetra::Import<LO, GO, NO>> importer = Xpetra::ImportFactory<LO, GO, NO>::Build(localDropMap, Ain->getColMap());
1201  finalVec->doImport(*toggleVec, *importer, Xpetra::ABSMAX);
1202 
1203  std::vector<GO> finalDropMapEntries = {};
1204  auto finalVec_h_2D = finalVec->getHostLocalView(Xpetra::Access::ReadOnly);
1205  auto finalVec_h_1D = Kokkos::subview(finalVec_h_2D, Kokkos::ALL(), 0);
1206  const size_t localLength = finalVec->getLocalLength();
1207 
1208  for (size_t k = 0; k < localLength; ++k) {
1210  finalDropMapEntries.push_back(finalVec->getMap()->getGlobalElement(k));
1211  }
1212  }
1213 
1215  localDropMap->lib(), Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(), finalDropMapEntries, 0, comm);
1216  return finalDropMap;
1217 } // importOffRankDroppingInfo
1218 
1219 } // namespace MueLu
1220 
1221 #define MUELU_UTILITIES_SHORT
1222 #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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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)