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"; }
71 virtual std::unique_ptr<SolverFactory> clone() const final
78 virtual void solve(
const LinearSystem<scalar, localIdx>& sys, Vector<scalar>& x)
const final
86 NeoN::la::petscSolverContext::petscSolverContext<scalar> petsctx(exec_);
88 std::size_t nrows = sys.rhs().size();
90 petsctx.initialize(sys);
92 Amat = petsctx.AMat();
97 VecSetValuesCOO(rhs, sys.rhs().data(), ADD_VALUES);
98 MatSetValuesCOO(Amat, sys.matrix().values().data(), ADD_VALUES);
105 KSPSetOperators(ksp, Amat, Amat);
111 PetscCallVoid(KSPSolve(ksp, rhs, sol));
114 PetscScalar* x_help =
static_cast<PetscScalar*
>(x.data());
115 VecGetArray(sol, &x_help);
A class to contain the data and executors for a field and define some basic operations.
A template class for registering derived classes with a base class.
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.