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_RowMatrixTransposer.hpp>
58 #include <Tpetra_Map.hpp>
59 #include <Tpetra_MultiVector.hpp>
63 
64 #include <MueLu_UtilitiesBase.hpp>
65 
66 namespace MueLu {
67 
68 #ifdef HAVE_MUELU_EPETRA
69 // defined after Utilities class
70 template <typename SC, typename LO, typename GO, typename NO>
71 RCP<Xpetra::CrsMatrixWrap<SC, LO, GO, NO>>
72 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP<Epetra_CrsMatrix>& epAB);
73 
74 template <typename SC, typename LO, typename GO, typename NO>
75 RCP<Xpetra::Matrix<SC, LO, GO, NO>>
77 
78 template <typename SC, typename LO, typename GO, typename NO>
79 RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
81 #endif
82 
83 template <typename SC, typename LO, typename GO, typename NO>
84 void leftRghtDofScalingWithinNode(const Xpetra::Matrix<SC, LO, GO, NO>& Atpetra, size_t blkSize, size_t nSweeps, Teuchos::ArrayRCP<SC>& rowScaling, Teuchos::ArrayRCP<SC>& colScaling);
85 
86 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
90 
98 template <class Scalar,
101  class Node = DefaultNode>
102 class Utilities : public UtilitiesBase<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
103 #undef MUELU_UTILITIES_SHORT
104 #include "MueLu_UseShortNames.hpp"
105 
106  public:
108 
109 #ifdef HAVE_MUELU_EPETRA
110  // @{
114 
117 
120 
123 
125  // @}
126 #endif
127 
128  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);
129 
131 
133 
134 }; // class Utilities
135 
137 
138 #ifdef HAVE_MUELU_EPETRA
139 
148 template <>
149 class Utilities<double, int, int, Xpetra::EpetraNode> : public UtilitiesBase<double, int, int, Xpetra::EpetraNode> {
150  public:
151  typedef double Scalar;
152  typedef int LocalOrdinal;
153  typedef int GlobalOrdinal;
156 #undef MUELU_UTILITIES_SHORT
157 #include "MueLu_UseShortNames.hpp"
158 
159  private:
162  // using EpetraCrsMatrix = Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node>;
163  public:
165  // @{
167  RCP<const EpetraMultiVector> tmpVec = rcp_dynamic_cast<EpetraMultiVector>(vec);
168  if (tmpVec == Teuchos::null)
169  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
170  return tmpVec->getEpetra_MultiVector();
171  }
173  RCP<const EpetraMultiVector> tmpVec = rcp_dynamic_cast<EpetraMultiVector>(vec);
174  if (tmpVec == Teuchos::null)
175  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
176  return tmpVec->getEpetra_MultiVector();
177  }
178 
179  static const Epetra_MultiVector& MV2EpetraMV(const MultiVector& vec) {
180  const EpetraMultiVector& tmpVec = dynamic_cast<const EpetraMultiVector&>(vec);
181  return *(tmpVec.getEpetra_MultiVector());
182  }
183  static Epetra_MultiVector& MV2NonConstEpetraMV(MultiVector& vec) {
184  const EpetraMultiVector& tmpVec = dynamic_cast<const EpetraMultiVector&>(vec);
185  return *(tmpVec.getEpetra_MultiVector());
186  }
187 
189  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
190  if (crsOp == Teuchos::null)
191  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
192  const RCP<const EpetraCrsMatrix>& tmp_ECrsMtx = rcp_dynamic_cast<const EpetraCrsMatrix>(crsOp->getCrsMatrix());
193  if (tmp_ECrsMtx == Teuchos::null)
194  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
195  return tmp_ECrsMtx->getEpetra_CrsMatrix();
196  }
198  RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(Op);
199  if (crsOp == Teuchos::null)
200  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
201  const RCP<const EpetraCrsMatrix>& tmp_ECrsMtx = rcp_dynamic_cast<const EpetraCrsMatrix>(crsOp->getCrsMatrix());
202  if (tmp_ECrsMtx == Teuchos::null)
203  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
204  return tmp_ECrsMtx->getEpetra_CrsMatrixNonConst();
205  }
206 
207  static const Epetra_CrsMatrix& Op2EpetraCrs(const Matrix& Op) {
208  try {
209  const CrsMatrixWrap& crsOp = dynamic_cast<const CrsMatrixWrap&>(Op);
210  try {
211  const EpetraCrsMatrix& tmp_ECrsMtx = dynamic_cast<const EpetraCrsMatrix&>(*crsOp.getCrsMatrix());
212  return *tmp_ECrsMtx.getEpetra_CrsMatrix();
213  } catch (std::bad_cast&) {
214  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
215  }
216  } catch (std::bad_cast&) {
217  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
218  }
219  }
221  try {
222  CrsMatrixWrap& crsOp = dynamic_cast<CrsMatrixWrap&>(Op);
223  try {
224  EpetraCrsMatrix& tmp_ECrsMtx = dynamic_cast<EpetraCrsMatrix&>(*crsOp.getCrsMatrix());
225  return *tmp_ECrsMtx.getEpetra_CrsMatrixNonConst();
226  } catch (std::bad_cast&) {
227  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
228  }
229  } catch (std::bad_cast&) {
230  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
231  }
232  }
233 
234  static const Epetra_Map& Map2EpetraMap(const Map& map) {
235  RCP<const EpetraMap> xeMap = rcp_dynamic_cast<const EpetraMap>(rcpFromRef(map));
236  if (xeMap == Teuchos::null)
237  throw Exceptions::BadCast("Utilities::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
238  return xeMap->getEpetra_Map();
239  }
240  // @}
241 
247  static RCP<Matrix> Transpose(Matrix& Op, bool /* optimizeTranspose */ = false, const std::string& label = std::string(), const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
248  switch (Op.getRowMap()->lib()) {
249  case Xpetra::UseTpetra: {
250 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
251  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
252  throw Exceptions::RuntimeError("Utilities::Transpose: Tpetra is not compiled with LO=GO=int. Add TPETRA_INST_INT_INT:BOOL=ON to your configuration!");
253 #else
255  /***************************************************************/
256  if (Helpers::isTpetraCrs(Op)) {
258 
259  // Compute the transpose A of the Tpetra matrix tpetraOp.
261  Tpetra::RowMatrixTransposer<Scalar, LocalOrdinal, GlobalOrdinal, Node> transposer(rcpFromRef(tpetraOp), label);
262 
263  {
265  using Teuchos::rcp;
266  RCP<ParameterList> transposeParams = params.is_null() ? rcp(new ParameterList) : rcp(new ParameterList(*params));
267  transposeParams->set("sort", false);
268  A = transposer.createTranspose(transposeParams);
269  }
270 
272  RCP<CrsMatrix> AAA = rcp_implicit_cast<CrsMatrix>(AA);
273  RCP<Matrix> AAAA = rcp(new CrsMatrixWrap(AAA));
274 
275  if (Op.IsView("stridedMaps"))
276  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true /*doTranspose*/);
277 
278  return AAAA;
279  }
280  /***************************************************************/
281  else if (Helpers::isTpetraBlockCrs(Op)) {
283  // using CRS = Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
284  const BCRS& tpetraOp = toTpetraBlock(Op);
285  RCP<BCRS> At;
286  {
288 
290  using Teuchos::rcp;
291  RCP<ParameterList> transposeParams = params.is_null() ? rcp(new ParameterList) : rcp(new ParameterList(*params));
292  transposeParams->set("sort", false);
293  At = transposer.createTranspose(transposeParams);
294  }
295 
297  RCP<CrsMatrix> AAA = rcp_implicit_cast<CrsMatrix>(AA);
298  RCP<Matrix> AAAA = rcp(new CrsMatrixWrap(AAA));
299 
300  if (Op.IsView("stridedMaps"))
301  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true /*doTranspose*/);
302 
303  return AAAA;
304 
305  }
306  /***************************************************************/
307  else {
308  throw Exceptions::RuntimeError("Utilities::Transpose failed, perhaps because matrix is not a Crs or BlockCrs matrix");
309  }
310 #endif
311  }
312  case Xpetra::UseEpetra: {
313 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT)
314  Teuchos::TimeMonitor tm(*Teuchos::TimeMonitor::getNewTimer("ZZ Entire Transpose"));
315  // Epetra case
318  Epetra_CrsMatrix* A = dynamic_cast<Epetra_CrsMatrix*>(&transposer(epetraOp));
319  transposer.ReleaseTranspose(); // So we can keep A in Muelu...
320 
321  RCP<Epetra_CrsMatrix> rcpA(A);
322  RCP<EpetraCrsMatrix> AA = rcp(new EpetraCrsMatrix(rcpA));
323  RCP<CrsMatrix> AAA = rcp_implicit_cast<CrsMatrix>(AA);
324  RCP<Matrix> AAAA = rcp(new CrsMatrixWrap(AAA));
325 
326  if (Op.IsView("stridedMaps"))
327  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true /*doTranspose*/);
328 
329  return AAAA;
330 #else
331  throw Exceptions::RuntimeError("Epetra (Err. 2)");
332 #endif
333  }
334  default:
335  throw Exceptions::RuntimeError("Only Epetra and Tpetra matrices can be transposed.");
336  }
337 
338  TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
339  }
340 
344  return Xscalar;
345  }
346 
351 
352  // check whether coordinates are contained in parameter list
353  if (paramList.isParameter("Coordinates") == false)
354  return coordinates;
355 
356 #if (defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT)) || \
357  (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))
358 
359  // define Tpetra::MultiVector type with Scalar=float only if
360  // * ETI is turned off, since then the compiler will instantiate it automatically OR
361  // * Tpetra is instantiated on Scalar=float
362 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
364  RCP<tfMV> floatCoords = Teuchos::null;
365 #endif
366 
367  // define Tpetra::MultiVector type with Scalar=double only if
368  // * ETI is turned off, since then the compiler will instantiate it automatically OR
369  // * Tpetra is instantiated on Scalar=double
371  RCP<tdMV> doubleCoords = Teuchos::null;
372  if (paramList.isType<RCP<tdMV>>("Coordinates")) {
373  // Coordinates are stored as a double vector
374  doubleCoords = paramList.get<RCP<tdMV>>("Coordinates");
375  paramList.remove("Coordinates");
376  }
377 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
378  else if (paramList.isType<RCP<tfMV>>("Coordinates")) {
379  // check if coordinates are stored as a float vector
380  floatCoords = paramList.get<RCP<tfMV>>("Coordinates");
381  paramList.remove("Coordinates");
382  doubleCoords = rcp(new tdMV(floatCoords->getMap(), floatCoords->getNumVectors()));
383  deep_copy(*doubleCoords, *floatCoords);
384  }
385 #endif
386  // We have the coordinates in a Tpetra double vector
387  if (doubleCoords != Teuchos::null) {
388  coordinates = Teuchos::rcp(new Xpetra::TpetraMultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LocalOrdinal, GlobalOrdinal, Node>(doubleCoords));
389  TEUCHOS_TEST_FOR_EXCEPT(doubleCoords->getNumVectors() != coordinates->getNumVectors());
390  }
391 #endif // Tpetra instantiated on GO=int and EpetraNode
392 
393 #if defined(HAVE_MUELU_EPETRA)
394  RCP<Epetra_MultiVector> doubleEpCoords;
395  if (paramList.isType<RCP<Epetra_MultiVector>>("Coordinates")) {
396  doubleEpCoords = paramList.get<RCP<Epetra_MultiVector>>("Coordinates");
397  paramList.remove("Coordinates");
400  TEUCHOS_TEST_FOR_EXCEPT(doubleEpCoords->NumVectors() != Teuchos::as<int>(coordinates->getNumVectors()));
401  }
402 #endif
403 
404  // check for Xpetra coordinates vector
405  if (paramList.isType<decltype(coordinates)>("Coordinates")) {
406  coordinates = paramList.get<decltype(coordinates)>("Coordinates");
407  }
408 
410  return coordinates;
411  }
412 
413 }; // class Utilities (specialization SC=double LO=GO=int)
414 
415 #endif // HAVE_MUELU_EPETRA
416 
447 
451 void TokenizeStringAndStripWhiteSpace(const std::string& stream, std::vector<std::string>& tokenList, const char* token = ",");
452 
455 bool IsParamMuemexVariable(const std::string& name);
456 
459 bool IsParamValidVariable(const std::string& name);
460 
461 #ifdef HAVE_MUELU_EPETRA
462 
466 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
467 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
472 
473  RCP<XCrsMatrix> Atmp = rcp(new XECrsMatrix(A));
474  return rcp(new XCrsMatrixWrap(Atmp));
475 }
476 
481 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
482 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
485 }
486 #endif
487 
515 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
517  LocalOrdinal nBlks = (Amat.getRowMap()->getLocalNumElements()) / blkSize;
518 
519  Teuchos::ArrayRCP<Scalar> rowScaleUpdate(blkSize);
520  Teuchos::ArrayRCP<Scalar> colScaleUpdate(blkSize);
521 
522  for (size_t i = 0; i < blkSize; i++) rowScaling[i] = 1.0;
523  for (size_t i = 0; i < blkSize; i++) colScaling[i] = 1.0;
524 
525  for (size_t k = 0; k < nSweeps; k++) {
526  LocalOrdinal row = 0;
527  for (size_t i = 0; i < blkSize; i++) rowScaleUpdate[i] = 0.0;
528 
529  for (LocalOrdinal i = 0; i < nBlks; i++) {
530  for (size_t j = 0; j < blkSize; j++) {
533  Amat.getLocalRowView(row, cols, vals);
534 
535  for (size_t kk = 0; kk < Teuchos::as<size_t>(vals.size()); kk++) {
536  size_t modGuy = (cols[kk] + 1) % blkSize;
537  if (modGuy == 0) modGuy = blkSize;
538  modGuy--;
539  rowScaleUpdate[j] += rowScaling[j] * (Teuchos::ScalarTraits<Scalar>::magnitude(vals[kk])) * colScaling[modGuy];
540  }
541  row++;
542  }
543  }
544  // combine information across processors
545  Teuchos::ArrayRCP<Scalar> tempUpdate(blkSize);
546  Teuchos::reduceAll(*(Amat.getRowMap()->getComm()), Teuchos::REDUCE_SUM, (LocalOrdinal)blkSize, rowScaleUpdate.getRawPtr(), tempUpdate.getRawPtr());
547  for (size_t i = 0; i < blkSize; i++) rowScaleUpdate[i] = tempUpdate[i];
548 
549  /* We want to scale by sqrt(1/rowScaleUpdate), but we'll */
550  /* normalize things by the minimum rowScaleUpdate. That is, the */
551  /* largest scaling is always one (as normalization is arbitrary).*/
552 
553  Scalar minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude((rowScaleUpdate[0] / rowScaling[0]) / rowScaling[0]);
554 
555  for (size_t i = 1; i < blkSize; i++) {
556  Scalar temp = (rowScaleUpdate[i] / rowScaling[i]) / rowScaling[i];
559  }
560  for (size_t i = 0; i < blkSize; i++) rowScaling[i] *= sqrt(minUpdate / rowScaleUpdate[i]);
561 
562  row = 0;
563  for (size_t i = 0; i < blkSize; i++) colScaleUpdate[i] = 0.0;
564 
565  for (LocalOrdinal i = 0; i < nBlks; i++) {
566  for (size_t j = 0; j < blkSize; j++) {
569  Amat.getLocalRowView(row, cols, vals);
570  for (size_t kk = 0; kk < Teuchos::as<size_t>(vals.size()); kk++) {
571  size_t modGuy = (cols[kk] + 1) % blkSize;
572  if (modGuy == 0) modGuy = blkSize;
573  modGuy--;
574  colScaleUpdate[modGuy] += colScaling[modGuy] * (Teuchos::ScalarTraits<Scalar>::magnitude(vals[kk])) * rowScaling[j];
575  }
576  row++;
577  }
578  }
579  Teuchos::reduceAll(*(Amat.getRowMap()->getComm()), Teuchos::REDUCE_SUM, (LocalOrdinal)blkSize, colScaleUpdate.getRawPtr(), tempUpdate.getRawPtr());
580  for (size_t i = 0; i < blkSize; i++) colScaleUpdate[i] = tempUpdate[i];
581 
582  /* We want to scale by sqrt(1/colScaleUpdate), but we'll */
583  /* normalize things by the minimum colScaleUpdate. That is, the */
584  /* largest scaling is always one (as normalization is arbitrary).*/
585 
586  minUpdate = Teuchos::ScalarTraits<Scalar>::magnitude((colScaleUpdate[0] / colScaling[0]) / colScaling[0]);
587 
588  for (size_t i = 1; i < blkSize; i++) {
589  Scalar temp = (colScaleUpdate[i] / colScaling[i]) / colScaling[i];
592  }
593  for (size_t i = 0; i < blkSize; i++) colScaling[i] *= sqrt(minUpdate / colScaleUpdate[i]);
594  }
595 }
596 
598 template <class T>
599 std::string toString(const T& what) {
600  std::ostringstream buf;
601  buf << what;
602  return buf.str();
603 }
604 
605 #ifdef HAVE_MUELU_EPETRA
606 
610 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
611 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
613 
618 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
619 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
621 #endif
622 
623 // Generates a communicator whose only members are other ranks of the baseComm on my node
624 Teuchos::RCP<const Teuchos::Comm<int>> GenerateNodeComm(RCP<const Teuchos::Comm<int>>& baseComm, int& NodeId, const int reductionFactor);
625 
626 // Lower case string
627 std::string lowerCase(const std::string& s);
628 
629 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
633  using SC = Scalar;
634  using LO = LocalOrdinal;
635  using GO = GlobalOrdinal;
636  using NO = Node;
637  using MT = typename Teuchos::ScalarTraits<SC>::magnitudeType;
638 
639  Teuchos::RCP<const Teuchos::Comm<int>> comm = localDropMap->getComm();
640 
642  toggleVec->putScalar(1);
643 
645  Teuchos::RCP<Xpetra::Import<LO, GO, NO>> importer = Xpetra::ImportFactory<LO, GO, NO>::Build(localDropMap, Ain->getColMap());
646  finalVec->doImport(*toggleVec, *importer, Xpetra::ABSMAX);
647 
648  std::vector<GO> finalDropMapEntries = {};
649  auto finalVec_h_2D = finalVec->getLocalViewHost(Xpetra::Access::ReadOnly);
650  auto finalVec_h_1D = Kokkos::subview(finalVec_h_2D, Kokkos::ALL(), 0);
651  const size_t localLength = finalVec->getLocalLength();
652 
653  for (size_t k = 0; k < localLength; ++k) {
655  finalDropMapEntries.push_back(finalVec->getMap()->getGlobalElement(k));
656  }
657  }
658 
660  localDropMap->lib(), Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(), finalDropMapEntries, 0, comm);
661  return finalDropMap;
662 } // importOffRankDroppingInfo
663 
664 } // namespace MueLu
665 
666 #define MUELU_UTILITIES_SHORT
667 #endif // MUELU_UTILITIES_DECL_HPP
Exception indicating invalid cast attempted.
static const Epetra_MultiVector & MV2EpetraMV(const MultiVector &vec)
MueLu::DefaultLocalOrdinal LocalOrdinal
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< 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)
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)
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
size_type size() const
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.
bool IsParamMuemexVariable(const std::string &name)
MueLu::DefaultNode Node
static RCP< Time > getNewTimer(const std::string &name)
bool isParameter(const std::string &name) 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)
virtual void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const =0
static RCP< Epetra_CrsMatrix > Op2NonConstEpetraCrs(RCP< Matrix > Op)
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)
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)
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.
RCP< Xpetra::CrsMatrixWrap< SC, LO, GO, NO > > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP< Epetra_CrsMatrix > &epAB)
bool IsParamValidVariable(const std::string &name)
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)
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
Teuchos::RCP< crs_matrix_type > createTranspose(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
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
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
Exception throws to report errors in the internal logical of the program.
static const Epetra_Map & Map2EpetraMap(const Map &map)
void TokenizeStringAndStripWhiteSpace(const std::string &stream, std::vector< std::string > &tokenList, const char *delimChars)
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< 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)
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...
bool is_null() const