Remember jayste, you asked. Danno1, your answer is correct; however it doesn't scratch the surface.
Let's take Thermo Dynamics as it applies to trains. The Ideal Gas law; PV=nTR or rewritten as PV/T=nR where nR is a constant and may be written for two conditions [1] and [2] P1V1/T1 = P2V2/T2. Ok, now what? Do you have an Air Compressor? Air enters the compressor at state 1, Pressure 1, Volume 1, and Temperature 1. When the piston moves to the top of its stroke the pressure is P2, volume is V2 at temperature T2. P2 will be greater than P1, T2>T1 and V1>V2. The ratio must be satisfied and predicts the values of P, T, and V of condition 2 starting from condition 1. So now you know why your compressor gets hot. I can't write the mathematical expression with this format in word, but here is a problem that relates to our discussion.
Ten lbs. of air is compressed from 14.696 psi atmospheric and 60 deg F to 60 psi gauge when the barometer is 14.696 psi atmospheric. Find the horsepower to drive the compressor.
a) the initial volume of ten pounds of air is calculated from the Ideal Gas Law;
b) V1= 10 lb. x 53.35 ft-lb/lb R x [60 +460] R / [ 12in x 12 in x 14.696 psf]= 131.0 cubic feet of air. Adding 460 converts the temperature to absolute or Rankin temperature
c) The final pressure is P2= 14.696 + 60 = 74.696 psi absolute. Adding 14.696 converts gauge pressure to absolute pressure.
d) The final volume V2= 10 lb. x 53.35 ft-lb/lb R x [60 +460] R / [ 12in x 12 in x 74.696 psf]= 25.8 cubic feet of air.
e) The Work to run the compressor is P1V1 log V2/V1 or 14.696 x 12 x 12 x 131 x log 28.8/131.0 = - 450,000 ft-lb of work.
f) Hp = work/ 33,000 = -450,000/33,000 or 13.6 hp to run the compressor.
Now this is using the Ideal Gas Law, there are other expressions that are more accurate and more complex.
This is also the fundamental beginnings of other thermal processes, Diesel Cycle, Otto Cycle, jet Cycle.
The nR is the stuff that is the working fluid [air], R is the constant that relates to that fluid, Air is 53.35, steam 85.81, co2 35.13.
N is the number of molecules in the fluid. However it is not that simple, when you have a chemical reaction, combustion than n is a chemical term, moles and much more complex.
So now what do we do with all this compressed air? Air Breaks, in a train yard it's used to move Switch Tracks. Internal combustion engines lose Hp as they gain altutide, at 7,500 feet only 75% hp is available relative to see level. How to get it back? Turbocharger the engine.
Stress Analysis; that is simple too, it pertains to every component in the train that must carry a load or resist a force.
Let's take an axel. The axle must support the weight of the car or engine. Lets say the shear force to fail the axel is 120,000 psi of the cross sectional area of the axel. An axel 10 inches in diameter is 78.5 sq in. 120,000 x 78.5 =9,420,000 lb. or 4710 tons. That's over simplified because 1) there is no safety factor and 2) every half turn of the axel the applied force changes direction. Use a safety factor of 10 and the maximum load is 4710/10 or 470 tons. Take into account spinning the axel and reversing the load and we need to de-rate the load again by 10, now the maximum load is 47 tons. Need to carry more load? Use more axles. BTW, where does the axel load end up? On the rail, more stress, and then where? The track ties and the ground/ballast.
Hope that gives you more insight to the problems.