I am trying to solve a simple 2d Poisson equation with **constant** Dirichlet boundary conditions (u = 0 on boundaries) but don’t find the correct way to set the bc. If, like the tutorial I choose a varying function there is no issue.

uD = fem.Function(V)

uD.interpolate(lambda x: 1 + x[0]**2 + 2 * x[1]**2)

But how can I make it constant? For example using

u_D = fem.Constant(domain, ScalarType(0))

gives an error.

import ufl

import numpy as np

from mpi4py import MPI

from petsc4py import PETSc

from dolfinx import mesh, fem, io, nls, log, plot

from petsc4py.PETSc import ScalarType

nGrid = 10

domain = mesh.create_unit_square(MPI.COMM_WORLD, nGrid, nGrid)

Vh = fem.FunctionSpace(domain, (“CG”, 1))

dofs_L = fem.locate_dofs_geometrical(Vh, lambda x: np.isclose(x[0], 0)) # where x=0

u_L = fem.Constant(domain, ScalarType(0))

bc_L = fem.dirichletbc(u_L, dofs_L)