"That their main business was not put into the mind knowledge which was not there before, but to turn the mind's eye towards light so that it might see for itself."
...Plato's advice to educators(429-347BC)

I am not familiar with MathLab, but I believe it can be done. You need to define your model (variables/relations/constraints) and write the code to deal with it. If you are familiar with MathLab, you should be able to learn EJS very quickly! You can check out SWF movie show step by step instructions to create java simulation with EJS to know what EJS can help you.

I really like your application but would be interested in something similar but different. I am interested in the mixing potentials of different gasses under ambient pressure. I'd really like a application that simulates the behaviour of three different gasses in a fixed volume over time.

lets say three hypothetical gasses: Gas A, Gas B and Gas C. Effectively running your application in three different colours in the same volume.

Inputs

The size and shape of the container (2 dimensions is fine), The mass of the gas molecules, A B and C (and or the gravitational effect buoyancy) The quantity of the individual gasses The over all energy of all the particles, i.e. temperature

I'd like to be able to monitor the system with respect to time from a random orientation

Particle particle interactions can for now be avoided to make the programming easier...

1. The size and shape of the container: I can add size as an input, but what do you mean by the shape of the container? Do you mean Square, Circle,... or just different width and height for rectangular shape? 2. The mass of the gas molecules, A B and C (and or the gravitational effect buoyancy) This can be done easily.

3. The quantity of the individual gasses: What is the range of for the number of particles? Remember collision need to be checked at least n*(n-1)/2 times.

4. The over all energy of all the particles, i.e. temperature Do you mean the average energy for all the particles?

Please provide possible range for all the physics properties, it will save me a lot of time and the result will be better fit with what you really want.

Size and shape. rectangular is good. would want to see the difference between a square container verses a tall thin rectangular one..

The number of particles would depend on the size and pressure. Could you maybe set Gas A as the basis that fills the remaining volume, and then allow for Gas B and C to be filled up to the whole volume as well. i.e. if the volume can hold 1000 molecules and you specify that Gas B has 100 molecules and Gas C has 200 then Gas A would be set to 700. ranges would then be 0-1000 for each B and C with A set automatically. Would be good to have as big a volume as is possible though I understand that the bigger the more complex the calculations. What sort of size would be reasonable? is 10 litres of space too much? 20L?

Temperature is the average temperature / energy of the molecules.

Would be good to be able to speed up the simulation of the time so a time factor could be written in to i.e. 1s = 1h in simulation time etc.

Physical properties: Gasses will be molecular mass 2-50. temp 200 K to 400K simulation time 0 s to few days. Three different colours for the different gasses, say Red, Blue, Yellow

Size would be rectangular from tall thin to wide flat as big as is reasonable, set by the volume. I'll run it direct off a PC so much more RAM for the calculations than off a website

I modified browian motion simulation to fit most of your request. The following is 1000 particles randomly distributed (position, velocity and direction). Number of three different particles are NA, NB and NC, there mass are ma,mb,mc The temperature T define the average velocity: V_{avg} proportional to sqrt(T/m)

The dimension of volume (e.g. 10 liters) is meanless if you mean to simulate a real volume. Because there are almost 10^{19} particles in 1 cm^{3}. Unless the colume is just used to calculate the pressure.

For the same reason, change the width/height of the container will not be able to represent real case.

There are limitation for the simulation: for example: in real world, most of the gas molecular moving with speed faster than speed of sound. And there are more than 10^{19} particles in 1 cm^{3}. if you want to visualize it. The particle can not move too fast on the screen.

The simulation has to be design in a proper way to show the effect. And for different purpose, it need to be designed differently.

Please write down the real problem you are studying and what kind of phenomena you are interested. May be we can find out a better way to simulate it. It might not be necessary to calculate the collision between particles, unless you want to study the energy transfer between particles. It will be better if you can write down the physics model of the system.

The following is the simulation I have created for you!

I'm trying to visualise how different gasses will separate out in different closed containers. e.g. if you had a container of air with some helium and some Argon, mass 29, 4, and 40 respectively, then the helium would settle out at the top of the container, air in the middle and argon at the bottom. I'm interested in how long this process would take is it minutes hours, days or weeks.

Is there a buoyancy effect on the force on each particle or is the mass only used to calculate the elastic collisions with other particles?

Each particle will have a downward force of 9.8 x real Mass. (Real mass = Mass x 1.66054 x 10E-27 Kg) the heavier molecules will therefore have a larger force pushing them down and will effectively settle out at the bottom first. (sorry if this is so obvious that it is already in the equations)

