DrAmine
Ansys Employee

As mentioned in the beginning of this thread: As Ansys Employee I do not debug User Defined Functions. 

I am not able to see any issues with your UDF, though I prefer accessing the phase domain being solved but that should even work in your case. Your UDF should work and as mine is working and looking very much the same. My testing case is 2D with some more cells than your 1D looking case.