9#include <Kokkos_Core.hpp>
10#include <petscvec_kokkos.hpp>
25namespace NeoN::la::petsc
30class petscSolver :
public SolverFactory::template Register<petscSolver>
33 using Base = SolverFactory::template Register<petscSolver>;
37 Dictionary solverDict_;
52 petscSolver(Executor exec, Dictionary solverDict) : Base(exec), solverDict_(solverDict)
59 virtual ~petscSolver()
67 static std::string
name() {
return "Petsc"; }
69 static std::string doc() {
return "TBD"; }
71 static std::string schema() {
return "none"; }
74 virtual std::unique_ptr<SolverFactory> clone() const final
81 virtual SolverStats
solve(
const LinearSystem<scalar>& sys, Vector<scalar>& x)
const final
89 NeoN::la::petscSolverContext::petscSolverContext<scalar> petsctx(exec_);
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};
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
std::optional< la::SolverStats > solve(Expression< typename VectorType::ElementType, IndexType > &exp, VectorType &solution, scalar t, scalar dt, const Dictionary &fvSchemes, const Dictionary &fvSolution, std::vector< const PostAssemblyBase< typename VectorType::ElementType, IndexType > * > p={})
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.