DirichletBC with mesh tags in dolfinx - weird behavior

Dear @marchirschvogel,

Next time, please supply a minimal working example (MWE), as with these few snippets, one had extra code to get your example to run.

To debug your Dirichlet condition, consider the following code:

import dolfinx
import dolfinx.io
import dolfinx.fem
from mpi4py import MPI
encoding = dolfinx.io.XDMFFile.Encoding.ASCII
comm = MPI.COMM_WORLD
with dolfinx.io.XDMFFile(comm,'mesh.xdmf','r',encoding=encoding) as infile:
        mesh = infile.read_mesh("Grid")
mesh.topology.create_connectivity(mesh.topology.dim-1, mesh.topology.dim)
with dolfinx.io.XDMFFile(comm,'input_boundary.xdmf','r',encoding=encoding) as infile:
     mt_s = infile.read_meshtags(mesh, "Grid_surf")

V = dolfinx.VectorFunctionSpace(mesh, ("CG",1))
uh = dolfinx.Function(V)
uh.vector.set(1.0)

dbc = dolfinx.DirichletBC(uh, dolfinx.fem.locate_dofs_topological(V, 2, mt_s.indices[mt_s.values == 1]))
u2 = dolfinx.Function(V)
dolfinx.fem.set_bc(u2.vector, [dbc])
outfile = dolfinx.io.XDMFFile(comm, "u2.xdmf", "w")
outfile.write_mesh(mesh)
outfile.write_function(u2)
outfile.close()

Here I set all vectorial values at your boundary to 1, therefore a vector with magnitude \sqrt{3}. This can be confirmed by visualizing the output function in for example Paraview.

1 Like