// @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_DEF_HPP #define _FROSCH_TOOLS_DEF_HPP #include #include #include #include namespace FROSch { using namespace std; using namespace Teuchos; using namespace Xpetra; template OverlappingData::OverlappingData(GO gid, int pid, LO lid) : GID_ (gid), PIDs_ (1,pid), LIDs_ (1,lid) { } template int OverlappingData::Merge(const RCP > od) const { FROSCH_ASSERT(GID_ == od->GID_,"FROSch::OverlappingData: GID_ != od->GID_"); for (typename IntVec::iterator it = od->PIDs_.begin(); it != od->PIDs_.end(); it++) { PIDs_.push_back(*it); } for (typename LOVec::iterator it = od->LIDs_.begin(); it != od->LIDs_.end(); it++) { LIDs_.push_back(*it); } return 0; } template int MergeList(Array > > &odList) { int numPackages = 0; std::sort(odList.begin(), odList.end(), [] (const RCP >& lhs, const RCP >& rhs) { return lhs->GID_ < rhs->GID_; } ); odList.erase(unique(odList.begin(), odList.end(), [] (const RCP > lhs, const RCP > rhs) { if (lhs->GID_ == rhs->GID_) { lhs->Merge(rhs); return true; } else { return false; } } ),odList.end()); typename Array > >::iterator tmpODPtrVecIt; for (tmpODPtrVecIt=odList.begin(); tmpODPtrVecIt!=odList.end(); tmpODPtrVecIt++) { numPackages += (*tmpODPtrVecIt)->PIDs_.size()*(*tmpODPtrVecIt)->PIDs_.size(); } return numPackages; } template LowerPIDTieBreak::LowerPIDTieBreak(CommPtr comm, ConstXMapPtr originalMap, UN dimension, UN levelID) : MpiComm_ (comm), OriginalMap_ (originalMap), ElementCounter_ (), OverlappingDataList_ (dimension*(OriginalMap_->getGlobalNumElements()/MpiComm_->getSize())+pow(3,dimension)), ComponentsSubdomains_ (OriginalMap_->getLocalNumElements()), LevelID_ (levelID) { FROSCH_DETAILTIMER_START_LEVELID(lowerPIDTieBreakTime,"LowerPIDTieBreak::LowerPIDTieBreak"); } template int LowerPIDTieBreak::sendDataToOriginalMap() { FROSCH_DETAILTIMER_START_LEVELID(sendDataToOriginalMapTime,"LowerPIDTieBreak::sendDataToOriginalMap"); // This is done analogously to DistributedNoncontiguousDirectory::DistributedNoncontiguousDirectory(const map_type& map,const tie_break_type& tie_break) typedef typename ArrayView::size_type size_type; OverlappingDataList_.resize(ElementCounter_); int numPackages = MergeList(OverlappingDataList_); Tpetra::Distributor distor (MpiComm_); const int packetSize = 2; IntVec sendImageIDs(numPackages); GOView exportEntries("FROSch::sendDataToOriginalMap::exportEntries", packetSize*numPackages); // data to send out { typename OverlappingDataPtrVec::iterator tmpODPtrVecIt; typename IntVec::iterator tmpIntVecIt; typename IntVec::iterator tmpIntVecIt2; typename LOVec::iterator tmpLOVecIt; size_type exportIndex = 0; size_type exportIndex2 = 0; for (tmpODPtrVecIt = OverlappingDataList_.begin(); tmpODPtrVecIt!=OverlappingDataList_.end(); tmpODPtrVecIt++) { tmpLOVecIt = (*tmpODPtrVecIt)->LIDs_.begin(); for (tmpIntVecIt = (*tmpODPtrVecIt)->PIDs_.begin(); tmpIntVecIt != (*tmpODPtrVecIt)->PIDs_.end(); tmpIntVecIt++) { for (tmpIntVecIt2 = (*tmpODPtrVecIt)->PIDs_.begin(); tmpIntVecIt2 != (*tmpODPtrVecIt)->PIDs_.end(); tmpIntVecIt2++) { exportEntries(exportIndex++) = (*tmpODPtrVecIt)->GID_; exportEntries(exportIndex++) = as(*tmpIntVecIt2); sendImageIDs[exportIndex2++] = *tmpIntVecIt; } tmpLOVecIt++; } } } distor.createFromSends(sendImageIDs); GOView importElements("FROSch::sendDataToOriginalMap::importElements", packetSize*distor.getTotalReceiveLength()); distor.doPostsAndWaits(exportEntries,packetSize,importElements); LO length = importElements.extent(0)/packetSize; for (LO i=0; igetLocalElement(importElements(2*i))].push_back(importElements(2*i+1)); } return 0; } template size_t LowerPIDTieBreak::selectedIndex(GO GID, const vector > & pid_and_lid) const { // Always choose index of pair with smallest pid const size_t numLids = pid_and_lid.size(); size_t idx = 0; int minpid = pid_and_lid[0].first; size_t minidx = 0; static int counter = 0; for (idx = 0; idx < numLids; ++idx) { // Organize the overlapping data to send it back to the original processes if (ElementCounter_(GID, pid_and_lid[idx].first, pid_and_lid[idx].second)); } else { FROSCH_WARNING("FROSch::LowerPIDTieBreak",counter == 0,"Preallocation for OverlappingDataList_ is not sufficient on proc."); OverlappingDataList_.push_back(RCP >(new OverlappingData(GID, pid_and_lid[idx].first, pid_and_lid[idx].second))); counter++; } ElementCounter_++; if (pid_and_lid[idx].first < minpid) { minpid = pid_and_lid[idx].first; minidx = idx; } } return minidx; } template void writeMM(std::string fileName, Teuchos::RCP > &matrix_) { FROSCH_DETAILTIMER_START(writeMMTime,"writeMM"); TEUCHOS_TEST_FOR_EXCEPTION( matrix_.is_null(), std::runtime_error,"Matrix in writeMM is null."); TEUCHOS_TEST_FOR_EXCEPTION( !(matrix_->getMap()->lib()==Xpetra::UseTpetra), std::logic_error,"Only available for Tpetra underlying lib."); typedef Tpetra::CrsMatrix TpetraCrsMatrix; typedef Teuchos::RCP TpetraCrsMatrixPtr; Xpetra::CrsMatrixWrap& crsOp = dynamic_cast&>(*matrix_); Xpetra::TpetraCrsMatrix& xTpetraMat = dynamic_cast&>(*crsOp.getCrsMatrix()); TpetraCrsMatrixPtr tpetraMat = xTpetraMat.getTpetra_CrsMatrixNonConst(); Tpetra::MatrixMarket::Writer< TpetraCrsMatrix > tpetraWriter; tpetraWriter.writeSparseFile(fileName, tpetraMat, "matrix", ""); } template void readMM(std::string fileName, Teuchos::RCP > &matrix_,RCP > &comm) { FROSCH_DETAILTIMER_START(readMMTime,"readMM"); TEUCHOS_TEST_FOR_EXCEPTION( !(matrix_->getMap()->lib()==Xpetra::UseTpetra), std::logic_error,"Only available for Tpetra underlying lib."); typedef Tpetra::CrsMatrix TpetraCrsMatrix; typedef Teuchos::RCP TpetraCrsMatrixPtr; TpetraCrsMatrixPtr tmpMatrix; Tpetra::MatrixMarket::Reader tpetraReader; tmpMatrix = tpetraReader.readSparseFile(fileName,comm); matrix_ = rcp_dynamic_cast >(tmpMatrix); } template RCP > BuildRepeatedMapGaleriStruct2D(RCP > matrix,int M,int Dim) { Teuchos::ArrayView< const GO> eleList; eleList = matrix->getMap()->getLocalElementList(); Teuchos::RCP< const Teuchos::Comm< int > > Comm = matrix->getMap()->getComm(); int size = Comm->getSize(); int rank = Comm->getRank(); Teuchos::Array vert; vert.reserve(M*Dim); Teuchos::Array horz; horz.reserve((M+1)*Dim); int numSubPerRow = sqrt(size); GO nodesInRow = M*Dim*numSubPerRow; Teuchos::Array newEle; newEle.reserve(eleList.size()+M*Dim+(M+1)*Dim); int count = 0; for (int i = 0;i::Build(matrix->getMap()->lib(),matrix->getMap()->getGlobalNumElements(),newEle(),0,Comm); } template RCP > BuildRepeatedMapGaleriStruct3D(RCP > matrix,int M,int Dim) { FROSCH_DETAILTIMER_START(Galeri3DMap,"BuildGeometricMap3D"); Teuchos::ArrayView< const GO> eleList; eleList = matrix->getLocalElementList(); Teuchos::RCP< const Teuchos::Comm< int > > Comm = matrix->getComm(); int size = Comm->getSize(); int rank = Comm->getRank(); Teuchos::Array vert; vert.reserve(M*Dim); Teuchos::Array horz; horz.reserve((M+1)*Dim); int numSubPerRow = std::pow(size,1/3.)+0.7; //int numSubPerRow = numSubPerRow1; // numSubPerRow = numSubPerRow+1; //if(Comm->getRank() == 0) std::cout<<"Size "<getRank() == 0) std::cout<<"numSubPerRow1 "<getRank() == 0) std::cout<<"subInLev "<getRank() == 0) std::cout<<"nodesInRow "<getRank() == 0) std::cout<<"nodesInLev "< newEle; newEle.reserve(eleList.size()+M*Dim+(M+1)*Dim); GO startval = eleList[0]/Dim; //Differentiate between locations of the sub //not back if (rank::Build(matrix->getMap()->lib(),matrix->getMap()->getGlobalNumElements(),newEle(),0,Comm); } template RCP > BuildUniqueMap(const RCP > map, bool useCreateOneToOneMap, RCP > tieBreak) { using Xpetra::Vector; FROSCH_DETAILTIMER_START(buildUniqueMapTime,"BuildUniqueMap"); if (useCreateOneToOneMap && map->lib()==UseTpetra) { // Obtain the underlying Tpetra Map const RCP >& xTpetraMap = rcp_dynamic_cast >(map); RCP > tpetraMap = xTpetraMap->getTpetra_Map(); RCP > tpetraMapUnique; if (tieBreak.is_null()) { tpetraMapUnique = createOneToOne(tpetraMap); } else { tpetraMapUnique = createOneToOne(tpetraMap,*tieBreak); } RCP > xTpetraMapUnique(new const TpetraMap(tpetraMapUnique)); return rcp_dynamic_cast >(xTpetraMapUnique); } else { // This is an alternative implementation to createOneToOneMap() FROSCH_WARNING("FROSch::BuildUniqueMap",(map->lib()==UseEpetra && map->getComm()->getRank()==0),"createOneToOneMap() does not exist for Epetra => Using a different implementation."); RCP > myIndices = VectorFactory::Build(map); myIndices->putScalar(map->getComm()->getRank()+1); RCP > linearMap = MapFactory::Build(map->lib(),map->getMaxAllGlobalIndex()+1,0,map->getComm()); RCP > globalIndices = VectorFactory::Build(linearMap); RCP > importer = ImportFactory::Build(map,linearMap); RCP > importer2 = ImportFactory::Build(linearMap,map); // AH 10/16/2017: Ist der notwendig??? Mit Epetra ging es auch ohne einen zweiten XImport und stattdessen mit einem Export globalIndices->doImport(*myIndices,*importer,INSERT); myIndices->putScalar(0); myIndices->doImport(*globalIndices,*importer2,ADD); Array uniqueVector; for (unsigned i=0; igetLocalLength(); i++) { if (myIndices->getData(0)[i] == map->getComm()->getRank()+1) { uniqueVector.push_back(map->getGlobalElement(i)); } } const GO INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(map->lib(),INVALID,uniqueVector(),0,map->getComm()); // We need this setup for maps with offset (with MaxGID+1 not being the number of global elements), or we need an allreduce to determine the number of global elements from uniqueVector // return MapFactory::Build(map->lib(),map->getMaxAllGlobalIndex()+1,uniqueVector(),0,map->getComm()); } } template ArrayRCP > > BuildRepeatedSubMaps(RCP > matrix, ArrayRCP > > subMaps) { FROSCH_DETAILTIMER_START(buildRepeatedSubMapsTime,"BuildRepeatedSubMaps"); ArrayRCP > > repeatedSubMaps(subMaps.size()); for (unsigned i = 0; i < subMaps.size(); i++) { RCP > subMatrixII; ArrayView indI = av_const_cast ( subMaps[i]->getLocalElementList() ); BuildSubmatrix(matrix,indI,subMatrixII); repeatedSubMaps[i] = BuildRepeatedMap(subMatrixII); } return repeatedSubMaps; } template ArrayRCP > > BuildRepeatedSubMaps(RCP > graph, ArrayRCP > > subMaps) { FROSCH_DETAILTIMER_START(buildRepeatedSubMapsTime,"BuildRepeatedSubMaps"); ArrayRCP > > repeatedSubMaps(subMaps.size()); for (unsigned i = 0; i < subMaps.size(); i++) { RCP > subGraphII; ArrayView indI = av_const_cast ( subMaps[i]->getLocalElementList() ); BuildSubgraph(graph,indI,subGraphII); repeatedSubMaps[i] = BuildRepeatedMap(subGraphII); } return repeatedSubMaps; } template RCP > BuildRepeatedMapNonConstOld(RCP > matrix) { FROSCH_DETAILTIMER_START(buildRepeatedMapNonConstTime,"BuildRepeatedMapNonConstOld"); RCP > uniqueMap = MapFactory::Build(matrix->getRowMap(),1); RCP > overlappingMap = uniqueMap.getConst(); ExtendOverlapByOneLayer(matrix,overlappingMap,matrix,overlappingMap); RCP > tmpMatrix = MatrixFactory::Build(overlappingMap,matrix->getGlobalMaxNumRowEntries()); RCP > scatter; RCP > gather = ExportFactory::Build(overlappingMap,uniqueMap); if (tmpMatrix->getRowMap()->lib()==UseEpetra) { scatter = ImportFactory::Build(uniqueMap,overlappingMap); tmpMatrix->doImport(*matrix,*scatter,ADD); } else { tmpMatrix->doImport(*matrix,*gather,ADD); } Array one(1,ScalarTraits::one()); Array myPID(1,uniqueMap->getComm()->getRank()); RCP > commMat = MatrixFactory::Build(overlappingMap,10); RCP > commMatTmp = MatrixFactory::Build(uniqueMap,10); for (unsigned i=0; igetLocalNumElements(); i++) { GO globalRow = overlappingMap->getGlobalElement(i); if (uniqueMap->getLocalElement(globalRow)<0) { ArrayView indices; ArrayView values; tmpMatrix->getGlobalRowView(globalRow,indices,values); LO j=0; while (jgetLocalElement(indices[j])>=0) { j++; } if (j!=indices.size()) { commMat->insertGlobalValues(overlappingMap->getGlobalElement(i),myPID(),one()); // Hier werden immer nur einzelne Werte eingefügt -> Das geht schneller, wenn es Zeilenwise gemacht wird } } } commMat->fillComplete(); commMatTmp->doExport(*commMat,*gather,INSERT); RCP > commMatTmp2 = MatrixFactory::Build(uniqueMap,10); for (unsigned i=0; igetLocalNumElements(); i++) { GO globalRow = uniqueMap->getGlobalElement(i); ArrayView indices; ArrayView values; commMatTmp->getGlobalRowView(globalRow,indices,values); if (indices.size()>0) { for (LO j=0; j pID(1,indices[j]); if (pIDinsertGlobalValues(globalRow,pID(),one()); // Hier werden immer nur einzelne Werte eingefügt -> Das geht schneller, wenn es Zeilenwise gemacht wird } } } } commMatTmp2->fillComplete(); commMatTmp.reset(); commMat = MatrixFactory::Build(overlappingMap,10); commMat->doImport(*commMatTmp2,*gather,ADD); ArrayView myGlobalElements = uniqueMap->getLocalElementList(); Array repeatedIndices(uniqueMap->getLocalNumElements()); for (unsigned i=0; igetLocalNumElements(); i++) { repeatedIndices.at(i) = myGlobalElements[i]; } for (unsigned i=0; igetLocalNumElements(); i++) { GO globalRow = overlappingMap->getGlobalElement(i); ArrayView indices; ArrayView values; commMat->getGlobalRowView(globalRow,indices,values); if (indices.size()>0) { for (LO j=0; j::invalid(); return MapFactory::Build(tmpMatrix->getRowMap()->lib(),INVALID,repeatedIndices(),0,matrix->getRowMap()->getComm()); } template RCP > BuildRepeatedMapOld(RCP > matrix) { return BuildRepeatedMapNonConst(matrix).getConst(); } template RCP > BuildRepeatedMapNonConstOld(RCP > graph) { FROSCH_DETAILTIMER_START(buildRepeatedMapNonConstTime,"BuildRepeatedMapNonConstOld"); RCP > uniqueMap = MapFactory::Build(graph->getRowMap(),1); RCP > overlappingMap = uniqueMap.getConst(); ExtendOverlapByOneLayer(graph,overlappingMap,graph,overlappingMap); RCP > tmpGraph = CrsGraphFactory::Build(overlappingMap); RCP > scatter; RCP > gather = ExportFactory::Build(overlappingMap,uniqueMap); if (tmpGraph->getRowMap()->lib()==UseEpetra) { scatter = ImportFactory::Build(uniqueMap,overlappingMap); tmpGraph->doImport(*graph,*scatter,ADD); } else { tmpGraph->doImport(*graph,*gather,ADD); } Array myPID(1,uniqueMap->getComm()->getRank()); RCP > commGraph = CrsGraphFactory::Build(overlappingMap,10); RCP > commGraphTmp = CrsGraphFactory::Build(uniqueMap,10); for (unsigned i=0; igetLocalNumElements(); i++) { GO globalRow = overlappingMap->getGlobalElement(i); if (uniqueMap->getLocalElement(globalRow)<0) { ArrayView indices; tmpGraph->getGlobalRowView(globalRow,indices); LO j=0; while (jgetLocalElement(indices[j])>=0) { j++; } if (j!=indices.size()) { commGraph->insertGlobalIndices(overlappingMap->getGlobalElement(i),myPID()); } } } commGraph->fillComplete(); commGraphTmp->doExport(*commGraph,*gather,INSERT); RCP > commGraphTmp2 = CrsGraphFactory::Build(uniqueMap,10); for (unsigned i=0; igetLocalNumElements(); i++) { GO globalRow = uniqueMap->getGlobalElement(i); ArrayView indices; commGraphTmp->getGlobalRowView(globalRow,indices); if (indices.size()>0) { for (LO j=0; j pID(1,indices[j]); if (pIDinsertGlobalIndices(globalRow,pID()); } } } } commGraphTmp2->fillComplete(); commGraphTmp.reset(); commGraph = CrsGraphFactory::Build(overlappingMap,10); commGraph->doImport(*commGraphTmp2,*gather,ADD); ArrayView myGlobalElements = uniqueMap->getLocalElementList(); Array repeatedIndices(uniqueMap->getLocalNumElements()); for (unsigned i=0; igetLocalNumElements(); i++) { repeatedIndices.at(i) = myGlobalElements[i]; } for (unsigned i=0; igetLocalNumElements(); i++) { GO globalRow = overlappingMap->getGlobalElement(i); ArrayView indices; commGraph->getGlobalRowView(globalRow,indices); if (indices.size()>0) { for (LO j=0; j::invalid(); return MapFactory::Build(tmpGraph->getRowMap()->lib(),INVALID,repeatedIndices(),0,graph->getRowMap()->getComm()); } template RCP > BuildRepeatedMapOld(RCP > graph) { return BuildRepeatedMapNonConstOld(graph).getConst(); } template RCP > BuildRepeatedMapNonConst(RCP > matrix) { return BuildRepeatedMapNonConst(matrix->getCrsGraph()); } template RCP > BuildRepeatedMap(RCP > matrix) { return BuildRepeatedMapNonConst(matrix).getConst(); } template RCP > BuildRepeatedMapNonConst(RCP > graph) { FROSCH_DETAILTIMER_START(buildRepeatedMapNonConstTime,"BuildRepeatedMapNonConst"); const GO INVALID = Teuchos::OrdinalTraits::invalid(); RCP > uniqueMap = graph->getRowMap(); RCP > overlappingMap; ExtendOverlapByOneLayer(graph,uniqueMap,graph,overlappingMap); RCP > tmpGraphUnique = CrsGraphFactory::Build(uniqueMap,1); Array myPID(1,uniqueMap->getComm()->getRank()); for (unsigned i=0; igetLocalNumElements(); i++) { tmpGraphUnique->insertGlobalIndices(uniqueMap->getGlobalElement(i),myPID()); } RCP > domainMap = MapFactory::Build(uniqueMap->lib(),INVALID,myPID(),0,uniqueMap->getComm()); tmpGraphUnique->fillComplete(domainMap,uniqueMap); RCP > tmpGraphOverlap = CrsGraphFactory::Build(overlappingMap); RCP > importer = ImportFactory::Build(uniqueMap,overlappingMap); tmpGraphOverlap->doImport(*tmpGraphUnique,*importer,ADD); ArrayView indices; Array repeatedIndices(0); for (unsigned i=0; igetLocalNumElements(); i++) { tmpGraphOverlap->getGlobalRowView(overlappingMap->getGlobalElement(i),indices); for (unsigned j=0; jgetComm()->getRank()) { repeatedIndices.push_back(overlappingMap->getGlobalElement(i)); } } } sortunique(repeatedIndices); return MapFactory::Build(uniqueMap->lib(),INVALID,repeatedIndices(),0,uniqueMap->getComm()); } template RCP > BuildRepeatedMap(RCP > graph) { return BuildRepeatedMapNonConst(graph).getConst(); } template Teuchos::RCP > BuildMapFromNodeMapRepeated(Teuchos::RCP > &nodesMap, unsigned dofsPerNode, unsigned dofOrdering) { FROSCH_ASSERT(dofOrdering==0 || dofOrdering==1,"ERROR: Specify a valid DofOrdering."); FROSCH_ASSERT(!nodesMap.is_null(),"nodesMap.is_null()."); unsigned numNodes = nodesMap->getLocalNumElements(); Teuchos::Array globalIDs(dofsPerNode*numNodes); if (dofOrdering==0) { for (unsigned i=0; igetMaxGlobalIndex()+1)+i; } } } else if (dofOrdering == 1) { for (unsigned i=0; igetGlobalElement(j)+i*(nodesMap->getMaxGlobalIndex()+1); } } } else { FROSCH_ASSERT(false,"dofOrdering unknown."); } const GO INVALID = Teuchos::OrdinalTraits::invalid(); return Xpetra::MapFactory::Build(nodesMap->lib(),INVALID,globalIDs(),0,nodesMap->getComm()); } /* template RCP > BuildRepeatedMap(RCP > matrix) { RCP > uniqueMap = MapFactory::Build(matrix->getRowMap(),1); RCP > overlappingMap = uniqueMap; ExtendOverlapByOneLayer(matrix,overlappingMap); RCP > tmpMatrix = matrix; matrix = MatrixFactory::Build(overlappingMap,2*tmpMatrix->getGlobalMaxNumRowEntries()); RCP > scatter = ImportFactory::Build(uniqueMap,overlappingMap); matrix->doImport(*tmpMatrix,*scatter,ADD); Array one(1,ScalarTraits::one()); Array myPID(1,uniqueMap->getComm()->getRank()); RCP > commMat = MatrixFactory::Build(overlappingMap,10); RCP > commMatTmp = MatrixFactory::Build(uniqueMap,10); RCP > commExporter = ExportFactory::Build(overlappingMap,uniqueMap); for (unsigned i=0; igetLocalNumElements(); i++) { GO globalRow = overlappingMap->getGlobalElement(i); if (uniqueMap->getLocalElement(globalRow)<0) { ArrayView indices; ArrayView values; matrix->getGlobalRowView(globalRow,indices,values); LO j=0; while (jgetLocalElement(indices[j])>=0) { j++; } if (j!=indices.size()) { commMat->insertGlobalValues(overlappingMap->getGlobalElement(i),myPID(),one()); // Hier werden immer nur einzelne Werte eingefügt -> Das geht schneller, wenn es Zeilenwise gemacht wird } } } commMat->fillComplete(); commMatTmp->doExport(*commMat,*commExporter,INSERT); RCP > commMatTmp2 = MatrixFactory::Build(uniqueMap,10); for (unsigned i=0; igetLocalNumElements(); i++) { GO globalRow = uniqueMap->getGlobalElement(i); ArrayView indices; ArrayView values; commMatTmp->getGlobalRowView(globalRow,indices,values); if (indices.size()>0) { for (LO j=0; j pID(1,indices[j]); if (pIDinsertGlobalValues(globalRow,pID(),one()); // Hier werden immer nur einzelne Werte eingefügt -> Das geht schneller, wenn es Zeilenwise gemacht wird } } } } commMatTmp2->fillComplete(); commMatTmp.reset(); commMat = MatrixFactory::Build(overlappingMap,10); commMat->doImport(*commMatTmp2,*commExporter,ADD); ArrayView myGlobalElements = uniqueMap->getLocalElementList(); Array repeatedIndices(uniqueMap->getLocalNumElements()); for (unsigned i=0; igetLocalNumElements(); i++) { repeatedIndices.at(i) = myGlobalElements[i]; } for (unsigned i=0; igetLocalNumElements(); i++) { GO globalRow = overlappingMap->getGlobalElement(i); ArrayView indices; ArrayView values; commMat->getGlobalRowView(globalRow,indices,values); if (indices.size()>0) { for (LO j=0; j::Build(matrix->getRowMap()->lib(),-1,repeatedIndices(),0,matrix->getRowMap()->getComm()); } */ template int ExtendOverlapByOneLayer_Old(RCP > inputMatrix, RCP > inputMap, RCP > &outputMatrix, RCP > &outputMap) { FROSCH_DETAILTIMER_START(extendOverlapByOneLayer_OldTime,"ExtendOverlapByOneLayer_Old"); RCP > tmpMatrix = MatrixFactory::Build(inputMap,inputMatrix->getGlobalMaxNumRowEntries()); RCP > scatter = ImportFactory::Build(inputMatrix->getRowMap(),inputMap); tmpMatrix->doImport(*inputMatrix,*scatter,ADD); outputMatrix = tmpMatrix.getConst(); Array indicesOverlappingSubdomain(0); for (unsigned i=0; igetLocalNumElements(); i++) { ArrayView indices; ArrayView values; outputMatrix->getGlobalRowView(inputMap->getGlobalElement(i),indices,values); for (LO j=0; j::invalid(); outputMap = MapFactory::Build(inputMap->lib(),INVALID,indicesOverlappingSubdomain(),0,inputMap->getComm()); tmpMatrix->fillComplete(inputMatrix->getDomainMap(),inputMatrix->getRangeMap()); return 0; } template int ExtendOverlapByOneLayer(RCP > inputMatrix, RCP > inputMap, RCP > &outputMatrix, RCP > &outputMap) { FROSCH_DETAILTIMER_START(extendOverlapByOneLayerTime,"ExtendOverlapByOneLayer"); RCP > tmpMatrix = MatrixFactory::Build(inputMap,inputMatrix->getGlobalMaxNumRowEntries()); RCP > scatter = ImportFactory::Build(inputMatrix->getRowMap(),inputMap); tmpMatrix->doImport(*inputMatrix,*scatter,ADD); tmpMatrix->fillComplete(inputMatrix->getDomainMap(),inputMatrix->getRangeMap()); outputMatrix = tmpMatrix.getConst(); outputMap = outputMatrix->getColMap(); return 0; } template int ExtendOverlapByOneLayer(RCP > inputGraph, RCP > inputMap, RCP > &outputGraph, RCP > &outputMap) { FROSCH_DETAILTIMER_START(extendOverlapByOneLayerTime,"ExtendOverlapByOneLayer"); RCP > tmpGraph = CrsGraphFactory::Build(inputMap,inputGraph->getGlobalMaxNumRowEntries()); RCP > scatter = ImportFactory::Build(inputGraph->getRowMap(),inputMap); tmpGraph->doImport(*inputGraph,*scatter,ADD); tmpGraph->fillComplete(inputGraph->getDomainMap(),inputGraph->getRangeMap()); outputGraph = tmpGraph.getConst(); outputMap = outputGraph->getColMap(); return 0; } template RCP > SortMapByGlobalIndex(RCP > inputMap) { FROSCH_DETAILTIMER_START(sortMapByGlobalIndexTime,"SortMapByGlobalIndex"); Array globalIDs(inputMap->getLocalElementList()); sort(globalIDs); const GO INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(inputMap->lib(),INVALID,globalIDs(),0,inputMap->getComm()); } template RCP > AssembleMaps(ArrayView > > mapVector, ArrayRCP > &partMappings) { FROSCH_DETAILTIMER_START(assembleMapsTime,"AssembleMaps"); FROSCH_ASSERT(mapVector.size()>0,"Length of mapVector is == 0!"); LO i = 0; LO localstart = 0; LO sizetmp = 0; LO size = 0; GO globalstart = 0; partMappings = ArrayRCP >(mapVector.size()); ArrayRCP assembledMapTmp(0); for (unsigned j=0; jgetLocalNumElements(); partMappings[j] = ArrayRCP(sizetmp); size += sizetmp; assembledMapTmp.resize(size); localstart = i; while (igetGlobalElement(i-localstart); i++; } //cout << mapVector[j]->getMaxAllGlobalIndex() << endl; /* globalstart += mapVector[j]->getMaxAllGlobalIndex(); if (mapVector[0]->lib()==UseEpetra || mapVector[j]->getGlobalNumElements()>0) { globalstart += 1; } */ globalstart += max(mapVector[j]->getMaxAllGlobalIndex(),(GO)-1)+1; // AH 04/05/2018: mapVector[j]->getMaxAllGlobalIndex() can result in -2147483648 if the map is empty on the process => introducing max(,) //if (mapVector[j]->getComm()->getRank() == 0) cout << endl << globalstart << endl; } const GO INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(mapVector[0]->lib(),INVALID,assembledMapTmp(),0,mapVector[0]->getComm()); } template RCP > AssembleMapsNonConst(ArrayView > > mapVector, ArrayRCP > &partMappings) { FROSCH_DETAILTIMER_START(assembleMapsTime,"AssembleMapsNonConst"); FROSCH_ASSERT(mapVector.size()>0,"Length of mapVector is == 0!"); LO i = 0; LO localstart = 0; LO sizetmp = 0; LO size = 0; GO globalstart = 0; partMappings = ArrayRCP >(mapVector.size()); ArrayRCP assembledMapTmp(0); for (unsigned j=0; jgetLocalNumElements(); partMappings[j] = ArrayRCP(sizetmp); size += sizetmp; assembledMapTmp.resize(size); localstart = i; while (igetGlobalElement(i-localstart); i++; } //std::cout << mapVector[j]->getMaxAllGlobalIndex() << std::endl; /* globalstart += mapVector[j]->getMaxAllGlobalIndex(); if (mapVector[0]->lib()==UseEpetra || mapVector[j]->getGlobalNumElements()>0) { globalstart += 1; } */ globalstart += std::max(mapVector[j]->getMaxAllGlobalIndex(),(GO)-1)+1; // AH 04/05/2018: mapVector[j]->getMaxAllGlobalIndex() can result in -2147483648 if the map is empty on the process => introducing max(,) //if (mapVector[j]->getComm()->getRank() == 0) std::cout << std::endl << globalstart << std::endl; } const GO INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(mapVector[0]->lib(),INVALID,assembledMapTmp(),0,mapVector[0]->getComm()); } template RCP > AssembleSubdomainMap(unsigned numberOfBlocks, ArrayRCP > > > dofsMaps, ArrayRCP dofsPerNode) { FROSCH_DETAILTIMER_START(assembleSubdomainMapTime,"AssembleSubdomainMap"); FROSCH_ASSERT(numberOfBlocks>0,"FROSch: numberOfBlocks==0"); FROSCH_ASSERT(dofsMaps.size()==numberOfBlocks,"FROSch: dofsMaps.size()!=NumberOfBlocks_"); FROSCH_ASSERT(dofsPerNode.size()==numberOfBlocks,"FROSch: dofsPerNode.size()!=NumberOfBlocks_"); Array mapVector(0); for (unsigned i=0; igetLocalNumElements(); for (unsigned j=1; jgetLocalNumElements()==(unsigned) numMyElements,"FROSch: dofsMaps[i][j]->getLocalNumElements()==numMyElements"); } for (unsigned j=0; jgetGlobalElement(j)); } } } FROSCH_ASSERT(!dofsMaps[0].is_null(),"FROSch: dofsMaps[0].is_null()"); const GO INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(dofsMaps[0][0]->lib(),INVALID,mapVector(),0,dofsMaps[0][0]->getComm()); } template RCP > MergeMapsNonConst(ArrayRCP > > mapVector) { FROSCH_DETAILTIMER_START(mergeMapsNonConstTime,"MergeMapsNonConst"); FROSCH_ASSERT(!mapVector.is_null(),"mapVector is null!"); FROSCH_ASSERT(mapVector.size()>0,"Length of mapVector is == 0!"); Array elementList(mapVector[0]->getLocalElementList()); GO tmpOffset = 0; for (unsigned i=1; igetLocalNumElements(); tmpOffset += mapVector[i-1]->getMaxAllGlobalIndex()+1; Array subElementList(nodeNumElements); for (LO j=0; jgetGlobalElement(j)+tmpOffset; } elementList.insert(elementList.end(),subElementList.begin(),subElementList.end()); } const GO INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(mapVector[0]->lib(),INVALID,elementList(),0,mapVector[0]->getComm()); } template RCP > MergeMaps(ArrayRCP > > mapVector) { return MergeMapsNonConst(mapVector).getConst(); } template int BuildDofMapsVec(const ArrayRCP > > mapVec, ArrayRCP dofsPerNodeVec, ArrayRCP dofOrderingVec, ArrayRCP > > &nodesMapVec, ArrayRCP > > >&dofMapsVec) { FROSCH_DETAILTIMER_START(buildDofMapsVecTime,"BuildDofMapsVec"); unsigned numberBlocks = mapVec.size(); nodesMapVec = ArrayRCP > > (numberBlocks); dofMapsVec = ArrayRCP > > > (numberBlocks); GO tmpOffset = 0; for (unsigned i = 0 ; i < numberBlocks; i++) { BuildDofMaps(mapVec[i],dofsPerNodeVec[i],dofOrderingVec[i],nodesMapVec[i],dofMapsVec[i],tmpOffset); tmpOffset += mapVec[i]->getMaxAllGlobalIndex()+1; } return 0; } template int BuildDofMaps(const RCP > map, unsigned dofsPerNode, unsigned dofOrdering, RCP > &nodesMap, ArrayRCP > > &dofMaps, GO offset) { FROSCH_DETAILTIMER_START(buildDofMapsTime,"BuildDofMaps"); //if (map->getComm()->getRank()==0) cout << "WARNING: BuildDofMaps is yet to be tested...\n"; FROSCH_ASSERT(dofOrdering==0 || dofOrdering==1,"ERROR: Specify a valid DofOrdering."); FROSCH_ASSERT(map->getGlobalNumElements()%dofsPerNode==0 && map->getLocalNumElements()%dofsPerNode==0,"ERROR: The number of dofsPerNode does not divide the number of global dofs in the map!"); Array nodes(map->getLocalNumElements()/dofsPerNode); Array > dofs(dofsPerNode); for (unsigned j=0; j(map->getLocalNumElements()/dofsPerNode); } if (dofOrdering==0) { for (unsigned i=0; igetGlobalElement(dofsPerNode*i)/dofsPerNode; for (unsigned j=0; jgetMaxAllGlobalIndex()+1; for (unsigned i=0; igetGlobalElement(i); for (unsigned j=0; j::invalid(); nodesMap = MapFactory::Build(map->lib(),INVALID,nodes(),0,map->getComm()); dofMaps = ArrayRCP > >(dofsPerNode); for (unsigned j=0; j::Build(map->lib(),INVALID,dofs[j](),0,map->getComm()); } return 0; } template RCP > BuildMapFromDofMaps(const ArrayRCP > > &dofMaps, unsigned dofsPerNode, unsigned dofOrdering) { FROSCH_DETAILTIMER_START(buildMapFromDofMapsTime,"BuildMapFromDofMaps"); FROSCH_ASSERT(dofOrdering==0 || dofOrdering==1,"ERROR: Specify a valid DofOrdering."); FROSCH_ASSERT(!dofMaps.is_null(),"dofMaps.is_null()."); FROSCH_ASSERT(dofMaps.size()==dofsPerNode,"dofMaps.size!=dofsPerNode."); for (unsigned i=0; igetGlobalNumElements()%dofsPerNode==0 && dofMaps[i]->getLocalNumElements()%dofsPerNode==0,"ERROR: The number of dofsPerNode does not divide the number of global dofs in the dofMaps!"); } unsigned numNodes = dofMaps[0]->getLocalNumElements(); Array globalIDs(numNodes); if (dofOrdering==0) { for (unsigned i=0; igetGlobalElement(j); } } } else if (dofOrdering == 1) { for (unsigned i=0; igetGlobalElement(j); } } } else { FROSCH_ASSERT(false,"dofOrdering unknown."); } const GO INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(dofMaps[0]->lib(),INVALID,globalIDs(),0,dofMaps[0]->getComm()); } template RCP > BuildMapFromNodeMap(RCP > &nodesMap, unsigned dofsPerNode, unsigned dofOrdering) { FROSCH_DETAILTIMER_START(buildMapFromNodeMapTime,"BuildMapFromNodeMap"); FROSCH_ASSERT(dofOrdering==0 || dofOrdering==1,"ERROR: Specify a valid DofOrdering."); FROSCH_ASSERT(!nodesMap.is_null(),"nodesMap.is_null()."); unsigned numNodes = nodesMap->getLocalNumElements(); Array globalIDs(dofsPerNode*numNodes); if (dofOrdering==0) { for (unsigned i=0; igetGlobalElement(j)+i; } } } else if (dofOrdering == 1) { for (unsigned i=0; igetGlobalElement(j)+i*nodesMap->getGlobalNumElements(); } } } else { FROSCH_ASSERT(false,"dofOrdering unknown."); } const GO INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(nodesMap->lib(),INVALID,globalIDs(),0,nodesMap->getComm()); } template ArrayRCP > > BuildNodeMapsFromDofMaps(ArrayRCP > > > dofsMapsVecVec, ArrayRCP dofsPerNodeVec, ArrayRCP dofOrderingVec) { typedef Map Map; typedef RCP MapConstPtr; typedef ArrayRCP MapConstPtrVecPtr; FROSCH_ASSERT(!dofsMapsVecVec.is_null(),"dofsMapsVecVec.is_null()."); FROSCH_ASSERT(dofsPerNodeVec.size()==dofOrderingVec.size() && dofsPerNodeVec.size()==dofsMapsVecVec.size(),"ERROR: Wrong number of maps, dof information and/or dof orderings"); unsigned nmbBlocks = dofsMapsVecVec.size(); for (unsigned i=0; i > comm = dofsMapsVecVec[0][0]->getComm(); //Check if the current block is a real block, or if dof indicies are consecutive over more than one block. Array isMergedPrior( nmbBlocks, false ); Array isMergedAfter( nmbBlocks, false ); for (unsigned block=1; blockgetMaxAllGlobalIndex() > dofsMapsVecVec[block][0]->getMinAllGlobalIndex()) {// It is enough to compare the first dofMaps of each block isMergedPrior[block] = true; isMergedAfter[block-1] = true; } } //Determine offset for each block based on isMergedPrior and isMergedAfter. Array blockOffset( nmbBlocks, ScalarTraits::zero() ); //if blocks are real blocks, this entry here will give provide the correct offset. Array consBlockOffset( nmbBlocks, ScalarTraits::zero() ); Array consThisBlockOffset( nmbBlocks, ScalarTraits::zero() ); for (unsigned block=0; block0 ) { blockOffset[block] += dofsMapsVecVec[block-1][dofsMapsVecVec[block-1].size()-1]->getMaxAllGlobalIndex(); //It is assumed that the last dofMap of a block has the highest GID of all block dof maps. unsigned j = block; while (isMergedAfter[j]) { blockOffset[j] = blockOffset[block]; j++; } } } MapConstPtrVecPtr nodeMapsVec( nmbBlocks ); // Build node maps for all blocks const GO INVALID = Teuchos::OrdinalTraits::invalid(); for (unsigned block=0; block globalIndices = dofsMapsVecVec[block][0]->getLocalElementList(); Array globalIndicesNode( globalIndices ); GO offset = dofsMapsVecVec[block][0]->getMinAllGlobalIndex(); for (unsigned i=0; i::Build( dofsMapsVecVec[block][0]->lib(), INVALID,globalIndicesNode(), 0, dofsMapsVecVec[block][0]->getComm() ); } else { //DimensionWise GO minGID = dofsMapsVecVec[block][0]->getMinAllGlobalIndex(); ArrayView< const GO > globalIndices = dofsMapsVecVec[block][0]->getLocalElementList(); Array globalIndicesNode( globalIndices ); for (unsigned i=0; i::Build( dofsMapsVecVec[block][0]->lib(), INVALID,globalIndicesNode(), 0, dofsMapsVecVec[block][0]->getComm() ); } } return nodeMapsVec; } template ArrayRCP > > BuildSubMaps(RCP > &fullMap, ArrayRCP maxSubGIDVec) { FROSCH_DETAILTIMER_START(buildSubMapsTime,"BuildSubMaps"); ArrayRCP > > subMaps(maxSubGIDVec.size()); Array > indicesSubMaps(maxSubGIDVec.size()); ArrayView nodeElementList = fullMap->getLocalElementList(); for (unsigned i = 0; igetLocalNumElements(); i++) { LO subMapNumber = -1; for (unsigned j = (maxSubGIDVec.size()); j > 0; j--) { if (nodeElementList[i] <= maxSubGIDVec[j-1]) { subMapNumber = j-1; } } FROSCH_ASSERT(subMapNumber>-1,"Index not resolved on sub map."); indicesSubMaps[subMapNumber].push_back(nodeElementList[i]); } const GO INVALID = Teuchos::OrdinalTraits::invalid(); for (unsigned j = 0 ; j < maxSubGIDVec.size(); j++) { subMaps[j] = MapFactory::Build(fullMap->lib(),INVALID,indicesSubMaps[j](),0,fullMap->getComm()); } return subMaps; } template ArrayRCP FindOneEntryOnlyRowsGlobal(RCP > matrix, RCP > repeatedMap) { FROSCH_DETAILTIMER_START(findOneEntryOnlyRowsGlobalTime,"FindOneEntryOnlyRowsGlobal"); RCP > repeatedMatrix = MatrixFactory::Build(repeatedMap,2*matrix->getGlobalMaxNumRowEntries()); RCP > scatter = ImportFactory::Build(matrix->getRowMap(),repeatedMap); repeatedMatrix->doImport(*matrix,*scatter,ADD); ArrayRCP oneEntryOnlyRows(repeatedMatrix->getLocalNumRows()); LO tmp = 0; LO nnz; GO row; for (unsigned i=0; igetLocalNumRows(); i++) { row = repeatedMap->getGlobalElement(i); ArrayView indices; ArrayView values; repeatedMatrix->getGlobalRowView(row,indices,values); nnz = indices.size(); if (indices.size()==1) { oneEntryOnlyRows[tmp] = row; tmp++; } else { for (LO j=0; j ArrayRCP FindOneEntryOnlyRowsGlobal(RCP > graph, RCP > repeatedMap) { FROSCH_DETAILTIMER_START(findOneEntryOnlyRowsGlobalTime,"FindOneEntryOnlyRowsGlobal"); RCP > repeatedGraph = CrsGraphFactory::Build(repeatedMap,2*graph->getGlobalMaxNumRowEntries()); RCP > scatter = ImportFactory::Build(graph->getRowMap(),repeatedMap); repeatedGraph->doImport(*graph,*scatter,ADD); ArrayRCP oneEntryOnlyRows(repeatedGraph->getLocalNumRows()); LO tmp = 0; GO row; for (unsigned i=0; igetLocalNumRows(); i++) { row = repeatedMap->getGlobalElement(i); ArrayView indices; repeatedGraph->getGlobalRowView(row,indices); if (indices.size()==1) { oneEntryOnlyRows[tmp] = row; tmp++; } } oneEntryOnlyRows.resize(tmp); return oneEntryOnlyRows; } template bool ismultiple(ArrayView A, ArrayView B) { Array zeros; Array nonzeros; FROSCH_ASSERT(A.size()==B.size(),"Cannot be multiple (size)"); // Search for non-zeros for (unsigned i=0; i=1.0e-12) { return false; } } // Check nonzeros for multiple double mult = B[nonzeros.at(0)]/A[nonzeros.at(0)], mult2; for (unsigned i=1; i=1.0e-12) { return false; } } return true; } template inline void sort(T &v) { std::sort(v.begin(),v.end()); } template inline void sortunique(T &v) { std::sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); } template RCP > ModifiedGramSchmidt(RCP > multiVector, ArrayView zero) { using Xpetra::Vector; FROSCH_DETAILTIMER_START(modifiedGramSchmidtTime,"ModifiedGramSchmidt"); /* n = size(V,1); k = size(V,2); U = zeros(n,k); U(:,1) = V(:,1)/sqrt(V(:,1)'*V(:,1)); for i = 2:k U(:,i) = V(:,i); for j = 1:i-1 U(:,i) = U(:,i) - ( U(:,i)'*U(:,j) )/( U(:,j)'*U(:,j) )*U(:,j); end U(:,i) = U(:,i)/sqrt(U(:,i)'*U(:,i)); end */ unsigned numVec = multiVector->getNumVectors(); Array arrayZero(0); RCP > multiVectorMap = multiVector->getMap(); RCP > resultMultiVector; if (numVec>0) { unsigned itmp = 0; SC en = ScalarTraits::zero(); SC de = ScalarTraits::zero(); SC norm = ScalarTraits::zero(); RCP > tmpMultiVector = MultiVectorFactory::Build(multiVectorMap,numVec); for (unsigned i=0; i > multiVector_i = multiVector->getVector(i); RCP > tmpMultiVectorNonConst_i_itmp = tmpMultiVector->getVectorNonConst(i-itmp); tmpMultiVectorNonConst_i_itmp->update(ScalarTraits::one(),*multiVector_i,ScalarTraits::zero()); for (unsigned j=0; j > tmpMultiVector_j = tmpMultiVector->getVector(j); en = tmpMultiVectorNonConst_i_itmp->dot(*tmpMultiVector_j); de = tmpMultiVector_j->dot(*tmpMultiVector_j); tmpMultiVectorNonConst_i_itmp->update(-en/de,*tmpMultiVector_j,ScalarTraits::one()); } norm = tmpMultiVectorNonConst_i_itmp->norm2(); if (norm<1.0e-10) { arrayZero.push_back(i); itmp++; } else { //tmpMultiVector->getVectorNonConst(i-itmp)->scale(1.0/norm); } } resultMultiVector = MultiVectorFactory::Build(multiVectorMap,numVec); for (unsigned i=0; igetVectorNonConst(i)->update(ScalarTraits::one(),*tmpMultiVector->getVector(i),ScalarTraits::zero()); } } zero = arrayZero(); return resultMultiVector; } template RCP > BuildNullSpace(unsigned dimension, const NullSpaceType nullSpaceType, RCP > repeatedMap, unsigned dofsPerNode, ArrayRCP > > dofsMaps, RCP > nodeList) { FROSCH_DETAILTIMER_START(buildNullSpaceTime,"BuildNullSpace"); /* Here, the nodeList has to be ordered in accordence to the dofsMaps. */ FROSCH_ASSERT(dofsMaps.size()==dofsPerNode,"dofsMaps.size()!=dofsPerNode."); RCP > nullSpaceBasis; if (nullSpaceType == NullSpaceType::Laplace) { nullSpaceBasis = MultiVectorFactory::Build(repeatedMap,dofsPerNode); for (unsigned i=0; igetLocalNumElements(); j++) { nullSpaceBasis->getDataNonConst(i)[repeatedMap->getLocalElement(dofsMaps[i]->getGlobalElement(j))] = ScalarTraits::one(); } } } else if (nullSpaceType == NullSpaceType::Elasticity) { FROSCH_ASSERT(!nodeList.is_null(),"nodeList.is_null()==true. Cannot build the null space for linear elasticity."); FROSCH_ASSERT(nodeList->getNumVectors()==dimension,"nodeList->getNumVectors()!=dimension."); FROSCH_ASSERT(dofsPerNode==dimension,"dofsPerNode==dimension."); if (dimension==2) { nullSpaceBasis = MultiVectorFactory::Build(repeatedMap,3); // translations for (unsigned i=0; i<2; i++) { for (unsigned j=0; jgetLocalNumElements(); j++) { nullSpaceBasis->getDataNonConst(i)[repeatedMap->getLocalElement(dofsMaps[i]->getGlobalElement(j))] = ScalarTraits::one(); } } // rotation for (unsigned j=0; jgetLocalNumElements(); j++) { nullSpaceBasis->getDataNonConst(2)[repeatedMap->getLocalElement(dofsMaps[0]->getGlobalElement(j))] = -nodeList->getData(1)[j]; nullSpaceBasis->getDataNonConst(2)[repeatedMap->getLocalElement(dofsMaps[1]->getGlobalElement(j))] = nodeList->getData(0)[j]; } } else if (dimension==3) { nullSpaceBasis = MultiVectorFactory::Build(repeatedMap,6); // translations for (unsigned i=0; i<3; i++) { for (unsigned j=0; jgetLocalNumElements(); j++) { nullSpaceBasis->getDataNonConst(i)[repeatedMap->getLocalElement(dofsMaps[i]->getGlobalElement(j))] = ScalarTraits::one(); } } // rotations for (unsigned j=0; jgetLocalNumElements(); j++) { nullSpaceBasis->getDataNonConst(3)[repeatedMap->getLocalElement(dofsMaps[0]->getGlobalElement(j))] = nodeList->getData(1)[j]; nullSpaceBasis->getDataNonConst(3)[repeatedMap->getLocalElement(dofsMaps[1]->getGlobalElement(j))] = -nodeList->getData(0)[j]; nullSpaceBasis->getDataNonConst(3)[repeatedMap->getLocalElement(dofsMaps[2]->getGlobalElement(j))] = ScalarTraits::zero(); nullSpaceBasis->getDataNonConst(4)[repeatedMap->getLocalElement(dofsMaps[0]->getGlobalElement(j))] = -nodeList->getData(2)[j]; nullSpaceBasis->getDataNonConst(4)[repeatedMap->getLocalElement(dofsMaps[1]->getGlobalElement(j))] = ScalarTraits::zero(); nullSpaceBasis->getDataNonConst(4)[repeatedMap->getLocalElement(dofsMaps[2]->getGlobalElement(j))] = nodeList->getData(0)[j]; nullSpaceBasis->getDataNonConst(5)[repeatedMap->getLocalElement(dofsMaps[0]->getGlobalElement(j))] = ScalarTraits::zero(); nullSpaceBasis->getDataNonConst(5)[repeatedMap->getLocalElement(dofsMaps[1]->getGlobalElement(j))] = nodeList->getData(2)[j]; nullSpaceBasis->getDataNonConst(5)[repeatedMap->getLocalElement(dofsMaps[2]->getGlobalElement(j))] = -nodeList->getData(1)[j]; } } } else { FROSCH_ASSERT(false,"NullSpaceType unknown."); } return nullSpaceBasis; } #ifdef HAVE_SHYLU_DDFROSCH_EPETRA template RCP > ConvertToXpetra::ConvertMap(UnderlyingLib lib, const Epetra_BlockMap &map, RCP > comm) { FROSCH_ASSERT(false,"FROSch::ConvertToXpetra: Needs specialization."); return null; } template RCP > ConvertToXpetra::ConvertMatrix(UnderlyingLib lib, Epetra_CrsMatrix &matrix, RCP > comm) { FROSCH_ASSERT(false,"FROSch::ConvertToXpetra: Needs specialization."); return null; } template RCP > ConvertToXpetra::ConvertMultiVector(UnderlyingLib lib, Epetra_MultiVector &vector, RCP > comm) { FROSCH_DETAILTIMER_START(convertMultiVectorTime,"ConvertToXpetra::ConvertMultiVector"); RCP > map = ConvertToXpetra::ConvertMap(lib,vector.Map(),comm); RCP > xMultiVector = MultiVectorFactory::Build(map,vector.NumVectors()); for (LO i=0; igetDataNonConst(i)[j] = vector[i][j]; } } return xMultiVector; } template RCP > ConvertToXpetra::ConvertMap(UnderlyingLib lib, const Epetra_BlockMap &map, RCP > comm) { FROSCH_DETAILTIMER_START(convertMapTime,"ConvertToXpetra::ConvertMap"); ArrayView mapArrayView(map.MyGlobalElements(),map.NumMyElements()); const int INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(lib,INVALID,mapArrayView,0,comm); } template RCP > ConvertToXpetra::ConvertMatrix(UnderlyingLib lib, Epetra_CrsMatrix &matrix, RCP > comm) { FROSCH_DETAILTIMER_START(convertMatrixTime,"ConvertToXpetra::ConvertMatrix"); RCP > rowMap = ConvertToXpetra::ConvertMap(lib,matrix.RowMap(),comm); RCP > xmatrix = MatrixFactory::Build(rowMap,matrix.MaxNumEntries()); for (unsigned i=0; igetLocalNumRows(); i++) { LO numEntries; LO* indices; SC* values; matrix.ExtractMyRowView(i,numEntries,values,indices); Array indicesArray(numEntries); ArrayView valuesArrayView(values,numEntries); for (LO j=0; jinsertGlobalValues(matrix.RowMap().GID(i),indicesArray(),valuesArrayView); } xmatrix->fillComplete(); return xmatrix; } template RCP > ConvertToXpetra::ConvertMultiVector(UnderlyingLib lib, Epetra_MultiVector &vector, RCP > comm) { FROSCH_DETAILTIMER_START(convertMultiVectorTime,"ConvertToXpetra::ConvertMultiVector"); RCP > map = ConvertToXpetra::ConvertMap(lib,vector.Map(),comm); RCP > xMultiVector = MultiVectorFactory::Build(map,vector.NumVectors()); for (LO i=0; igetDataNonConst(i)[j] = vector[i][j]; } } return xMultiVector; } template RCP > ConvertToXpetra::ConvertMap(UnderlyingLib lib, const Epetra_BlockMap &map, RCP > comm) { FROSCH_DETAILTIMER_START(convertMapTime,"ConvertToXpetra::ConvertMap"); ArrayView mapArrayView(map.MyGlobalElements64(),map.NumMyElements()); const long long INVALID = Teuchos::OrdinalTraits::invalid(); return MapFactory::Build(lib,INVALID,mapArrayView,0,comm); } template RCP > ConvertToXpetra::ConvertMatrix(UnderlyingLib lib, Epetra_CrsMatrix &matrix, RCP > comm) { FROSCH_DETAILTIMER_START(convertMatrixTime,"ConvertToXpetra::ConvertMatrix"); RCP > rowMap = ConvertToXpetra::ConvertMap(lib,matrix.RowMap(),comm); RCP > xmatrix = MatrixFactory::Build(rowMap,matrix.MaxNumEntries()); for (unsigned i=0; igetLocalNumRows(); i++) { LO numEntries; LO* indices; SC* values; matrix.ExtractMyRowView(i,numEntries,values,indices); Array indicesArray(numEntries); ArrayView valuesArrayView(values,numEntries); for (LO j=0; jinsertGlobalValues(matrix.RowMap().GID64(i),indicesArray(),valuesArrayView); } xmatrix->fillComplete(); return xmatrix; } template RCP > ConvertToXpetra::ConvertMultiVector(UnderlyingLib lib, Epetra_MultiVector &vector, RCP > comm) { FROSCH_DETAILTIMER_START(convertMultiVectorTime,"ConvertToXpetra::ConvertMultiVector"); RCP > map = ConvertToXpetra::ConvertMap(lib,vector.Map(),comm); RCP > xMultiVector = MultiVectorFactory::Build(map,vector.NumVectors()); for (LO i=0; igetDataNonConst(i)[j] = vector[i][j]; } } return xMultiVector; } #endif template RCP ExtractPtrFromParameterList(ParameterList& paramList, string namePtr) { FROSCH_DETAILTIMER_START(extractPtrFromParameterListTime,"ExtractPtrFromParameterList"); RCP pointer = null; if (paramList.isParameter(namePtr) == false) return pointer; if (paramList.isType(namePtr)) { pointer = paramList.get(namePtr); } return pointer; } template ArrayRCP ExtractVectorFromParameterList(ParameterList& paramList, string nameVector) { FROSCH_DETAILTIMER_START(extractVectorFromParameterListTime,"ExtractVectorFromParameterList"); ArrayRCP vector = null; if (paramList.isParameter(nameVector) == false) return vector; if (paramList.isType(nameVector)) { vector = paramList.get(nameVector); } return vector; } #ifdef HAVE_SHYLU_DDFROSCH_EPETRA template RCP ConvertToEpetra(const Map &map, RCP epetraComm) { FROSCH_DETAILTIMER_START(convertToEpetraTime,"ConvertToEpetra"); ArrayView elementList = map.getLocalElementList(); GO numGlobalElements = map.getGlobalNumElements(); if (elementList.size()>0) return rcp(new Epetra_Map(numGlobalElements,elementList.size(),elementList.getRawPtr(),0,*epetraComm)); else return rcp(new Epetra_Map(numGlobalElements,0,NULL,0,*epetraComm)); } template RCP ConvertToEpetra(const MultiVector &vector, RCP epetraComm) { FROSCH_DETAILTIMER_START(convertToEpetraTime,"ConvertToEpetra"); RCP map = ConvertToEpetra(*vector.getMap(),epetraComm); RCP multiVector(new Epetra_MultiVector(*map,vector.getNumVectors())); for (LO i=0; i RCP ConvertToEpetra(const Matrix &matrix, RCP epetraComm) { FROSCH_DETAILTIMER_START(convertToEpetraTime,"ConvertToEpetra"); RCP map = ConvertToEpetra(*matrix.getMap(),epetraComm); RCP matrixEpetra(new Epetra_CrsMatrix(::Copy,*map,matrix.getGlobalMaxNumRowEntries())); ArrayView valuesArrayView; ArrayView indicesArrayView; for (LO i=0; i<(LO) matrix.getRowMap()->getLocalNumElements(); i++) { matrix.getLocalRowView(i, indicesArrayView, valuesArrayView); Array indicesGlobal(indicesArrayView.size()); for (LO j=0; jgetGlobalElement(indicesArrayView[j]); } if (indicesArrayView.size()>0) { matrixEpetra->InsertGlobalValues(matrix.getRowMap()->getGlobalElement(i), indicesArrayView.size(), &(valuesArrayView[0]), &(indicesGlobal[0])); } } matrixEpetra->FillComplete(); return matrixEpetra; } #endif template Array GetIndicesFromString(string string, LO dummy) { Array indices(0); for (unsigned i=0; i int RepartionMatrixZoltan2(RCP > &crsMatrix, RCP parameterList) { FROSCH_DETAILTIMER_START(repartionMatrixZoltan2Time,"RepartionMatrixZoltan2"); RCP fancy = fancyOStream(rcpFromRef(cout)); using inputAdapter = Zoltan2::XpetraCrsMatrixAdapter >; RCP > tmpCrsWrap = rcp_dynamic_cast >(crsMatrix); RCP > tmpCrsMatrix = tmpCrsWrap->getCrsMatrix(); inputAdapter adaptedMatrix(tmpCrsMatrix); RCP > problem = rcp(new Zoltan2::PartitioningProblem(&adaptedMatrix, parameterList.get())); problem->solve(); RCP > matrixRepartition; adaptedMatrix.applyPartitioningSolution(*tmpCrsMatrix,matrixRepartition,problem->getSolution()); RCP > tmpCrsWrap2 = rcp(new CrsMatrixWrap(matrixRepartition)); crsMatrix = rcp_dynamic_cast >(tmpCrsWrap2); return 0; } template int BuildRepMapZoltan(RCP > Xgraph, RCP > B, RCP parameterList, Teuchos::RCP > TeuchosComm, RCP > &RepeatedMap) { FROSCH_DETAILTIMER_START(BuildRepMapZoltanTime,"Tools::BuildRepMapZoltan"); //Zoltan2 Problem typedef Zoltan2::XpetraCrsGraphAdapter > inputAdapter; Teuchos::RCP tmpList = Teuchos::sublist(parameterList,"Zoltan2 Parameter"); Teuchos::RCP adaptedMatrix = Teuchos::rcp(new inputAdapter(Xgraph,0,0)); size_t MaxRow = B->getGlobalMaxNumRowEntries(); Teuchos::RCP > ColMap = Xpetra::MapFactory::createLocalMap(Xgraph->getRowMap()->lib(),MaxRow,TeuchosComm); Teuchos::RCP >problem; { problem = Teuchos::RCP >(new Zoltan2::PartitioningProblem (adaptedMatrix.getRawPtr(), tmpList.get(),TeuchosComm)); problem->solve(); } // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Teuchos::RCP > ReGraph; { adaptedMatrix->applyPartitioningSolution(*Xgraph,ReGraph,problem->getSolution()); } Teuchos::RCP > scatter = Xpetra::ImportFactory::Build(Xgraph->getRowMap(),ReGraph->getRowMap()); Teuchos::RCP > BB = Xpetra::CrsGraphFactory::Build(ReGraph->getRowMap(),MaxRow); { BB->doImport(*B,*scatter,Xpetra::INSERT); } // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Teuchos::Array repeatedMapEntries(0); for (unsigned i = 0; igetRowMap()->getLocalNumElements(); i++) { Teuchos::ArrayView arr; Teuchos::ArrayView cc; GO gi = ReGraph->getRowMap()->getGlobalElement(i); BB->getGlobalRowView(gi,arr); for (unsigned j=0; j::invalid(); RepeatedMap = Xpetra::MapFactory::Build(ReGraph->getColMap()->lib(),INVALID,repeatedMapEntries(),0,ReGraph->getColMap()->getComm()); return 0; } #endif } // namespace FROSch #endif