Hi,
I suggest you to please check forum discussion on opening and closing of valve which is done using udf: https://forum.ansys.com/forums/topic/how-to-do-a-udf-to-simulate-the-opening-and-closing-of-compressor-valves/
Hope you will find this useful.
Thank you.