diff --git a/src/mapping/GinkgoRadialBasisFctSolver.hpp b/src/mapping/GinkgoRadialBasisFctSolver.hpp index c8323aa5ea..831fceedb5 100644 --- a/src/mapping/GinkgoRadialBasisFctSolver.hpp +++ b/src/mapping/GinkgoRadialBasisFctSolver.hpp @@ -5,13 +5,14 @@ #include #include #include -#include "GinkgoDefinitions.hpp" -#include "GinkgoKernels.hpp" +#include "mapping/GinkgoDefinitions.hpp" #include "mapping/config/MappingConfiguration.hpp" +#include "mapping/device/GinkgoRBFKernels.hpp" #include "mapping/impl/BasisFunctions.hpp" #include "mesh/Mesh.hpp" #include "precice/types.hpp" #include "profiling/Event.hpp" +#include "utils/Ginkgo.hpp" #ifdef PRECICE_WITH_HIP #include "mapping/device/HipQRSolver.hip.hpp" #endif @@ -164,6 +165,8 @@ class GinkgoRadialBasisFctSolver { std::shared_ptr::Factory> _residualCriterion; + std::shared_ptr::Factory> _absoluteResidualCriterion; + MappingConfiguration::GinkgoParameter _ginkgoParameter; }; @@ -301,6 +304,7 @@ GinkgoRadialBasisFctSolver::GinkgoRadialBasisFctSolver( .on(_deviceExecutor), gko::stop::ResidualNorm<>::build() .with_reduction_factor(1e-6) + .with_baseline(gko::stop::mode::initial_resnorm) .on(_deviceExecutor)) .on(_deviceExecutor); @@ -334,8 +338,15 @@ GinkgoRadialBasisFctSolver::GinkgoRadialBasisFctSolver( _residualCriterion = gko::share(gko::stop::ResidualNorm<>::build() .with_reduction_factor(ginkgoParameter.residualNorm) + .with_baseline(gko::stop::mode::initial_resnorm) .on(_deviceExecutor)); + // For cases where we reach a stationary solution such that the coupling data doesn't change (or map zero data) + _absoluteResidualCriterion = gko::share(gko::stop::ResidualNorm<>::build() + .with_reduction_factor(1e-30) + .with_baseline(gko::stop::mode::absolute) + .on(_deviceExecutor)); + if (_solverType == GinkgoSolverType::CG) { if (GinkgoPreconditionerType::None != _preconditionerType && ginkgoParameter.usePreconditioner) { @@ -348,13 +359,13 @@ GinkgoRadialBasisFctSolver::GinkgoRadialBasisFctSolver( }(); auto solverFactory = solverFactoryWithPreconditioner - .with_criteria(_iterationCriterion, _residualCriterion) + .with_criteria(_iterationCriterion, _residualCriterion, _absoluteResidualCriterion) .on(_deviceExecutor); _cgSolver = gko::share(solverFactory->generate(_rbfSystemMatrix)); } else { auto solverFactory = cg::build() - .with_criteria(_iterationCriterion, _residualCriterion) + .with_criteria(_iterationCriterion, _residualCriterion, _absoluteResidualCriterion) .on(_deviceExecutor); _cgSolver = gko::share(solverFactory->generate(_rbfSystemMatrix)); @@ -372,13 +383,13 @@ GinkgoRadialBasisFctSolver::GinkgoRadialBasisFctSolver( }(); auto solverFactory = solverFactoryWithPreconditioner - .with_criteria(_iterationCriterion, _residualCriterion) + .with_criteria(_iterationCriterion, _residualCriterion, _absoluteResidualCriterion) .on(_deviceExecutor); _gmresSolver = gko::share(solverFactory->generate(_rbfSystemMatrix)); } else { auto solverFactory = gmres::build() - .with_criteria(_iterationCriterion, _residualCriterion) + .with_criteria(_iterationCriterion, _residualCriterion, _absoluteResidualCriterion) .on(_deviceExecutor); _gmresSolver = gko::share(solverFactory->generate(_rbfSystemMatrix)); @@ -421,6 +432,7 @@ void GinkgoRadialBasisFctSolver::_solveRBFSystem(const _iterationCriterion->add_logger(logger); _residualCriterion->add_logger(logger); + _absoluteResidualCriterion->add_logger(logger); precice::profiling::Event solverEvent("map.rbf.ginkgo.solveSystemMatrix"); if (_solverType == GinkgoSolverType::CG) { @@ -442,6 +454,7 @@ void GinkgoRadialBasisFctSolver::_solveRBFSystem(const _iterationCriterion->clear_loggers(); _residualCriterion->clear_loggers(); + _absoluteResidualCriterion->clear_loggers(); } template @@ -561,6 +574,7 @@ Eigen::VectorXd GinkgoRadialBasisFctSolver::solveConser .on(_deviceExecutor), gko::stop::ResidualNorm<>::build() .with_reduction_factor(1e-6) + .with_baseline(gko::stop::mode::initial_resnorm) .on(_deviceExecutor)) .on(_deviceExecutor); diff --git a/src/mapping/device/GinkgoRBFKernels.cpp b/src/mapping/device/GinkgoRBFKernels.cpp index 923cdf5843..5223635cd3 100644 --- a/src/mapping/device/GinkgoRBFKernels.cpp +++ b/src/mapping/device/GinkgoRBFKernels.cpp @@ -1,4 +1,4 @@ -#include "mapping/GinkgoKernels.hpp" +#include "mapping/device/GinkgoRBFKernels.hpp" #include "mapping/impl/BasisFunctions.hpp" #include "math/math.hpp" @@ -9,8 +9,8 @@ using precice::mapping::RadialBasisParameters; using precice::math::pow_int; -template -using native_type = gko::ext::kokkos::native_type; +template +using native_type = gko::ext::kokkos::native_type; using gko::ext::kokkos::map_data; diff --git a/src/mapping/GinkgoKernels.hpp b/src/mapping/device/GinkgoRBFKernels.hpp similarity index 84% rename from src/mapping/GinkgoKernels.hpp rename to src/mapping/device/GinkgoRBFKernels.hpp index b012f3c950..8006a3ae68 100644 --- a/src/mapping/GinkgoKernels.hpp +++ b/src/mapping/device/GinkgoRBFKernels.hpp @@ -1,10 +1,8 @@ -#ifndef PRECICE_GINKGOKERNELS_HPP -#define PRECICE_GINKGOKERNELS_HPP +#pragma once -#include "GinkgoDefinitions.hpp" +#include "mapping/GinkgoDefinitions.hpp" #include "mapping/impl/BasisFunctions.hpp" - namespace precice { namespace mapping { @@ -16,14 +14,9 @@ void create_rbf_system_matrix(std::shared_ptr exec, gko::ptr_param supportPoints, gko::ptr_param targetPoints, EvalFunctionType f, ::precice::mapping::RadialBasisParameters rbf_params, bool addPolynomial, unsigned int extraDims = 0); - void fill_polynomial_matrix(std::shared_ptr exec, gko::ptr_param mtx, gko::ptr_param x, const unsigned int dims); - -} -} -} - - -#endif // PRECICE_GINKGOKERNELS_HPP +} // namespace kernel +} // namespace mapping +} // namespace precice