46 #ifndef MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP 47 #define MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP 49 #include "Xpetra_ImportFactory.hpp" 50 #include "Xpetra_MultiVectorFactory.hpp" 51 #include "Xpetra_MapFactory.hpp" 53 #include "MueLu_CoarseMapFactory.hpp" 54 #include "MueLu_Aggregates.hpp" 56 #include "MueLu_Utilities.hpp" 63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 RCP<ParameterList> validParamList = rcp(
new ParameterList());
67 validParamList->set< RCP<const FactoryBase> >(
"Coordinates", Teuchos::null,
"Factory for coordinates generation");
68 validParamList->set< RCP<const FactoryBase> >(
"Aggregates", Teuchos::null,
"Factory for coordinates generation");
69 validParamList->set< RCP<const FactoryBase> >(
"CoarseMap", Teuchos::null,
"Generating factory of the coarse map");
70 validParamList->set<
int > (
"write start", -1,
"first level at which coordinates should be written to file");
71 validParamList->set<
int > (
"write end", -1,
"last level at which coordinates should be written to file");
73 return validParamList;
76 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 static bool isAvailableCoords =
false;
81 isAvailableCoords = coarseLevel.
IsAvailable(
"Coordinates",
this);
83 if (isAvailableCoords ==
false) {
84 Input(fineLevel,
"Coordinates");
85 Input(fineLevel,
"Aggregates");
86 Input(fineLevel,
"CoarseMap");
90 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
94 typedef Xpetra::MultiVector<double,LO,GO,NO> xdMV;
96 GetOStream(
Runtime0) <<
"Transferring coordinates" << std::endl;
99 GetOStream(
Runtime0) <<
"Reusing coordinates" << std::endl;
103 RCP<Aggregates> aggregates = Get< RCP<Aggregates> > (fineLevel,
"Aggregates");
104 RCP<xdMV> fineCoords = Get< RCP<xdMV> >(fineLevel,
"Coordinates");
105 RCP<const Map> coarseMap = Get< RCP<const Map> > (fineLevel,
"CoarseMap");
111 ArrayView<const GO> elementAList = coarseMap->getNodeElementList();
113 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
114 blkSize = rcp_dynamic_cast<
const StridedMap>(coarseMap)->getFixedBlockSize();
116 GO indexBase = coarseMap->getIndexBase();
117 size_t numElements = elementAList.size() / blkSize;
118 Array<GO> elementList(numElements);
121 for (LO i = 0; i < Teuchos::as<LO>(numElements); i++)
122 elementList[i] = (elementAList[i*blkSize]-indexBase)/blkSize + indexBase;
124 RCP<const Map> uniqueMap = fineCoords->getMap();
125 RCP<const Map> coarseCoordMap = MapFactory ::Build(coarseMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), elementList, indexBase, coarseMap->getComm());
126 RCP<xdMV> coarseCoords = Xpetra::MultiVectorFactory<double,LO,GO,NO>::Build(coarseCoordMap, fineCoords->getNumVectors());
129 RCP<xdMV> ghostedCoords = fineCoords;
130 if (aggregates->AggregatesCrossProcessors()) {
131 RCP<const Map> nonUniqueMap = aggregates->GetMap();
132 RCP<const Import> importer = ImportFactory::Build(uniqueMap, nonUniqueMap);
134 ghostedCoords = Xpetra::MultiVectorFactory<double,LO,GO,NO>::Build(nonUniqueMap, fineCoords->getNumVectors());
135 ghostedCoords->doImport(*fineCoords, *importer, Xpetra::INSERT);
139 int myPID = uniqueMap->getComm()->getRank();
140 LO numAggs = aggregates->GetNumAggregates();
141 ArrayRCP<LO> aggSizes = aggregates->ComputeAggregateSizes(
true,
true);
142 const ArrayRCP<const LO> vertex2AggID = aggregates->GetVertex2AggId()->getData(0);
143 const ArrayRCP<const LO> procWinner = aggregates->GetProcWinner()->getData(0);
146 for (
size_t j = 0; j < fineCoords->getNumVectors(); j++) {
147 ArrayRCP<const double> fineCoordsData = ghostedCoords->getData(j);
148 ArrayRCP<double> coarseCoordsData = coarseCoords->getDataNonConst(j);
150 for (LO lnode = 0; lnode < vertex2AggID.size(); lnode++)
151 if (procWinner[lnode] == myPID)
152 coarseCoordsData[vertex2AggID[lnode]] += fineCoordsData[lnode];
154 for (LO agg = 0; agg < numAggs; agg++)
155 coarseCoordsData[agg] /= aggSizes[agg];
158 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
160 const ParameterList& pL = GetParameterList();
161 int writeStart = pL.get<
int>(
"write start"), writeEnd = pL.get<
int>(
"write end");
162 if (writeStart == 0 && fineLevel.GetLevelID() == 0 && writeStart <= writeEnd) {
163 std::ostringstream buf;
164 buf << fineLevel.GetLevelID();
165 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
168 if (writeStart <= coarseLevel.GetLevelID() && coarseLevel.GetLevelID() <= writeEnd) {
169 std::ostringstream buf;
170 buf << coarseLevel.GetLevelID();
171 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
178 #endif // MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP static void Write(const std::string &fileName, const Map &M)
Read/Write methods.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
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.
One-liner description of what is happening.
Namespace for MueLu classes and methods.
RequestMode GetRequestMode() const
Class that holds all level-specific information.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.