98 using xdMV = Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>;
100 GetOStream(
Runtime0) <<
"Transferring coordinates" << std::endl;
103 RCP<xdMV> coarseCoords;
104 RCP<xdMV> fineCoords;
105 Array<GO> gCoarseNodesPerDir;
106 Array<LO> lCoarseNodesPerDir;
108 const ParameterList& pL = GetParameterList();
110 if (pL.get<
bool>(
"hybrid aggregation") ==
true) {
111 std::string regionType = Get<std::string>(fineLevel,
"aggregationRegionTypeCoarse");
112 numDimensions = Get<int>(fineLevel,
"numDimensions");
113 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
114 Set<std::string>(coarseLevel,
"aggregationRegionType", regionType);
115 Set<int>(coarseLevel,
"numDimensions", numDimensions);
116 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
118 if ((pL.get<
bool>(
"interface aggregation") ==
true) && (regionType ==
"uncoupled")) {
119 Array<LO> coarseInterfacesDimensions = Get<Array<LO> >(fineLevel,
"coarseInterfacesDimensions");
120 Array<LO> nodeOnCoarseInterface = Get<Array<LO> >(fineLevel,
"nodeOnCoarseInterface");
121 Set<Array<LO> >(coarseLevel,
"interfacesDimensions", coarseInterfacesDimensions);
122 Set<Array<LO> >(coarseLevel,
"nodeOnInterface", nodeOnCoarseInterface);
125 }
else if (pL.get<
bool>(
"structured aggregation") ==
true) {
126 if (pL.get<
bool>(
"aggregation coupled") ==
true) {
127 gCoarseNodesPerDir = Get<Array<GO> >(fineLevel,
"gCoarseNodesPerDim");
128 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
130 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
131 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
132 numDimensions = Get<int>(fineLevel,
"numDimensions");
133 Set<int>(coarseLevel,
"numDimensions", numDimensions);
135 }
else if (pL.get<
bool>(
"Geometric") ==
true) {
136 coarseCoords = Get<RCP<xdMV> >(coarseLevel,
"coarseCoordinates");
137 gCoarseNodesPerDir = Get<Array<GO> >(coarseLevel,
"gCoarseNodesPerDim");
138 lCoarseNodesPerDir = Get<Array<LO> >(coarseLevel,
"lCoarseNodesPerDim");
139 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
140 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
142 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
145 if (coarseLevel.
IsAvailable(
"Coordinates",
this)) {
146 GetOStream(
Runtime0) <<
"Reusing coordinates" << std::endl;
150 fineCoords = Get<RCP<xdMV> >(fineLevel,
"Coordinates");
151 RCP<const Map> coarseMap = Get<RCP<const Map> >(fineLevel,
"CoarseMap");
153 RCP<const Map> coarseCoordMap;
154 RCP<const Map> uniqueMap = fineCoords->getMap();
160 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
161 blkSize = rcp_dynamic_cast<const StridedMap>(coarseMap)->getFixedBlockSize();
163 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
164 blkSize = rcp_dynamic_cast<const StridedMap>(coarseMap)->getFixedBlockSize();
169 coarseCoordMap = coarseMap;
176 coarseCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>::Build(coarseCoordMap, fineCoords->getNumVectors());
178 RCP<Aggregates> aggregates;
179 bool aggregatesCrossProcessors;
180 aggregates = Get<RCP<Aggregates> >(fineLevel,
"Aggregates");
181 aggregatesCrossProcessors = aggregates->AggregatesCrossProcessors();
184 RCP<xdMV> ghostedCoords = fineCoords;
185 if (aggregatesCrossProcessors) {
186 RCP<const Map> nonUniqueMap = aggregates->GetMap();
187 RCP<const Import> importer = ImportFactory::Build(uniqueMap, nonUniqueMap);
189 ghostedCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>::Build(nonUniqueMap, fineCoords->getNumVectors());
190 ghostedCoords->doImport(*fineCoords, *importer, Xpetra::INSERT);
195 auto aggGraph = aggregates->GetGraph();
196 auto numAggs = aggGraph.numRows();
198 auto fineCoordsView = ghostedCoords->getLocalViewDevice(Tpetra::Access::ReadOnly);
199 auto coarseCoordsView = coarseCoords->getLocalViewDevice(Tpetra::Access::OverwriteAll);
205 const auto dim = ghostedCoords->getNumVectors();
207 typename AppendTrait<
decltype(fineCoordsView), Kokkos::RandomAccess>::type fineCoordsRandomView = fineCoordsView;
208 for (
size_t j = 0; j < dim; j++) {
209 Kokkos::parallel_for(
210 "MueLu:CoordinatesTransferF:Build:coord", Kokkos::RangePolicy<local_ordinal_type, execution_space>(0, numAggs),
211 KOKKOS_LAMBDA(
const LO i) {
215 auto aggregate = aggGraph.rowConst(i);
217 typename Teuchos::ScalarTraits<Scalar>::magnitudeType sum = 0.0;
218 for (
size_t colID = 0; colID < static_cast<size_t>(aggregate.length); colID++)
219 sum += fineCoordsRandomView(aggregate(colID), j);
221 coarseCoordsView(i, j) = sum / aggregate.length;
226 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
229 int writeStart = pL.get<
int>(
"write start"), writeEnd = pL.get<
int>(
"write end");
230 if (writeStart == 0 && fineLevel.
GetLevelID() == 0 && writeStart <= writeEnd) {
231 std::ostringstream buf;
233 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
234 Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>::Write(fileName, *fineCoords);
237 std::ostringstream buf;
239 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
240 Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>::Write(fileName, *coarseCoords);