Skip to content

Knook/EquationBC_GMG #4338

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

Draft
wants to merge 4 commits into
base: release
Choose a base branch
from
Draft

Knook/EquationBC_GMG #4338

wants to merge 4 commits into from

Conversation

KarsKnook
Copy link
Contributor

Necessary code to get geometric multigrid working with EquationBC.

MFE:

from firedrake import *

mesh = UnitIntervalMesh(10)
mesh_hierarchy = MeshHierarchy(mesh, 1)
mesh = mesh_hierarchy[-1]
x = SpatialCoordinate(mesh)

V = FunctionSpace(mesh, "CG", 1)
print(f"# DoFs = {V.dim()}")
u = Function(V)
v = TestFunction(V)

f = pi**2 * sin(pi * x[0])  # gives exact solution u = sin(pi*x)
F = (inner(grad(u), grad(v)) - inner(f, v)) * dx

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

sp = {
    "snes_monitor": None,
    "ksp_monitor": None,
    #"pc_type": "lu",
    #"pc_factor_mat_solver_type": "mumps",
    "pc_type": "mg",
    "mg_coarse": {
        "ksp_monitor": None,
        "pc_type": "lu",
        "pc_factor_mat_solver_type": "mumps",
        },
    "mg_levels": {
        "ksp_monitor": None,
        "ksp_type": "richardson",
        "pc_type": "none",
        },
}

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

@connorjward
Copy link
Contributor

If this is a bugfix this should likely go into release, not master. In particular notice the large number of extra commits that are erroneously included here.

Also if you have an MFE that this fixes then please include some sort of test.

@KarsKnook KarsKnook changed the base branch from master to release May 26, 2025 10:00
@KarsKnook KarsKnook force-pushed the knook/EquationBC_GMG branch from a00a90a to 2d8da62 Compare May 26, 2025 11:41
@@ -488,6 +488,7 @@ class EquationBC(object):
def __init__(self, *args, bcs=None, J=None, Jp=None, V=None, is_linear=False, Jp_eq_J=False):
from firedrake.variational_solver import check_pde_args, is_form_consistent
if isinstance(args[0], ufl.classes.Equation):
self.function_arg = firedrake.Constant(0) # so line 286 of mg/ufl_utils.py runs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 286 ufl_utils.py should extract the Functions from the Form in EquationBC

@@ -311,7 +321,8 @@ def mult(self, mat, x, y, inc=False):
x.copy(v)
self.manager.prolong(self.cprimal, self.fprimal)
for bc in self.fbcs:
bc.zero(self.fprimal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BCBase or EquationBC should implement zero()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants