8#include <Kokkos_Core.hpp>
9#include <petscvec_kokkos.hpp>
23namespace NeoN::la::petsc
28class petscSolver :
public SolverFactory::template
Register<petscSolver>
35 Dictionary solverDict_;
50 petscSolver(Executor exec, Dictionary solverDict) : Base(exec), solverDict_(solverDict)
57 virtual ~petscSolver()
65 static std::string
name() {
return "Petsc"; }
67 static std::string doc() {
return "TBD"; }
69 static std::string schema() {
return "none"; }
72 virtual std::unique_ptr<SolverFactory> clone() const final
80 solve(
const LinearSystem<scalar, localIdx>& sys, Vector<scalar>& x)
const final
88 NeoN::la::petscSolverContext::petscSolverContext<scalar> petsctx(exec_);
90 std::size_t nrows = sys.rhs().size();
92 petsctx.initialize(sys);
94 Amat = petsctx.AMat();
99 VecSetValuesCOO(rhs, sys.rhs().data(), ADD_VALUES);
100 MatSetValuesCOO(Amat, sys.matrix().values().data(), ADD_VALUES);
107 KSPSetOperators(ksp, Amat, Amat);
113 PetscCallVoid(KSPSolve(ksp, rhs, sol));
116 KSPGetIterationNumber(ksp, &numIter);
119 PetscScalar* x_help =
static_cast<PetscScalar*
>(x.data());
120 VecGetArray(sol, &x_help);
122 Vector<scalar> x2(x.exec(),
static_cast<scalar*
>(x_help), nrows, x.exec());
126 return {numIter, 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.