Skip to content

Commit

Permalink
COnvergence checks updates
Browse files Browse the repository at this point in the history
  • Loading branch information
davidscn committed Sep 13, 2023
1 parent 2019236 commit 344707d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
26 changes: 20 additions & 6 deletions src/mapping/GinkgoRadialBasisFctSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include <cmath>
#include <functional>
#include <numeric>
#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
Expand Down Expand Up @@ -164,6 +165,8 @@ class GinkgoRadialBasisFctSolver {

std::shared_ptr<gko::stop::ResidualNorm<>::Factory> _residualCriterion;

std::shared_ptr<gko::stop::ResidualNorm<>::Factory> _absoluteResidualCriterion;

MappingConfiguration::GinkgoParameter _ginkgoParameter;
};

Expand Down Expand Up @@ -301,6 +304,7 @@ GinkgoRadialBasisFctSolver<RADIAL_BASIS_FUNCTION_T>::GinkgoRadialBasisFctSolver(
.on(_deviceExecutor),
gko::stop::ResidualNorm<>::build()
.with_reduction_factor(1e-6)
.with_baseline(gko::stop::mode::initial_resnorm)
.on(_deviceExecutor))
.on(_deviceExecutor);

Expand Down Expand Up @@ -334,8 +338,15 @@ GinkgoRadialBasisFctSolver<RADIAL_BASIS_FUNCTION_T>::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) {
Expand All @@ -348,13 +359,13 @@ GinkgoRadialBasisFctSolver<RADIAL_BASIS_FUNCTION_T>::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));
Expand All @@ -372,13 +383,13 @@ GinkgoRadialBasisFctSolver<RADIAL_BASIS_FUNCTION_T>::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));
Expand Down Expand Up @@ -421,6 +432,7 @@ void GinkgoRadialBasisFctSolver<RADIAL_BASIS_FUNCTION_T>::_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) {
Expand All @@ -442,6 +454,7 @@ void GinkgoRadialBasisFctSolver<RADIAL_BASIS_FUNCTION_T>::_solveRBFSystem(const

_iterationCriterion->clear_loggers();
_residualCriterion->clear_loggers();
_absoluteResidualCriterion->clear_loggers();
}

template <typename RADIAL_BASIS_FUNCTION_T>
Expand Down Expand Up @@ -561,6 +574,7 @@ Eigen::VectorXd GinkgoRadialBasisFctSolver<RADIAL_BASIS_FUNCTION_T>::solveConser
.on(_deviceExecutor),
gko::stop::ResidualNorm<>::build()
.with_reduction_factor(1e-6)
.with_baseline(gko::stop::mode::initial_resnorm)
.on(_deviceExecutor))
.on(_deviceExecutor);

Expand Down
6 changes: 3 additions & 3 deletions src/mapping/device/GinkgoRBFKernels.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "mapping/GinkgoKernels.hpp"
#include "mapping/device/GinkgoRBFKernels.hpp"
#include "mapping/impl/BasisFunctions.hpp"
#include "math/math.hpp"

Expand All @@ -9,8 +9,8 @@
using precice::mapping::RadialBasisParameters;
using precice::math::pow_int;

template <typename T, typename MemorySpace>
using native_type = gko::ext::kokkos::native_type<T, MemorySpace>;
template <typename T>
using native_type = gko::ext::kokkos::native_type<T>;

using gko::ext::kokkos::map_data;

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -16,14 +14,9 @@ void create_rbf_system_matrix(std::shared_ptr<const gko::Executor> exec,
gko::ptr_param<GinkgoMatrix> supportPoints, gko::ptr_param<GinkgoMatrix> targetPoints,
EvalFunctionType f, ::precice::mapping::RadialBasisParameters rbf_params, bool addPolynomial, unsigned int extraDims = 0);


void fill_polynomial_matrix(std::shared_ptr<const gko::Executor> exec,
gko::ptr_param<GinkgoMatrix> mtx, gko::ptr_param<const GinkgoMatrix> x, const unsigned int dims);


}
}
}


#endif // PRECICE_GINKGOKERNELS_HPP
} // namespace kernel
} // namespace mapping
} // namespace precice

0 comments on commit 344707d

Please sign in to comment.