Hi dokken, here is an example as what I mentioned before. In this script, I tried to generate and save a simple mesh with hexahedral elements and then use this mesh file again to check if there is any change.
import numpy as np
from mpi4py import MPI
from dolfinx import Function, FunctionSpace, Constant, BoxMesh, VectorFunctionSpace
from dolfinx.io import XDMFFile
# Create the mesh file
Mesh =BoxMesh(
MPI.COMM_WORLD, [np.array([-0.5, -5, 0]),
np.array([0.5, 5, 0.5])], [2, 2, 2],
CellType.hexahedron, dolfinx.cpp.mesh.GhostMode.none)
# Save solution in XDMF format
with XDMFFile(MPI.COMM_WORLD, "mesh_hex.xdmf", "w") as file:
file.write_mesh(Mesh)
def expr(x):
return x[0] + x[1] + x[2]
# use "Mesh" to generate function u
W = FunctionSpace(Mesh, ("Lagrange", 1))
w = Function(W)
w.interpolate(expr)
vertex_w = w.compute_point_values()
print(vertex_w)
# use "mesh" to generate function u
with XDMFFile(MPI.COMM_WORLD,"mesh_hex.xdmf", "r") as infile:
mesh = infile.read_mesh(name = "mesh")
U = FunctionSpace(mesh, ("Lagrange", 1))
u = Function(U)
u.interpolate(expr)
vertex_u = u.compute_point_values()
# compare the difference
print(vertex_u - vertex_w)
print(np.linalg.norm((vertex_u - vertex_w)))
with XDMFFile(MPI.COMM_WORLD, "test_hex.xdmf", "w") as out_file:
out_file.write_mesh(mesh)
out_file.write_function(u)
And the difference of the two functions is not zero, which looks weird to me. Thanks in advance for your any comments.