9#include <Kokkos_Core.hpp>
10#include <petscvec_kokkos.hpp>
24namespace NeoN::la::petsc
29class petscSolver :
public SolverFactory::template
Register<petscSolver>
36 Dictionary solverDict_;
51 petscSolver(Executor exec, Dictionary solverDict) : Base(exec), solverDict_(solverDict)
58 virtual ~petscSolver()
66 static std::string
name() {
return "Petsc"; }
68 static std::string doc() {
return "TBD"; }
70 static std::string schema() {
return "none"; }
73 virtual std::unique_ptr<SolverFactory> clone() const final
81 solve(
const LinearSystem<scalar, localIdx>& sys, Vector<scalar>& x)
const final
89 NeoN::la::petscSolverContext::petscSolverContext<scalar> petsctx(exec_);
91 std::size_t nrows = sys.rhs().size();
93 petsctx.initialize(sys);
95 Amat = petsctx.AMat();
100 VecSetValuesCOO(rhs, sys.rhs().data(), ADD_VALUES);
101 MatSetValuesCOO(Amat, sys.matrix().values().data(), ADD_VALUES);
108 KSPSetOperators(ksp, Amat, Amat);
114 PetscCallVoid(KSPSolve(ksp, rhs, sol));
117 KSPGetIterationNumber(ksp, &numIter);
120 PetscScalar* x_help =
static_cast<PetscScalar*
>(x.data());
121 VecGetArray(sol, &x_help);
123 Vector<scalar> x2(x.exec(),
static_cast<scalar*
>(x_help), nrows, x.exec());
127 return {numIter, 0.0, 0.0, 0.0};
A template class for registering derived classes with a base class.
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
void solve(Expression< typename VectorType::ElementType > &exp, VectorType &solution, scalar t, scalar dt, const Dictionary &fvSchemes, const Dictionary &fvSolution)
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.