Hi all,
I wanted to report a bug with the MeshValueCollection function.
I was trying to read cell data from the input mesh that marks a domain initially using:
mesh_file = XDMFFile(MESH_FILE_NAME)
mesh = Mesh()
mesh_file.read(mesh)
Dim = mesh.topology().dim()
MATID = MeshValueCollection("size_t", mesh, Dim)
mesh_file.read(MATID, "Mat ID")
domainMarks = MeshFunction("size_t", mesh, MATID)
domainMarks.rename("Mat ID","label")
But somehow the MeshValueCollection a value that was originally for example 3, when read becomes 2.
I dug a bit deeper, and when I used “double” in the MeshValueCollection, 3 was read as 2.99999995 and when using “size_t” or “int”, it rounded it to 2.
So now instead of the above code I am using the following:
mesh_file = XDMFFile(MESH_FILE_NAME)
mesh = Mesh()
mesh_file.read(mesh)
Dim = mesh.topology().dim()
MATID = MeshValueCollection("double", mesh, Dim)
MATID_int = MeshValueCollection("size_t", mesh, Dim)
mesh_file.read(MATID, "Mat ID")
mesh_file.read(MATID_int, "Mat ID")
for ii in range(MATID.size()):
MATID_int.set_value(ii,0,round(MATID.get_value(ii,0)))
domainMarks = MeshFunction("size_t", mesh, MATID_int)
domainMarks.rename("Mat ID","label")
I am using 2019.2.dev0 version. I am not sure if the function exists or was fixed in DolfinX.