本文整理汇总了C++中Level::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ Level::Set方法的具体用法?C++ Level::Set怎么用?C++ Level::Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level
的用法示例。
在下文中一共展示了Level::Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Aggregates
TEUCHOS_UNIT_TEST(CoarseMap, StandardCase)
{
out << "version: " << MueLu::Version() << std::endl;
Level myLevel;
myLevel.SetLevelID(0);
RCP<Matrix> A = TestHelpers::TestFactory<SC, LO, GO, NO, LMO>::Build1DPoisson(15);
myLevel.Set("A", A);
// build dummy aggregate structure
Teuchos::RCP<Aggregates> aggs = Teuchos::rcp(new Aggregates(A->getRowMap()));
aggs->SetNumAggregates(10); // set (local!) number of aggregates
myLevel.Set("Aggregates", aggs);
// build dummy nullspace vector
Teuchos::RCP<MultiVector> nsp = MultiVectorFactory::Build(A->getRowMap(),1);
nsp->putScalar(1.0);
myLevel.Set("Nullspace", nsp);
RCP<CoarseMapFactory> myCMF = Teuchos::rcp(new CoarseMapFactory());
myLevel.Request("CoarseMap",myCMF.get());
myCMF->SetFactory("Aggregates",MueLu::NoFactory::getRCP());
myCMF->SetFactory("Nullspace",MueLu::NoFactory::getRCP());
myCMF->Build(myLevel);
Teuchos::RCP<const Map> myCoarseMap = myLevel.Get<Teuchos::RCP<const Map> >("CoarseMap",myCMF.get());
TEST_EQUALITY(myCoarseMap->getMinAllGlobalIndex() == 0, true);
TEST_EQUALITY(myCoarseMap->getMaxLocalIndex()==9,true);
}
示例2: matter
void TopRAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level & fineLevel, Level & coarseLevel) const {
if ((PFact_ != Teuchos::null) && (PFact_ != NoFactory::getRCP())) {
RCP<Operator> oP = coarseLevel.Get<RCP<Operator> >("P", PFact_.get());
RCP<Matrix> P = rcp_dynamic_cast<Matrix>(oP);
if (!P.is_null()) coarseLevel.Set("P", P, NoFactory::get());
else coarseLevel.Set("P", oP, NoFactory::get());
coarseLevel.AddKeepFlag ("P", NoFactory::get(), MueLu::Final); // FIXME2: Order of Remove/Add matter (data removed otherwise). Should do something about this
coarseLevel.RemoveKeepFlag("P", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack, I should change behavior of Level::Set() instead. FIXME3: Should not be removed if flag was there already
}
if ((RFact_ != Teuchos::null) && (RFact_ != NoFactory::getRCP()) ) {
RCP<Operator> oR = coarseLevel.Get<RCP<Operator> >("R", RFact_.get());
RCP<Matrix> R = rcp_dynamic_cast<Matrix>(oR);
if (!R.is_null()) coarseLevel.Set("R", R, NoFactory::get());
else coarseLevel.Set("R", oR, NoFactory::get());
coarseLevel.AddKeepFlag ("R", NoFactory::get(), MueLu::Final);
coarseLevel.RemoveKeepFlag("R", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack
}
if ((AcFact_ != Teuchos::null) && (AcFact_ != NoFactory::getRCP())) {
RCP<Operator> oA = coarseLevel.Get<RCP<Operator> >("A", AcFact_.get());
RCP<Matrix> A = rcp_dynamic_cast<Matrix>(oA);
if (!A.is_null()) coarseLevel.Set("A", A, NoFactory::get());
else coarseLevel.Set("A", oA, NoFactory::get());
coarseLevel.AddKeepFlag ("A", NoFactory::get(), MueLu::Final);
coarseLevel.RemoveKeepFlag("A", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack
}
}
示例3:
void TopSmootherFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level & level) const {
if (preSmootherFact_.is_null() && postSmootherFact_.is_null())
return;
// NOTE 1: We need to set at least some keep flag for the smoothers, otherwise it is going to be removed as soon as all requests are released.
// We choose to set the Final flag for the data. In addition, we allow this data to be retrieved by only using the name by the means
// of using NoFactory. However, any data set with NoFactory gets UserData flag by default. We don't really want that flag, so we remove it.
// NOTE 2: some smoother factories are tricky (see comments in MueLu::SmootherFactory
// Sometimes, we don't know whether the factory is able to generate "PreSmoother" or "PostSmoother"
// For the SmootherFactory, however, we are able to check that.
if (!preSmootherFact_.is_null()) {
// Checking for null is not sufficient, as SmootherFactory(null, something) does not generate "PreSmoother"
bool isAble = true;
RCP<const SmootherFactory> s = rcp_dynamic_cast<const SmootherFactory>(preSmootherFact_);
if (!s.is_null()) {
RCP<SmootherPrototype> pre, post;
s->GetSmootherPrototypes(pre, post);
if (pre.is_null())
isAble = false;
} else {
// We assume that if presmoother factory is not SmootherFactory, it *is* able to generate "PreSmoother"
}
if (isAble) {
RCP<SmootherBase> Pre = level.Get<RCP<SmootherBase> >("PreSmoother", preSmootherFact_.get());
level.Set ("PreSmoother", Pre, NoFactory::get());
level.AddKeepFlag ("PreSmoother", NoFactory::get(), MueLu::Final);
level.RemoveKeepFlag("PreSmoother", NoFactory::get(), MueLu::UserData);
}
}
if (!postSmootherFact_.is_null()) {
// Checking for null is not sufficient, as SmootherFactory(something, null) does not generate "PostSmoother"
bool isAble = true;
RCP<const SmootherFactory> s = rcp_dynamic_cast<const SmootherFactory>(postSmootherFact_);
if (!s.is_null()) {
RCP<SmootherPrototype> pre, post;
s->GetSmootherPrototypes(pre, post);
if (post.is_null())
isAble = false;
} else {
// We assume that if presmoother factory is not SmootherFactory, it *is* able to generate "PreSmoother"
}
if (isAble) {
RCP<SmootherBase> Post = level.Get<RCP<SmootherBase> >("PostSmoother", postSmootherFact_.get());
level.Set ("PostSmoother", Post, NoFactory::get());
level.AddKeepFlag ("PostSmoother", NoFactory::get(), MueLu::Final);
level.RemoveKeepFlag("PostSmoother", NoFactory::get(), MueLu::UserData);
}
}
}
示例4: m
void RebalanceMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(Level &level) const {
FactoryMonitor m(*this, "Build", level);
//Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
// extract data from Level object
const Teuchos::ParameterList & pL = GetParameterList();
std::string mapName = pL.get<std::string> ("Map name");
Teuchos::RCP<const FactoryBase> mapFactory = GetFactory ("Map factory");
RCP<const Import> rebalanceImporter = Get<RCP<const Import> >(level, "Importer");
if(rebalanceImporter != Teuchos::null) {
// input map (not rebalanced)
RCP<const Map> map = level.Get< RCP<const Map> >(mapName,mapFactory.get());
// create vector based on input map
// Note, that the map can be a part only of the full map stored in rebalanceImporter.getSourceMap()
RCP<Vector> v = VectorFactory::Build(map);
v->putScalar(1.0);
// create a new vector based on the full rebalanceImporter.getSourceMap()
// import the partial map information to the full source map
RCP<const Import> blowUpImporter = ImportFactory::Build(map, rebalanceImporter->getSourceMap());
RCP<Vector> pv = VectorFactory::Build(rebalanceImporter->getSourceMap());
pv->doImport(*v,*blowUpImporter,Xpetra::INSERT);
// do rebalancing using rebalanceImporter
RCP<Vector> ptv = VectorFactory::Build(rebalanceImporter->getTargetMap());
ptv->doImport(*pv,*rebalanceImporter,Xpetra::INSERT);
if (pL.get<bool>("repartition: use subcommunicators") == true)
ptv->replaceMap(ptv->getMap()->removeEmptyProcesses());
// reconstruct rebalanced partial map
Teuchos::ArrayRCP< const Scalar > ptvData = ptv->getData(0);
std::vector<GlobalOrdinal> localGIDs; // vector with GIDs that are stored on current proc
for (size_t k = 0; k < ptv->getLocalLength(); k++) {
if(ptvData[k] == 1.0) {
localGIDs.push_back(ptv->getMap()->getGlobalElement(k));
}
}
const Teuchos::ArrayView<const GlobalOrdinal> localGIDs_view(&localGIDs[0],localGIDs.size());
Teuchos::RCP<const Map> localGIDsMap = MapFactory::Build(
map->lib(),
Teuchos::OrdinalTraits<int>::invalid(),
localGIDs_view,
0, ptv->getMap()->getComm()); // use correct communicator here!
// store rebalanced partial map using the same name and generating factory as the original map
// in the level class
level.Set(mapName, localGIDsMap, mapFactory.get());
}
} //Build()
示例5: matter
void TopRAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Build(Level & fineLevel, Level & coarseLevel) const {
if (PFact_ != Teuchos::null) {
RCP<Matrix> P = coarseLevel.Get<RCP<Matrix> >("P", PFact_.get());
coarseLevel.Set ("P", P, NoFactory::get());
coarseLevel.AddKeepFlag ("P", NoFactory::get(), MueLu::Final); // FIXME2: Order of Remove/Add matter (data removed otherwise). Should do something about this
coarseLevel.RemoveKeepFlag("P", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack, I should change behavior of Level::Set() instead. FIXME3: Should not be removed if flag was there already
}
if (RFact_ != Teuchos::null) {
RCP<Matrix> R = coarseLevel.Get<RCP<Matrix> >("R", RFact_.get());
coarseLevel.Set ("R", R, NoFactory::get());
coarseLevel.AddKeepFlag ("R", NoFactory::get(), MueLu::Final);
coarseLevel.RemoveKeepFlag("R", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack
}
if ((AcFact_ != Teuchos::null) && (AcFact_ != NoFactory::getRCP())) {
RCP<Matrix> Ac = coarseLevel.Get<RCP<Matrix> >("A", AcFact_.get());
coarseLevel.Set ("A", Ac, NoFactory::get());
coarseLevel.AddKeepFlag ("A", NoFactory::get(), MueLu::Final);
coarseLevel.RemoveKeepFlag("A", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack
}
}
示例6: m
void MapTransferFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Build(Level & fineLevel, Level & coarseLevel) const {
typedef Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> OperatorClass; //TODO
typedef Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> MapClass;
typedef Xpetra::MapFactory<LocalOrdinal, GlobalOrdinal, Node> MapFactoryClass;
Monitor m(*this, "Contact Map transfer factory");
if (fineLevel.IsAvailable(mapName_, mapFact_.get())==false) {
GetOStream(Runtime0, 0) << "MapTransferFactory::Build: User provided map " << mapName_ << " not found in Level class." << std::endl;
}
// fetch map extractor from level
RCP<const MapClass> transferMap = fineLevel.Get<RCP<const MapClass> >(mapName_,mapFact_.get());
// Get default tentative prolongator factory
// Getting it that way ensure that the same factory instance will be used for both SaPFactory and NullspaceFactory.
// -- Warning: Do not use directly initialPFact_. Use initialPFact instead everywhere!
RCP<const FactoryBase> tentPFact = GetFactory("P");
if (tentPFact == Teuchos::null) { tentPFact = coarseLevel.GetFactoryManager()->GetFactory("Ptent"); }
TEUCHOS_TEST_FOR_EXCEPTION(!coarseLevel.IsAvailable("P",tentPFact.get()),Exceptions::RuntimeError, "MueLu::MapTransferFactory::Build(): P (generated by TentativePFactory) not available.");
RCP<OperatorClass> Ptent = coarseLevel.Get<RCP<OperatorClass> >("P", tentPFact.get());
std::vector<GlobalOrdinal > coarseMapGids;
// loop over local rows of Ptent
for(size_t row=0; row<Ptent->getNodeNumRows(); row++) {
GlobalOrdinal grid = Ptent->getRowMap()->getGlobalElement(row);
if(transferMap->isNodeGlobalElement(grid)) {
Teuchos::ArrayView<const LocalOrdinal> indices;
Teuchos::ArrayView<const Scalar> vals;
Ptent->getLocalRowView(row, indices, vals);
for(size_t i=0; i<(size_t)indices.size(); i++) {
// mark all columns in Ptent(grid,*) to be coarse Dofs of next level transferMap
GlobalOrdinal gcid = Ptent->getColMap()->getGlobalElement(indices[i]);
coarseMapGids.push_back(gcid);
}
} // end if isNodeGlobalElement(grid)
}
// build column maps
std::sort(coarseMapGids.begin(), coarseMapGids.end());
coarseMapGids.erase(std::unique(coarseMapGids.begin(), coarseMapGids.end()), coarseMapGids.end());
Teuchos::ArrayView<GlobalOrdinal> coarseMapGidsView (&coarseMapGids[0],coarseMapGids.size());
Teuchos::RCP<const MapClass> coarseTransferMap = MapFactoryClass::Build(Ptent->getColMap()->lib(), -1, coarseMapGidsView, Ptent->getColMap()->getIndexBase(), Ptent->getColMap()->getComm());
// store map extractor in coarse level
coarseLevel.Set(mapName_, coarseTransferMap, mapFact_.get());
}
示例7: set
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoarseMap_kokkos, StandardCase, Scalar, LocalOrdinal, GlobalOrdinal, Node)
{
# include "MueLu_UseShortNames.hpp"
RUN_EPETRA_ONLY_WITH_SERIAL_NODE(Node);
MueLu::VerboseObject::SetDefaultOStream(Teuchos::rcpFromRef(out));
out << "version: " << MueLu::Version() << std::endl;
Level fineLevel;
TestHelpers_kokkos::TestFactory<SC,LO,GO,NO>::createSingleLevelHierarchy(fineLevel);
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(15);
fineLevel.Set("A", A);
// build dummy aggregate structure
RCP<Aggregates_kokkos> aggs = Teuchos::rcp(new Aggregates_kokkos(A->getRowMap()));
aggs->SetNumAggregates(10); // set (local!) number of aggregates
fineLevel.Set("Aggregates", aggs);
// build dummy nullspace vector
RCP<MultiVector> nsp = MultiVectorFactory::Build(A->getRowMap(),1);
nsp->putScalar(1.0);
fineLevel.Set("Nullspace", nsp);
RCP<CoarseMapFactory_kokkos> coarseMapFactory = Teuchos::rcp(new CoarseMapFactory_kokkos());
coarseMapFactory->SetFactory("Aggregates", MueLu::NoFactory::getRCP());
coarseMapFactory->SetFactory("Nullspace", MueLu::NoFactory::getRCP());
fineLevel.Request("CoarseMap", coarseMapFactory.get());
coarseMapFactory->Build(fineLevel);
auto myCoarseMap = fineLevel.Get<Teuchos::RCP<const Map> >("CoarseMap", coarseMapFactory.get());
TEST_EQUALITY(myCoarseMap->getMinAllGlobalIndex() == 0, true);
TEST_EQUALITY(myCoarseMap->getMaxLocalIndex() == 9, true);
}
示例8: rcp
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(ThresholdAFilterFactory, Basic, Scalar, LocalOrdinal, GlobalOrdinal, Node)
{
# include <MueLu_UseShortNames.hpp>
MUELU_TESTING_SET_OSTREAM;
MUELU_TESTING_LIMIT_EPETRA_SCOPE(Scalar,GlobalOrdinal,Node);
out << "version: " << MueLu::Version() << std::endl;
Level aLevel;
TestHelpers::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(aLevel);
RCP<Matrix> A = TestHelpers::TestFactory<SC, LO, GO, NO>::Build1DPoisson(20); //can be an empty operator
RCP<ThresholdAFilterFactory> AfilterFactory0 = rcp(new ThresholdAFilterFactory("A",0.1)); // keep all
RCP<ThresholdAFilterFactory> AfilterFactory1 = rcp(new ThresholdAFilterFactory("A",1.1)); // keep only diagonal
RCP<ThresholdAFilterFactory> AfilterFactory2 = rcp(new ThresholdAFilterFactory("A",3)); // keep only diagonal
aLevel.Set("A",A);
aLevel.Request("A",AfilterFactory0.get());
AfilterFactory0->Build(aLevel);
TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory0.get()), true);
RCP<Matrix> A0 = aLevel.Get< RCP<Matrix> >("A",AfilterFactory0.get());
aLevel.Release("A",AfilterFactory0.get());
TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory0.get()), false);
TEST_EQUALITY(A0->getNodeNumEntries(), A->getNodeNumEntries());
TEST_EQUALITY(A0->getGlobalNumEntries(), A->getGlobalNumEntries());
aLevel.Request("A",AfilterFactory1.get());
AfilterFactory1->Build(aLevel);
TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory1.get()), true);
RCP<Matrix> A1 = aLevel.Get< RCP<Matrix> >("A",AfilterFactory1.get());
aLevel.Release("A",AfilterFactory1.get());
TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory1.get()), false);
TEST_EQUALITY(A1->getGlobalNumEntries(), A1->getGlobalNumRows());
aLevel.Request("A",AfilterFactory2.get());
AfilterFactory2->Build(aLevel);
TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory2.get()), true);
RCP<Matrix> A2 = aLevel.Get< RCP<Matrix> >("A",AfilterFactory2.get());
aLevel.Release("A",AfilterFactory2.get());
TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory2.get()), false);
TEST_EQUALITY(A2->getGlobalNumEntries(), A2->getGlobalNumRows());
}
示例9: gimmeUncoupledAggregates
Teuchos::RCP<MueLu::Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Node>>
gimmeUncoupledAggregates(const Teuchos::RCP<Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>>& A,
Teuchos::RCP<MueLu::AmalgamationInfo<LocalOrdinal, GlobalOrdinal, Node>>& amalgInfo,
bool bPhase1 = true, bool bPhase2a = true, bool bPhase2b = true, bool bPhase3 = true) {
# include "MueLu_UseShortNames.hpp"
Level level;
TestHelpers_kokkos::TestFactory<SC,LO,GO,NO>::createSingleLevelHierarchy(level);
level.Set("A", A);
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos());
dropFact->SetFactory("UnAmalgamationInfo", amalgFact);
using Teuchos::ParameterEntry;
// Setup aggregation factory (use default factory for graph)
RCP<UncoupledAggregationFactory_kokkos> aggFact = rcp(new UncoupledAggregationFactory_kokkos());
aggFact->SetFactory("Graph", dropFact);
aggFact->SetParameter("aggregation: max agg size", ParameterEntry(3));
aggFact->SetParameter("aggregation: min agg size", ParameterEntry(3));
aggFact->SetParameter("aggregation: max selected neighbors", ParameterEntry(0));
aggFact->SetParameter("aggregation: ordering", ParameterEntry(std::string("natural")));
aggFact->SetParameter("aggregation: enable phase 1", ParameterEntry(bPhase1));
aggFact->SetParameter("aggregation: enable phase 2a", ParameterEntry(bPhase2a));
aggFact->SetParameter("aggregation: enable phase 2b", ParameterEntry(bPhase2b));
aggFact->SetParameter("aggregation: enable phase 3", ParameterEntry(bPhase3));
level.Request("Aggregates", aggFact.get());
level.Request("UnAmalgamationInfo", amalgFact.get());
level.Request(*aggFact);
aggFact->Build(level);
auto aggregates = level.Get<RCP<Aggregates_kokkos> >("Aggregates", aggFact.get());
amalgInfo = level.Get<RCP<AmalgamationInfo> >("UnAmalgamationInfo", amalgFact.get());
level.Release("UnAmalgamationInfo", amalgFact.get());
level.Release("Aggregates", aggFact.get());
return aggregates;
}
示例10: rcp
TEUCHOS_UNIT_TEST(Zoltan, Build3PDEs)
{
typedef Teuchos::ScalarTraits<Scalar> ST;
out << "version: " << MueLu::Version() << std::endl;
out << std::endl;
out << "This tests that the partitioning produced by Zoltan is \"reasonable\" for a matrix" << std::endl;
out << "that has a random number of nonzeros per row and 3 DOFs per mesh point. Good results have been precomputed" << std::endl;
out << "for up to 5 processors. The results are the number of nonzeros in the local matrix" << std::endl;
out << "once the Zoltan repartitioning has been applied." << std::endl;
out << "The results can be viewed in Paraview by enabling code guarded by the macro MUELU_VISUALIZE_REPARTITIONING" << std::endl;
RCP<const Teuchos::Comm<int> > comm = TestHelpers::Parameters::getDefaultComm();
if (comm->getSize() > 5) {
out << std::endl;
out << "This test must be run on 1 to 5 processes." << std::endl;
TEST_EQUALITY(true, true);
return;
}
Level level;
RCP<FactoryManagerBase> factoryHandler = rcp(new FactoryManager());
level.SetFactoryManager(factoryHandler);
int nx=9;
int ny=nx;
int dofsPerNode = 3;
GO numGlobalElements = nx*ny*dofsPerNode;
size_t maxEntriesPerRow=30;
RCP<const Map> map;
int numMyNodes = numGlobalElements / dofsPerNode;
if (comm->getSize() > 1) {
// In parallel, make sure that the dof's associated with a node all
// reside on the same processor.
int numNodes = numGlobalElements / dofsPerNode;
TEUCHOS_TEST_FOR_EXCEPTION( (numGlobalElements - numNodes * dofsPerNode) != 0, MueLu::Exceptions::RuntimeError,
"Number of matrix rows is not divisible by #dofs" );
int nproc = comm->getSize();
if (comm->getRank() < nproc-1) numMyNodes = numNodes / nproc;
else numMyNodes = numNodes - (numNodes/nproc) * (nproc-1);
map = MapFactory::createContigMap(TestHelpers::Parameters::getLib(), numGlobalElements, numMyNodes*dofsPerNode, comm);
} else {
map = MapFactory::createUniformContigMap(TestHelpers::Parameters::getLib(), numGlobalElements, comm);
}
const size_t numMyElements = map->getNodeNumElements();
Teuchos::ArrayView<const GlobalOrdinal> myGlobalElements = map->getNodeElementList();
RCP<Matrix> A = rcp(new CrsMatrixWrap(map, 1)); // Force underlying linear algebra library to allocate more
// memory on the fly. While not super efficient, this
// ensures that no zeros are being stored. Thus, from
// Zoltan's perspective the matrix is imbalanced.
// Populate CrsMatrix with random number of entries (up to maxEntriesPerRow) per row.
// Create a vector with random integer entries in [1,maxEntriesPerRow].
ST::seedrandom(666*comm->getRank());
RCP<Xpetra::Vector<LO,LO,GO,NO> > entriesPerRow = Xpetra::VectorFactory<LO,LO,GO,NO>::Build(map,false);
Teuchos::ArrayRCP<LO> eprData = entriesPerRow->getDataNonConst(0);
for (Teuchos::ArrayRCP<LO>::iterator i=eprData.begin(); i!=eprData.end(); ++i) {
*i = (LO)(std::floor(((ST::random()+1)*0.5*maxEntriesPerRow)+1));
}
RCP<Teuchos::FancyOStream> fos = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
fos->setOutputToRootOnly(-1);
Teuchos::Array<Scalar> vals(maxEntriesPerRow);
Teuchos::Array<GO> cols(maxEntriesPerRow);
for (size_t i = 0; i < numMyElements; ++i) {
Teuchos::ArrayView<SC> av(&vals[0],eprData[i]);
Teuchos::ArrayView<GO> iv(&cols[0],eprData[i]);
//stick in ones for values
for (LO j=0; j< eprData[i]; ++j) vals[j] = ST::one();
//figure out valid column indices
GO start = std::max(myGlobalElements[i]-eprData[i]+1,0);
for (LO j=0; j< eprData[i]; ++j) cols[j] = start+j;
A->insertGlobalValues(myGlobalElements[i], iv, av);
}
A->fillComplete();
// Now treat the matrix as if it has 3 DOFs per node.
A->SetFixedBlockSize(dofsPerNode);
level.Set("A",A);
//build coordinates
Teuchos::ParameterList list;
list.set("nx",nx);
list.set("ny",ny);
RCP<const Map> coalescedMap = MapFactory::createContigMap(TestHelpers::Parameters::getLib(), numGlobalElements/dofsPerNode, numMyNodes, comm);
RCP<MultiVector> XYZ = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map,MultiVector>("2D",coalescedMap,list);
// XYZ are the "coalesce" coordinates as it has been generated for 1 DOF/node and we are using them for 3 DOFS/node
// level.Set("Coordinates",XYZ); "Coordinates" == uncoalesce. "X,Y,ZCoordinates" == coalesce
{
RCP<MultiVector> coordinates = XYZ;
// making a copy because I don't want to keep 'open' the Xpetra_MultiVector
if (coordinates->getNumVectors() >= 1) {
Teuchos::ArrayRCP<const SC> coord = coordinates->getData(0);
Teuchos::ArrayRCP<SC> coordCpy(coord.size());
//.........这里部分代码省略.........
示例11: fineSFM
void BlockedPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Build(Level& fineLevel, Level &coarseLevel) const {
typedef Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> MatrixClass;
typedef Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> CrsMatrixClass;
typedef Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> CrsMatrixWrapClass;
typedef Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> BlockedCrsOMatrix;
typedef Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> MapClass;
typedef Xpetra::MapFactory<LocalOrdinal, GlobalOrdinal, Node> MapFactoryClass;
typedef Xpetra::MapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node> MapExtractorClass;
typedef Xpetra::MapExtractorFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node> MapExtractorFactoryClass;
//Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
//std::ostringstream buf; buf << coarseLevel.GetLevelID();
// Level Get
//RCP<Matrix> A = fineLevel. Get< RCP<Matrix> >("A", AFact_.get()); // IMPORTANT: use main factory manager for getting A
RCP<Matrix> A = Get< RCP<Matrix> >(fineLevel, "A");
RCP<BlockedCrsOMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsOMatrix>(A);
TEUCHOS_TEST_FOR_EXCEPTION(bA==Teuchos::null, Exceptions::BadCast, "MueLu::BlockedPFactory::Build: input matrix A is not of type BlockedCrsMatrix! error.");
// plausibility check
TEUCHOS_TEST_FOR_EXCEPTION(bA->Rows() != FactManager_.size(), Exceptions::RuntimeError, "MueLu::BlockedPFactory::Build: number of block rows of A does not match number of SubFactoryManagers. error.");
TEUCHOS_TEST_FOR_EXCEPTION(bA->Cols() != FactManager_.size(), Exceptions::RuntimeError, "MueLu::BlockedPFactory::Build: number of block cols of A does not match number of SubFactoryManagers. error.");
// build blocked prolongator
std::vector<RCP<Matrix> > subBlockP;
std::vector<RCP<const MapClass> > subBlockPRangeMaps;
std::vector<RCP<const MapClass > > subBlockPDomainMaps;
std::vector<GO> fullRangeMapVector;
std::vector<GO> fullDomainMapVector;
subBlockP.reserve(FactManager_.size()); // reserve size for block P operators
subBlockPRangeMaps.reserve(FactManager_.size()); // reserve size for block P operators
subBlockPDomainMaps.reserve(FactManager_.size()); // reserve size for block P operators
// build and store the subblocks and the corresponding range and domain maps
// since we put together the full range and domain map from the submaps we do not have
// to use the maps from blocked A
std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
for(it = FactManager_.begin(); it!=FactManager_.end(); ++it) {
SetFactoryManager fineSFM (rcpFromRef(fineLevel), *it);
SetFactoryManager coarseSFM(rcpFromRef(coarseLevel), *it);
if(!restrictionMode_) {
subBlockP.push_back(coarseLevel.Get<RCP<Matrix> >("P", (*it)->GetFactory("P").get())); // create and return block P operator
}
else {
subBlockP.push_back(coarseLevel.Get<RCP<Matrix> >("R", (*it)->GetFactory("R").get())); // create and return block R operator
}
// check if prolongator/restrictor operators have strided maps
TEUCHOS_TEST_FOR_EXCEPTION(subBlockP.back()->IsView("stridedMaps")==false, Exceptions::BadCast, "MueLu::BlockedPFactory::Build: subBlock P operator has no strided map information. error.");
// append strided row map (= range map) to list of range maps.
Teuchos::RCP<const Map> rangeMap = subBlockP.back()->getRowMap("stridedMaps"); /* getRangeMap(); //*/
subBlockPRangeMaps.push_back(rangeMap);
// use plain range map to determine the DOF ids
Teuchos::ArrayView< const GlobalOrdinal > nodeRangeMap = subBlockP.back()->getRangeMap()->getNodeElementList(); //subBlockPRangeMaps.back()->getNodeElementList();
fullRangeMapVector.insert(fullRangeMapVector.end(), nodeRangeMap.begin(), nodeRangeMap.end());
sort(fullRangeMapVector.begin(), fullRangeMapVector.end());
// append strided col map (= domain map) to list of range maps.
Teuchos::RCP<const Map> domainMap = subBlockP.back()->getColMap("stridedMaps"); /* getDomainMap(); //*/
subBlockPDomainMaps.push_back(domainMap);
// use plain domain map to determine the DOF ids
Teuchos::ArrayView< const GlobalOrdinal > nodeDomainMap = subBlockP.back()->getDomainMap()->getNodeElementList(); //subBlockPDomainMaps.back()->getNodeElementList();
fullDomainMapVector.insert(fullDomainMapVector.end(), nodeDomainMap.begin(), nodeDomainMap.end());
sort(fullDomainMapVector.begin(), fullDomainMapVector.end());
}
// extract map index base from maps of blocked A
GO rangeIndexBase = 0;
GO domainIndexBase = 0;
if(!restrictionMode_) { // prolongation mode: just use index base of range and domain map of bA
rangeIndexBase = bA->getRangeMap()->getIndexBase();
domainIndexBase= bA->getDomainMap()->getIndexBase();
} else { // restriction mode: switch range and domain map for blocked restriction operator
rangeIndexBase = bA->getDomainMap()->getIndexBase();
domainIndexBase= bA->getRangeMap()->getIndexBase();
}
// build full range map.
// If original range map has striding information, then transfer it to the new range map
RCP<const MapExtractorClass> rangeAMapExtractor = bA->getRangeMapExtractor();
Teuchos::ArrayView<GO> fullRangeMapGIDs(&fullRangeMapVector[0],fullRangeMapVector.size());
Teuchos::RCP<const StridedMap> stridedRgFullMap = Teuchos::rcp_dynamic_cast<const StridedMap>(rangeAMapExtractor->getFullMap());
Teuchos::RCP<const Map > fullRangeMap = Teuchos::null;
if(stridedRgFullMap != Teuchos::null) {
std::vector<size_t> stridedData = stridedRgFullMap->getStridingData();
fullRangeMap =
StridedMapFactory::Build(
bA->getRangeMap()->lib(),
Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(),
fullRangeMapGIDs,
rangeIndexBase,
stridedData,
bA->getRangeMap()->getComm(),
stridedRgFullMap->getStridedBlockId(),
//.........这里部分代码省略.........
示例12: GetParameterList
void SubBlockAFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Build(Level & currentLevel) const {
typedef Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> OMatrix; //TODO
typedef Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> CrsMatrixClass; //TODO
typedef Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> CrsMatrixWrapClass; //TODO
typedef Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> BlockedCrsOMatrix; //TODO
typedef Xpetra::MapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node> MapExtractorClass;
const ParameterList & pL = GetParameterList();
size_t row = Teuchos::as<size_t>(pL.get<int>("block row"));
size_t col = Teuchos::as<size_t>(pL.get<int>("block col"));
RCP<OMatrix> Ain = Teuchos::null;
Ain = Get< RCP<OMatrix> >(currentLevel, "A");
RCP<BlockedCrsOMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsOMatrix>(Ain);
TEUCHOS_TEST_FOR_EXCEPTION(bA==Teuchos::null, Exceptions::BadCast, "MueLu::SubBlockAFactory::Build: input matrix A is not of type BlockedCrsMatrix! error.");
TEUCHOS_TEST_FOR_EXCEPTION(row > bA->Rows(), Exceptions::RuntimeError, "MueLu::SubBlockAFactory::Build: A.Rows() > rows_! error.");
TEUCHOS_TEST_FOR_EXCEPTION(col > bA->Cols(), Exceptions::RuntimeError, "MueLu::SubBlockAFactory::Build: A.Cols() > cols_! error.");
Teuchos::RCP<CrsMatrixClass> A = bA->getMatrix(row, col);
Teuchos::RCP<CrsMatrixWrapClass> Op = Teuchos::rcp(new CrsMatrixWrapClass(A));
//////////////// EXPERIMENTAL
// extract striding information from RangeMapExtractor
Teuchos::RCP<const MapExtractorClass> rgMapExtractor = bA->getRangeMapExtractor();
Teuchos::RCP<const MapExtractorClass> doMapExtractor = bA->getDomainMapExtractor();
Teuchos::RCP<const Map> rgMap = rgMapExtractor->getMap(row);
Teuchos::RCP<const Map> doMap = doMapExtractor->getMap(col);
Teuchos::RCP<const StridedMap> srgMap = Teuchos::rcp_dynamic_cast<const StridedMap>(rgMap);
Teuchos::RCP<const StridedMap> sdoMap = Teuchos::rcp_dynamic_cast<const StridedMap>(doMap);
if(srgMap == Teuchos::null) {
Teuchos::RCP<const Map> fullRgMap = rgMapExtractor->getFullMap();
Teuchos::RCP<const StridedMap> sFullRgMap = Teuchos::rcp_dynamic_cast<const StridedMap>(fullRgMap);
TEUCHOS_TEST_FOR_EXCEPTION(sFullRgMap==Teuchos::null, Exceptions::BadCast, "MueLu::SubBlockAFactory::Build: full rangeMap is not a strided map");
std::vector<size_t> stridedData = sFullRgMap->getStridingData();
if(stridedData.size() == 1 && row > 0) // we have block matrices. use striding block information 0
srgMap = StridedMapFactory::Build(rgMap, stridedData, 0, sFullRgMap->getOffset());
else // we have strided matrices. use striding information of the corresponding block
srgMap = StridedMapFactory::Build(rgMap, stridedData, row, sFullRgMap->getOffset());
}
if(sdoMap == Teuchos::null) {
Teuchos::RCP<const Map> fullDoMap = doMapExtractor->getFullMap();
Teuchos::RCP<const StridedMap> sFullDoMap = Teuchos::rcp_dynamic_cast<const StridedMap>(fullDoMap);
TEUCHOS_TEST_FOR_EXCEPTION(sFullDoMap==Teuchos::null, Exceptions::BadCast, "MueLu::SubBlockAFactory::Build: full domainMap is not a strided map");
std::vector<size_t> stridedData2 = sFullDoMap->getStridingData();
if(stridedData2.size() == 1 && col > 0) // we have block matrices. use striding block information 0
sdoMap = StridedMapFactory::Build(doMap, stridedData2, 0, sFullDoMap->getOffset());
else // we have strided matrices. use striding information of the corresponding block
sdoMap = StridedMapFactory::Build(doMap, stridedData2, col, sFullDoMap->getOffset());
}
TEUCHOS_TEST_FOR_EXCEPTION(srgMap==Teuchos::null, Exceptions::BadCast, "MueLu::SubBlockAFactory::Build: rangeMap " << row << " is not a strided map");
TEUCHOS_TEST_FOR_EXCEPTION(sdoMap==Teuchos::null, Exceptions::BadCast, "MueLu::SubBlockAFactory::Build: domainMap " << col << " is not a strided map");
GetOStream(Statistics1) << "A(" << row << "," << col << ") has strided maps: range map fixed block size=" << srgMap->getFixedBlockSize() << " strided block id = " << srgMap->getStridedBlockId() << ", domain map fixed block size=" << sdoMap->getFixedBlockSize() << ", strided block id=" << sdoMap->getStridedBlockId() << std::endl;
if(Op->IsView("stridedMaps") == true) Op->RemoveView("stridedMaps");
Op->CreateView("stridedMaps", srgMap, sdoMap);
TEUCHOS_TEST_FOR_EXCEPTION(Op->IsView("stridedMaps")==false, Exceptions::RuntimeError, "MueLu::SubBlockAFactory::Build: failed to set stridedMaps");
//////////////// EXPERIMENTAL
currentLevel.Set("A", Teuchos::rcp_dynamic_cast<OMatrix>(Op), this);
}
示例13: sortingPermutation
//.........这里部分代码省略.........
for(size_t row=0; row<permPTmatrix->getNodeNumRows(); row++) {
if(permPTmatrix->getNumEntriesInLocalRow(row) != 1)
GetOStream(Warnings0,0) <<"#entries in row " << row << " of permPTmatrix is " << permPTmatrix->getNumEntriesInLocalRow(row) << std::endl;
if(permPmatrix->getNumEntriesInLocalRow(row) != 1)
GetOStream(Warnings0,0) <<"#entries in row " << row << " of permPmatrix is " << permPmatrix->getNumEntriesInLocalRow(row) << std::endl;
if(permQTmatrix->getNumEntriesInLocalRow(row) != 1)
GetOStream(Warnings0,0) <<"#entries in row " << row << " of permQmatrix is " << permQTmatrix->getNumEntriesInLocalRow(row) << std::endl;
}
// build permP * A * permQT
Teuchos::RCP<Matrix> ApermQt = Utils::Multiply(*A, false, *permQTmatrix, false);
Teuchos::RCP<Matrix> permPApermQt = Utils::Multiply(*permPmatrix, false, *ApermQt, false);
/*
MueLu::Utils<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Write("A.mat", *A);
MueLu::Utils<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Write("permP.mat", *permPmatrix);
MueLu::Utils<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Write("permQt.mat", *permQTmatrix);
MueLu::Utils<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Write("permPApermQt.mat", *permPApermQt);
*/
// build scaling matrix
Teuchos::RCP<Vector> diagVec = VectorFactory::Build(permPApermQt->getRowMap(),true);
Teuchos::RCP<Vector> invDiagVec = VectorFactory::Build(permPApermQt->getRowMap(),true);
Teuchos::ArrayRCP< const Scalar > diagVecData = diagVec->getData(0);
Teuchos::ArrayRCP< Scalar > invDiagVecData = invDiagVec->getDataNonConst(0);
permPApermQt->getLocalDiagCopy(*diagVec);
for(size_t i = 0; i<diagVec->getMap()->getNodeNumElements(); ++i) {
if(diagVecData[i] != 0.0)
invDiagVecData[i] = 1/diagVecData[i];
else {
invDiagVecData[i] = 1.0;
GetOStream(Statistics0,0) << "MueLu::PermutationFactory: found zero on diagonal in row " << i << std::endl;
}
}
Teuchos::RCP<CrsMatrixWrap> diagScalingOp = Teuchos::rcp(new CrsMatrixWrap(permPApermQt->getRowMap(),1,Xpetra::StaticProfile));
for(size_t row=0; row<A->getNodeNumRows(); row++) {
Teuchos::ArrayRCP<GlobalOrdinal> indout(1,permPApermQt->getRowMap()->getGlobalElement(row)); // column idx for Perm^T
Teuchos::ArrayRCP<Scalar> valout(1,invDiagVecData[row]);
diagScalingOp->insertGlobalValues(A->getRowMap()->getGlobalElement(row), indout.view(0,indout.size()), valout.view(0,valout.size()));
}
diagScalingOp->fillComplete();
Teuchos::RCP<Matrix> scaledA = Utils::Multiply(*diagScalingOp, false, *permPApermQt, false);
currentLevel.Set("A", Teuchos::rcp_dynamic_cast<Matrix>(scaledA), genFactory/*this*/);
currentLevel.Set("permA", Teuchos::rcp_dynamic_cast<Matrix>(permPApermQt), genFactory/*this*/); // TODO careful with this!!!
currentLevel.Set("permP", Teuchos::rcp_dynamic_cast<Matrix>(permPmatrix), genFactory/*this*/);
currentLevel.Set("permQT", Teuchos::rcp_dynamic_cast<Matrix>(permQTmatrix), genFactory/*this*/);
currentLevel.Set("permScaling", Teuchos::rcp_dynamic_cast<Matrix>(diagScalingOp), genFactory/*this*/);
//// count row permutations
// count zeros on diagonal in P -> number of row permutations
Teuchos::RCP<Vector> diagPVec = VectorFactory::Build(permPmatrix->getRowMap(),true);
permPmatrix->getLocalDiagCopy(*diagPVec);
Teuchos::ArrayRCP< const Scalar > diagPVecData = diagPVec->getData(0);
LocalOrdinal lNumRowPermutations = 0;
GlobalOrdinal gNumRowPermutations = 0;
for(size_t i = 0; i<diagPVec->getMap()->getNodeNumElements(); ++i) {
if(diagPVecData[i] == 0.0) {
lNumRowPermutations++;
}
}
// sum up all entries in multipleColRequests over all processors
sumAll(diagPVec->getMap()->getComm(), Teuchos::as<GlobalOrdinal>(lNumRowPermutations), gNumRowPermutations);
//// count column permutations
// count zeros on diagonal in Q^T -> number of column permutations
Teuchos::RCP<Vector> diagQTVec = VectorFactory::Build(permQTmatrix->getRowMap(),true);
permQTmatrix->getLocalDiagCopy(*diagQTVec);
Teuchos::ArrayRCP< const Scalar > diagQTVecData = diagQTVec->getData(0);
LocalOrdinal lNumColPermutations = 0;
GlobalOrdinal gNumColPermutations = 0;
for(size_t i = 0; i<diagQTVec->getMap()->getNodeNumElements(); ++i) {
if(diagQTVecData[i] == 0.0) {
lNumColPermutations++;
}
}
// sum up all entries in multipleColRequests over all processors
sumAll(diagQTVec->getMap()->getComm(), Teuchos::as<GlobalOrdinal>(lNumColPermutations), gNumColPermutations);
currentLevel.Set("#RowPermutations", gNumRowPermutations, genFactory/*this*/);
currentLevel.Set("#ColPermutations", gNumColPermutations, genFactory/*this*/);
currentLevel.Set("#WideRangeRowPermutations", gWideRangeRowPermutations, genFactory/*this*/);
currentLevel.Set("#WideRangeColPermutations", gWideRangeColPermutations, genFactory/*this*/);
GetOStream(Statistics0, 0) << "#Row permutations/max possible permutations: " << gNumRowPermutations << "/" << diagPVec->getMap()->getGlobalNumElements() << std::endl;
GetOStream(Statistics0, 0) << "#Column permutations/max possible permutations: " << gNumColPermutations << "/" << diagQTVec->getMap()->getGlobalNumElements() << std::endl;
GetOStream(Runtime1, 0) << "#wide range row permutations: " << gWideRangeRowPermutations << " #wide range column permutations: " << gWideRangeColPermutations << std::endl;
#else
#warning PermutationFactory not compiling/working for Scalar==complex.
#endif // #ifndef HAVE_MUELU_INST_COMPLEX_INT_INT
}
示例14: GetParameterList
void SubBlockAFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level& currentLevel) const {
const ParameterList& pL = GetParameterList();
size_t row = Teuchos::as<size_t>(pL.get<int>("block row"));
size_t col = Teuchos::as<size_t>(pL.get<int>("block col"));
RCP<Matrix> Ain = Get<RCP<Matrix> >(currentLevel, "A");
RCP<BlockedCrsMatrix> A = rcp_dynamic_cast<BlockedCrsMatrix>(Ain);
TEUCHOS_TEST_FOR_EXCEPTION(A.is_null(), Exceptions::BadCast, "Input matrix A is not a BlockedCrsMatrix.");
TEUCHOS_TEST_FOR_EXCEPTION(row > A->Rows(), Exceptions::RuntimeError, "row [" << row << "] > A.Rows() [" << A->Rows() << "].");
TEUCHOS_TEST_FOR_EXCEPTION(col > A->Cols(), Exceptions::RuntimeError, "col [" << col << "] > A.Cols() [" << A->Cols() << "].");
RCP<CrsMatrixWrap> Op = Teuchos::rcp(new CrsMatrixWrap(A->getMatrix(row, col)));
//////////////// EXPERIMENTAL
// extract striding information from RangeMapExtractor
RCP<const MapExtractor> rangeMapExtractor = A->getRangeMapExtractor();
RCP<const MapExtractor> domainMapExtractor = A->getDomainMapExtractor();
RCP<const Map> rangeMap = rangeMapExtractor ->getMap(row);
RCP<const Map> domainMap = domainMapExtractor->getMap(col);
RCP<const StridedMap> srangeMap = rcp_dynamic_cast<const StridedMap>(rangeMap);
RCP<const StridedMap> sdomainMap = rcp_dynamic_cast<const StridedMap>(domainMap);
if (srangeMap.is_null()) {
RCP<const Map> fullRangeMap = rangeMapExtractor->getFullMap();
RCP<const StridedMap> sFullRangeMap = rcp_dynamic_cast<const StridedMap>(fullRangeMap);
TEUCHOS_TEST_FOR_EXCEPTION(sFullRangeMap.is_null(), Exceptions::BadCast, "Full rangeMap is not a strided map.");
std::vector<size_t> stridedData = sFullRangeMap->getStridingData();
if (stridedData.size() == 1 && row > 0) {
// We have block matrices. use striding block information 0
srangeMap = StridedMapFactory::Build(rangeMap, stridedData, 0, sFullRangeMap->getOffset());
} else {
// We have strided matrices. use striding information of the corresponding block
srangeMap = StridedMapFactory::Build(rangeMap, stridedData, row, sFullRangeMap->getOffset());
}
}
if (sdomainMap.is_null()) {
RCP<const Map> fullDomainMap = domainMapExtractor->getFullMap();
RCP<const StridedMap> sFullDomainMap = rcp_dynamic_cast<const StridedMap>(fullDomainMap);
TEUCHOS_TEST_FOR_EXCEPTION(sFullDomainMap.is_null(), Exceptions::BadCast, "Full domainMap is not a strided map");
std::vector<size_t> stridedData = sFullDomainMap->getStridingData();
if (stridedData.size() == 1 && col > 0) {
// We have block matrices. use striding block information 0
sdomainMap = StridedMapFactory::Build(domainMap, stridedData, 0, sFullDomainMap->getOffset());
} else {
// We have strided matrices. use striding information of the corresponding block
sdomainMap = StridedMapFactory::Build(domainMap, stridedData, col, sFullDomainMap->getOffset());
}
}
TEUCHOS_TEST_FOR_EXCEPTION(srangeMap.is_null(), Exceptions::BadCast, "rangeMap " << row << " is not a strided map.");
TEUCHOS_TEST_FOR_EXCEPTION(sdomainMap.is_null(), Exceptions::BadCast, "domainMap " << col << " is not a strided map.");
GetOStream(Statistics1) << "A(" << row << "," << col << ") has strided maps:"
<< "\n range map fixed block size = " << srangeMap ->getFixedBlockSize() << ", strided block id = " << srangeMap ->getStridedBlockId()
<< "\n domain map fixed block size = " << sdomainMap->getFixedBlockSize() << ", strided block id = " << sdomainMap->getStridedBlockId() << std::endl;
if (Op->IsView("stridedMaps") == true)
Op->RemoveView("stridedMaps");
Op->CreateView("stridedMaps", srangeMap, sdomainMap);
TEUCHOS_TEST_FOR_EXCEPTION(Op->IsView("stridedMaps") == false, Exceptions::RuntimeError, "Failed to set \"stridedMaps\" view.");
//////////////// EXPERIMENTAL
currentLevel.Set("A", rcp_dynamic_cast<Matrix>(Op), this);
}
示例15: setupSmoother
// SmootherPrototype helper function
void setupSmoother(RCP<Matrix>& A, SmootherPrototype & smoother, Teuchos::FancyOStream & out, bool & success) {
Level level; TestHelpers::TestFactory<SC,LO,GO,NO,LMO>::createSingleLevelHierarchy(level);
level.Set("A", A);
smoother.Setup(level);
}