Debian Codegraph @

packages/muelu/test/navierstokes/Navier2DBlocked_Simple.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 /*
11 * Navier2D_epetra.cpp
12 *
13 * Created on: Mar 26, 2011
14 * Author: wiesner
15 */
16
17 #include <unistd.h>
18 #include <iostream>
19 #include <fstream>
20
21 // Teuchos
22 #include <Teuchos_RCP.hpp>
23 #include <Teuchos_ParameterList.hpp>
24 #include <Teuchos_CommandLineProcessor.hpp>
25 #include <Teuchos_GlobalMPISession.hpp>
26 #include <Teuchos_DefaultComm.hpp>
27 #include <Teuchos_ArrayRCP.hpp>
28 #include <Teuchos_ScalarTraits.hpp>
29 #include <Teuchos_StandardCatchMacros.hpp>
30
31 // Epetra
32 #include <EpetraExt_CrsMatrixIn.h>
33 #include <EpetraExt_VectorIn.h>
34 #include <EpetraExt_MultiVectorIn.h>
35
36 // Xpetra
37 #include <Xpetra_Map.hpp>
38 #include <Xpetra_MapFactory.hpp>
39 #include <Xpetra_Matrix.hpp>
40 #include <Xpetra_CrsMatrixWrap.hpp>
41 #include <Xpetra_MultiVectorFactory.hpp>
42 #include <Xpetra_VectorFactory.hpp>
43 #include <Xpetra_Parameters.hpp>
44 #include <Xpetra_MapExtractorFactory.hpp>
45 #include <Xpetra_BlockedCrsMatrix.hpp>
46 #include <Xpetra_StridedMapFactory.hpp>
47 #include <Xpetra_StridedMap.hpp>
48
49 // MueLu
50 #include "MueLu_ConfigDefs.hpp"
51 #include "MueLu_Memory.hpp"
52 #include "MueLu_Hierarchy.hpp"
53 #include "MueLu_UncoupledAggregationFactory.hpp"
54 #include "MueLu_PgPFactory.hpp"
55 #include "MueLu_GenericRFactory.hpp"
56 #include "MueLu_SaPFactory.hpp"
57 #include "MueLu_TransPFactory.hpp"
58 #include "MueLu_BlockedRAPFactory.hpp"
59 #include "MueLu_TrilinosSmoother.hpp"
60 #include "MueLu_Utilities.hpp"
61 #include "MueLu_Exceptions.hpp"
62 #include "MueLu_Aggregates.hpp"
63 #include "MueLu_CoalesceDropFactory.hpp"
64 #include "MueLu_PreDropFunctionConstVal.hpp"
65 #include "MueLu_NullspaceFactory.hpp"
66 #include "MueLu_TentativePFactory.hpp"
67 #include "MueLu_SmootherFactory.hpp"
68 #include "MueLu_DirectSolver.hpp"
69 #include "MueLu_EpetraOperator.hpp"
70 #include "MueLu_SubBlockAFactory.hpp"
71 #include "MueLu_BlockedPFactory.hpp"
72 #include "MueLu_BlockedGaussSeidelSmoother.hpp"
73 #include "MueLu_SchurComplementFactory.hpp"
74 #include "MueLu_SimpleSmoother.hpp"
75 #include "MueLu_InverseApproximationFactory.hpp"
76
77 #include "MueLu_CoarseMapFactory.hpp"
78
79 #include "MueLu_AmalgamationFactory.hpp"
80 #include "MueLu_AggregationExportFactory.hpp"
81
82 #include <Epetra_LinearProblem.h>
83 #include <AztecOO.h>
84
85 #include "Navier2D_Helpers.h"
86
87 /*!
88 * 2d Navier Stokes example (for Epetra)
89 *
90 * using block matrices
91 */
92
93 int main(int argc, char* argv[]) {
94 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT)
95 typedef double Scalar;
96 typedef int LocalOrdinal;
97 typedef int GlobalOrdinal;
98 typedef LocalOrdinal LO;
99 typedef GlobalOrdinal GO;
100 typedef Xpetra::EpetraNode Node;
101 #include "MueLu_UseShortNames.hpp"
102
103 using Teuchos::RCP;
104 using Teuchos::rcp;
105
106 Teuchos::oblackholestream blackhole;
107 Teuchos::GlobalMPISession mpiSession(&argc, &argv, &blackhole);
108
109 bool success = false;
110 bool verbose = true;
111 try {
112 //
113 RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
114 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
115 out->setOutputToRootOnly(0);
116 *out << MueLu::MemUtils::PrintMemoryUsage() << std::endl;
117
118 // Timing
119 Teuchos::Time myTime("global");
120 Teuchos::TimeMonitor MM(myTime);
121
122 // custom parameters
123 LocalOrdinal maxLevels = 3;
124
125 GlobalOrdinal maxCoarseSize = 1; // FIXME clp doesn't like long long int
126
127 int globalNumDofs = 1500; // used for the maps
128 int nDofsPerNode = 3; // used for generating the fine level null-space
129
130 // build strided maps
131 // striding information: 2 velocity dofs and 1 pressure dof = 3 dofs per node
132 std::vector<size_t> stridingInfo;
133 stridingInfo.push_back(2);
134 stridingInfo.push_back(1);
135
136 /////////////////////////////////////// build strided maps
137 // build strided maps:
138 // xstridedfullmap: full map (velocity and pressure dof gids), continous
139 // xstridedvelmap: only velocity dof gid maps (i.e. 0,1,3,4,6,7...)
140 // xstridedpremap: only pressure dof gid maps (i.e. 2,5,8,...)
141 Xpetra::UnderlyingLib lib = Xpetra::UseEpetra;
142 RCP<StridedMap> xstridedfullmap = StridedMapFactory::Build(lib, globalNumDofs, 0, stridingInfo, comm, -1);
143 RCP<StridedMap> xstridedvelmap = StridedMapFactory::Build(xstridedfullmap, 0);
144 RCP<StridedMap> xstridedpremap = StridedMapFactory::Build(xstridedfullmap, 1);
145
146 /////////////////////////////////////// transform Xpetra::Map objects to Epetra
147 // this is needed for AztecOO
148 const RCP<const Epetra_Map> fullmap = Teuchos::rcpFromRef(Xpetra::toEpetra(*xstridedfullmap));
149 RCP<const Epetra_Map> velmap = Teuchos::rcpFromRef(Xpetra::toEpetra(*xstridedvelmap));
150 RCP<const Epetra_Map> premap = Teuchos::rcpFromRef(Xpetra::toEpetra(*xstridedpremap));
151
152 /////////////////////////////////////// import problem matrix and RHS from files (-> Epetra)
153
154 // read in problem
155 Epetra_CrsMatrix* ptrA = 0;
156 Epetra_Vector* ptrf = 0;
157 Epetra_MultiVector* ptrNS = 0;
158
159 *out << "Reading matrix market file" << std::endl;
160
161 EpetraExt::MatrixMarketFileToCrsMatrix("A_re1000_5932.txt", *fullmap, *fullmap, *fullmap, ptrA);
162 EpetraExt::MatrixMarketFileToVector("b_re1000_5932.txt", *fullmap, ptrf);
163
164 RCP<Epetra_CrsMatrix> epA = Teuchos::rcp(ptrA);
165 RCP<Epetra_Vector> epv = Teuchos::rcp(ptrf);
166 RCP<Epetra_MultiVector> epNS = Teuchos::rcp(ptrNS);
167
168 /////////////////////////////////////// split system into 2x2 block system
169
170 *out << "Split matrix into 2x2 block matrix" << std::endl;
171
172 // split fullA into A11,..., A22
173 Teuchos::RCP<Epetra_CrsMatrix> A11;
174 Teuchos::RCP<Epetra_CrsMatrix> A12;
175 Teuchos::RCP<Epetra_CrsMatrix> A21;
176 Teuchos::RCP<Epetra_CrsMatrix> A22;
177
178 if (MueLuTests::SplitMatrix2x2(epA, *velmap, *premap, A11, A12, A21, A22) == false)
179 *out << "Problem with splitting matrix" << std::endl;
180
181 /////////////////////////////////////// transform Epetra objects to Xpetra (needed for MueLu)
182
183 // build Xpetra objects from Epetra_CrsMatrix objects
184 Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xA11 = Teuchos::rcp(new Xpetra::EpetraCrsMatrixT<GlobalOrdinal, Node>(A11));
185 Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xA12 = Teuchos::rcp(new Xpetra::EpetraCrsMatrixT<GlobalOrdinal, Node>(A12));
186 Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xA21 = Teuchos::rcp(new Xpetra::EpetraCrsMatrixT<GlobalOrdinal, Node>(A21));
187 Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xA22 = Teuchos::rcp(new Xpetra::EpetraCrsMatrixT<GlobalOrdinal, Node>(A22));
188
189 /////////////////////////////////////// generate MapExtractor object
190
191 std::vector<Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > > xmaps;
192 xmaps.push_back(xstridedvelmap);
193 xmaps.push_back(xstridedpremap);
194
195 Teuchos::RCP<const Xpetra::MapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node> > map_extractor = Xpetra::MapExtractorFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(xstridedfullmap, xmaps);
196
197 /////////////////////////////////////// build blocked transfer operator
198 // using the map extractor
199 Teuchos::RCP<Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > bOp = Teuchos::rcp(new Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>(map_extractor, map_extractor, 10));
200 bOp->setMatrix(0, 0, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA11)));
201 bOp->setMatrix(0, 1, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA12)));
202 bOp->setMatrix(1, 0, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA21)));
203 bOp->setMatrix(1, 1, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA22)));
204
205 bOp->fillComplete();
206
207 //////////////////////////////////////////////////// create Hierarchy
208 RCP<Hierarchy> H = rcp(new Hierarchy());
209 H->setDefaultVerbLevel(Teuchos::VERB_HIGH);
210 // H->setDefaultVerbLevel(Teuchos::VERB_NONE);
211 H->SetMaxCoarseSize(maxCoarseSize);
212
213 //////////////////////////////////////////////////////// finest Level
214 RCP<MueLu::Level> Finest = H->GetLevel();
215 Finest->setDefaultVerbLevel(Teuchos::VERB_HIGH);
216 Finest->Set("A", Teuchos::rcp_dynamic_cast<Matrix>(bOp));
217
218 /////////////////////////////////////////////// define subblocks of A
219 // make A11 block and A22 block available as variable "A" generated
220 // by A11Fact and A22Fact
221 RCP<SubBlockAFactory> A11Fact = rcp(new SubBlockAFactory());
222 A11Fact->SetFactory("A", MueLu::NoFactory::getRCP());
223 A11Fact->SetParameter("block row", Teuchos::ParameterEntry(0));
224 A11Fact->SetParameter("block col", Teuchos::ParameterEntry(0));
225 RCP<SubBlockAFactory> A22Fact = rcp(new SubBlockAFactory());
226 A22Fact->SetFactory("A", MueLu::NoFactory::getRCP());
227 A22Fact->SetParameter("block row", Teuchos::ParameterEntry(1));
228 A22Fact->SetParameter("block col", Teuchos::ParameterEntry(1));
229
230 ////////////////////////////////////////// prepare null space for A11
231 RCP<MultiVector> nullspace11 = MultiVectorFactory::Build(xstridedvelmap, 2); // this is a 2D standard null space
232
233 for (int i = 0; i < nDofsPerNode - 1; ++i) {
234 Teuchos::ArrayRCP<Scalar> nsValues = nullspace11->getDataNonConst(i);
235 int numBlocks = nsValues.size() / (nDofsPerNode - 1);
236 for (int j = 0; j < numBlocks; ++j) {
237 nsValues[j * (nDofsPerNode - 1) + i] = 1.0;
238 }
239 }
240
241 Finest->Set("Nullspace1", nullspace11);
242
243 ///////////////////////////////////////// define CoalesceDropFactory and Aggregation for A11
244 // set up amalgamation for A11. Note: we're using a default null space factory (Teuchos::null)
245 RCP<AmalgamationFactory> amalgFact11 = rcp(new AmalgamationFactory());
246 amalgFact11->SetFactory("A", A11Fact);
247
248 amalgFact11->setDefaultVerbLevel(Teuchos::VERB_EXTREME);
249 RCP<CoalesceDropFactory> dropFact11 = rcp(new CoalesceDropFactory());
250 dropFact11->SetFactory("A", A11Fact);
251 dropFact11->SetFactory("UnAmalgamationInfo", amalgFact11);
252 dropFact11->setDefaultVerbLevel(Teuchos::VERB_EXTREME);
253 RCP<UncoupledAggregationFactory> CoupledAggFact11 = rcp(new UncoupledAggregationFactory());
254 CoupledAggFact11->SetFactory("Graph", dropFact11);
255 CoupledAggFact11->SetMinNodesPerAggregate(9);
256 CoupledAggFact11->SetMaxNeighAlreadySelected(2);
257 CoupledAggFact11->SetOrdering("natural");
258
259 ///////////////////////////////////////// define transfer ops for A11
260 #if 0
261 // use PG-AMG
262 RCP<PgPFactory> P11Fact = rcp(new PgPFactory());
263
264 RCP<GenericRFactory> R11Fact = rcp(new GenericRFactory());
265 Teuchos::RCP<NullspaceFactory> nspFact11 = Teuchos::rcp(new NullspaceFactory("Nullspace1",P11tentFact));
266
267 Teuchos::RCP<NullspaceFactory> nspFact11 = Teuchos::rcp(new NullspaceFactory("Nullspace1"));
268
269 RCP<CoarseMapFactory> coarseMapFact11 = Teuchos::rcp(new CoarseMapFactory());
270 coarseMapFact11->setStridingData(stridingInfo);
271 coarseMapFact11->setStridedBlockId(0);
272
273 //////////////////////////////// define factory manager for (1,1) block
274 RCP<FactoryManager> M11 = rcp(new FactoryManager());
275 M11->SetFactory("A", A11Fact);
276 M11->SetFactory("P", P11Fact);
277 M11->SetFactory("R", R11Fact);
278 M11->SetFactory("Aggregates", CoupledAggFact11);
279 M11->SetFactory("UnAmalgamationInfo", amalgFact11);
280 M11->SetFactory("Nullspace", nspFact11);
281 // M11->SetFactory("Ptent", P11tentFact);
282 M11->SetFactory("CoarseMap", coarseMapFact11);
283 #else
284 RCP<TentativePFactory> P11Fact = rcp(new TentativePFactory());
285
286 RCP<TransPFactory> R11Fact = rcp(new TransPFactory());
287
288 Teuchos::RCP<NullspaceFactory> nspFact11 = Teuchos::rcp(new NullspaceFactory("Nullspace1"));
289 nspFact11->SetFactory("Nullspace1", P11Fact);
290
291 RCP<CoarseMapFactory> coarseMapFact11 = Teuchos::rcp(new CoarseMapFactory());
292 coarseMapFact11->setStridingData(stridingInfo);
293 coarseMapFact11->setStridedBlockId(0);
294
295 //////////////////////////////// define factory manager for (1,1) block
296 RCP<FactoryManager> M11 = rcp(new FactoryManager());
297 M11->SetFactory("A", A11Fact);
298 M11->SetFactory("P", P11Fact);
299 M11->SetFactory("R", R11Fact);
300 M11->SetFactory("Aggregates", CoupledAggFact11);
301 M11->SetFactory("UnAmalgamationInfo", amalgFact11);
302 M11->SetFactory("Nullspace", nspFact11);
303 // M11->SetFactory("Ptent", P11Fact);
304 M11->SetFactory("CoarseMap", coarseMapFact11);
305 M11->SetFactory("Graph", dropFact11);
306 #endif
307 M11->SetIgnoreUserData(true); // always use data from factories defined in factory manager
308
309 ////////////////////////////////////////// prepare null space for A22
310 RCP<MultiVector> nullspace22 = MultiVectorFactory::Build(xstridedpremap, 1); // this is a 2D standard null space
311 Teuchos::ArrayRCP<Scalar> nsValues22 = nullspace22->getDataNonConst(0);
312 for (int j = 0; j < nsValues22.size(); ++j) {
313 nsValues22[j] = 1.0;
314 }
315
316 Finest->Set("Nullspace2", nullspace22);
317
318 ///////////////////////////////////////// define transfer ops for A22
319 #if 0
320 // use PGAMG
321 RCP<AmalgamationFactory> amalgFact22 = rcp(new AmalgamationFactory(A22Fact));
322 RCP<TentativePFactory> P22tentFact = rcp(new TentativePFactory(CoupledAggFact11, amalgFact22));
323
324 RCP<SaPFactory> P22Fact = rcp(new SaPFactory(P22tentFact));
325
326 //RCP<GenericRFactory> R22Fact = rcp(new GenericRFactory(P22Fact));
327 RCP<TransPFactory> R22Fact = rcp(new TransPFactory(P22Fact));
328
329 Teuchos::RCP<NullspaceFactory> nspFact22 = Teuchos::rcp(new NullspaceFactory("Nullspace2",P22tentFact));
330 RCP<CoarseMapFactory> coarseMapFact22 = Teuchos::rcp(new CoarseMapFactory(CoupledAggFact11, nspFact22));
331 coarseMapFact22->setStridingData(stridingInfo);
332 coarseMapFact22->setStridedBlockId(1);
333
334 //////////////////////////////// define factory manager for (2,2) block
335 RCP<FactoryManager> M22 = rcp(new FactoryManager());
336 M22->SetFactory("A", A22Fact);
337 M22->SetFactory("P", P22Fact);
338 M22->SetFactory("R", R22Fact);
339 M22->SetFactory("UnAmalgamationInfo", amalgFact22);
340 M22->SetFactory("Aggregates", AggFact22);
341 M22->SetFactory("Nullspace", nspFact22);
342 M22->SetFactory("Ptent", P22tentFact);
343 M22->SetFactory("CoarseMap", coarseMapFact22);
344 M22->SetIgnoreUserData(true); // always use data from factories defined in factory manager
345
346 #else
347 // use TentativePFactory
348 RCP<AmalgamationFactory> amalgFact22 = rcp(new AmalgamationFactory());
349 RCP<TentativePFactory> P22Fact = rcp(new TentativePFactory()); // check me (fed with A22) wrong column GIDS!!!
350
351 RCP<TransPFactory> R22Fact = rcp(new TransPFactory());
352
353 Teuchos::RCP<NullspaceFactory> nspFact22 = Teuchos::rcp(new NullspaceFactory("Nullspace2"));
354 nspFact22->SetFactory("Nullspace2", P22Fact);
355 RCP<CoarseMapFactory> coarseMapFact22 = Teuchos::rcp(new CoarseMapFactory());
356 coarseMapFact22->setStridingData(stridingInfo);
357 coarseMapFact22->setStridedBlockId(1);
358
359 //////////////////////////////// define factory manager for (2,2) block
360 RCP<FactoryManager> M22 = rcp(new FactoryManager());
361 M22->SetFactory("A", A22Fact);
362 M22->SetFactory("P", P22Fact);
363 M22->SetFactory("R", R22Fact);
364 M22->SetFactory("Aggregates", CoupledAggFact11);
365 M22->SetFactory("Nullspace", nspFact22);
366 M22->SetFactory("UnAmalgamationInfo", amalgFact22);
367 M22->SetFactory("Ptent", P22Fact);
368 M22->SetFactory("CoarseMap", coarseMapFact22);
369 M22->SetIgnoreUserData(true); // always use data from factories defined in factory manager
370 #endif
371
372 /////////////////////////////////////////// define blocked transfer ops
373 RCP<BlockedPFactory> PFact = rcp(new BlockedPFactory());
374 PFact->AddFactoryManager(M11);
375 PFact->AddFactoryManager(M22);
376
377 RCP<GenericRFactory> RFact = rcp(new GenericRFactory());
378 RFact->SetFactory("P", PFact);
379
380 RCP<Factory> AcFact = rcp(new BlockedRAPFactory());
381 AcFact->SetFactory("P", PFact);
382 AcFact->SetFactory("R", RFact);
383
384 *out << "Creating Simple Smoother" << std::endl;
385
386 //////////////////////////////////////////////////////////////////////
387 // Smoothers
388
389 RCP<SubBlockAFactory> A00Fact = Teuchos::rcp(new SubBlockAFactory());
390 A00Fact->SetFactory("A", MueLu::NoFactory::getRCP());
391 A00Fact->SetParameter("block row", Teuchos::ParameterEntry(0));
392 A00Fact->SetParameter("block col", Teuchos::ParameterEntry(0));
393 std::string ifpackTypePredictSmoother;
394 Teuchos::ParameterList ifpackListPredictSmoother;
395 ifpackListPredictSmoother.set("relaxation: sweeps", (LocalOrdinal)1);
396 ifpackListPredictSmoother.set("relaxation: damping factor", (Scalar)0.5);
397 ifpackTypePredictSmoother = "RELAXATION";
398 ifpackListPredictSmoother.set("relaxation: type", "Gauss-Seidel");
399 RCP<SmootherPrototype> smoProtoPredict = rcp(new TrilinosSmoother(ifpackTypePredictSmoother, ifpackListPredictSmoother, 0));
400 smoProtoPredict->SetFactory("A", A00Fact);
401 RCP<SmootherFactory> SmooPredictFact = rcp(new SmootherFactory(smoProtoPredict));
402
403 RCP<FactoryManager> MPredict = rcp(new FactoryManager());
404 MPredict->SetFactory("A", A00Fact); // SchurComplement operator for correction step (defined as "A")
405 MPredict->SetFactory("Smoother", SmooPredictFact); // solver/smoother for correction step
406 MPredict->SetFactory("PreSmoother", SmooPredictFact);
407 MPredict->SetFactory("PostSmoother", SmooPredictFact);
408 MPredict->SetIgnoreUserData(true); // always use data from factories defined in factory manager
409
410 ////////////////////////////////////////////////
411 // InverseApproximation
412 Teuchos::RCP<InverseApproximationFactory> AinvFact = Teuchos::rcp(new InverseApproximationFactory());
413 AinvFact->SetFactory("A", A11Fact);
414 AinvFact->SetParameter("inverse: approximation type", Teuchos::ParameterEntry(std::string("lumping")));
415
416 // SchurComp
417 // create SchurComp factory (SchurComplement smoother is provided by local FactoryManager)
418 Teuchos::RCP<SchurComplementFactory> SFact = Teuchos::rcp(new SchurComplementFactory());
419 SFact->SetParameter("omega", Teuchos::ParameterEntry(0.8));
420 SFact->SetFactory("A", MueLu::NoFactory::getRCP()); // 2x2 blocked operator
421 SFact->SetFactory("Ainv", AinvFact);
422
423 // define SchurComplement solver
424 std::string ifpackTypeSchurSmoother;
425 ifpackTypeSchurSmoother = "RELAXATION";
426 Teuchos::ParameterList ifpackListSchurSmoother;
427 ifpackListSchurSmoother.set("relaxation: sweeps", (LocalOrdinal)10);
428 ifpackListSchurSmoother.set("relaxation: damping factor", (Scalar)0.8);
429 ifpackListSchurSmoother.set("relaxation: type", "Gauss-Seidel");
430 RCP<SmootherPrototype> smoProtoSC = rcp(new TrilinosSmoother(ifpackTypeSchurSmoother, ifpackListSchurSmoother, 0));
431 smoProtoSC->SetFactory("A", SFact); // explicitely use SchurComplement matrix as input for smoother
432 RCP<SmootherFactory> SmooSCFact = rcp(new SmootherFactory(smoProtoSC));
433
434 // setup local factory manager for SchurComplementFactory
435 Teuchos::RCP<FactoryManager> MSchur = Teuchos::rcp(new FactoryManager());
436 MSchur->SetFactory("A", SFact); // SchurCompFactory as generating factory for SchurComp equation
437 MSchur->SetFactory("Smoother", SmooSCFact);
438 MSchur->SetIgnoreUserData(true);
439
440 /////////////////////////////////////////////////////
441 // create smoother prototype
442
443 RCP<SimpleSmoother> smootherPrototype = rcp(new SimpleSmoother());
444 smootherPrototype->SetParameter("Sweeps", Teuchos::ParameterEntry(3));
445 smootherPrototype->SetParameter("Damping factor", Teuchos::ParameterEntry(0.6));
446
447 smootherPrototype->AddFactoryManager(MPredict, 0); // set temporary factory manager for prediction step
448 smootherPrototype->AddFactoryManager(MSchur, 1); // set temporary factory manager for correction step
449 smootherPrototype->SetFactory("A", MueLu::NoFactory::getRCP());
450
451 /////////////////////////////////////////////////////
452 // create smoother factories
453 RCP<SmootherFactory> smootherFact = rcp(new SmootherFactory(smootherPrototype)); // pre and postsmoothing with SIMPLE on the finest and intermedium levels
454 RCP<SmootherFactory> coarseSmootherFact = rcp(new SmootherFactory(smootherPrototype, Teuchos::null)); // only presmoothing on finest level (we do not want to run two SIMPLE iterations on the coarsest level)
455
456 // main factory manager
457 FactoryManager M;
458 M.SetFactory("A", AcFact);
459 M.SetFactory("P", PFact);
460 M.SetFactory("R", RFact);
461 M.SetFactory("Smoother", smootherFact); // TODO fix me
462 M.SetFactory("CoarseSolver", coarseSmootherFact);
463
464 //////////////////////////////////// setup multigrid
465
466 H->Setup(M, 0, maxLevels);
467
468 Finest->print(*out);
469
470 RCP<Level> coarseLevel = H->GetLevel(1);
471 coarseLevel->print(*out);
472
473 // RCP<Level> coarseLevel2 = H->GetLevel(2);
474 // coarseLevel2->print(*out);
475
476 RCP<MultiVector> xLsg = MultiVectorFactory::Build(xstridedfullmap, 1);
477
478 // Use AMG directly as an iterative method
479 #if 0
480 {
481 xLsg->putScalar( (SC) 0.0);
482
483 // Epetra_Vector -> Xpetra::Vector
484 RCP<Vector> xRhs = Teuchos::rcp(new Xpetra::EpetraVector(epv));
485
486 // calculate initial (absolute) residual
487 Teuchos::Array<Teuchos::ScalarTraits<SC>::magnitudeType> norms(1);
488 xRhs->norm2(norms);
489 *out << "||x_0|| = " << norms[0] << std::endl;
490
491 // apply ten multigrid iterations
492 H->Iterate(*xRhs,*xLsg,100);
493
494
495 // calculate and print residual
496 RCP<MultiVector> xTmp = MultiVectorFactory::Build(xstridedfullmap,1);
497 bOp->apply(*xLsg,*xTmp,Teuchos::NO_TRANS,(SC)1.0,(SC)0.0);
498 xRhs->update((SC)-1.0,*xTmp,(SC)1.0);
499 xRhs->norm2(norms);
500 *out << "||x|| = " << norms[0] << std::endl;
501 }
502 #endif
503
504 //
505 // Solve Ax = b using AMG as a preconditioner in AztecOO
506 //
507 {
508 RCP<Epetra_Vector> X = rcp(new Epetra_Vector(epv->Map()));
509 X->PutScalar(0.0);
510 Epetra_LinearProblem epetraProblem(epA.get(), X.get(), epv.get());
511
512 AztecOO aztecSolver(epetraProblem);
513 aztecSolver.SetAztecOption(AZ_solver, AZ_gmres);
514
515 MueLu::EpetraOperator aztecPrec(H);
516 aztecSolver.SetPrecOperator(&aztecPrec);
517
518 int maxIts = 50;
519 double tol = 1e-8;
520
521 aztecSolver.Iterate(maxIts, tol);
522 }
523
524 success = true;
525 }
526 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
527
528 return (success ? EXIT_SUCCESS : EXIT_FAILURE);
529 #else
530 std::cout << "Epetra (and/or EpetraExt) are not available. Skip test." << std::endl;
531 return EXIT_SUCCESS;
532 #endif // #if defined(HAVE_MUELU_SERIAL) && defined(HAVE_MUELU_EPETRA)
533 }