Hello,
I am trying to impose BCs using Lagrange multipliers similar to some old posts:
Imposing bcs using Lagrange Multiplier
Applying a constraint using a Lagrange multiplier dolfinx
How to specify Lagrange Multiplier on a boundary?
However, non of them were solved. I’ve tried running all of the similar post’s MWE, with no luck, and combinations of each approach. Right now, my MWE is modified from the fundamentals code tutorial. Following all of the other approaches, I attempted to apply Lagrange multiplier constraints with a mixed finite element formulation. I also tried treating the constraint space two ways: 1. as the full domain mesh, with boundary integrals specified in the weak form, and 2. on a mesh derived from the boundary facets. The MWE code is:
from mpi4py import MPI
from dolfinx import mesh
import numpy
from dolfinx import mesh, fem,plot
import ufl
from mpi4py import MPI
from petsc4py import PETSc
from petsc4py.PETSc import ScalarType
import pyvista
from dolfinx.fem import FunctionSpace
import numpy
# Create mesh and boundary mesh
domain = mesh.create_unit_square(MPI.COMM_WORLD, 8, 8, mesh.CellType.quadrilateral)
tdim = domain.topology.dim
fdim = tdim - 1
domain.topology.create_connectivity(fdim, tdim)
boundary_facets = mesh.exterior_facet_indices(domain.topology)
boundEdges = mesh.meshtags(domain,fdim,boundary_facets,55)
boundDomain = boundEdges.mesh
# define mixed finite element space
P1 = ufl.FiniteElement("Lagrange", domain.ufl_cell(), 1)
P1b = ufl.FiniteElement("Lagrange", boundDomain.ufl_cell(), 1)
V, LG = fem.FunctionSpace(domain, P1), fem.FunctionSpace(boundDomain, P1b)
M = ufl.MixedElement([P1, P1])
# mixed space and test+trial functions
W = fem.FunctionSpace(domain, M)
u, lg = ufl.TrialFunctions(W)
v, mu = ufl.TestFunctions(W)
# boundary condition for weak enforcement
uD = fem.Function(V)
uD.interpolate(lambda x: 1 + x[0]**2 + 2 * x[1]**2)
# weak form
f = fem.Constant(domain, ScalarType(-6))
a = ufl.dot(ufl.grad(u), ufl.grad(v)) * ufl.dx + ufl.inner(v,lg)*ufl.ds + u*mu*ufl.ds
L = f * v * ufl.dx+ mu*uD*ufl.ds
# solve
problem = fem.petsc.LinearProblem(a, L)
uh = problem.solve()
us, lgs = uh.split()
lgs.x.array
and outputs Infs. Also, in the lines defining the function spaces, I’ve also tried with:
# define mixed finite element space
P1 = ufl.FiniteElement("Lagrange", domain.ufl_cell(), 1)
P1b = ufl.FiniteElement("Lagrange", boundDomain.ufl_cell(), 1)
V, LG = fem.FunctionSpace(domain, P1), fem.FunctionSpace(boundDomain, P1b)
M = ufl.MixedElement([P1, P1b]) # change here in lagrange multiplier space
Does anyone have suggestions or know the solution? Thanks!!