| 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 |
//#include <Tpetra_CrsMatrix_decl.hpp> |
| 11 |
//#include <Teuchos_RCPDecl.hpp> |
| 12 |
|
| 13 |
#include "coloring.hpp" |
| 14 |
|
| 15 |
typedef Tpetra::CrsMatrix<double, int, int, KokkosClassic::DefaultNode::DefaultNodeType> tpetra_matrix_type; |
| 16 |
typedef Tpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, int, int, KokkosClassic::DefaultNode::DefaultNodeType> tpetra_multivector_type; |
| 17 |
typedef typename Teuchos::ArrayView<const int>::const_iterator iterator_type; |
| 18 |
typedef Tpetra::KokkosClassic::DefaultNode::DefaultNodeType node_type2; |
| 19 |
|
| 20 |
void neighbours1D(Teuchos::RCP<tpetra_matrix_type> tpetra_prolong, std::vector<int>& neighbours, Teuchos::RCP<const Teuchos::Comm<int> > comm) { |
| 21 |
// INPUT: tpetra_prolong is the tentative prolongator, here it is just used to get the Total number of aggregates given by the nubmer of columns |
| 22 |
// INPUT: neighoubrs is a vector where the neoghbours of the current MPI processor (=subdomain) are stored |
| 23 |
// INPUT: comm = MPI communicator (MPI_COMM_WORLD) |
| 24 |
|
| 25 |
neighbours.clear(); |
| 26 |
|
| 27 |
int mypid = comm->getRank(); |
| 28 |
|
| 29 |
for (int color = 0; color < 3; ++color) { |
| 30 |
if ((mypid - 1) % 3 == color && (mypid - 1) >= 0 && (mypid - 1) < tpetra_prolong->getGlobalNumCols()) |
| 31 |
neighbours.emplace_back(mypid - 1); |
| 32 |
else if ((mypid - 2) % 3 == color && (mypid - 2) >= 0 && (mypid - 2) < tpetra_prolong->getGlobalNumCols()) |
| 33 |
neighbours.emplace_back(mypid - 2); |
| 34 |
else if ((mypid) % 3 == color && (mypid) >= 0 && (mypid) < tpetra_prolong->getGlobalNumCols()) |
| 35 |
neighbours.emplace_back(mypid); |
| 36 |
} |
| 37 |
|
| 38 |
neighbours.shrink_to_fit(); |
| 39 |
} |
| 40 |
|
| 41 |
void neighbours2D(Teuchos::RCP<tpetra_matrix_type> tpetra_prolong, std::vector<int>& neighbours, Teuchos::RCP<const Teuchos::Comm<int> > comm, int ndx) { |
| 42 |
// INPUT: tpetra_prolong is the tentative prolongator, here it is just used to get the Total number of aggregates given by the nubmer of columns |
| 43 |
// INPUT: neighoubrs is a vector where the neoghbours of the current MPI processor (=subdomain) are stored |
| 44 |
// INPUT: comm = MPI communicator (MPI_COMM_WORLD) |
| 45 |
// INPUT: ndx is the number of domains along the x-direction |
| 46 |
|
| 47 |
neighbours.clear(); |
| 48 |
int mypid = comm->getRank(); |
| 49 |
int brick_id = mypid; |
| 50 |
int shifted_id = brick_id - 1; |
| 51 |
|
| 52 |
if (mypid > 0) { |
| 53 |
for (int color = 0; color < 9; ++color) { |
| 54 |
int neighbour = -1; |
| 55 |
|
| 56 |
// The following if statements control the neighbours of a subdomain in a 2D brick partitioned mesh |
| 57 |
// Each subdomains is incorporated in a 3x3 square which is sliced into 3 stripes |
| 58 |
// The neighbours of a subdomain are checked plane by plane: in total there are three planes to span |
| 59 |
// In case the subdomains sit on a boundary, there are missing neighbours for a specific color |
| 60 |
// (this is what the last two conditions of each if statement take care of) |
| 61 |
if (coloring2D(brick_id, ndx) == color && (shifted_id) >= 0 && (shifted_id) < tpetra_prolong->getGlobalNumCols()) |
| 62 |
neighbour = (shifted_id); |
| 63 |
|
| 64 |
else if (coloring2D(brick_id - 1, ndx) == color && (shifted_id - 1) >= 0 && (shifted_id - 1) < tpetra_prolong->getGlobalNumCols()) |
| 65 |
neighbour = (shifted_id - 1); |
| 66 |
|
| 67 |
else if (coloring2D(brick_id + 1, ndx) == color && (shifted_id + 1) >= 0 && (shifted_id + 1) < tpetra_prolong->getGlobalNumCols()) |
| 68 |
neighbour = (shifted_id + 1); |
| 69 |
|
| 70 |
else if (coloring2D(brick_id - ndx, ndx) == color && (shifted_id - ndx) >= 0 && (shifted_id - ndx) < tpetra_prolong->getGlobalNumCols()) |
| 71 |
neighbour = (shifted_id - ndx); |
| 72 |
|
| 73 |
else if (coloring2D(brick_id - ndx - 1, ndx) == color && (shifted_id - ndx - 1) >= 0 && (shifted_id - ndx - 1) < tpetra_prolong->getGlobalNumCols()) |
| 74 |
neighbour = (shifted_id - ndx - 1); |
| 75 |
|
| 76 |
else if (coloring2D(brick_id - ndx + 1, ndx) == color && (shifted_id - ndx + 1) >= 0 && (shifted_id - ndx + 1) < tpetra_prolong->getGlobalNumCols()) |
| 77 |
neighbour = (shifted_id - ndx + 1); |
| 78 |
|
| 79 |
else if (coloring2D(brick_id + ndx, ndx) == color && (shifted_id + ndx) >= 0 && (shifted_id + ndx) < tpetra_prolong->getGlobalNumCols()) |
| 80 |
neighbour = (shifted_id + ndx); |
| 81 |
|
| 82 |
else if (coloring2D(brick_id + ndx - 1, ndx) == color && (shifted_id + ndx - 1) >= 0 && (shifted_id + ndx - 1) < tpetra_prolong->getGlobalNumCols()) |
| 83 |
neighbour = (shifted_id + ndx - 1); |
| 84 |
|
| 85 |
else if (coloring2D(brick_id + ndx + 1, ndx) == color && (shifted_id + ndx + 1) >= 0 && (shifted_id + ndx + 1) < tpetra_prolong->getGlobalNumCols()) |
| 86 |
neighbour = (shifted_id + ndx + 1); |
| 87 |
|
| 88 |
if (neighbour >= 0) |
| 89 |
neighbours.emplace_back(neighbour); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
neighbours.shrink_to_fit(); |
| 94 |
} |
| 95 |
|
| 96 |
void neighbours3D(Teuchos::RCP<tpetra_matrix_type> tpetra_prolong, std::vector<int>& neighbours, Teuchos::RCP<const Teuchos::Comm<int> > comm, int ndx, int ndy) { |
| 97 |
// INPUT: tpetra_prolong is the tentative prolongator, here it is just used to get the Total number of aggregates given by the nubmer of columns |
| 98 |
// INPUT: neighoubrs is a vector where the neoghbours of the current MPI processor (=subdomain) are stored |
| 99 |
// INPUT: comm = MPI communicator (MPI_COMM_WORLD) |
| 100 |
// INPUT: ndx is the number of domains along the x-direction |
| 101 |
// INPUT: ndy is the nubmer of domains along the y-direction |
| 102 |
|
| 103 |
neighbours.clear(); |
| 104 |
int mypid = comm->getRank(); |
| 105 |
int brick_id = mypid; |
| 106 |
int shifted_id = brick_id - 1; |
| 107 |
|
| 108 |
if (mypid > 0) { |
| 109 |
for (int color = 0; color < 27; ++color) { |
| 110 |
int neighbour = -1; |
| 111 |
|
| 112 |
// The following if statements control the neighbours of a subdomain in a 3D brick partitioned mesh |
| 113 |
// Each subdomains is incorporated in a 3x3x3 cube which is sliced into 3 squares living on three different planes |
| 114 |
// The neighbours of a subdomain are checked plane by plane: in total there are three planes to span |
| 115 |
// In case the subdomains sit on a boundary, there are missing neighbours for a specific color |
| 116 |
// (this is what the last two conditions of each if statement take care of) |
| 117 |
// Identification of neighbours that are on the current plane |
| 118 |
if (coloring3D(brick_id, ndx, ndy) == color && (shifted_id) >= 0 && (shifted_id) < tpetra_prolong->getGlobalNumCols()) |
| 119 |
neighbour = (shifted_id); |
| 120 |
else if (coloring3D(brick_id - 1, ndx, ndy) == color && (shifted_id - 1) >= 0 && (shifted_id - 1) < tpetra_prolong->getGlobalNumCols()) |
| 121 |
neighbour = (shifted_id - 1); |
| 122 |
else if (coloring3D(brick_id + 1, ndx, ndy) == color && (shifted_id + 1) >= 0 && (shifted_id + 1) < tpetra_prolong->getGlobalNumCols()) |
| 123 |
neighbour = (shifted_id + 1); |
| 124 |
else if (coloring3D(brick_id - ndx, ndx, ndy) == color && (shifted_id - ndx) >= 0 && (shifted_id - ndx) < tpetra_prolong->getGlobalNumCols()) |
| 125 |
neighbour = (shifted_id - ndx); |
| 126 |
else if (coloring3D(brick_id - ndx - 1, ndx, ndy) == color && (shifted_id - ndx - 1) >= 0 && (shifted_id - ndx - 1) < tpetra_prolong->getGlobalNumCols()) |
| 127 |
neighbour = (shifted_id - ndx - 1); |
| 128 |
else if (coloring3D(brick_id - ndx + 1, ndx, ndy) == color && (shifted_id - ndx + 1) >= 0 && (shifted_id - ndx + 1) < tpetra_prolong->getGlobalNumCols()) |
| 129 |
neighbour = (shifted_id - ndx + 1); |
| 130 |
else if (coloring3D(brick_id + ndx, ndx, ndy) == color && (shifted_id + ndx) >= 0 && (shifted_id + ndx) < tpetra_prolong->getGlobalNumCols()) |
| 131 |
neighbour = (shifted_id + ndx); |
| 132 |
else if (coloring3D(brick_id + ndx - 1, ndx, ndy) == color && (shifted_id + ndx - 1) >= 0 && (shifted_id + ndx - 1) < tpetra_prolong->getGlobalNumCols()) |
| 133 |
neighbour = (shifted_id + ndx - 1); |
| 134 |
else if (coloring3D(brick_id + ndx + 1, ndx, ndy) == color && (shifted_id + ndx + 1) >= 0 && (shifted_id + ndx + 1) < tpetra_prolong->getGlobalNumCols()) |
| 135 |
neighbour = (shifted_id + ndx + 1); |
| 136 |
|
| 137 |
// Identification of the neighbours that are on the plane below |
| 138 |
else if (coloring3D(brick_id - ndx * ndy, ndx, ndy) == color && (shifted_id - ndx * ndy) >= 0 && (shifted_id - ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 139 |
neighbour = (shifted_id - ndx * ndy); |
| 140 |
else if (coloring3D(brick_id - 1 - ndx * ndy, ndx, ndy) == color && (shifted_id - 1 - ndx * ndy) >= 0 && (shifted_id - 1 - ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 141 |
neighbour = (shifted_id - 1 - ndx * ndy); |
| 142 |
else if (coloring3D(brick_id + 1 - ndx * ndy, ndx, ndy) == color && (shifted_id + 1 - ndx * ndy) >= 0 && (shifted_id + 1 - ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 143 |
neighbour = (shifted_id + 1 - ndx * ndy); |
| 144 |
else if (coloring3D(brick_id - ndx - ndx * ndy, ndx, ndy) == color && (shifted_id - ndx - ndx * ndy) >= 0 && (shifted_id - ndx - ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 145 |
neighbour = (shifted_id - ndx - ndx * ndy); |
| 146 |
else if (coloring3D(brick_id - ndx - 1 - ndx * ndy, ndx, ndy) == color && (shifted_id - ndx - 1 - ndx * ndy) >= 0 && (shifted_id - ndx - 1 - ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 147 |
neighbour = (shifted_id - ndx - 1 - ndx * ndy); |
| 148 |
else if (coloring3D(brick_id - ndx + 1 - ndx * ndy, ndx, ndy) == color && (shifted_id - ndx + 1 - ndx * ndy) >= 0 && (shifted_id - ndx + 1 - ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 149 |
neighbour = (shifted_id - ndx + 1 - ndx * ndy); |
| 150 |
else if (coloring3D(brick_id + ndx - ndx * ndy, ndx, ndy) == color && (shifted_id + ndx - ndx * ndy) >= 0 && (shifted_id + ndx - ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 151 |
neighbour = (shifted_id + ndx - ndx * ndy); |
| 152 |
else if (coloring3D(brick_id + ndx - 1 - ndx * ndy, ndx, ndy) == color && (shifted_id + ndx - 1 - ndx * ndy) >= 0 && (shifted_id + ndx - 1 - ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 153 |
neighbour = (shifted_id + ndx - 1 - ndx * ndy); |
| 154 |
else if (coloring3D(brick_id + ndx + 1 - ndx * ndy, ndx, ndy) == color && (shifted_id + ndx + 1 - ndx * ndy) >= 0 && (shifted_id + ndx + 1 - ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 155 |
neighbour = (shifted_id + ndx + 1 - ndx * ndy); |
| 156 |
|
| 157 |
// Identification of the neighbours that are on the plane above |
| 158 |
else if (coloring3D(brick_id + ndx * ndy, ndx, ndy) == color && (shifted_id + ndx * ndy) >= 0 && (shifted_id + ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 159 |
neighbour = (shifted_id + ndx * ndy); |
| 160 |
else if (coloring3D(brick_id - 1 + ndx * ndy, ndx, ndy) == color && (shifted_id - 1 + ndx * ndy) >= 0 && (shifted_id - 1 + ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 161 |
neighbour = (shifted_id - 1 + ndx * ndy); |
| 162 |
else if (coloring3D(brick_id + 1 + ndx * ndy, ndx, ndy) == color && (shifted_id + 1 + ndx * ndy) >= 0 && (shifted_id + 1 + ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 163 |
neighbour = (shifted_id + 1 + ndx * ndy); |
| 164 |
else if (coloring3D(brick_id - ndx + ndx * ndy, ndx, ndy) == color && (shifted_id - ndx + ndx * ndy) >= 0 && (shifted_id - ndx + ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 165 |
neighbour = (shifted_id - ndx + ndx * ndy); |
| 166 |
else if (coloring3D(brick_id - ndx - 1 + ndx * ndy, ndx, ndy) == color && (shifted_id - ndx - 1 + ndx * ndy) >= 0 && (shifted_id - ndx - 1 + ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 167 |
neighbour = (shifted_id - ndx - 1 + ndx * ndy); |
| 168 |
else if (coloring3D(brick_id - ndx + 1 + ndx * ndy, ndx, ndy) == color && (shifted_id - ndx + 1 + ndx * ndy) >= 0 && (shifted_id - ndx + 1 + ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 169 |
neighbour = (shifted_id - ndx + 1 + ndx * ndy); |
| 170 |
else if (coloring3D(brick_id + ndx + ndx * ndy, ndx, ndy) == color && (shifted_id + ndx + ndx * ndy) >= 0 && (shifted_id + ndx + ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 171 |
neighbour = (shifted_id + ndx + ndx * ndy); |
| 172 |
else if (coloring3D(brick_id + ndx - 1 + ndx * ndy, ndx, ndy) == color && (shifted_id + ndx - 1 + ndx * ndy) >= 0 && (shifted_id + ndx - 1 + ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 173 |
neighbour = (shifted_id + ndx - 1 + ndx * ndy); |
| 174 |
else if (coloring3D(brick_id + ndx + 1 + ndx * ndy, ndx, ndy) == color && (shifted_id + ndx + 1 + ndx * ndy) >= 0 && (shifted_id + ndx + 1 + ndx * ndy) < tpetra_prolong->getGlobalNumCols()) |
| 175 |
neighbour = (shifted_id + ndx + 1 + ndx * ndy); |
| 176 |
|
| 177 |
if (neighbour >= 0) |
| 178 |
neighbours.emplace_back(neighbour); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
neighbours.shrink_to_fit(); |
| 183 |
} |