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