Rodin::PETSc module

PETSc integration module for Rodin.

Solver::KSP(poisson).solve();

PETSc::Math::LinearSystem groups PETSc matrix and vector handles, while KSP and SNES expose linear and nonlinear solvers. PETSc-backed variational and assembly specializations connect the same weak-form interfaces to distributed algebra, preconditioning, and solver configuration for larger PDE systems.

PETSc-specific linear algebra, solver, variational, and assembly adapters are documented in their corresponding headers.

Submodules

  • Math — PETSc vector, matrix, and linear system wrappers
  • Solver — KSP, SNES, CG, and GMRES solver aliases
  • Assembly — Assembly strategies for PETSc objects (sequential, MPI, OpenMP)
  • Variational — Trial/test functions, forms, grid functions, and problems backed by PETSc

Typical Usage (Sequential)

#include <Rodin/PETSc.h>

PetscInitialize(&argc, &argv, PETSC_NULLPTR, PETSC_NULLPTR);

Mesh mesh;
mesh = mesh.UniformGrid(Polytope::Type::Triangle, {16, 16});
mesh.getConnectivity().compute(1, 2);

P1 Vh(mesh);
PETSc::Variational::TrialFunction u(Vh);
PETSc::Variational::TestFunction  v(Vh);

Problem poisson(u, v);
poisson = Integral(Grad(u), Grad(v))
        - Integral(f, v)
        + DirichletBC(u, Zero());

Solver::CG(poisson).solve();

PetscFinalize();

Typical Usage (MPI + PETSc)

#include <Rodin/MPI.h>
#include <Rodin/PETSc.h>

boost::mpi::environment env(argc, argv);
boost::mpi::communicator world;
Context::MPI mpi(env, world);
PetscInitialize(&argc, &argv, PETSC_NULLPTR, PETSC_NULLPTR);

// Partition and distribute mesh
MPI::Sharder sharder(mpi);
// ... (see MPI module documentation)
auto mesh = sharder.gather(0);
mesh.getConnectivity().compute(2, 3);
mesh.reconcile(2);

P1 Vh(mesh);
PETSc::Variational::TrialFunction u(Vh);
PETSc::Variational::TestFunction  v(Vh);

Problem poisson(u, v);
poisson = Integral(Grad(u), Grad(v))
        - Integral(f, v)
        + DirichletBC(u, Zero());

Solver::CG(poisson).solve();

PetscFinalize();

Multi-Field Problems (Stokes)

PETSc problems support an arbitrary number of coupled trial/test function pairs for saddle-point systems:

H1  uh(std::integral_constant<size_t, 2>{}, mesh, mesh.getSpaceDimension());
H1  ph(std::integral_constant<size_t, 1>{}, mesh);
P0g lh(mesh);

PETSc::Variational::TrialFunction u(uh);
PETSc::Variational::TrialFunction p(ph);
PETSc::Variational::TrialFunction l(lh);

PETSc::Variational::TestFunction v(uh);
PETSc::Variational::TestFunction q(ph);
PETSc::Variational::TestFunction m(lh);

Problem stokes(u, p, l, v, q, m);
stokes = Integral(Jacobian(u), Jacobian(v))
       - Integral(p, Div(v))
       + Integral(Div(u), q)
       + Integral(l, q)
       + Integral(p, m)
       - Integral(f, v)
       + DirichletBC(u, u_exact);

Solver::KSP(stokes).solve();

PETSc command-line options can be used to configure field-split preconditioning: ./Stokes -ksp_type gmres -pc_type fieldsplit -ksp_rtol 1e-8

Namespaces

namespace Assembly
PETSc-specific assembly strategies.
namespace Math
PETSc-backed linear algebra adapters.
namespace Solver
PETSc-backed linear and nonlinear solver adapters.
namespace Variational
PETSc-backed variational form adapters.

Classes

template<class Handle>
class Object
RAII base class for wrappers around PETSc opaque handles.

Typedefs

using Scalar = PetscScalar
Scalar type used by PETSc vectors and matrices.
using Integer = PetscInt
Integer index type used by PETSc row/column indices.
using Real = PetscReal
Real-valued floating-point type (tolerances, norms, etc.).
using Complex = PetscComplex
Complex scalar type (available when PETSc is built with complex support).

Typedef documentation

using Scalar = PetscScalar

Defined in Rodin/PETSc/Types.h

Scalar type used by PETSc vectors and matrices.

using Integer = PetscInt

Defined in Rodin/PETSc/Types.h

Integer index type used by PETSc row/column indices.

using Real = PetscReal

Defined in Rodin/PETSc/Types.h

Real-valued floating-point type (tolerances, norms, etc.).

using Complex = PetscComplex

Defined in Rodin/PETSc/Types.h

Complex scalar type (available when PETSc is built with complex support).