Sunday, July 13, 2014

simulations - How do I simulate an ideal gas?


I wish to write a simple simulation of an ideal gas, but my maths and how I should have a model based the equation isn't quite up to it. I need some help understanding the relationship between pressure, the amount of the gas, and the temperature (the volume is a constant), not just at one moment, but as one or more of the variables change...


Right now, I have global variables for P, T and n, and an update loop in my code where I check to see if T has changed. If so, I can solve the ideal gas equation P=nRT/V as the others are unchanged. The results look ok to me. I can warm the tank, and the pressure rises.


Now, if I add or remove some gas, by changing n, I am unsure how to change both P and T. If I just recalculate P, I can remove gas until the pressure falls to 0, yet the temp remains constant the whole time. This doesn't seem right, shouldn't there be some temperature drop too?


Can you explain how I should go about improving this simulation?




No comments:

Post a Comment

classical mechanics - Moment of a force about a given axis (Torque) - Scalar or vectorial?

I am studying Statics and saw that: The moment of a force about a given axis (or Torque) is defined by the equation: $M_X = (\vec r \times \...