本文整理汇总了C++中teuchos::RCP::BuildMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ RCP::BuildMatrix方法的具体用法?C++ RCP::BuildMatrix怎么用?C++ RCP::BuildMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::RCP
的用法示例。
在下文中一共展示了RCP::BuildMatrix方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
#include <MueLu_UseShortNames.hpp>
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::Time;
using Teuchos::TimeMonitor;
//
// MPI initialization using Teuchos
//
Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL);
RCP< const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
//
// Parameters
//
Teuchos::CommandLineProcessor clp(false);
GO nx, ny, nz;
nx=50;
ny=50;
nz=50;
Galeri::Xpetra::Parameters<GO> matrixParameters(clp, nx, ny, nz, "Laplace2D"); // manage parameters of the test case
Xpetra::Parameters xpetraParameters(clp); // manage parameters of Xpetra
int optNraps = 5; clp.setOption("nraps", &optNraps, "number of RAPS to perform");
bool optTimings = true; clp.setOption("timings", "notimings", &optTimings, "print timings to screen");
switch (clp.parse(argc, argv)) {
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; break;
case Teuchos::CommandLineProcessor::PARSE_ERROR:
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; break;
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break;
}
if (comm->getRank() == 0) {
std::cout << "========================================================" << std::endl
<< xpetraParameters << matrixParameters;
}
//
// Construct the problem
//
{
TimeMonitor globalTimeMonitor(*TimeMonitor::getNewTimer("RAPScalingTest: S - Global Time"));
RCP<Matrix> A;
RCP<MultiVector> coordinates;
{
TimeMonitor tm(*TimeMonitor::getNewTimer("RAPScalingTest: 1 - Matrix creation"));
RCP<const Map> map;
// Retrieve matrix parameters (they may have been changed on the command line), and pass them to Galeri.
// Galeri will attempt to create a square-as-possible distribution of subdomains di, e.g.,
// d1 d2 d3
// d4 d5 d6
// d7 d8 d9
// d10 d11 d12
// A perfect distribution is only possible when the #processors is a perfect square.
// This *will* result in "strip" distribution if the #processors is a prime number or if the factors are very different in
// size. For example, np=14 will give a 7-by-2 distribution.
// If you don't want Galeri to do this, specify mx or my on the galeriList.
Teuchos::ParameterList pl = matrixParameters.GetParameterList();
Teuchos::ParameterList galeriList;
galeriList.set("nx", pl.get("nx", nx));
galeriList.set("ny", pl.get("ny", ny));
galeriList.set("nz", pl.get("nz", nz));
if (matrixParameters.GetMatrixType() == "Laplace1D") {
map = MapFactory::Build(xpetraParameters.GetLib(), matrixParameters.GetNumGlobalElements(), 0, comm);
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, MultiVector>("1D", map, matrixParameters.GetParameterList());
}
else if (matrixParameters.GetMatrixType() == "Laplace2D" || matrixParameters.GetMatrixType() == "Star2D") {
map = Galeri::Xpetra::CreateMap<LO, GO, Node>(xpetraParameters.GetLib(), "Cartesian2D", comm, galeriList);
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, MultiVector>("2D", map, matrixParameters.GetParameterList());
}
else if (matrixParameters.GetMatrixType() == "Laplace3D") {
map = Galeri::Xpetra::CreateMap<LO, GO, Node>(xpetraParameters.GetLib(), "Cartesian3D", comm, galeriList);
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, MultiVector>("3D", map, matrixParameters.GetParameterList());
}
//FIXME
if (comm->getRank() == 0) {
GO mx = galeriList.get("mx", -1);
GO my = galeriList.get("my", -1);
std::cout << "Processor subdomains in x direction: " << mx << std::endl
<< "Processor subdomains in y direction: " << my << std::endl
<< "========================================================" << std::endl;
}
Teuchos::RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr =
Galeri::Xpetra::BuildProblem<SC,LO,GO,Map,CrsMatrixWrap,MultiVector>(matrixParameters.GetMatrixType(), map, matrixParameters.GetParameterList());
A = Pr->BuildMatrix();
}
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break;
}
RCP<TimeMonitor> globalTimeMonitor = rcp (new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: S - Global Time")));
if (optDebug) {
Utils::PauseForDebugger();
}
matrixParameters.check();
xpetraParameters.check();
// TODO: check custom parameters
std::transform(optSmooType.begin(), optSmooType.end(), optSmooType.begin(), ::tolower);
Xpetra::UnderlyingLib lib = xpetraParameters.GetLib();
if (comm->getRank() == 0) {
std::cout << xpetraParameters << matrixParameters;
// TODO: print custom parameters // Or use paramList::print()!
}
//
// CREATE INITIAL MATRIX */
//
RCP<const Map> map;
RCP<Matrix> A;
RCP<MultiVector> coordinates;
{
TimeMonitor tm(*TimeMonitor::getNewTimer("ScalingTest: 1 - Matrix Build"));
map = MapFactory::Build(lib, matrixParameters.GetNumGlobalElements(), 0, comm);
Teuchos::RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr =
Galeri::Xpetra::BuildProblem<SC,LO,GO,Map,CrsMatrixWrap,MultiVector>(matrixParameters.GetMatrixType(), map, matrixParameters.GetParameterList()); //TODO: Matrix vs. CrsMatrixWrap
A = Pr->BuildMatrix();
if (matrixParameters.GetMatrixType() == "Laplace1D") {
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, MultiVector>("1D", map, matrixParameters.GetParameterList());
}
else if (matrixParameters.GetMatrixType() == "Laplace2D") {
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, MultiVector>("2D", map, matrixParameters.GetParameterList());
}
else if (matrixParameters.GetMatrixType() == "Laplace3D") {
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, MultiVector>("3D", map, matrixParameters.GetParameterList());
}
}
//
//
//
// dump matrix to file
if (optDump) {
std::string fileName = "Amat.mm";
Utils::Write(fileName, *A);
}
RCP<MultiVector> nullspace = MultiVectorFactory::Build(map, 1);
nullspace->putScalar( (SC) 1.0);
Teuchos::Array<Teuchos::ScalarTraits<SC>::magnitudeType> norms(1);
nullspace->norm1(norms);
if (comm->getRank() == 0)
std::cout << "||NS|| = " << norms[0] << std::endl;
RCP<MueLu::Hierarchy<SC, LO, GO, NO, LMO> > H;
示例3: main
int main(int argc, char *argv[]) {
#include <MueLu_UseShortNames.hpp>
using Teuchos::RCP;
Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL);
typedef Teuchos::ScalarTraits<SC> ST;
bool success = false;
bool verbose = true;
try {
RCP< const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
//
// Parameters
//
Teuchos::CommandLineProcessor clp(false);
Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 8748);
Xpetra::Parameters xpetraParameters(clp);
bool optRecycling = true; clp.setOption("recycling", "no-recycling", &optRecycling, "Enable recycling of the multigrid preconditioner");
/* DO NOT WORK YET
bool optRecyclingRAPpattern = true; clp.setOption("recycling-rap-pattern", "no-recycling-rap-pattern", &optRecyclingRAPpattern, "Enable recycling of Ac=RAP pattern");
bool optRecyclingAPpattern = false; clp.setOption("recycling-ap-pattern", "no-recycling-ap-pattern", &optRecyclingAPpattern, "Enable recycling of AP pattern");
*/
bool optRecyclingRAPpattern = false;
bool optRecyclingAPpattern = false;
switch (clp.parse(argc, argv)) {
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; break;
case Teuchos::CommandLineProcessor::PARSE_ERROR:
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; break;
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break;
}
// option dependencies
if (optRecycling == false) {
optRecyclingRAPpattern = false;
optRecyclingAPpattern = false;
}
//
// Construct the problems
//
RCP<const Map> map = MapFactory::Build(xpetraParameters.GetLib(), matrixParameters.GetNumGlobalElements(), 0, comm);
Teuchos::RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr =
Galeri::Xpetra::BuildProblem<SC,LO,GO,Map,CrsMatrixWrap,MultiVector>(matrixParameters.GetMatrixType(), map, matrixParameters.GetParameterList());
RCP<Matrix> A1 = Pr->BuildMatrix();
RCP<Matrix> A2 = Pr->BuildMatrix(); // TODO: generate another problem would be more meaningful (ex: scale A1)
//
// First solve
//
FactoryManager M;
Hierarchy H(A1);
if (optRecycling) {
// Configuring "Keep" options before running the first setup.
// Note: "Keep" flags should not be set on the default factories provided by the FactoryManager because in the current
// implementation of FactoryManager, those factories are freed and reallocated between Hierarchy::Setup() calls (see FactoryManager::Clean() and Hierarchy::Setup()).
// So we define our own factories here.
// AGGREGATES:
// Note: aggregates are only used to build Ptent, so it is not useful to keep them. Keeping Ptent is enough.
// RCP<Factory> AggFact = rcp(new CoupledAggregationFactory());
// M.SetFactory("Aggregates", AggFact);
// H.Keep("Aggregates", AggFact.get());
// PTENT:
RCP<Factory> PtentFact = rcp(new TentativePFactory());
M.SetFactory("Ptent", PtentFact);
H.Keep("P", PtentFact.get());
}
RCP<Factory> AcFact = rcp(new RAPFactory());
M.SetFactory("A", AcFact);
if (optRecyclingRAPpattern) {
H.Keep("RAP graph", AcFact.get());
}
if (optRecyclingAPpattern) {
H.Keep("AP graph", AcFact.get());
}
//
H.Setup(M);
{
RCP<Vector> X = VectorFactory::Build(map);
RCP<Vector> B = VectorFactory::Build(map);
X->putScalar((Scalar) 0.0);
B->setSeed(846930886); B->randomize();
//.........这里部分代码省略.........
示例4: main
int main(int argc, char *argv[]) {
#include "MueLu_UseShortNames.hpp"
Teuchos::oblackholestream blackhole;
Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);
bool success = false;
bool verbose = true;
try {
Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
/**********************************************************************************/
/* SET TEST PARAMETERS */
/**********************************************************************************/
/**********************************************************************************/
/* SET TEST PARAMETERS */
/**********************************************************************************/
// Note: use --help to list available options.
Teuchos::CommandLineProcessor clp(false);
// Default is Laplace1D with nx = 8748.
// It's a nice size for 1D and perfect aggregation. (6561=3^8)
//Nice size for 1D and perfect aggregation on small numbers of processors. (8748=4*3^7)
Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 8748); // manage parameters of the test case
Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra
// custom parameters
int pauseForDebugger=0;
//std::string aggOrdering = "natural";
int minPerAgg=2; //was 3 in simple
int maxNbrAlreadySelected=0;
int printTimings=0;
//clp.setOption("aggOrdering",&aggOrdering,"aggregation ordering strategy (natural,graph)");
clp.setOption("debug",&pauseForDebugger,"pause to attach debugger");
clp.setOption("maxNbrSel",&maxNbrAlreadySelected,"maximum # of nbrs allowed to be in other aggregates");
clp.setOption("minPerAgg",&minPerAgg,"minimum #DOFs per aggregate");
clp.setOption("timings",&printTimings,"print timings to screen");
switch (clp.parse(argc,argv)) {
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; break;
case Teuchos::CommandLineProcessor::PARSE_ERROR:
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; break;
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break;
}
Teuchos::RCP<Teuchos::TimeMonitor> globalTimeMonitor = Teuchos::rcp (new Teuchos::TimeMonitor(*Teuchos::TimeMonitor::getNewTimer("Timings: Global Time")));
if (pauseForDebugger) {
Utilities::PauseForDebugger();
}
matrixParameters.check();
xpetraParameters.check();
Xpetra::UnderlyingLib lib = xpetraParameters.GetLib();
if (comm->getRank() == 0) {
std::cout << xpetraParameters << matrixParameters;
}
/**********************************************************************************/
/* CREATE INITIAL MATRIX */
/**********************************************************************************/
Teuchos::RCP<const Map> map;
Teuchos::RCP<Matrix> A;
{
Teuchos::TimeMonitor tm(*Teuchos::TimeMonitor::getNewTimer("Timings: Matrix Build"));
map = MapFactory::Build(lib, matrixParameters.GetNumGlobalElements(), 0, comm);
Teuchos::RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr =
Galeri::Xpetra::BuildProblem<SC,LO,GO,Map,CrsMatrixWrap,MultiVector>(matrixParameters.GetMatrixType(), map, matrixParameters.GetParameterList()); //TODO: Matrix vs. CrsMatrixWrap
A = Pr->BuildMatrix();
}
/**********************************************************************************/
/* */
/**********************************************************************************/
Teuchos::RCP<Hierarchy> hierarchy = Teuchos::rcp(new Hierarchy(A));
hierarchy->SetDefaultVerbLevel(MueLu::toMueLuVerbLevel(Teuchos::VERB_EXTREME));
hierarchy->SetMaxCoarseSize(100);
///////////////////////////////////////////////////////////
Teuchos::RCP<MueLu::Level> Finest = hierarchy->GetLevel(); // get finest level
Finest->Set("A",A);
Teuchos::RCP<AmalgamationFactory> amalgFact = Teuchos::rcp(new AmalgamationFactory());
Teuchos::RCP<CoalesceDropFactory> dropFact = Teuchos::rcp(new CoalesceDropFactory());
dropFact->SetFactory("UnAmalgamationInfo", amalgFact);
// aggregation factory
Teuchos::RCP<UncoupledAggregationFactory> UnCoupledAggFact = Teuchos::rcp(new UncoupledAggregationFactory(/*dropFact*/));
UnCoupledAggFact->SetFactory("Graph", dropFact);
UnCoupledAggFact->SetFactory("DofsPerNode", dropFact);
//UnCoupledAggFact->SetFactory("Graph", dropFact); // UnCoupledAggFact not changed to new factory handling
//UnCoupledAggFact->SetMinNodesPerAggregate(minPerAgg);
//.........这里部分代码省略.........
示例5: main
//.........这里部分代码省略.........
// This *will* result in "strip" distribution if the #processors is a prime number or if the factors are very different in
// size. For example, np=14 will give a 7-by-2 distribution.
// If you don't want Galeri to do this, specify mx or my on the galeriList.
Teuchos::ParameterList pl = matrixParameters.GetParameterList();
Teuchos::ParameterList galeriList;
galeriList.set("nx", pl.get("nx", nx));
galeriList.set("ny", pl.get("ny", ny));
galeriList.set("nz", pl.get("nz", nz));
if (matrixParameters.GetMatrixType() == "Laplace1D") {
map = MapFactory::Build(xpetraParameters.GetLib(), matrixParameters.GetNumGlobalElements(), 0, comm);
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, MultiVector>("1D", map, matrixParameters.GetParameterList());
}
else if (matrixParameters.GetMatrixType() == "Laplace2D" || matrixParameters.GetMatrixType() == "Star2D") {
map = Galeri::Xpetra::CreateMap<LO, GO, Node>(xpetraParameters.GetLib(), "Cartesian2D", comm, galeriList);
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, MultiVector>("2D", map, matrixParameters.GetParameterList());
}
else if (matrixParameters.GetMatrixType() == "Laplace3D") {
map = Galeri::Xpetra::CreateMap<LO, GO, Node>(xpetraParameters.GetLib(), "Cartesian3D", comm, galeriList);
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, MultiVector>("3D", map, matrixParameters.GetParameterList());
}
//FIXME
if (comm->getRank() == 0) {
GO mx = galeriList.get("mx", -1);
GO my = galeriList.get("my", -1);
std::cout << "Processor subdomains in x direction: " << mx << std::endl
<< "Processor subdomains in y direction: " << my << std::endl
<< "========================================================" << std::endl;
}
Teuchos::RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr =
Galeri::Xpetra::BuildProblem<SC,LO,GO,Map,CrsMatrixWrap,MultiVector>(matrixParameters.GetMatrixType(), map, matrixParameters.GetParameterList());
A = Pr->BuildMatrix();
} //matrix creation
Level fineLevel, coarseLevel;
//RCP<SaPFactory> PFact;
RCP<UncoupledAggregationFactory> aggFact;
RCP<TentativePFactory> PFact;
RCP<CoalesceDropFactory> cdFact;
{
timerName = testName + ": 2 - Setup";
TimeMonitor tm(*TimeMonitor::getNewTimer(timerName));
Teuchos::ParameterList paramList;
if (!xmlFileName.empty())
Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(¶mList), *comm);
MueLuTests::TestHelpers::TestFactory<SC, LO, GO, NO, LMO>::createTwoLevelHierarchy(fineLevel, coarseLevel);
fineLevel.Set("A", A);
cdFact = rcp( new CoalesceDropFactory());
aggFact = rcp( new UncoupledAggregationFactory());
//PFact = rcp( new SaPFactory());
PFact = rcp( new TentativePFactory());
// set factory options according to the XML input file
Teuchos::ParameterList cdList = paramList.sublist("CoalesceDrop");
cdFact->SetParameterList(cdList);
Teuchos::ParameterList aggregationList = paramList.sublist("Aggregates");
aggFact->SetParameterList(aggregationList);
Teuchos::ParameterList prolongatorList = paramList.sublist("Prolongator");
PFact->SetParameterList(prolongatorList);
示例6: main
int main(int argc, char *argv[]) {
#include "MueLu_UseShortNames.hpp"
Teuchos::oblackholestream blackhole;
Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);
bool success = true;
bool verbose = true;
try {
Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
/**********************************************************************************/
/* SET TEST PARAMETERS */
/**********************************************************************************/
// Note: use --help to list available options.
Teuchos::CommandLineProcessor clp(false);
// Default is Laplace1D with nx = 8748.
// It's a nice size for 1D and perfect aggregation. (6561=3^8)
//Nice size for 1D and perfect aggregation on small numbers of processors. (8748=4*3^7)
Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 8748); // manage parameters of the test case
Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra
// custom parameters
int pauseForDebugger=0;
//std::string aggOrdering = "natural";
int minPerAgg=2; //was 3 in simple
int maxNbrAlreadySelected=0;
int printTimings=0;
std::string xmlFile="parameters.xml";
//clp.setOption("aggOrdering",&aggOrdering,"aggregation ordering strategy (natural,graph)");
clp.setOption("debug",&pauseForDebugger,"pause to attach debugger");
clp.setOption("maxNbrSel",&maxNbrAlreadySelected,"maximum # of nbrs allowed to be in other aggregates");
clp.setOption("minPerAgg",&minPerAgg,"minimum #DOFs per aggregate");
clp.setOption("timings",&printTimings,"print timings to screen");
clp.setOption("xmlFile",&xmlFile,"file name containing MueLu multigrid parameters in XML format");
switch (clp.parse(argc,argv)) {
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; break;
case Teuchos::CommandLineProcessor::PARSE_ERROR:
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; break;
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break;
}
Teuchos::RCP<Teuchos::TimeMonitor> globalTimeMonitor = Teuchos::rcp (new Teuchos::TimeMonitor(*Teuchos::TimeMonitor::getNewTimer("Timings: Global Time")));
if (pauseForDebugger) {
Utilities::PauseForDebugger();
}
matrixParameters.check();
xpetraParameters.check();
Xpetra::UnderlyingLib lib = xpetraParameters.GetLib();
if (comm->getRank() == 0) {
std::cout << xpetraParameters << matrixParameters;
}
/**********************************************************************************/
/* CREATE INITIAL MATRIX */
/**********************************************************************************/
Teuchos::RCP<const Map> map;
Teuchos::RCP<Matrix> A;
{
Teuchos::TimeMonitor tm(*Teuchos::TimeMonitor::getNewTimer("Timings: Matrix Build"));
map = MapFactory::Build(lib, matrixParameters.GetNumGlobalElements(), 0, comm);
Teuchos::RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr =
Galeri::Xpetra::BuildProblem<SC,LO,GO,Map,CrsMatrixWrap,MultiVector>(matrixParameters.GetMatrixType(), map, matrixParameters.GetParameterList()); //TODO: Matrix vs. CrsMatrixWrap
A = Pr->BuildMatrix();
}
/**********************************************************************************/
/* */
/**********************************************************************************/
Teuchos::ParameterList paramList;
Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFile, Teuchos::Ptr<Teuchos::ParameterList>(¶mList), *comm);
// create parameter list interpreter
Teuchos::RCP<HierarchyManager> mueluFactory = Teuchos::rcp(new ParameterListInterpreter(paramList));
Teuchos::RCP<Hierarchy> H = mueluFactory->CreateHierarchy();
H->GetLevel(0)->Set< Teuchos::RCP<Matrix> >("A", A);
Teuchos::RCP<MultiVector> nullspace = MultiVectorFactory::Build(A->getRowMap(), 1);
nullspace->putScalar(1.0);
H->GetLevel(0)->Set("Nullspace", nullspace);
// set minimal information about number of layers for semicoarsening...
// This information can also be provided as a user parameter in the xml file using the
// parameter: "semicoarsen: num layers"
H->GetLevel(0)->Set("NumZLayers",matrixParameters.GetParameterList().get<GO>("nz"));
mueluFactory->SetupHierarchy(*H);
for (int l=0; l<H->GetNumLevels(); l++) {
//.........这里部分代码省略.........
示例7: main
int main(int argc, char *argv[]) {
using Teuchos::RCP;
Teuchos::oblackholestream blackhole;
Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
out->setOutputToRootOnly(0);
#ifndef HAVE_TEUCHOS_LONG_LONG_INT
*out << "Warning: scaling test was not compiled with long long int support" << std::endl;
#endif
/**********************************************************************************/
/* SET TEST PARAMETERS */
/**********************************************************************************/
// Note: use --help to list available options.
Teuchos::CommandLineProcessor clp(false);
// Default is Laplace1D with nx = 8748.
// It's a nice size for 1D and perfect aggregation. (6561=3^8)
//Nice size for 1D and perfect aggregation on small numbers of processors. (8748=4*3^7)
Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 8748); // manage parameters of the test case
Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra
// custom parameters
std::string aggOrdering = "natural";
int minPerAgg=2;
int maxNbrAlreadySelected=0;
clp.setOption("aggOrdering",&aggOrdering,"aggregation ordering strategy (natural,random,graph)");
clp.setOption("minPerAgg",&minPerAgg,"minimum #DOFs per aggregate");
clp.setOption("maxNbrSel",&maxNbrAlreadySelected,"maximum # of nbrs allowed to be in other aggregates");
switch (clp.parse(argc,argv)) {
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; break;
case Teuchos::CommandLineProcessor::PARSE_ERROR:
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; break;
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break;
}
matrixParameters.check();
xpetraParameters.check();
// TODO: check custom parameters
if (comm->getRank() == 0) {
std::cout << matrixParameters << xpetraParameters << std::endl;
// TODO: print custom parameters
}
/**********************************************************************************/
/* CREATE INITIAL MATRIX */
/**********************************************************************************/
const RCP<const Map> map = MapFactory::Build(xpetraParameters.GetLib(), matrixParameters.GetNumGlobalElements(), 0, comm);
Teuchos::RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr =
Galeri::Xpetra::BuildProblem<SC,LO,GO,Map,CrsMatrixWrap,MultiVector>(matrixParameters.GetMatrixType(), map, matrixParameters.GetParameterList()); //TODO: Matrix vs. CrsMatrixWrap
RCP<Matrix> A = Pr->BuildMatrix();
// return EXIT_SUCCESS;
/**********************************************************************************/
/* */
/**********************************************************************************/
Level Finest;
Finest.SetLevelID(0); // must be level 0 for NullspaceFactory
Finest.Set("A", A);
Finest.SetFactoryManager( rcp( new FactoryManager() ));
CoupledAggregationFactory CoupledAggFact;
Finest.Request(CoupledAggFact);
*out << "========================= Aggregate option summary =========================" << std::endl;
*out << "min DOFs per aggregate : " << minPerAgg << std::endl;
*out << "min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
CoupledAggFact.SetMinNodesPerAggregate(minPerAgg); //TODO should increase if run anything other than 1D
CoupledAggFact.SetMaxNeighAlreadySelected(maxNbrAlreadySelected);
std::transform(aggOrdering.begin(), aggOrdering.end(), aggOrdering.begin(), ::tolower);
if (aggOrdering == "natural") {
*out << "aggregate ordering : NATURAL" << std::endl;
CoupledAggFact.SetOrdering(MueLu::AggOptions::NATURAL);
} else if (aggOrdering == "random") {
*out << "aggregate ordering : RANDOM" << std::endl;
CoupledAggFact.SetOrdering(MueLu::AggOptions::RANDOM);
} else if (aggOrdering == "graph") {
*out << "aggregate ordering : GRAPH" << std::endl;
CoupledAggFact.SetOrdering(MueLu::AggOptions::GRAPH);
} else {
std::string msg = "main: bad aggregation option """ + aggOrdering + """.";
throw(MueLu::Exceptions::RuntimeError(msg));
}
CoupledAggFact.SetPhase3AggCreation(0.5);
*out << "=============================================================================" << std::endl;
CoupledAggFact.Build(Finest);
return EXIT_SUCCESS;
}