Defining a subdomaim from cell data

Hello everyone. Appreciate any help.

I have a vtk mesh with contains a scalar number for each cell. Those numbers (scalars) are used to define subdomains. In a simple way, they are 1,3 or 4. So I have ordered for each cell this parameter (scalar). What I did so far is to save it in a .txt format.

I need help to define subdomains after loading the mesh. In a few words, I want to load the mesh (.xml or .xdmf format), read my .txt file, and create 2 subdomains: one if the respective cell the ID is 1, another if the specific cell is different from 1 (3 or 4).

I’ll try to illustrate below:

Here is my mesh:

Those are my IDs (scalars for subdomains):

I have each scalar (ID) saved for each cell number. So, I think I have to load the .txt data with the ID date and loop each cell assigning the respective ID.

My question is: how can I loop and assign my .txt data to each respective cell data?

Appreciate any help

I would suggest using meshio, as for instance explained in this post: Accessing and marking imported boundaries - #8 by dokken
Here, you can replace: cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
with the read in array (assuming that it is ordered in the same way as the VTK file and cells), and convert it to XDMF (including the cell markers), which in turn can be read into Dolfin as shown for instance in:
Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio - #3 by dokken