Skip to content

Commit

Permalink
Review update.
Browse files Browse the repository at this point in the history
Co-authored-by: Fritz Göbel <fritz.goebel@kit.edu>
  • Loading branch information
pratikvn and fritzgoebel committed Apr 4, 2022
1 parent 7d2fa04 commit 3386664
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
9 changes: 7 additions & 2 deletions include/ginkgo/core/multigrid/fixed_coarsening.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 42 additions & 1 deletion reference/test/multigrid/fixed_coarsening_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/base/exception.hpp>
#include <ginkgo/core/base/executor.hpp>
#include <ginkgo/core/base/math.hpp>
#include <ginkgo/core/matrix/coo.hpp>
#include <ginkgo/core/matrix/csr.hpp>
#include <ginkgo/core/matrix/dense.hpp>
#include <ginkgo/core/matrix/diagonal.hpp>
Expand All @@ -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<value_type, index_type>;
using CooMtx = gko::matrix::Coo<value_type, index_type>;
using Vec = gko::matrix::Dense<value_type>;
using SparsityCsr = gko::matrix::SparsityCsr<value_type, index_type>;
using MgLevel = gko::multigrid::FixedCoarsening<value_type, index_type>;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<index_type>(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<Mtx>(prolong_op->transpose()));

auto coarse_fine = mglevel_sort->generate(matrix);

GKO_ASSERT_MTX_NEAR(gko::as<Mtx>(coarse_fine->get_restrict_op()),
restrict_op, r<value_type>::value);
GKO_ASSERT_MTX_NEAR(gko::as<Mtx>(coarse_fine->get_prolong_op()), prolong_op,
r<value_type>::value);
GKO_ASSERT_MTX_NEAR(gko::as<Mtx>(coarse_fine->get_coarse_op()),
this->coarse, r<value_type>::value);
}


} // namespace

0 comments on commit 3386664

Please sign in to comment.