| 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_StandardCatchMacros.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_EpetraMap.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_CoarseMapFactory.hpp" |
| 74 |
#include "MueLu_AmalgamationFactory.hpp" |
| 75 |
|
| 76 |
#include <Epetra_LinearProblem.h> |
| 77 |
#include <AztecOO.h> |
| 78 |
|
| 79 |
#include "Navier2D_Helpers.h" |
| 80 |
|
| 81 |
/*! |
| 82 |
* 2d Navier Stokes example (for Epetra) |
| 83 |
* |
| 84 |
* using block matrices |
| 85 |
*/ |
| 86 |
|
| 87 |
int main(int argc, char* argv[]) { |
| 88 |
#if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT) |
| 89 |
typedef double Scalar; |
| 90 |
typedef int LocalOrdinal; |
| 91 |
typedef int GlobalOrdinal; |
| 92 |
typedef LocalOrdinal LO; |
| 93 |
typedef GlobalOrdinal GO; |
| 94 |
typedef Xpetra::EpetraNode Node; |
| 95 |
#include "MueLu_UseShortNames.hpp" |
| 96 |
|
| 97 |
using Teuchos::RCP; |
| 98 |
using Teuchos::rcp; |
| 99 |
using namespace MueLuTests; |
| 100 |
using namespace Teuchos; |
| 101 |
|
| 102 |
oblackholestream blackhole; |
| 103 |
GlobalMPISession mpiSession(&argc, &argv, &blackhole); |
| 104 |
|
| 105 |
bool success = false; |
| 106 |
bool verbose = true; |
| 107 |
try { |
| 108 |
// default parameters |
| 109 |
LO BGS_nSweeps = 3; |
| 110 |
Scalar BGS_omega = 1.0; |
| 111 |
|
| 112 |
// Note: use --help to list available options. |
| 113 |
CommandLineProcessor clp(false); |
| 114 |
clp.setOption("BGS_sweeps", &BGS_nSweeps, "number of sweeps with BGS smoother"); |
| 115 |
clp.setOption("BGS_omega", &BGS_omega, "scaling factor for BGS smoother"); |
| 116 |
|
| 117 |
switch (clp.parse(argc, argv)) { |
| 118 |
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; |
| 119 |
case Teuchos::CommandLineProcessor::PARSE_ERROR: |
| 120 |
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; |
| 121 |
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; |
| 122 |
} |
| 123 |
|
| 124 |
RCP<const Comm<int> > comm = DefaultComm<int>::getComm(); |
| 125 |
RCP<FancyOStream> out = fancyOStream(rcpFromRef(std::cout)); |
| 126 |
out->setOutputToRootOnly(0); |
| 127 |
*out << MueLu::MemUtils::PrintMemoryUsage() << std::endl; |
| 128 |
|
| 129 |
// Timing |
| 130 |
Time myTime("global"); |
| 131 |
TimeMonitor MM(myTime); |
| 132 |
|
| 133 |
// custom parameters |
| 134 |
LO maxLevels = 2; // TODO: singular system if MaxLevels > 2? |
| 135 |
|
| 136 |
GO maxCoarseSize = 1; // FIXME clp doesn't like long long int |
| 137 |
|
| 138 |
int globalNumDofs = 1500; // used for the maps |
| 139 |
int nDofsPerNode = 3; // used for generating the fine level null-space |
| 140 |
|
| 141 |
// build strided maps |
| 142 |
// striding information: 2 velocity dofs and 1 pressure dof = 3 dofs per node |
| 143 |
std::vector<size_t> stridingInfo; |
| 144 |
stridingInfo.push_back(2); |
| 145 |
stridingInfo.push_back(1); |
| 146 |
|
| 147 |
/////////////////////////////////////// build strided maps |
| 148 |
// build strided maps: |
| 149 |
// xstridedfullmap: full map (velocity and pressure dof gids), continous |
| 150 |
// xstridedvelmap: only velocity dof gid maps (i.e. 0,1,3,4,6,7...) |
| 151 |
// xstridedpremap: only pressure dof gid maps (i.e. 2,5,8,...) |
| 152 |
Xpetra::UnderlyingLib lib = Xpetra::UseEpetra; |
| 153 |
RCP<const StridedMap> xstridedfullmap = StridedMapFactory::Build(lib, globalNumDofs, 0, stridingInfo, comm, -1); |
| 154 |
RCP<const StridedMap> xstridedvelmap = StridedMapFactory::Build(xstridedfullmap, 0); |
| 155 |
RCP<const StridedMap> xstridedpremap = StridedMapFactory::Build(xstridedfullmap, 1); |
| 156 |
|
| 157 |
/////////////////////////////////////// transform Xpetra::Map objects to Epetra |
| 158 |
// this is needed for AztecOO |
| 159 |
const RCP<const Epetra_Map> fullmap = rcpFromRef(Xpetra::toEpetra(*xstridedfullmap)); |
| 160 |
RCP<const Epetra_Map> velmap = rcpFromRef(Xpetra::toEpetra(*xstridedvelmap)); |
| 161 |
RCP<const Epetra_Map> premap = rcpFromRef(Xpetra::toEpetra(*xstridedpremap)); |
| 162 |
|
| 163 |
/////////////////////////////////////// import problem matrix and RHS from files (-> Epetra) |
| 164 |
|
| 165 |
// read in problem |
| 166 |
Epetra_CrsMatrix* ptrA = 0; |
| 167 |
Epetra_Vector* ptrf = 0; |
| 168 |
Epetra_MultiVector* ptrNS = 0; |
| 169 |
|
| 170 |
*out << "Reading matrix market file" << std::endl; |
| 171 |
EpetraExt::MatrixMarketFileToCrsMatrix("A_re1000_5932.txt", *fullmap, *fullmap, *fullmap, ptrA); |
| 172 |
EpetraExt::MatrixMarketFileToVector("b_re1000_5932.txt", *fullmap, ptrf); |
| 173 |
RCP<Epetra_CrsMatrix> epA = rcp(ptrA); |
| 174 |
RCP<Epetra_Vector> epv = rcp(ptrf); |
| 175 |
RCP<Epetra_MultiVector> epNS = rcp(ptrNS); |
| 176 |
|
| 177 |
/////////////////////////////////////// split system into 2x2 block system |
| 178 |
|
| 179 |
*out << "Split matrix into 2x2 block matrix" << std::endl; |
| 180 |
|
| 181 |
// split fullA into A11,..., A22 |
| 182 |
RCP<Epetra_CrsMatrix> A11; |
| 183 |
RCP<Epetra_CrsMatrix> A12; |
| 184 |
RCP<Epetra_CrsMatrix> A21; |
| 185 |
RCP<Epetra_CrsMatrix> A22; |
| 186 |
|
| 187 |
if (SplitMatrix2x2(epA, *velmap, *premap, A11, A12, A21, A22) == false) |
| 188 |
*out << "Problem with splitting matrix" << std::endl; |
| 189 |
|
| 190 |
/////////////////////////////////////// transform Epetra objects to Xpetra (needed for MueLu) |
| 191 |
|
| 192 |
// build Xpetra objects from Epetra_CrsMatrix objects |
| 193 |
RCP<Xpetra::CrsMatrix<Scalar, LO, GO, Node> > xA11 = rcp(new Xpetra::EpetraCrsMatrixT<GO, Node>(A11)); |
| 194 |
RCP<Xpetra::CrsMatrix<Scalar, LO, GO, Node> > xA12 = rcp(new Xpetra::EpetraCrsMatrixT<GO, Node>(A12)); |
| 195 |
RCP<Xpetra::CrsMatrix<Scalar, LO, GO, Node> > xA21 = rcp(new Xpetra::EpetraCrsMatrixT<GO, Node>(A21)); |
| 196 |
RCP<Xpetra::CrsMatrix<Scalar, LO, GO, Node> > xA22 = rcp(new Xpetra::EpetraCrsMatrixT<GO, Node>(A22)); |
| 197 |
|
| 198 |
/////////////////////////////////////// generate MapExtractor object |
| 199 |
|
| 200 |
std::vector<RCP<const Xpetra::Map<LO, GO, Node> > > xmaps; |
| 201 |
xmaps.push_back(xstridedvelmap); |
| 202 |
xmaps.push_back(xstridedpremap); |
| 203 |
|
| 204 |
RCP<const Xpetra::MapExtractor<Scalar, LO, GO, Node> > map_extractor = Xpetra::MapExtractorFactory<Scalar, LO, GO, Node>::Build(xstridedfullmap, xmaps); |
| 205 |
|
| 206 |
/////////////////////////////////////// build blocked transfer operator |
| 207 |
// using the map extractor |
| 208 |
RCP<Xpetra::BlockedCrsMatrix<Scalar, LO, GO, Node> > bOp = rcp(new Xpetra::BlockedCrsMatrix<Scalar, LO, GO, Node>(map_extractor, map_extractor, 10)); |
| 209 |
bOp->setMatrix(0, 0, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA11))); |
| 210 |
bOp->setMatrix(0, 1, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA12))); |
| 211 |
bOp->setMatrix(1, 0, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA21))); |
| 212 |
bOp->setMatrix(1, 1, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA22))); |
| 213 |
|
| 214 |
bOp->fillComplete(); |
| 215 |
|
| 216 |
//////////////////////////////////////////////////// create Hierarchy |
| 217 |
RCP<Hierarchy> H = rcp(new Hierarchy()); |
| 218 |
H->setDefaultVerbLevel(VERB_HIGH); |
| 219 |
H->SetMaxCoarseSize(maxCoarseSize); |
| 220 |
|
| 221 |
//////////////////////////////////////////////////////// finest Level |
| 222 |
RCP<MueLu::Level> Finest = H->GetLevel(); |
| 223 |
Finest->setDefaultVerbLevel(VERB_HIGH); |
| 224 |
Finest->Set("A", rcp_dynamic_cast<Matrix>(bOp)); |
| 225 |
|
| 226 |
/////////////////////////////////////////////// define subblocks of A |
| 227 |
// make A11 block and A22 block available as variable "A" generated |
| 228 |
// by A11Fact and A22Fact |
| 229 |
RCP<SubBlockAFactory> A11Fact = rcp(new SubBlockAFactory()); |
| 230 |
A11Fact->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 231 |
A11Fact->SetParameter("block row", ParameterEntry(0)); |
| 232 |
A11Fact->SetParameter("block col", ParameterEntry(0)); |
| 233 |
RCP<SubBlockAFactory> A22Fact = rcp(new SubBlockAFactory()); |
| 234 |
A22Fact->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 235 |
A22Fact->SetParameter("block row", ParameterEntry(1)); |
| 236 |
A22Fact->SetParameter("block col", ParameterEntry(1)); |
| 237 |
|
| 238 |
///////////////////////////////////////////// define smoother for A11 |
| 239 |
// define block smoother for the first block matrix row in BlockGaussSeidel Smoother |
| 240 |
std::string ifpack11Type; |
| 241 |
ParameterList ifpack11List; |
| 242 |
ifpack11List.set("relaxation: sweeps", (LO)3); |
| 243 |
ifpack11List.set("relaxation: damping factor", (SC)0.5); |
| 244 |
ifpack11Type = "RELAXATION"; |
| 245 |
ifpack11List.set("relaxation: type", "Gauss-Seidel"); |
| 246 |
RCP<SmootherPrototype> smoProto11 = rcp(new TrilinosSmoother(ifpack11Type, ifpack11List, 0)); |
| 247 |
smoProto11->SetFactory("A", A11Fact); |
| 248 |
RCP<SmootherFactory> Smoo11Fact = rcp(new SmootherFactory(smoProto11)); |
| 249 |
|
| 250 |
////////////////////////////////////////// prepare null space for A11 |
| 251 |
RCP<MultiVector> nullspace11 = MultiVectorFactory::Build(xstridedvelmap, 2); // this is a 2D standard null space |
| 252 |
|
| 253 |
for (int i = 0; i < nDofsPerNode - 1; ++i) { |
| 254 |
ArrayRCP<Scalar> nsValues = nullspace11->getDataNonConst(i); |
| 255 |
int numBlocks = nsValues.size() / (nDofsPerNode - 1); |
| 256 |
for (int j = 0; j < numBlocks; ++j) { |
| 257 |
nsValues[j * (nDofsPerNode - 1) + i] = 1.0; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
Finest->Set("Nullspace1", nullspace11); |
| 262 |
|
| 263 |
///////////////////////////////////////// define CoalesceDropFactory and Aggregation for A11 |
| 264 |
// set up amalgamation for A11. Note: we're using a default null space factory (null) |
| 265 |
RCP<AmalgamationFactory> amalgFact11 = rcp(new AmalgamationFactory()); |
| 266 |
amalgFact11->SetFactory("A", A11Fact); |
| 267 |
RCP<CoalesceDropFactory> dropFact11 = rcp(new CoalesceDropFactory()); |
| 268 |
dropFact11->SetFactory("A", A11Fact); |
| 269 |
dropFact11->SetFactory("UnAmalgamationInfo", amalgFact11); |
| 270 |
RCP<UncoupledAggregationFactory> CoupledAggFact11 = rcp(new UncoupledAggregationFactory()); |
| 271 |
CoupledAggFact11->SetFactory("Graph", dropFact11); |
| 272 |
CoupledAggFact11->SetMinNodesPerAggregate(5); |
| 273 |
CoupledAggFact11->SetMaxNeighAlreadySelected(1); |
| 274 |
CoupledAggFact11->SetOrdering("natural"); |
| 275 |
|
| 276 |
///////////////////////////////////////// define transfer ops for A11 |
| 277 |
#if 0 |
| 278 |
// use PG-AMG |
| 279 |
RCP<TentativePFactory> P11tentFact = rcp(new TentativePFactory()); // check me |
| 280 |
|
| 281 |
RCP<PgPFactory> P11Fact = rcp(new PgPFactory()); |
| 282 |
|
| 283 |
RCP<GenericRFactory> R11Fact = rcp(new GenericRFactory()); |
| 284 |
|
| 285 |
RCP<NullspaceFactory> nspFact11 = rcp(new NullspaceFactory("Nullspace1")); |
| 286 |
nspFact11->SetFactory("Nullspace1", P11tentFact); |
| 287 |
|
| 288 |
RCP<CoarseMapFactory> coarseMapFact11 = rcp(new CoarseMapFactory()); |
| 289 |
coarseMapFact11->setStridingData(stridingInfo); |
| 290 |
coarseMapFact11->setStridedBlockId(0); |
| 291 |
|
| 292 |
//////////////////////////////// define factory manager for (1,1) block |
| 293 |
RCP<FactoryManager> M11 = rcp(new FactoryManager()); |
| 294 |
M11->SetFactory("A", A11Fact); |
| 295 |
M11->SetFactory("P", P11Fact); |
| 296 |
M11->SetFactory("R", R11Fact); |
| 297 |
M11->SetFactory("Nullspace", nspFact11); |
| 298 |
M11->SetFactory("Aggregates", CoupledAggFact11); |
| 299 |
M11->SetFactory("UnAmalgamationInfo", amalgFact11); |
| 300 |
M11->SetFactory("Ptent", P11tentFact); |
| 301 |
M11->SetFactory("Smoother", Smoo11Fact); |
| 302 |
M11->SetFactory("CoarseMap", coarseMapFact11); |
| 303 |
|
| 304 |
#else |
| 305 |
|
| 306 |
RCP<TentativePFactory> P11Fact = rcp(new TentativePFactory()); |
| 307 |
|
| 308 |
RCP<TransPFactory> R11Fact = rcp(new TransPFactory()); |
| 309 |
|
| 310 |
RCP<NullspaceFactory> nspFact11 = rcp(new NullspaceFactory("Nullspace1")); |
| 311 |
nspFact11->SetFactory("Nullspace1", P11Fact); |
| 312 |
|
| 313 |
RCP<CoarseMapFactory> coarseMapFact11 = rcp(new CoarseMapFactory()); |
| 314 |
coarseMapFact11->setStridingData(stridingInfo); |
| 315 |
coarseMapFact11->setStridedBlockId(0); |
| 316 |
|
| 317 |
//////////////////////////////// define factory manager for (1,1) block |
| 318 |
RCP<FactoryManager> M11 = rcp(new FactoryManager()); |
| 319 |
M11->SetFactory("A", A11Fact); |
| 320 |
M11->SetFactory("P", P11Fact); |
| 321 |
M11->SetFactory("R", R11Fact); |
| 322 |
M11->SetFactory("Graph", dropFact11); |
| 323 |
M11->SetFactory("Aggregates", CoupledAggFact11); |
| 324 |
M11->SetFactory("UnAmalgamationInfo", amalgFact11); |
| 325 |
M11->SetFactory("Nullspace", nspFact11); |
| 326 |
M11->SetFactory("Ptent", P11Fact); |
| 327 |
M11->SetFactory("Smoother", Smoo11Fact); |
| 328 |
M11->SetFactory("CoarseMap", coarseMapFact11); |
| 329 |
|
| 330 |
#if OLD |
| 331 |
RCP<TentativePFactory> P11Fact = rcp(new TentativePFactory(CoupledAggFact11, amalgFact11)); // check me |
| 332 |
|
| 333 |
RCP<TransPFactory> R11Fact = rcp(new TransPFactory(P11Fact)); |
| 334 |
|
| 335 |
RCP<NullspaceFactory> nspFact11 = rcp(new NullspaceFactory("Nullspace1", P11Fact)); |
| 336 |
|
| 337 |
RCP<CoarseMapFactory> coarseMapFact11 = rcp(new CoarseMapFactory(CoupledAggFact11, nspFact11)); |
| 338 |
coarseMapFact11->setStridingData(stridingInfo); |
| 339 |
coarseMapFact11->setStridedBlockId(0); |
| 340 |
|
| 341 |
//////////////////////////////// define factory manager for (1,1) block |
| 342 |
RCP<FactoryManager> M11 = rcp(new FactoryManager()); |
| 343 |
M11->SetFactory("A", A11Fact); |
| 344 |
M11->SetFactory("P", P11Fact); |
| 345 |
M11->SetFactory("R", R11Fact); |
| 346 |
M11->SetFactory("Nullspace", nspFact11); |
| 347 |
M11->SetFactory("Ptent", P11Fact); |
| 348 |
M11->SetFactory("Smoother", Smoo11Fact); |
| 349 |
M11->SetFactory("CoarseMap", coarseMapFact11); |
| 350 |
#endif // TODO remove this |
| 351 |
|
| 352 |
#endif |
| 353 |
M11->SetIgnoreUserData(true); // always use data from factories defined in factory manager |
| 354 |
|
| 355 |
///////////////////////////////////////////// define smoother for A22 |
| 356 |
std::string ifpack22Type; |
| 357 |
ParameterList ifpack22List; |
| 358 |
ifpack22List.set("relaxation: sweeps", (LO)1); |
| 359 |
ifpack22List.set("relaxation: damping factor", (SC)0.3); |
| 360 |
ifpack22Type = "RELAXATION"; |
| 361 |
ifpack22List.set("relaxation: type", "Gauss-Seidel"); |
| 362 |
RCP<SmootherPrototype> smoProto22 = rcp(new TrilinosSmoother(ifpack22Type, ifpack22List, 0)); |
| 363 |
smoProto22->SetFactory("A", A22Fact); |
| 364 |
RCP<SmootherFactory> Smoo22Fact = rcp(new SmootherFactory(smoProto22)); |
| 365 |
|
| 366 |
////////////////////////////////////////// prepare null space for A22 |
| 367 |
RCP<MultiVector> nullspace22 = MultiVectorFactory::Build(xstridedpremap, 1); // this is a 2D standard null space |
| 368 |
ArrayRCP<Scalar> nsValues22 = nullspace22->getDataNonConst(0); |
| 369 |
for (int j = 0; j < nsValues22.size(); ++j) { |
| 370 |
nsValues22[j] = 1.0; |
| 371 |
} |
| 372 |
|
| 373 |
Finest->Set("Nullspace2", nullspace22); |
| 374 |
|
| 375 |
///////////////////////////////////////// define transfer ops for A22 |
| 376 |
#if 0 |
| 377 |
// use PGAMG |
| 378 |
RCP<AmalgamationFactory> amalgFact22 = rcp(new AmalgamationFactory(A22Fact)); |
| 379 |
RCP<TentativePFactory> P22tentFact = rcp(new TentativePFactory(CoupledAggFact11, amalgFact22)); // check me (fed with A22) wrong column GIDS!!! |
| 380 |
|
| 381 |
RCP<SaPFactory> P22Fact = rcp(new SaPFactory(P22tentFact)); |
| 382 |
|
| 383 |
//RCP<GenericRFactory> R22Fact = rcp(new GenericRFactory(P22Fact)); |
| 384 |
RCP<TransPFactory> R22Fact = rcp(new TransPFactory(P22Fact)); |
| 385 |
|
| 386 |
RCP<NullspaceFactory> nspFact22 = rcp(new NullspaceFactory("Nullspace2",P22tentFact)); |
| 387 |
|
| 388 |
RCP<CoarseMapFactory> coarseMapFact22 = rcp(new CoarseMapFactory(CoupledAggFact11, nspFact22)); |
| 389 |
coarseMapFact22->setStridingData(stridingInfo); |
| 390 |
coarseMapFact22->setStridedBlockId(1); |
| 391 |
|
| 392 |
//////////////////////////////// define factory manager for (2,2) block |
| 393 |
RCP<FactoryManager> M22 = rcp(new FactoryManager()); |
| 394 |
M22->SetFactory("A", A22Fact); |
| 395 |
M22->SetFactory("P", P22Fact); |
| 396 |
M22->SetFactory("R", R22Fact); |
| 397 |
M22->SetFactory("UnAmalgamationInfo", amalgFact22); |
| 398 |
M22->SetFactory("Aggregates", AggFact22); |
| 399 |
M22->SetFactory("Nullspace", nspFact22); |
| 400 |
M22->SetFactory("Ptent", P22tentFact); |
| 401 |
M22->SetFactory("Smoother", Smoo22Fact); |
| 402 |
M22->SetFactory("CoarseMap", coarseMapFact22); |
| 403 |
M22->SetIgnoreUserData(true); // always use data from factories defined in factory manager |
| 404 |
|
| 405 |
#else |
| 406 |
// use TentativePFactory |
| 407 |
RCP<AmalgamationFactory> amalgFact22 = rcp(new AmalgamationFactory()); |
| 408 |
RCP<TentativePFactory> P22Fact = rcp(new TentativePFactory()); // check me (fed with A22) wrong column GIDS!!! |
| 409 |
|
| 410 |
RCP<TransPFactory> R22Fact = rcp(new TransPFactory()); |
| 411 |
|
| 412 |
RCP<NullspaceFactory> nspFact22 = rcp(new NullspaceFactory("Nullspace2")); |
| 413 |
nspFact22->SetFactory("Nullspace2", P22Fact); |
| 414 |
|
| 415 |
RCP<CoarseMapFactory> coarseMapFact22 = rcp(new CoarseMapFactory()); |
| 416 |
coarseMapFact22->setStridingData(stridingInfo); |
| 417 |
coarseMapFact22->setStridedBlockId(1); |
| 418 |
|
| 419 |
//////////////////////////////// define factory manager for (2,2) block |
| 420 |
RCP<FactoryManager> M22 = rcp(new FactoryManager()); |
| 421 |
M22->SetFactory("A", A22Fact); |
| 422 |
M22->SetFactory("P", P22Fact); |
| 423 |
M22->SetFactory("R", R22Fact); |
| 424 |
M22->SetFactory("UnAmalgamationInfo", amalgFact22); |
| 425 |
M22->SetFactory("Aggregates", CoupledAggFact11); |
| 426 |
M22->SetFactory("Nullspace", nspFact22); |
| 427 |
M22->SetFactory("Ptent", P22Fact); |
| 428 |
M22->SetFactory("Smoother", Smoo22Fact); |
| 429 |
M22->SetFactory("CoarseMap", coarseMapFact22); |
| 430 |
M22->SetIgnoreUserData(true); // always use data from factories defined in factory manager |
| 431 |
#endif |
| 432 |
|
| 433 |
/////////////////////////////////////////// define blocked transfer ops |
| 434 |
RCP<BlockedPFactory> PFact = rcp(new BlockedPFactory()); // use row map index base from bOp |
| 435 |
PFact->AddFactoryManager(M11); |
| 436 |
PFact->AddFactoryManager(M22); |
| 437 |
|
| 438 |
RCP<GenericRFactory> RFact = rcp(new GenericRFactory()); |
| 439 |
RFact->SetFactory("P", PFact); |
| 440 |
|
| 441 |
RCP<Factory> AcFact = rcp(new BlockedRAPFactory()); |
| 442 |
AcFact->SetFactory("P", PFact); |
| 443 |
AcFact->SetFactory("R", RFact); |
| 444 |
|
| 445 |
////////////////////////////////////////////////////////////////////// |
| 446 |
// Smoothers |
| 447 |
RCP<BlockedGaussSeidelSmoother> smootherPrototype = rcp(new BlockedGaussSeidelSmoother()); |
| 448 |
smootherPrototype->SetParameter("Sweeps", Teuchos::ParameterEntry(BGS_nSweeps)); |
| 449 |
smootherPrototype->SetParameter("Damping factor", Teuchos::ParameterEntry(BGS_omega)); |
| 450 |
smootherPrototype->AddFactoryManager(M11, 0); |
| 451 |
smootherPrototype->AddFactoryManager(M22, 1); |
| 452 |
RCP<SmootherFactory> smootherFact = rcp(new SmootherFactory(smootherPrototype)); |
| 453 |
|
| 454 |
// Coarse grid correction |
| 455 |
RCP<BlockedGaussSeidelSmoother> coarseSolverPrototype = rcp(new BlockedGaussSeidelSmoother()); |
| 456 |
coarseSolverPrototype->SetParameter("Sweeps", Teuchos::ParameterEntry(BGS_nSweeps)); |
| 457 |
coarseSolverPrototype->SetParameter("Damping factor", Teuchos::ParameterEntry(BGS_omega)); |
| 458 |
coarseSolverPrototype->AddFactoryManager(M11, 0); |
| 459 |
coarseSolverPrototype->AddFactoryManager(M22, 1); |
| 460 |
RCP<SmootherFactory> coarseSolverFact = rcp(new SmootherFactory(coarseSolverPrototype, null)); |
| 461 |
|
| 462 |
// main factory manager |
| 463 |
FactoryManager M; |
| 464 |
M.SetFactory("A", AcFact); |
| 465 |
M.SetFactory("P", PFact); |
| 466 |
M.SetFactory("R", RFact); |
| 467 |
M.SetFactory("Smoother", smootherFact); // TODO fix me |
| 468 |
M.SetFactory("PreSmoother", smootherFact); // TODO fix me |
| 469 |
M.SetFactory("PostSmoother", smootherFact); // TODO fix me |
| 470 |
M.SetFactory("CoarseSolver", coarseSolverFact); |
| 471 |
|
| 472 |
//////////////////////////////////// setup multigrid |
| 473 |
|
| 474 |
H->Setup(M, 0, maxLevels); |
| 475 |
|
| 476 |
*out << std::endl; |
| 477 |
*out << "print content of multigrid levels:" << std::endl; |
| 478 |
|
| 479 |
Finest->print(*out); |
| 480 |
|
| 481 |
RCP<Level> coarseLevel = H->GetLevel(1); |
| 482 |
coarseLevel->print(*out); |
| 483 |
|
| 484 |
// RCP<Level> coarseLevel2 = H->GetLevel(2); |
| 485 |
// coarseLevel2->print(*out); |
| 486 |
|
| 487 |
RCP<MultiVector> xLsg = MultiVectorFactory::Build(xstridedfullmap, 1); |
| 488 |
|
| 489 |
// Use AMG directly as an iterative method |
| 490 |
{ |
| 491 |
xLsg->putScalar((SC)0.0); |
| 492 |
|
| 493 |
// Epetra_Vector -> Xpetra::Vector |
| 494 |
RCP<Vector> xRhs = rcp(new Xpetra::EpetraVectorT<int, Node>(epv)); |
| 495 |
|
| 496 |
// calculate initial (absolute) residual |
| 497 |
Array<ScalarTraits<SC>::magnitudeType> norms(1); |
| 498 |
xRhs->norm2(norms); |
| 499 |
*out << "||x_0|| = " << norms[0] << std::endl; |
| 500 |
|
| 501 |
// apply ten multigrid iterations |
| 502 |
H->Iterate(*xRhs, *xLsg, 100); |
| 503 |
|
| 504 |
// calculate and print residual |
| 505 |
RCP<MultiVector> xTmp = MultiVectorFactory::Build(xstridedfullmap, 1); |
| 506 |
bOp->apply(*xLsg, *xTmp, NO_TRANS, (SC)1.0, (SC)0.0); |
| 507 |
xRhs->update((SC)-1.0, *xTmp, (SC)1.0); |
| 508 |
xRhs->norm2(norms); |
| 509 |
*out << "||r|| = " << norms[0] << std::endl; |
| 510 |
} |
| 511 |
|
| 512 |
// TODO: don't forget to add Aztec as prerequisite in CMakeLists.txt! |
| 513 |
// |
| 514 |
// Solve Ax = b using AMG as a preconditioner in AztecOO |
| 515 |
// |
| 516 |
{ |
| 517 |
RCP<Epetra_Vector> X = rcp(new Epetra_Vector(epv->Map())); |
| 518 |
X->PutScalar(0.0); |
| 519 |
Epetra_LinearProblem epetraProblem(epA.get(), X.get(), epv.get()); |
| 520 |
|
| 521 |
AztecOO aztecSolver(epetraProblem); |
| 522 |
aztecSolver.SetAztecOption(AZ_solver, AZ_gmres); |
| 523 |
|
| 524 |
MueLu::EpetraOperator aztecPrec(H); |
| 525 |
aztecSolver.SetPrecOperator(&aztecPrec); |
| 526 |
|
| 527 |
int maxIts = 50; |
| 528 |
double tol = 1e-8; |
| 529 |
|
| 530 |
aztecSolver.Iterate(maxIts, tol); |
| 531 |
} |
| 532 |
|
| 533 |
success = true; |
| 534 |
} |
| 535 |
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); |
| 536 |
|
| 537 |
return (success ? EXIT_SUCCESS : EXIT_FAILURE); |
| 538 |
#else |
| 539 |
std::cout << "Epetra (and/or EpetraExt) are not available. Skip test." << std::endl; |
| 540 |
return EXIT_SUCCESS; |
| 541 |
#endif // #if defined(HAVE_MUELU_SERIAL) && defined(HAVE_MUELU_EPETRA) |
| 542 |
} |