What is the best way to programatically generate a CompiledMethod from a string?
This is what I currently do:
mthd := Compiler new compile:(String streamContents: [:stream | stream nextPutAll: 'bindingsString'; cr; tab; nextPutAll: 'Dynamically generated by bindingsString:' asSmalltalkComment; cr; tab; nextPutAll: '^ '; nextPutAll: aString surroundedBySingleQuotes; nextPut: $.; cr. ]) in:self classified:'bindings' notifying:nil ifFail:[:x | ^ x]. self class addSelector:#bindingsString withMethod: mthd generate. self class organization classify: #bindingsString under:#bindings suppressIfDefault:false.
This works, actually, though I'm sure the "ifFail" block is totally wrong. However, it doesn't "feel" like the right way. For one thing, I am not sure that method of Compiler is a public API. For another, I have to repeat a lot of information such as the selector and classification.
This is in relation to my last message: I am trying to generate methods that will return constant data so that it survives Monticello. (I also tried hacking around with MCClassDefinition, but that seemed like a lot of work...). The constant data is only a string, so if there is an easier way I'm all ears.
thanks!
Niko
Actually, there is one additional problem with this technique:
the comment which I insert gets lost.
thanks! Niko
On Dec 7, 2007, at 11:28 AM, Niko Matsakis wrote:
What is the best way to programatically generate a CompiledMethod from a string?
This is what I currently do:
mthd := Compiler new compile:(String streamContents: [:stream | stream nextPutAll: 'bindingsString'; cr; tab; nextPutAll: 'Dynamically generated by bindingsString:' asSmalltalkComment; cr; tab; nextPutAll: '^ '; nextPutAll: aString surroundedBySingleQuotes; nextPut: $.; cr. ]) in:self classified:'bindings' notifying:nil ifFail:[:x | ^ x]. self class addSelector:#bindingsString withMethod: mthd generate. self class organization classify: #bindingsString under:#bindings suppressIfDefault:false.
This works, actually, though I'm sure the "ifFail" block is totally wrong. However, it doesn't "feel" like the right way. For one thing, I am not sure that method of Compiler is a public API. For another, I have to repeat a lot of information such as the selector and classification.
This is in relation to my last message: I am trying to generate methods that will return constant data so that it survives Monticello. (I also tried hacking around with MCClassDefinition, but that seemed like a lot of work...). The constant data is only a string, so if there is an easier way I'm all ears.
thanks!
Niko
Hi Niko,
2007/12/7, Niko Matsakis niko@alum.mit.edu:
What is the best way to programatically generate a CompiledMethod from a string?
I'm not sure you want to play with CompiledMethod. What about:
Object compile: 'method ^ 123.' classified: 'accessing'
That looks easy. I'll give it a try, thanks!
Niko
On Dec 7, 2007, at 11:39 AM, Damien Cassou wrote:
Hi Niko,
2007/12/7, Niko Matsakis niko@alum.mit.edu:
What is the best way to programatically generate a CompiledMethod from a string?
I'm not sure you want to play with CompiledMethod. What about:
Object compile: 'method ^ 123.' classified: 'accessing'
-- Damien Cassou
... that's Computational Fluid Dynamics. I'm specifically interested in running a Navier-Stokes simulation using something like the Volume of Fluid model to deal with free surface movement. My first goal is to be able to duplicate something like the following simulation of a breaking wave:
http://www.coastal.udel.edu/faculty/jpuleo/RIPPLE/ripple.mov
I want to be able to run similar simulations for waves breaking against different shaped walls.
Most people use big programs in C or Fortran (!), and half the trouble is learning how to use them, since there's no prayer of changing them. However the basic equations can be written in half a page, and I don't need it to run very fast.
It could be fun but so far it looks like it will be simpler to build a wave tank :-(.
Thanks for any useful pointers.
- Dan
I don't know of any Squeak code to do this. The starting-point paper about this kind of simulation (for computer graphics, anyway) is "Stable Fluids" by Jos Stam (http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/ns.pdf ). I'm not sure if there is a later paper that is more approachable; the others I've seen are more complicated. Also note that I don't believe that Stam's method can model breaking waves... it doesn't allow for a dynamic boundary between different fluids (eg: air and water).
Ron Fedkiw has some of the most impressive results (for example: http://physbam.stanford.edu/~fedkiw/animations/lighthouse.avi) . Of course, the implementations are more complicated.
Sorry I couldn't be more helpful; hopefully someone else has better pointers.
Josh
On Dec 11, 2007, at 9:23 AM, Dan Ingalls wrote:
... that's Computational Fluid Dynamics. I'm specifically interested in running a Navier-Stokes simulation using something like the Volume of Fluid model to deal with free surface movement. My first goal is to be able to duplicate something like the following simulation of a breaking wave:
http://www.coastal.udel.edu/faculty/jpuleo/RIPPLE/ripple.mov
I want to be able to run similar simulations for waves breaking against different shaped walls.
Most people use big programs in C or Fortran (!), and half the trouble is learning how to use them, since there's no prayer of changing them. However the basic equations can be written in half a page, and I don't need it to run very fast.
It could be fun but so far it looks like it will be simpler to build a wave tank :-(.
Thanks for any useful pointers.
- Dan
Dan Ingalls wrote:
It could be fun but so far it looks like it will be simpler to build a wave tank :-(.
That is very likely.
Thanks for any useful pointers.
No actual pointers, sorry, but I do note most of the complexity of the available software is in getting the data in and then getting the results out. This is something that perhaps Croquet could help with? For the actual equations something like StarSqueak or Kedama might be a good match, specially if extended for 3D.
-- Jecel
... that's Computational Fluid Dynamics. I'm specifically interested in running a Navier-Stokes simulation using something like the Volume of Fluid model to deal with free surface movement. My first goal is to be able to duplicate something like the following simulation of a breaking wave:
http://www.coastal.udel.edu/faculty/jpuleo/RIPPLE/ripple.mov
I want to be able to run similar simulations for waves breaking against different shaped walls.
Most people use big programs in C or Fortran (!), and half the trouble is learning how to use them, since there's no prayer of changing them. However the basic equations can be written in half a page, and I don't need it to run very fast.
It could be fun but so far it looks like it will be simpler to build a wave tank :-(.
I'm getting more serious about this. As a point of reference I did build a wave tank...
http://www.youtube.com/watch?v=joRv6aiST3s
It's fun to build stuff (and I now have a 300-pound structure in my driveway waiting for the next time when the tide is right), but I would still like to be able to do some simulations, even if only in 2D at first.
I have a feeling that if one understands the basic equations, plus the volume-of-fluid method for the surface and other boundaries (as in http://www.math.rug.nl/~veldman/preprints/ECCOMAS2004.pdf), it wouldn't take more than a couple of pages of Squeak, and it might even fit the StarSqueak or Kedama framework as suggested by Jecel.
Sadly I have only personal funds to work with at this point but, if someone thought they could duplicate, eg, the little ripple.mov above in a few pages of Squeak, I'd pay real money for it, and maybe more for future experiments. Let me know if this appeals to you and perhaps we can negotiate some sort of agreement.
- Dan
Dan-
Cool wave tank video.
This existing Java applet is maybe not as fancy as you want eventually, but check out this link for a ripple tank simulator for what is easily possible if you are willing to just have a non-particle meshwork ripple model at first: http://www.falstad.com/ripple/ "This java applet is a simulation of a ripple tank. It demonstrates waves in two dimensions, including such wave phenomena as interference, diffraction (single slit, double slit, etc.), refraction, resonance, phased arrays, and the Doppler effect. To get started with the applet, just go through the items in the Setup menu in the upper right. You can also draw on the screen with the mouse. The predefined setups are just starting points; you can modify the sources and walls as you desire. Click the 3-D View checkbox to see a 3-D view. "
The code is there too in Java, but only for two dimensions (shore waves do some funky circular particle rolling thing I think, if you want to be really accurate). http://en.wikipedia.org/wiki/Ocean_surface_wave (that links to a simpler wave applet, by the way).
It should not be that hard for someone like you to translate that "ripple" WaveBox applet to Smalltalk. Only about 1700 lines: ~/downloaded_files$ wc WaveBox.java 1693 5881 48302 WaveBox.java It's a surprisingly complex applet as far as the GUI, so way more than half of the code seems related to the GUI and the drawing. From a casual glance at it, I'm guessing the core part is, as you say, only a few pages of code, mostly towards the end. There is no license statement in the file though. :-(
From the start of the source file:
// WaveBox.java (c) 2001 by Paul Falstad, www.falstad.com. // Rendering algorithm in this applet is based on the description of // the algorithm used in Atom in a Box by Dean Dauger (www.dauger.com). // We raytrace through a 3-d dataset, sampling a number of points and // integrating over them using Simpson's rule. (So, not much on the wave part, and no other detailed comments in the file).
Anyway, this sort of numerically oriented wave library is exactly the kind of thing you might want to code in Smalltalk and then translate to Scala to run on the JVM. It would only go 1/2 to 1/3 of native C or Fortran speeds probably, but it would be run fast everywhere Squeak/JVM would run. Or course, having the JVM set up right is a hassle. Or, of course, you could write is such that Slang could translate part of it to C. But running that code everywhere might be harder.
This example makes me think it might be nice to have a Java->Smalltalk translator as well as a Smalltalk->Java/Scala one as part of a Squeak/JVM, because there sure is a lot of Java code out there of educational interest. (Too bad Jim Spohrer's EOE educaitonal Java applet directory site seems not to be up these days, last I looked.)
--Paul Fernhout
Dan Ingalls wrote:
... that's Computational Fluid Dynamics. I'm specifically interested in running a Navier-Stokes simulation using something like the Volume of Fluid model to deal with free surface movement. My first goal is to be able to duplicate something like the following simulation of a breaking wave:
http://www.coastal.udel.edu/faculty/jpuleo/RIPPLE/ripple.mov
I want to be able to run similar simulations for waves breaking against different shaped walls.
Most people use big programs in C or Fortran (!), and half the trouble is learning how to use them, since there's no prayer of changing them. However the basic equations can be written in half a page, and I don't need it to run very fast.
It could be fun but so far it looks like it will be simpler to build a wave tank :-(.
I'm getting more serious about this. As a point of reference I did build a wave tank...
http://www.youtube.com/watch?v=joRv6aiST3s
It's fun to build stuff (and I now have a 300-pound structure in my driveway waiting for the next time when the tide is right), but I would still like to be able to do some simulations, even if only in 2D at first.
I have a feeling that if one understands the basic equations, plus the volume-of-fluid method for the surface and other boundaries (as in http://www.math.rug.nl/~veldman/preprints/ECCOMAS2004.pdf), it wouldn't take more than a couple of pages of Squeak, and it might even fit the StarSqueak or Kedama framework as suggested by Jecel.
Sadly I have only personal funds to work with at this point but, if someone thought they could duplicate, eg, the little ripple.mov above in a few pages of Squeak, I'd pay real money for it, and maybe more for future experiments. Let me know if this appeals to you and perhaps we can negotiate some sort of agreement.
Dan Ingalls schrieb:
... that's Computational Fluid Dynamics. I'm specifically interested in running a Navier-Stokes simulation using something like the Volume of Fluid model to deal with free surface movement. My first goal is to be able to duplicate something like the following simulation of a breaking wave:
http://www.coastal.udel.edu/faculty/jpuleo/RIPPLE/ripple.mov
I want to be able to run similar simulations for waves breaking against different shaped walls.
Most people use big programs in C or Fortran (!), and half the trouble is learning how to use them, since there's no prayer of changing them. However the basic equations can be written in half a page, and I don't need it to run very fast.
It could be fun but so far it looks like it will be simpler to build a wave tank :-(.
I'm getting more serious about this. As a point of reference I did build a wave tank...
http://www.youtube.com/watch?v=joRv6aiST3s
It's fun to build stuff (and I now have a 300-pound structure in my driveway waiting for the next time when the tide is right), but I would still like to be able to do some simulations, even if only in 2D at first.
I have a feeling that if one understands the basic equations, plus the volume-of-fluid method for the surface and other boundaries (as in http://www.math.rug.nl/~veldman/preprints/ECCOMAS2004.pdf), it wouldn't take more than a couple of pages of Squeak, and it might even fit the StarSqueak or Kedama framework as suggested by Jecel.
Sadly I have only personal funds to work with at this point but, if someone thought they could duplicate, eg, the little ripple.mov above in a few pages of Squeak, I'd pay real money for it, and maybe more for future experiments. Let me know if this appeals to you and perhaps we can negotiate some sort of agreement.
- Dan
During my master thesis, I have experimented a bit with fluid visualization using Marching Cubes algorithm in squeak. http://www.gaguls.de/danilo/downloads/PlayfulAnimation_low.pdf (page 51)
The simulation where particle based, but I get more and more interested to do fluid simulation using Navier Strokes algorithm. My personal interest is visualization and the interest in how it works. I simply did not found the time yet. I can inform you, when I have time for it. Maybe we find a way to cooperate.
Danilo
On Feb 13, 2008, at 1:50 AM, Danilo wrote:
During my master thesis, I have experimented a bit with fluid visualization using Marching Cubes algorithm in squeak. http://www.gaguls.de/danilo/downloads/PlayfulAnimation_low.pdf (page 51)
The simulation where particle based, but I get more and more interested to do fluid simulation using Navier Strokes algorithm. My personal interest is visualization and the interest in how it works. I simply did not found the time yet. I can inform you, when I have time for it. Maybe we find a way to cooperate.
Danilo
Neat paper Danilo! Thanks for the link.
How was the VerletFluids app implemented? Does it use a VM plugin for speed, for either the particle animation or the isosurface extraction? Or is Squeak fast enough?
Thanks, Josh
Joshua Gargus wrote:
On Feb 13, 2008, at 1:50 AM, Danilo wrote:
During my master thesis, I have experimented a bit with fluid visualization using Marching Cubes algorithm in squeak. http://www.gaguls.de/danilo/downloads/PlayfulAnimation_low.pdf (page 51)
The simulation where particle based, but I get more and more interested to do fluid simulation using Navier Strokes algorithm. My personal interest is visualization and the interest in how it works. I simply did not found the time yet. I can inform you, when I have time for it. Maybe we find a way to cooperate.
Danilo
Neat paper Danilo! Thanks for the link.
How was the VerletFluids app implemented? Does it use a VM plugin for speed, for either the particle animation or the isosurface extraction? Or is Squeak fast enough?
Thanks, Josh
The particle simulation and isosurface extraction were pure smalltalk, no special plugins. It worked only interactive for small simulations. The screenshot in the paper was from an interactive simulation, that used 16 particles and a grit for surface extraction of about 15x15x15 cells.
Danilo
squeak-dev@lists.squeakfoundation.org