Simulation of Compressed Air Driven Piston

I am writing a MATLAB script that generates a dynamic simulation of a piston being driven by compressed air. My starting values for pressure and volume are as follows:

P0 = 14000000; %nm-2 or 140 Bar
V0 = 0.005; %m3 or 500cc

The simulation needs to be quite detailed and must take into account the following factors:

1. Force required to open the valve (assume hammer type)
2. Duration valve will remain open
3. Flow rate from valve and change over time
4. Expansion into transfer port over time
5. Force imparted to piston
6. Account for inertia and friction to move piston
7. Expansion into cylinder over time
8. Velocity, mass and force of air over time

I suppose this is a lot to ask in one post, but I have made a start on this. I will run through the sequence of events and describe the formulas I have, or have identified so far.

The process begins with a hammer striking a valve to open the seal. This can be modeled as a collision over time and a series of forces (force of hammer, force of spring sealing valve and force of air pressure inside valve):

We can then calculate the distance the valve seal will move and compare that with size/volume of the valve opening.

This then leads to air rushing into the valve and where the equation begin to become complex. I think I can model this as a flow through an orifice. As such, I have identified the following formulas (MATLAB comments):