From 33866647ff17fef25890ab949a35b03ef3baa150 Mon Sep 17 00:00:00 2001 From: Pratik Nayak Date: Mon, 4 Apr 2022 14:24:47 +0200 Subject: [PATCH] Review update. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fritz Göbel --- .../core/multigrid/fixed_coarsening.hpp | 9 +++- .../multigrid/fixed_coarsening_kernels.cpp | 43 ++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/include/ginkgo/core/multigrid/fixed_coarsening.hpp b/include/ginkgo/core/multigrid/fixed_coarsening.hpp index 40a0b6f780a..7451c5cebbf 100644 --- a/include/ginkgo/core/multigrid/fixed_coarsening.hpp +++ b/include/ginkgo/core/multigrid/fixed_coarsening.hpp @@ -51,8 +51,13 @@ namespace multigrid { /** * FixedCoarsening is a very simple coarse grid generation algorithm. It selects - * the coarse matrix from the fine matrix by either constant jumps or with a - * user-specified index_set of rows. + * the coarse matrix from the fine matrix by with user-specified indices. + * + * The user needs to specify the indices (with global numbering) of the fine + * matrix, they wish to be in the coarse matrix. The restriction and + * prolongation matrices will map to and from the coarse space without any + * interpolation or weighting. + * * * @tparam ValueType precision of matrix elements * @tparam IndexType precision of matrix indexes diff --git a/reference/test/multigrid/fixed_coarsening_kernels.cpp b/reference/test/multigrid/fixed_coarsening_kernels.cpp index d4225a8283b..27e7dfba57f 100644 --- a/reference/test/multigrid/fixed_coarsening_kernels.cpp +++ b/reference/test/multigrid/fixed_coarsening_kernels.cpp @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include #include @@ -67,6 +68,7 @@ class FixedCoarsening : public ::testing::Test { using index_type = typename std::tuple_element<1, decltype(ValueIndexType())>::type; using Mtx = gko::matrix::Csr; + using CooMtx = gko::matrix::Coo; using Vec = gko::matrix::Dense; using SparsityCsr = gko::matrix::SparsityCsr; using MgLevel = gko::multigrid::FixedCoarsening; @@ -348,7 +350,7 @@ TYPED_TEST(FixedCoarsening, GenerateMgLevel) } -TYPED_TEST(FixedCoarsening, GenerateMgLevelOnUnsortedMatrix) +TYPED_TEST(FixedCoarsening, GenerateMgLevelOnUnsortedCsrMatrix) { using value_type = typename TestFixture::value_type; using index_type = typename TestFixture::index_type; @@ -386,4 +388,43 @@ TYPED_TEST(FixedCoarsening, GenerateMgLevelOnUnsortedMatrix) } +TYPED_TEST(FixedCoarsening, GenerateMgLevelOnUnsortedCooMatrix) +{ + using value_type = typename TestFixture::value_type; + using index_type = typename TestFixture::index_type; + using CooMtx = typename TestFixture::CooMtx; + using Mtx = typename TestFixture::Mtx; + using MgLevel = typename TestFixture::MgLevel; + auto coarse_rows = gko::Array(this->exec, {0, 2, 3}); + auto mglevel_sort = + MgLevel::build().with_coarse_rows(coarse_rows).on(this->exec); + /* this unsorted matrix is stored as this->fine: + * 5 -3 -3 0 0 + * -3 5 0 -2 -1 + * -3 0 5 0 -1 + * 0 -3 0 5 0 + * 0 -2 -2 0 5 + */ + auto mtx_values = {-3, -3, 5, -3, -2, -1, 5, -3, -1, 5, -3, 5, -2, -2, 5}; + auto mtx_col_idxs = {1, 2, 0, 0, 3, 4, 1, 0, 4, 2, 1, 3, 1, 2, 4}; + auto mtx_row_idxs = {0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4}; + auto matrix = gko::share( + CooMtx::create(this->exec, gko::dim<2>{5, 5}, std::move(mtx_values), + std::move(mtx_col_idxs), std::move(mtx_row_idxs))); + auto prolong_op = gko::share(Mtx::create(this->exec, gko::dim<2>{5, 3}, 0)); + // 0-2-3 + prolong_op->read({{5, 3}, {{0, 0, 1}, {2, 1, 1}, {3, 2, 1}}}); + auto restrict_op = gko::share(gko::as(prolong_op->transpose())); + + auto coarse_fine = mglevel_sort->generate(matrix); + + GKO_ASSERT_MTX_NEAR(gko::as(coarse_fine->get_restrict_op()), + restrict_op, r::value); + GKO_ASSERT_MTX_NEAR(gko::as(coarse_fine->get_prolong_op()), prolong_op, + r::value); + GKO_ASSERT_MTX_NEAR(gko::as(coarse_fine->get_coarse_op()), + this->coarse, r::value); +} + + } // namespace