93 RCP<Matrix> A = Get<RCP<Matrix> >(fineLevel,
"A");
94 RCP<MultiVector> fineNullspace = Get<RCP<MultiVector> >(fineLevel,
"Nullspace");
97 const ParameterList& pL = GetParameterList();
98 LO CoarsenRate = as<LO>(pL.get<
int>(
"semicoarsen: coarsen rate"));
99 bool buildRestriction = pL.get<
bool>(
"semicoarsen: calculate nonsym restriction");
100 bool doLinear = pL.get<
bool>(
"semicoarsen: piecewise linear");
103 LO BlkSize = A->GetFixedBlockSize();
104 RCP<const Map> rowMap = A->getRowMap();
105 LO Ndofs = rowMap->getLocalNumElements();
106 LO Nnodes = Ndofs / BlkSize;
109 LO FineNumZLayers = Get<LO>(fineLevel,
"CoarseNumZLayers");
110 Teuchos::ArrayRCP<LO> TVertLineId = Get<Teuchos::ArrayRCP<LO> >(fineLevel,
"LineDetection_VertLineIds");
111 Teuchos::ArrayRCP<LO> TLayerId = Get<Teuchos::ArrayRCP<LO> >(fineLevel,
"LineDetection_Layers");
112 LO* VertLineId = TVertLineId.getRawPtr();
113 LO* LayerId = TLayerId.getRawPtr();
116 RCP<const Map> theCoarseMap;
118 RCP<MultiVector> coarseNullspace;
119 GO Ncoarse = MakeSemiCoarsenP(Nnodes, FineNumZLayers, CoarsenRate, LayerId, VertLineId,
120 BlkSize, A, P, theCoarseMap, fineNullspace, coarseNullspace, R, buildRestriction, doLinear);
123 if (A->IsView(
"stridedMaps") ==
true)
124 P->CreateView(
"stridedMaps", A->getRowMap(
"stridedMaps"), theCoarseMap);
126 P->CreateView(
"stridedMaps", P->getRangeMap(), theCoarseMap);
128 if (buildRestriction) {
129 if (A->IsView(
"stridedMaps") ==
true)
130 R->CreateView(
"stridedMaps", theCoarseMap, A->getRowMap(
"stridedMaps"));
132 R->CreateView(
"stridedMaps", theCoarseMap, R->getDomainMap());
134 if (pL.get<
bool>(
"semicoarsen: piecewise constant")) {
135 TEUCHOS_TEST_FOR_EXCEPTION(buildRestriction,
Exceptions::RuntimeError,
"Cannot use calculate nonsym restriction with piecewise constant.");
136 RevertToPieceWiseConstant(P, BlkSize);
138 if (pL.get<
bool>(
"semicoarsen: piecewise linear")) {
139 TEUCHOS_TEST_FOR_EXCEPTION(buildRestriction,
Exceptions::RuntimeError,
"Cannot use calculate nonsym restriction with piecewise linear.");
140 TEUCHOS_TEST_FOR_EXCEPTION(pL.get<
bool>(
"semicoarsen: piecewise constant"),
Exceptions::RuntimeError,
"Cannot use piecewise constant with piecewise linear.");
147 LO CoarseNumZLayers = FineNumZLayers * Ncoarse;
148 CoarseNumZLayers /= Ndofs;
152 Set(coarseLevel,
"P", P);
153 if (buildRestriction) Set(coarseLevel,
"RfromPfactory", R);
155 Set(coarseLevel,
"Nullspace", coarseNullspace);
158 if (bTransferCoordinates_) {
159 typedef Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::coordinateType, LO, GO, NO> xdMV;
160 RCP<xdMV> fineCoords = Teuchos::null;
165 RCP<const FactoryBase> myCoordsFact = GetFactory(
"Coordinates");
166 if (myCoordsFact == Teuchos::null) {
169 if (fineLevel.
IsAvailable(
"Coordinates", myCoordsFact.get())) {
170 fineCoords = fineLevel.
Get<RCP<xdMV> >(
"Coordinates", myCoordsFact.get());
174 TEUCHOS_TEST_FOR_EXCEPTION(fineCoords == Teuchos::null,
Exceptions::RuntimeError,
"No Coordinates found provided by the user.");
176 TEUCHOS_TEST_FOR_EXCEPTION(fineCoords->getNumVectors() != 3,
Exceptions::RuntimeError,
"Three coordinates arrays must be supplied if line detection orientation not given.");
177 ArrayRCP<typename Teuchos::ScalarTraits<Scalar>::coordinateType> x = fineCoords->getDataNonConst(0);
178 ArrayRCP<typename Teuchos::ScalarTraits<Scalar>::coordinateType> y = fineCoords->getDataNonConst(1);
179 ArrayRCP<typename Teuchos::ScalarTraits<Scalar>::coordinateType> z = fineCoords->getDataNonConst(2);
182 typename Teuchos::ScalarTraits<Scalar>::coordinateType zval_max = -Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<Scalar>::coordinateType>::one() / Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<Scalar>::coordinateType>::sfmin();
183 typename Teuchos::ScalarTraits<Scalar>::coordinateType zval_min = Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<Scalar>::coordinateType>::one() / Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<Scalar>::coordinateType>::sfmin();
184 for (
auto it = z.begin(); it != z.end(); ++it) {
185 if (*it > zval_max) zval_max = *it;
186 if (*it < zval_min) zval_min = *it;
189 LO myCoarseZLayers = Teuchos::as<LO>(CoarseNumZLayers);
191 ArrayRCP<typename Teuchos::ScalarTraits<Scalar>::coordinateType> myZLayerCoords = Teuchos::arcp<typename Teuchos::ScalarTraits<Scalar>::coordinateType>(myCoarseZLayers);
192 if (myCoarseZLayers == 1) {
193 myZLayerCoords[0] = zval_min;
195 typename Teuchos::ScalarTraits<Scalar>::coordinateType dz = (zval_max - zval_min) / (myCoarseZLayers - 1);
196 for (LO k = 0; k < myCoarseZLayers; ++k) {
197 myZLayerCoords[k] = k * dz;
205 LO numVertLines = Nnodes / FineNumZLayers;
206 LO numLocalCoarseNodes = numVertLines * myCoarseZLayers;
208 RCP<const Map> coarseCoordMap =
209 MapFactory::Build(fineCoords->getMap()->lib(),
210 Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(),
211 Teuchos::as<size_t>(numLocalCoarseNodes),
212 fineCoords->getMap()->getIndexBase(),
213 fineCoords->getMap()->getComm());
214 RCP<xdMV> coarseCoords = Xpetra::MultiVectorFactory<typename Teuchos::ScalarTraits<Scalar>::coordinateType, LO, GO, NO>::Build(coarseCoordMap, fineCoords->getNumVectors());
215 coarseCoords->putScalar(-1.0);
216 ArrayRCP<typename Teuchos::ScalarTraits<Scalar>::coordinateType> cx = coarseCoords->getDataNonConst(0);
217 ArrayRCP<typename Teuchos::ScalarTraits<Scalar>::coordinateType> cy = coarseCoords->getDataNonConst(1);
218 ArrayRCP<typename Teuchos::ScalarTraits<Scalar>::coordinateType> cz = coarseCoords->getDataNonConst(2);
221 LO cntCoarseNodes = 0;
222 for (LO vt = 0; vt < TVertLineId.size(); ++vt) {
224 LO curVertLineId = TVertLineId[vt];
226 if (cx[curVertLineId * myCoarseZLayers] == -1.0 &&
227 cy[curVertLineId * myCoarseZLayers] == -1.0) {
229 for (LO n = 0; n < myCoarseZLayers; ++n) {
230 cx[curVertLineId * myCoarseZLayers + n] = x[vt];
231 cy[curVertLineId * myCoarseZLayers + n] = y[vt];
232 cz[curVertLineId * myCoarseZLayers + n] = myZLayerCoords[n];
234 cntCoarseNodes += myCoarseZLayers;
237 TEUCHOS_TEST_FOR_EXCEPTION(cntCoarseNodes > numLocalCoarseNodes,
Exceptions::RuntimeError,
"number of coarse nodes is inconsistent.");
238 if (cntCoarseNodes == numLocalCoarseNodes)
break;
242 Set(coarseLevel,
"Coordinates", coarseCoords);
305 MakeSemiCoarsenP(LO
const Ntotal, LO
const nz, LO
const CoarsenRate, LO
const LayerId[],
306 LO
const VertLineId[], LO
const DofsPerNode, RCP<Matrix>& Amat, RCP<Matrix>& P,
307 RCP<const Map>& coarseMap,
const RCP<MultiVector> fineNullspace,
308 RCP<MultiVector>& coarseNullspace, RCP<Matrix>& R,
bool buildRestriction,
bool doLinear)
const {
359 int NLayers, NVertLines, MaxNnz, NCLayers, MyLine, MyLayer;
360 int *InvLineLayer = NULL, *CptLayers = NULL, StartLayer, NStencilNodes;
361 int BlkRow = -1, dof_j, node_k, *Sub2FullMap = NULL, RowLeng;
362 int i, j, iii, col, count, index, loc, PtRow, PtCol;
363 SC *BandSol = NULL, *BandMat = NULL, TheSum, *RestrictBandMat = NULL, *RestrictBandSol = NULL;
364 int *IPIV = NULL, KL, KU, KLU, N, NRHS, LDAB, INFO;
371 int MaxStencilSize, MaxNnzPerRow;
373 int CurRow, LastGuy = -1, NewPtr, RLastGuy = -1;
376 LO *Layerdofs = NULL, *Col2Dof = NULL;
378 Teuchos::LAPACK<LO, SC> lapack;
388 Teuchos::ArrayRCP<LO> TLayDiff = Teuchos::arcp<LO>(1 + MaxNnzPerRow);
389 LayDiff = TLayDiff.getRawPtr();
391 Nghost = Amat->getColMap()->getLocalNumElements() - Amat->getDomainMap()->getLocalNumElements();
392 if (Nghost < 0) Nghost = 0;
393 Teuchos::ArrayRCP<LO> TLayerdofs = Teuchos::arcp<LO>(Ntotal * DofsPerNode + Nghost + 1);
394 Layerdofs = TLayerdofs.getRawPtr();
395 Teuchos::ArrayRCP<LO> TCol2Dof = Teuchos::arcp<LO>(Ntotal * DofsPerNode + Nghost + 1);
396 Col2Dof = TCol2Dof.getRawPtr();
398 RCP<Xpetra::Vector<LO, LO, GO, NO> > localdtemp = Xpetra::VectorFactory<LO, LO, GO, NO>::Build(Amat->getDomainMap());
399 RCP<Xpetra::Vector<LO, LO, GO, NO> > dtemp = Xpetra::VectorFactory<LO, LO, GO, NO>::Build(Amat->getColMap());
400 ArrayRCP<LO> valptr = localdtemp->getDataNonConst(0);
402 for (i = 0; i < Ntotal * DofsPerNode; i++)
403 valptr[i] = LayerId[i / DofsPerNode];
404 valptr = ArrayRCP<LO>();
406 RCP<const Import> importer;
407 importer = Amat->getCrsGraph()->getImporter();
408 if (importer == Teuchos::null) {
409 importer = ImportFactory::Build(Amat->getDomainMap(), Amat->getColMap());
411 dtemp->doImport(*localdtemp, *(importer), Xpetra::INSERT);
413 valptr = dtemp->getDataNonConst(0);
414 for (i = 0; i < Ntotal * DofsPerNode + Nghost; i++) Layerdofs[i] = valptr[i];
415 valptr = localdtemp->getDataNonConst(0);
416 for (i = 0; i < Ntotal * DofsPerNode; i++) valptr[i] = i % DofsPerNode;
417 valptr = ArrayRCP<LO>();
418 dtemp->doImport(*localdtemp, *(importer), Xpetra::INSERT);
420 valptr = dtemp->getDataNonConst(0);
421 for (i = 0; i < Ntotal * DofsPerNode + Nghost; i++) Col2Dof[i] = valptr[i];
422 valptr = ArrayRCP<LO>();
425 NLayers = LayerId[0];
426 NVertLines = VertLineId[0];
432 for (i = 1; i < Ntotal; i++) {
433 if (VertLineId[i] > NVertLines) NVertLines = VertLineId[i];
434 if (LayerId[i] > NLayers) NLayers = LayerId[i];
444 Teuchos::ArrayRCP<LO> TInvLineLayer = Teuchos::arcp<LO>(1 + NVertLines * NLayers);
445 InvLineLayer = TInvLineLayer.getRawPtr();
446 for (i = 0; i < Ntotal; i++) {
447 InvLineLayer[VertLineId[i] + 1 + LayerId[i] * NVertLines] = i;
454 Teuchos::ArrayRCP<LO> TCptLayers = Teuchos::arcp<LO>(nz + 1);
455 CptLayers = TCptLayers.getRawPtr();
456 NCLayers = FindCpts(nz, CoarsenRate, 0, &CptLayers);
468 MaxStencilSize = CptLayers[2];
470 for (i = 3; i <= NCLayers; i++) {
471 if (MaxStencilSize < CptLayers[i] - CptLayers[i - 2])
472 MaxStencilSize = CptLayers[i] - CptLayers[i - 2];
475 if (MaxStencilSize < nz - CptLayers[NCLayers - 1] + 1)
476 MaxStencilSize = nz - CptLayers[NCLayers - 1] + 1;
486 Teuchos::ArrayRCP<LO> TSub2FullMap = Teuchos::arcp<LO>((MaxStencilSize + 1) * DofsPerNode);
487 Sub2FullMap = TSub2FullMap.getRawPtr();
488 Teuchos::ArrayRCP<SC> TBandSol = Teuchos::arcp<SC>((MaxStencilSize + 1) * DofsPerNode * DofsPerNode);
489 BandSol = TBandSol.getRawPtr();
490 Teuchos::ArrayRCP<SC> TResBandSol;
491 if (buildRestriction) {
492 TResBandSol = Teuchos::arcp<SC>((MaxStencilSize + 1) * DofsPerNode * DofsPerNode);
493 RestrictBandSol = TResBandSol.getRawPtr();
498 KL = 2 * DofsPerNode - 1;
499 KU = 2 * DofsPerNode - 1;
501 LDAB = 2 * KL + KU + 1;
503 Teuchos::ArrayRCP<SC> TBandMat = Teuchos::arcp<SC>(LDAB * MaxStencilSize * DofsPerNode + 1);
504 BandMat = TBandMat.getRawPtr();
505 Teuchos::ArrayRCP<LO> TIPIV = Teuchos::arcp<LO>((MaxStencilSize + 1) * DofsPerNode);
506 IPIV = TIPIV.getRawPtr();
508 Teuchos::ArrayRCP<SC> TResBandMat;
509 if (buildRestriction) {
510 TResBandMat = Teuchos::arcp<SC>(LDAB * MaxStencilSize * DofsPerNode + 1);
511 RestrictBandMat = TResBandMat.getRawPtr();
521 Ndofs = DofsPerNode * Ntotal;
522 MaxNnz = 2 * DofsPerNode * Ndofs;
524 RCP<const Map> rowMap = Amat->getRowMap();
525 Xpetra::global_size_t GNdofs = rowMap->getGlobalNumElements();
527 std::vector<size_t> stridingInfo_;
528 stridingInfo_.push_back(DofsPerNode);
530 Xpetra::global_size_t itemp = GNdofs / nz;
531 coarseMap = StridedMapFactory::Build(rowMap->lib(),
533 NCLayers * NVertLines * DofsPerNode,
542 P = rcp(
new CrsMatrixWrap(rowMap, coarseMap, 0));
543 coarseNullspace = MultiVectorFactory::Build(coarseMap, fineNullspace->getNumVectors());
545 Teuchos::ArrayRCP<SC> TPvals = Teuchos::arcp<SC>(1 + MaxNnz);
546 Pvals = TPvals.getRawPtr();
547 Teuchos::ArrayRCP<size_t> TPptr = Teuchos::arcp<size_t>(DofsPerNode * (2 + Ntotal));
548 Pptr = TPptr.getRawPtr();
549 Teuchos::ArrayRCP<LO> TPcols = Teuchos::arcp<LO>(1 + MaxNnz);
550 Pcols = TPcols.getRawPtr();
556 Teuchos::ArrayRCP<SC> TRvals;
557 Teuchos::ArrayRCP<size_t> TRptr;
558 Teuchos::ArrayRCP<LO> TRcols;
559 LO RmaxNnz = -1, RmaxPerRow = -1;
560 if (buildRestriction) {
561 RmaxPerRow = ((LO)ceil(((
double)(MaxNnz + 7)) / ((double)(coarseMap->getLocalNumElements()))));
562 RmaxNnz = RmaxPerRow * coarseMap->getLocalNumElements();
563 TRvals = Teuchos::arcp<SC>(1 + RmaxNnz);
564 Rvals = TRvals.getRawPtr();
565 TRptr = Teuchos::arcp<size_t>((2 + coarseMap->getLocalNumElements()));
566 Rptr = TRptr.getRawPtr();
567 TRcols = Teuchos::arcp<LO>(1 + RmaxNnz);
568 Rcols = TRcols.getRawPtr();
579 for (i = 1; i <= MaxNnz; i++) Pcols[i] = -1;
581 for (i = 1; i <= DofsPerNode * Ntotal + 1; i++) {
583 count += (2 * DofsPerNode);
585 if (buildRestriction) {
586 for (i = 1; i <= RmaxNnz; i++) Rcols[i] = -1;
588 for (i = 1; i <= (int)(coarseMap->getLocalNumElements() + 1); i++) {
602 for (MyLine = 1; MyLine <= NVertLines; MyLine += 1) {
603 for (iii = 1; iii <= NCLayers; iii += 1) {
605 MyLayer = CptLayers[iii];
619 StartLayer = CptLayers[iii - 1] + 1;
624 NStencilNodes = CptLayers[iii + 1] - StartLayer;
626 NStencilNodes = NLayers - StartLayer + 1;
628 N = NStencilNodes * DofsPerNode;
635 for (i = 0; i < NStencilNodes * DofsPerNode * DofsPerNode; i++) BandSol[i] = 0.0;
636 for (i = 0; i < LDAB * N; i++) BandMat[i] = 0.0;
637 if (buildRestriction) {
638 for (i = 0; i < NStencilNodes * DofsPerNode * DofsPerNode; i++) RestrictBandSol[i] = 0.0;
639 for (i = 0; i < LDAB * N; i++) RestrictBandMat[i] = 0.0;
648 for (node_k = 1; node_k <= NStencilNodes; node_k++) {
653 BlkRow = InvLineLayer[MyLine + (StartLayer + node_k - 2) * NVertLines] + 1;
654 Sub2FullMap[node_k] = BlkRow;
667 for (
int dof_i = 0; dof_i < DofsPerNode; dof_i++) {
668 j = (BlkRow - 1) * DofsPerNode + dof_i;
669 ArrayView<const LO> AAcols;
670 ArrayView<const SC> AAvals;
671 Amat->getLocalRowView(j, AAcols, AAvals);
672 const int* Acols = AAcols.getRawPtr();
673 const SC* Avals = AAvals.getRawPtr();
674 RowLeng = AAvals.size();
676 TEUCHOS_TEST_FOR_EXCEPTION(RowLeng >= MaxNnzPerRow,
Exceptions::RuntimeError,
"MakeSemiCoarsenP: recompile with larger Max(HorNeighborNodes)\n");
678 for (i = 0; i < RowLeng; i++) {
679 LayDiff[i] = Layerdofs[Acols[i]] - StartLayer - node_k + 2;
687 PtRow = (node_k - 1) * DofsPerNode + dof_i + 1;
688 for (dof_j = 0; dof_j < DofsPerNode; dof_j++) {
689 PtCol = (node_k - 1) * DofsPerNode + dof_j + 1;
693 for (i = 0; i < RowLeng; i++) {
694 if ((LayDiff[i] == 0) && (Col2Dof[Acols[i]] == dof_j))
697 index = LDAB * (PtCol - 1) + KLU + PtRow - PtCol;
698 BandMat[index] = TheSum;
699 if (buildRestriction) RestrictBandMat[index] = TheSum;
700 if (node_k != NStencilNodes) {
704 for (i = 0; i < RowLeng; i++) {
705 if ((LayDiff[i] == 1) && (Col2Dof[Acols[i]] == dof_j))
708 j = PtCol + DofsPerNode;
709 index = LDAB * (j - 1) + KLU + PtRow - j;
710 BandMat[index] = TheSum;
711 if (buildRestriction) RestrictBandMat[index] = TheSum;
717 for (i = 0; i < RowLeng; i++) {
718 if ((LayDiff[i] == -1) && (Col2Dof[Acols[i]] == dof_j))
721 j = PtCol - DofsPerNode;
722 index = LDAB * (j - 1) + KLU + PtRow - j;
723 BandMat[index] = TheSum;
724 if (buildRestriction) RestrictBandMat[index] = TheSum;
729 node_k = MyLayer - StartLayer + 1;
730 for (
int dof_i = 0; dof_i < DofsPerNode; dof_i++) {
733 PtRow = (node_k - 1) * DofsPerNode + dof_i + 1;
734 BandSol[(dof_i)*DofsPerNode * NStencilNodes + PtRow - 1] = 1.;
735 if (buildRestriction) RestrictBandSol[(dof_i)*DofsPerNode * NStencilNodes + PtRow - 1] = 1.;
737 for (dof_j = 0; dof_j < DofsPerNode; dof_j++) {
738 PtCol = (node_k - 1) * DofsPerNode + dof_j + 1;
739 index = LDAB * (PtCol - 1) + KLU + PtRow - PtCol;
741 BandMat[index] = 1.0;
743 BandMat[index] = 0.0;
744 if (buildRestriction) {
745 index = LDAB * (PtRow - 1) + KLU + PtCol - PtRow;
747 RestrictBandMat[index] = 1.0;
749 RestrictBandMat[index] = 0.0;
751 if (node_k != NStencilNodes) {
752 PtCol = (node_k)*DofsPerNode + dof_j + 1;
753 index = LDAB * (PtCol - 1) + KLU + PtRow - PtCol;
754 BandMat[index] = 0.0;
755 if (buildRestriction) {
756 index = LDAB * (PtRow - 1) + KLU + PtCol - PtRow;
757 RestrictBandMat[index] = 0.0;
761 PtCol = (node_k - 2) * DofsPerNode + dof_j + 1;
762 index = LDAB * (PtCol - 1) + KLU + PtRow - PtCol;
763 BandMat[index] = 0.0;
764 if (buildRestriction) {
765 index = LDAB * (PtRow - 1) + KLU + PtCol - PtRow;
766 RestrictBandMat[index] = 0.0;
774 lapack.GBTRF(N, N, KL, KU, BandMat, LDAB, IPIV, &INFO);
778 lapack.GBTRS(notrans[0], N, KL, KU, NRHS, BandMat, LDAB, IPIV,
783 for (dof_j = 0; dof_j < DofsPerNode; dof_j++) {
784 for (
int dof_i = 0; dof_i < DofsPerNode; dof_i++) {
785 for (i = 1; i <= NStencilNodes; i++) {
786 index = (Sub2FullMap[i] - 1) * DofsPerNode + dof_i + 1;
788 Pcols[loc] = (col - 1) * DofsPerNode + dof_j + 1;
789 Pvals[loc] = BandSol[dof_j * DofsPerNode * NStencilNodes +
790 (i - 1) * DofsPerNode + dof_i];
791 Pptr[index] = Pptr[index] + 1;
795 if (buildRestriction) {
796 lapack.GBTRF(N, N, KL, KU, RestrictBandMat, LDAB, IPIV, &INFO);
798 lapack.GBTRS(trans[0], N, KL, KU, NRHS, RestrictBandMat, LDAB, IPIV, RestrictBandSol, N, &INFO);
800 for (dof_j = 0; dof_j < DofsPerNode; dof_j++) {
801 for (
int dof_i = 0; dof_i < DofsPerNode; dof_i++) {
802 for (i = 1; i <= NStencilNodes; i++) {
803 index = (col - 1) * DofsPerNode + dof_j + 1;
805 Rcols[loc] = (Sub2FullMap[i] - 1) * DofsPerNode + dof_i + 1;
806 Rvals[loc] = RestrictBandSol[dof_j * DofsPerNode * NStencilNodes +
807 (i - 1) * DofsPerNode + dof_i];
808 Rptr[index] = Rptr[index] + 1;
814 int denom1 = MyLayer - StartLayer + 1;
815 int denom2 = StartLayer + NStencilNodes - MyLayer;
816 for (
int dof_i = 0; dof_i < DofsPerNode; dof_i++) {
817 for (i = 1; i <= NStencilNodes; i++) {
818 index = (InvLineLayer[MyLine + (StartLayer + i - 2) * NVertLines]) * DofsPerNode + dof_i + 1;
820 Pcols[loc] = (col - 1) * DofsPerNode + dof_i + 1;
822 Pvals[loc] = 1.0 + ((double)(denom1 - i)) / ((
double)denom2);
824 Pvals[loc] = ((double)(i)) / ((
double)denom1);
825 Pptr[index] = Pptr[index] + 1;
833 BlkRow = InvLineLayer[MyLine + (MyLayer - 1) * NVertLines] + 1;
834 for (
int k = 0; k < static_cast<int>(fineNullspace->getNumVectors()); k++) {
835 Teuchos::ArrayRCP<SC> OneCNull = coarseNullspace->getDataNonConst(k);
836 Teuchos::ArrayRCP<SC> OneFNull = fineNullspace->getDataNonConst(k);
837 for (
int dof_i = 0; dof_i < DofsPerNode; dof_i++) {
838 OneCNull[(col - 1) * DofsPerNode + dof_i] = OneFNull[(BlkRow - 1) * DofsPerNode + dof_i];
853 for (
size_t ii = 1; ii <= Pptr[Ntotal * DofsPerNode] - 1; ii++) {
854 if (ii == Pptr[CurRow]) {
855 Pptr[CurRow] = LastGuy;
857 while (ii > Pptr[CurRow]) {
858 Pptr[CurRow] = LastGuy;
862 if (Pcols[ii] != -1) {
863 Pcols[NewPtr - 1] = Pcols[ii] - 1;
864 Pvals[NewPtr - 1] = Pvals[ii];
869 for (i = CurRow; i <= Ntotal * DofsPerNode; i++) Pptr[CurRow] = LastGuy;
874 for (i = -Ntotal * DofsPerNode + 1; i >= 2; i--) {
875 Pptr[i - 1] = Pptr[i - 2];
880 if (buildRestriction) {
883 for (
size_t ii = 1; ii <= Rptr[coarseMap->getLocalNumElements()] - 1; ii++) {
884 if (ii == Rptr[CurRow]) {
885 Rptr[CurRow] = RLastGuy;
887 while (ii > Rptr[CurRow]) {
888 Rptr[CurRow] = RLastGuy;
892 if (Rcols[ii] != -1) {
893 Rcols[NewPtr - 1] = Rcols[ii] - 1;
894 Rvals[NewPtr - 1] = Rvals[ii];
899 for (i = CurRow; i <= ((int)coarseMap->getLocalNumElements()); i++) Rptr[CurRow] = RLastGuy;
900 for (i = -coarseMap->getLocalNumElements() + 1; i >= 2; i--) {
901 Rptr[i - 1] = Rptr[i - 2];
905 ArrayRCP<size_t> rcpRowPtr;
906 ArrayRCP<LO> rcpColumns;
907 ArrayRCP<SC> rcpValues;
909 RCP<CrsMatrix> PCrs = toCrsMatrix(P);
910 LO nnz = Pptr[Ndofs];
911 PCrs->allocateAllValues(nnz, rcpRowPtr, rcpColumns, rcpValues);
913 ArrayView<size_t> rowPtr = rcpRowPtr();
914 ArrayView<LO> columns = rcpColumns();
915 ArrayView<SC> values = rcpValues();
919 for (LO ii = 0; ii <= Ndofs; ii++) rowPtr[ii] = Pptr[ii];
920 for (LO ii = 0; ii < nnz; ii++) columns[ii] = Pcols[ii];
921 for (LO ii = 0; ii < nnz; ii++) values[ii] = Pvals[ii];
922 PCrs->setAllValues(rcpRowPtr, rcpColumns, rcpValues);
923 PCrs->expertStaticFillComplete(coarseMap, Amat->getDomainMap());
924 ArrayRCP<size_t> RrcpRowPtr;
925 ArrayRCP<LO> RrcpColumns;
926 ArrayRCP<SC> RrcpValues;
928 if (buildRestriction) {
929 R = rcp(
new CrsMatrixWrap(coarseMap, rowMap, 0));
930 RCrs = toCrsMatrix(R);
931 nnz = Rptr[coarseMap->getLocalNumElements()];
932 RCrs->allocateAllValues(nnz, RrcpRowPtr, RrcpColumns, RrcpValues);
934 ArrayView<size_t> RrowPtr = RrcpRowPtr();
935 ArrayView<LO> Rcolumns = RrcpColumns();
936 ArrayView<SC> Rvalues = RrcpValues();
940 for (LO ii = 0; ii <= ((LO)coarseMap->getLocalNumElements()); ii++) RrowPtr[ii] = Rptr[ii];
941 for (LO ii = 0; ii < nnz; ii++) Rcolumns[ii] = Rcols[ii];
942 for (LO ii = 0; ii < nnz; ii++) Rvalues[ii] = Rvals[ii];
943 RCrs->setAllValues(RrcpRowPtr, RrcpColumns, RrcpValues);
944 RCrs->expertStaticFillComplete(Amat->getRangeMap(), coarseMap);
947 return NCLayers * NVertLines * DofsPerNode;