35 RCP<ParameterList> validParamList = rcp(
new ParameterList());
37 validParamList->set<RCP<const FactoryBase> >(
"Coordinates", Teuchos::null,
"Factory for coordinates generation");
38 validParamList->set<RCP<const FactoryBase> >(
"Aggregates", Teuchos::null,
"Factory for coordinates generation");
39 validParamList->set<RCP<const FactoryBase> >(
"CoarseMap", Teuchos::null,
"Generating factory of the coarse map");
40 validParamList->set<
bool>(
"structured aggregation",
false,
"Flag specifying that the geometric data is transferred for StructuredAggregationFactory");
41 validParamList->set<
bool>(
"aggregation coupled",
false,
"Flag specifying if the aggregation algorithm was used in coupled mode.");
42 validParamList->set<
bool>(
"Geometric",
false,
"Flag specifying that the coordinates are transferred for GeneralGeometricPFactory");
43 validParamList->set<RCP<const FactoryBase> >(
"coarseCoordinates", Teuchos::null,
"Factory for coarse coordinates generation");
44 validParamList->set<RCP<const FactoryBase> >(
"gCoarseNodesPerDim", Teuchos::null,
"Factory providing the global number of nodes per spatial dimensions of the mesh");
45 validParamList->set<RCP<const FactoryBase> >(
"lCoarseNodesPerDim", Teuchos::null,
"Factory providing the local number of nodes per spatial dimensions of the mesh");
46 validParamList->set<RCP<const FactoryBase> >(
"numDimensions", Teuchos::null,
"Factory providing the number of spatial dimensions of the mesh");
47 validParamList->set<
int>(
"write start", -1,
"first level at which coordinates should be written to file");
48 validParamList->set<
int>(
"write end", -1,
"last level at which coordinates should be written to file");
49 validParamList->set<
bool>(
"hybrid aggregation",
false,
"Flag specifying that hybrid aggregation data is transfered for HybridAggregationFactory");
50 validParamList->set<RCP<const FactoryBase> >(
"aggregationRegionTypeCoarse", Teuchos::null,
"Factory indicating what aggregation type is to be used on the coarse level of the region");
51 validParamList->set<
bool>(
"interface aggregation",
false,
"Flag specifying that interface aggregation data is transfered for HybridAggregationFactory");
52 validParamList->set<RCP<const FactoryBase> >(
"coarseInterfacesDimensions", Teuchos::null,
"Factory providing coarseInterfacesDimensions");
53 validParamList->set<RCP<const FactoryBase> >(
"nodeOnCoarseInterface", Teuchos::null,
"Factory providing nodeOnCoarseInterface");
55 return validParamList;
97 using xdMV = Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>;
102 RCP<xdMV> coarseCoords;
103 RCP<xdMV> fineCoords;
104 Array<GO> gCoarseNodesPerDir;
105 Array<LO> lCoarseNodesPerDir;
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");
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);
144 if (coarseLevel.
IsAvailable(
"Coordinates",
this)) {
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;
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;
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);