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> (
"structured aggregation",
false,
"Flag specifying that the geometric data is transferred for StructuredAggregationFactory");
72 validParamList->set<
bool> (
"aggregation coupled",
false,
"Flag specifying if the aggregation algorithm was used in coupled mode.");
73 validParamList->set<
bool> (
"Geometric",
false,
"Flag specifying that the coordinates are transferred for GeneralGeometricPFactory");
74 validParamList->set<RCP<const FactoryBase> >(
"coarseCoordinates", Teuchos::null,
"Factory for coarse coordinates generation");
75 validParamList->set<RCP<const FactoryBase> >(
"gCoarseNodesPerDim", Teuchos::null,
"Factory providing the global number of nodes per spatial dimensions of the mesh");
76 validParamList->set<RCP<const FactoryBase> >(
"lCoarseNodesPerDim", Teuchos::null,
"Factory providing the local number of nodes per spatial dimensions of the mesh");
77 validParamList->set<
int> (
"write start", -1,
"first level at which coordinates should be written to file");
78 validParamList->set<
int> (
"write end", -1,
"last level at which coordinates should be written to file");
79 validParamList->set<RCP<const FactoryBase> >(
"aggregationRegionTypeCoarse", Teuchos::null,
"Factory indicating what aggregation type is to be used on the coarse level of the region");
80 validParamList->set<
bool> (
"hybrid aggregation",
false,
"Flag specifying that hybrid aggregation data is transfered for HybridAggregationFactory");
83 return validParamList;
86 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
88 static bool isAvailableCoords =
false;
90 const ParameterList& pL = GetParameterList();
91 if(pL.get<
bool>(
"structured aggregation") ==
true) {
92 if(pL.get<
bool>(
"aggregation coupled") ==
true) {
93 Input(fineLevel,
"gCoarseNodesPerDim");
95 Input(fineLevel,
"lCoarseNodesPerDim");
96 }
else if(pL.get<
bool>(
"Geometric") ==
true) {
97 Input(coarseLevel,
"coarseCoordinates");
98 Input(coarseLevel,
"gCoarseNodesPerDim");
99 Input(coarseLevel,
"lCoarseNodesPerDim");
102 isAvailableCoords = coarseLevel.
IsAvailable(
"Coordinates",
this);
104 if (isAvailableCoords ==
false) {
105 Input(fineLevel,
"Coordinates");
106 Input(fineLevel,
"Aggregates");
107 Input(fineLevel,
"CoarseMap");
110 if(pL.get<
bool>(
"hybrid aggregation") ==
true) {
111 Input(fineLevel,
"aggregationRegionTypeCoarse");
112 Input(fineLevel,
"lCoarseNodesPerDim");
116 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
120 using xdMV = Xpetra::MultiVector<double,LO,GO,NO>;
122 GetOStream(
Runtime0) <<
"Transferring coordinates" << std::endl;
124 RCP<xdMV> coarseCoords;
125 RCP<xdMV> fineCoords;
126 Array<GO> gCoarseNodesPerDir;
127 Array<LO> lCoarseNodesPerDir;
129 const ParameterList& pL = GetParameterList();
131 if(pL.get<
bool>(
"hybrid aggregation") ==
true) {
132 std::string regionType = Get<std::string>(fineLevel,
"aggregationRegionTypeCoarse");
133 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
134 Set<std::string>(coarseLevel,
"aggregationRegionType", regionType);
135 Set< Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
138 if(pL.get<
bool>(
"structured aggregation") ==
true) {
139 if(pL.get<
bool>(
"aggregation coupled") ==
true) {
140 gCoarseNodesPerDir = Get<Array<GO> >(fineLevel,
"gCoarseNodesPerDim");
141 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
143 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
144 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
145 }
else if(pL.get<
bool>(
"Geometric") ==
true) {
146 coarseCoords = Get<RCP<xdMV> >(coarseLevel,
"coarseCoordinates");
147 gCoarseNodesPerDir = Get<Array<GO> >(coarseLevel,
"gCoarseNodesPerDim");
148 lCoarseNodesPerDir = Get<Array<LO> >(coarseLevel,
"lCoarseNodesPerDim");
149 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
150 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
152 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
155 if (coarseLevel.
IsAvailable(
"Coordinates",
this)) {
156 GetOStream(
Runtime0) <<
"Reusing coordinates" << std::endl;
160 RCP<Aggregates> aggregates = Get< RCP<Aggregates> > (fineLevel,
"Aggregates");
161 fineCoords = Get< RCP<xdMV> >(fineLevel,
"Coordinates");
162 RCP<const Map> coarseMap = Get< RCP<const Map> > (fineLevel,
"CoarseMap");
168 ArrayView<const GO> elementAList = coarseMap->getNodeElementList();
171 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
172 blkSize = rcp_dynamic_cast<
const StridedMap>(coarseMap)->getFixedBlockSize();
174 GO indexBase = coarseMap->getIndexBase();
175 size_t numElements = elementAList.size() / blkSize;
176 Array<GO> elementList(numElements);
179 for (LO i = 0; i < Teuchos::as<LO>(numElements); i++)
180 elementList[i] = (elementAList[i*blkSize]-indexBase)/blkSize + indexBase;
182 RCP<const Map> uniqueMap = fineCoords->getMap();
183 RCP<const Map> coarseCoordMap = MapFactory ::Build(coarseMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), elementList, indexBase, coarseMap->getComm());
184 coarseCoords = Xpetra::MultiVectorFactory<double,LO,GO,NO>::Build(coarseCoordMap, fineCoords->getNumVectors());
187 RCP<xdMV> ghostedCoords = fineCoords;
188 if (aggregates->AggregatesCrossProcessors()) {
189 RCP<const Map> nonUniqueMap = aggregates->GetMap();
190 RCP<const Import> importer = ImportFactory::Build(uniqueMap, nonUniqueMap);
192 ghostedCoords = Xpetra::MultiVectorFactory<double,LO,GO,NO>::Build(nonUniqueMap, fineCoords->getNumVectors());
193 ghostedCoords->doImport(*fineCoords, *importer, Xpetra::INSERT);
197 int myPID = uniqueMap->getComm()->getRank();
198 LO numAggs = aggregates->GetNumAggregates();
199 ArrayRCP<LO> aggSizes = aggregates->ComputeAggregateSizes();
200 const ArrayRCP<const LO> vertex2AggID = aggregates->GetVertex2AggId()->getData(0);
201 const ArrayRCP<const LO> procWinner = aggregates->GetProcWinner()->getData(0);
204 for (
size_t j = 0; j < fineCoords->getNumVectors(); j++) {
205 ArrayRCP<const double> fineCoordsData = ghostedCoords->getData(j);
206 ArrayRCP<double> coarseCoordsData = coarseCoords->getDataNonConst(j);
208 for (LO lnode = 0; lnode < vertex2AggID.size(); lnode++) {
209 if (procWinner[lnode] == myPID &&
210 lnode < vertex2AggID.size() &&
211 lnode < fineCoordsData.size() &&
212 vertex2AggID[lnode] < coarseCoordsData.size() &&
213 Teuchos::ScalarTraits<double>::isnaninf(fineCoordsData[lnode]) ==
false) {
214 coarseCoordsData[vertex2AggID[lnode]] += fineCoordsData[lnode];
217 for (LO agg = 0; agg < numAggs; agg++) {
218 coarseCoordsData[agg] /= aggSizes[agg];
222 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
225 int writeStart = pL.get<
int>(
"write start"), writeEnd = pL.get<
int>(
"write end");
226 if (writeStart == 0 && fineLevel.
GetLevelID() == 0 && writeStart <= writeEnd) {
227 std::ostringstream buf;
229 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
230 Xpetra::IO<double,LO,GO,NO>::Write(fileName,*fineCoords);
233 std::ostringstream buf;
235 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
236 Xpetra::IO<double,LO,GO,NO>::Write(fileName,*coarseCoords);
242 #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.