Skip to content

Commit

Permalink
Wrap PCBDDC
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrubeck committed Mar 5, 2024
1 parent 8f4dd6d commit 470fc59
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions firedrake/preconditioners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
from firedrake.preconditioners.fdm import * # noqa: F401
from firedrake.preconditioners.hiptmair import * # noqa: F401
from firedrake.preconditioners.facet_split import * # noqa: F401
from firedrake.preconditioners.bddc import * # noqa: F401
49 changes: 49 additions & 0 deletions firedrake/preconditioners/bddc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from firedrake.preconditioners.base import PCBase
from firedrake.preconditioners.patch import bcdofs
from firedrake.petsc import PETSc
from firedrake.dmhooks import get_appctx
import numpy


__all__ = ("BDDCPC",)


class BDDCPC(PCBase):
"""PC for PETSc PCBDDC"""

_prefix = "bddc"

def initialize(self, pc):
# Get context from pc
_, P = pc.getOperators()
dm = pc.getDM()
self.prefix = pc.getOptionsPrefix() + self._prefix

# Create new PC object as BDDC type
bddcpc = PETSc.PC().create(comm=pc.comm)
bddcpc.incrementTabLevel(1, parent=pc)
bddcpc.setOptionsPrefix(self.prefix)
bddcpc.setOperators(*pc.getOperators())
bddcpc.setType(PETSc.PC.Type.BDDC)

ctx = get_appctx(dm)
bcs = tuple(ctx._problem.bcs)
if len(bcs) > 0:
bc_nodes = numpy.unique(numpy.concatenate([bcdofs(bc, ghost=False) for bc in bcs]))
bndr = PETSc.IS().createGeneral(bc_nodes, comm=pc.comm)
bddcpc.setBDDCDirichletBoundariesLocal(bndr)

This comment has been minimized.

Copy link
@stefanozampini

stefanozampini Mar 5, 2024

Contributor

bcdofs is in global ordering? if so, you must remove the Local from the BDDC call.
Local is always an ordering associated with the way you create the MATIS.
Try to use global ordering here, BDDC will do the proper global to local inside the setup

This comment has been minimized.

Copy link
@stefanozampini

stefanozampini Mar 5, 2024

Contributor

Also, is the ctx the way to pass general customization to the solver? can we do something like
hasattr(ctx, '_bddcxxx') to inquire for special customization? i.e. local CSR, Nedelec discrete gradient, etc


bddcpc.setFromOptions()
self.pc = bddcpc

def view(self, pc, viewer=None):
self.pc.view(viewer=viewer)

def update(self, pc):
pass

def apply(self, pc, x, y):
self.pc.apply(x, y)

def applyTranspose(self, pc, x, y):
self.pc.applyTranspose(x, y)

0 comments on commit 470fc59

Please sign in to comment.