-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pulsating sphere #69
Pulsating sphere #69
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff!
Would it be possible to drop pulsating_sphere_displacement()
?
I guess this could be obtained from pulsating_sphere_velocity()
with http://python.sfstoolbox.org/en/latest/utilities.html#sfs.util.displacement
Can you please add the velocity and pressure animations to the example file?
Or did I miss them?
Thanks for adding 2 more animations, but wouldn't it be better to make a single file that generates all 3 animations? Right now there is a lot of repetition. |
The commit message for 4421b3c is supposed to be
|
radius = 0.25 | ||
amplitude = 1 / (radius * omega * sfs.defs.rho0 * sfs.defs.c) | ||
p = sfs.mono.source.pulsating_sphere(omega, x0, radius, amplitude, grid) | ||
v = sfs.mono.source.pulsating_sphere_velocity(omega, x0, radius, amplitude, vgrid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line has more than 79 characters (more specifically it has 82) when shown in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes!
What about making a pressure plot in the docstring of pulsating_sphere()
and a combined pressure/velocity plot in pulsating_sphere_velocity()
, like it is done for the other source types?
By default, Sphinx should only build the pages with changes (unless you use the For further options see
|
The text in the docstring is updated but the plot is not. |
Particle animation with colors. The radial component of the particle velocity is indicated by color gradient. Red means positive radial velocity (outward movement) whereas blue means negative radial velocity (inward movement). The red wavefronts (positive) are a bit narrower than the blue ones (negative). This is because the particles are compressed when the particles are moving outward. When the particles are moving inward, on the other hand, the particles are rarefied and have a wider spatial extent. |
The colored animation looks nice!
Well the particle density should reflect the sound pressure, which is physical, right? The different width of the "rings" might be an optical illusion? Did you try plotting the isobar lines where the pressure is 0?
This sounds a bit like #64. This is probably because the old images are cached by the browser? |
I would say it is not only an optical illusion and I would suspect that near the sphere it also has to be that way. Maybe it will look more equally distributed if you go farer away from the source? |
I think the reason for the "illusion" is the movement of particles. The velocity is computed for a uniform grid, which is the equilibrium points of the particles. Then the corresponding colors are applied to a nonuniform grid, because the particles are swinging around the equilibrium. The resulting plot is therefore "distorted". If the colors were plotted at the equilibrium, there would be no such illusion. Another thing to notice is that the amplitude of the displacement is set to 5 cm which is way too large. For 750 Hz, this corresponds to about 24750 Pa at 1 m distance, which makes no sense. To have about 1 Pa, the amplitude should be in the order of millimeters. The animation then look like this: The particles are at rest (probably moving in the order of subpixel) which is kinda boring. But now the "rings" have the same widths. For educational purposes, I find the earlier (insane) animation more useful as it (even without the colors) visualizes the particle velocity and density (therefore the pressure) at the same time. Maybe the colored animation, although it looks nice, should be used/shown with care.
Thank you, I will check. |
But this would be physically wrong, wouldn't it? It makes sense to show the speed (by means of the color) of the particle at the point in space where the particle actually is at the given point in time (or rather at a given phase angle). At the maximum displacement, the velocity should be 0. But it wouldn't be correct to show this speed at the equilibrium point, because the particle isn't there in the moment. And a different particle which happens to be there in that moment will actually have a different speed! I now think that this is actually a physical effect, the rings of particles with negative speed should be slightly wider than those with positive speed. Of course this is all extremely exaggerated, but I think without exaggeration it's useless. I think it would be best to show a plot with the actual (unnoticeable) displacement and directly afterwards show the exaggerated plot. This would be similar to what I did with the point and line sources (see http://python.sfstoolbox.org/en/0.4.0/frequency-domain.html#sfs.mono.source.point), where I first showed the plot where hardly anything can be seen, and afterwards I showed the normalized plot. I've seen particle plots where a single particle (or a few selected ones) was plotted in a different color (and probably slightly bigger?), this made it much easier to see the actual displacement of a single particle. BTW, @spors used a randomized grid in https://github.com/sfstoolbox/sfs-python/blob/master/doc/examples/plot_particle_density.py. I think this looks better and the patterns of the regular grid can be distracting. |
I agree that this would actually happens for oscillating particles and the velocity should be visualized at the corresponding position, no matter where it is. What I am not sure about is whether we can use the wave propagation model for arbitrarily large particle displacement. Let me approach this from a slightly different point of view. I'm not so sure about this, though. In our simulation, we are assuming constant speed of sound and linear acoustics. If we want to show something that really happens for large amplitude, the variation of the propagation speed has to be taken into account. In my opinion, the nonlinear effect we are observing is sort of an artifact caused by applying linear acoustics to nonlinear range.
That's true. I'm not saying that we should always stick to realistic values. As you mentioned, we often normalize the sound pressure for a better visualization. The particle displacement should be amplified for the same reason. But adding colors to such an exaggerated simulation shows a sound field with a modified spatial structure. This might lead innocent readers/users to misunderstanding. Maybe I am being unnecessarily cautious:-)?
Right, I also saw it before. Wouldn't be a problem. I will make new animation.
IMHO, the uniform grid is a better representation of the particle.
The particle is not referring to individual air molecule but a chunk of air which can be assumed to be an infinitesimal volume element. Thus, each point in the simulation should be seen as the center of mass of the volume element. If there is no sound wave, all volume elements should be of the same size and equidistant because there is no net flow or force among them. So the grid points must be uniform when there is no sound wave. Of course, we might want to simulate the air molecules (not the sound particles) using random grids. But then the particle velocity shouldn't be used to simulate the individual air molecules, because it is not the air molecules that have such a motion. They would rather have a Brownian motion.
|
This can be found in [Kuttruff, Ch. 4 p. 67] but my explanation was incorrect. The steepening/flattening is observed after a long propagation. Although more pronounced for larger amplitudes, the effect would also occur for not-so-crazy amplitudes. I think this effect is not relevant to our discussion since we are in the near field. The nonlinear effect that would occur in near field and at high amplitude is the expansion and compression of the waveform for positive and negative amplitudes, respectively. This kind of distortion is illustrated in [ibid, Ch. 2, p. 33] for a exemplary nonlinear system. Now I am wondering whether we can actually simulate the second nonlinear effect with the current model. |
Since the model is based on the linear losless wave-equation, nonlinear effects should not be included. |
Exactly! |
@narahahn Now there are multiple scripts creating the same animations, right? |
The old scripts are removed. In |
Thanks for the update! Why is the hole in the pressure plot not changing its size? Thanks for trying to make it Probably this was too ambitious? I don't mind either way, but if you decide to make it |
This is because now the sound pressure is computed only for outside the sphere. Line 756 in 9bcb063
Before this line was added, the sound field inside the sphere was also computed. Maybe I can add an option to choose whether the sound field inside the sphere
Thank you for the review. Let me try to fix it. |
Hmmm, this is unfortunate. The actual radius depends on the selected phase angle, doesn't it? Probably you could use the minimum radius? |
You should also run Sphinx and check for errors. There are some right now.
Yeah, that's the browser not checking if the file was changed. If you want a nicer workflow, you could try to use something like this: from IPython.display import Image
Image('pulsating_sphere_displacement_square_grid.gif') This should avoid the re-loading problem. You should also create a normal link in some Markdown cell:
This way you make sure that Or you can just remove all this GIF stuff.
If you use this, you don't have to use
One reason is that you removed the
Exactly. Just as you've done it in the meantime. I personally would just move the function definition down a bit after all the captured variables are defined. That's not strictly necessary, but I think it makes it easier to understand where those variables come from. |
It works great in jupyter notebook, but unfortunately the images are not shown
Thanks, now it works. The trick was to put the returned value in a bracket
I'm afraid there are still some errors. I guess the followings are related to my code.
Can you tell what's wrong here? |
You mean that this is shown instead of the image:
Right? I didn't think of that! Apparently But if you still want to use your precious GIFs, there is yet another possible work-around: Image(url='pulsating_sphere_displacement_square_grid.gif') But for this to work with
Yes. It creates a Python
Not at all! This is a bug in Matplotlib for which I happened to have submitted a fix just a few hours ago: matplotlib/matplotlib#13633
Yes, you are using single backticks where you should use double backticks. See also http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#inline-markup This is different in Markdown, where single backticks switch to code formatting. |
Another idea: What about renaming the functions in Instead of Then you could do something like: import animations_pulsating_sphere as animate And later: ani = animate.particle_displacement(blah, blah, blah)
ani.save(blah, blah)
...
HTML(ani.to_jshtml()) I think this would look nicer, what do you think? |
eac554e
to
1a139fc
Compare
Yeah, good idea! |
Now I use Do you know how to automatically start the video in
I see, thank you! |
@mgeier Would you prefer just using |
You should decide, I like both. I just don't like GIFs, but Whatever you choose, it would be great to show the other option in one example (as you are currently doing). BTW, converting the animation to a video doesn't currently work on Travis-CI. I think you can fix this by adding addons:
apt:
packages:
- pandoc
- ffmpeg |
I prefer
I agree.
Thanks. |
Yes, it's definitely much faster to compute. And when saving it to the notebook the resulting notebook is much smaller.
No. I think it's not possible. I would also like to have that.
This works for me, but some of the videos just randomly stopped at some point (probably when switching between browser tabs?).
It's an outdated technology and it was for a long time encumbered by patents (which it isn't anymore, but it still has this slightly ugly taste to it). |
FYI: some tests on Travis-CI don't pass, that's the fix: #118 |
Should I apply it in this PR? |
No need. Just ignore the CI results for Python 3.5 and 3.6. |
Sorry, I forgot something in my previous review:
|
Sorry, I should have checked it.
Much better, thank you. It's a bit unfortunate that the links don't look like those in the API document.
Would it be better to save the animations of the python script example |
What do you mean by that?
No, that's OK. We can add other formats later, if we feel like it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should merge this soon.
Do you want to keep all the individual commits in the history?
Or do you want to squash some or all of them?
I was hoping to make a link to the functions with programming font inside a box.
Alright.
No, I will squash and rebase when it's ready to merge. |
OK, I see. That's currently not possible.
I think it's ready! |
0a29ddb
to
44a2c5e
Compare
Here we go. Thanks a lot for your review. |
Simulation of the particle displacement and particle velocity of a pulsating sphere.