If its not homework most cost friendly option would be to hire a consultant
However, principle:
Find an ethanlphy and an entrophy diamgram (or table) for air
For each tank calculate initial mass of air
For each tank assume constant mass entrophy
For valves assume constant enthalphy
Break into time steps (e.g spread sheet)
For each timestep:
1) Calculate flow for each valve based on initial conditions
2) Calculate mass in each vessel at end of timestep.
3A) For vessel 1 From new mass in vessel you now know new density (because the volume dosnt change and you know the "new" mass) - use constant entrophy to calculate final temperature for expanding gas in vessel (or compression if the density in tank 2 increases) and pressure
3B) For vessel B: First step only consider the initial mass in the vessel and the mass that was removed. Knowing the "final mass" (when disregarding the mass entering from vessel 1) use this to calculate the density and then the temperature of the gas assuming constant entrophy and the presasure
4) Find the temperature after valve 1 (constant enthophy) during the timestep (assume constant initial conditions)
5) calculate the "actual" temperature of tank 2 by using the final mass and temperature for step 3B adding the mass transferred with the known temperature from 4) but at the pressure found stp 3B
6) Calculate the final "density" - when considering the gas entering tank 2 and again use the constant entrophy to calculate the final temperature and pressure in tank 2
7) repeat and make sure you time steps are small enough for the assumptions that things are constant throughout each timestep.
The procedure assumes that the air is dry - taking condensing water into account is a bit more difficult...
The main assumption in this methodology is that the mass transfer is constant throughout the timestep from tank 1 to tank 2 and from tank 2 to atm and equal to the flow at the conditions at the start of each timestep. Therefore you must choose your timesteps wisely. A table for the air properties will be easier (use look-up in excel)
Best regards, Morten