Debian Codegraph @

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