diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fb85d091..02ec9640c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/Solver/CG/GKOCG.H b/Solver/CG/GKOCG.H index 427a58ca9..a644e4f8f 100644 --- a/Solver/CG/GKOCG.H +++ b/Solver/CG/GKOCG.H @@ -36,7 +36,6 @@ namespace Foam { class GKOCGFactory { private: - using mtx = gko::matrix::Csr; using vec = gko::matrix::Dense; using cg = gko::solver::Cg; diff --git a/Solver/IR/GKOIR.H b/Solver/IR/GKOIR.H index 94b9d9516..e162a358f 100644 --- a/Solver/IR/GKOIR.H +++ b/Solver/IR/GKOIR.H @@ -74,19 +74,28 @@ public: outerStoppingCriterion_(solverControls), innerStoppingCriterion_(StoppingCriterion(innerSolverControls_)){}; - CREATE_SOLVER_METHODS(ir) + + std::unique_ptr> + create_dist_solver( + std::shared_ptr exec, + std::shared_ptr gkomatrix, std::shared_ptr x, + std::shared_ptr b, const label verbose, + const bool export_res, std::shared_ptr 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::Factory>> - create_default(std::shared_ptr exec, - std::shared_ptr gkomatrix, std::shared_ptr x, - std::shared_ptr b, const label verbose) const + create_default(std::shared_ptr exec) const { - innerStoppingCriterionVec_.push_back( - innerStoppingCriterion_.build_stopping_criterion( - exec, gkomatrix, x, b, verbose, false, 0)); - - auto inner = gko::share(gko::solver::Cg::build() .with_criteria(innerStoppingCriterionVec_) .on(exec)); @@ -99,29 +108,6 @@ public: return ir; }; - std::unique_ptr::Factory, - std::default_delete::Factory>> - create_scalar_jacobi(std::shared_ptr exec, - std::shared_ptr gkomatrix, std::shared_ptr x, - std::shared_ptr 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 { @@ -135,7 +121,7 @@ public: scalar get_res_norm_time() const { - return stoppingCriterion_.get_res_norm_time(); + return outerStoppingCriterion_.get_res_norm_time(); } @@ -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_); } + }; /*---------------------------------------------------------------------------*\