95 Level ¤tLevel)
const {
96 using Dual2Primal_type = std::map<LocalOrdinal, LocalOrdinal>;
103 "Number of dual DOFs per node < 0 (default value). Specify a valid \"number of DOFs per dual node\" in the parameter list for the InterfaceAggregationFactory.");
106 ArrayRCP<const LocalOrdinal> primalVertex2AggId = primalAggregates->GetVertex2AggId()->getData(0);
109 RCP<Dual2Primal_type> mapNodesDualToPrimal;
111 mapNodesDualToPrimal = currentLevel.
Get<RCP<Dual2Primal_type>>(
"DualNodeID2PrimalNodeID",
NoFactory::get());
115 RCP<const Map> operatorRangeMap = A->getRangeMap();
116 const size_t myRank = operatorRangeMap->getComm()->getRank();
118 LocalOrdinal globalNumDualNodes = operatorRangeMap->getGlobalNumElements() / numDofsPerDualNode;
119 LocalOrdinal localNumDualNodes = operatorRangeMap->getLocalNumElements() / numDofsPerDualNode;
121 TEUCHOS_TEST_FOR_EXCEPTION(localNumDualNodes != Teuchos::as<LocalOrdinal>(mapNodesDualToPrimal->size()),
122 std::runtime_error, prefix <<
" MueLu requires the range map and the DualNodeID2PrimalNodeID map to be compatible.");
124 RCP<const Map> dualNodeMap = Teuchos::null;
125 if (numDofsPerDualNode == 1)
126 dualNodeMap = operatorRangeMap;
129 auto comm = operatorRangeMap->getComm();
130 std::vector<GlobalOrdinal> myDualNodes = {};
132 for (
size_t i = 0; i < operatorRangeMap->getLocalNumElements(); i += numDofsPerDualNode)
133 myDualNodes.push_back((operatorRangeMap->getGlobalElement(i) - indexBase) / numDofsPerDualNode + indexBase);
135 dualNodeMap = MapFactory::Build(operatorRangeMap->lib(), globalNumDualNodes, myDualNodes, indexBase, comm);
137 TEUCHOS_TEST_FOR_EXCEPTION(localNumDualNodes != Teuchos::as<LocalOrdinal>(dualNodeMap->getLocalNumElements()),
138 std::runtime_error, prefix <<
" Local number of dual nodes given by user is incompatible to the dual node map.");
140 RCP<Aggregates> dualAggregates = rcp(
new Aggregates(dualNodeMap));
141 dualAggregates->setObjectLabel(
"InterfaceAggregation");
144 dualAggregates->AggregatesCrossProcessors(primalAggregates->AggregatesCrossProcessors());
146 ArrayRCP<LocalOrdinal> dualVertex2AggId = dualAggregates->GetVertex2AggId()->getDataNonConst(0);
147 ArrayRCP<LocalOrdinal> dualProcWinner = dualAggregates->GetProcWinner()->getDataNonConst(0);
149 RCP<Dual2Primal_type> coarseMapNodesDualToPrimal = rcp(
new Dual2Primal_type());
150 RCP<Dual2Primal_type> coarseMapNodesPrimalToDual = rcp(
new Dual2Primal_type());
159 LocalOrdinal localPrimalNodeID = -Teuchos::ScalarTraits<LocalOrdinal>::one();
160 LocalOrdinal currentPrimalAggId = -Teuchos::ScalarTraits<LocalOrdinal>::one();
161 for (
LocalOrdinal localDualNodeID = 0; localDualNodeID < localNumDualNodes; ++localDualNodeID) {
163 localPrimalNodeID = (*mapNodesDualToPrimal)[localDualNodeID];
166 currentPrimalAggId = primalVertex2AggId[localPrimalNodeID];
170 if (coarseMapNodesPrimalToDual->count(currentPrimalAggId) == 0) {
172 (*coarseMapNodesPrimalToDual)[currentPrimalAggId] = numLocalDualAggregates;
173 (*coarseMapNodesDualToPrimal)[numLocalDualAggregates] = currentPrimalAggId;
174 ++numLocalDualAggregates;
178 dualVertex2AggId[localDualNodeID] = (*coarseMapNodesPrimalToDual)[currentPrimalAggId];
179 dualProcWinner[localDualNodeID] = myRank;
183 dualAggregates->SetNumAggregates(numLocalDualAggregates);
184 Set(currentLevel,
"Aggregates", dualAggregates);
185 Set(currentLevel,
"CoarseDualNodeID2PrimalNodeID", coarseMapNodesDualToPrimal);
191 const std::string &prefix,
Level ¤tLevel)
const {
192 const GlobalOrdinal GO_ZERO = Teuchos::ScalarTraits<LocalOrdinal>::zero();
193 const GlobalOrdinal GO_ONE = Teuchos::ScalarTraits<GlobalOrdinal>::one();
202 ArrayRCP<const LocalOrdinal> primalVertex2AggId = primalAggregates->GetVertex2AggId()->getData(0);
204 auto comm = A01->getRowMap()->getComm();
205 const int myRank = comm->getRank();
207 RCP<const Map> primalInterfaceDofRowMap = Teuchos::null;
210 primalInterfaceDofRowMap = currentLevel.
Get<RCP<const Map>>(
"Primal interface DOF map",
NoFactory::get());
212 primalInterfaceDofRowMap =
Get<RCP<const Map>>(currentLevel,
"Primal interface DOF map");
214 TEUCHOS_ASSERT(!primalInterfaceDofRowMap.is_null());
215 if (A01->IsView(
"stridedMaps") && rcp_dynamic_cast<const StridedMap>(A01->getRowMap(
"stridedMaps")) != Teuchos::null) {
216 auto stridedRowMap = rcp_dynamic_cast<const StridedMap>(A01->getRowMap(
"stridedMaps"));
217 auto stridedColMap = rcp_dynamic_cast<const StridedMap>(A01->getColMap(
"stridedMaps"));
218 numDofsPerPrimalNode = Teuchos::as<LocalOrdinal>(stridedRowMap->getFixedBlockSize());
219 numDofsPerDualNode = Teuchos::as<LocalOrdinal>(stridedColMap->getFixedBlockSize());
221 if (numDofsPerPrimalNode != numDofsPerDualNode) {
223 << numDofsPerPrimalNode <<
" primal DOFs per node and " << numDofsPerDualNode <<
" dual DOFs per node."
224 <<
"Be careful! Algorithm is not well-tested, if number of primal and dual DOFs per node differ." << std::endl;
229 "InterfaceAggregationFactory could not extract the number of primal DOFs per node from striding information. At least, make sure that StridedMap information has actually been provided.");
231 "InterfaceAggregationFactory could not extract the number of dual DOFs per node from striding information. At least, make sure that StridedMap information has actually been provided.");
252 GlobalOrdinal dualDofOffset = A01->getRowMap()->getMaxAllGlobalIndex() + 1;
255 RCP<const Map> dualDofMap = A01->getDomainMap();
257 dualDofMap->getMaxAllGlobalIndex(), dualBlockDim, dualDofOffset, dualDofMap->getIndexBase());
259 dualDofMap->getMinAllGlobalIndex(), dualBlockDim, dualDofOffset, dualDofMap->getIndexBase());
262 <<
", block dim = " << dualBlockDim
263 <<
", gid offset = " << dualDofOffset
267 <<
"/" << numDofsPerDualNode <<
"]" << std::endl;
270 Array<GlobalOrdinal> dualNodeId2primalNodeId(gMaxDualNodeId - gMinDualNodeId + 1, -GO_ONE);
271 Array<GlobalOrdinal> local_dualNodeId2primalNodeId(gMaxDualNodeId - gMinDualNodeId + 1, -GO_ONE);
274 Array<GlobalOrdinal> dualNodeId2primalAggId(gMaxDualNodeId - gMinDualNodeId + 1, -GO_ONE);
275 Array<GlobalOrdinal> local_dualNodeId2primalAggId(gMaxDualNodeId - gMinDualNodeId + 1, -GO_ONE);
277 Array<GlobalOrdinal> dualDofId2primalDofId(primalInterfaceDofRowMap->getGlobalNumElements(), -GO_ONE);
278 Array<GlobalOrdinal> local_dualDofId2primalDofId(primalInterfaceDofRowMap->getGlobalNumElements(), -GO_ONE);
281 const size_t numMyPrimalInterfaceDOFs = primalInterfaceDofRowMap->getLocalNumElements();
282 for (
size_t r = 0; r < numMyPrimalInterfaceDOFs; r += numDofsPerPrimalNode) {
283 GlobalOrdinal gPrimalRowId = primalInterfaceDofRowMap->getGlobalElement(r);
285 if (A01->getRowMap()->isNodeGlobalElement(gPrimalRowId))
287 const LocalOrdinal lPrimalRowId = A01->getRowMap()->getLocalElement(gPrimalRowId);
289 const LocalOrdinal lPrimalNodeId = lPrimalRowId / numDofsPerPrimalNode;
290 const LocalOrdinal primalAggId = primalVertex2AggId[lPrimalNodeId];
291 const GlobalOrdinal gDualDofId = A01->getDomainMap()->getGlobalElement(r);
294 TEUCHOS_TEST_FOR_EXCEPTION(local_dualNodeId2primalNodeId[gDualNodeId - gMinDualNodeId] != -GO_ONE,
296 "PROC: " << myRank <<
" gDualNodeId " << gDualNodeId
297 <<
" is already connected to primal nodeId "
298 << local_dualNodeId2primalNodeId[gDualNodeId - gMinDualNodeId]
299 <<
". This shouldn't be. A possible reason might be: "
300 "Check if parallel distribution of primalInterfaceDofRowMap corresponds "
301 "to the parallel distribution of subblock matrix A01.");
303 local_dualNodeId2primalNodeId[gDualNodeId - gMinDualNodeId] = gPrimalNodeId;
304 local_dualNodeId2primalAggId[gDualNodeId - gMinDualNodeId] = primalAggId;
307 const int dualNodeId2primalNodeIdSize = Teuchos::as<int>(local_dualNodeId2primalNodeId.size());
308 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, dualNodeId2primalNodeIdSize,
309 &local_dualNodeId2primalNodeId[0], &dualNodeId2primalNodeId[0]);
310 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, dualNodeId2primalNodeIdSize,
311 &local_dualNodeId2primalAggId[0], &dualNodeId2primalAggId[0]);
316 std::vector<GlobalOrdinal> dualNodes;
317 for (
size_t r = 0; r < A01->getDomainMap()->getLocalNumElements(); r++) {
321 GlobalOrdinal gDualDofId = A01->getDomainMap()->getGlobalElement(r);
323 dualNodes.push_back(gDualNodeId);
327 dualNodes.erase(std::unique(dualNodes.begin(), dualNodes.end()), dualNodes.end());
330 Teuchos::RCP<const Map> dualNodeMap = MapFactory::Build(A01->getRowMap()->lib(),
331 Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), dualNodes, A01->getRowMap()->getIndexBase(), comm);
334 Teuchos::RCP<Aggregates> dualAggregates = Teuchos::rcp(
new Aggregates(dualNodeMap));
335 dualAggregates->setObjectLabel(
"UC (dual variables)");
338 Teuchos::ArrayRCP<LocalOrdinal> dualVertex2AggId = dualAggregates->GetVertex2AggId()->getDataNonConst(0);
339 Teuchos::ArrayRCP<LocalOrdinal> dualProcWinner = dualAggregates->GetProcWinner()->getDataNonConst(0);
343 std::map<GlobalOrdinal, LocalOrdinal> primalAggId2localDualAggId;
344 for (
size_t lDualNodeID = 0; lDualNodeID < dualNodeMap->getLocalNumElements(); ++lDualNodeID) {
345 const GlobalOrdinal gDualNodeId = dualNodeMap->getGlobalElement(lDualNodeID);
346 const GlobalOrdinal primalAggId = dualNodeId2primalAggId[gDualNodeId - gMinDualNodeId];
347 if (primalAggId2localDualAggId.count(primalAggId) == 0)
348 primalAggId2localDualAggId[primalAggId] = nLocalAggregates++;
349 dualVertex2AggId[lDualNodeID] = primalAggId2localDualAggId[primalAggId];
350 dualProcWinner[lDualNodeID] = myRank;
358 RCP<Array<LO>> rowTranslation = rcp(
new Array<LO>());
359 RCP<Array<LO>> colTranslation = rcp(
new Array<LO>());
360 const size_t numMyDualNodes = dualNodeMap->getLocalNumElements();
361 for (
size_t lDualNodeID = 0; lDualNodeID < numMyDualNodes; ++lDualNodeID) {
362 for (
LocalOrdinal dof = 0; dof < numDofsPerDualNode; ++dof) {
363 rowTranslation->push_back(lDualNodeID);
364 colTranslation->push_back(lDualNodeID);
368 TEUCHOS_ASSERT(A01->isFillComplete());
370 RCP<AmalgamationInfo> dualAmalgamationInfo = rcp(
new AmalgamationInfo(rowTranslation, colTranslation,
371 A01->getDomainMap(), A01->getDomainMap(), A01->getDomainMap(),
372 fullblocksize, dualDofOffset, blockid, nStridedOffset, stridedblocksize));
374 dualAggregates->SetNumAggregates(nLocalAggregates);
375 dualAggregates->AggregatesCrossProcessors(primalAggregates->AggregatesCrossProcessors());
377 if (dualAggregates->AggregatesCrossProcessors())
378 GetOStream(
Runtime1) <<
"Interface aggregates cross processor boundaries." << std::endl;
380 GetOStream(
Runtime1) <<
"Interface aggregates do not cross processor boundaries." << std::endl;
382 currentLevel.
Set(
"Aggregates", dualAggregates,
this);
383 currentLevel.
Set(
"UnAmalgamationInfo", dualAmalgamationInfo,
this);