// @HEADER // ***************************************************************************** // ShyLU: Scalable Hybrid LU Preconditioner and Solver // // Copyright 2011 NTESS and the ShyLU contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef _FROSCH_TOOLS_DECL_HPP #define _FROSCH_TOOLS_DECL_HPP #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_SHYLU_DDFROSCH_ZOLTAN2 #include #include #include #include #endif namespace FROSch { using namespace std; using namespace Teuchos; using namespace Xpetra; template class OverlappingData { protected: using IntVec = Array; using LOVec = Array; public: OverlappingData(GO gid, int pid, LO lid); int Merge(const RCP > od) const; GO GID_; mutable IntVec PIDs_; mutable LOVec LIDs_; }; template int MergeList(Array > > &odList); template class LowerPIDTieBreak : public Tpetra::Details::TieBreak { protected: using CommPtr = RCP >; using XMap = Map; using XMapPtr = RCP; using ConstXMapPtr = RCP; using XMapPtrVecPtr = ArrayRCP; using ConstXMapPtrVecPtr = ArrayRCP; using XMapPtrVecPtr2D = ArrayRCP; using ConstXMapPtrVecPtr2D = ArrayRCP; using OverlappingDataPtr = RCP >; using OverlappingDataPtrVec = Array; using UN = unsigned; using IntVec = Array; using IntVecVecPtr = ArrayRCP; using LOVec = Array; using GOVec = Array; using GOVecPtr = ArrayRCP; using GOVecVec = Array; using GOVecVecPtr = ArrayRCP; using GOView = Kokkos::View; public: LowerPIDTieBreak(CommPtr comm, ConstXMapPtr originalMap, UN dimension, UN levelID = 1); // This is in order to estimate the length of SendImageIDs_ and ExportEntries_ in advance virtual bool mayHaveSideEffects() const { return false; } IntVecVecPtr& getComponents() { return ComponentsSubdomains_; } int sendDataToOriginalMap(); virtual size_t selectedIndex(GO GID, const vector > & pid_and_lid) const; protected: CommPtr MpiComm_; ConstXMapPtr OriginalMap_; mutable LO ElementCounter_; // This is mutable such that it can be modified in selectedIndex() mutable OverlappingDataPtrVec OverlappingDataList_; // This is mutable such that it can be modified in selectedIndex() IntVecVecPtr ComponentsSubdomains_; // This is mutable such that it can be modified in selectedIndex() UN LevelID_ = 1; }; template void writeMM(std::string fileName, Teuchos::RCP > &matrix_); template void writeMM(Teuchos::RCP >& matrix_,std::string fileName); template void readMM(std::string fileName, Teuchos::RCP > &matrix_,RCP > &comm); template RCP > BuildRepeatedMapGaleriStruct2D(RCP > matrix,int M,int Dim); template RCP > BuildRepeatedMapGaleriStruct3D(RCP > matrix,int M,int Dim); template RCP > BuildUniqueMap(const RCP > map, bool useCreateOneToOneMap = true, RCP > tieBreak = null); template ArrayRCP > > BuildRepeatedSubMaps(RCP > matrix, ArrayRCP > > subMaps); template ArrayRCP > > BuildRepeatedSubMaps(RCP > graph, ArrayRCP > > subMaps); template RCP > BuildRepeatedMapNonConstOld(RCP > matrix); template RCP > BuildRepeatedMapOld(RCP > matrix); template RCP > BuildRepeatedMapNonConstOld(RCP > graph); template RCP > BuildRepeatedMapOld(RCP > graph); template RCP > BuildRepeatedMapNonConst(RCP > matrix); template RCP > BuildRepeatedMap(RCP > matrix); template RCP > BuildRepeatedMapNonConst(RCP > graph); template RCP > BuildRepeatedMap(RCP > graph); template Teuchos::RCP > BuildMapFromNodeMapRepeated(Teuchos::RCP > &nodesMap, unsigned dofsPerNode, unsigned dofOrdering); template int ExtendOverlapByOneLayer_Old(RCP > inputMatrix, RCP > inputMap, RCP > &outputMatrix, RCP > &outputMap); template int ExtendOverlapByOneLayer(RCP > inputMatrix, RCP > inputMap, RCP > &outputMatrix, RCP > &outputMap); template int ExtendOverlapByOneLayer(RCP > inputGraph, RCP > inputMap, RCP > &outputGraph, RCP > &outputMap); /*! \brief Sort the Xpetra::Map by the global IDs \c x * \param[in] inputMap Unsorted input map */ template RCP > SortMapByGlobalIndex(RCP > inputMap); template RCP > AssembleMaps(ArrayView > > mapVector, ArrayRCP > &partMappings); template RCP > AssembleMapsNonConst(ArrayView > > mapVector, ArrayRCP > &partMappings); template RCP > AssembleSubdomainMap(unsigned numberOfBlocks, ArrayRCP > > > dofsMaps, ArrayRCP dofsPerNode); template RCP > MergeMapsNonConst(ArrayRCP > > mapVector); template RCP > MergeMaps(ArrayRCP > > mapVector); template int BuildDofMaps(const RCP > map, unsigned dofsPerNode, unsigned dofOrdering, RCP > &nodesMap, ArrayRCP > > &dofMaps, GO offset = 0); template int BuildDofMapsVec(const ArrayRCP > > mapVec, ArrayRCP dofsPerNodeVec, ArrayRCP dofOrderingVec, ArrayRCP > > &nodesMapVec, ArrayRCP > > >&dofMapsVec); template RCP > BuildMapFromDofMaps(const ArrayRCP > > &dofMaps, unsigned dofsPerNode, unsigned dofOrdering); template RCP > BuildMapFromNodeMap(RCP > &nodesMap, unsigned dofsPerNode, unsigned dofOrdering); template ArrayRCP > > BuildNodeMapsFromDofMaps(ArrayRCP > > >dofsMapsVecVec, ArrayRCP dofsPerNodeVec, ArrayRCP dofOrderingVec); template ArrayRCP > > BuildSubMaps(RCP > &fullMap, ArrayRCP maxSubGIDVec); template ArrayRCP FindOneEntryOnlyRowsGlobal(RCP > matrix, RCP > repeatedMap); template ArrayRCP FindOneEntryOnlyRowsGlobal(RCP > graph, RCP > repeatedMap); template bool ismultiple(ArrayView A, ArrayView B); template inline void sort(T &v); template inline void sortunique(T &v); template RCP > ModifiedGramSchmidt(RCP > multiVector, ArrayView zero = ArrayView()); template RCP > BuildNullSpace(unsigned dimension, const NullSpaceType nullSpaceType, RCP > repeatedMap, unsigned dofsPerNode, ArrayRCP > > dofsMaps, RCP > nodeList = null); #ifdef HAVE_SHYLU_DDFROSCH_EPETRA template struct ConvertToXpetra { public: static RCP > ConvertMap(UnderlyingLib lib, const Epetra_BlockMap &map, RCP > comm); static RCP > ConvertMatrix(UnderlyingLib lib, Epetra_CrsMatrix &matrix, RCP > comm); static RCP > ConvertMultiVector(UnderlyingLib lib, Epetra_MultiVector &vector, RCP > comm); }; template struct ConvertToXpetra { public: static RCP > ConvertMap(UnderlyingLib lib, const Epetra_BlockMap &map, RCP > comm); static RCP > ConvertMatrix(UnderlyingLib lib, Epetra_CrsMatrix &matrix, RCP > comm); static RCP > ConvertMultiVector(UnderlyingLib lib, Epetra_MultiVector &vector, RCP > comm); }; template struct ConvertToXpetra { public: static RCP > ConvertMap(UnderlyingLib lib, const Epetra_BlockMap &map, RCP > comm); static RCP > ConvertMatrix(UnderlyingLib lib, Epetra_CrsMatrix &matrix, RCP > comm); static RCP > ConvertMultiVector(UnderlyingLib lib, Epetra_MultiVector &vector, RCP > comm); }; #endif template RCP ExtractPtrFromParameterList(ParameterList& paramList, string namePtr="Ptr"); template ArrayRCP ExtractVectorFromParameterList(ParameterList& paramList, string nameVector="Vector"); #ifdef HAVE_SHYLU_DDFROSCH_EPETRA template RCP ConvertToEpetra(const Map &map, RCP epetraComm); template RCP ConvertToEpetra(const MultiVector &vector, RCP epetraComm); template RCP ConvertToEpetra(const Matrix &matrix, RCP epetraComm); #endif template Array GetIndicesFromString(string string); #ifdef HAVE_SHYLU_DDFROSCH_ZOLTAN2 template int RepartionMatrixZoltan2(RCP > &crsMatrix, RCP parameterList); template int BuildRepMapZoltan(RCP > Xgraph, RCP > B, RCP parameterList, Teuchos::RCP > TeuchosComm, RCP > &RepeatedMap); #endif /*! \brief Throw runtime error due to missing package in build configuration As many packages are optional, we might detect only at runtime that are certain package is not included into the build configuration, but still is used by FROSch. Use this routine to throw a generic error message with some information for the user and provide details how to fix it. \param[in] forschObj FROSch object that is asking for the missing package \param[in] packageName Name of the missing package */ inline void ThrowErrorMissingPackage(const string& froschObj, const string& packageName) { // Create the error message stringstream errMsg; errMsg << froschObj << " is asking for the Trilinos packate '"<< packageName << "', " "but this package is not included in your build configuration. " "Please enable '" << packageName << "' in your build configuration to be used with ShyLU_DDFROSch."; // Throw the error FROSCH_ASSERT(false, errMsg.str()); } } #endif