46 #ifndef MUELU_LOCALORDINALTRANSFER_FACTORY_DEF_HPP
47 #define MUELU_LOCALORDINALTRANSFER_FACTORY_DEF_HPP
51 #include "Xpetra_MapFactory.hpp"
56 #include "MueLu_Aggregates.hpp"
64 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
73 return validParamList;
76 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 static bool isAvailableXfer =
false;
80 isAvailableXfer = coarseLevel.
IsAvailable(TransferVecName_,
this);
81 if (isAvailableXfer ==
false) {
82 Input(fineLevel, TransferVecName_);
83 Input(fineLevel,
"CoarseMap");
85 if (useAggregatesMode_)
86 Input(fineLevel,
"Aggregates");
88 Input(coarseLevel,
"P Graph");
94 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 if (useAggregatesMode_)
97 BuildAggregates(fineLevel, coarseLevel);
99 BuildFC(fineLevel, coarseLevel);
102 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
106 GetOStream(
Runtime0) <<
"Transferring " << TransferVecName_ << std::endl;
109 if (coarseLevel.
IsAvailable(TransferVecName_,
this)) {
110 GetOStream(
Runtime0) <<
"Reusing " << TransferVecName_ << std::endl;
117 RCP<const Map> coarseMap = Get<RCP<const Map> >(fineLevel,
"CoarseMap");
126 for (
LO i = 0; i < coarseData.
size(); i++)
127 coarseData[i] = LO_INVALID;
130 LO domMapNumElements = P->getDomainMap()->getLocalNumElements();
131 for (
LO row = 0; row < (
LO)P->getLocalNumRows(); row++) {
132 LO fineNumber = fineData[row];
134 P->getLocalRowView(row, indices);
136 for (
LO j = 0; j < (
LO)indices.
size(); j++) {
138 if (col >= domMapNumElements) {
141 coarseData[col] = fineNumber;
146 #ifdef HAVE_MUELU_DEBUG
147 size_t error_count = 0;
152 coarseTVghosted = LocalOrdinalVectorFactory::Build(P->getColMap(), 1);
155 coarseTVghosted = coarseTV;
157 ArrayRCP<LO> coarseDataGhosted = coarseTVghosted->getDataNonConst(0);
158 for (
LO col = 0; col < (
LO)P->getColMap()->getLocalNumElements(); col++) {
159 if (coarseDataGhosted[col] == LO_INVALID)
162 for (
LO row = 0; row < (
LO)P->getLocalNumRows(); row++) {
163 LO fineNumber = fineData[row];
165 P->getLocalRowView(row, indices);
166 for (
LO j = 0; j < (
LO)indices.
size(); j++) {
167 if (coarseDataGhosted[indices[j]] != fineNumber)
174 if (error_count > 0) {
175 std::ostringstream ofs;
176 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.";
177 throw std::runtime_error(ofs.str());
181 Set<RCP<LocalOrdinalVector> >(coarseLevel, TransferVecName_, coarseTV);
184 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
188 GetOStream(
Runtime0) <<
"Transferring " << TransferVecName_ << std::endl;
193 if (coarseLevel.
IsAvailable(TransferVecName_,
this)) {
194 GetOStream(
Runtime0) <<
"Reusing " << TransferVecName_ << std::endl;
198 RCP<Aggregates> aggregates = Get<RCP<Aggregates> >(fineLevel,
"Aggregates");
199 fineTV = Get<RCP<LocalOrdinalVector> >(fineLevel, TransferVecName_);
200 RCP<const Map> coarseMap = Get<RCP<const Map> >(fineLevel,
"CoarseMap");
205 coarseTV = LocalOrdinalVectorFactory::Build(coarseMap, 1);
213 ghostedTV = LocalOrdinalVectorFactory::Build(nonUniqueMap, 1);
218 int myPID = uniqueMap->getComm()->getRank();
227 for (
LO i = 0; i < coarseData.
size(); i++)
228 coarseData[i] = LO_INVALID;
231 size_t error_count = 0;
232 for (
LO lnode = 0; lnode < vertex2AggID.
size(); lnode++) {
233 if (procWinner[lnode] == myPID &&
235 lnode < fineData.
size() &&
236 vertex2AggID[lnode] < coarseData.
size()) {
237 if (coarseData[vertex2AggID[lnode]] == LO_INVALID)
238 coarseData[vertex2AggID[lnode]] = fineData[lnode];
239 if (coarseData[vertex2AggID[lnode]] != fineData[lnode])
245 if (error_count > 0) {
246 std::ostringstream ofs;
247 ofs <<
"LocalOrdinalTransferFactory: ERROR: Each aggregate must have a unique LO value. We had " << std::to_string(error_count) <<
" unknowns that did not match.";
248 throw std::runtime_error(ofs.str());
251 Set<RCP<LocalOrdinalVector> >(coarseLevel, TransferVecName_, coarseTV);
256 #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
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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.