65 RCP<ParameterList> validParamList = rcp(
new ParameterList());
67 validParamList->set<RCP<const FactoryBase> >(
"Coordinates", Teuchos::null,
"Factory for coordinates generation");
68 validParamList->set<RCP<const FactoryBase> >(
"Aggregates", Teuchos::null,
"Factory for coordinates generation");
69 validParamList->set<RCP<const FactoryBase> >(
"CoarseMap", Teuchos::null,
"Generating factory of the coarse map");
70 validParamList->set<
bool> (
"structured aggregation",
false,
"Flag specifying that the geometric data is transferred for StructuredAggregationFactory");
71 validParamList->set<
bool> (
"aggregation coupled",
false,
"Flag specifying if the aggregation algorithm was used in coupled mode.");
72 validParamList->set<
bool> (
"Geometric",
false,
"Flag specifying that the coordinates are transferred for GeneralGeometricPFactory");
73 validParamList->set<RCP<const FactoryBase> >(
"coarseCoordinates", Teuchos::null,
"Factory for coarse coordinates generation");
74 validParamList->set<RCP<const FactoryBase> >(
"gCoarseNodesPerDim", Teuchos::null,
"Factory providing the global number of nodes per spatial dimensions of the mesh");
75 validParamList->set<RCP<const FactoryBase> >(
"lCoarseNodesPerDim", Teuchos::null,
"Factory providing the local number of nodes per spatial dimensions of the mesh");
76 validParamList->set<RCP<const FactoryBase> >(
"numDimensions" , Teuchos::null,
"Factory providing the number of spatial dimensions of the mesh");
77 validParamList->set<
int> (
"write start", -1,
"first level at which coordinates should be written to file");
78 validParamList->set<
int> (
"write end", -1,
"last level at which coordinates should be written to file");
79 validParamList->set<
bool> (
"hybrid aggregation",
false,
"Flag specifying that hybrid aggregation data is transfered for HybridAggregationFactory");
80 validParamList->set<RCP<const FactoryBase> >(
"aggregationRegionTypeCoarse", Teuchos::null,
"Factory indicating what aggregation type is to be used on the coarse level of the region");
81 validParamList->set<
bool> (
"interface aggregation",
false,
"Flag specifying that interface aggregation data is transfered for HybridAggregationFactory");
82 validParamList->set<RCP<const FactoryBase> >(
"coarseInterfacesDimensions", Teuchos::null,
"Factory providing coarseInterfacesDimensions");
83 validParamList->set<RCP<const FactoryBase> >(
"nodeOnCoarseInterface", Teuchos::null,
"Factory providing nodeOnCoarseInterface");
86 return validParamList;
128 using xdMV = Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>;
133 RCP<xdMV> coarseCoords;
134 RCP<xdMV> fineCoords;
135 Array<GO> gCoarseNodesPerDir;
136 Array<LO> lCoarseNodesPerDir;
140 if(pL.get<
bool>(
"hybrid aggregation") ==
true) {
141 std::string regionType =
Get<std::string>(fineLevel,
"aggregationRegionTypeCoarse");
142 numDimensions =
Get<int>(fineLevel,
"numDimensions");
143 lCoarseNodesPerDir =
Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
145 Set<int> (coarseLevel,
"numDimensions", numDimensions);
146 Set<Array<LO> > (coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
148 if((pL.get<
bool>(
"interface aggregation") ==
true) && (regionType ==
"uncoupled")) {
149 Array<LO> coarseInterfacesDimensions =
Get<Array<LO> >(fineLevel,
"coarseInterfacesDimensions");
150 Array<LO> nodeOnCoarseInterface =
Get<Array<LO> >(fineLevel,
"nodeOnCoarseInterface");
151 Set<Array<LO> >(coarseLevel,
"interfacesDimensions", coarseInterfacesDimensions);
152 Set<Array<LO> >(coarseLevel,
"nodeOnInterface", nodeOnCoarseInterface);
155 }
else if(pL.get<
bool>(
"structured aggregation") ==
true) {
156 if(pL.get<
bool>(
"aggregation coupled") ==
true) {
157 gCoarseNodesPerDir =
Get<Array<GO> >(fineLevel,
"gCoarseNodesPerDim");
158 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
160 lCoarseNodesPerDir =
Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
161 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
162 numDimensions =
Get<int>(fineLevel,
"numDimensions");
163 Set<int>(coarseLevel,
"numDimensions", numDimensions);
165 }
else if(pL.get<
bool>(
"Geometric") ==
true) {
166 coarseCoords =
Get<RCP<xdMV> >(coarseLevel,
"coarseCoordinates");
167 gCoarseNodesPerDir =
Get<Array<GO> >(coarseLevel,
"gCoarseNodesPerDim");
168 lCoarseNodesPerDir =
Get<Array<LO> >(coarseLevel,
"lCoarseNodesPerDim");
169 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
170 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
175 if (coarseLevel.
IsAvailable(
"Coordinates",
this)) {
187 ArrayView<const GO> elementAList = coarseMap->getLocalElementList();
190 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
191 blkSize = rcp_dynamic_cast<const StridedMap>(coarseMap)->getFixedBlockSize();
193 GO indexBase = coarseMap->getIndexBase();
194 size_t numElements = elementAList.size() / blkSize;
195 Array<GO> elementList(numElements);
198 for (LO i = 0; i < Teuchos::as<LO>(numElements); i++)
199 elementList[i] = (elementAList[i*blkSize]-indexBase)/blkSize + indexBase;
201 RCP<const Map> uniqueMap = fineCoords->getMap();
202 RCP<const Map> coarseCoordMap = MapFactory ::Build(coarseMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), elementList, indexBase, coarseMap->getComm());
203 coarseCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>
::Build(coarseCoordMap, fineCoords->getNumVectors());
206 RCP<Aggregates> aggregates;
207 bool aggregatesCrossProcessors;
209 aggregatesCrossProcessors = aggregates->AggregatesCrossProcessors();
212 RCP<xdMV> ghostedCoords = fineCoords;
213 if (aggregatesCrossProcessors) {
214 RCP<const Map> nonUniqueMap = aggregates->GetMap();
215 RCP<const Import> importer = ImportFactory::Build(uniqueMap, nonUniqueMap);
217 ghostedCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>
::Build(nonUniqueMap, fineCoords->getNumVectors());
218 ghostedCoords->doImport(*fineCoords, *importer, Xpetra::INSERT);
223 auto aggGraph = aggregates->GetGraph();
224 auto numAggs = aggGraph.numRows();
226 auto fineCoordsView = ghostedCoords->getDeviceLocalView(Xpetra::Access::ReadOnly);
227 auto coarseCoordsView = coarseCoords->getDeviceLocalView(Xpetra::Access::OverwriteAll);
233 const auto dim = ghostedCoords->getNumVectors();
235 typename AppendTrait<
decltype(fineCoordsView), Kokkos::RandomAccess>::type fineCoordsRandomView = fineCoordsView;
236 for (
size_t j = 0; j < dim; j++) {
237 Kokkos::parallel_for(
"MueLu:CoordinatesTransferF:Build:coord", Kokkos::RangePolicy<local_ordinal_type, execution_space>(0, numAggs),
238 KOKKOS_LAMBDA(
const LO i) {
242 auto aggregate = aggGraph.rowConst(i);
244 typename Teuchos::ScalarTraits<Scalar>::magnitudeType sum = 0.0;
245 for (
size_t colID = 0; colID < static_cast<size_t>(aggregate.length); colID++)
246 sum += fineCoordsRandomView(aggregate(colID),j);
248 coarseCoordsView(i,j) = sum / aggregate.length;
257 int writeStart = pL.get<
int>(
"write start"), writeEnd = pL.get<
int>(
"write end");
258 if (writeStart == 0 && fineLevel.
GetLevelID() == 0 && writeStart <= writeEnd) {
259 std::ostringstream buf;
261 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
262 Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>::Write(fileName,*fineCoords);
265 std::ostringstream buf;
267 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
268 Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>::Write(fileName,*coarseCoords);