47#ifndef MUELU_MAPTRANSFERFACTORY_DEF_HPP_
48#define MUELU_MAPTRANSFERFACTORY_DEF_HPP_
52#include <Xpetra_Map.hpp>
53#include <Xpetra_MapFactory.hpp>
54#include <Xpetra_Matrix.hpp>
62 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 RCP<ParameterList> validParamList = rcp(
new ParameterList());
66 validParamList->setEntry(
"map: name", Teuchos::ParameterEntry(std::string(
"")));
67 validParamList->setEntry(
"map: factory", Teuchos::ParameterEntry(std::string(
"null")));
69 validParamList->set<RCP<const FactoryBase>>(
"P", Teuchos::null,
"Tentative prolongator factory");
70 validParamList->set<std::string>(
"nullspace vectors: limit to",
"all",
"Limit the number of nullspace vectors to be used for the map transfer (especially to exclude rotational vectors).");
72 return validParamList;
75 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 const ParameterList & pL = GetParameterList();
78 const std::string mapFactName = pL.get<std::string>(
"map: factory");
79 const std::string mapName = pL.get<std::string>(
"map: name");
89 if (mapFactName ==
"" || mapFactName ==
"NoFactory")
91 else if (mapFactName !=
"null")
100 Teuchos::RCP<const FactoryBase> tentPFact = GetFactory(
"P");
101 if (tentPFact == Teuchos::null)
106 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
108 Monitor m(*
this,
"MapTransferFactory");
110 const ParameterList & pL = GetParameterList();
111 const std::string mapName = pL.get<std::string>(
"map: name");
112 const int maxNumProlongCols = GetLimitOfProlongatorColumns(pL);
115 RCP<const Map> transferMap = Teuchos::null;
119 if (fineLevel.
IsAvailable(mapName, mapFact_.get()) ==
false)
120 GetOStream(
Runtime0) <<
"MapTransferFactory::Build: User provided map \"" << mapName <<
"\" not found in Level class on level " << fineLevel.
GetLevelID() <<
"." << std::endl;
121 transferMap = fineLevel.
Get<RCP<const Map>>(mapName, mapFact_.get());
126 RCP<const FactoryBase> tentPFact = GetFactory(
"P");
127 if (tentPFact == Teuchos::null)
130 "MueLu::MapTransferFactory::Build(): P (generated by TentativePFactory) not available.");
131 RCP<Matrix> Ptent = coarseLevel.
Get<RCP<Matrix> >(
"P", tentPFact.get());
134 Array<GO > coarseMapGids;
135 RCP<const Map> prolongColMap = Ptent->getColMap();
137 int numColEntries = 0;
138 for (
size_t row = 0; row < Ptent->getLocalNumRows(); ++row) {
139 gRowID = Ptent->getRowMap()->getGlobalElement(row);
141 if (transferMap->isNodeGlobalElement(gRowID)) {
142 Teuchos::ArrayView<const LO> indices;
143 Teuchos::ArrayView<const SC> vals;
144 Ptent->getLocalRowView(row, indices, vals);
146 numColEntries = as<int>(indices.size());
147 if (maxNumProlongCols > 0)
148 numColEntries = std::min(numColEntries, maxNumProlongCols);
150 for (
size_t col = 0; col < as<size_t>(numColEntries); ++col) {
152 GO gcid = prolongColMap->getGlobalElement(indices[col]);
153 coarseMapGids.push_back(gcid);
159 const GO INVALID = Teuchos::OrdinalTraits<GlobalOrdinal>::invalid();
160 std::sort(coarseMapGids.begin(), coarseMapGids.end());
161 coarseMapGids.erase(std::unique(coarseMapGids.begin(), coarseMapGids.end()), coarseMapGids.end());
162 RCP<const Map> coarseTransferMap = MapFactory::Build(prolongColMap->lib(), INVALID, coarseMapGids(),
163 prolongColMap->getIndexBase(), prolongColMap->getComm());
168 const std::string mapFactName = pL.get<std::string>(
"map: factory");
169 RCP<const FactoryBase> mapFact = coarseLevel.
GetFactoryManager()->GetFactory(mapFactName);
170 coarseLevel.
Set(mapName, coarseTransferMap, mapFact.get());
173 coarseLevel.
Set(mapName, coarseTransferMap, mapFact_.get());
177 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
180 const std::string useTheseNspVectors = pL.get<std::string>(
"nullspace vectors: limit to");
183 if (useTheseNspVectors ==
"all" || useTheseNspVectors ==
"")
187 int maxNumProlongCols = -1;
188 if (useTheseNspVectors ==
"translations")
189 maxNumProlongCols = 1;
193 return maxNumProlongCols;
Exception throws to report invalid user entry.
Exception throws to report errors in the internal logical of the program.
Class that holds all level-specific information.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
const RCP< const FactoryManagerBase > GetFactoryManager()
returns the current factory manager
int GetLevelID() const
Return level number.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
int GetLimitOfProlongatorColumns(const ParameterList &pL) const
Get the max number of entries per row of P to be considered for map transfer.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const override
Input.
void Build(Level &fineLevel, Level &coarseLevel) const override
Build an object with this factory.
RCP< const ParameterList > GetValidParameterList() const override
Input.
Timer to be used in non-factories.
static const RCP< const NoFactory > getRCP()
Static Get() functions.
static const NoFactory * get()
Namespace for MueLu classes and methods.
@ Runtime0
One-liner description of what is happening.