Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom coarsening method #1659

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions include/ginkgo/core/multigrid/custom_coarsening.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#ifndef GKO_PUBLIC_CORE_MULTIGRID_CUSTOM_COARSE_HPP_
#define GKO_PUBLIC_CORE_MULTIGRID_CUSTOM_COARSE_HPP_


#include <vector>

#include <ginkgo/core/base/exception_helpers.hpp>
#include <ginkgo/core/base/lin_op.hpp>
#include <ginkgo/core/multigrid/multigrid_level.hpp>

namespace gko {
namespace multigrid {


/**
* CustomCoarsening allows users to set up the entire multigrid hierarchy.
*
* @tparam ValueType precision of matrix elements
*
* @ingroup MultigridLevel
* @ingroup Multigrid
* @ingroup LinOp
*/
template <typename ValueType = default_precision>
class CustomCoarsening : public EnableLinOp<CustomCoarse<ValueType>>,
public EnableMultigridLevel<ValueType> {
friend class EnableLinOp<CustomCoarse>;
friend class EnablePolymorphicObject<CustomCoarse, LinOp>;

public:
using value_type = ValueType;

/**
* Returns the system operator (matrix) of the linear system.
*
* @return the system operator (matrix)
*/
std::shared_ptr<const LinOp> get_system_matrix() const
{
return system_matrix_;
}

GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
{
std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(restriction,
nullptr);

std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(prologation,
nullptr);

std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(coarse,
nullptr);
};
GKO_ENABLE_LIN_OP_FACTORY(CustomCoarse, parameters, Factory);
GKO_ENABLE_BUILD_METHOD(Factory);

protected:
void apply_impl(const LinOp* b, LinOp* x) const override
{
this->get_composition()->apply(b, x);
}

void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
LinOp* x) const override
{
this->get_composition()->apply(alpha, b, beta, x);
}

explicit CustomCoarsening(std::shared_ptr<const Executor> exec)
: EnableLinOp<CustomCoarsening>(std::move(exec))
{}

explicit CustomCoarsening(const Factory* factory,
std::shared_ptr<const LinOp> system_matrix)
: EnableLinOp<CustomCoarsening>(factory->get_executor(),
system_matrix->get_size()),
EnableMultigridLevel<ValueType>(system_matrix),
parameters_{factory->get_parameters()},
system_matrix_{system_matrix}
{
GKO_ASSERT(parameters_.restriction != nullptr);
GKO_ASSERT(parameters_.prologation != nullptr);
GKO_ASSERT(parameters_.coarse != nullptr);
if (system_matrix_->get_size()[0] != 0) {
this->set_multigrid_level(parameters_.prologation,
parameters_.coarse,
parameters_.restriction);
}
}

private:
std::shared_ptr<const LinOp> system_matrix_{};
};


} // namespace multigrid
} // namespace gko


#endif // GKO_PUBLIC_CORE_MULTIGRID_CUSTOM_COARSE_HPP_
1 change: 1 addition & 0 deletions include/ginkgo/ginkgo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#include <ginkgo/core/matrix/sellp.hpp>
#include <ginkgo/core/matrix/sparsity_csr.hpp>

#include <ginkgo/core/multigrid/custom_coarsening.hpp>
#include <ginkgo/core/multigrid/fixed_coarsening.hpp>
#include <ginkgo/core/multigrid/multigrid_level.hpp>
#include <ginkgo/core/multigrid/pgm.hpp>
Expand Down
Loading