Debian Codegraph @

packages/muelu/test/unit_tests_kokkos/StructuredAggregation_kokkos.cpp

raw
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 "MueLu_TestHelpers_kokkos.hpp"
14 #include "MueLu_Version.hpp"
15
16 #include "MueLu_Level.hpp"
17 #include "MueLu_FactoryManagerBase.hpp"
18 #include "MueLu_AmalgamationFactory.hpp"
19 #include "MueLu_CoalesceDropFactory_kokkos.hpp"
20 #include "MueLu_CoarseMapFactory.hpp"
21 #include "MueLu_IndexManager_kokkos.hpp"
22 #include "MueLu_StructuredAggregationFactory_kokkos.hpp"
23 #include "MueLu_TentativePFactory_kokkos.hpp"
24
25 namespace MueLuTests {
26
27 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(StructuredAggregation_kokkos, CreateCrsGraphConstant, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
28 #include "MueLu_UseShortNames.hpp"
29 MUELU_TESTING_SET_OSTREAM;
30 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
31
32 if (TestHelpers_kokkos::Parameters::getLib() == Xpetra::UseEpetra) {
33 out << "skipping test for linAlgebra==UseEpetra" << std::endl;
34 return;
35 }
36
37 typedef typename Teuchos::ScalarTraits<SC>::magnitudeType real_type;
38 typedef typename Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
39
40 typedef Teuchos::ScalarTraits<Scalar> TST;
41 typedef TestHelpers_kokkos::TestFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node> test_factory;
42
43 out << "version: " << MueLu::Version() << std::endl;
44
45 Level currentLevel;
46 test_factory::createSingleLevelHierarchy(currentLevel);
47 currentLevel.SetFactoryManager(Teuchos::null); // factory manager is not used on this test
48
49 // Set global geometric data
50 const std::string meshLayout = "Local Lexicographic";
51 const std::string coupling = "uncoupled";
52 LO numDimensions = 3;
53 Array<GO> meshData;
54 Array<LO> lNodesPerDir(3);
55 Array<GO> gNodesPerDir(3);
56 for (int dim = 0; dim < 3; ++dim) {
57 if (dim < numDimensions) {
58 // Use more nodes in 1D to have a reasonable number of nodes per procs
59 gNodesPerDir[dim] = 6;
60 } else {
61 gNodesPerDir[dim] = 1;
62 }
63 }
64
65 RCP<RealValuedMultiVector> Coordinates =
66 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildGeoCoordinates(numDimensions, gNodesPerDir,
67 lNodesPerDir, meshData,
68 meshLayout);
69
70 // Since we are doing uncoupled aggregation we fill meshData with -1
71 for (size_t idx = 0; idx < (size_t)meshData.size(); ++idx) {
72 meshData[idx] = -1;
73 }
74
75 Teuchos::ParameterList matrixList;
76 matrixList.set("nx", gNodesPerDir[0]);
77 matrixList.set("matrixType", "Laplace1D");
78 RCP<Galeri::Xpetra::Problem<Map, CrsMatrixWrap, MultiVector> > Pr = Galeri::Xpetra::
79 BuildProblem<SC, LO, GO, Map, CrsMatrixWrap, MultiVector>("Laplace3D", Coordinates->getMap(),
80 matrixList);
81 RCP<Matrix> A = Pr->BuildMatrix();
82 currentLevel.Request("A");
83 currentLevel.Set("A", A);
84 currentLevel.Set("numDimensions", numDimensions);
85 currentLevel.Set("Coordinates", Coordinates);
86 currentLevel.Set("lNodesPerDim", lNodesPerDir);
87
88 // only one NS vector -> exercises manual orthogonalization
89 LocalOrdinal NSdim = 1;
90 RCP<MultiVector> nullSpace = MultiVectorFactory::Build(A->getRowMap(), NSdim);
91 nullSpace->putScalar(1.0);
92 currentLevel.Set("Nullspace", nullSpace);
93
94 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
95 RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos());
96 dropFact->SetFactory("UnAmalgamationInfo", amalgFact);
97 RCP<StructuredAggregationFactory_kokkos> StructuredAggFact = rcp(new StructuredAggregationFactory_kokkos());
98 StructuredAggFact->SetFactory("Graph", dropFact);
99 StructuredAggFact->SetFactory("DofsPerNode", dropFact);
100 StructuredAggFact->SetParameter("aggregation: coarsening order",
101 Teuchos::ParameterEntry(0));
102 StructuredAggFact->SetParameter("aggregation: coarsening rate",
103 Teuchos::ParameterEntry(std::string("{3}")));
104 StructuredAggFact->SetParameter("aggregation: output type",
105 Teuchos::ParameterEntry(std::string("CrsGraph")));
106
107 currentLevel.Request("prolongatorGraph", StructuredAggFact.get()); // request prolongatorGraph
108 currentLevel.Request(*StructuredAggFact);
109 StructuredAggFact->Build(currentLevel);
110 } // CreateCrsGraphConstant
111
112 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(StructuredAggregation_kokkos, CreateCrsGraphLinear, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
113 #include "MueLu_UseShortNames.hpp"
114 MUELU_TESTING_SET_OSTREAM;
115 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
116
117 if (TestHelpers_kokkos::Parameters::getLib() == Xpetra::UseEpetra) {
118 out << "skipping test for linAlgebra==UseEpetra" << std::endl;
119 return;
120 }
121
122 typedef typename Teuchos::ScalarTraits<SC>::magnitudeType real_type;
123 typedef typename Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
124
125 typedef Teuchos::ScalarTraits<Scalar> TST;
126 typedef TestHelpers_kokkos::TestFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node> test_factory;
127
128 out << "version: " << MueLu::Version() << std::endl;
129
130 Level currentLevel;
131 test_factory::createSingleLevelHierarchy(currentLevel);
132 currentLevel.SetFactoryManager(Teuchos::null); // factory manager is not used on this test
133
134 // Set global geometric data
135 const std::string meshLayout = "Local Lexicographic";
136 const std::string coupling = "uncoupled";
137 LO numDimensions = 3;
138 Array<GO> meshData;
139 Array<LO> lNodesPerDir(3);
140 Array<GO> gNodesPerDir(3);
141 for (int dim = 0; dim < 3; ++dim) {
142 if (dim < numDimensions) {
143 // Use more nodes in 1D to have a reasonable number of nodes per procs
144 gNodesPerDir[dim] = 6;
145 } else {
146 gNodesPerDir[dim] = 1;
147 }
148 }
149
150 RCP<RealValuedMultiVector> Coordinates =
151 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildGeoCoordinates(numDimensions, gNodesPerDir,
152 lNodesPerDir, meshData,
153 meshLayout);
154
155 // Since we are doing uncoupled aggregation we fill meshData with -1
156 for (size_t idx = 0; idx < (size_t)meshData.size(); ++idx) {
157 meshData[idx] = -1;
158 }
159
160 Teuchos::ParameterList matrixList;
161 matrixList.set("nx", gNodesPerDir[0]);
162 matrixList.set("matrixType", "Laplace1D");
163 RCP<Galeri::Xpetra::Problem<Map, CrsMatrixWrap, MultiVector> > Pr = Galeri::Xpetra::
164 BuildProblem<SC, LO, GO, Map, CrsMatrixWrap, MultiVector>("Laplace3D", Coordinates->getMap(),
165 matrixList);
166 RCP<Matrix> A = Pr->BuildMatrix();
167 currentLevel.Request("A");
168 currentLevel.Set("A", A);
169 currentLevel.Set("numDimensions", numDimensions);
170 currentLevel.Set("Coordinates", Coordinates);
171 currentLevel.Set("lNodesPerDim", lNodesPerDir);
172
173 // only one NS vector -> exercises manual orthogonalization
174 LocalOrdinal NSdim = 1;
175 RCP<MultiVector> nullSpace = MultiVectorFactory::Build(A->getRowMap(), NSdim);
176 nullSpace->putScalar(1.0);
177 currentLevel.Set("Nullspace", nullSpace);
178
179 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
180 RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos());
181 dropFact->SetFactory("UnAmalgamationInfo", amalgFact);
182 RCP<StructuredAggregationFactory_kokkos> StructuredAggFact = rcp(new StructuredAggregationFactory_kokkos());
183 StructuredAggFact->SetFactory("Graph", dropFact);
184 StructuredAggFact->SetFactory("DofsPerNode", dropFact);
185 StructuredAggFact->SetParameter("aggregation: coarsening order",
186 Teuchos::ParameterEntry(1));
187 StructuredAggFact->SetParameter("aggregation: coarsening rate",
188 Teuchos::ParameterEntry(std::string("{3}")));
189 StructuredAggFact->SetParameter("aggregation: output type",
190 Teuchos::ParameterEntry(std::string("CrsGraph")));
191
192 currentLevel.Request("prolongatorGraph", StructuredAggFact.get()); // request prolongatorGraph
193 currentLevel.Request(*StructuredAggFact);
194 StructuredAggFact->Build(currentLevel);
195
196 RCP<CrsGraph> prolongatorGraph;
197 currentLevel.Get("prolongatorGraph", prolongatorGraph, StructuredAggFact.get());
198
199 } // CreateCrsGraphLinear
200
201 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(StructuredAggregation_kokkos, UncoupledTentative3D, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
202 #include "MueLu_UseShortNames.hpp"
203 MUELU_TESTING_SET_OSTREAM;
204 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
205
206 if (TestHelpers_kokkos::Parameters::getLib() == Xpetra::UseEpetra) {
207 out << "skipping test for linAlgebra==UseEpetra" << std::endl;
208 return;
209 }
210
211 using real_type = typename Teuchos::ScalarTraits<SC>::coordinateType;
212 using RealValuedMultiVector = typename Xpetra::MultiVector<real_type, LO, GO, NO>;
213 using TST = Teuchos::ScalarTraits<SC>;
214 using magnitude_type = typename TST::magnitudeType;
215 using TMT = Teuchos::ScalarTraits<magnitude_type>;
216 using test_factory = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>;
217
218 out << "version: " << MueLu::Version() << std::endl;
219
220 Level fineLevel, coarseLevel;
221 test_factory::createTwoLevelHierarchy(fineLevel, coarseLevel);
222 fineLevel.SetFactoryManager(Teuchos::null); // factory manager is not used on this test
223 coarseLevel.SetFactoryManager(Teuchos::null);
224
225 // Set global geometric data
226 const std::string meshLayout = "Local Lexicographic";
227 const std::string coupling = "uncoupled";
228 LO numDimensions = 3;
229 Array<GO> meshData;
230 Array<LO> lNodesPerDir(3);
231 Array<GO> gNodesPerDir(3);
232 for (int dim = 0; dim < 3; ++dim) {
233 if (dim < numDimensions) {
234 // Use more nodes in 1D to have a reasonable number of nodes per procs
235 gNodesPerDir[dim] = 6;
236 } else {
237 gNodesPerDir[dim] = 1;
238 }
239 }
240
241 RCP<RealValuedMultiVector> Coordinates =
242 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildGeoCoordinates(numDimensions, gNodesPerDir,
243 lNodesPerDir, meshData,
244 meshLayout);
245
246 // Since we are doing uncoupled aggregation we fill meshData with -1
247 for (size_t idx = 0; idx < (size_t)meshData.size(); ++idx) {
248 meshData[idx] = -1;
249 }
250
251 Teuchos::ParameterList matrixList;
252 matrixList.set("nx", gNodesPerDir[0]);
253 matrixList.set("matrixType", "Laplace1D");
254 RCP<Galeri::Xpetra::Problem<Map, CrsMatrixWrap, MultiVector> > Pr = Galeri::Xpetra::
255 BuildProblem<SC, LO, GO, Map, CrsMatrixWrap, MultiVector>("Laplace3D", Coordinates->getMap(),
256 matrixList);
257 RCP<Matrix> A = Pr->BuildMatrix();
258 fineLevel.Request("A");
259 fineLevel.Set("A", A);
260 fineLevel.Set("numDimensions", numDimensions);
261 fineLevel.Set("Coordinates", Coordinates);
262 fineLevel.Set("lNodesPerDim", lNodesPerDir);
263
264 // only one NS vector -> exercises manual orthogonalization
265 LocalOrdinal NSdim = 1;
266 RCP<MultiVector> nullSpace = MultiVectorFactory::Build(A->getRowMap(), NSdim);
267 nullSpace->putScalar(1.0);
268 fineLevel.Set("Nullspace", nullSpace);
269
270 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
271 RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos());
272 dropFact->SetFactory("UnAmalgamationInfo", amalgFact);
273 RCP<StructuredAggregationFactory_kokkos> StructuredAggFact = rcp(new StructuredAggregationFactory_kokkos());
274 StructuredAggFact->SetFactory("Graph", dropFact);
275 StructuredAggFact->SetFactory("DofsPerNode", dropFact);
276 StructuredAggFact->SetParameter("aggregation: coarsening order",
277 Teuchos::ParameterEntry(0));
278 StructuredAggFact->SetParameter("aggregation: coarsening rate",
279 Teuchos::ParameterEntry(std::string("{3}")));
280
281 RCP<CoarseMapFactory> coarseMapFact = rcp(new CoarseMapFactory());
282 coarseMapFact->SetFactory("Aggregates", StructuredAggFact);
283 RCP<TentativePFactory_kokkos> TentativePFact = rcp(new TentativePFactory_kokkos());
284 TentativePFact->SetFactory("Aggregates", StructuredAggFact);
285 TentativePFact->SetFactory("UnAmalgamationInfo", amalgFact);
286 TentativePFact->SetFactory("CoarseMap", coarseMapFact);
287
288 coarseLevel.Request("P", TentativePFact.get()); // request Ptent
289 coarseLevel.Request("Nullspace", TentativePFact.get());
290 coarseLevel.Request(*TentativePFact);
291 TentativePFact->Build(fineLevel, coarseLevel);
292
293 RCP<Matrix> Ptent;
294 coarseLevel.Get("P", Ptent, TentativePFact.get());
295
296 RCP<MultiVector> coarseNullSpace = coarseLevel.Get<RCP<MultiVector> >("Nullspace", TentativePFact.get());
297
298 coarseLevel.Release("P", TentativePFact.get()); // release Ptent
299 coarseLevel.Release("Nullspace", TentativePFact.get());
300
301 // check normalization and orthogonality of prolongator columns
302 Teuchos::RCP<Xpetra::Matrix<SC, LO, GO, Node> > PtentTPtent = Xpetra::MatrixMatrix<SC, LO, GO, Node>::Multiply(*Ptent, true, *Ptent, false, out);
303 Teuchos::RCP<Xpetra::Vector<SC, LO, GO, Node> > diagVec = Xpetra::VectorFactory<SC, LO, GO, Node>::Build(PtentTPtent->getRowMap());
304 PtentTPtent->getLocalDiagCopy(*diagVec);
305 if (TST::name().find("complex") == std::string::npos) // skip check for Scalar=complex
306 TEST_FLOATING_EQUALITY(diagVec->norm1(), Teuchos::as<magnitude_type>(diagVec->getGlobalLength()), 1000 * TMT::eps());
307 TEST_FLOATING_EQUALITY(diagVec->normInf(), TMT::one(), 1000 * TMT::eps());
308 TEST_EQUALITY(PtentTPtent->getGlobalNumEntries(), diagVec->getGlobalLength());
309
310 } // UncoupledTentative3D
311
312 #define MUELU_ETI_GROUP(SC, LO, GO, NO) \
313 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(StructuredAggregation_kokkos, CreateCrsGraphConstant, SC, LO, GO, NO) \
314 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(StructuredAggregation_kokkos, CreateCrsGraphLinear, SC, LO, GO, NO) \
315 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(StructuredAggregation_kokkos, UncoupledTentative3D, SC, LO, GO, NO)
316
317 #include <MueLu_ETI_4arg.hpp>
318
319 } // namespace MueLuTests