Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FDMPC: Support MatIS and PCBDDC #3436

Merged
merged 67 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
b099d1f
ASMExtrudedStarPC: include vertical edge and face star patches
pbrubeck Feb 22, 2024
584b513
ASMExtrudedStar: test edge/face-star equivalence with Jacobi on NCE(1…
pbrubeck Feb 22, 2024
5426620
Update firedrake/preconditioners/asm.py
pbrubeck Feb 23, 2024
8b743b4
remove try ... except, as it was not required
pbrubeck Feb 23, 2024
052a590
Merge branch 'pbrubeck/fix/extruded-asm-edge-face' of github.com:fire…
pbrubeck Feb 23, 2024
5da9b79
FDMPC: support MATIS
pbrubeck Feb 26, 2024
2f70fb1
non_ghosted_lgmaps
pbrubeck Feb 26, 2024
1c65209
non_ghosted_lgmaps
pbrubeck Feb 26, 2024
3e585a0
disable hex mesh space checks
pbrubeck Feb 27, 2024
e810ef1
Transfer nullspace to MatNest blocks
pbrubeck Feb 27, 2024
e2357ee
dmhooks: handle the single function space case
stefanozampini Feb 27, 2024
58a970f
fdm: fix assembly
stefanozampini Feb 27, 2024
9ea9e5c
Merge branch 'pbrubeck/fdm-matis' of github.com:firedrakeproject/fire…
stefanozampini Feb 27, 2024
b3e1765
lgmaps: add non_ghost_cells kwarg and support extruded meshes
pbrubeck Feb 28, 2024
82a0daa
FDMPC: cache preallocator kernel and use it on Pmat to freeze nonzero…
pbrubeck Feb 28, 2024
36bb6ab
UNUSED_NONZERO_LOCATION_ERR
pbrubeck Feb 28, 2024
f2e60c2
cleanup
pbrubeck Feb 28, 2024
2deb254
set values local
pbrubeck Feb 29, 2024
2bef646
Merge branch 'master' into pbrubeck/fdm-matis
pbrubeck Mar 1, 2024
49390c7
fix F4 typo
pbrubeck Mar 1, 2024
9fc3d85
Correct broken LGMap
pbrubeck Mar 1, 2024
6b05029
remove PetscFunctionBeginUser
pbrubeck Mar 2, 2024
d35814b
Merge branch 'master' into pbrubeck/fdm-matis
pbrubeck Mar 3, 2024
f9f35d8
merge master
pbrubeck Mar 3, 2024
766317e
cleanup
pbrubeck Mar 4, 2024
8aae9ce
FDMPC: avoid MatAXPY
pbrubeck Mar 4, 2024
0b1acb1
FDMPC: setISAllowRepeated
pbrubeck Mar 4, 2024
2ce569a
code review suggestions
pbrubeck Mar 4, 2024
8f4dd6d
cleanup
pbrubeck Mar 5, 2024
470fc59
Wrap PCBDDC
pbrubeck Mar 5, 2024
8cd4752
BDDC: use global bc nodes
pbrubeck Mar 5, 2024
b2342c5
BDDCPC: attach discrete gradient and divergence mat
pbrubeck Mar 5, 2024
193e3b6
add missing underscore to prefix
pbrubeck Mar 5, 2024
b0c2a89
normalize subVectors
pbrubeck Mar 5, 2024
c29c0f4
BDDCPC: Disable computation of disconected components of subdomain in…
pbrubeck Mar 5, 2024
c240e34
refactor
pbrubeck Mar 8, 2024
24aa931
cannot preallocate upper triangular part of the matrix when using set…
pbrubeck Mar 8, 2024
4a002a2
refactor
pbrubeck Mar 11, 2024
dc5c900
Merge branch 'master' into pbrubeck/fdm-matis
pbrubeck Mar 11, 2024
5fc90a7
Merge branch 'pbrubeck/fdm-matis' of github.com:firedrakeproject/fire…
pbrubeck Mar 11, 2024
b6a6589
refactor
pbrubeck Mar 11, 2024
64cf55b
Call copy on subvector otherwise normalize will fail
stefanozampini Mar 12, 2024
909aa74
refactor
pbrubeck Mar 12, 2024
9cb4ac6
Merge branch 'pbrubeck/fdm-matis' of github.com:firedrakeproject/fire…
pbrubeck Mar 12, 2024
b7ed7d2
refactor
pbrubeck Mar 12, 2024
73357ba
refactor
pbrubeck Mar 12, 2024
36fb5fa
setBDDCNeumannBoundaries
pbrubeck Mar 12, 2024
67ed33b
BDDC: fix auxiliary space construction
pbrubeck Mar 20, 2024
f5d5577
FDMPC: add option -fdm_mat_is_allow_repeated
pbrubeck Mar 21, 2024
ce4c247
BDDC: pass the curl mat for 2D H(curl)
pbrubeck Mar 21, 2024
180f5b8
BDDC: hack to get a denser gradient
pbrubeck Mar 21, 2024
485a6a7
BDDC remove gradient sparsity hack
pbrubeck Mar 21, 2024
984902a
BDDC: get vertex DOFs
pbrubeck Mar 25, 2024
b7de870
add view from options for pmat
stefanozampini Mar 26, 2024
d5fc173
Finish discrete gradient
stefanozampini Mar 26, 2024
f8d7bc6
move restricted_local_dofs to facet_split
pbrubeck Mar 26, 2024
c2ef243
fix merge conflict
pbrubeck Mar 26, 2024
b2f9ec9
lint
pbrubeck Mar 26, 2024
00ea4ed
Merge branch 'master' into pbrubeck/fdm-matis
pbrubeck Apr 15, 2024
389b007
Fix FacetSplit
pbrubeck Apr 15, 2024
99026c3
Fix FacetSplit
pbrubeck Apr 15, 2024
42f5086
Merge branch 'pbrubeck/fdm-matis' of github.com:firedrakeproject/fire…
pbrubeck Apr 15, 2024
b24589f
do not view
pbrubeck Apr 29, 2024
734f78f
Merge branch 'master' into pbrubeck/fdm-matis
pbrubeck Apr 29, 2024
0747513
Add a test
pbrubeck Nov 25, 2024
dec6180
docs
pbrubeck Dec 4, 2024
62c48d6
docs
pbrubeck Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Christopher Hawkes

Miklós Homolya

Joshua Hope-Collins...........<https://www.imperial.ac.uk/people/joshua.hope-collins13>

Christian T. Jacobs

Darko Janeković
Expand Down
2 changes: 1 addition & 1 deletion CITATION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you publish results using Firedrake, we would be grateful if you would cite t

@manual{FiredrakeUserManual,
title = {Firedrake User Manual},
author = {David A. Ham and Paul H. J. Kelly and Lawrence Mitchell and Colin J. Cotter and Robert C. Kirby and Koki Sagiyama and Nacime Bouziani and Thomas J. Gregory and Jack Betteridge and Daniel R. Shapero and Reuben W. Nixon-Hill and Connor J. Ward and Patrick E. Farrell and Pablo D. Brubeck and India Marsden and Daiane I. Dolci and Sophia Vorderwuelbecke and Thomas H. Gibson and Miklós Homolya and Tianjiao Sun and Andrew T. T. McRae and Fabio Luporini and Alastair Gregory and Michael Lange and Simon W. Funke and Florian Rathgeber and Gheorghe-Teodor Bercea and Graham R. Markall},
author = {David A. Ham and Paul H. J. Kelly and Lawrence Mitchell and Colin J. Cotter and Robert C. Kirby and Koki Sagiyama and Nacime Bouziani and Thomas J. Gregory and Jack Betteridge and Daniel R. Shapero and Reuben W. Nixon-Hill and Connor J. Ward and Patrick E. Farrell and Pablo D. Brubeck and India Marsden and Daiane I. Dolci and Joshua Hope-Collins and Sophia Vorderwuelbecke and Thomas H. Gibson and Miklós Homolya and Tianjiao Sun and Andrew T. T. McRae and Fabio Luporini and Alastair Gregory and Michael Lange and Simon W. Funke and Florian Rathgeber and Gheorghe-Teodor Bercea and Graham R. Markall},
organization = {Imperial College London and University of Oxford and Baylor University and University of Washington},
edition = {First edition},
year = {2023},
Expand Down
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
142 changes: 142 additions & 0 deletions firedrake/preconditioners/bddc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
from firedrake.preconditioners.base import PCBase
from firedrake.preconditioners.patch import bcdofs
from firedrake.preconditioners.facet_split import restrict, get_restriction_indices
from firedrake.petsc import PETSc
from firedrake.dmhooks import get_function_space, get_appctx
from firedrake.ufl_expr import TestFunction, TrialFunction
from firedrake.functionspace import FunctionSpace, VectorFunctionSpace, TensorFunctionSpace
from ufl import curl, div, HCurl, HDiv, inner, dx
from pyop2.utils import as_tuple
import numpy

__all__ = ("BDDCPC",)


class BDDCPC(PCBase):
"""PC for PETSc PCBDDC (Balancing Domain Decomposition by Constraints).
JHopeCollins marked this conversation as resolved.
Show resolved Hide resolved
This is a domain decomposition method using subdomains defined by the
blocks in a Mat of type IS.

Internally, this PC creates a PETSc PCBDDC object that can be controlled by
the options:
- ``'bddc_pc_bddc_neumann'`` to set sub-KSPs on subdomains excluding corners,
- ``'bddc_pc_bddc_dirichlet'`` to set sub-KSPs on subdomain interiors,
- ``'bddc_pc_bddc_coarse'`` to set the coarse solver KSP.

This PC also inspects optional arguments supplied in the application context:
- ``'discrete_gradient'`` for problems in H(curl), this sets the arguments
(a Mat tabulating the gradient of the auxiliary H1 space) and
keyword arguments supplied to ``PETSc.PC.setBDDCDiscreteGradient``.
- ``'divergence_mat'`` for 3D problems in H(div), this sets the Mat with the
assembled bilinear form testing the divergence against an L2 space.

Notes
-----
Currently the Mat type IS is only supported by FDMPC.

"""

_prefix = "bddc_"

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

V = get_function_space(dm)

# 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)

opts = PETSc.Options(bddcpc.getOptionsPrefix())
if V.ufl_element().variant() == "fdm" and "pc_bddc_use_local_mat_graph" not in opts:
# Disable computation of disconected components of subdomain interfaces
opts["pc_bddc_use_local_mat_graph"] = False

ctx = get_appctx(dm)
bcs = tuple(ctx._problem.bcs)
if V.extruded:
boundary_nodes = numpy.unique(numpy.concatenate(list(map(V.boundary_nodes, ("on_boundary", "top", "bottom")))))
else:
boundary_nodes = V.boundary_nodes("on_boundary")
if len(bcs) == 0:
dir_nodes = numpy.empty(0, dtype=boundary_nodes.dtype)
else:
dir_nodes = numpy.unique(numpy.concatenate([bcdofs(bc, ghost=False) for bc in bcs]))
neu_nodes = numpy.setdiff1d(boundary_nodes, dir_nodes)

V.dof_dset.lgmap.apply(dir_nodes, result=dir_nodes)
dir_bndr = PETSc.IS().createGeneral(dir_nodes, comm=pc.comm)
bddcpc.setBDDCDirichletBoundaries(dir_bndr)

V.dof_dset.lgmap.apply(neu_nodes, result=neu_nodes)
neu_bndr = PETSc.IS().createGeneral(neu_nodes, comm=pc.comm)
bddcpc.setBDDCNeumannBoundaries(neu_bndr)

appctx = self.get_appctx(pc)
sobolev_space = V.ufl_element().sobolev_space

tdim = V.mesh().topological_dimension()
degree = max(as_tuple(V.ufl_element().degree()))
if tdim >= 2 and V.finat_element.formdegree == tdim-1:
B = appctx.get("divergence_mat", None)
if B is None:
from firedrake.assemble import assemble
d = {HCurl: curl, HDiv: div}[sobolev_space]
if V.shape == ():
make_function_space = FunctionSpace
elif len(V.shape) == 1:
make_function_space = VectorFunctionSpace
else:
make_function_space = TensorFunctionSpace
Q = make_function_space(V.mesh(), "DG", degree-1)
b = inner(d(TrialFunction(V)), TestFunction(Q)) * dx(degree=2*(degree-1))
B = assemble(b, mat_type="matfree")
bddcpc.setBDDCDivergenceMat(B.petscmat)
elif sobolev_space == HCurl:
gradient = appctx.get("discrete_gradient", None)
if gradient is None:
from firedrake.preconditioners.fdm import tabulate_exterior_derivative
from firedrake.preconditioners.hiptmair import curl_to_grad
Q = FunctionSpace(V.mesh(), curl_to_grad(V.ufl_element()))
gradient = tabulate_exterior_derivative(Q, V)
corners = get_vertex_dofs(Q)
gradient.compose('_elements_corners', corners)
grad_args = (gradient,)
grad_kwargs = {'order': degree}
else:
try:
grad_args, grad_kwargs = gradient
except ValueError:
grad_args = (gradient,)
grad_kwargs = dict()

bddcpc.setBDDCDiscreteGradient(*grad_args, **grad_kwargs)

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)


def get_vertex_dofs(V):
W = FunctionSpace(V.mesh(), restrict(V.ufl_element(), "vertex"))
indices = get_restriction_indices(V, W)
V.dof_dset.lgmap.apply(indices, result=indices)
vertex_dofs = PETSc.IS().createGeneral(indices, comm=V.comm)
return vertex_dofs
Loading
Loading