104 typedef Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO> doubleMultiVector;
106 GetOStream(
Runtime0) <<
"Transferring coordinates" << std::endl;
108 if (coarseLevel.
IsAvailable(
"Coordinates",
this)) {
109 GetOStream(
Runtime0) <<
"Reusing coordinates" << std::endl;
114 const ParameterList& pL = GetParameterList();
115 if(pL.get<
bool>(
"structured aggregation") ==
true) {
116 Array<LO> lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
117 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
118 int numDimensions = Get<int>(fineLevel,
"numDimensions");
119 Set<int>(coarseLevel,
"numDimensions", numDimensions);
124 auto aggregates = Get<RCP<Aggregates_kokkos> >(fineLevel,
"Aggregates");
125 auto fineCoords = Get<RCP<doubleMultiVector> >(fineLevel,
"Coordinates");
126 auto coarseMap = Get<RCP<const Map> > (fineLevel,
"CoarseMap");
132 ArrayView<const GO> elementAList = coarseMap->getLocalElementList();
133 GO indexBase = coarseMap->getIndexBase();
136 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
137 blkSize = rcp_dynamic_cast<const StridedMap>(coarseMap)->getFixedBlockSize();
139 Array<GO> elementList;
140 ArrayView<const GO> elementListView;
144 elementListView = elementAList;
147 auto numElements = elementAList.size() / blkSize;
149 elementList.resize(numElements);
152 for (LO i = 0; i < Teuchos::as<LO>(numElements); i++)
153 elementList[i] = (elementAList[i*blkSize]-indexBase)/blkSize + indexBase;
155 elementListView = elementList;
158 auto uniqueMap = fineCoords->getMap();
159 auto coarseCoordMap = MapFactory::Build(coarseMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(),
160 elementListView, indexBase, coarseMap->getComm());
161 RCP<doubleMultiVector> coarseCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>::Build(coarseCoordMap, fineCoords->getNumVectors());
164 RCP<doubleMultiVector> ghostedCoords = fineCoords;
165 if (aggregates->AggregatesCrossProcessors()) {
166 auto nonUniqueMap = aggregates->GetMap();
167 auto importer = ImportFactory::Build(uniqueMap, nonUniqueMap);
169 ghostedCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>::Build(nonUniqueMap, fineCoords->getNumVectors());
170 ghostedCoords->doImport(*fineCoords, *importer, Xpetra::INSERT);
175 auto aggGraph = aggregates->GetGraph();
176 auto numAggs = aggGraph.numRows();
178 auto fineCoordsView = fineCoords ->getDeviceLocalView(Xpetra::Access::ReadOnly);
179 auto coarseCoordsView = coarseCoords->getDeviceLocalView(Xpetra::Access::OverwriteAll);
185 const auto dim = fineCoords->getNumVectors();
187 typename AppendTrait<
decltype(fineCoordsView), Kokkos::RandomAccess>::type fineCoordsRandomView = fineCoordsView;
188 for (
size_t j = 0; j < dim; j++) {
189 Kokkos::parallel_for(
"MueLu:CoordinatesTransferF:Build:coord", Kokkos::RangePolicy<local_ordinal_type, execution_space>(0, numAggs),
190 KOKKOS_LAMBDA(
const LO i) {
194 auto aggregate = aggGraph.rowConst(i);
196 typename Teuchos::ScalarTraits<Scalar>::magnitudeType sum = 0.0;
197 for (
size_t colID = 0; colID < static_cast<size_t>(aggregate.length); colID++)
198 sum += fineCoordsRandomView(aggregate(colID),j);
200 coarseCoordsView(i,j) = sum / aggregate.length;
205 Set<RCP<doubleMultiVector> >(coarseLevel,
"Coordinates", coarseCoords);
207 int writeStart = pL.get<
int>(
"write start"), writeEnd = pL.get<
int>(
"write end");
208 if (writeStart == 0 && fineLevel.
GetLevelID() == 0 && writeStart <= writeEnd) {
209 std::string fileName =
"coordinates_before_rebalance_level_" +
toString(fineLevel.
GetLevelID()) +
".m";
210 Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>::Write(fileName, *fineCoords);
213 std::string fileName =
"coordinates_before_rebalance_level_" +
toString(coarseLevel.
GetLevelID()) +
".m";
214 Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>::Write(fileName,*coarseCoords);