10 #ifndef MUELU_UTILITIES_DECL_HPP
11 #define MUELU_UTILITIES_DECL_HPP
17 #include <Teuchos_DefaultComm.hpp>
21 #include <Xpetra_TpetraBlockCrsMatrix_fwd.hpp>
24 #include <Xpetra_CrsMatrixWrap.hpp>
35 #ifdef HAVE_MUELU_EPETRA
47 #ifdef HAVE_MUELU_EPETRAEXT
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>
64 #include <MueLu_UtilitiesBase.hpp>
68 #ifdef HAVE_MUELU_EPETRA
70 template <
typename SC,
typename LO,
typename GO,
typename NO>
71 RCP<Xpetra::CrsMatrixWrap<SC, LO, GO, NO>>
74 template <
typename SC,
typename LO,
typename GO,
typename NO>
75 RCP<Xpetra::Matrix<SC, LO, GO, NO>>
78 template <
typename SC,
typename LO,
typename GO,
typename NO>
79 RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
83 template <
typename SC,
typename LO,
typename GO,
typename NO>
86 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
102 class Utilities :
public UtilitiesBase<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
103 #undef MUELU_UTILITIES_SHORT
109 #ifdef HAVE_MUELU_EPETRA
138 #ifdef HAVE_MUELU_EPETRA
156 #undef MUELU_UTILITIES_SHORT
168 if (tmpVec == Teuchos::null)
169 throw Exceptions::BadCast(
"Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
170 return tmpVec->getEpetra_MultiVector();
174 if (tmpVec == Teuchos::null)
175 throw Exceptions::BadCast(
"Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
176 return tmpVec->getEpetra_MultiVector();
190 if (crsOp == Teuchos::null)
193 if (tmp_ECrsMtx == Teuchos::null)
194 throw Exceptions::BadCast(
"Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
195 return tmp_ECrsMtx->getEpetra_CrsMatrix();
199 if (crsOp == Teuchos::null)
202 if (tmp_ECrsMtx == Teuchos::null)
203 throw Exceptions::BadCast(
"Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
204 return tmp_ECrsMtx->getEpetra_CrsMatrixNonConst();
209 const CrsMatrixWrap& crsOp =
dynamic_cast<const CrsMatrixWrap&
>(Op);
212 return *tmp_ECrsMtx.getEpetra_CrsMatrix();
213 }
catch (std::bad_cast&) {
214 throw Exceptions::BadCast(
"Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
216 }
catch (std::bad_cast&) {
222 CrsMatrixWrap& crsOp =
dynamic_cast<CrsMatrixWrap&
>(Op);
225 return *tmp_ECrsMtx.getEpetra_CrsMatrixNonConst();
226 }
catch (std::bad_cast&) {
227 throw Exceptions::BadCast(
"Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
229 }
catch (std::bad_cast&) {
236 if (xeMap == Teuchos::null)
237 throw Exceptions::BadCast(
"Utilities::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
238 return xeMap->getEpetra_Map();
248 switch (Op.getRowMap()->lib()) {
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!");
256 if (Helpers::isTpetraCrs(Op)) {
267 transposeParams->set(
"sort",
false);
275 if (Op.IsView(
"stridedMaps"))
276 AAAA->CreateView(
"stridedMaps", Teuchos::rcpFromRef(Op),
true );
281 else if (Helpers::isTpetraBlockCrs(Op)) {
284 const BCRS& tpetraOp = toTpetraBlock(Op);
292 transposeParams->set(
"sort",
false);
300 if (Op.IsView(
"stridedMaps"))
301 AAAA->CreateView(
"stridedMaps", Teuchos::rcpFromRef(Op),
true );
308 throw Exceptions::RuntimeError(
"Utilities::Transpose failed, perhaps because matrix is not a Crs or BlockCrs matrix");
313 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT)
326 if (Op.IsView(
"stridedMaps"))
327 AAAA->CreateView(
"stridedMaps", Teuchos::rcpFromRef(Op),
true );
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))
362 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
375 paramList.
remove(
"Coordinates");
377 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
381 paramList.
remove(
"Coordinates");
382 doubleCoords =
rcp(
new tdMV(floatCoords->getMap(), floatCoords->getNumVectors()));
387 if (doubleCoords != Teuchos::null) {
391 #endif // Tpetra instantiated on GO=int and EpetraNode
393 #if defined(HAVE_MUELU_EPETRA)
397 paramList.
remove(
"Coordinates");
405 if (paramList.
isType<decltype(coordinates)>(
"Coordinates")) {
406 coordinates = paramList.
get<decltype(coordinates)>(
"Coordinates");
415 #endif // HAVE_MUELU_EPETRA
461 #ifdef HAVE_MUELU_EPETRA
466 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
467 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
474 return rcp(
new XCrsMatrixWrap(Atmp));
481 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
482 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
515 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
517 LocalOrdinal nBlks = (Amat.getRowMap()->getLocalNumElements()) / blkSize;
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;
525 for (
size_t k = 0; k < nSweeps; k++) {
527 for (
size_t i = 0; i < blkSize; i++) rowScaleUpdate[i] = 0.0;
530 for (
size_t j = 0; j < blkSize; j++) {
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;
547 for (
size_t i = 0; i < blkSize; i++) rowScaleUpdate[i] = tempUpdate[i];
555 for (
size_t i = 1; i < blkSize; i++) {
556 Scalar temp = (rowScaleUpdate[i] / rowScaling[i]) / rowScaling[i];
560 for (
size_t i = 0; i < blkSize; i++) rowScaling[i] *= sqrt(minUpdate / rowScaleUpdate[i]);
563 for (
size_t i = 0; i < blkSize; i++) colScaleUpdate[i] = 0.0;
566 for (
size_t j = 0; j < blkSize; j++) {
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;
580 for (
size_t i = 0; i < blkSize; i++) colScaleUpdate[i] = tempUpdate[i];
588 for (
size_t i = 1; i < blkSize; i++) {
589 Scalar temp = (colScaleUpdate[i] / colScaling[i]) / colScaling[i];
593 for (
size_t i = 0; i < blkSize; i++) colScaling[i] *= sqrt(minUpdate / colScaleUpdate[i]);
600 std::ostringstream buf;
605 #ifdef HAVE_MUELU_EPETRA
610 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
611 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
618 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
619 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
627 std::string
lowerCase(
const std::string& s);
629 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
642 toggleVec->putScalar(1);
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();
653 for (
size_t k = 0; k < localLength; ++k) {
655 finalDropMapEntries.push_back(finalVec->getMap()->getGlobalElement(k));
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)
T & get(const std::string &name, T def_value)
static RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LocalOrdinal, GlobalOrdinal, Node > > ExtractCoordinatesFromParameterList(ParameterList ¶mList)
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)
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)
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)
static Epetra_CrsMatrix & Op2NonConstEpetraCrs(Matrix &Op)
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 > ¶ms=Teuchos::null)
static RCP< Matrix > Transpose(Matrix &Op, bool=false, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > ¶ms=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 > ¶ms=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 > ¶ms=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)
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
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 ¶mList)
Extract coordinates from parameter list and return them in a Xpetra::MultiVector. ...
#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...