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" 52 #include "Xpetra_IO.hpp" 54 #include "MueLu_CoarseMapFactory.hpp" 55 #include "MueLu_Aggregates.hpp" 64 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
66 RCP<ParameterList> validParamList = rcp(
new ParameterList());
68 validParamList->set<RCP<const FactoryBase> >(
"Coordinates", Teuchos::null,
"Factory for coordinates generation");
69 validParamList->set<RCP<const FactoryBase> >(
"Aggregates", Teuchos::null,
"Factory for coordinates generation");
70 validParamList->set<RCP<const FactoryBase> >(
"CoarseMap", Teuchos::null,
"Generating factory of the coarse map");
71 validParamList->set<
bool> (
"Geometric",
false,
"Flag specifying that the coordinates are transfered for GeneralGeometricPFactory");
72 validParamList->set<RCP<const FactoryBase> >(
"coarseCoordinates", Teuchos::null,
"Factory for coarse coordinates generation");
73 validParamList->set<RCP<const FactoryBase> >(
"gCoarseNodesPerDim", Teuchos::null,
"Factory providing the global number of nodes per spatial dimensions of the mesh");
74 validParamList->set<RCP<const FactoryBase> >(
"lCoarseNodesPerDim", Teuchos::null,
"Factory providing the local number of nodes per spatial dimensions of the mesh");
75 validParamList->set<
int> (
"write start", -1,
"first level at which coordinates should be written to file");
76 validParamList->set<
int> (
"write end", -1,
"last level at which coordinates should be written to file");
78 return validParamList;
81 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
83 static bool isAvailableCoords =
false;
85 const ParameterList& pL = GetParameterList();
86 if(pL.get<
bool>(
"Geometric") ==
true) {
87 Input(coarseLevel,
"coarseCoordinates");
88 Input(coarseLevel,
"gCoarseNodesPerDim");
89 Input(coarseLevel,
"lCoarseNodesPerDim");
92 isAvailableCoords = coarseLevel.
IsAvailable(
"Coordinates",
this);
94 if (isAvailableCoords ==
false) {
95 Input(fineLevel,
"Coordinates");
96 Input(fineLevel,
"Aggregates");
97 Input(fineLevel,
"CoarseMap");
102 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
106 using xdMV = Xpetra::MultiVector<double,LO,GO,NO>;
108 GetOStream(
Runtime0) <<
"Transferring coordinates" << std::endl;
110 RCP<xdMV> coarseCoords;
111 RCP<xdMV> fineCoords;
112 Array<GO> gCoarseNodesPerDim;
113 Array<LO> lCoarseNodesPerDim;
115 const ParameterList& pL = GetParameterList();
116 if(pL.get<
bool>(
"Geometric") ==
true) {
117 coarseCoords = Get<RCP<xdMV> >(coarseLevel,
"coarseCoordinates");
118 gCoarseNodesPerDim = Get<Array<GO> >(coarseLevel,
"gCoarseNodesPerDim");
119 lCoarseNodesPerDim = Get<Array<LO> >(coarseLevel,
"lCoarseNodesPerDim");
120 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDim);
121 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDim);
126 if (coarseLevel.
IsAvailable(
"Coordinates",
this)) {
127 GetOStream(
Runtime0) <<
"Reusing coordinates" << std::endl;
131 RCP<Aggregates> aggregates = Get< RCP<Aggregates> > (fineLevel,
"Aggregates");
132 fineCoords = Get< RCP<xdMV> >(fineLevel,
"Coordinates");
133 RCP<const Map> coarseMap = Get< RCP<const Map> > (fineLevel,
"CoarseMap");
139 ArrayView<const GO> elementAList = coarseMap->getNodeElementList();
141 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
142 blkSize = rcp_dynamic_cast<
const StridedMap>(coarseMap)->getFixedBlockSize();
144 GO indexBase = coarseMap->getIndexBase();
145 size_t numElements = elementAList.size() / blkSize;
146 Array<GO> elementList(numElements);
149 for (LO i = 0; i < Teuchos::as<LO>(numElements); i++)
150 elementList[i] = (elementAList[i*blkSize]-indexBase)/blkSize + indexBase;
152 RCP<const Map> uniqueMap = fineCoords->getMap();
153 RCP<const Map> coarseCoordMap = MapFactory ::Build(coarseMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), elementList, indexBase, coarseMap->getComm());
154 coarseCoords = Xpetra::MultiVectorFactory<double,LO,GO,NO>::Build(coarseCoordMap, fineCoords->getNumVectors());
157 RCP<xdMV> ghostedCoords = fineCoords;
158 if (aggregates->AggregatesCrossProcessors()) {
159 RCP<const Map> nonUniqueMap = aggregates->GetMap();
160 RCP<const Import> importer = ImportFactory::Build(uniqueMap, nonUniqueMap);
162 ghostedCoords = Xpetra::MultiVectorFactory<double,LO,GO,NO>::Build(nonUniqueMap, fineCoords->getNumVectors());
163 ghostedCoords->doImport(*fineCoords, *importer, Xpetra::INSERT);
167 int myPID = uniqueMap->getComm()->getRank();
168 LO numAggs = aggregates->GetNumAggregates();
169 ArrayRCP<LO> aggSizes = aggregates->ComputeAggregateSizes(
true,
true);
170 const ArrayRCP<const LO> vertex2AggID = aggregates->GetVertex2AggId()->getData(0);
171 const ArrayRCP<const LO> procWinner = aggregates->GetProcWinner()->getData(0);
174 for (
size_t j = 0; j < fineCoords->getNumVectors(); j++) {
175 ArrayRCP<const double> fineCoordsData = ghostedCoords->getData(j);
176 ArrayRCP<double> coarseCoordsData = coarseCoords->getDataNonConst(j);
178 for (LO lnode = 0; lnode < vertex2AggID.size(); lnode++)
179 if (procWinner[lnode] == myPID)
180 coarseCoordsData[vertex2AggID[lnode]] += fineCoordsData[lnode];
182 for (LO agg = 0; agg < numAggs; agg++)
183 coarseCoordsData[agg] /= aggSizes[agg];
187 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
189 int writeStart = pL.get<
int>(
"write start"), writeEnd = pL.get<
int>(
"write end");
190 if (writeStart == 0 && fineLevel.
GetLevelID() == 0 && writeStart <= writeEnd) {
191 std::ostringstream buf;
193 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
194 Xpetra::IO<double,LO,GO,NO>::Write(fileName,*fineCoords);
196 if (writeStart <= coarseLevel.GetLevelID() && coarseLevel.GetLevelID() <= writeEnd) {
197 std::ostringstream buf;
198 buf << coarseLevel.GetLevelID();
199 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
200 Xpetra::IO<double,LO,GO,NO>::Write(fileName,*coarseCoords);
206 #endif // MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP RequestMode GetRequestMode() const
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.
int GetLevelID() const
Return level number.
void DeclareInput(Level &finelevel, Level &coarseLevel) const
Specifies the data that this class needs, and the factories that generate that data.
Class that holds all level-specific information.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.