149 typedef Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO> MultiVector_d;
151 const ParameterList& pL = GetParameterList();
152 RCP<MultiVector_d> coords = Get<RCP<MultiVector_d> >(currentLevel,
"Coordinates");
153 RCP<Matrix> A = Get< RCP<Matrix> > (currentLevel,
"A");
154 RCP<const Map> rowMap = A->getRowMap();
155 RCP<const Map> colMap = A->getColMap();
156 GO GO_INVALID = Teuchos::OrdinalTraits<GO>::invalid();
158 RCP<const Teuchos::Comm<int> > comm = rowMap->getComm();
159 int numProcs = comm->getSize();
160 int myRank = comm->getRank();
162 int numPoints = colMap->getNodeNumElements();
164 bx_ = pL.get<
int>(
"aggregation: brick x size");
165 by_ = pL.get<
int>(
"aggregation: brick y size");
166 bz_ = pL.get<
int>(
"aggregation: brick z size");
168 dirichletX_ = pL.get<
bool>(
"aggregation: brick x Dirichlet");
169 dirichletY_ = pL.get<
bool>(
"aggregation: brick y Dirichlet");
170 dirichletZ_ = pL.get<
bool>(
"aggregation: brick z Dirichlet");
171 if(dirichletX_) GetOStream(
Runtime0) <<
"Dirichlet boundaries in the x direction"<<std::endl;
172 if(dirichletY_) GetOStream(
Runtime0) <<
"Dirichlet boundaries in the y direction"<<std::endl;
173 if(dirichletZ_) GetOStream(
Runtime0) <<
"Dirichlet boundaries in the z direction"<<std::endl;
180 RCP<MultiVector_d> overlappedCoords = coords;
181 RCP<const Import> importer = ImportFactory::Build(coords->getMap(), colMap);
182 if (!importer.is_null()) {
183 overlappedCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LO,GO,NO>::Build(colMap, coords->getNumVectors());
184 overlappedCoords->doImport(*coords, *importer, Xpetra::INSERT);
189 Setup(comm, overlappedCoords, colMap);
191 GetOStream(
Runtime0) <<
"Using brick size: " << bx_
192 << (nDim_ > 1 ?
"x " +
toString(by_) :
"")
193 << (nDim_ > 2 ?
"x " +
toString(bz_) :
"") << std::endl;
196 RCP<Aggregates> aggregates = rcp(
new Aggregates(colMap));
197 aggregates->setObjectLabel(
"Brick");
199 ArrayRCP<LO> vertex2AggId = aggregates->GetVertex2AggId()->getDataNonConst(0);
200 ArrayRCP<LO> procWinner = aggregates->GetProcWinner() ->getDataNonConst(0);
209 std::set<GO> myAggGIDs, remoteAggGIDs;
210 for (LO LID = 0; LID < numPoints; LID++) {
211 GO aggGID = getAggGID(LID);
213 if(aggGID == GO_INVALID)
continue;
216 if ((revMap_.find(getRoot(LID)) != revMap_.end()) && rowMap->isNodeGlobalElement(colMap->getGlobalElement(revMap_[getRoot(LID)]))) {
218 vertex2AggId[LID] = aggGID;
219 myAggGIDs.insert(aggGID);
222 aggregates->SetIsRoot(LID);
225 remoteAggGIDs.insert(aggGID);
228 size_t numAggregates = myAggGIDs .size();
229 size_t numRemote = remoteAggGIDs.size();
230 aggregates->SetNumAggregates(numAggregates);
232 std::map<GO,LO> AggG2L;
233 std::map<GO,int> AggG2R;
235 Array<GO> myAggGIDsArray(numAggregates), remoteAggGIDsArray(numRemote);
239 for (
typename std::set<GO>::const_iterator it = myAggGIDs.begin(); it != myAggGIDs.end(); it++) {
241 AggG2R[*it] = myRank;
243 myAggGIDsArray[ind++] = *it;
247 RCP<Map> aggMap = MapFactory::Build(rowMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(),
248 myAggGIDsArray, 0, comm);
251 for (
typename std::set<GO>::const_iterator it = remoteAggGIDs.begin(); it != remoteAggGIDs.end(); it++)
252 remoteAggGIDsArray[ind++] = *it;
255 Array<int> remoteProcIDs(numRemote);
256 Array<LO> remoteLIDs (numRemote);
257 aggMap->getRemoteIndexList(remoteAggGIDsArray, remoteProcIDs, remoteLIDs);
260 for (
size_t i = 0; i < numRemote; i++) {
261 AggG2L[remoteAggGIDsArray[i]] = remoteLIDs [i];
262 AggG2R[remoteAggGIDsArray[i]] = remoteProcIDs[i];
266 for (LO LID = 0; LID < numPoints; LID++) {
267 if (revMap_.find(getRoot(LID)) != revMap_.end() && rowMap->isNodeGlobalElement(colMap->getGlobalElement(revMap_[getRoot(LID)]))) {
268 GO aggGID = vertex2AggId[LID];
270 vertex2AggId[LID] = AggG2L[aggGID];
271 procWinner [LID] = AggG2R[aggGID];
279 aggregates->AggregatesCrossProcessors(numGlobalRemote);
281 Set(currentLevel,
"Aggregates", aggregates);
283 GetOStream(
Statistics1) << aggregates->description() << std::endl;
288 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>& )
const {
289 nDim_ = coords->getNumVectors();
291 x_ = coords->getData(0);
292 xMap_ = Construct1DMap(comm, x_);
297 y_ = coords->getData(1);
298 yMap_ = Construct1DMap(comm, y_);
304 z_ = coords->getData(2);
305 zMap_ = Construct1DMap(comm, z_);
309 for (
size_t ind = 0; ind < coords->getLocalLength(); ind++) {
310 GO i = (*xMap_)[(coords->getData(0))[ind]], j = 0, k = 0;
312 j = (*yMap_)[(coords->getData(1))[ind]];
314 k = (*zMap_)[(coords->getData(2))[ind]];
316 revMap_[k*ny_*nx_ + j*nx_ + i] = ind;
321 int xboost = dirichletX_ ? 1 : 0;
322 int yboost = dirichletY_ ? 1 : 0;
323 int zboost = dirichletZ_ ? 1 : 0;
324 naggx_ = (nx_-2*xboost)/bx_ + ((nx_-2*xboost) % bx_ ? 1 : 0);
327 naggy_ = (ny_-2*yboost)/by_ + ( (ny_-2*yboost) % by_ ? 1 : 0);
332 naggz_ = (nz_-2*zboost)/bz_ + ( (nz_-2*zboost) % bz_ ? 1 : 0);
342 const ArrayRCP<
const typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& x)
const
347 RCP<container> gMap = rcp(
new container);
348 for (
int i = 0; i < n; i++)
355 int numProcs = comm->getSize();
357 RCP<const Teuchos::MpiComm<int> > dupMpiComm = rcp_dynamic_cast<const Teuchos::MpiComm<int> >(comm->duplicate());
359 MPI_Comm rawComm = (*dupMpiComm->getRawMpiComm())();
361 int sendCnt = gMap->size(), cnt = 0, recvSize;
362 Array<int> recvCnt(numProcs), Displs(numProcs);
363 Array<double> sendBuf, recvBuf;
365 sendBuf.resize(sendCnt);
366 for (
typename container::const_iterator cit = gMap->begin(); cit != gMap->end(); cit++)
367 sendBuf[cnt++] = Teuchos::as<double>(STS::real(cit->first));
369 MPI_Allgather(&sendCnt, 1, MPI_INT, recvCnt.getRawPtr(), 1, MPI_INT, rawComm);
371 for (
int i = 0; i < numProcs-1; i++)
372 Displs[i+1] = Displs[i] + recvCnt[i];
373 recvSize = Displs[numProcs-1] + recvCnt[numProcs-1];
374 recvBuf.resize(recvSize);
375 MPI_Allgatherv(sendBuf.getRawPtr(), sendCnt, MPI_DOUBLE, recvBuf.getRawPtr(), recvCnt.getRawPtr(), Displs.getRawPtr(), MPI_DOUBLE, rawComm);
377 for (
int i = 0; i < recvSize; i++)
378 (*gMap)[as<SC>(recvBuf[i])] = 0;
383 for (
typename container::iterator it = gMap->begin(); it != gMap->end(); it++)