Very small difference between tabulate_dof_coordinates and geometry.x

There is a very small difference between the coordinates of vertices, if one calculates them via tabulate_dof_coordinates() or via mesh.geometry.x. Cf. this minimal working example

import numpy as np
import dolfinx as dfx
from mpi4py import MPI

mesh = dfx.mesh.create_unit_cube(MPI.COMM_WORLD, 2,2,2, dfx.mesh.CellType.tetrahedron)
V = dfx.fem.functionspace(mesh, ("Lagrange", 1))
f = dfx.fem.Function(V)
f.interpolate(lambda x: 1 + x[0]**2 + x[1]**2 + x[2]**2)
dof_coordinates = V.tabulate_dof_coordinates()
mesh_coordinates = mesh.geometry.x
maximal_difference = np.max(np.abs(dof_coordinates - mesh_coordinates))

print(maximal_difference)

which returns 2.220446049250313e-16.

Why does this happen?

See, for example, Machine epsilon - Wikipedia.

This has also been discussed to some length at:

2 Likes

Thank you very much for the explanation!