I recommend having a look into the customization manual.
What I understand here is that the the UDF has to be applied on non Fluid thread? Is this expected?
You forgot a thread loop of all threads in the domain if you are not focusing on certain thread ID.