How to define spatially varying materials

Yes, I have tried to learn that case by the access you provided. The reordered mapping of nodes can truly be obtained. I also checked that the element order was still unchanged, the only changes happened in the nodes order.

But the question is that I have Initial information of value list for each element arranged by the element index. I don’t know why it went wrong when I assigned the values to the function and conducted the output. I thought I have found the answer before by the access How to assign different material properties to elements (Linear Elasticity) But after I tried to perform my adapted code. The results were unsatisfactory (Fig.4). It indeed assigned the value to the corresponding element, but the element was wrong. It actually changed the element id instead of assigning the value to the correct element.

I just don’t know why the value is mismatched with the mesh after I write output. Sorry, I’m extremely confused.

The msh file of this minimal example is attched here. I just want to assign the value [1,2,3,4,5,6,7,8] respectively to the 1st,2nd,3rd… element in the msh file.

Thanks a lot!