Consider the short MWE :
import ufl
import dolfinx as dfx
from dolfinx.io import XDMFFile
from mpi4py.MPI import COMM_WORLD
with XDMFFile(COMM_WORLD, "mesh.xdmf", "r") as file:
mesh = file.read_mesh(name="Grid")
FE=ufl.FiniteElement("Lagrange",mesh.ufl_cell(),1)
V = dfx.FunctionSpace(mesh,FE)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
#r = ufl.SpatialCoordinate(mesh)[1]
r = dfx.Function(V)
r.interpolate(lambda x: x[1])
n = ufl.inner(u,v)*r**2*ufl.dx
N = dfx.fem.assemble_matrix(n)
N.assemble()
x, y = N.createVecs()
x.set(1)
N.mult(x,y)
t = dfx.Function(V)
t.vector[:]=y
with XDMFFile(COMM_WORLD, "sanity_check_N_dummy_test.xdmf","w") as xdmf:
xdmf.write_mesh(mesh)
xdmf.write_function(t)
I was expecting a smooth square going from 0 at the bottom to max at the top. Instead I get :
The mesh is here. I strongly suspect it could be the source of the error since I couldn’t reproduce that error with a mesh=dfx.generation.UnitSquareMesh(COMM_WORLD,100,100)
. But that gives me no hint on how to fix the original mesh…
This is a non-uniform structured mesh of quads originally generated using gmsh
, then put through an entire ordeal, but it still looks fine to me. Besides, I’m surprised the code doesn’t fail at reading if something is really wrong with the code.
Does anyone have an idea as to the root cause of the problem ?