| 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 <Teuchos_DefaultComm.hpp> |
| 12 |
|
| 13 |
#include <Xpetra_MultiVector.hpp> |
| 14 |
#include <Xpetra_Matrix.hpp> |
| 15 |
|
| 16 |
#include "MueLu_TestHelpers_kokkos.hpp" |
| 17 |
#include "MueLu_Version.hpp" |
| 18 |
|
| 19 |
#include "MueLu_AmalgamationFactory.hpp" |
| 20 |
#include "MueLu_CoalesceDropFactory_kokkos.hpp" |
| 21 |
#include "MueLu_CoarseMapFactory.hpp" |
| 22 |
#include "MueLu_TentativePFactory_kokkos.hpp" |
| 23 |
#include "MueLu_MatrixFreeTentativePFactory.hpp" |
| 24 |
#include "MueLu_UncoupledAggregationFactory.hpp" |
| 25 |
#include "MueLu_NullspaceFactory.hpp" |
| 26 |
|
| 27 |
namespace MueLuTests { |
| 28 |
|
| 29 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(MatrixFreeTentativePFactory, Constructor, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 30 |
#include "MueLu_UseShortNames.hpp" |
| 31 |
MUELU_TESTING_SET_OSTREAM; |
| 32 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO); |
| 33 |
if (TestHelpers_kokkos::Parameters::getLib() == Xpetra::UseEpetra) { |
| 34 |
out << "skipping test for linAlgebra==UseEpetra" << std::endl; |
| 35 |
return; |
| 36 |
} |
| 37 |
out << "version: " << MueLu::Version() << std::endl; |
| 38 |
|
| 39 |
RCP<MatrixFreeTentativePFactory> MFtentPFact = rcp(new MatrixFreeTentativePFactory); |
| 40 |
TEST_EQUALITY(MFtentPFact != Teuchos::null, true); |
| 41 |
} |
| 42 |
|
| 43 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(MatrixFreeTentativePFactory, MakeTentative, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 44 |
#include "MueLu_UseShortNames.hpp" |
| 45 |
MUELU_TESTING_SET_OSTREAM; |
| 46 |
MUELU_TESTING_LIMIT_SCOPE(SC, GO, NO); |
| 47 |
|
| 48 |
using STS = Teuchos::ScalarTraits<Scalar>; |
| 49 |
using magnitude_type = typename Teuchos::ScalarTraits<Scalar>::magnitudeType; |
| 50 |
using TMT = Teuchos::ScalarTraits<magnitude_type>; |
| 51 |
|
| 52 |
if (TestHelpers_kokkos::Parameters::getLib() == Xpetra::UseEpetra) { |
| 53 |
out << "skipping test for linAlgebra==UseEpetra" << std::endl; |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); |
| 58 |
|
| 59 |
out << "version: " << MueLu::Version() << std::endl; |
| 60 |
out << "Test with user-supplied nullspace" << std::endl; |
| 61 |
|
| 62 |
Level fineLevel, coarseLevel; |
| 63 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createTwoLevelHierarchy(fineLevel, coarseLevel); |
| 64 |
|
| 65 |
fineLevel.SetFactoryManager(Teuchos::null); // factory manager is not used on this test |
| 66 |
coarseLevel.SetFactoryManager(Teuchos::null); |
| 67 |
|
| 68 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(199); |
| 69 |
fineLevel.Request("A"); |
| 70 |
fineLevel.Set("A", A); |
| 71 |
|
| 72 |
// Only one NS vector -> exercises manual orthogonalization |
| 73 |
LO NSdim = 1; |
| 74 |
RCP<MultiVector> nullSpace = MultiVectorFactory::Build(A->getRowMap(), NSdim); |
| 75 |
nullSpace->putScalar(1.0); |
| 76 |
fineLevel.Set("Nullspace", nullSpace); |
| 77 |
|
| 78 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 79 |
|
| 80 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 81 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 82 |
|
| 83 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 84 |
ParameterList aggParams; |
| 85 |
aggParams.set("aggregation: ordering", "natural"); |
| 86 |
aggParams.set("aggregation: deterministic", true); |
| 87 |
aggParams.set("aggregation: min agg size", 3); |
| 88 |
aggParams.set("aggregation: max selected neighbors", 0); |
| 89 |
aggFact->SetParameterList(aggParams); |
| 90 |
aggFact->SetFactory("DofsPerNode", dropFact); |
| 91 |
aggFact->SetFactory("Graph", dropFact); |
| 92 |
|
| 93 |
RCP<CoarseMapFactory> coarseMapFact = rcp(new CoarseMapFactory()); |
| 94 |
coarseMapFact->SetFactory("Aggregates", aggFact); |
| 95 |
|
| 96 |
RCP<MatrixFreeTentativePFactory> MFTentativePFact = rcp(new MatrixFreeTentativePFactory()); |
| 97 |
MFTentativePFact->SetFactory("Aggregates", aggFact); |
| 98 |
MFTentativePFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 99 |
MFTentativePFact->SetFactory("CoarseMap", coarseMapFact); |
| 100 |
|
| 101 |
coarseLevel.Request("P", MFTentativePFact.get()); // request Ptent |
| 102 |
coarseLevel.Request("Nullspace", MFTentativePFact.get()); |
| 103 |
coarseLevel.Request(*MFTentativePFact); |
| 104 |
MFTentativePFact->Build(fineLevel, coarseLevel); |
| 105 |
|
| 106 |
RCP<Operator> Ptent; |
| 107 |
coarseLevel.Get("P", Ptent, MFTentativePFact.get()); |
| 108 |
|
| 109 |
RCP<MultiVector> coarseNullspace = coarseLevel.Get<RCP<MultiVector> >("Nullspace", MFTentativePFact.get()); |
| 110 |
|
| 111 |
// Check interpolation by computing ||fineNS - P*coarseNS|| |
| 112 |
// PtN = P*coarseNS |
| 113 |
RCP<MultiVector> PtN = MultiVectorFactory::Build(Ptent->getRangeMap(), NSdim); |
| 114 |
Ptent->apply(*coarseNullspace, *PtN, Teuchos::NO_TRANS, 1.0, 0.0); |
| 115 |
|
| 116 |
RCP<MultiVector> diff = MultiVectorFactory::Build(A->getRowMap(), NSdim); |
| 117 |
diff->putScalar(0.0); |
| 118 |
|
| 119 |
coarseLevel.Release("P", MFTentativePFact.get()); // release Ptent |
| 120 |
coarseLevel.Release("Nullspace", MFTentativePFact.get()); |
| 121 |
|
| 122 |
// diff = fineNS - PtN = fineNS - P*coarseNS |
| 123 |
diff->update(1.0, *nullSpace, -1.0, *PtN, 0.0); |
| 124 |
|
| 125 |
Array<typename Teuchos::ScalarTraits<SC>::magnitudeType> norms(NSdim); |
| 126 |
diff->norm2(norms); |
| 127 |
for (LO i = 0; i < NSdim; ++i) { |
| 128 |
out << "||diff_" << i << "||_2 = " << norms[i] << std::endl; |
| 129 |
TEST_COMPARE_CONST(norms[i], <, 100 * TMT::eps()); |
| 130 |
} |
| 131 |
|
| 132 |
} // MakeTentative |
| 133 |
|
| 134 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(MatrixFreeTentativePFactory, MakeTentativeVectorBasedUsingDefaultNullspace, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 135 |
#include "MueLu_UseShortNames.hpp" |
| 136 |
MUELU_TESTING_SET_OSTREAM; |
| 137 |
MUELU_TESTING_LIMIT_SCOPE(SC, GO, NO); |
| 138 |
|
| 139 |
using STS = Teuchos::ScalarTraits<Scalar>; |
| 140 |
using magnitude_type = typename Teuchos::ScalarTraits<Scalar>::magnitudeType; |
| 141 |
using TMT = Teuchos::ScalarTraits<magnitude_type>; |
| 142 |
|
| 143 |
if (TestHelpers_kokkos::Parameters::getLib() == Xpetra::UseEpetra) { |
| 144 |
out << "skipping test for linAlgebra==UseEpetra" << std::endl; |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
out << "version: " << MueLu::Version() << std::endl; |
| 149 |
out << "Test when nullspace isn't supplied by user" << std::endl; |
| 150 |
|
| 151 |
Level fineLevel, coarseLevel; |
| 152 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createTwoLevelHierarchy(fineLevel, coarseLevel); |
| 153 |
|
| 154 |
auto A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(200); |
| 155 |
|
| 156 |
A->SetFixedBlockSize(2); |
| 157 |
|
| 158 |
fineLevel.Set("A", A); |
| 159 |
|
| 160 |
auto amalgFact = rcp(new AmalgamationFactory()); |
| 161 |
|
| 162 |
auto dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 163 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 164 |
|
| 165 |
auto aggFact = rcp(new UncoupledAggregationFactory()); |
| 166 |
ParameterList aggParams; |
| 167 |
aggParams.set("aggregation: ordering", "natural"); |
| 168 |
aggParams.set("aggregation: deterministic", true); |
| 169 |
aggParams.set("aggregation: min agg size", 3); |
| 170 |
aggParams.set("aggregation: max selected neighbors", 0); |
| 171 |
aggFact->SetParameterList(aggParams); |
| 172 |
aggFact->SetFactory("DofsPerNode", dropFact); |
| 173 |
aggFact->SetFactory("Graph", dropFact); |
| 174 |
|
| 175 |
auto coarseMapFact = rcp(new CoarseMapFactory()); |
| 176 |
coarseMapFact->SetFactory("Aggregates", aggFact); |
| 177 |
|
| 178 |
auto MFTentativePFact = rcp(new MatrixFreeTentativePFactory()); |
| 179 |
MFTentativePFact->SetFactory("Aggregates", aggFact); |
| 180 |
MFTentativePFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 181 |
MFTentativePFact->SetFactory("CoarseMap", coarseMapFact); |
| 182 |
|
| 183 |
coarseLevel.Request("P", MFTentativePFact.get()); // request Ptent |
| 184 |
coarseLevel.Request("Nullspace", MFTentativePFact.get()); // request coarse nullspace |
| 185 |
coarseLevel.Request(*MFTentativePFact); |
| 186 |
MFTentativePFact->Build(fineLevel, coarseLevel); |
| 187 |
|
| 188 |
RCP<Operator> Ptent; |
| 189 |
coarseLevel.Get("P", Ptent, MFTentativePFact.get()); |
| 190 |
|
| 191 |
auto coarseNullspace = coarseLevel.Get<RCP<MultiVector> >("Nullspace", MFTentativePFact.get()); |
| 192 |
|
| 193 |
size_t NSdim = coarseNullspace->getNumVectors(); |
| 194 |
TEST_EQUALITY(NSdim, 2); |
| 195 |
|
| 196 |
// coarseNullspace->describe(out, Teuchos::VERB_EXTREME); |
| 197 |
|
| 198 |
// Check interpolation by computing ||fineNS - P*coarseNS|| |
| 199 |
auto PtN = MultiVectorFactory::Build(Ptent->getRangeMap(), NSdim); |
| 200 |
// Ptent->apply(*coarseNullspace, *PtN, Teuchos::NO_TRANS, 1.0, 0.0); // TODO: don't support strides :) |
| 201 |
|
| 202 |
auto diff = MultiVectorFactory::Build(A->getRowMap(), NSdim); |
| 203 |
diff->putScalar(0.0); |
| 204 |
|
| 205 |
coarseLevel.Release("P", MFTentativePFact.get()); // release Ptent |
| 206 |
coarseLevel.Release("Nullspace", MFTentativePFact.get()); |
| 207 |
|
| 208 |
auto nspFact = Teuchos::rcp(new NullspaceFactory()); |
| 209 |
fineLevel.Request("Nullspace", nspFact.get()); |
| 210 |
|
| 211 |
nspFact->Build(fineLevel); |
| 212 |
|
| 213 |
auto fineNullspace = fineLevel.Get<RCP<MultiVector> >("Nullspace", nspFact.get()); |
| 214 |
|
| 215 |
TEST_EQUALITY(fineNullspace->getNumVectors(), 2); |
| 216 |
|
| 217 |
// diff = fineNS - (P*coarseNS) |
| 218 |
diff->update(1.0, *fineNullspace, -1.0, *PtN, 0.0); |
| 219 |
|
| 220 |
Array<magnitude_type> norms(NSdim); |
| 221 |
diff->norm2(norms); |
| 222 |
// for (decltype(NSdim) i = 0; i < NSdim; ++i) |
| 223 |
// TEST_COMPARE_CONST(norms[i], <, 100*TMT::eps()); |
| 224 |
} |
| 225 |
|
| 226 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(MatrixFreeTentativePFactory, MakeTentativeUsingDefaultNullspace, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 227 |
#include "MueLu_UseShortNames.hpp" |
| 228 |
MUELU_TESTING_SET_OSTREAM; |
| 229 |
MUELU_TESTING_LIMIT_SCOPE(SC, GO, NO); |
| 230 |
|
| 231 |
using STS = Teuchos::ScalarTraits<Scalar>; |
| 232 |
using magnitude_type = typename Teuchos::ScalarTraits<Scalar>::magnitudeType; |
| 233 |
using TMT = Teuchos::ScalarTraits<magnitude_type>; |
| 234 |
|
| 235 |
if (TestHelpers_kokkos::Parameters::getLib() == Xpetra::UseEpetra) { |
| 236 |
out << "skipping test for linAlgebra==UseEpetra" << std::endl; |
| 237 |
return; |
| 238 |
} |
| 239 |
|
| 240 |
out << "version: " << MueLu::Version() << std::endl; |
| 241 |
out << "Test when nullspace isn't supplied by user" << std::endl; |
| 242 |
|
| 243 |
Level fineLevel, coarseLevel; |
| 244 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createTwoLevelHierarchy(fineLevel, coarseLevel); |
| 245 |
|
| 246 |
auto A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(199); |
| 247 |
|
| 248 |
fineLevel.Set("A", A); |
| 249 |
|
| 250 |
auto amalgFact = rcp(new AmalgamationFactory()); |
| 251 |
|
| 252 |
auto dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 253 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 254 |
|
| 255 |
auto aggFact = rcp(new UncoupledAggregationFactory()); |
| 256 |
ParameterList aggParams; |
| 257 |
aggParams.set("aggregation: ordering", "natural"); |
| 258 |
aggParams.set("aggregation: deterministic", true); |
| 259 |
aggParams.set("aggregation: min agg size", 3); |
| 260 |
aggParams.set("aggregation: max selected neighbors", 0); |
| 261 |
aggFact->SetParameterList(aggParams); |
| 262 |
aggFact->SetFactory("DofsPerNode", dropFact); |
| 263 |
aggFact->SetFactory("Graph", dropFact); |
| 264 |
|
| 265 |
auto coarseMapFact = rcp(new CoarseMapFactory()); |
| 266 |
coarseMapFact->SetFactory("Aggregates", aggFact); |
| 267 |
|
| 268 |
auto MFTentativePFact = rcp(new MatrixFreeTentativePFactory()); |
| 269 |
MFTentativePFact->SetFactory("Aggregates", aggFact); |
| 270 |
MFTentativePFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 271 |
MFTentativePFact->SetFactory("CoarseMap", coarseMapFact); |
| 272 |
|
| 273 |
coarseLevel.Request("P", MFTentativePFact.get()); // request Ptent |
| 274 |
coarseLevel.Request("Nullspace", MFTentativePFact.get()); // request coarse nullspace |
| 275 |
coarseLevel.Request(*MFTentativePFact); |
| 276 |
MFTentativePFact->Build(fineLevel, coarseLevel); |
| 277 |
|
| 278 |
RCP<Operator> Ptent; |
| 279 |
coarseLevel.Get("P", Ptent, MFTentativePFact.get()); |
| 280 |
|
| 281 |
auto coarseNullspace = coarseLevel.Get<RCP<MultiVector> >("Nullspace", MFTentativePFact.get()); |
| 282 |
|
| 283 |
coarseLevel.Release("P", MFTentativePFact.get()); // release Ptent |
| 284 |
coarseLevel.Release("Nullspace", MFTentativePFact.get()); // release coarse nullspace |
| 285 |
|
| 286 |
// grab default fine level nullspace (vector of all ones) |
| 287 |
auto nullSpace = MultiVectorFactory::Build(A->getRowMap(), 1); |
| 288 |
nullSpace->putScalar(1.0); |
| 289 |
|
| 290 |
// check interpolation |
| 291 |
LO NSdim = 1; |
| 292 |
auto PtN = MultiVectorFactory::Build(A->getRowMap(), NSdim); |
| 293 |
Ptent->apply(*coarseNullspace, *PtN, Teuchos::NO_TRANS, 1.0, 0.0); |
| 294 |
|
| 295 |
auto diff = MultiVectorFactory::Build(A->getRowMap(), NSdim); |
| 296 |
diff->putScalar(0.0); |
| 297 |
|
| 298 |
// diff = fineNS + (-1.0)*(P*coarseNS) + 0*diff |
| 299 |
diff->update(1.0, *nullSpace, -1.0, *PtN, 0.0); |
| 300 |
|
| 301 |
Teuchos::Array<magnitude_type> norms(NSdim); |
| 302 |
diff->norm2(norms); |
| 303 |
for (LO i = 0; i < NSdim; ++i) |
| 304 |
TEST_COMPARE_CONST(norms[i], <, 100 * TMT::eps()); |
| 305 |
|
| 306 |
} // MakeTentativeUsingDefaultNullspace |
| 307 |
|
| 308 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(MatrixFreeTentativePFactory, MatrixVsMatrixFree, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 309 |
#include "MueLu_UseShortNames.hpp" |
| 310 |
MUELU_TESTING_SET_OSTREAM; |
| 311 |
MUELU_TESTING_LIMIT_SCOPE(SC, GO, NO); |
| 312 |
|
| 313 |
using STS = Teuchos::ScalarTraits<Scalar>; |
| 314 |
using magnitude_type = typename Teuchos::ScalarTraits<Scalar>::magnitudeType; |
| 315 |
using TMT = Teuchos::ScalarTraits<magnitude_type>; |
| 316 |
|
| 317 |
if (TestHelpers_kokkos::Parameters::getLib() == Xpetra::UseEpetra) { |
| 318 |
out << "skipping test for linAlgebra==UseEpetra" << std::endl; |
| 319 |
return; |
| 320 |
} |
| 321 |
|
| 322 |
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); |
| 323 |
|
| 324 |
out << "version: " << MueLu::Version() << std::endl; |
| 325 |
out << "Test matvec speed in matrix and matrix-free versions and compare results" << std::endl; |
| 326 |
|
| 327 |
unsigned int numMatVecs = 100; |
| 328 |
|
| 329 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(199); |
| 330 |
RCP<MultiVector> X = MultiVectorFactory::Build(A->getDomainMap(), 1); |
| 331 |
RCP<MultiVector> Xcoarse; |
| 332 |
RCP<MultiVector> MFXcoarse; |
| 333 |
RCP<MultiVector> diff; |
| 334 |
X->randomize(); |
| 335 |
|
| 336 |
// Matrix version |
| 337 |
{ |
| 338 |
Level fineLevel, coarseLevel; |
| 339 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createTwoLevelHierarchy(fineLevel, coarseLevel); |
| 340 |
|
| 341 |
fineLevel.SetFactoryManager(Teuchos::null); // factory manager is not used on this test |
| 342 |
coarseLevel.SetFactoryManager(Teuchos::null); |
| 343 |
fineLevel.Request("A"); |
| 344 |
fineLevel.Set("A", A); |
| 345 |
|
| 346 |
// Only one NS vector -> exercises manual orthogonalization |
| 347 |
LO NSdim = 1; |
| 348 |
RCP<MultiVector> nullSpace = MultiVectorFactory::Build(A->getRowMap(), NSdim); |
| 349 |
nullSpace->putScalar(1.0); |
| 350 |
fineLevel.Set("Nullspace", nullSpace); |
| 351 |
|
| 352 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 353 |
|
| 354 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 355 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 356 |
|
| 357 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 358 |
ParameterList aggParams; |
| 359 |
aggParams.set("aggregation: ordering", "natural"); |
| 360 |
aggParams.set("aggregation: deterministic", true); |
| 361 |
aggParams.set("aggregation: min agg size", 3); |
| 362 |
aggParams.set("aggregation: max selected neighbors", 0); |
| 363 |
aggFact->SetParameterList(aggParams); |
| 364 |
aggFact->SetFactory("DofsPerNode", dropFact); |
| 365 |
aggFact->SetFactory("Graph", dropFact); |
| 366 |
|
| 367 |
RCP<CoarseMapFactory> coarseMapFact = rcp(new CoarseMapFactory()); |
| 368 |
coarseMapFact->SetFactory("Aggregates", aggFact); |
| 369 |
|
| 370 |
RCP<TentativePFactory_kokkos> TentativePFact = rcp(new TentativePFactory_kokkos()); |
| 371 |
TentativePFact->SetFactory("Aggregates", aggFact); |
| 372 |
TentativePFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 373 |
TentativePFact->SetFactory("CoarseMap", coarseMapFact); |
| 374 |
|
| 375 |
coarseLevel.Request("P", TentativePFact.get()); // request Ptent |
| 376 |
coarseLevel.Request("Nullspace", TentativePFact.get()); |
| 377 |
coarseLevel.Request(*TentativePFact); |
| 378 |
TentativePFact->Build(fineLevel, coarseLevel); |
| 379 |
|
| 380 |
RCP<Matrix> Ptent; |
| 381 |
coarseLevel.Get("P", Ptent, TentativePFact.get()); |
| 382 |
Xcoarse = MultiVectorFactory::Build(Ptent->getDomainMap(), 1); |
| 383 |
Ptent->apply(*X, *Xcoarse, Teuchos::TRANS); |
| 384 |
|
| 385 |
RCP<MultiVector> coarseNullspace = coarseLevel.Get<RCP<MultiVector> >("Nullspace", TentativePFact.get()); |
| 386 |
RCP<MultiVector> PtN = MultiVectorFactory::Build(Ptent->getRangeMap(), NSdim); |
| 387 |
|
| 388 |
// warm-up apply operations |
| 389 |
for (unsigned int i = 0; i < 5; ++i) |
| 390 |
Ptent->apply(*coarseNullspace, *PtN, Teuchos::NO_TRANS, 1.0, 0.0); |
| 391 |
|
| 392 |
{ |
| 393 |
RCP<Teuchos::TimeMonitor> tm = rcp(new Teuchos::TimeMonitor(*Teuchos::TimeMonitor::getNewTimer("MatVec original"))); |
| 394 |
for (unsigned int i = 0; i < numMatVecs; ++i) |
| 395 |
Ptent->apply(*coarseNullspace, *PtN, Teuchos::NO_TRANS, 1.0, 0.0); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
// Matrix-free version |
| 400 |
{ |
| 401 |
Level fineLevel, coarseLevel; |
| 402 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createTwoLevelHierarchy(fineLevel, coarseLevel); |
| 403 |
|
| 404 |
fineLevel.SetFactoryManager(Teuchos::null); // factory manager is not used on this test |
| 405 |
coarseLevel.SetFactoryManager(Teuchos::null); |
| 406 |
fineLevel.Request("A"); |
| 407 |
fineLevel.Set("A", A); |
| 408 |
|
| 409 |
// Only one NS vector -> exercises manual orthogonalization |
| 410 |
LO NSdim = 1; |
| 411 |
RCP<MultiVector> nullSpace = MultiVectorFactory::Build(A->getRowMap(), NSdim); |
| 412 |
nullSpace->putScalar(1.0); |
| 413 |
fineLevel.Set("Nullspace", nullSpace); |
| 414 |
|
| 415 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 416 |
|
| 417 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 418 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 419 |
|
| 420 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 421 |
ParameterList aggParams; |
| 422 |
aggParams.set("aggregation: ordering", "natural"); |
| 423 |
aggParams.set("aggregation: deterministic", true); |
| 424 |
aggParams.set("aggregation: min agg size", 3); |
| 425 |
aggParams.set("aggregation: max selected neighbors", 0); |
| 426 |
aggFact->SetParameterList(aggParams); |
| 427 |
aggFact->SetFactory("DofsPerNode", dropFact); |
| 428 |
aggFact->SetFactory("Graph", dropFact); |
| 429 |
|
| 430 |
RCP<CoarseMapFactory> coarseMapFact = rcp(new CoarseMapFactory()); |
| 431 |
coarseMapFact->SetFactory("Aggregates", aggFact); |
| 432 |
|
| 433 |
RCP<MatrixFreeTentativePFactory> MFTentativePFact = rcp(new MatrixFreeTentativePFactory()); |
| 434 |
MFTentativePFact->SetFactory("Aggregates", aggFact); |
| 435 |
MFTentativePFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 436 |
MFTentativePFact->SetFactory("CoarseMap", coarseMapFact); |
| 437 |
|
| 438 |
coarseLevel.Request("P", MFTentativePFact.get()); // request Ptent |
| 439 |
coarseLevel.Request("Nullspace", MFTentativePFact.get()); |
| 440 |
coarseLevel.Request(*MFTentativePFact); |
| 441 |
MFTentativePFact->Build(fineLevel, coarseLevel); |
| 442 |
|
| 443 |
RCP<Operator> MFPtent; |
| 444 |
coarseLevel.Get("P", MFPtent, MFTentativePFact.get()); |
| 445 |
MFXcoarse = MultiVectorFactory::Build(MFPtent->getDomainMap(), 1); |
| 446 |
MFPtent->apply(*X, *MFXcoarse, Teuchos::TRANS); |
| 447 |
|
| 448 |
RCP<MultiVector> coarseNullspace = coarseLevel.Get<RCP<MultiVector> >("Nullspace", MFTentativePFact.get()); |
| 449 |
RCP<MultiVector> PtN = MultiVectorFactory::Build(MFPtent->getRangeMap(), NSdim); |
| 450 |
// warm-up apply operations |
| 451 |
for (unsigned int i = 0; i < 5; ++i) |
| 452 |
MFPtent->apply(*coarseNullspace, *PtN, Teuchos::NO_TRANS, 1.0, 0.0); |
| 453 |
|
| 454 |
{ |
| 455 |
RCP<Teuchos::TimeMonitor> tm = rcp(new Teuchos::TimeMonitor(*Teuchos::TimeMonitor::getNewTimer("MatVec matrix-free"))); |
| 456 |
for (unsigned int i = 0; i < numMatVecs; ++i) |
| 457 |
MFPtent->apply(*coarseNullspace, *PtN, Teuchos::NO_TRANS, 1.0, 0.0); |
| 458 |
} |
| 459 |
|
| 460 |
// need scope |
| 461 |
diff = MultiVectorFactory::Build(MFPtent->getDomainMap(), 1); |
| 462 |
diff->putScalar(0.0); |
| 463 |
} |
| 464 |
|
| 465 |
Teuchos::TimeMonitor::summarize(A->getRowMap()->getComm().ptr(), std::cout, false, true, false, Teuchos::Union, "", true); |
| 466 |
Teuchos::TimeMonitor::zeroOutTimers(); |
| 467 |
|
| 468 |
// Compare Xcoarse and MFXcoarse (diff = Xcoarse - MFXcoarse + 0*diff) |
| 469 |
diff->update(1.0, *Xcoarse, -1.0, *MFXcoarse, 0.0); |
| 470 |
Array<typename Teuchos::ScalarTraits<SC>::magnitudeType> norms(1); |
| 471 |
diff->norm2(norms); |
| 472 |
out << "||diff||_2 = " << norms[0] << std::endl; |
| 473 |
TEST_COMPARE_CONST(norms[0], <, 100 * TMT::eps()); |
| 474 |
|
| 475 |
} // MatrixVsMatrixFree |
| 476 |
|
| 477 |
#define MUELU_ETI_GROUP(SC, LO, GO, NO) \ |
| 478 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(MatrixFreeTentativePFactory, Constructor, SC, LO, GO, NO) \ |
| 479 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(MatrixFreeTentativePFactory, MakeTentative, SC, LO, GO, NO) \ |
| 480 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(MatrixFreeTentativePFactory, MakeTentativeUsingDefaultNullspace, SC, LO, GO, NO) \ |
| 481 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(MatrixFreeTentativePFactory, MatrixVsMatrixFree, SC, LO, GO, NO) |
| 482 |
|
| 483 |
#include <MueLu_ETI_4arg.hpp> |
| 484 |
|
| 485 |
} // namespace MueLuTests |