10 #ifndef MUELU_LOCALORDINALTRANSFER_FACTORY_DEF_HPP
11 #define MUELU_LOCALORDINALTRANSFER_FACTORY_DEF_HPP
15 #include "Xpetra_MapFactory.hpp"
20 #include "MueLu_Aggregates.hpp"
28 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
37 return validParamList;
40 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
42 static bool isAvailableXfer =
false;
44 isAvailableXfer = coarseLevel.
IsAvailable(TransferVecName_,
this);
45 if (isAvailableXfer ==
false) {
46 Input(fineLevel, TransferVecName_);
47 Input(fineLevel,
"CoarseMap");
49 if (useAggregatesMode_)
50 Input(fineLevel,
"Aggregates");
52 Input(coarseLevel,
"P Graph");
58 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 if (useAggregatesMode_)
61 BuildAggregates(fineLevel, coarseLevel);
63 BuildFC(fineLevel, coarseLevel);
66 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 GetOStream(
Runtime0) <<
"Transferring " << TransferVecName_ << std::endl;
73 if (coarseLevel.
IsAvailable(TransferVecName_,
this)) {
74 GetOStream(
Runtime0) <<
"Reusing " << TransferVecName_ << std::endl;
81 RCP<const Map> coarseMap = Get<RCP<const Map> >(fineLevel,
"CoarseMap");
90 for (
LO i = 0; i < coarseData.
size(); i++)
91 coarseData[i] = LO_INVALID;
94 LO domMapNumElements = P->getDomainMap()->getLocalNumElements();
95 for (
LO row = 0; row < (
LO)P->getLocalNumRows(); row++) {
96 LO fineNumber = fineData[row];
98 P->getLocalRowView(row, indices);
100 for (
LO j = 0; j < (
LO)indices.
size(); j++) {
102 if (col >= domMapNumElements) {
105 coarseData[col] = fineNumber;
110 #ifdef HAVE_MUELU_DEBUG
111 size_t error_count = 0;
116 coarseTVghosted = LocalOrdinalVectorFactory::Build(P->getColMap(), 1);
119 coarseTVghosted = coarseTV;
121 ArrayRCP<LO> coarseDataGhosted = coarseTVghosted->getDataNonConst(0);
122 for (
LO col = 0; col < (
LO)P->getColMap()->getLocalNumElements(); col++) {
123 if (coarseDataGhosted[col] == LO_INVALID)
126 for (
LO row = 0; row < (
LO)P->getLocalNumRows(); row++) {
127 LO fineNumber = fineData[row];
129 P->getLocalRowView(row, indices);
130 for (
LO j = 0; j < (
LO)indices.
size(); j++) {
131 if (coarseDataGhosted[indices[j]] != fineNumber)
138 if (error_count > 0) {
139 std::ostringstream ofs;
140 ofs <<
"LocalOrdinalTransferFactory(" << TransferVecName_ <<
"): ERROR: Each coarse dof must have a unique LO value. We had " << std::to_string(error_count) <<
" unknowns that did not match.";
141 throw std::runtime_error(ofs.str());
145 Set<RCP<LocalOrdinalVector> >(coarseLevel, TransferVecName_, coarseTV);
148 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
152 GetOStream(
Runtime0) <<
"Transferring " << TransferVecName_ << std::endl;
157 if (coarseLevel.
IsAvailable(TransferVecName_,
this)) {
158 GetOStream(
Runtime0) <<
"Reusing " << TransferVecName_ << std::endl;
162 RCP<Aggregates> aggregates = Get<RCP<Aggregates> >(fineLevel,
"Aggregates");
163 fineTV = Get<RCP<LocalOrdinalVector> >(fineLevel, TransferVecName_);
164 RCP<const Map> coarseMap = Get<RCP<const Map> >(fineLevel,
"CoarseMap");
169 coarseTV = LocalOrdinalVectorFactory::Build(coarseMap, 1);
177 ghostedTV = LocalOrdinalVectorFactory::Build(nonUniqueMap, 1);
182 int myPID = uniqueMap->getComm()->getRank();
191 for (
LO i = 0; i < coarseData.
size(); i++)
192 coarseData[i] = LO_INVALID;
195 size_t error_count = 0;
196 for (
LO lnode = 0; lnode < vertex2AggID.
size(); lnode++) {
197 if (procWinner[lnode] == myPID &&
199 lnode < fineData.
size() &&
200 vertex2AggID[lnode] < coarseData.
size()) {
201 if (coarseData[vertex2AggID[lnode]] == LO_INVALID)
202 coarseData[vertex2AggID[lnode]] = fineData[lnode];
203 if (coarseData[vertex2AggID[lnode]] != fineData[lnode])
209 if (error_count > 0) {
210 std::ostringstream ofs;
211 ofs <<
"LocalOrdinalTransferFactory: ERROR: Each aggregate must have a unique LO value. We had " << std::to_string(error_count) <<
" unknowns that did not match.";
212 throw std::runtime_error(ofs.str());
215 Set<RCP<LocalOrdinalVector> >(coarseLevel, TransferVecName_, coarseTV);
220 #endif // MUELU_LOCALORDINALTRANSFER_FACTORY_DEF_HPP
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
const RCP< LOVector > & GetProcWinner() const
Returns constant vector that maps local node IDs to owning processor IDs.
void BuildFC(Level &fineLevel, Level &coarseLevel) const
void DeclareInput(Level &finelevel, Level &coarseLevel) const
Specifies the data that this class needs, and the factories that generate that data.
Timer to be used in factories. Similar to Monitor but with additional timers.
const RCP< const Map > GetMap() const
returns (overlapping) map of aggregate/node distribution
One-liner description of what is happening.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
RequestMode GetRequestMode() const
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void BuildAggregates(Level &fineLevel, Level &coarseLevel) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Teuchos::ArrayRCP< LocalOrdinal > ComputeAggregateSizesArrayRCP(bool forceRecompute=false) const
Compute sizes of aggregates.
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool &flag)
Record whether aggregates include DOFs from other processes.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.