| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include <Teuchos_UnitTestHarness.hpp> |
| 11 |
#include <Xpetra_MultiVectorFactory.hpp> |
| 12 |
|
| 13 |
#include "MueLu_TestHelpers_kokkos.hpp" |
| 14 |
#include "MueLu_Utilities.hpp" |
| 15 |
#include "MueLu_Version.hpp" |
| 16 |
|
| 17 |
#include "MueLu_LineDetectionFactory.hpp" |
| 18 |
#include "MueLu_SemiCoarsenPFactory_kokkos.hpp" |
| 19 |
|
| 20 |
namespace MueLuTests { |
| 21 |
|
| 22 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(SemiCoarsenPFactory_kokkos, TestSemiCoarsenP, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 23 |
#include "MueLu_UseShortNames.hpp" |
| 24 |
MUELU_TESTING_SET_OSTREAM; |
| 25 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 26 |
|
| 27 |
out << "version: " << MueLu::Version() << std::endl; |
| 28 |
|
| 29 |
typedef TestHelpers_kokkos::TestFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node> test_factory; |
| 30 |
Level fineLevel, coarseLevel; |
| 31 |
test_factory::createTwoLevelHierarchy(fineLevel, coarseLevel); |
| 32 |
fineLevel.SetFactoryManager(Teuchos::null); // factory manager is not used on this test |
| 33 |
coarseLevel.SetFactoryManager(Teuchos::null); |
| 34 |
|
| 35 |
// Set global geometric data |
| 36 |
const std::string meshLayout = "Global Lexicographic"; |
| 37 |
const std::string coupling = "uncoupled"; |
| 38 |
const LO numDimensions = 3; |
| 39 |
const LO numSize = 5; |
| 40 |
Array<GO> meshData; |
| 41 |
Array<LO> lNodesPerDir(numDimensions); |
| 42 |
Array<GO> gNodesPerDir(numDimensions); |
| 43 |
for (int dim = 0; dim < numDimensions; ++dim) |
| 44 |
gNodesPerDir[dim] = numSize; |
| 45 |
|
| 46 |
typedef typename Teuchos::ScalarTraits<Scalar>::coordinateType coord_type; |
| 47 |
typedef Xpetra::MultiVector<coord_type, LO, GO, NO> CoordMV; |
| 48 |
RCP<CoordMV> fineCoords = |
| 49 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildGeoCoordinates(numDimensions, gNodesPerDir, |
| 50 |
lNodesPerDir, meshData, |
| 51 |
meshLayout); |
| 52 |
|
| 53 |
Teuchos::ParameterList matrixList; |
| 54 |
matrixList.set("nx", gNodesPerDir[0]); |
| 55 |
matrixList.set("ny", gNodesPerDir[1]); |
| 56 |
matrixList.set("nz", gNodesPerDir[2]); |
| 57 |
matrixList.set("matrixType", "Laplace3D"); |
| 58 |
matrixList.set("left boundary", "Neumann"); |
| 59 |
matrixList.set("right boundary", "Neumann"); |
| 60 |
matrixList.set("front boundary", "Neumann"); |
| 61 |
matrixList.set("back boundary", "Neumann"); |
| 62 |
matrixList.set("bottom boundary", "Dirichlet"); |
| 63 |
matrixList.set("top boundary", "Dirichlet"); |
| 64 |
RCP<Galeri::Xpetra::Problem<Map, CrsMatrixWrap, MultiVector>> Pr = Galeri::Xpetra:: |
| 65 |
BuildProblem<SC, LO, GO, Map, CrsMatrixWrap, MultiVector>("Laplace3D", fineCoords->getMap(), |
| 66 |
matrixList); |
| 67 |
RCP<Matrix> A = Pr->BuildMatrix(); |
| 68 |
|
| 69 |
LocalOrdinal NSdim = 1; |
| 70 |
RCP<MultiVector> nullSpace = MultiVectorFactory::Build(A->getRowMap(), NSdim); |
| 71 |
nullSpace->putScalar(1.0); |
| 72 |
|
| 73 |
fineLevel.Set("A", A); |
| 74 |
fineLevel.Set("Nullspace", nullSpace); |
| 75 |
fineLevel.Set("Coordinates", fineCoords); |
| 76 |
fineLevel.Set("CoarseNumZLayers", numSize); |
| 77 |
|
| 78 |
RCP<LineDetectionFactory> LineDetectionFact = rcp(new LineDetectionFactory()); |
| 79 |
LineDetectionFact->SetParameter("linedetection: orientation", |
| 80 |
Teuchos::ParameterEntry(std::string("coordinates"))); |
| 81 |
LineDetectionFact->SetParameter("linedetection: num layers", |
| 82 |
Teuchos::ParameterEntry(numSize)); |
| 83 |
|
| 84 |
RCP<SemiCoarsenPFactory_kokkos> SemiCoarsenPFact = rcp(new SemiCoarsenPFactory_kokkos()); |
| 85 |
SemiCoarsenPFact->SetParameter("semicoarsen: coarsen rate", Teuchos::ParameterEntry(2)); |
| 86 |
SemiCoarsenPFact->SetFactory("LineDetection_VertLineIds", LineDetectionFact); |
| 87 |
SemiCoarsenPFact->SetFactory("LineDetection_Layers", LineDetectionFact); |
| 88 |
SemiCoarsenPFact->SetFactory("CoarseNumZLayers", LineDetectionFact); |
| 89 |
coarseLevel.Request("P", SemiCoarsenPFact.get()); |
| 90 |
coarseLevel.Request("Coordinates", SemiCoarsenPFact.get()); |
| 91 |
SemiCoarsenPFact->Build(fineLevel, coarseLevel); |
| 92 |
|
| 93 |
RCP<Matrix> P; |
| 94 |
coarseLevel.Get("P", P, SemiCoarsenPFact.get()); |
| 95 |
RCP<CoordMV> coarseCoords = coarseLevel.Get<RCP<CoordMV>>("Coordinates", SemiCoarsenPFact.get()); |
| 96 |
|
| 97 |
coarseLevel.Release("P", SemiCoarsenPFact.get()); |
| 98 |
coarseLevel.Release("Coordinates", SemiCoarsenPFact.get()); |
| 99 |
|
| 100 |
// Prolongate coarse coords and compute difference |
| 101 |
using STS = Teuchos::ScalarTraits<SC>; |
| 102 |
const auto one = STS::one(); |
| 103 |
RCP<MultiVector> coarseCoordsSC = Utilities::RealValuedToScalarMultiVector(coarseCoords); |
| 104 |
RCP<MultiVector> fineCoordsDiff = Utilities::RealValuedToScalarMultiVector(fineCoords); |
| 105 |
P->apply(*coarseCoordsSC, *fineCoordsDiff, Teuchos::NO_TRANS, one, -one); |
| 106 |
|
| 107 |
// check prolongation of coarse coordinates |
| 108 |
// in this special case, the third layer will have the correct coordinates |
| 109 |
using impl_SC = typename Kokkos::ArithTraits<SC>::val_type; |
| 110 |
using impl_ATS = Kokkos::ArithTraits<impl_SC>; |
| 111 |
const auto fineCoordsDiffView = fineCoordsDiff->getDeviceLocalView(Xpetra::Access::ReadOnly); |
| 112 |
const int numNodes = fineCoordsDiff->getLocalLength(); |
| 113 |
const int numVectors = fineCoordsDiff->getNumVectors(); |
| 114 |
const auto fineMap = fineCoordsDiff->getMap()->getLocalMap(); |
| 115 |
const GO gStartLayer3 = 2 * numSize * numSize; |
| 116 |
const GO gEndLayer3 = 3 * numSize * numSize; |
| 117 |
using range_policy = Kokkos::RangePolicy<LO, typename SemiCoarsenPFactory_kokkos::execution_space>; |
| 118 |
LO numBadCoords = 0; |
| 119 |
Kokkos::parallel_reduce( |
| 120 |
"Checking zeros on third layer", |
| 121 |
range_policy(0, numNodes), KOKKOS_LAMBDA(const LO node, LO& lNumBadCoords) { |
| 122 |
const GO gnode = fineMap.getGlobalElement(node); |
| 123 |
if (gnode >= gStartLayer3 && gnode < gEndLayer3) |
| 124 |
for (int k = 0; k < numVectors; ++k) |
| 125 |
if (impl_ATS::magnitude(fineCoordsDiffView(node, k)) > 100 * impl_ATS::eps()) |
| 126 |
lNumBadCoords += 1; |
| 127 |
}, |
| 128 |
numBadCoords); |
| 129 |
LO gNumBadCoords; |
| 130 |
const auto comm = Teuchos::DefaultComm<int>::getComm(); |
| 131 |
Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, 1, &numBadCoords, &gNumBadCoords); |
| 132 |
TEST_EQUALITY(gNumBadCoords, 0); |
| 133 |
} |
| 134 |
|
| 135 |
#define MUELU_ETI_GROUP(SC, LO, GO, NO) \ |
| 136 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(SemiCoarsenPFactory_kokkos, TestSemiCoarsenP, SC, LO, GO, NO) |
| 137 |
|
| 138 |
#include <MueLu_ETI_4arg.hpp> |
| 139 |
|
| 140 |
} // namespace MueLuTests |