Skip to content

BUG: EquationBC not compatible with geometric multigrid #4295

Open
@KarsKnook

Description

@KarsKnook

EquationBC is not compatible with geometric multigrid because firedrake/mg/ufl_utils.py assumes DirichletBC.

MFE:

from firedrake import *

mesh = UnitSquareMesh(10,10)
mesh_hierarchy = MeshHierarchy(mesh, 1)
mesh = mesh_hierarchy[-1]

V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
v = TestFunction(V)

F = (inner(grad(u), grad(v)) + inner(u, v)) * dx
F -= inner(Constant(1), v) * dx

bcs = [EquationBC(inner(u, v) * ds == 0, u, "on_boundary", V=V)]

sp = {
    "pc_type": "mg",
}

NLVP = NonlinearVariationalProblem(F, u, bcs=bcs)
NLVS = NonlinearVariationalSolver(NLVP, solver_parameters=sp)
NLVS.solve()

Error:

Traceback (most recent call last):
  File "petsc4py/PETSc/PETSc.pyx", line 348, in petsc4py.PETSc.PetscPythonErrorHandler
  File "petsc4py/PETSc/PETSc.pyx", line 348, in petsc4py.PETSc.PetscPythonErrorHandler
  File "petsc4py/PETSc/PETSc.pyx", line 348, in petsc4py.PETSc.PetscPythonErrorHandler
  [Previous line repeated 5 more times]
  File "petsc4py/PETSc/petscdmshell.pxi", line 239, in petsc4py.PETSc.DMSHELL_Coarsen
  File "petsc4py/PETSc/Log.pyx", line 188, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 189, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/scratch/knook/firedrake/src/firedrake/firedrake/dmhooks.py", line 433, in coarsen
    cctx = coarsen(ctx, coarsen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/functools.py", line 909, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/knook/firedrake/src/firedrake/firedrake/mg/ufl_utils.py", line 276, in coarsen_snescontext
    for val in chain(coefficient_mapping.values(), (bc.function_arg for bc in problem.bcs)):
  File "/scratch/knook/firedrake/src/firedrake/firedrake/mg/ufl_utils.py", line 276, in <genexpr>
    for val in chain(coefficient_mapping.values(), (bc.function_arg for bc in problem.bcs)):
                                                    ^^^^^^^^^^^^^^^
AttributeError: 'EquationBC' object has no attribute 'function_arg'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/knook/Documents/thermal_OSM/dumbbell/2D/MFE_EquationBC_GMG.py", line 22, in <module>
    NLVS.solve()
  File "petsc4py/PETSc/Log.pyx", line 188, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 189, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/scratch/knook/firedrake/src/firedrake/firedrake/adjoint_utils/variational_solver.py", line 104, in wrapper
    out = solve(self, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/knook/firedrake/src/firedrake/firedrake/variational_solver.py", line 330, in solve
    self.snes.solve(None, work)
  File "petsc4py/PETSc/SNES.pyx", line 1724, in petsc4py.PETSc.SNES.solve
petsc4py.PETSc.Error: error code -1
[0] SNESSolve() at /scratch/knook/firedrake/src/petsc/src/snes/interface/snes.c:4839
[0] SNESSolve_NEWTONLS() at /scratch/knook/firedrake/src/petsc/src/snes/impls/ls/ls.c:221
[0] KSPSolve() at /scratch/knook/firedrake/src/petsc/src/ksp/ksp/interface/itfunc.c:1075
[0] KSPSolve_Private() at /scratch/knook/firedrake/src/petsc/src/ksp/ksp/interface/itfunc.c:826
[0] KSPSetUp() at /scratch/knook/firedrake/src/petsc/src/ksp/ksp/interface/itfunc.c:415
[0] PCSetUp() at /scratch/knook/firedrake/src/petsc/src/ksp/pc/interface/precon.c:1071
[0] PCSetUp_MG() at /scratch/knook/firedrake/src/petsc/src/ksp/pc/impls/mg/mg.c:976
[0] DMCoarsen() at /scratch/knook/firedrake/src/petsc/src/dm/interface/dm.c:3327

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions