| 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_FancyOStream.hpp> |
| 11 |
#include <Teuchos_ScalarTraits.hpp> |
| 12 |
#include <Teuchos_UnitTestHarness.hpp> |
| 13 |
#include <Teuchos_VerboseObject.hpp> |
| 14 |
// Galeri |
| 15 |
#include <Galeri_XpetraParameters.hpp> |
| 16 |
#include <Galeri_XpetraProblemFactory.hpp> |
| 17 |
#include <Galeri_XpetraUtils.hpp> |
| 18 |
//#include <Galeri_XpetraMaps.hpp> |
| 19 |
|
| 20 |
#include <MueLu_AmalgamationFactory.hpp> |
| 21 |
#include <MueLu_CoalesceDropFactory_kokkos.hpp> |
| 22 |
#include <MueLu_config.hpp> |
| 23 |
#include <MueLu_TestHelpers_kokkos.hpp> |
| 24 |
#include <MueLu_Version.hpp> |
| 25 |
|
| 26 |
#include <MueLu_UncoupledAggregationFactory.hpp> |
| 27 |
|
| 28 |
namespace MueLuTests { |
| 29 |
|
| 30 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(UncoupledAggregationFactory, Constructor, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 31 |
#include <MueLu_UseShortNames.hpp> |
| 32 |
|
| 33 |
out << "version: " << MueLu::Version() << std::endl; |
| 34 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 35 |
TEST_EQUALITY(aggFact != Teuchos::null, true); |
| 36 |
TEST_THROW(aggFact->SetOrdering("unknown_ordering"), Teuchos::Exceptions::InvalidParameterValue); |
| 37 |
aggFact->SetOrdering("natural"); |
| 38 |
TEST_EQUALITY(aggFact->GetOrdering() == "natural", true); |
| 39 |
aggFact->SetOrdering("graph"); |
| 40 |
TEST_EQUALITY(aggFact->GetOrdering() == "graph", true); |
| 41 |
aggFact->SetOrdering("random"); |
| 42 |
TEST_EQUALITY(aggFact->GetOrdering() == "random", true); |
| 43 |
|
| 44 |
aggFact->SetMaxNeighAlreadySelected(100); |
| 45 |
TEST_EQUALITY(aggFact->GetMaxNeighAlreadySelected() == 100, true); |
| 46 |
aggFact->SetMinNodesPerAggregate(10); |
| 47 |
TEST_EQUALITY(aggFact->GetMinNodesPerAggregate() == 10, true); |
| 48 |
|
| 49 |
auto validParamList = aggFact->GetValidParameterList(); |
| 50 |
TEST_EQUALITY(validParamList != Teuchos::null, true); |
| 51 |
|
| 52 |
} // Constructor |
| 53 |
|
| 54 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(UncoupledAggregationFactory, Build, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 55 |
#include <MueLu_UseShortNames.hpp> |
| 56 |
MUELU_TESTING_SET_OSTREAM; |
| 57 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 58 |
out << "version: " << MueLu::Version() << std::endl; |
| 59 |
RCP<const Teuchos::Comm<int> > comm = TestHelpers_kokkos::Parameters::getDefaultComm(); |
| 60 |
|
| 61 |
// Make a Matrix with multiple degrees of freedom per node |
| 62 |
GlobalOrdinal nx = 20, ny = 20; |
| 63 |
|
| 64 |
// Describes the initial layout of matrix rows across processors. |
| 65 |
Teuchos::ParameterList galeriList; |
| 66 |
galeriList.set("nx", nx); |
| 67 |
galeriList.set("ny", ny); |
| 68 |
|
| 69 |
const GO nxx = 200; |
| 70 |
using test_factory = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>; |
| 71 |
Teuchos::CommandLineProcessor clp(false); |
| 72 |
Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 8748); // manage parameters of the test case |
| 73 |
Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra |
| 74 |
|
| 75 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(nxx); |
| 76 |
RCP<const Map> map = MapFactory::Build(xpetraParameters.GetLib(), matrixParameters.GetNumGlobalElements(), 0, comm); |
| 77 |
|
| 78 |
map = Xpetra::MapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(map, 2); // expand map for 2 DOFs per node |
| 79 |
A->SetFixedBlockSize(2); |
| 80 |
|
| 81 |
Level aLevel; |
| 82 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(aLevel); |
| 83 |
aLevel.Request("A"); |
| 84 |
aLevel.Set("A", A); |
| 85 |
|
| 86 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 87 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 88 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 89 |
|
| 90 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 91 |
aggFact->SetFactory("Graph", dropFact); |
| 92 |
|
| 93 |
aLevel.Request(*aggFact); |
| 94 |
|
| 95 |
aggFact->Build(aLevel); |
| 96 |
|
| 97 |
} // Build |
| 98 |
|
| 99 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(UncoupledAggregationFactory, Build_MIS2_Coarsen, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 100 |
#include <MueLu_UseShortNames.hpp> |
| 101 |
MUELU_TESTING_SET_OSTREAM; |
| 102 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 103 |
out << "version: " << MueLu::Version() << std::endl; |
| 104 |
RCP<const Teuchos::Comm<int> > comm = TestHelpers_kokkos::Parameters::getDefaultComm(); |
| 105 |
|
| 106 |
// Make a Matrix with multiple degrees of freedom per node |
| 107 |
GlobalOrdinal nx = 20, ny = 20; |
| 108 |
|
| 109 |
// Describes the initial layout of matrix rows across processors. |
| 110 |
Teuchos::ParameterList galeriList; |
| 111 |
galeriList.set("nx", nx); |
| 112 |
galeriList.set("ny", ny); |
| 113 |
|
| 114 |
const GO nxx = 200; |
| 115 |
using test_factory = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>; |
| 116 |
Teuchos::CommandLineProcessor clp(false); |
| 117 |
Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 8748); // manage parameters of the test case |
| 118 |
Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra |
| 119 |
|
| 120 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(nxx); |
| 121 |
RCP<const Map> map = MapFactory::Build(xpetraParameters.GetLib(), matrixParameters.GetNumGlobalElements(), 0, comm); |
| 122 |
|
| 123 |
map = Xpetra::MapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(map, 2); // expand map for 2 DOFs per node |
| 124 |
A->SetFixedBlockSize(2); |
| 125 |
|
| 126 |
Level aLevel; |
| 127 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(aLevel); |
| 128 |
aLevel.Request("A"); |
| 129 |
aLevel.Set("A", A); |
| 130 |
|
| 131 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 132 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 133 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 134 |
|
| 135 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 136 |
aggFact->SetFactory("Graph", dropFact); |
| 137 |
aggFact->SetParameter("aggregation: coloring algorithm", |
| 138 |
Teuchos::ParameterEntry(std::string("mis2 coarsening"))); |
| 139 |
|
| 140 |
aLevel.Request(*aggFact); |
| 141 |
|
| 142 |
aggFact->Build(aLevel); |
| 143 |
|
| 144 |
} // Build_MIS2_Coarsen |
| 145 |
|
| 146 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(UncoupledAggregationFactory, Build_MIS2_Aggregate, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 147 |
#include <MueLu_UseShortNames.hpp> |
| 148 |
MUELU_TESTING_SET_OSTREAM; |
| 149 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 150 |
out << "version: " << MueLu::Version() << std::endl; |
| 151 |
RCP<const Teuchos::Comm<int> > comm = TestHelpers_kokkos::Parameters::getDefaultComm(); |
| 152 |
|
| 153 |
// Make a Matrix with multiple degrees of freedom per node |
| 154 |
GlobalOrdinal nx = 20, ny = 20; |
| 155 |
|
| 156 |
// Describes the initial layout of matrix rows across processors. |
| 157 |
Teuchos::ParameterList galeriList; |
| 158 |
galeriList.set("nx", nx); |
| 159 |
galeriList.set("ny", ny); |
| 160 |
|
| 161 |
const GO nxx = 200; |
| 162 |
using test_factory = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>; |
| 163 |
Teuchos::CommandLineProcessor clp(false); |
| 164 |
Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 8748); // manage parameters of the test case |
| 165 |
Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra |
| 166 |
|
| 167 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(nxx); |
| 168 |
RCP<const Map> map = MapFactory::Build(xpetraParameters.GetLib(), matrixParameters.GetNumGlobalElements(), 0, comm); |
| 169 |
|
| 170 |
map = Xpetra::MapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(map, 2); // expand map for 2 DOFs per node |
| 171 |
A->SetFixedBlockSize(2); |
| 172 |
|
| 173 |
Level aLevel; |
| 174 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(aLevel); |
| 175 |
aLevel.Request("A"); |
| 176 |
aLevel.Set("A", A); |
| 177 |
|
| 178 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 179 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 180 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 181 |
|
| 182 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 183 |
aggFact->SetFactory("Graph", dropFact); |
| 184 |
aggFact->SetParameter("aggregation: coloring algorithm", |
| 185 |
Teuchos::ParameterEntry(std::string("mis2 aggregation"))); |
| 186 |
|
| 187 |
aLevel.Request(*aggFact); |
| 188 |
|
| 189 |
aggFact->Build(aLevel); |
| 190 |
|
| 191 |
} // Build_MIS2_Aggregate |
| 192 |
|
| 193 |
#define MUELU_ETI_GROUP(Scalar, LO, GO, Node) \ |
| 194 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(UncoupledAggregationFactory, Constructor, Scalar, LO, GO, Node) \ |
| 195 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(UncoupledAggregationFactory, Build, Scalar, LO, GO, Node) \ |
| 196 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(UncoupledAggregationFactory, Build_MIS2_Coarsen, Scalar, LO, GO, Node) \ |
| 197 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(UncoupledAggregationFactory, Build_MIS2_Aggregate, Scalar, LO, GO, Node) |
| 198 |
|
| 199 |
#include <MueLu_ETI_4arg.hpp> |
| 200 |
|
| 201 |
} // namespace MueLuTests |