diff --git a/packages/muelu/src/Transfers/GeneralGeometric/MueLu_RegionRFactory_def.hpp b/packages/muelu/src/Transfers/GeneralGeometric/MueLu_RegionRFactory_def.hpp index 521ae93430a4..f0dbe4f2ef8b 100644 --- a/packages/muelu/src/Transfers/GeneralGeometric/MueLu_RegionRFactory_def.hpp +++ b/packages/muelu/src/Transfers/GeneralGeometric/MueLu_RegionRFactory_def.hpp @@ -159,21 +159,22 @@ namespace MueLu { else Tparams= rcp(new ParameterList); + // R->describe(*out, Teuchos::VERB_EXTREME); + *out << "Compute P=R^t" << std::endl; // By default, we don't need global constants for transpose Tparams->set("compute global constants: temporaries",Tparams->get("compute global constants: temporaries", false)); Tparams->set("compute global constants", Tparams->get("compute global constants",false)); std::string label = "MueLu::RegionR-transR" + Teuchos::toString(coarseLevel.GetLevelID()); - // RCP P; RCP P = Utilities::Transpose(*R, true, label, Tparams); - // RCP PCrs = rcp_dynamic_cast(P)->getCrsMatrix(); - // Xpetra::CrsMatrixUtils::sortCrsEntries(); + *out << "Compute coarse nullspace" << std::endl; RCP fineNullspace = Get >(fineLevel, "Nullspace"); RCP coarseNullspace = MultiVectorFactory::Build(R->getRowMap(), fineNullspace->getNumVectors()); R->apply(*fineNullspace, *coarseNullspace, Teuchos::NO_TRANS, Teuchos::ScalarTraits::one(), Teuchos::ScalarTraits::zero()); + *out << "Set data on coarse level" << std::endl; Set(coarseLevel, "numDimensions", numDimensions); Set(coarseLevel, "lNodesPerDim", lCoarseNodesPerDim); Set(coarseLevel, "Nullspace", coarseNullspace); diff --git a/packages/muelu/test/unit_tests/RegionRFactory.cpp b/packages/muelu/test/unit_tests/RegionRFactory.cpp index 00a8ef8993ed..0d9a856ec7f8 100644 --- a/packages/muelu/test/unit_tests/RegionRFactory.cpp +++ b/packages/muelu/test/unit_tests/RegionRFactory.cpp @@ -76,7 +76,8 @@ void createRegionMatrix(const Teuchos::ParameterList galeriList, std::vector > >& colImportPerGrp, std::vector > >& regionGrpMats, Teuchos::ArrayRCP& regionMatVecLIDs, - Teuchos::RCP >& regionInterfaceImporter) { + Teuchos::RCP >& regionInterfaceImporter, + Teuchos::Array& rNodesPerDim) { #include std::string matrixType = galeriList.get("matrixType"); @@ -115,7 +116,6 @@ void createRegionMatrix(const Teuchos::ParameterList galeriList, LO numLocalRegionNodes = 0; Array sendGIDs; Array sendPIDs; - Array rNodesPerDim(3); Array compositeToRegionLIDs(nodeMap->getNodeNumElements()*numDofsPerNode); Array quasiRegionGIDs; Array quasiRegionCoordGIDs; @@ -197,7 +197,8 @@ void createProblem(const int maxRegPerProc, const LocalOrdinal numDofsPerNode, std::vector > >& revisedRowMapPerGrp, std::vector > >& rowImportPerGrp, Teuchos::ArrayRCP& regionMatVecLIDs, - RCP >& regionInterfaceImporter) { + RCP >& regionInterfaceImporter, + Teuchos::Array& rNodesPerDim) { #include using TST = Teuchos::ScalarTraits; using magnitude_type = typename TST::magnitudeType; @@ -240,7 +241,7 @@ void createProblem(const int maxRegPerProc, const LocalOrdinal numDofsPerNode, createRegionMatrix(galeriList, numDofsPerNode, maxRegPerProc, nodeMap, dofMap, A, rowMapPerGrp, colMapPerGrp, revisedRowMapPerGrp, revisedColMapPerGrp, rowImportPerGrp, colImportPerGrp, regionGrpMats, - regionMatVecLIDs, regionInterfaceImporter); + regionMatVecLIDs, regionInterfaceImporter, rNodesPerDim); // Create regional nullspace an coordinates Teuchos::Array > quasiRegionNullspace(maxRegPerProc); @@ -286,11 +287,13 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(RegionRFactory, RegionRFactLaplace3D, Scalar, // Get MPI parameter RCP > comm = TestHelpers::Parameters::getDefaultComm(); + const int numRanks = comm->getSize(); + const int myRank = comm->getRank(); const int numDimensions = 3; const int maxRegPerProc = 1; const LO numDofsPerNode = 1; - GO nx = 10, ny = 10, nz = 10; + GO nx = 7, ny = 7, nz = 4; Teuchos::Array lNodesPerDim({static_cast(nx), static_cast(ny), static_cast(nz)}); Teuchos::CommandLineProcessor &clp = Teuchos::UnitTestRepository::getCLP(); Galeri::Xpetra::Parameters galeriParameters(clp, nx, ny, nz, "Laplace3D"); @@ -302,11 +305,12 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(RegionRFactory, RegionRFactLaplace3D, Scalar, std::vector > rowImportPerGrp(maxRegPerProc); Teuchos::ArrayRCP regionMatVecLIDs; RCP regionInterfaceImporter; + Teuchos::Array rNodesPerDim(3); createProblem(maxRegPerProc, numDofsPerNode, galeriParameters, comm, A, regionGrpMats, regionNullspace, regionCoordinates, revisedRowMapPerGrp, rowImportPerGrp, - regionMatVecLIDs, regionInterfaceImporter); + regionMatVecLIDs, regionInterfaceImporter, rNodesPerDim); RCP regionMat = regionGrpMats[0]; @@ -320,7 +324,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(RegionRFactory, RegionRFactLaplace3D, Scalar, fineLevel.Request("A"); fineLevel.Set("A", regionMat); fineLevel.Set("numDimensions", numDimensions); - fineLevel.Set("lNodesPerDim", lNodesPerDim); + fineLevel.Set("lNodesPerDim", rNodesPerDim); fineLevel.Set("Nullspace", regionNullspace[0]); fineLevel.Set("Coordinates", regionCoordinates[0]); @@ -345,24 +349,90 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(RegionRFactory, RegionRFactLaplace3D, Scalar, RCP R; coarseLevel.Get("R", R, myRFact.get()); coarseLevel.Release("R", myRFact.get()); + TEST_EQUALITY(R != Teuchos::null, true); RCP P; coarseLevel.Get("P", P, myRFact.get()); coarseLevel.Release("P", myRFact.get()); + TEST_EQUALITY(P != Teuchos::null, true); RCP coarseNullspace; coarseLevel.Get("Nullspace", coarseNullspace, myRFact.get()); coarseLevel.Release("Nullspace", myRFact.get()); + TEST_EQUALITY(coarseNullspace != Teuchos::null, true); RCP::coordinateType, LO, GO, NO> > coarseCoordinates; coarseLevel.Get("Coordinates", coarseCoordinates, myRFact.get()); coarseLevel.Release("Coordinates", myRFact.get()); - - R->describe(out, Teuchos::VERB_EXTREME); - P->describe(out, Teuchos::VERB_EXTREME); - // coarseNullspace->describe(out, Teuchos::VERB_EXTREME); - // regionNullspace[0]->describe(out, Teuchos::VERB_EXTREME); - // coarseCoordinates->describe(out, Teuchos::VERB_EXTREME); + TEST_EQUALITY(coarseCoordinates != Teuchos::null, true); + + // R->describe(out, Teuchos::VERB_EXTREME); + + if(numRanks == 1) { + TEST_EQUALITY(R->getGlobalNumRows(), 18); + TEST_EQUALITY(R->getGlobalNumCols(), 196); + TEST_EQUALITY(R->getNodeNumRows(), 18); + TEST_EQUALITY(R->getCrsGraph()->getNodeNumCols(), 196); + TEST_EQUALITY(R->getNodeNumEntries(), 726); + + Array rowLength = {{27, 45, 27, 45, 75, 45, 27, 45, 27, + 27, 45, 27, 45, 75, 45, 27, 45, 27}}; + ArrayView rowEntries; + ArrayView rowValues; + for(int rowIdx = 0; rowIdx < static_cast(R->getNodeNumRows()); ++rowIdx) { + R->getLocalRowView(rowIdx, rowEntries, rowValues); + TEST_EQUALITY(static_cast(rowEntries.size()), rowLength[rowIdx]); + } + + } else { // Running with 4 ranks + TEST_EQUALITY(R->getGlobalNumRows(), 32); + TEST_EQUALITY(R->getCrsGraph()->getNodeNumCols(), 64); + TEST_EQUALITY(R->getNodeNumEntries(), 216); + + ArrayView rowEntries; + ArrayView rowValues; + if(myRank == 0) { + TEST_EQUALITY(R->getNodeNumRows(), 8); + TEST_EQUALITY(R->getCrsGraph()->getNodeNumCols(), 64); + TEST_EQUALITY(R->getNodeNumEntries(), 216); + + Array rowLength = {{27, 27, 27, 27, 27, 27, 27, 27}}; + for(int rowIdx = 0; rowIdx < static_cast(R->getNodeNumRows()); ++rowIdx) { + R->getLocalRowView(rowIdx, rowEntries, rowValues); + TEST_EQUALITY(static_cast(rowEntries.size()), rowLength[rowIdx]); + } + } else if(myRank == 1) { + TEST_EQUALITY(R->getNodeNumRows(), 8); + TEST_EQUALITY(R->getCrsGraph()->getNodeNumCols(), 64); + TEST_EQUALITY(R->getNodeNumEntries(), 216); + + Array rowLength = {{27, 27, 27, 27, 27, 27, 27, 27}}; + for(int rowIdx = 0; rowIdx < static_cast(R->getNodeNumRows()); ++rowIdx) { + R->getLocalRowView(rowIdx, rowEntries, rowValues); + TEST_EQUALITY(static_cast(rowEntries.size()), rowLength[rowIdx]); + } + } else if(myRank == 2) { + TEST_EQUALITY(R->getNodeNumRows(), 8); + TEST_EQUALITY(R->getCrsGraph()->getNodeNumCols(), 64); + TEST_EQUALITY(R->getNodeNumEntries(), 216); + + Array rowLength = {{27, 27, 27, 27, 27, 27, 27, 27}}; + for(int rowIdx = 0; rowIdx < static_cast(R->getNodeNumRows()); ++rowIdx) { + R->getLocalRowView(rowIdx, rowEntries, rowValues); + TEST_EQUALITY(static_cast(rowEntries.size()), rowLength[rowIdx]); + } + } else if(myRank == 3) { + TEST_EQUALITY(R->getNodeNumRows(), 8); + TEST_EQUALITY(R->getCrsGraph()->getNodeNumCols(), 64); + TEST_EQUALITY(R->getNodeNumEntries(), 216); + + Array rowLength = {{27, 27, 27, 27, 27, 27, 27, 27}}; + for(int rowIdx = 0; rowIdx < static_cast(R->getNodeNumRows()); ++rowIdx) { + R->getLocalRowView(rowIdx, rowEntries, rowValues); + TEST_EQUALITY(static_cast(rowEntries.size()), rowLength[rowIdx]); + } + } + } } // RegionRFactLaplace3D