| 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 <unistd.h> |
| 11 |
#include <iostream> |
| 12 |
#include <fstream> |
| 13 |
|
| 14 |
// Teuchos |
| 15 |
#include <Teuchos_RCP.hpp> |
| 16 |
#include <Teuchos_ParameterList.hpp> |
| 17 |
#include <Teuchos_CommandLineProcessor.hpp> |
| 18 |
#include <Teuchos_GlobalMPISession.hpp> |
| 19 |
#include <Teuchos_DefaultComm.hpp> |
| 20 |
#include <Teuchos_ArrayRCP.hpp> |
| 21 |
#include <Teuchos_ScalarTraits.hpp> |
| 22 |
#include <Teuchos_StandardCatchMacros.hpp> |
| 23 |
|
| 24 |
// Epetra |
| 25 |
#include <EpetraExt_CrsMatrixIn.h> |
| 26 |
#include <EpetraExt_VectorIn.h> |
| 27 |
#include <EpetraExt_MultiVectorIn.h> |
| 28 |
|
| 29 |
// Xpetra |
| 30 |
#include <Xpetra_Map.hpp> |
| 31 |
#include <Xpetra_MapFactory.hpp> |
| 32 |
#include <Xpetra_Matrix.hpp> |
| 33 |
#include <Xpetra_CrsMatrixWrap.hpp> |
| 34 |
#include <Xpetra_MultiVectorFactory.hpp> |
| 35 |
#include <Xpetra_VectorFactory.hpp> |
| 36 |
#include <Xpetra_Parameters.hpp> |
| 37 |
#include <Xpetra_MapExtractorFactory.hpp> |
| 38 |
#include <Xpetra_BlockedCrsMatrix.hpp> |
| 39 |
#include <Xpetra_StridedMapFactory.hpp> |
| 40 |
#include <Xpetra_StridedMap.hpp> |
| 41 |
|
| 42 |
// MueLu |
| 43 |
#include "MueLu_ConfigDefs.hpp" |
| 44 |
#include "MueLu_Memory.hpp" |
| 45 |
#include "MueLu_Hierarchy.hpp" |
| 46 |
#include "MueLu_UncoupledAggregationFactory.hpp" |
| 47 |
#include "MueLu_PgPFactory.hpp" |
| 48 |
#include "MueLu_GenericRFactory.hpp" |
| 49 |
#include "MueLu_SaPFactory.hpp" |
| 50 |
#include "MueLu_TransPFactory.hpp" |
| 51 |
#include "MueLu_BlockedRAPFactory.hpp" |
| 52 |
#include "MueLu_TrilinosSmoother.hpp" |
| 53 |
#include "MueLu_Utilities.hpp" |
| 54 |
#include "MueLu_Exceptions.hpp" |
| 55 |
#include "MueLu_Aggregates.hpp" |
| 56 |
#include "MueLu_CoalesceDropFactory.hpp" |
| 57 |
#include "MueLu_PreDropFunctionConstVal.hpp" |
| 58 |
#include "MueLu_NullspaceFactory.hpp" |
| 59 |
#include "MueLu_TentativePFactory.hpp" |
| 60 |
#include "MueLu_SmootherFactory.hpp" |
| 61 |
#include "MueLu_DirectSolver.hpp" |
| 62 |
#include "MueLu_EpetraOperator.hpp" |
| 63 |
#include "MueLu_SubBlockAFactory.hpp" |
| 64 |
#include "MueLu_BlockedPFactory.hpp" |
| 65 |
#include "MueLu_BlockedGaussSeidelSmoother.hpp" |
| 66 |
#include "MueLu_SchurComplementFactory.hpp" |
| 67 |
#include "MueLu_BraessSarazinSmoother.hpp" |
| 68 |
|
| 69 |
#include "MueLu_CoarseMapFactory.hpp" |
| 70 |
|
| 71 |
#include "MueLu_AmalgamationFactory.hpp" |
| 72 |
#include "MueLu_AggregationExportFactory.hpp" |
| 73 |
|
| 74 |
#if defined(HAVE_MPI) && defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MUELU_ISORROPIA) |
| 75 |
#include "MueLu_RepartitionFactory.hpp" |
| 76 |
#include "MueLu_RepartitionHeuristicFactory.hpp" |
| 77 |
#include "MueLu_RebalanceTransferFactory.hpp" |
| 78 |
#include "MueLu_IsorropiaInterface.hpp" |
| 79 |
#include "MueLu_RebalanceBlockAcFactory.hpp" |
| 80 |
#include "MueLu_RebalanceBlockInterpolationFactory.hpp" |
| 81 |
#include "MueLu_RebalanceBlockRestrictionFactory.hpp" |
| 82 |
#include "MueLu_RepartitionInterface.hpp" |
| 83 |
#include "MueLu_CloneRepartitionInterface.hpp" |
| 84 |
#endif |
| 85 |
|
| 86 |
#include <Epetra_LinearProblem.h> |
| 87 |
#include <AztecOO.h> |
| 88 |
|
| 89 |
#include "Navier2D_Helpers.h" |
| 90 |
|
| 91 |
/*! |
| 92 |
* 2d Navier Stokes example (for Epetra) |
| 93 |
* |
| 94 |
* using block matrices |
| 95 |
* |
| 96 |
* 3 level multigrid with Braess-Sarazin smoother |
| 97 |
* Reuse aggregates of block 0 for aggregates in block 1 |
| 98 |
* |
| 99 |
*/ |
| 100 |
|
| 101 |
int main(int argc, char* argv[]) { |
| 102 |
#if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT) |
| 103 |
typedef double Scalar; |
| 104 |
typedef int LocalOrdinal; |
| 105 |
typedef int GlobalOrdinal; |
| 106 |
typedef LocalOrdinal LO; |
| 107 |
typedef GlobalOrdinal GO; |
| 108 |
typedef Xpetra::EpetraNode Node; |
| 109 |
#include "MueLu_UseShortNames.hpp" |
| 110 |
|
| 111 |
using Teuchos::RCP; |
| 112 |
using Teuchos::rcp; |
| 113 |
using Teuchos::rcpFromRef; |
| 114 |
using namespace MueLuTests; |
| 115 |
|
| 116 |
Teuchos::oblackholestream blackhole; |
| 117 |
Teuchos::GlobalMPISession mpiSession(&argc, &argv, &blackhole); |
| 118 |
|
| 119 |
bool success = false; |
| 120 |
bool verbose = true; |
| 121 |
try { |
| 122 |
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); |
| 123 |
RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); |
| 124 |
out->setOutputToRootOnly(0); |
| 125 |
*out << MueLu::MemUtils::PrintMemoryUsage() << std::endl; |
| 126 |
|
| 127 |
// Timing |
| 128 |
Teuchos::Time myTime("global"); |
| 129 |
Teuchos::TimeMonitor MM(myTime); |
| 130 |
|
| 131 |
// read in some command line parameters |
| 132 |
Teuchos::CommandLineProcessor clp(false); |
| 133 |
|
| 134 |
int rebalanceBlocks = 1; |
| 135 |
clp.setOption("rebalanceBlocks", &rebalanceBlocks, "rebalance blocks (1=yes, else=no)"); |
| 136 |
|
| 137 |
switch (clp.parse(argc, argv)) { |
| 138 |
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; |
| 139 |
case Teuchos::CommandLineProcessor::PARSE_ERROR: |
| 140 |
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; |
| 141 |
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; |
| 142 |
} |
| 143 |
|
| 144 |
#if defined(HAVE_MPI) && defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MUELU_ISORROPIA) |
| 145 |
#ifndef HAVE_XPETRA_INT_LONG_LONG |
| 146 |
*out << "Warning: scaling test was not compiled with long long int support" << std::endl; |
| 147 |
|
| 148 |
// custom parameters |
| 149 |
LocalOrdinal maxLevels = 3; |
| 150 |
|
| 151 |
GlobalOrdinal maxCoarseSize = 1; // FIXME clp doesn't like long long int |
| 152 |
|
| 153 |
int globalNumDofs = 1500; // used for the maps |
| 154 |
int nDofsPerNode = 3; // used for generating the fine level null-space |
| 155 |
|
| 156 |
// build strided maps |
| 157 |
// striding information: 2 velocity dofs and 1 pressure dof = 3 dofs per node |
| 158 |
std::vector<size_t> stridingInfo; |
| 159 |
stridingInfo.push_back(2); |
| 160 |
stridingInfo.push_back(1); |
| 161 |
|
| 162 |
/////////////////////////////////////// build strided maps |
| 163 |
// build strided maps: |
| 164 |
// xstridedfullmap: full map (velocity and pressure dof gids), continous |
| 165 |
// xstridedvelmap: only velocity dof gid maps (i.e. 0,1,3,4,6,7...) |
| 166 |
// xstridedpremap: only pressure dof gid maps (i.e. 2,5,8,...) |
| 167 |
Xpetra::UnderlyingLib lib = Xpetra::UseEpetra; |
| 168 |
RCP<const StridedMap> xstridedfullmap = StridedMapFactory::Build(lib, globalNumDofs, 0, stridingInfo, comm, -1); |
| 169 |
RCP<const StridedMap> xstridedvelmap = StridedMapFactory::Build(xstridedfullmap, 0); |
| 170 |
RCP<const StridedMap> xstridedpremap = StridedMapFactory::Build(xstridedfullmap, 1); |
| 171 |
|
| 172 |
/////////////////////////////////////// transform Xpetra::Map objects to Epetra |
| 173 |
// this is needed for AztecOO |
| 174 |
const RCP<const Epetra_Map> fullmap = rcpFromRef(Xpetra::toEpetra(*xstridedfullmap)); |
| 175 |
RCP<const Epetra_Map> velmap = rcpFromRef(Xpetra::toEpetra(*xstridedvelmap)); |
| 176 |
RCP<const Epetra_Map> premap = rcpFromRef(Xpetra::toEpetra(*xstridedpremap)); |
| 177 |
|
| 178 |
/////////////////////////////////////// import problem matrix and RHS from files (-> Epetra) |
| 179 |
|
| 180 |
// read in problem |
| 181 |
Epetra_CrsMatrix* ptrA = 0; |
| 182 |
Epetra_Vector* ptrf = 0; |
| 183 |
Epetra_MultiVector* ptrNS = 0; |
| 184 |
|
| 185 |
*out << "Reading matrix market file" << std::endl; |
| 186 |
|
| 187 |
EpetraExt::MatrixMarketFileToCrsMatrix("A_re1000_5932.txt", *fullmap, *fullmap, *fullmap, ptrA); |
| 188 |
EpetraExt::MatrixMarketFileToVector("b_re1000_5932.txt", *fullmap, ptrf); |
| 189 |
// EpetraExt::MatrixMarketFileToCrsMatrix("/home/tobias/promotion/trilinos/fc17-dyn/packages/muelu/test/navierstokes/A_re1000_5932.txt",*fullmap,*fullmap,*fullmap,ptrA); |
| 190 |
// EpetraExt::MatrixMarketFileToVector("/home/tobias/promotion/trilinos/fc17-dyn/packages/muelu/test/navierstokes/b_re1000_5932.txt",*fullmap,ptrf); |
| 191 |
|
| 192 |
RCP<Epetra_CrsMatrix> epA = Teuchos::rcp(ptrA); |
| 193 |
RCP<Epetra_Vector> epv = Teuchos::rcp(ptrf); |
| 194 |
RCP<Epetra_MultiVector> epNS = Teuchos::rcp(ptrNS); |
| 195 |
|
| 196 |
/////////////////////////////////////// split system into 2x2 block system |
| 197 |
|
| 198 |
*out << "Split matrix into 2x2 block matrix" << std::endl; |
| 199 |
|
| 200 |
// split fullA into A11,..., A22 |
| 201 |
Teuchos::RCP<Epetra_CrsMatrix> A11; |
| 202 |
Teuchos::RCP<Epetra_CrsMatrix> A12; |
| 203 |
Teuchos::RCP<Epetra_CrsMatrix> A21; |
| 204 |
Teuchos::RCP<Epetra_CrsMatrix> A22; |
| 205 |
|
| 206 |
if (SplitMatrix2x2(epA, *velmap, *premap, A11, A12, A21, A22) == false) |
| 207 |
*out << "Problem with splitting matrix" << std::endl; |
| 208 |
|
| 209 |
/////////////////////////////////////// transform Epetra objects to Xpetra (needed for MueLu) |
| 210 |
|
| 211 |
// build Xpetra objects from Epetra_CrsMatrix objects |
| 212 |
Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xA11 = Teuchos::rcp(new Xpetra::EpetraCrsMatrixT<GlobalOrdinal, Node>(A11)); |
| 213 |
Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xA12 = Teuchos::rcp(new Xpetra::EpetraCrsMatrixT<GlobalOrdinal, Node>(A12)); |
| 214 |
Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xA21 = Teuchos::rcp(new Xpetra::EpetraCrsMatrixT<GlobalOrdinal, Node>(A21)); |
| 215 |
Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xA22 = Teuchos::rcp(new Xpetra::EpetraCrsMatrixT<GlobalOrdinal, Node>(A22)); |
| 216 |
|
| 217 |
/////////////////////////////////////// generate MapExtractor object |
| 218 |
|
| 219 |
std::vector<Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > > xmaps; |
| 220 |
xmaps.push_back(xstridedvelmap); |
| 221 |
xmaps.push_back(xstridedpremap); |
| 222 |
|
| 223 |
Teuchos::RCP<const Xpetra::MapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node> > map_extractor = Xpetra::MapExtractorFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(xstridedfullmap, xmaps); |
| 224 |
|
| 225 |
/////////////////////////////////////// build blocked transfer operator |
| 226 |
// using the map extractor |
| 227 |
Teuchos::RCP<Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > bOp = Teuchos::rcp(new Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>(map_extractor, map_extractor, 10)); |
| 228 |
bOp->setMatrix(0, 0, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA11))); |
| 229 |
bOp->setMatrix(0, 1, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA12))); |
| 230 |
bOp->setMatrix(1, 0, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA21))); |
| 231 |
bOp->setMatrix(1, 1, Teuchos::rcp(new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(xA22))); |
| 232 |
|
| 233 |
bOp->fillComplete(); |
| 234 |
|
| 235 |
//////////////////////////////////////////////////// create Hierarchy |
| 236 |
RCP<Hierarchy> H = rcp(new Hierarchy()); |
| 237 |
H->setDefaultVerbLevel(Teuchos::VERB_HIGH); |
| 238 |
// H->setDefaultVerbLevel(Teuchos::VERB_NONE); |
| 239 |
H->SetMaxCoarseSize(maxCoarseSize); |
| 240 |
|
| 241 |
//////////////////////////////////////////////////////// finest Level |
| 242 |
RCP<MueLu::Level> Finest = H->GetLevel(); |
| 243 |
Finest->setDefaultVerbLevel(Teuchos::VERB_HIGH); |
| 244 |
Finest->Set("A", Teuchos::rcp_dynamic_cast<Matrix>(bOp)); |
| 245 |
|
| 246 |
////////////////////////////////////////// prepare null space for A11 |
| 247 |
RCP<MultiVector> nullspace11 = MultiVectorFactory::Build(xstridedvelmap, 2); // this is a 2D standard null space |
| 248 |
|
| 249 |
for (int i = 0; i < nDofsPerNode - 1; ++i) { |
| 250 |
Teuchos::ArrayRCP<Scalar> nsValues = nullspace11->getDataNonConst(i); |
| 251 |
int numBlocks = nsValues.size() / (nDofsPerNode - 1); |
| 252 |
for (int j = 0; j < numBlocks; ++j) { |
| 253 |
nsValues[j * (nDofsPerNode - 1) + i] = 1.0; |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
Finest->Set("Nullspace1", nullspace11); |
| 258 |
|
| 259 |
////////////////////////////////////////// prepare null space for A22 |
| 260 |
RCP<MultiVector> nullspace22 = MultiVectorFactory::Build(xstridedpremap, 1); // this is a 2D standard null space |
| 261 |
Teuchos::ArrayRCP<Scalar> nsValues22 = nullspace22->getDataNonConst(0); |
| 262 |
for (int j = 0; j < nsValues22.size(); ++j) { |
| 263 |
nsValues22[j] = 1.0; |
| 264 |
} |
| 265 |
|
| 266 |
Finest->Set("Nullspace2", nullspace22); |
| 267 |
|
| 268 |
/////////////////////////////////////////// define rebalanced block AC factory |
| 269 |
// This is the main factory for "A" and defines the input for |
| 270 |
// - the SubBlockAFactory objects |
| 271 |
// - the rebalanced block Ac factory |
| 272 |
RCP<RebalanceBlockAcFactory> RebalancedAcFact = rcp(new RebalanceBlockAcFactory()); |
| 273 |
|
| 274 |
/////////////////////////////////////////// define non-rebalanced blocked transfer ops |
| 275 |
RCP<BlockedPFactory> PFact = rcp(new BlockedPFactory()); // use row map index base from bOp |
| 276 |
RCP<GenericRFactory> RFact = rcp(new GenericRFactory()); |
| 277 |
RFact->SetFactory("P", PFact); |
| 278 |
|
| 279 |
// non-rebalanced block coarse matrix factory |
| 280 |
// output is non-rebalanced coarse block matrix Ac |
| 281 |
// used as input for rebalanced block coarse factory RebalancedAcFact |
| 282 |
RCP<Factory> AcFact = rcp(new BlockedRAPFactory()); |
| 283 |
AcFact->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 284 |
AcFact->SetFactory("P", PFact); // use non-rebalanced block prolongator as input |
| 285 |
AcFact->SetFactory("R", RFact); // use non-rebalanced block restrictor as input |
| 286 |
|
| 287 |
// Repartitioning (decides how many partitions are built) |
| 288 |
RCP<Factory> RepartitionHeuristicFact = rcp(new RepartitionHeuristicFactory()); |
| 289 |
{ |
| 290 |
Teuchos::ParameterList paramList; |
| 291 |
paramList.set("repartition: min rows per proc", 200); |
| 292 |
paramList.set("repartition: max imbalance", 1.3); |
| 293 |
if (rebalanceBlocks == 1) |
| 294 |
paramList.set("repartition: start level", 1); |
| 295 |
else |
| 296 |
paramList.set("repartition: start level", 10); // supress rebalancing |
| 297 |
RepartitionHeuristicFact->SetParameterList(paramList); |
| 298 |
} |
| 299 |
RepartitionHeuristicFact->SetFactory("A", AcFact); |
| 300 |
|
| 301 |
// define matrix sub-blocks of possibly rebalanced block matrix A |
| 302 |
// These are used as input for |
| 303 |
// - the sub blocks of the transfer operators |
| 304 |
RCP<SubBlockAFactory> A11Fact = Teuchos::rcp(new SubBlockAFactory()); |
| 305 |
A11Fact->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 306 |
A11Fact->SetParameter("block row", Teuchos::ParameterEntry(0)); |
| 307 |
A11Fact->SetParameter("block col", Teuchos::ParameterEntry(0)); |
| 308 |
/*A11Fact->SetParameter("Range map: Striding info",Teuchos::ParameterEntry(std::string("{ 2 1 }"))); |
| 309 |
A11Fact->SetParameter("Range map: Strided block id",Teuchos::ParameterEntry(0)); |
| 310 |
A11Fact->SetParameter("Domain map: Striding info",Teuchos::ParameterEntry(std::string("{ 2 1 }"))); |
| 311 |
A11Fact->SetParameter("Domain map: Strided block id",Teuchos::ParameterEntry(0));*/ |
| 312 |
|
| 313 |
RCP<SubBlockAFactory> A22Fact = Teuchos::rcp(new SubBlockAFactory()); |
| 314 |
A22Fact->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 315 |
A22Fact->SetParameter("block row", Teuchos::ParameterEntry(1)); |
| 316 |
A22Fact->SetParameter("block col", Teuchos::ParameterEntry(1)); |
| 317 |
/*A22Fact->SetParameter("Range map: Striding info",Teuchos::ParameterEntry(std::string("{ 2 1 }"))); |
| 318 |
A22Fact->SetParameter("Range map: Strided block id",Teuchos::ParameterEntry(1)); |
| 319 |
A22Fact->SetParameter("Domain map: Striding info",Teuchos::ParameterEntry(std::string("{ 2 1 }"))); |
| 320 |
A22Fact->SetParameter("Domain map: Strided block id",Teuchos::ParameterEntry(1));*/ |
| 321 |
|
| 322 |
/////////////////////////////////////////// define rebalancing factories |
| 323 |
// define sub blocks of the coarse non-rebalanced block matrix Ac |
| 324 |
// input is the block operator generated by AcFact |
| 325 |
RCP<SubBlockAFactory> rebA11Fact = Teuchos::rcp(new SubBlockAFactory()); |
| 326 |
rebA11Fact->SetFactory("A", AcFact); |
| 327 |
rebA11Fact->SetParameter("block row", Teuchos::ParameterEntry(0)); |
| 328 |
rebA11Fact->SetParameter("block col", Teuchos::ParameterEntry(0)); |
| 329 |
rebA11Fact->SetParameter("Range map: Striding info", Teuchos::ParameterEntry(std::string("{ 2, 1 }"))); |
| 330 |
rebA11Fact->SetParameter("Range map: Strided block id", Teuchos::ParameterEntry(0)); |
| 331 |
rebA11Fact->SetParameter("Domain map: Striding info", Teuchos::ParameterEntry(std::string("{ 2, 1 }"))); |
| 332 |
rebA11Fact->SetParameter("Domain map: Strided block id", Teuchos::ParameterEntry(0)); |
| 333 |
|
| 334 |
RCP<SubBlockAFactory> rebA22Fact = Teuchos::rcp(new SubBlockAFactory()); |
| 335 |
rebA22Fact->SetFactory("A", AcFact); |
| 336 |
rebA22Fact->SetParameter("block row", Teuchos::ParameterEntry(1)); |
| 337 |
rebA22Fact->SetParameter("block col", Teuchos::ParameterEntry(1)); |
| 338 |
rebA22Fact->SetParameter("Range map: Striding info", Teuchos::ParameterEntry(std::string("{ 2, 1 }"))); |
| 339 |
rebA22Fact->SetParameter("Range map: Strided block id", Teuchos::ParameterEntry(1)); |
| 340 |
rebA22Fact->SetParameter("Domain map: Striding info", Teuchos::ParameterEntry(std::string("{ 2, 1 }"))); |
| 341 |
rebA22Fact->SetParameter("Domain map: Strided block id", Teuchos::ParameterEntry(1)); |
| 342 |
|
| 343 |
// define rebalancing factory for coarse block matrix A(1,1) |
| 344 |
RCP<AmalgamationFactory> rebAmalgFact11 = rcp(new AmalgamationFactory()); |
| 345 |
rebAmalgFact11->SetFactory("A", rebA11Fact); |
| 346 |
rebAmalgFact11->setDefaultVerbLevel(Teuchos::VERB_EXTREME); |
| 347 |
|
| 348 |
RCP<MueLu::IsorropiaInterface<LO, GO, NO> > isoInterface1 = rcp(new MueLu::IsorropiaInterface<LO, GO, NO>()); |
| 349 |
isoInterface1->SetFactory("A", rebA11Fact); |
| 350 |
isoInterface1->SetFactory("number of partitions", RepartitionHeuristicFact); |
| 351 |
isoInterface1->SetFactory("UnAmalgamationInfo", rebAmalgFact11); |
| 352 |
|
| 353 |
RCP<MueLu::RepartitionInterface<LO, GO, NO> > repInterface1 = rcp(new MueLu::RepartitionInterface<LO, GO, NO>()); |
| 354 |
repInterface1->SetFactory("A", rebA11Fact); |
| 355 |
repInterface1->SetFactory("number of partitions", RepartitionHeuristicFact); |
| 356 |
repInterface1->SetFactory("AmalgamatedPartition", isoInterface1); |
| 357 |
|
| 358 |
// Repartitioning (creates "Importer" from "Partition") |
| 359 |
RCP<Factory> RepartitionFact = rcp(new RepartitionFactory()); |
| 360 |
RepartitionFact->SetFactory("A", rebA11Fact); |
| 361 |
RepartitionFact->SetFactory("number of partitions", RepartitionHeuristicFact); |
| 362 |
RepartitionFact->SetFactory("Partition", repInterface1); |
| 363 |
RepartitionFact->SetParameter("repartition: print partition distribution", Teuchos::ParameterEntry(true)); |
| 364 |
RepartitionFact->SetParameter("repartition: remap parts", Teuchos::ParameterEntry(true)); |
| 365 |
|
| 366 |
// define rebalancing factory for coarse block matrix A(1,1) |
| 367 |
RCP<AmalgamationFactory> rebAmalgFact22 = rcp(new AmalgamationFactory()); |
| 368 |
rebAmalgFact22->SetFactory("A", rebA22Fact); |
| 369 |
rebAmalgFact22->setDefaultVerbLevel(Teuchos::VERB_EXTREME); |
| 370 |
|
| 371 |
RCP<MueLu::CloneRepartitionInterface<SC, LO, GO, NO> > repInterface2 = rcp(new MueLu::CloneRepartitionInterface<SC, LO, GO, NO>()); |
| 372 |
repInterface2->SetFactory("A", rebA22Fact); |
| 373 |
repInterface2->SetFactory("number of partitions", RepartitionHeuristicFact); |
| 374 |
repInterface2->SetFactory("Partition", repInterface1); |
| 375 |
|
| 376 |
// second repartition factory |
| 377 |
RCP<Factory> RepartitionFact2 = rcp(new RepartitionFactory()); |
| 378 |
RepartitionFact2->SetFactory("A", rebA22Fact); |
| 379 |
RepartitionFact2->SetFactory("number of partitions", RepartitionHeuristicFact); |
| 380 |
RepartitionFact2->SetFactory("Partition", repInterface2); // this is not valid |
| 381 |
RepartitionFact2->SetParameter("repartition: print partition distribution", Teuchos::ParameterEntry(true)); |
| 382 |
RepartitionFact2->SetParameter("repartition: remap parts", Teuchos::ParameterEntry(false)); /* do not remap! */ |
| 383 |
|
| 384 |
////////////////////////////////////////// build non-rebalanced matrix blocks |
| 385 |
// build factories for transfer operator P(1,1) and R(1,1) |
| 386 |
RCP<AmalgamationFactory> amalgFact11 = rcp(new AmalgamationFactory()); |
| 387 |
amalgFact11->SetFactory("A", A11Fact); |
| 388 |
amalgFact11->setDefaultVerbLevel(Teuchos::VERB_EXTREME); |
| 389 |
|
| 390 |
RCP<CoalesceDropFactory> dropFact11 = rcp(new CoalesceDropFactory()); |
| 391 |
dropFact11->SetFactory("A", A11Fact); |
| 392 |
dropFact11->SetFactory("UnAmalgamationInfo", amalgFact11); |
| 393 |
dropFact11->setDefaultVerbLevel(Teuchos::VERB_EXTREME); |
| 394 |
|
| 395 |
RCP<UncoupledAggregationFactory> UncoupledAggFact11 = rcp(new UncoupledAggregationFactory()); |
| 396 |
UncoupledAggFact11->SetFactory("Graph", dropFact11); |
| 397 |
UncoupledAggFact11->SetMinNodesPerAggregate(9); |
| 398 |
UncoupledAggFact11->SetMaxNeighAlreadySelected(2); |
| 399 |
UncoupledAggFact11->SetOrdering("natural"); |
| 400 |
|
| 401 |
RCP<CoarseMapFactory> coarseMapFact11 = Teuchos::rcp(new CoarseMapFactory()); |
| 402 |
coarseMapFact11->setStridingData(stridingInfo); |
| 403 |
coarseMapFact11->setStridedBlockId(0); |
| 404 |
|
| 405 |
RCP<TentativePFactory> P11Fact = rcp(new TentativePFactory()); |
| 406 |
RCP<TransPFactory> R11Fact = rcp(new TransPFactory()); |
| 407 |
|
| 408 |
Teuchos::RCP<NullspaceFactory> nspFact11 = Teuchos::rcp(new NullspaceFactory("Nullspace1")); |
| 409 |
nspFact11->SetFactory("Nullspace1", P11Fact); // pick "Nullspace1" from Finest level |
| 410 |
|
| 411 |
//////////////////////////////// define factory manager for (1,1) block |
| 412 |
RCP<FactoryManager> M11 = rcp(new FactoryManager()); |
| 413 |
M11->SetFactory("A", A11Fact); // rebalanced fine-level block operator |
| 414 |
M11->SetFactory("P", P11Fact); // non-rebalanced transfer operator block P(1,1) |
| 415 |
M11->SetFactory("R", R11Fact); // non-rebalanced transfer operator block R(1,1) |
| 416 |
M11->SetFactory("Aggregates", UncoupledAggFact11); |
| 417 |
M11->SetFactory("Graph", dropFact11); |
| 418 |
M11->SetFactory("DofsPerNode", dropFact11); |
| 419 |
M11->SetFactory("UnAmalgamationInfo", amalgFact11); |
| 420 |
M11->SetFactory("Nullspace", nspFact11); // TODO check me? |
| 421 |
M11->SetFactory("CoarseMap", coarseMapFact11); |
| 422 |
M11->SetIgnoreUserData(true); // always use data from factories defined in factory manager |
| 423 |
|
| 424 |
////////////////////////////////////////// build non-rebalanced matrix blocks |
| 425 |
// build factories for transfer operator P(2,2) and R(2,2) |
| 426 |
RCP<AmalgamationFactory> amalgFact22 = rcp(new AmalgamationFactory()); |
| 427 |
RCP<TentativePFactory> P22Fact = rcp(new TentativePFactory()); |
| 428 |
RCP<TransPFactory> R22Fact = rcp(new TransPFactory()); |
| 429 |
|
| 430 |
// connect null space and tentative PFactory |
| 431 |
Teuchos::RCP<NullspaceFactory> nspFact22 = Teuchos::rcp(new NullspaceFactory("Nullspace2")); |
| 432 |
nspFact22->SetFactory("Nullspace2", P22Fact); // define null space generated by P22Fact as null space for coarse level (non-rebalanced) |
| 433 |
|
| 434 |
RCP<CoarseMapFactory> coarseMapFact22 = Teuchos::rcp(new CoarseMapFactory()); |
| 435 |
coarseMapFact22->setStridingData(stridingInfo); |
| 436 |
coarseMapFact22->setStridedBlockId(1); |
| 437 |
|
| 438 |
//////////////////////////////// define factory manager for (2,2) block |
| 439 |
RCP<FactoryManager> M22 = rcp(new FactoryManager()); |
| 440 |
M22->SetFactory("A", A22Fact); // rebalanced fine-level block operator |
| 441 |
M22->SetFactory("P", P22Fact); // non-rebalanced transfer operator P(2,2) |
| 442 |
M22->SetFactory("R", R22Fact); // non-rebalanced transfer operator R(2,2) |
| 443 |
M22->SetFactory("Aggregates", UncoupledAggFact11); // aggregates from block (1,1) |
| 444 |
M22->SetFactory("Nullspace", nspFact22); |
| 445 |
M22->SetFactory("UnAmalgamationInfo", amalgFact22); |
| 446 |
M22->SetFactory("Ptent", P22Fact); |
| 447 |
M22->SetFactory("CoarseMap", coarseMapFact22); |
| 448 |
M22->SetIgnoreUserData(true); |
| 449 |
|
| 450 |
/////////////////////////////////////////// define rebalanced blocked transfer ops |
| 451 |
//////////////////////////////// define factory manager for (1,1) block |
| 452 |
RCP<FactoryManager> rebM11 = rcp(new FactoryManager()); |
| 453 |
rebM11->SetFactory("A", AcFact); // important: must be a 2x2 block A Factory |
| 454 |
rebM11->SetFactory("Importer", RepartitionFact); |
| 455 |
rebM11->SetFactory("number of partitions", RepartitionHeuristicFact); |
| 456 |
rebM11->SetFactory("Nullspace", nspFact11); |
| 457 |
// rebM11->SetIgnoreUserData(true); |
| 458 |
|
| 459 |
RCP<FactoryManager> rebM22 = rcp(new FactoryManager()); |
| 460 |
rebM22->SetFactory("A", AcFact); // important: must be a 2x2 block A Factory |
| 461 |
rebM22->SetFactory("Importer", RepartitionFact2); // use dummy repartitioning factory |
| 462 |
rebM22->SetFactory("number of partitions", RepartitionHeuristicFact); |
| 463 |
rebM22->SetFactory("Nullspace", nspFact22); |
| 464 |
|
| 465 |
// Reordering of the transfer operators |
| 466 |
RCP<RebalanceBlockInterpolationFactory> RebalancedBlockPFact = rcp(new RebalanceBlockInterpolationFactory()); |
| 467 |
RebalancedBlockPFact->SetFactory("P", PFact); // use non-rebalanced block P operator as input |
| 468 |
RebalancedBlockPFact->AddFactoryManager(rebM11); |
| 469 |
RebalancedBlockPFact->AddFactoryManager(rebM22); |
| 470 |
|
| 471 |
RCP<RebalanceBlockRestrictionFactory> RebalancedBlockRFact = rcp(new RebalanceBlockRestrictionFactory()); |
| 472 |
// RebalancedBlockRFact->SetParameter("type", Teuchos::ParameterEntry(std::string("Restriction"))); |
| 473 |
RebalancedBlockRFact->SetFactory("R", RFact); // non-rebalanced block P operator |
| 474 |
RebalancedBlockRFact->SetParameter("repartition: use subcommunicators", Teuchos::ParameterEntry(true)); |
| 475 |
RebalancedBlockRFact->AddFactoryManager(rebM11); |
| 476 |
RebalancedBlockRFact->AddFactoryManager(rebM22); |
| 477 |
|
| 478 |
///////////////////////////////////////// initialize non-rebalanced block transfer operators |
| 479 |
// output are the non-rebalanced block transfer operators used as input in AcFact to build |
| 480 |
// the non-rebalanced coarse level block matrix Ac |
| 481 |
PFact->AddFactoryManager(M11); // use non-rebalanced information from sub block factory manager M11 |
| 482 |
PFact->AddFactoryManager(M22); // use non-rebalanced information from sub block factory manager M22 |
| 483 |
|
| 484 |
///////////////////////////////////////// initialize rebalanced coarse block AC factory |
| 485 |
RebalancedAcFact->SetFactory("A", AcFact); // use non-rebalanced block operator as input |
| 486 |
RebalancedAcFact->SetParameter("repartition: use subcommunicators", Teuchos::ParameterEntry(true)); |
| 487 |
RebalancedAcFact->AddFactoryManager(rebM11); |
| 488 |
RebalancedAcFact->AddFactoryManager(rebM22); |
| 489 |
|
| 490 |
////////////////////////////////////////////////////////////////////// |
| 491 |
// Smoothers |
| 492 |
|
| 493 |
// Another factory manager for braes sarazin smoother |
| 494 |
// Schur Complement Factory, using the factory to generate AcFact |
| 495 |
SC omega = 1.3; |
| 496 |
RCP<SchurComplementFactory> SFact = Teuchos::rcp(new SchurComplementFactory()); |
| 497 |
SFact->SetParameter("omega", Teuchos::ParameterEntry(omega)); |
| 498 |
SFact->SetFactory("A", MueLu::NoFactory::getRCP()); // this finally be the rebalanced block operator! |
| 499 |
|
| 500 |
// Smoother Factory, using SFact as a factory for A |
| 501 |
std::string ifpackSCType; |
| 502 |
Teuchos::ParameterList ifpackSCList; |
| 503 |
ifpackSCList.set("relaxation: sweeps", (LocalOrdinal)3); |
| 504 |
ifpackSCList.set("relaxation: damping factor", (Scalar)1.0); |
| 505 |
ifpackSCType = "RELAXATION"; |
| 506 |
ifpackSCList.set("relaxation: type", "Gauss-Seidel"); |
| 507 |
RCP<SmootherPrototype> smoProtoSC = rcp(new TrilinosSmoother(ifpackSCType, ifpackSCList, 0)); |
| 508 |
smoProtoSC->SetFactory("A", SFact); |
| 509 |
RCP<SmootherFactory> SmooSCFact = rcp(new SmootherFactory(smoProtoSC)); |
| 510 |
|
| 511 |
RCP<BraessSarazinSmoother> smootherPrototype = rcp(new BraessSarazinSmoother()); |
| 512 |
smootherPrototype->SetParameter("Sweeps", Teuchos::ParameterEntry(3)); |
| 513 |
smootherPrototype->SetParameter("Damping factor", Teuchos::ParameterEntry(omega)); |
| 514 |
smootherPrototype->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 515 |
RCP<SmootherFactory> smootherFact = rcp(new SmootherFactory(smootherPrototype)); |
| 516 |
|
| 517 |
RCP<BraessSarazinSmoother> coarseSolverPrototype = rcp(new BraessSarazinSmoother()); |
| 518 |
coarseSolverPrototype->SetParameter("Sweeps", Teuchos::ParameterEntry(3)); |
| 519 |
coarseSolverPrototype->SetParameter("Damping factor", Teuchos::ParameterEntry(omega)); |
| 520 |
coarseSolverPrototype->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 521 |
RCP<SmootherFactory> coarseSolverFact = rcp(new SmootherFactory(coarseSolverPrototype, Teuchos::null)); |
| 522 |
|
| 523 |
RCP<FactoryManager> MB = rcp(new FactoryManager()); |
| 524 |
MB->SetFactory("A", SFact); |
| 525 |
MB->SetFactory("Smoother", SmooSCFact); |
| 526 |
MB->SetIgnoreUserData(true); // always use data from factories defined in factory manager |
| 527 |
smootherPrototype->AddFactoryManager(MB, 0); |
| 528 |
coarseSolverPrototype->AddFactoryManager(MB, 0); |
| 529 |
|
| 530 |
////////////////////////////////////////// define main factory manager |
| 531 |
FactoryManager M; |
| 532 |
M.SetFactory("A", RebalancedAcFact); // rebalance block AC Factory using importer |
| 533 |
M.SetFactory("P", RebalancedBlockPFact); // rebalance prolongator using non-balanced Ac |
| 534 |
M.SetFactory("R", RebalancedBlockRFact); // rebalance restrictor and null space using non-balanced Ac |
| 535 |
M.SetFactory("Smoother", smootherFact); |
| 536 |
M.SetFactory("PreSmoother", smootherFact); |
| 537 |
M.SetFactory("PostSmoother", smootherFact); |
| 538 |
M.SetFactory("CoarseSolver", coarseSolverFact); |
| 539 |
|
| 540 |
H->Setup(M, 0, maxLevels); |
| 541 |
|
| 542 |
/**out << std::endl; |
| 543 |
*out << "print content of multigrid levels:" << std::endl; |
| 544 |
|
| 545 |
Finest->print(*out); |
| 546 |
|
| 547 |
RCP<Level> coarseLevel = H->GetLevel(1); |
| 548 |
coarseLevel->print(*out); |
| 549 |
|
| 550 |
RCP<Level> coarseLevel2 = H->GetLevel(2); |
| 551 |
coarseLevel2->print(*out);*/ |
| 552 |
|
| 553 |
RCP<MultiVector> xLsg = MultiVectorFactory::Build(xstridedfullmap, 1); |
| 554 |
|
| 555 |
// Use AMG directly as an iterative method |
| 556 |
#if 0 |
| 557 |
{ |
| 558 |
xLsg->putScalar( (SC) 0.0); |
| 559 |
|
| 560 |
// Epetra_Vector -> Xpetra::Vector |
| 561 |
RCP<Vector> xRhs = Teuchos::rcp(new Xpetra::EpetraVector(epv)); |
| 562 |
|
| 563 |
// calculate initial (absolute) residual |
| 564 |
Teuchos::Array<Teuchos::ScalarTraits<SC>::magnitudeType> norms(1); |
| 565 |
xRhs->norm2(norms); |
| 566 |
*out << "||x_0|| = " << norms[0] << std::endl; |
| 567 |
|
| 568 |
// apply ten multigrid iterations |
| 569 |
H->Iterate(*xRhs,*xLsg,100); |
| 570 |
|
| 571 |
|
| 572 |
// calculate and print residual |
| 573 |
RCP<MultiVector> xTmp = MultiVectorFactory::Build(xstridedfullmap,1); |
| 574 |
bOp->apply(*xLsg,*xTmp,Teuchos::NO_TRANS,(SC)1.0,(SC)0.0); |
| 575 |
xRhs->update((SC)-1.0,*xTmp,(SC)1.0); |
| 576 |
xRhs->norm2(norms); |
| 577 |
*out << "||x|| = " << norms[0] << std::endl; |
| 578 |
} |
| 579 |
#endif |
| 580 |
|
| 581 |
// |
| 582 |
// Solve Ax = b using AMG as a preconditioner in AztecOO |
| 583 |
// |
| 584 |
{ |
| 585 |
RCP<Epetra_Vector> X = rcp(new Epetra_Vector(epv->Map())); |
| 586 |
X->PutScalar(0.0); |
| 587 |
Epetra_LinearProblem epetraProblem(epA.get(), X.get(), epv.get()); |
| 588 |
|
| 589 |
AztecOO aztecSolver(epetraProblem); |
| 590 |
aztecSolver.SetAztecOption(AZ_solver, AZ_gmres); |
| 591 |
|
| 592 |
MueLu::EpetraOperator aztecPrec(H); |
| 593 |
aztecSolver.SetPrecOperator(&aztecPrec); |
| 594 |
|
| 595 |
int maxIts = 50; |
| 596 |
double tol = 1e-8; |
| 597 |
|
| 598 |
aztecSolver.Iterate(maxIts, tol); |
| 599 |
} |
| 600 |
|
| 601 |
#endif // end ifndef HAVE_LONG_LONG_INT |
| 602 |
#endif // #if defined(HAVE_MPI) && defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MUELU_ISORROPIA) |
| 603 |
success = true; |
| 604 |
} |
| 605 |
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); |
| 606 |
|
| 607 |
return (success ? EXIT_SUCCESS : EXIT_FAILURE); |
| 608 |
#else |
| 609 |
std::cout << "Epetra (and/or EpetraExt) are not available. Skip test." << std::endl; |
| 610 |
return EXIT_SUCCESS; |
| 611 |
#endif |
| 612 |
} |