I think maybe the scale is so small that the particles are not given the space to settle and the proximity of the walls mean that the elastic collisions far out weigh the buoyancy differences of the gas molecules. If we were to define each dot as a unit volume of gas, say 1000 molecules, then the model would be considerably bigger and the distance between the walls would be significantly longer reducing the effect of the elastic collisions while the downward force would be considerably higher. in real terms 1000 molecules is a fraction of a fraction of a cm3 so easily justifiable as a modelling constraint.

Can you have a button to turn off the particle particle interactions? and see if they settle better with only particle-wall interactions.

Now, I understand more what you want for the simulation. There is no gravity in the previous version. I just added gravity (can be changed with slider) and also draw Y_{average} for three different particles. The difference between those three curves (Y_{average})are due to statistical error (because number of particles are not big enough).

More options are added. 1. Gravity g can be changed with slider. 2. Collision between particles can be turn off with check box. 3. The top boundary can be turn on/off.

The separation process will be faster if you un-check closetop check box. The above simulation has been updated with new version.

Hia. This is fantastic and beginning to look like I had envisaged..

Can I suggest a couple more alterations?

1) the particles now really clump at the bottom of the container with largely vacuum at the top. could we maybe change the gravity effect into a relative vertical component vector. By this I mean Ma =29 therefore relative to it's self it has a vertical force of 29/29 upwards and 29/29 downwards. Gas B has a upwards force of Ma/Mb and downwards force of Mb/Ma and Gas C has a upwards force of Ma/Mc and downwards Mc/Ma. This way lighter gasses will rise while Heavier gasses will fall. The space will be more uniformly filled without all the gas accumulating at the bottom..

The alternative is to incorporate some force of attraction towards the empty space that is higher for the smaller less dense molecules than it is for the heavier more dense molecules.. (this I think is quite a challenge..)

2) could you extend the temperature range to cover much lower temperatures. This will slow the particles down and might help to lower the significance of the P-P interactions while not affecting the gravitational forces.

1. Simulation can be done with different model. What is important is how make sense of the simulation. The gravity is the same (-g ) for all particles in the above simulation, because that what phyiscs tell me.

Quote

Ma =29 therefore relative to it's self it has a vertical force of 29/29 upwards and 29/29 downwards. Gas B has a upwards force of Ma/Mb and downwards force of Mb/Ma and Gas C has a upwards force of Ma/Mc and downwards Mc/Ma.

I do not understand the physics meaning of your model: 1. What do you mean by upward force and downward force? If particle A has the same upwards and downwards force, the net force is zero. Then, particle should move with constant velocity. 2. Why the download forces and upwards force are different for particle B/C? 3. Do you mean force or acceleration?

The temperature range can be change easily. However, the value of temperature slider (T) was used to calculate the initial average velocity for all the particles. It is not the real temperature when it reach equilibrium later on. In order to visualize the effect you want, the gravitation energy was set to a much larger value (compared to real gas under STP condition).

If you just want to have three different gas particles moving in different layer, it can be generated, too! However, it is far from real!

Do you really want to simulate some physical model you have? Or you just want to have some visualized effect? Are you using it for teaching purpose? What is the purpose to have such simulation?

For real gas: The separation between gas particles are much larger than the size of the particles. And there are 10^{19} particles in 1 cm^{3}.

A good model need to be designed properly to simulate real gas.

Hia, I'm after a good combination of visual effect and real science. I think i know what will happen in reality and I'm trying to form a model that will show what happens with a set of principles and constraints that can be argued from scientific first principles. The effect of gravity will not be the same on all particles as the force downwards will depend on the mass. the acceleration downwards might be uniform but there is also the buoyancy effect from the displacement of the other atoms as one falls due to gravity. The lighter gasses will rise to the top and the heavier gasses will sink to the bottom, relative to the mass of the main constituent of the volume. Setting the gravitational effect on gas A as uniformly up and down (i.e. no effect) was in my mind a way of simplifying the process to make the model appear more like the real situation. This should stop the appearance of a vacuum at the top and a dense cloud of gas at the bottom. The relative effects would be multiplied by the gravitational acceleration.

In effect the particle A should have no relative gravitational effect, B should have a positive effect in the upwards direction and C should have a positive effect in the down wards direction.

A balloon of helium has the potential to lift the amount of weight that is equal to the difference in mass of the volume of Helium and the mass of air that is displaced. There is therefore an upward force provided by each molecule that is equal to it's buoyancy or mass difference times the gravitational constant.

To explain this better 24 litres of helium would displace 24 litres of Air so the mass of the 24 litres would be 4gramms rather than 29gramms. There is therefore the potential to lift 25 grams so the overall force upwards is 0.025 x 9.8 N. mathematically this equates to (Mb-Ma/1000)*9.8 (negative = upwards, positive = downwards)

