本文整理汇总了C++中teuchos::RCP::IsAvailable方法的典型用法代码示例。如果您正苦于以下问题:C++ RCP::IsAvailable方法的具体用法?C++ RCP::IsAvailable怎么用?C++ RCP::IsAvailable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::RCP
的用法示例。
在下文中一共展示了RCP::IsAvailable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExportAggregates
void ExportAggregates(const Teuchos::RCP<Level>& level, const MueLu::FactoryBase* aggFact,const Teuchos::RCP<const Teuchos::Comm<int> >& comm ) {
if(level->IsAvailable("Aggregates",aggFact) == false) {
std::cout << "no Aggregates available." << std::endl;
return;
}
if(level->IsAvailable("A") == false) {
std::cout << "no matrix A available" << std::endl;
return;
}
Teuchos::RCP<Aggregates> aggregates = level->Get< Teuchos::RCP<Aggregates> >("Aggregates",aggFact);
Teuchos::RCP<Matrix> Op = level->Get<Teuchos::RCP<Matrix> >("A");
Teuchos::RCP<LOVector>vertex2AggId_vector = aggregates->GetVertex2AggId();
Teuchos::RCP<LOVector>procWinner_vector = aggregates->GetProcWinner();
Teuchos::ArrayRCP<LO> vertex2AggId = aggregates->GetVertex2AggId()->getDataNonConst(0);
Teuchos::ArrayRCP<LO> procWinner = aggregates->GetProcWinner()->getDataNonConst(0);
// 1.) prepare for calculating global aggregate ids
std::vector<GlobalOrdinal> numAggsGlobal(comm->getSize(),0);
std::vector<GlobalOrdinal> numAggsLocal(comm->getSize(),0);
std::vector<GlobalOrdinal> minGlobalAggId(comm->getSize(),0);
numAggsLocal[comm->getRank()] = aggregates->GetNumAggregates();
Teuchos::reduceAll(*comm,Teuchos::REDUCE_SUM, comm->getSize(),&numAggsLocal[0], &numAggsGlobal[0]);
for(int i=1; i<Teuchos::as<int>(numAggsGlobal.size()); ++i) {
numAggsGlobal[i] += numAggsGlobal[i-1];
minGlobalAggId[i] = numAggsGlobal[i-1];
}
// 2.) build overlapping vector (global row id (column map) -> global AggId)
Teuchos::RCP<MultiVector> OverlappingRowId2GlobalAggId = MultiVectorFactory::Build(Op->getColMap(),1);
Teuchos::ArrayRCP<Scalar> OverlappingRowId2GlobalAggId_data = OverlappingRowId2GlobalAggId->getDataNonConst(0);
// loop over local aggids
for(LocalOrdinal lrow=0; lrow<vertex2AggId.size(); ++lrow)
{
LocalOrdinal localAggId = vertex2AggId[lrow];
LocalOrdinal localAggIdProc = procWinner[lrow];
GlobalOrdinal globalAggId = minGlobalAggId[localAggIdProc] + localAggId;
OverlappingRowId2GlobalAggId_data[lrow] = globalAggId;
}
// 3.) communicate vector (global row id -> global agg id)
Teuchos::RCP<const Import> importer = ImportFactory::Build(Op->getColMap(), Op->getRowMap());
Teuchos::RCP<MultiVector> RowMap2GlobalAggId = MultiVectorFactory::Build(Op->getRowMap(),1);
RowMap2GlobalAggId->doImport(*OverlappingRowId2GlobalAggId,*importer,Xpetra::INSERT);
Teuchos::ArrayRCP<Scalar> RowMap2GlobalAggId_data = RowMap2GlobalAggId->getDataNonConst(0);
// 4.) write to file
std::stringstream filename;
filename << "aggs_level" << level->GetLevelID() << "_proc" << comm->getRank() << ".out";
std::ofstream fout(filename.str().c_str());
for(size_t i=0; i<RowMap2GlobalAggId->getLocalLength(); i++) {
fout << i << " " << Op->getRowMap()->getGlobalElement(i) << " " << RowMap2GlobalAggId_data[i] << std::endl;
}
fout.close();
}
示例2: main
//.........这里部分代码省略.........
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++) {
Teuchos::RCP<MueLu::Level> level = H->GetLevel(l);
if(level->IsAvailable("A", MueLu::NoFactory::get()) == false) { success = false; H->GetLevel(l)->print(std::cout, MueLu::Debug);}
if(level->IsAvailable("P", MueLu::NoFactory::get()) == false && l>0) { success = false; H->GetLevel(l)->print(std::cout, MueLu::Debug);}
if(level->IsAvailable("R", MueLu::NoFactory::get()) == false && l>0) { success = false; H->GetLevel(l)->print(std::cout, MueLu::Debug);}
if(level->IsAvailable("PreSmoother", MueLu::NoFactory::get()) == false) { success = false; H->GetLevel(l)->print(std::cout, MueLu::Debug);}
if(level->IsAvailable("PostSmoother", MueLu::NoFactory::get()) == false && l<H->GetNumLevels()-1) { success = false; H->GetLevel(l)->print(std::cout, MueLu::Debug);}
if(level->IsAvailable("NumZLayers", MueLu::NoFactory::get()) == true && l>0) { success = false; H->GetLevel(l)->print(std::cout, MueLu::Debug);}
H->GetLevel(l)->print(std::cout, MueLu::Debug);
}
///////////////////////////////////////////////////////////
// =========================================================================
// System solution (Ax = b)
// =========================================================================
comm->barrier();
typedef Teuchos::ScalarTraits<SC> STS;
SC zero = STS::zero(), one = STS::one();
Teuchos::RCP<Vector> X = VectorFactory::Build(A->getRowMap());
Teuchos::RCP<Vector> B = VectorFactory::Build(A->getRowMap());
{
// we set seed for reproducibility
Utilities::SetRandomSeed(*comm);
X->randomize();
A->apply(*X, *B, Teuchos::NO_TRANS, one, zero);
Teuchos::Array<STS::magnitudeType> norms(1);
B->norm2(norms);
B->scale(one/norms[0]);
X->putScalar(zero);
}
comm->barrier();
H->IsPreconditioner(false);
H->Iterate(*B, *X, 20);
// Timer final summaries
globalTimeMonitor = Teuchos::null; // stop this timer before summary
if (printTimings)
Teuchos::TimeMonitor::summarize();
}
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
}