MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_BrickAggregationFactory_def.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// MueLu: A package for multigrid based preconditioning
4//
5// Copyright 2012 NTESS and the MueLu contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef MUELU_BRICKAGGREGATIONFACTORY_DEF_HPP_
11#define MUELU_BRICKAGGREGATIONFACTORY_DEF_HPP_
12
14#ifdef HAVE_MPI
15#include <Teuchos_DefaultMpiComm.hpp>
16#include <Teuchos_CommHelpers.hpp>
17#endif
18#include <Teuchos_OrdinalTraits.hpp>
19
20#include <Xpetra_Import.hpp>
21#include <Xpetra_ImportFactory.hpp>
22#include <Xpetra_Map.hpp>
23#include <Xpetra_MapFactory.hpp>
24#include <Xpetra_Matrix.hpp>
25#include <Xpetra_MultiVector.hpp>
26#include <Xpetra_MultiVectorFactory.hpp>
27
28#include "MueLu_Aggregates.hpp"
29#include "MueLu_Level.hpp"
30#include "MueLu_MasterList.hpp"
31#include "MueLu_Monitor.hpp"
32#include "MueLu_Utilities.hpp"
33#include "MueLu_LWGraph.hpp"
34
35#include "MueLu_LWGraph.hpp"
36
37namespace MueLu {
38
39template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
41 RCP<ParameterList> validParamList = rcp(new ParameterList());
42
43#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
44 SET_VALID_ENTRY("aggregation: brick x size");
45 SET_VALID_ENTRY("aggregation: brick y size");
46 SET_VALID_ENTRY("aggregation: brick z size");
47 SET_VALID_ENTRY("aggregation: brick x Dirichlet");
48 SET_VALID_ENTRY("aggregation: brick y Dirichlet");
49 SET_VALID_ENTRY("aggregation: brick z Dirichlet");
50#undef SET_VALID_ENTRY
51
52 validParamList->set<RCP<const FactoryBase> >("A", Teuchos::null, "Generating factory for matrix");
53 validParamList->set<RCP<const FactoryBase> >("Coordinates", Teuchos::null, "Generating factory for coordinates");
54 return validParamList;
55}
56
57template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
59 Input(currentLevel, "A");
60 Input(currentLevel, "Coordinates");
61}
62
63// The current implementation cannot deal with bricks larger than 3x3(x3) in
64// parallel. The reason is that aggregation infrastructure in place has
65// major drawbacks.
66//
67// Aggregates class is constructed with a help of a provided map, either
68// taken from a graph, or provided directly. This map is usually taken to be
69// a column map of a matrix. The reason for that is that if we have an
70// overlapped aggregation, we want the processor owning aggregates to store
71// agg id for all nodes in this aggregate. If we used row map, there would
72// be no way for the processor to know whether there are some other nodes on
73// a different processor which belong to its aggregate. On the other hand,
74// using column map allows both vertex2AggId and procWinner arrays in
75// Aggregates class to store some extra data, such as whether nodes belonging
76// to a different processor belong to this processor aggregate.
77//
78// The drawback of this is that it stores only overlap=1 data. For aggressive
79// coarsening, such a brick aggregation with a large single dimension of
80// brick, it could happen that we need to know depth two or more extra nodes
81// in the other processor subdomain.
82//
83// Another issue is that we may have some implicit connection between
84// aggregate map and maps of A used in the construction of a tentative
85// prolongator.
86//
87// Another issue is that it seems that some info is unused or not required.
88// Specifically, it seems that if a node belongs to an aggregate on a
89// different processor, we don't actually need to set vertex2AggId and
90// procWinner, despite the following comment in
91// Aggregates decl:
92// vertex2AggId[k] gives a local id
93// corresponding to the aggregate to which
94// local id k has been assigned. While k
95// is the local id on my processor (MyPID)
96// vertex2AggId[k] is the local id on the
97// processor which actually owns the
98// aggregate. This owning processor has id
99// given by procWinner[k].
100// It is possible that that info is only used during arbitration in
101// CoupledAggregationFactory.
102//
103// The steps that we need to do to resolve this issue:
104// - Break the link between maps in TentativePFactory, allowing any maps in Aggregates
105// - Allow Aggregates to construct their own maps, if necessary, OR
106// - construct aggregates based on row map
107template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
109 FactoryMonitor m(*this, "Build", currentLevel);
110
111 typedef Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO> MultiVector_d;
112
113 const ParameterList& pL = GetParameterList();
114 RCP<MultiVector_d> coords = Get<RCP<MultiVector_d> >(currentLevel, "Coordinates");
115 RCP<Matrix> A = Get<RCP<Matrix> >(currentLevel, "A");
116 RCP<const Map> rowMap = A->getRowMap();
117 RCP<const Map> colMap = A->getColMap();
118 GO GO_INVALID = Teuchos::OrdinalTraits<GO>::invalid();
119
120 RCP<const Teuchos::Comm<int> > comm = rowMap->getComm();
121 int numProcs = comm->getSize();
122 int myRank = comm->getRank();
123
124 int numPoints = colMap->getLocalNumElements();
125
126 bx_ = pL.get<int>("aggregation: brick x size");
127 by_ = pL.get<int>("aggregation: brick y size");
128 bz_ = pL.get<int>("aggregation: brick z size");
129
130 dirichletX_ = pL.get<bool>("aggregation: brick x Dirichlet");
131 dirichletY_ = pL.get<bool>("aggregation: brick y Dirichlet");
132 dirichletZ_ = pL.get<bool>("aggregation: brick z Dirichlet");
133 if (dirichletX_) GetOStream(Runtime0) << "Dirichlet boundaries in the x direction" << std::endl;
134 if (dirichletY_) GetOStream(Runtime0) << "Dirichlet boundaries in the y direction" << std::endl;
135 if (dirichletZ_) GetOStream(Runtime0) << "Dirichlet boundaries in the z direction" << std::endl;
136
137 if (numProcs > 1) {
138 // TODO: deal with block size > 1 (see comments above)
139 // TEUCHOS_TEST_FOR_EXCEPTION(bx_ > 3 || by_ > 3 || bz_ > 3, Exceptions::RuntimeError, "Currently cannot deal with brick size > 3");
140 }
141
142 RCP<MultiVector_d> overlappedCoords = coords;
143 RCP<const Import> importer = ImportFactory::Build(coords->getMap(), colMap);
144 if (!importer.is_null()) {
145 overlappedCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>::Build(colMap, coords->getNumVectors());
146 overlappedCoords->doImport(*coords, *importer, Xpetra::INSERT);
147 }
148
149 // Setup misc structures
150 // Logically, we construct enough data to query topological information of a rectangular grid
151 Setup(comm, overlappedCoords, colMap);
152
153 GetOStream(Runtime0) << "Using brick size: " << bx_
154 << (nDim_ > 1 ? "x " + toString(by_) : "")
155 << (nDim_ > 2 ? "x " + toString(bz_) : "") << std::endl;
156
157 // Build the graph
158 BuildGraph(currentLevel, A);
159
160 // Construct aggregates
161 RCP<Aggregates> aggregates = rcp(new Aggregates(colMap));
162 aggregates->setObjectLabel("Brick");
163
164 ArrayRCP<LO> vertex2AggId = aggregates->GetVertex2AggId()->getDataNonConst(0);
165 ArrayRCP<LO> procWinner = aggregates->GetProcWinner()->getDataNonConst(0);
166
167 // In the first pass, we set a mapping from a vertex to aggregate global id. We deal with a structured
168 // rectangular mesh, therefore we know the structure of aggregates. For each vertex we can tell exactly
169 // which aggregate it belongs to.
170 // If we determine that the aggregate does not belong to us (i.e. the root vertex does not belong to this
171 // processor, or is outside and we lost "" arbitration), we record the global aggregate id in order to
172 // fetch the local info from the processor owning the aggregate. This is required for aggregates, as it
173 // uses the local aggregate ids of the owning processor.
174 std::set<GO> myAggGIDs, remoteAggGIDs;
175 for (LO LID = 0; LID < numPoints; LID++) {
176 GO aggGID = getAggGID(LID);
177 // printf("[%d] (%d,%d,%d) => agg %d\n",LID,(int)(*xMap_)[x_[LID]],nDim_ > 1 ? (int)(*yMap_)[y_[LID]] : -1,nDim_ > 2 ? (int)(*zMap_)[z_[LID]] : -1,(int)aggGID);
178 if (aggGID == GO_INVALID) continue;
179 // printf("[%d] getRoot = %d\n",(int)LID,(int)getRoot(LID));
180
181 if ((revMap_.find(getRoot(LID)) != revMap_.end()) && rowMap->isNodeGlobalElement(colMap->getGlobalElement(revMap_[getRoot(LID)]))) {
182 // Root of the brick aggregate containing GID (<- LID) belongs to us
183 vertex2AggId[LID] = aggGID;
184 myAggGIDs.insert(aggGID);
185
186 if (isRoot(LID))
187 aggregates->SetIsRoot(LID);
188 // printf("[%d] initial vertex2AggId = %d\n",(int)LID,(int)vertex2AggId[LID]);
189 } else {
190 remoteAggGIDs.insert(aggGID);
191 }
192 }
193 size_t numAggregates = myAggGIDs.size();
194 size_t numRemote = remoteAggGIDs.size();
195 aggregates->SetNumAggregates(numAggregates);
196
197 std::map<GO, LO> AggG2L; // Map: Agg GID -> Agg LID (possibly on a different processor)
198 std::map<GO, int> AggG2R; // Map: Agg GID -> processor rank owning aggregate
199
200 Array<GO> myAggGIDsArray(numAggregates), remoteAggGIDsArray(numRemote);
201
202 // Fill in the maps for aggregates that we own
203 size_t ind = 0;
204 for (typename std::set<GO>::const_iterator it = myAggGIDs.begin(); it != myAggGIDs.end(); it++) {
205 AggG2L[*it] = ind;
206 AggG2R[*it] = myRank;
207
208 myAggGIDsArray[ind++] = *it;
209 }
210
211 // The map is a convenient way to fetch remote local indices from global indices.
212 RCP<Map> aggMap = MapFactory::Build(rowMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(),
213 myAggGIDsArray, 0, comm);
214
215 ind = 0;
216 for (typename std::set<GO>::const_iterator it = remoteAggGIDs.begin(); it != remoteAggGIDs.end(); it++)
217 remoteAggGIDsArray[ind++] = *it;
218
219 // Fetch the required aggregate local ids and ranks
220 Array<int> remoteProcIDs(numRemote);
221 Array<LO> remoteLIDs(numRemote);
222 aggMap->getRemoteIndexList(remoteAggGIDsArray, remoteProcIDs, remoteLIDs);
223
224 // Fill in the maps for aggregates that we don't own but which have some of our vertices
225 for (size_t i = 0; i < numRemote; i++) {
226 AggG2L[remoteAggGIDsArray[i]] = remoteLIDs[i];
227 AggG2R[remoteAggGIDsArray[i]] = remoteProcIDs[i];
228 }
229
230 // Remap aggregate GIDs to LIDs and set up owning processors
231 for (LO LID = 0; LID < numPoints; LID++) {
232 if (revMap_.find(getRoot(LID)) != revMap_.end() && rowMap->isNodeGlobalElement(colMap->getGlobalElement(revMap_[getRoot(LID)]))) {
233 GO aggGID = vertex2AggId[LID];
234 if (aggGID != MUELU_UNAGGREGATED) {
235 vertex2AggId[LID] = AggG2L[aggGID];
236 procWinner[LID] = AggG2R[aggGID];
237 }
238 }
239 }
240
241 GO numGlobalRemote;
242 MueLu_sumAll(comm, as<GO>(numRemote), numGlobalRemote);
243 aggregates->AggregatesCrossProcessors(numGlobalRemote);
244
245 Set(currentLevel, "Aggregates", aggregates);
246
247 GetOStream(Statistics1) << aggregates->description() << std::endl;
248}
249
250template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
252 Setup(const RCP<const Teuchos::Comm<int> >& comm, const RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO> >& coords, const RCP<const Map>& /* map */) const {
253 nDim_ = coords->getNumVectors();
254
255 x_ = coords->getData(0);
256 xMap_ = Construct1DMap(comm, x_);
257 nx_ = xMap_->size();
258
259 ny_ = 1;
260 if (nDim_ > 1) {
261 y_ = coords->getData(1);
262 yMap_ = Construct1DMap(comm, y_);
263 ny_ = yMap_->size();
264 }
265
266 nz_ = 1;
267 if (nDim_ > 2) {
268 z_ = coords->getData(2);
269 zMap_ = Construct1DMap(comm, z_);
270 nz_ = zMap_->size();
271 }
272
273 for (size_t ind = 0; ind < coords->getLocalLength(); ind++) {
274 GO i = (*xMap_)[(coords->getData(0))[ind]], j = 0, k = 0;
275 if (nDim_ > 1)
276 j = (*yMap_)[(coords->getData(1))[ind]];
277 if (nDim_ > 2)
278 k = (*zMap_)[(coords->getData(2))[ind]];
279
280 revMap_[k * ny_ * nx_ + j * nx_ + i] = ind;
281 }
282
283 // Get the number of aggregates in each direction, correcting for Dirichlet
284 int xboost = dirichletX_ ? 1 : 0;
285 int yboost = dirichletY_ ? 1 : 0;
286 int zboost = dirichletZ_ ? 1 : 0;
287 naggx_ = (nx_ - 2 * xboost) / bx_ + ((nx_ - 2 * xboost) % bx_ ? 1 : 0);
288
289 if (nDim_ > 1)
290 naggy_ = (ny_ - 2 * yboost) / by_ + ((ny_ - 2 * yboost) % by_ ? 1 : 0);
291 else
292 naggy_ = 1;
293
294 if (nDim_ > 2)
295 naggz_ = (nz_ - 2 * zboost) / bz_ + ((nz_ - 2 * zboost) % bz_ ? 1 : 0);
296 else
297 naggz_ = 1;
298}
299
300template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
301RCP<typename BrickAggregationFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::container>
303 Construct1DMap(const RCP<const Teuchos::Comm<int> >& comm,
304 const ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& x) const {
305 int n = x.size();
306
307 // Step 1: Create a local vector with unique coordinate points
308 RCP<container> gMap = rcp(new container);
309 for (int i = 0; i < n; i++)
310 (*gMap)[x[i]] = 0;
311
312#ifdef HAVE_MPI
313 // Step 2: exchange coordinates
314 // NOTE: we assume the coordinates are double, or double compatible
315 // That means that for complex case, we assume that all imaginary parts are zeros
316 int numProcs = comm->getSize();
317 if (numProcs > 1) {
318 RCP<const Teuchos::MpiComm<int> > dupMpiComm = rcp_dynamic_cast<const Teuchos::MpiComm<int> >(comm->duplicate());
319
320 MPI_Comm rawComm = (*dupMpiComm->getRawMpiComm())();
321
322 int sendCnt = gMap->size(), cnt = 0, recvSize;
323 Array<int> recvCnt(numProcs), Displs(numProcs);
324 Array<double> sendBuf, recvBuf;
325
326 sendBuf.resize(sendCnt);
327 for (typename container::const_iterator cit = gMap->begin(); cit != gMap->end(); cit++)
328 sendBuf[cnt++] = Teuchos::as<double>(STS::real(cit->first));
329
330 MPI_Allgather(&sendCnt, 1, MPI_INT, recvCnt.getRawPtr(), 1, MPI_INT, rawComm);
331 Displs[0] = 0;
332 for (int i = 0; i < numProcs - 1; i++)
333 Displs[i + 1] = Displs[i] + recvCnt[i];
334 recvSize = Displs[numProcs - 1] + recvCnt[numProcs - 1];
335 recvBuf.resize(recvSize);
336 MPI_Allgatherv(sendBuf.getRawPtr(), sendCnt, MPI_DOUBLE, recvBuf.getRawPtr(), recvCnt.getRawPtr(), Displs.getRawPtr(), MPI_DOUBLE, rawComm);
337
338 for (int i = 0; i < recvSize; i++)
339 (*gMap)[as<SC>(recvBuf[i])] = 0;
340 }
341#endif
342
343 GO cnt = 0;
344 for (typename container::iterator it = gMap->begin(); it != gMap->end(); it++)
345 it->second = cnt++;
346
347 return gMap;
348}
349
350template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
352 int i, j, k;
353 getIJK(LID, i, j, k);
354
355 return (k * ny_ * nx_ + j * nx_ + i) == getRoot(LID);
356}
357
358template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
360 bool boundary = false;
361 int i, j, k;
362 getIJK(LID, i, j, k);
363 if (dirichletX_ && (i == 0 || i == nx_ - 1))
364 boundary = true;
365 if (nDim_ > 1 && dirichletY_ && (j == 0 || j == ny_ - 1))
366 boundary = true;
367 if (nDim_ > 2 && dirichletZ_ && (k == 0 || k == nz_ - 1))
368 boundary = true;
369
370 return boundary;
371}
372
373template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
375 if (isDirichlet(LID))
376 return Teuchos::OrdinalTraits<GlobalOrdinal>::invalid();
377
378 int aggI, aggJ, aggK;
379 getAggIJK(LID, aggI, aggJ, aggK);
380 int xboost = dirichletX_ ? 1 : 0;
381 int yboost = dirichletY_ ? 1 : 0;
382 int zboost = dirichletZ_ ? 1 : 0;
383
384 int i = xboost + aggI * bx_ + (bx_ - 1) / 2;
385 int j = (nDim_ > 1) ? yboost + aggJ * by_ + (by_ - 1) / 2 : 0;
386 int k = (nDim_ > 2) ? zboost + aggK * bz_ + (bz_ - 1) / 2 : 0;
387
388 return k * ny_ * nx_ + j * nx_ + i;
389}
390
391template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
393 i = (*xMap_)[x_[LID]];
394 j = (nDim_ > 1) ? (*yMap_)[y_[LID]] : 0;
395 k = (nDim_ > 2) ? (*zMap_)[z_[LID]] : 0;
396}
397
398template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
400 int xboost = dirichletX_ ? 1 : 0;
401 int yboost = dirichletY_ ? 1 : 0;
402 int zboost = dirichletZ_ ? 1 : 0;
403 int pointI, pointJ, pointK;
404 getIJK(LID, pointI, pointJ, pointK);
405 i = (pointI - xboost) / bx_;
406
407 if (nDim_ > 1)
408 j = (pointJ - yboost) / by_;
409 else
410 j = 0;
411
412 if (nDim_ > 2)
413 k = (pointK - zboost) / bz_;
414 else
415 k = 0;
416}
417
418template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
420 bool boundary = false;
421
422 int i, j, k;
423 getIJK(LID, i, j, k);
424 int ii, jj, kk;
425 getAggIJK(LID, ii, jj, kk);
426
427 if (dirichletX_ && (i == 0 || i == nx_ - 1)) boundary = true;
428 if (nDim_ > 1 && dirichletY_ && (j == 0 || j == ny_ - 1)) boundary = true;
429 if (nDim_ > 2 && dirichletZ_ && (k == 0 || k == nz_ - 1)) boundary = true;
430
431 /*
432 if(boundary)
433 printf("[%d] coord = (%d,%d,%d) {%d,%d,%d} agg = (%d,%d,%d) {%d,%d,%d} => agg %s\n",LID,i,j,k,nx_,ny_,nz_,ii,jj,kk,naggx_,naggy_,naggz_,"BOUNDARY");
434 else
435 printf("[%d] coord = (%d,%d,%d) {%d,%d,%d} agg = (%d,%d,%d) {%d,%d,%d} => agg %d\n",LID,i,j,k,nx_,ny_,nz_,ii,jj,kk,naggx_,naggy_,naggz_,kk*naggy_*naggx_ + jj*naggx_ + ii);
436 */
437
438 if (boundary)
439 return Teuchos::OrdinalTraits<GlobalOrdinal>::invalid();
440 else
441 return Teuchos::as<GlobalOrdinal>(kk * naggy_ * naggx_) + Teuchos::as<GlobalOrdinal>(jj * naggx_) + ii;
442}
443
444template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
446 // TODO: Currently only works w/ 1 DOF per node
447 double dirichletThreshold = 0.0;
448
449 if (bx_ > 1 && (nDim_ <= 1 || by_ > 1) && (nDim_ <= 2 || bz_ > 1)) {
450 FactoryMonitor m(*this, "Generating Graph (trivial)", currentLevel);
451 /*** Case 1: Use the matrix is the graph ***/
452 // Bricks are of non-trivial size in all active dimensions
453 RCP<LWGraph> graph = rcp(new LWGraph(A->getCrsGraph(), "graph of A"));
454 auto boundaryNodes = MueLu::Utilities<SC, LO, GO, NO>::DetectDirichletRows_kokkos_host(*A, dirichletThreshold);
455 graph->SetBoundaryNodeMap(boundaryNodes);
456
457 if (GetVerbLevel() & Statistics1) {
458 GO numLocalBoundaryNodes = 0;
459 GO numGlobalBoundaryNodes = 0;
460 for (size_t i = 0; i < boundaryNodes.size(); ++i)
461 if (boundaryNodes(i))
462 numLocalBoundaryNodes++;
463 RCP<const Teuchos::Comm<int> > comm = A->getRowMap()->getComm();
464 MueLu_sumAll(comm, numLocalBoundaryNodes, numGlobalBoundaryNodes);
465 GetOStream(Statistics1) << "Detected " << numGlobalBoundaryNodes << " Dirichlet nodes" << std::endl;
466 }
467 Set(currentLevel, "DofsPerNode", 1);
468 Set(currentLevel, "Graph", graph);
469 Set(currentLevel, "Filtering", false);
470 } else {
471 FactoryMonitor m(*this, "Generating Graph", currentLevel);
472 /*** Case 2: Dropping required ***/
473 // There is at least one active dimension in which we are not coarsening.
474 // Those connections need to be dropped
475 bool drop_x = (bx_ == 1);
476 bool drop_y = (nDim_ > 1 && by_ == 1);
477 bool drop_z = (nDim_ > 2 && bz_ == 1);
478
479 typename LWGraph::row_type::non_const_type rows("rows", A->getLocalNumRows() + 1);
480 typename LWGraph::entries_type::non_const_type columns("columns", A->getLocalNumEntries());
481
482 size_t N = A->getRowMap()->getLocalNumElements();
483
484 // FIXME: Do this on the host because indexing functions are host functions
485 auto G = A->getLocalMatrixHost().graph;
486 auto rowptr = G.row_map;
487 auto colind = G.entries;
488
489 int ct = 0;
490 rows(0) = 0;
491 for (size_t row = 0; row < N; row++) {
492 // NOTE: Assumes that the first part of the colmap is the rowmap
493 int ir, jr, kr;
494 LO row2 = A->getColMap()->getLocalElement(A->getRowMap()->getGlobalElement(row));
495 getIJK(row2, ir, jr, kr);
496
497 for (size_t cidx = rowptr[row]; cidx < rowptr[row + 1]; cidx++) {
498 int ic, jc, kc;
499 LO col = colind[cidx];
500 getIJK(col, ic, jc, kc);
501
502 if ((row2 != col) && ((drop_x && ir != ic) || (drop_y && jr != jc) || (drop_z && kr != kc))) {
503 // Drop it
504 // printf("[%4d] DROP row = (%d,%d,%d) col = (%d,%d,%d)\n",(int)row,ir,jr,kr,ic,jc,kc);
505 } else {
506 // Keep it
507 // printf("[%4d] KEEP row = (%d,%d,%d) col = (%d,%d,%d)\n",(int)row,ir,jr,kr,ic,jc,kc);
508 columns(ct) = col;
509 ct++;
510 }
511 }
512 rows(row + 1) = ct;
513 } // end for
514
515 RCP<LWGraph> graph = rcp(new LWGraph(rows, columns, A->getRowMap(), A->getColMap(), "thresholded graph of A"));
516
517 auto boundaryNodes = MueLu::Utilities<SC, LO, GO, NO>::DetectDirichletRows_kokkos_host(*A, dirichletThreshold);
518 graph->SetBoundaryNodeMap(boundaryNodes);
519
520 if (GetVerbLevel() & Statistics1) {
521 GO numLocalBoundaryNodes = 0;
522 GO numGlobalBoundaryNodes = 0;
523 for (size_t i = 0; i < boundaryNodes.size(); ++i)
524 if (boundaryNodes(i))
525 numLocalBoundaryNodes++;
526 RCP<const Teuchos::Comm<int> > comm = A->getRowMap()->getComm();
527 MueLu_sumAll(comm, numLocalBoundaryNodes, numGlobalBoundaryNodes);
528 GetOStream(Statistics1) << "Detected " << numGlobalBoundaryNodes << " Dirichlet nodes" << std::endl;
529 }
530 Set(currentLevel, "DofsPerNode", 1);
531 Set(currentLevel, "Graph", graph);
532 Set(currentLevel, "Filtering", true);
533 } // end else
534
535} // end BuildGraph
536
537} // namespace MueLu
538
539#endif /* MUELU_BRICKAGGREGATIONFACTORY_DEF_HPP_ */
#define MUELU_UNAGGREGATED
#define SET_VALID_ENTRY(name)
#define MueLu_sumAll(rcpComm, in, out)
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Container class for aggregation information.
void Setup(const RCP< const Teuchos::Comm< int > > &comm, const RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LO, GO, NO > > &coords, const RCP< const Map > &map) const
std::map< Scalar, GlobalOrdinal, compare > container
GlobalOrdinal getRoot(LocalOrdinal LID) const
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
GlobalOrdinal getAggGID(LocalOrdinal LID) const
void DeclareInput(Level &currentLevel) const
Input.
void Build(Level &currentLevel) const
Build aggregates.
void BuildGraph(Level &currentLevel, const RCP< Matrix > &A) const
void getAggIJK(LocalOrdinal LID, int &i, int &j, int &k) const
RCP< container > Construct1DMap(const RCP< const Teuchos::Comm< int > > &comm, const ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &x) const
void getIJK(LocalOrdinal LID, int &i, int &j, int &k) const
Timer to be used in factories. Similar to Monitor but with additional timers.
Lightweight MueLu representation of a compressed row storage graph.
Class that holds all level-specific information.
static Kokkos::View< bool *, typename Kokkos::HostSpace > DetectDirichletRows_kokkos_host(const Matrix &A, const Magnitude &tol=Teuchos::ScalarTraits< typename Teuchos::ScalarTraits< SC >::magnitudeType >::zero(), const bool count_twos_as_dirichlet=false)
Namespace for MueLu classes and methods.
@ Statistics1
Print more statistics.
@ Runtime0
One-liner description of what is happening.
std::string toString(const T &what)
Little helper function to convert non-string types to strings.