Bug with MeshValueCollection (v 2019.2.dev0)?

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.

Without having the file that you are reading, it is hard to do anything further with this. To me it Seems like you are trying to read something that has a different datastyre (dtype) than you are trying to read in.

In DOLFINx MeshValueCollection has been replaced with MeshTags. It is a new implementation, so it is unlikely that a similar bug would be present (if it indeed is a bug).

Hi Dokken,

I am attaching a sample mesh using which this bug can be noticed. It is a 4x4x4 cube with 3 subdomains.

I wanted to report in case someone is using the same method I am using and may not have seen this issue. I am not sure if it could be a problem with the build I am using.

Best regards,