In the case of an individual molecule it would be (Mb-Ma)x1.66054 x 10E-27 X 9.8 N. again this would be negative for upwards and positive for downwards.

We can easily expand the area so that there is more space between the molecules if that helps the reality of the gas.

In a big enough system the gasses should separate out completely given enough time with only a small overlap in the "mixing region".

If I can get it to give the results I need with a reasonable level of scientifically sound assumptions then I'd like to use it in a lecture and a scientific paper. (Naturally you will be acknowledged.)

Here is another simulation with more options. ga,gb,gc to adjust gravity for different particles. gscale: adjust over all gravity scale vscale: adjust over all velocity (to change ratio between relative thermal energy and gravitation energy ) diameter: to change the collision rate.

I can not find the right parameters to show what you would like to see. May be some other factors need to be considered.

It seems that you are trying to using particle model to simulate fluid behavior. I think we need to find a better model to simulate what you want!

The above simulation is created with EJS. Please 1. download EJS and unzip it to c:\ 2. Click c:\Ejs4.2\EjsConsole.jar to test the installation (Your computer need to support java :assume java run time has been installed) 3. Download jar file from the link just below the simulation. 4. Double click downloaded jar file to tun it. 5. RIght click in the simulation and select "open EJS model" to open source code in EJS. 6. You can modify variables/ relations/GUI element and properties in the simulation and click run button to compile it.

If you need the source code for the simulation at the first post, just download idealGas.java However, it was written more than 10 years ago with JDK1.0.2.

I receive question related to this simulation as private message. [quote] Good morning, professor.

I have been using a model like this for my students.

My students learn that the "starting point" is 300 K, 100 kPa, 1.00 L, and approximately 0.040 moles of gas. If we use air, we find that the "average velocity" is something like 450 m/s, not 100 m/s. why is there a discrepancy between this simulation and the value that I've calculated?

The velocity of ideal gas depends on temperature and mass of the particle. The average velocity for hydrogen atom will be much larger than average velocity for oxygen atom. I did not specify temperature and mass of the particle in the simulation. The simulation was designed to show relation between number of particle N, pressure P and Volume V. You can ask student what is the initial temoerature if the simulation is for air. The temperature of the simulation is related to velocity. How to change the velocity so that it is can be used to simulate air at room temperature.

I just pick up simple number: N=200 P-50 V=100 without specify any unit for the above parameter. In reality, there is more than 10^{19} particle in 1 cm^{3}. There is no way to add so many particle in the simulation. The pressure is proportion to the number of objects on top of the movable piston.

Dear Professor , Can you please email me the 2nd collision simulation source code where you kept the volume constant. I tried downloading the files directly but it tells me that the files are corrupted. Do help me out

Hi Fu-Kwun Hwang, Bernoulli's equation (ignoring gravity) can be illustrated with a straight tube connected to a tapering tube connected to another straight tube, with pistons in the straight tubes. question 1: can this be simulated with an ideal gas between the pistons? question 2: is Bernoulli's equation true for an ideal gas? thanks for thinking about this.

question 1: can this be simulated with an ideal gas between the pistons?

Could you describe your model in more detail? I can not catch your ideas.

Quote

question 2: is Bernoulli's equation true for an ideal gas?

The Bernoulli's principle is valid for incompressible flows (e.g. most liquid flows) and also for compressible flows (e.g. gases) moving at low Mach numbers

basically, we're changing the shape of an ideal gas, keeping the volume the same. but we're looking at the process while it is happening, not a "before" and "after" situation. it's not clear that we can ignore the temperature. nor is it clear that the pressure on one piston is the same as the pressure on the wall of its corresponding straight tube section. nor is it clear that the density in the straight tube sections is the same.

i thought a simulation might help see what's happening. i have no idea if anyone has done this.

You can add text in between [code] and [/code] to keep space in the text. (I have already modified your text for you. :-)

Bernoulli's equation is valid for steady fluid which can be represented by stream lines.

It is a different situation you have pistons on both side of the tube: this is a closed system.

We can use fluid model to simulate gas flow when the mean free path is much smaller than the size of the tube. (fluid dynamics)

The molecular model can be used when the mean free path is smaller than the size of the tube, and this is a good time to use particles to simulate the situation. (However, a lot of computational power is needed: to simulate large number of particles!)

If you are talking about the simulation at the first post: then the umber of particles are 200 as default and can be changed from user input. The pressure was calculated by momentum change per second. Because there are limited number of particles so that the pressure change over time. In real case, it will be more than particles per center meter square.

"That their main business was not put into the mind knowledge which was not there before, but to turn the mind's eye towards light so that it might see for itself."
...Plato's advice to educators(429-347BC)