97 using xdMV = Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>;
99 GetOStream(
Runtime0) <<
"Transferring coordinates" << std::endl;
102 RCP<xdMV> coarseCoords;
103 RCP<xdMV> fineCoords;
104 Array<GO> gCoarseNodesPerDir;
105 Array<LO> lCoarseNodesPerDir;
107 const ParameterList& pL = GetParameterList();
109 if (pL.get<
bool>(
"hybrid aggregation") ==
true) {
110 std::string regionType = Get<std::string>(fineLevel,
"aggregationRegionTypeCoarse");
111 numDimensions = Get<int>(fineLevel,
"numDimensions");
112 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
113 Set<std::string>(coarseLevel,
"aggregationRegionType", regionType);
114 Set<int>(coarseLevel,
"numDimensions", numDimensions);
115 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
117 if ((pL.get<
bool>(
"interface aggregation") ==
true) && (regionType ==
"uncoupled")) {
118 Array<LO> coarseInterfacesDimensions = Get<Array<LO> >(fineLevel,
"coarseInterfacesDimensions");
119 Array<LO> nodeOnCoarseInterface = Get<Array<LO> >(fineLevel,
"nodeOnCoarseInterface");
120 Set<Array<LO> >(coarseLevel,
"interfacesDimensions", coarseInterfacesDimensions);
121 Set<Array<LO> >(coarseLevel,
"nodeOnInterface", nodeOnCoarseInterface);
124 }
else if (pL.get<
bool>(
"structured aggregation") ==
true) {
125 if (pL.get<
bool>(
"aggregation coupled") ==
true) {
126 gCoarseNodesPerDir = Get<Array<GO> >(fineLevel,
"gCoarseNodesPerDim");
127 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
129 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
130 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
131 numDimensions = Get<int>(fineLevel,
"numDimensions");
132 Set<int>(coarseLevel,
"numDimensions", numDimensions);
134 }
else if (pL.get<
bool>(
"Geometric") ==
true) {
135 coarseCoords = Get<RCP<xdMV> >(coarseLevel,
"coarseCoordinates");
136 gCoarseNodesPerDir = Get<Array<GO> >(coarseLevel,
"gCoarseNodesPerDim");
137 lCoarseNodesPerDir = Get<Array<LO> >(coarseLevel,
"lCoarseNodesPerDim");
138 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
139 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
141 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
144 if (coarseLevel.
IsAvailable(
"Coordinates",
this)) {
145 GetOStream(
Runtime0) <<
"Reusing coordinates" << std::endl;
149 fineCoords = Get<RCP<xdMV> >(fineLevel,
"Coordinates");
150 RCP<const Map> coarseMap = Get<RCP<const Map> >(fineLevel,
"CoarseMap");
156 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
157 blkSize = rcp_dynamic_cast<const StridedMap>(coarseMap)->getFixedBlockSize();
159 RCP<const Map> coarseCoordMap;
160 RCP<const Map> uniqueMap = fineCoords->getMap();
164 GO indexBase = coarseMap->getIndexBase();
165 ArrayView<const GO> elementAList = coarseMap->getLocalElementList();
166 size_t numElements = elementAList.size() / blkSize;
167 Array<GO> elementList(numElements);
170 for (LO i = 0; i < Teuchos::as<LO>(numElements); i++)
171 elementList[i] = (elementAList[i * blkSize] - indexBase) / blkSize + indexBase;
175 coarseCoordMap = MapFactory ::Build(coarseMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), elementList, indexBase, coarseMap->getComm());
179 coarseCoordMap = coarseMap;
183 coarseCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>::Build(coarseCoordMap, fineCoords->getNumVectors());
185 RCP<Aggregates> aggregates;
186 bool aggregatesCrossProcessors;
187 aggregates = Get<RCP<Aggregates> >(fineLevel,
"Aggregates");
188 aggregatesCrossProcessors = aggregates->AggregatesCrossProcessors();
191 RCP<xdMV> ghostedCoords = fineCoords;
192 if (aggregatesCrossProcessors) {
193 RCP<const Map> nonUniqueMap = aggregates->GetMap();
194 RCP<const Import> importer = ImportFactory::Build(uniqueMap, nonUniqueMap);
196 ghostedCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>::Build(nonUniqueMap, fineCoords->getNumVectors());
197 ghostedCoords->doImport(*fineCoords, *importer, Xpetra::INSERT);
202 auto aggGraph = aggregates->GetGraph();
203 auto numAggs = aggGraph.numRows();
205 auto fineCoordsView = ghostedCoords->getDeviceLocalView(Xpetra::Access::ReadOnly);
206 auto coarseCoordsView = coarseCoords->getDeviceLocalView(Xpetra::Access::OverwriteAll);
212 const auto dim = ghostedCoords->getNumVectors();
214 typename AppendTrait<
decltype(fineCoordsView), Kokkos::RandomAccess>::type fineCoordsRandomView = fineCoordsView;
215 for (
size_t j = 0; j < dim; j++) {
216 Kokkos::parallel_for(
217 "MueLu:CoordinatesTransferF:Build:coord", Kokkos::RangePolicy<local_ordinal_type, execution_space>(0, numAggs),
218 KOKKOS_LAMBDA(
const LO i) {
222 auto aggregate = aggGraph.rowConst(i);
224 typename Teuchos::ScalarTraits<Scalar>::magnitudeType sum = 0.0;
225 for (
size_t colID = 0; colID < static_cast<size_t>(aggregate.length); colID++)
226 sum += fineCoordsRandomView(aggregate(colID), j);
228 coarseCoordsView(i, j) = sum / aggregate.length;
233 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
236 int writeStart = pL.get<
int>(
"write start"), writeEnd = pL.get<
int>(
"write end");
237 if (writeStart == 0 && fineLevel.
GetLevelID() == 0 && writeStart <= writeEnd) {
238 std::ostringstream buf;
240 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
241 Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>::Write(fileName, *fineCoords);
244 std::ostringstream buf;
246 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
247 Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>::Write(fileName, *coarseCoords);