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

Fix/ir build #123

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ target_sources(
HostMatrix/HostMatrixFreeFunctions.C
Solver/CG/GKOCG.C
Solver/BiCGStab/GKOBiCGStab.C
# Solver / IR / GKOIR.C Solver / Multigrid / GKOMultigrid.C
Solver/IR/GKOIR.C
# Solver / Multigrid / GKOMultigrid.C
Solver/GMRES/GKOGMRES.C
# LduMatrix / GKOACG / GKOACG.C
PUBLIC common/common.H
Expand Down
1 change: 0 additions & 1 deletion Solver/CG/GKOCG.H
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace Foam {

class GKOCGFactory {
private:
using mtx = gko::matrix::Csr<scalar>;
using vec = gko::matrix::Dense<scalar>;
using cg = gko::solver::Cg<scalar>;

Expand Down
76 changes: 40 additions & 36 deletions Solver/IR/GKOIR.H
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,28 @@ public:
outerStoppingCriterion_(solverControls),
innerStoppingCriterion_(StoppingCriterion(innerSolverControls_)){};

CREATE_SOLVER_METHODS(ir)

std::unique_ptr<ir::Factory, std::default_delete<ir::Factory>>
create_dist_solver(
std::shared_ptr<gko::Executor> exec,
std::shared_ptr<gko::LinOp> gkomatrix, std::shared_ptr<dist_vec> x,
std::shared_ptr<dist_vec> b, const label verbose,
const bool export_res, std::shared_ptr<gko::LinOp> precond) const
{
outerStoppingCriterionVec_.push_back(
outerStoppingCriterion_.build_dist_stopping_criterion(
exec, gkomatrix, x, b, verbose, export_res,
get_prev_number_of_iterations(),
get_solve_prev_rel_res_cost()));

return create_default(exec);
};


std::unique_ptr<ir::Factory,
std::default_delete<gko::solver::Ir<scalar>::Factory>>
create_default(std::shared_ptr<gko::Executor> exec,
std::shared_ptr<mtx> gkomatrix, std::shared_ptr<vec> x,
std::shared_ptr<vec> b, const label verbose) const
create_default(std::shared_ptr<gko::Executor> exec) const
{
innerStoppingCriterionVec_.push_back(
innerStoppingCriterion_.build_stopping_criterion(
exec, gkomatrix, x, b, verbose, false, 0));


auto inner = gko::share(gko::solver::Cg<scalar>::build()
.with_criteria(innerStoppingCriterionVec_)
.on(exec));
Expand All @@ -99,29 +108,6 @@ public:
return ir;
};

std::unique_ptr<gko::solver::Ir<scalar>::Factory,
std::default_delete<gko::solver::Ir<scalar>::Factory>>
create_scalar_jacobi(std::shared_ptr<gko::Executor> exec,
std::shared_ptr<mtx> gkomatrix, std::shared_ptr<vec> x,
std::shared_ptr<vec> b, const label verbose) const
{
using bj = gko::preconditioner::Jacobi<>;
label blockSize =
innerSolverControls_.lookupOrDefault("maxBlockSize", label(1));
auto bj_factory = bj::build()
.with_max_block_size(blockSize)
.with_skip_sorting(true)
// .with_storage_optimization(
// gko::precision_reduction::autodetect())
.on(exec);

auto ir = ir::build()
.with_solver(gko::share(bj_factory))
.with_criteria(outerStoppingCriterionVec_)
.on(exec);

return ir;
};

scalar get_init_res_norm() const
{
Expand All @@ -135,7 +121,7 @@ public:

scalar get_res_norm_time() const
{
return stoppingCriterion_.get_res_norm_time();
return outerStoppingCriterion_.get_res_norm_time();
}


Expand All @@ -147,15 +133,33 @@ public:
void store_number_of_iterations() const
{
set_solve_prev_iters(sysMatrixName_, db_,
stoppingCriterion_.get_num_iters(),
stoppingCriterion_.get_is_final());
outerStoppingCriterion_.get_num_iters(),
outerStoppingCriterion_.get_is_final());
}

label get_prev_number_of_iterations() const
{
return get_solve_prev_iters(sysMatrixName_, db_,
stoppingCriterion_.get_is_final());
outerStoppingCriterion_.get_is_final());
}

label get_number_of_iterations() const
{
return outerStoppingCriterion_.get_num_iters();
}

// TODO FIXME add via macro or base class
void set_prev_rel_res_cost(scalar prev_rel_res_cost) const
{
return ::Foam::set_solve_prev_rel_res_cost(sysMatrixName_, db_,
prev_rel_res_cost);
}

scalar get_solve_prev_rel_res_cost() const
{
return ::Foam::get_solve_prev_rel_res_cost(sysMatrixName_, db_);
}

};

/*---------------------------------------------------------------------------*\
Expand Down
Loading