This is because setting dof values to a RT array doesn’t really make sense.
You should be quite careful with this, as the degrees of freedom relate to vector basis functions.
Here is a way to illustrate the same, but with an actually well defined function (the constant vector (2,1,3), you could change this to (1,1,1) if you want to)
# # Using Dolfinx
try:
import dolfinx as dlfx
from mpi4py import MPI
import ufl
import numpy as np
def f(x):
values = np.zeros((3, x.shape[1]))
values[0] = 2
values[1] = 1
values[2] = 3
return values
mesh_dlfx = dlfx.mesh.create_unit_cube(MPI.COMM_WORLD,
10,
10,
10,
dlfx.mesh.CellType.tetrahedron)
V_dlfx = dlfx.fem.functionspace(mesh_dlfx, ("RT", 1))
f_dlfx = dlfx.fem.Function(V_dlfx)
f_dlfx.interpolate(f)
vol_dlfx = dlfx.fem.assemble_scalar(dlfx.fem.form(
dlfx.fem.Constant(mesh_dlfx, 1.0) * ufl.dx))
res_dlfx = dlfx.fem.assemble_scalar(
dlfx.fem.form(ufl.dot(f_dlfx, f_dlfx)**(1/2) * ufl.dx))
print("dolfinx")
print(f"{vol_dlfx=}")
print(f"{res_dlfx=}")
except ImportError:
# Using Dolfin
import dolfin as dlf
mesh_dlf = dlf.BoxMesh(dlf.Point(0.0, 0.0, 0.0),
dlf.Point(1.0, 1.0, 1.0),
10, 10, 10)
V_dlf = dlf.FunctionSpace(mesh_dlf, "RT", 1)
f_dlf = dlf.Function(V_dlf)
f_dlf.interpolate(dlf.Expression(("2", "1", "3"), degree=1))
vol_dlf = dlf.assemble(dlf.Constant(
1) * dlf.Measure('dx', domain=mesh_dlf))
res_dlf = dlf.assemble(dlf.dot(f_dlf, f_dlf)**(1/2) * dlf.dx)
print("legacy dolfin")
print(f"{vol_dlf=}")
print(f"{res_dlf=}")
yields
dolfinx
vol_dlfx=0.9999999999999232
res_dlfx=3.7416573867708562
and
legacy dolfin
vol_dlf=0.9999999999999232
res_dlf=3.74165738677434