| 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_Matrix.hpp> |
| 14 |
#include <Xpetra_MultiVectorFactory.hpp> |
| 15 |
#include <Xpetra_Vector.hpp> |
| 16 |
#include <Xpetra_IteratorOps.hpp> |
| 17 |
#include <Xpetra_IO.hpp> |
| 18 |
|
| 19 |
#include "MueLu_TestHelpers_kokkos.hpp" |
| 20 |
#include "MueLu_Version.hpp" |
| 21 |
|
| 22 |
#include "MueLu_SaPFactory.hpp" |
| 23 |
#include "MueLu_Utilities.hpp" |
| 24 |
|
| 25 |
#include "MueLu_UseDefaultTypes.hpp" |
| 26 |
|
| 27 |
namespace MueLuTests { |
| 28 |
|
| 29 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(SaPFactory_kokkos, Constructor, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 30 |
#include "MueLu_UseShortNames.hpp" |
| 31 |
MUELU_TESTING_SET_OSTREAM; |
| 32 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 33 |
out << "version: " << MueLu::Version() << std::endl; |
| 34 |
|
| 35 |
RCP<SaPFactory> sapFactory = rcp(new SaPFactory); |
| 36 |
TEST_EQUALITY(sapFactory != Teuchos::null, true); |
| 37 |
|
| 38 |
out << *sapFactory << std::endl; |
| 39 |
} |
| 40 |
|
| 41 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(SaPFactory_kokkos, Build, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 42 |
#include "MueLu_UseShortNames.hpp" |
| 43 |
MUELU_TESTING_SET_OSTREAM; |
| 44 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 45 |
out << "version: " << MueLu::Version() << std::endl; |
| 46 |
|
| 47 |
RCP<const Teuchos::Comm<int>> comm = Teuchos::DefaultComm<int>::getComm(); |
| 48 |
|
| 49 |
// construct two levels |
| 50 |
Level fineLevel, coarseLevel; |
| 51 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createTwoLevelHierarchy(fineLevel, coarseLevel); |
| 52 |
|
| 53 |
// construct matrices |
| 54 |
const typename Teuchos::ScalarTraits<Scalar>::magnitudeType lambdaMax = 5; |
| 55 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build2DPoisson(27 * comm->getSize()); |
| 56 |
A->SetMaxEigenvalueEstimate(lambdaMax); |
| 57 |
RCP<Matrix> Ptent = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build2DPoisson(27 * comm->getSize()); |
| 58 |
|
| 59 |
// set level matrices |
| 60 |
fineLevel.Set("A", A); |
| 61 |
coarseLevel.Set("P", Ptent); |
| 62 |
|
| 63 |
// construct the factory to be tested |
| 64 |
const double dampingFactor = 0.5; |
| 65 |
RCP<SaPFactory> sapFactory = rcp(new SaPFactory); |
| 66 |
ParameterList Pparams; |
| 67 |
Pparams.set("sa: damping factor", dampingFactor); |
| 68 |
Pparams.set("use kokkos refactor", true); |
| 69 |
sapFactory->SetParameterList(Pparams); |
| 70 |
sapFactory->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 71 |
sapFactory->SetFactory("P", MueLu::NoFactory::getRCP()); |
| 72 |
|
| 73 |
// build the data |
| 74 |
coarseLevel.Request("P", sapFactory.get()); |
| 75 |
sapFactory->Build(fineLevel, coarseLevel); |
| 76 |
|
| 77 |
// fetch the data |
| 78 |
RCP<Matrix> Pfact = coarseLevel.Get<RCP<Matrix>>("P", sapFactory.get()); |
| 79 |
|
| 80 |
// construct the data to compare |
| 81 |
SC omega = dampingFactor / lambdaMax; |
| 82 |
RCP<Vector> invDiag = Utilities::GetMatrixDiagonalInverse(*A); |
| 83 |
RCP<ParameterList> APparams = rcp(new ParameterList); |
| 84 |
RCP<Matrix> Ptest = Xpetra::IteratorOps<SC, LO, GO, NO>::Jacobi(omega, *invDiag, *A, *Ptent, Teuchos::null, out, "label", APparams); |
| 85 |
|
| 86 |
// compare matrices by multiplying them by a random vector |
| 87 |
RCP<MultiVector> X = MultiVectorFactory::Build(A->getDomainMap(), 1); |
| 88 |
X->setSeed(846930886); |
| 89 |
X->randomize(); |
| 90 |
|
| 91 |
RCP<MultiVector> Bfact = MultiVectorFactory::Build(A->getRangeMap(), 1); |
| 92 |
RCP<MultiVector> Btest = MultiVectorFactory::Build(A->getRangeMap(), 1); |
| 93 |
|
| 94 |
typedef Teuchos::ScalarTraits<SC> STS; |
| 95 |
SC zero = STS::zero(), one = STS::one(); |
| 96 |
|
| 97 |
Pfact->apply(*X, *Bfact, Teuchos::NO_TRANS, one, zero); |
| 98 |
Ptest->apply(*X, *Btest, Teuchos::NO_TRANS, one, zero); |
| 99 |
Btest->update(-one, *Bfact, one); |
| 100 |
|
| 101 |
Array<typename STS::magnitudeType> norms(1); |
| 102 |
Btest->norm2(norms); |
| 103 |
out << "|| B_factory - B_test || = " << norms[0] << std::endl; |
| 104 |
TEST_EQUALITY(norms[0] < 1e-12, true); |
| 105 |
} |
| 106 |
|
| 107 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(SaPFactory_kokkos, EnforceConstraints, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 108 |
#include "MueLu_UseShortNames.hpp" |
| 109 |
MUELU_TESTING_SET_OSTREAM; |
| 110 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 111 |
out << "version: " << MueLu::Version() << std::endl; |
| 112 |
|
| 113 |
typedef Teuchos::ScalarTraits<SC> STS; |
| 114 |
SC zero = STS::zero(), one = STS::one(); |
| 115 |
|
| 116 |
RCP<const Teuchos::Comm<int>> comm = Teuchos::DefaultComm<int>::getComm(); |
| 117 |
|
| 118 |
// construct two levels |
| 119 |
Level fineLevel, coarseLevel; |
| 120 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createTwoLevelHierarchy(fineLevel, coarseLevel); |
| 121 |
|
| 122 |
// construct matrices |
| 123 |
SC lambdaMax = 2; |
| 124 |
|
| 125 |
Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib(); |
| 126 |
Teuchos::ParameterList mp; |
| 127 |
mp.set("matrixType", "Star2D"); |
| 128 |
const GO nx = 6; |
| 129 |
mp.set("nx", nx); |
| 130 |
mp.set("ny", nx); |
| 131 |
mp.set("a", 2.0); |
| 132 |
mp.set("b", -1.0); |
| 133 |
mp.set("c", -1.0); |
| 134 |
mp.set("d", 0.5); |
| 135 |
mp.set("e", 0.5); |
| 136 |
mp.set("z1", -0.25); |
| 137 |
mp.set("z2", -0.25); |
| 138 |
mp.set("z3", -0.25); |
| 139 |
mp.set("z4", -0.25); |
| 140 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildMatrix(mp, lib); |
| 141 |
A->SetMaxEigenvalueEstimate(lambdaMax); |
| 142 |
mp.set("a", 1.0); |
| 143 |
mp.set("b", 1.0); |
| 144 |
mp.set("c", 1.0); |
| 145 |
mp.set("d", 1.0); |
| 146 |
mp.set("e", 1.0); |
| 147 |
mp.set("z1", 1.0); |
| 148 |
mp.set("z2", 1.0); |
| 149 |
mp.set("z3", 1.0); |
| 150 |
mp.set("z4", 1.0); |
| 151 |
RCP<Matrix> Ptent = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildMatrix(mp, lib); |
| 152 |
|
| 153 |
// set level matrices |
| 154 |
fineLevel.Set("A", A); |
| 155 |
coarseLevel.Set("P", Ptent); |
| 156 |
|
| 157 |
// construct the factory to be tested |
| 158 |
const double dampingFactor = 0.5; |
| 159 |
RCP<SaPFactory> sapFactory = rcp(new SaPFactory); |
| 160 |
ParameterList Pparams; |
| 161 |
Pparams.set("sa: damping factor", dampingFactor); |
| 162 |
Pparams.set("sa: enforce constraints", true); |
| 163 |
Pparams.set("sa: max eigenvalue", (double)2.0); |
| 164 |
Pparams.set("tentative: calculate qr", false); |
| 165 |
Pparams.set("use kokkos refactor", true); |
| 166 |
|
| 167 |
sapFactory->SetParameterList(Pparams); |
| 168 |
sapFactory->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 169 |
sapFactory->SetFactory("P", MueLu::NoFactory::getRCP()); |
| 170 |
|
| 171 |
// build the data |
| 172 |
coarseLevel.Request("P", sapFactory.get()); |
| 173 |
sapFactory->Build(fineLevel, coarseLevel); |
| 174 |
|
| 175 |
// fetch the data |
| 176 |
RCP<Matrix> Pfact = coarseLevel.Get<RCP<Matrix>>("P", sapFactory.get()); |
| 177 |
|
| 178 |
// check that row sums are all one by checking the norm of the vector |
| 179 |
RCP<MultiVector> X = MultiVectorFactory::Build(A->getDomainMap(), 1); |
| 180 |
RCP<MultiVector> Bfact = MultiVectorFactory::Build(A->getRangeMap(), 1); |
| 181 |
X->putScalar(one); |
| 182 |
Pfact->apply(*X, *Bfact, Teuchos::NO_TRANS, one, zero); |
| 183 |
Array<typename STS::magnitudeType> norms(1); |
| 184 |
Bfact->norm2(norms); |
| 185 |
out << "|| B_factory ones || = " << norms[0] << std::endl; |
| 186 |
using magnitude_type = typename Teuchos::ScalarTraits<Scalar>::magnitudeType; |
| 187 |
using TMT = Teuchos::ScalarTraits<magnitude_type>; |
| 188 |
TEST_FLOATING_EQUALITY(STS::magnitude(norms[0]), STS::magnitude(as<Scalar>(6.0)), 100 * TMT::eps()); |
| 189 |
} |
| 190 |
|
| 191 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(SaPFactory_kokkos, ConstrainRowOptimalScalarPDE, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 192 |
#include "MueLu_UseShortNames.hpp" |
| 193 |
MUELU_TESTING_SET_OSTREAM; |
| 194 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 195 |
out << "version: " << MueLu::Version() << std::endl; |
| 196 |
|
| 197 |
typedef Teuchos::ScalarTraits<SC> STS; |
| 198 |
SC zero = STS::zero(), one = STS::one(); |
| 199 |
|
| 200 |
RCP<const Teuchos::Comm<int>> comm = Teuchos::DefaultComm<int>::getComm(); |
| 201 |
|
| 202 |
// Don't test for complex - matrix reader won't work |
| 203 |
if (STS::isComplex) { |
| 204 |
success = true; |
| 205 |
return; |
| 206 |
} |
| 207 |
|
| 208 |
RCP<Matrix> P; |
| 209 |
Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib(); |
| 210 |
P = Xpetra::IO<SC, LO, GO, NO>::Read("../unit_tests/TestMatrices/SaP_constrainTest_P.mat", lib, comm); |
| 211 |
|
| 212 |
RCP<SaPFactory> sapFactory = rcp(new SaPFactory); |
| 213 |
ParameterList Pparams; |
| 214 |
Pparams.set("use kokkos refactor", true); |
| 215 |
sapFactory->SetParameterList(Pparams); |
| 216 |
sapFactory->optimalSatisfyPConstraintsForScalarPDEs(P); |
| 217 |
|
| 218 |
// check that row sums are all one by checking the norm of the vector |
| 219 |
// note: optimalSatisfyPConstraintsForScalarPDEs preserves row sum of original P (one in this case), |
| 220 |
// but SatisfyPConstraints normalizes each row sum to one. |
| 221 |
RCP<MultiVector> X = MultiVectorFactory::Build(P->getDomainMap(), 1); |
| 222 |
RCP<MultiVector> Bfact = MultiVectorFactory::Build(P->getRangeMap(), 1); |
| 223 |
X->putScalar(one); |
| 224 |
P->apply(*X, *Bfact, Teuchos::NO_TRANS, one, zero); |
| 225 |
Array<typename STS::magnitudeType> norms(1); |
| 226 |
Bfact->norm2(norms); |
| 227 |
out << "|| B_factory ones || = " << norms[0] << std::endl; |
| 228 |
using magnitude_type = typename Teuchos::ScalarTraits<Scalar>::magnitudeType; |
| 229 |
using TMT = Teuchos::ScalarTraits<magnitude_type>; |
| 230 |
TEST_FLOATING_EQUALITY(STS::magnitude(norms[0]), STS::magnitude(6.0), 100 * TMT::eps()); |
| 231 |
|
| 232 |
// check that the min and max of each row are in [0,1] |
| 233 |
bool lowerViolation = false; |
| 234 |
bool upperViolation = false; |
| 235 |
for (size_t j = 0; j < as<size_t>(P->getRowMap()->getLocalNumElements()); j++) { |
| 236 |
Teuchos::ArrayView<const LocalOrdinal> indices; |
| 237 |
Teuchos::ArrayView<const Scalar> vals; |
| 238 |
P->getLocalRowView((LocalOrdinal)j, indices, vals); |
| 239 |
size_t nnz = indices.size(); |
| 240 |
for (LO i = 0; i < (LO)nnz; i++) { |
| 241 |
if (Teuchos::ScalarTraits<SC>::real(vals[i]) < Teuchos::ScalarTraits<SC>::real(zero)) lowerViolation = true; |
| 242 |
if (Teuchos::ScalarTraits<SC>::real(vals[i]) > Teuchos::ScalarTraits<SC>::real(one)) upperViolation = true; |
| 243 |
} |
| 244 |
} |
| 245 |
TEST_EQUALITY(lowerViolation, false); |
| 246 |
TEST_EQUALITY(upperViolation, false); |
| 247 |
|
| 248 |
} // SaPFactory_ConstrainRowOptimalScalarPDE |
| 249 |
|
| 250 |
// FIXME_KOKKOS: uncomment the test when we get all corresponding factories ported to kokkos |
| 251 |
#if 0 |
| 252 |
#if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT) && defined(HAVE_MUELU_IFPACK) && defined(HAVE_MUELU_IFPACK2) |
| 253 |
TEUCHOS_UNIT_TEST(SaPFactory_kokkos, EpetraVsTpetra) |
| 254 |
{ |
| 255 |
#include "MueLu_UseShortNames.hpp" |
| 256 |
MueLu::VerboseObject::SetMueLuOStream(Teuchos::rcpFromRef(out)); |
| 257 |
|
| 258 |
out << "version: " << MueLu::Version() << std::endl; |
| 259 |
out << "Compare results of Epetra and Tpetra" << std::endl; |
| 260 |
out << "for 3 level AMG solver using smoothed aggregation with" << std::endl; |
| 261 |
out << "one SGS sweep on each multigrid level as pre- and postsmoother" << std::endl; |
| 262 |
|
| 263 |
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); |
| 264 |
|
| 265 |
typedef Teuchos::ScalarTraits<SC> STS; |
| 266 |
SC zero = STS::zero(), one = STS::one(); |
| 267 |
|
| 268 |
Array<STS::magnitudeType> results(2); |
| 269 |
|
| 270 |
// run test only on 1 proc |
| 271 |
if(comm->getSize() == 1) { |
| 272 |
Xpetra::UnderlyingLib lib = Xpetra::UseEpetra; |
| 273 |
|
| 274 |
// run Epetra and Tpetra test |
| 275 |
for (int run = 0; run < 2; run++) { //TODO: create a subfunction instead or Tuple of UnderlyingLib |
| 276 |
if (run == 0) lib = Xpetra::UseEpetra; |
| 277 |
else lib = Xpetra::UseTpetra; |
| 278 |
|
| 279 |
// generate problem |
| 280 |
LO maxLevels = 3; |
| 281 |
LO its = 10; |
| 282 |
GO nEle = 63; |
| 283 |
const RCP<const Map> map = MapFactory::Build(lib, nEle, 0, comm); |
| 284 |
Teuchos::ParameterList matrixParameters; |
| 285 |
matrixParameters.set("nx", nEle); |
| 286 |
|
| 287 |
RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr = |
| 288 |
Galeri::Xpetra::BuildProblem<SC,LO,GO,Map,CrsMatrixWrap,MultiVector>("Laplace1D", map, matrixParameters); |
| 289 |
RCP<Matrix> Op = Pr->BuildMatrix(); |
| 290 |
|
| 291 |
// build nullspace |
| 292 |
RCP<MultiVector> nullSpace = MultiVectorFactory::Build(map,1); |
| 293 |
nullSpace->putScalar(one); |
| 294 |
Array<STS::magnitudeType> norms(1); |
| 295 |
nullSpace->norm1(norms); |
| 296 |
if (comm->getRank() == 0) |
| 297 |
out << "||NS|| = " << norms[0] << std::endl; |
| 298 |
|
| 299 |
// fill hierarchy |
| 300 |
RCP<Hierarchy> H = rcp( new Hierarchy() ); |
| 301 |
H->setDefaultVerbLevel(Teuchos::VERB_HIGH); |
| 302 |
|
| 303 |
RCP<Level> Finest = H->GetLevel(); |
| 304 |
Finest->setDefaultVerbLevel(Teuchos::VERB_HIGH); |
| 305 |
Finest->Set("A",Op); // set fine level matrix |
| 306 |
Finest->Set("Nullspace",nullSpace); // set null space information for finest level |
| 307 |
|
| 308 |
// define transfer operators |
| 309 |
RCP<UncoupledAggregationFactory> UncoupledAggFact = rcp(new UncoupledAggregationFactory()); |
| 310 |
UncoupledAggFact->SetMinNodesPerAggregate(3); |
| 311 |
UncoupledAggFact->SetMaxNeighAlreadySelected(0); |
| 312 |
UncoupledAggFact->SetOrdering("natural"); |
| 313 |
|
| 314 |
RCP<TentativePFactory> Ptentfact = rcp(new TentativePFactory()); |
| 315 |
RCP<SaPFactory> Pfact = rcp( new SaPFactory()); |
| 316 |
RCP<Factory> Rfact = rcp( new TransPFactory() ); |
| 317 |
RCP<RAPFactory> Acfact = rcp( new RAPFactory() ); |
| 318 |
H->SetMaxCoarseSize(1); |
| 319 |
|
| 320 |
// setup smoothers |
| 321 |
Teuchos::ParameterList smootherParamList; |
| 322 |
smootherParamList.set("relaxation: type", "Symmetric Gauss-Seidel"); |
| 323 |
smootherParamList.set("relaxation: sweeps", (LO) 1); |
| 324 |
smootherParamList.set("relaxation: damping factor", (SC) 1.0); |
| 325 |
RCP<SmootherPrototype> smooProto = rcp( new TrilinosSmoother("RELAXATION", smootherParamList) ); |
| 326 |
RCP<SmootherFactory> SmooFact = rcp( new SmootherFactory(smooProto) ); |
| 327 |
Acfact->setVerbLevel(Teuchos::VERB_HIGH); |
| 328 |
|
| 329 |
RCP<SmootherFactory> coarseSolveFact = rcp(new SmootherFactory(smooProto, Teuchos::null)); |
| 330 |
|
| 331 |
FactoryManager M; |
| 332 |
M.SetFactory("P", Pfact); |
| 333 |
M.SetFactory("R", Rfact); |
| 334 |
M.SetFactory("A", Acfact); |
| 335 |
M.SetFactory("Ptent", Ptentfact); |
| 336 |
M.SetFactory("Aggregates", UncoupledAggFact); |
| 337 |
M.SetFactory("Smoother", SmooFact); |
| 338 |
M.SetFactory("CoarseSolver", coarseSolveFact); |
| 339 |
|
| 340 |
H->Setup(M, 0, maxLevels); |
| 341 |
|
| 342 |
// test some basic multigrid data |
| 343 |
RCP<Level> coarseLevel = H->GetLevel(1); |
| 344 |
TEST_EQUALITY(coarseLevel->IsRequested("A",MueLu::NoFactory::get()), false); |
| 345 |
TEST_EQUALITY(coarseLevel->IsRequested("P",MueLu::NoFactory::get()), false); |
| 346 |
TEST_EQUALITY(coarseLevel->IsRequested("PreSmoother",MueLu::NoFactory::get()), false); |
| 347 |
TEST_EQUALITY(coarseLevel->IsRequested("PostSmoother",MueLu::NoFactory::get()), false); |
| 348 |
TEST_EQUALITY(coarseLevel->IsRequested("R",MueLu::NoFactory::get()), false); |
| 349 |
TEST_EQUALITY(coarseLevel->IsAvailable("A",MueLu::NoFactory::get()), true); |
| 350 |
TEST_EQUALITY(coarseLevel->IsAvailable("P",MueLu::NoFactory::get()), true); |
| 351 |
TEST_EQUALITY(coarseLevel->IsAvailable("PreSmoother",MueLu::NoFactory::get()), true); |
| 352 |
TEST_EQUALITY(coarseLevel->IsAvailable("PostSmoother",MueLu::NoFactory::get()), true); |
| 353 |
TEST_EQUALITY(coarseLevel->IsAvailable("R",MueLu::NoFactory::get()), true); |
| 354 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("A",MueLu::NoFactory::get()), MueLu::Final); |
| 355 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("P",MueLu::NoFactory::get()), MueLu::Final); |
| 356 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("PreSmoother",MueLu::NoFactory::get()), MueLu::Final); |
| 357 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("PostSmoother",MueLu::NoFactory::get()), MueLu::Final); |
| 358 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("R",MueLu::NoFactory::get()), MueLu::Final); |
| 359 |
TEST_EQUALITY(coarseLevel->IsRequested("P",Pfact.get()), false); |
| 360 |
TEST_EQUALITY(coarseLevel->IsRequested("P",Ptentfact.get()), false); |
| 361 |
TEST_EQUALITY(coarseLevel->IsRequested("PreSmoother",SmooFact.get()), false); |
| 362 |
TEST_EQUALITY(coarseLevel->IsRequested("PostSmoother",SmooFact.get()), false); |
| 363 |
TEST_EQUALITY(coarseLevel->IsRequested("R",Rfact.get()), false); |
| 364 |
TEST_EQUALITY(coarseLevel->IsRequested("A",Acfact.get()), false); |
| 365 |
TEST_EQUALITY(coarseLevel->IsAvailable("P",Pfact.get()), false); |
| 366 |
TEST_EQUALITY(coarseLevel->IsAvailable("P",Ptentfact.get()), false); |
| 367 |
TEST_EQUALITY(coarseLevel->IsAvailable("PreSmoother",SmooFact.get()), false); |
| 368 |
TEST_EQUALITY(coarseLevel->IsAvailable("PostSmoother",SmooFact.get()), false); |
| 369 |
TEST_EQUALITY(coarseLevel->IsAvailable("R",Rfact.get()), false); |
| 370 |
TEST_EQUALITY(coarseLevel->IsAvailable("A",Acfact.get()), false); |
| 371 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("P",Pfact.get()), 0); |
| 372 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("P",Ptentfact.get()), 0); |
| 373 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("PreSmoother",SmooFact.get()), 0); |
| 374 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("PostSmoother",SmooFact.get()), 0); |
| 375 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("R",Rfact.get()), 0); |
| 376 |
TEST_EQUALITY(coarseLevel->GetKeepFlag("A",Acfact.get()), 0); |
| 377 |
RCP<Matrix> P1 = coarseLevel->Get< RCP<Matrix> >("P"); |
| 378 |
RCP<Matrix> R1 = coarseLevel->Get< RCP<Matrix> >("R"); |
| 379 |
TEST_EQUALITY(P1->getGlobalNumRows(), 63); |
| 380 |
TEST_EQUALITY(P1->getGlobalNumCols(), 21); |
| 381 |
TEST_EQUALITY(R1->getGlobalNumRows(), 21); |
| 382 |
TEST_EQUALITY(R1->getGlobalNumCols(), 63); |
| 383 |
RCP<Level> coarseLevel2 = H->GetLevel(2); |
| 384 |
TEST_EQUALITY(coarseLevel2->IsRequested("A",MueLu::NoFactory::get()), false); |
| 385 |
TEST_EQUALITY(coarseLevel2->IsRequested("P",MueLu::NoFactory::get()), false); |
| 386 |
TEST_EQUALITY(coarseLevel2->IsRequested("R",MueLu::NoFactory::get()), false); |
| 387 |
TEST_EQUALITY(coarseLevel2->IsRequested("PreSmoother",MueLu::NoFactory::get()), false); |
| 388 |
TEST_EQUALITY(coarseLevel2->IsRequested("PostSmoother",MueLu::NoFactory::get()), false); |
| 389 |
TEST_EQUALITY(coarseLevel2->IsAvailable("A",MueLu::NoFactory::get()), true); |
| 390 |
TEST_EQUALITY(coarseLevel2->IsAvailable("P",MueLu::NoFactory::get()), true); |
| 391 |
TEST_EQUALITY(coarseLevel2->IsAvailable("PreSmoother",MueLu::NoFactory::get()), true); |
| 392 |
TEST_EQUALITY(coarseLevel2->IsAvailable("PostSmoother",MueLu::NoFactory::get()), false); |
| 393 |
TEST_EQUALITY(coarseLevel2->IsAvailable("R",MueLu::NoFactory::get()), true); |
| 394 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("A",MueLu::NoFactory::get()), MueLu::Final); |
| 395 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("P",MueLu::NoFactory::get()), MueLu::Final); |
| 396 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("PreSmoother",MueLu::NoFactory::get()), MueLu::Final); |
| 397 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("PostSmoother",MueLu::NoFactory::get()), 0); |
| 398 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("R",MueLu::NoFactory::get()), MueLu::Final); |
| 399 |
TEST_EQUALITY(coarseLevel2->IsRequested("P",Pfact.get()), false); |
| 400 |
TEST_EQUALITY(coarseLevel2->IsRequested("P",Ptentfact.get()), false); |
| 401 |
TEST_EQUALITY(coarseLevel2->IsRequested("R",Rfact.get()), false); |
| 402 |
TEST_EQUALITY(coarseLevel2->IsAvailable("P",Pfact.get()), false); |
| 403 |
TEST_EQUALITY(coarseLevel2->IsAvailable("P",Ptentfact.get()), false); |
| 404 |
TEST_EQUALITY(coarseLevel2->IsAvailable("PreSmoother",SmooFact.get()), false); |
| 405 |
TEST_EQUALITY(coarseLevel2->IsAvailable("PostSmoother",SmooFact.get()), false); |
| 406 |
TEST_EQUALITY(coarseLevel2->IsAvailable("R",Rfact.get()), false); |
| 407 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("P",Pfact.get()), 0); |
| 408 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("P",Ptentfact.get()), 0); |
| 409 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("PreSmoother",SmooFact.get()), 0); |
| 410 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("PostSmoother",SmooFact.get()), 0); |
| 411 |
TEST_EQUALITY(coarseLevel2->GetKeepFlag("R",Rfact.get()), 0); |
| 412 |
RCP<Matrix> P2 = coarseLevel2->Get< RCP<Matrix> >("P"); |
| 413 |
RCP<Matrix> R2 = coarseLevel2->Get< RCP<Matrix> >("R"); |
| 414 |
TEST_EQUALITY(P2->getGlobalNumRows(), 21); |
| 415 |
TEST_EQUALITY(P2->getGlobalNumCols(), 7); |
| 416 |
TEST_EQUALITY(R2->getGlobalNumRows(), 7); |
| 417 |
TEST_EQUALITY(R2->getGlobalNumCols(), 21); |
| 418 |
|
| 419 |
Teuchos::RCP<Xpetra::Matrix<Scalar,LO,GO> > PtentTPtent = Xpetra::MatrixMatrix<Scalar,LO,GO>::Multiply(*P1,true,*P1,false,out); |
| 420 |
TEST_EQUALITY(PtentTPtent->getGlobalMaxNumRowEntries()-3<1e-12, true); |
| 421 |
TEST_EQUALITY(P1->getGlobalMaxNumRowEntries()-2<1e-12, true); |
| 422 |
TEST_EQUALITY(P2->getGlobalMaxNumRowEntries()-2<1e-12, true); |
| 423 |
|
| 424 |
// Define RHS |
| 425 |
RCP<MultiVector> X = MultiVectorFactory::Build(map,1); |
| 426 |
RCP<MultiVector> RHS = MultiVectorFactory::Build(map,1); |
| 427 |
|
| 428 |
X->putScalar(1.0); |
| 429 |
X->norm2(norms); |
| 430 |
if (comm->getRank() == 0) |
| 431 |
out << "||X_true|| = " << std::setiosflags(std::ios::fixed) << std::setprecision(10) << norms[0] << std::endl; |
| 432 |
|
| 433 |
Op->apply(*X,*RHS,Teuchos::NO_TRANS,(SC)1.0,(SC)0.0); |
| 434 |
|
| 435 |
// Use AMG directly as an iterative method |
| 436 |
{ |
| 437 |
X->putScalar( (SC) 0.0); |
| 438 |
|
| 439 |
H->Iterate(*RHS,*X,its); |
| 440 |
|
| 441 |
X->norm2(norms); |
| 442 |
if (comm->getRank() == 0) |
| 443 |
out << "||X_" << std::setprecision(2) << its << "|| = " << std::setiosflags(std::ios::fixed) << std::setprecision(10) << norms[0] << std::endl; |
| 444 |
results[run] = norms[0]; |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
TEST_EQUALITY(results[0] - results[1] < 1e-10, true); // check results of EPETRA vs TPETRA |
| 449 |
} // comm->getSize == 1 |
| 450 |
|
| 451 |
} //SaPFactory_EpetraVsTpetra |
| 452 |
#endif |
| 453 |
#endif |
| 454 |
|
| 455 |
#define MUELU_ETI_GROUP(SC, LO, GO, NO) \ |
| 456 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(SaPFactory_kokkos, Constructor, SC, LO, GO, NO) \ |
| 457 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(SaPFactory_kokkos, Build, SC, LO, GO, NO) \ |
| 458 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(SaPFactory_kokkos, EnforceConstraints, SC, LO, GO, NO) \ |
| 459 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(SaPFactory_kokkos, ConstrainRowOptimalScalarPDE, SC, LO, GO, NO) |
| 460 |
|
| 461 |
#include <MueLu_ETI_4arg.hpp> |
| 462 |
|
| 463 |
} // namespace MueLuTests |