Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trilinos Master Merge PR Generator: Auto PR created to promote from master_merge_20200824_000609 branch to master #7885

Merged
merged 2 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Matrix> P;
RCP<Matrix> P = Utilities::Transpose(*R, true, label, Tparams);
// RCP<CrsMatrix> PCrs = rcp_dynamic_cast<CrsMatrixWrap>(P)->getCrsMatrix();
// Xpetra::CrsMatrixUtils<SC,LO,GO,NO>::sortCrsEntries();

*out << "Compute coarse nullspace" << std::endl;
RCP<MultiVector> fineNullspace = Get<RCP<MultiVector> >(fineLevel, "Nullspace");
RCP<MultiVector> coarseNullspace = MultiVectorFactory::Build(R->getRowMap(),
fineNullspace->getNumVectors());
R->apply(*fineNullspace, *coarseNullspace, Teuchos::NO_TRANS, Teuchos::ScalarTraits<SC>::one(),
Teuchos::ScalarTraits<SC>::zero());

*out << "Set data on coarse level" << std::endl;
Set(coarseLevel, "numDimensions", numDimensions);
Set(coarseLevel, "lNodesPerDim", lCoarseNodesPerDim);
Set(coarseLevel, "Nullspace", coarseNullspace);
Expand Down
96 changes: 83 additions & 13 deletions packages/muelu/test/unit_tests/RegionRFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ void createRegionMatrix(const Teuchos::ParameterList galeriList,
std::vector<RCP<Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node> > >& colImportPerGrp,
std::vector<RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > >& regionGrpMats,
Teuchos::ArrayRCP<LocalOrdinal>& regionMatVecLIDs,
Teuchos::RCP<Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node> >& regionInterfaceImporter) {
Teuchos::RCP<Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node> >& regionInterfaceImporter,
Teuchos::Array<LocalOrdinal>& rNodesPerDim) {
#include <MueLu_UseShortNames.hpp>

std::string matrixType = galeriList.get<std::string>("matrixType");
Expand Down Expand Up @@ -115,7 +116,6 @@ void createRegionMatrix(const Teuchos::ParameterList galeriList,
LO numLocalRegionNodes = 0;
Array<GO> sendGIDs;
Array<int> sendPIDs;
Array<LO> rNodesPerDim(3);
Array<LO> compositeToRegionLIDs(nodeMap->getNodeNumElements()*numDofsPerNode);
Array<GO> quasiRegionGIDs;
Array<GO> quasiRegionCoordGIDs;
Expand Down Expand Up @@ -197,7 +197,8 @@ void createProblem(const int maxRegPerProc, const LocalOrdinal numDofsPerNode,
std::vector<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > >& revisedRowMapPerGrp,
std::vector<RCP<Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node> > >& rowImportPerGrp,
Teuchos::ArrayRCP<LocalOrdinal>& regionMatVecLIDs,
RCP<Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node> >& regionInterfaceImporter) {
RCP<Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node> >& regionInterfaceImporter,
Teuchos::Array<LocalOrdinal>& rNodesPerDim) {
#include <MueLu_UseShortNames.hpp>
using TST = Teuchos::ScalarTraits<SC>;
using magnitude_type = typename TST::magnitudeType;
Expand Down Expand Up @@ -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<RCP<MultiVector> > quasiRegionNullspace(maxRegPerProc);
Expand Down Expand Up @@ -286,11 +287,13 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(RegionRFactory, RegionRFactLaplace3D, Scalar,

// Get MPI parameter
RCP<const Teuchos::Comm<int> > 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<LO> lNodesPerDim({static_cast<LO>(nx), static_cast<LO>(ny), static_cast<LO>(nz)});
Teuchos::CommandLineProcessor &clp = Teuchos::UnitTestRepository::getCLP();
Galeri::Xpetra::Parameters<GO> galeriParameters(clp, nx, ny, nz, "Laplace3D");
Expand All @@ -302,11 +305,12 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(RegionRFactory, RegionRFactLaplace3D, Scalar,
std::vector<RCP<Import> > rowImportPerGrp(maxRegPerProc);
Teuchos::ArrayRCP<LocalOrdinal> regionMatVecLIDs;
RCP<Import> regionInterfaceImporter;
Teuchos::Array<LO> rNodesPerDim(3);

createProblem(maxRegPerProc, numDofsPerNode, galeriParameters, comm,
A, regionGrpMats, regionNullspace, regionCoordinates,
revisedRowMapPerGrp, rowImportPerGrp,
regionMatVecLIDs, regionInterfaceImporter);
regionMatVecLIDs, regionInterfaceImporter, rNodesPerDim);

RCP<Matrix> regionMat = regionGrpMats[0];

Expand All @@ -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]);

Expand All @@ -345,24 +349,90 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(RegionRFactory, RegionRFactLaplace3D, Scalar,
RCP<Matrix> R;
coarseLevel.Get("R", R, myRFact.get());
coarseLevel.Release("R", myRFact.get());
TEST_EQUALITY(R != Teuchos::null, true);

RCP<Matrix> P;
coarseLevel.Get("P", P, myRFact.get());
coarseLevel.Release("P", myRFact.get());
TEST_EQUALITY(P != Teuchos::null, true);

RCP<MultiVector> coarseNullspace;
coarseLevel.Get("Nullspace", coarseNullspace, myRFact.get());
coarseLevel.Release("Nullspace", myRFact.get());
TEST_EQUALITY(coarseNullspace != Teuchos::null, true);

RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::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<LO> rowLength = {{27, 45, 27, 45, 75, 45, 27, 45, 27,
27, 45, 27, 45, 75, 45, 27, 45, 27}};
ArrayView<const LO> rowEntries;
ArrayView<const SC> rowValues;
for(int rowIdx = 0; rowIdx < static_cast<int>(R->getNodeNumRows()); ++rowIdx) {
R->getLocalRowView(rowIdx, rowEntries, rowValues);
TEST_EQUALITY(static_cast<LO>(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<const LO> rowEntries;
ArrayView<const SC> rowValues;
if(myRank == 0) {
TEST_EQUALITY(R->getNodeNumRows(), 8);
TEST_EQUALITY(R->getCrsGraph()->getNodeNumCols(), 64);
TEST_EQUALITY(R->getNodeNumEntries(), 216);

Array<LO> rowLength = {{27, 27, 27, 27, 27, 27, 27, 27}};
for(int rowIdx = 0; rowIdx < static_cast<int>(R->getNodeNumRows()); ++rowIdx) {
R->getLocalRowView(rowIdx, rowEntries, rowValues);
TEST_EQUALITY(static_cast<LO>(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<LO> rowLength = {{27, 27, 27, 27, 27, 27, 27, 27}};
for(int rowIdx = 0; rowIdx < static_cast<int>(R->getNodeNumRows()); ++rowIdx) {
R->getLocalRowView(rowIdx, rowEntries, rowValues);
TEST_EQUALITY(static_cast<LO>(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<LO> rowLength = {{27, 27, 27, 27, 27, 27, 27, 27}};
for(int rowIdx = 0; rowIdx < static_cast<int>(R->getNodeNumRows()); ++rowIdx) {
R->getLocalRowView(rowIdx, rowEntries, rowValues);
TEST_EQUALITY(static_cast<LO>(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<LO> rowLength = {{27, 27, 27, 27, 27, 27, 27, 27}};
for(int rowIdx = 0; rowIdx < static_cast<int>(R->getNodeNumRows()); ++rowIdx) {
R->getLocalRowView(rowIdx, rowEntries, rowValues);
TEST_EQUALITY(static_cast<LO>(rowEntries.size()), rowLength[rowIdx]);
}
}
}

} // RegionRFactLaplace3D

Expand Down