Hello Kala, You shall firstly develop a one-dimensional/phenomenological model for the entire engine cycle.
So, you can use a simple flow trough the valves (like that shown in Heywood's book) and then gets the temperature of the work fluid when it is passing the exhausts valve exit. If you wanna, I could send you my Master Dissertation and some matlab codes for your appreciation. I have developed a set of diferential equations and the interative solve used was the 5th Order Runge-Kutta method for great stability.
In the Richard Stone's book you can find a simplified model that teaches you to match the engine with the turbocharger. It is fun!!!