Even while enjoying my writer’s block, I still won’t disappoint you. … My browsing has yielded some material, and I am going to share it with you.

It all began with googling for some notes on CFD. One thing led to another, and soon enough, I was at this page [^] maintained by Prof. Praveen Chandrashekhar of TIFR Bangalore.

Do go through the aforementioned link; highly recommended. It tells you about the nature of my trade [CFD]…

As that page notes, this article had first appeared in the AIAA Student Journal. Looking at the particulars of the anachronisms, I wanted to know the precise date of the writing. Googling on the title of the article led me to a PDF document which was hidden under a “webpage-old” sub-directory, for the web pages for the ME608 course offered by Prof. Jayathi Murthy at Purdue [^]. At the bottom of this PDF document is a note that the AIAA article had appeared in the Summer of 1985. … Hmm…. Sounds right.

If you enjoy your writer’s block [the way I do], one sure way to continue having it intact is to continue googling. You are guaranteed never to come out it. I mean to say, at least as far as I know, there is no equivalent of Godwin’s law [^] on the browsing side.

Anyway, so, what I next googled on was: “wind tunnels.” I was expecting to see the Wright brothers as the inventors of the idea. Well, I was proved wrong. The history section on the Wiki page [^] mentions Benjamin Robins and his “whirling arm” apparatus to determine drag. The reference for this fact goes to a book bearing the title “Mathematical Tracts of the late Benjamin Robins, Esq,” published, I gathered, in 1761. The description of the reference adds the sub-title (or the chapter title): “An account of the experiments, relating to the resistance of the air, exhibited at different times before the Royal Society, in the year 1746.” [The emphasis in the italics is mine, of course! [Couldn’t you have just guessed it?]]

Since I didn’t know anything about the “whirling arm,” and since the Wiki article didn’t explain it either, a continuation of googling was entirely in order. [The other reason was what I’ve told you already: I was enjoying my writer’s block, and didn’t want it to go away—not so soon, anyway.] The fallout of the search was one k-12 level page maintained by NASA [^]. Typical of the government-run NASA, there was no diagram to illustrate the text. … So I quickly closed the tab, came back to the next entries in the search results, and landed on this blog post [^] by “Gina.” The name of the blog was “Fluids in motion.”

… Interesting…. You know, I knew about, you know, “Fuck Yeah Fluid Dynamics” [^] (which is a major time- and bandwidth-sink) but not about “Fluids in motion.” So I had to browse the new blog, too. [As to the FYFD, I only today discovered the origin of the peculiar name; it is given in the Science mag story here [^].]

Anyway, coming back to Gina’s blog, I then clicked on the “fluids” category, and landed here [^]… Turns out that Gina’s is a less demanding on the bandwidth, as compared to FYFD. [… I happen to have nearly exhausted my monthly data limit of 10 GB, and the monthly renewal is on the 5th June. …. Sigh!…]

Anyway, so here I was, at Gina’s blog, and the first post in the “fluids” category was on “murmuration of starlings,” [^]. There was a link to a video… Video… Video? … Intermediate Conclusion: Writer’s blocks are costly. … Soon after, a quiet temptation thought: I must get to know what the phrase “murmuration of starlings” means. … A weighing in of the options, and the final conclusion: what the hell! [what else], I will buy an extra 1 or 2 GB add-on pack, but I gotta see that video. [Writer’s block, I told you, is enjoyable.] … Anyway, go, watch that video. It’s awesome. Also, Gina’s book “Modeling Ships and Space Craft.” It too seems to be awesome: [^] and [^].

The only way to avoid further spending on the bandwidth was to get out of my writer’s block. Somehow.

So, I browsed a bit on the term [^], and took the links on the first page of this search. To my dismay, I found that not even a single piece was helpful to me, because none was relevant to my situation: every piece of advice there was obviously written only after assuming that you are not enjoying your writer’s block. But what if you do? …

Anyway, I had to avoid any further expenditure on the bandwidth—my expenditure—and so, I had to get out of my writer’s block.

So, I wrote something—this post!

[Blogging will continue to remain sparse. … Humor apart, I am in the middle of writing some C++ code, and it is enjoyable but demanding on my time. I will remain busy with this code until at least the middle of June. So, expect the next post only around that time.]

[May be one more editing pass tomorrow… Done.]

[E&OE]

/

# Papers must fall out…

Over the past couple of weeks or so, I’ve been going over SPH (smoothed particle hydrodynamics).

I once again went through the beginning references noted in my earlier post, here [^]. However, instead of rewriting my notes (which I lost in the last HDD crash), this time round, I went straight to programming. … In this post, let me recap recall what all I did.

First, I went through the great post “Why my fluids don’t flow” [^] by Tom Madams. … His blog has the title: “I am doing it wrong,” with the sub-text: “most of the time.” [Me too, Tom, me too!] This post gave a listing of what looked like a fully working C++ code. Seeing this code listing (even if the videos are no longer accessible), I had to try it.

So, I installed the Eclipse CDT. [Remember my HDD crash?—the OS on the new HDD had no IDEs/C++ compilers installed till now; I had thus far installed only Python and PyCharm]. I also installed MinGW, freeglut, Java JRE, but not all of them in the correct order. [Remember, I too do it wrong, most of the time.] I then created a “Hello World” project, and copy-pasted Tom’s code.

Tom’s program not only compiled well, but it also worked beautifully. Quite naturally, I had to change something about it.

So I removed his call to glDrawArrays(), and replaced the related code with the even older glBegin(GL_POINTS), glVertex2d(), glEnd() sort of a code. As I had anticipated,  there indeed was no noticeable performance difference. If the fluid in the original code required something like a minute (of computer’s physical time) to settle down to a certain quiescent state, then so did the one with the oldest-style usage of OpenGL. The FPS in the two cases were identical in almost all of the release runs, and they differed by less than 5–7% for the debug runs as well, when the trials were conducted on absolutely fresh cold-starts (i.e. with no ready-to-access memory pages in either physical or virtual memory).

Happy with my change, I then came to study Tom’s SPH code proper. I didn’t like the emitters. True to my core engineering background, what I wanted to simulate was the dam break. That means, all the 3000 particles would be present in the system right from the word go, thereby also having a slower performance throughout, including in the beginning. But Tom’s code was too tied up with the emitters. True to my software engineering background, rather than search and remove the emitters-related portion and thus waste my time fixing the resulting compiler errors, I felt like writing my own code. [Which true programmer doesn’t?]

So I did that, writing only stubs for the functions involving the calculations of the kernels and the accelerations. … I, however, did implement the grid-based nearest-neighbor search. Due to laziness, I simply reused the STL lists, rather than implementing the more basic (and perhaps slightly more efficient) “p->next” idiom.

Then I once again came back to Tom’s code, and began looking more carefully at his SPH-specific computations.

What I now didn’t like was the variables defined for the near-density and the near-pressure. These quantities didn’t fit very well into my preconceived notions of how a decent SPH code ought to look like.

So, I decided to deprove [which word is defined as an antonym of “improve”] this part, by taking this 2010 code from its 2007 (Becker et al.) theoretical basis, to a 2003 basis (Muller et al., Eurographics).

Further following my preconceived notions, I also decided to keep the values of the physical constants (density, gas stiffness, viscosity, surface tension) the same as those for the actual water.

The code, of course, wouldn’t work. The fluid would explode as if it were a gas, not water.

I then turned my learner’s attention to David Bindel’s code (see the “Resources” section at the bottom of his page here [^]).

Visiting Bindel’s pages once again, this time round, I noticed that he had apparently written this code only as a background material for a (mere) course-assignment! It was not even an MS thesis! And here I was, still struggling with SPH, even after having spent something like two weeks of full-time effort on it! [The difference was caused by the use of the realistic physical constants, of course. But I didn’t want to simply copy-paste Tom’s or Bindel’s parameter values; I wanted to understand where they came from—what kind of physical and computational contexts made those specific values give reasonable results.]

I of course liked some of the aspects of Bindel’s code better—e.g. kernels—and so, I happily changed my code here and there to incorporate them.

But I didn’t want to follow Bindel’s normalize_mass routine. Two reasons: (i) Once again according to my preconceived notions, I wanted to first set aside a sub-region of the overall domain for the fluid; then decide with how many particles to populate it, and what lattice arrangement to follow (square? body centered-cubic? hexagonal close-packed?); based on that, calculate each particle’s radius; then compute the volume of each particle; and only then set its mass using the gross physical density of the material from which it is composed (using the volume the particle would occupy if it were to be isolated from all others, as an intermediate step). The mass of a particle, thus computed (and not assumed) would remain fixed for all the time-steps in the program. (ii) I eventually wanted a multi-phase dam-break, and so wasn’t going to assume a global constant for the mass. Naturally, my code wouldn’t be able to blindly follow Bindel on all counts.

I also didn’t like the version of the leapfrog he has implemented. His version requires you to maintain additional quantities of the velocities at the half time-steps (I didn’t mind that), and also to implement a separate leapfrog_start() function (which I did mind—an additional sequence of very similar-looking function calls becomes tricky to modify and maintain). So, I implemented the other version of the leapfrog, viz., the “velocity Verlet.” It has exactly the same computational properties (of being symplectic and time-reversible), the same error/convergence properties (it too is second-order accurate), but it comes with the advantage that the quantities are defined only at the integer time-steps—no half-time business, and no tricky initialization sequence to be maintained.

My code, of course, still  didn’t work. The fluid would still explode. The reason, still, was: the parameter values. But the rest of the code now was satisfactory. How do I know this last part? Simple. Because, I commented out the calls to all the functions involving all other accelerations, and retained only the acceleration due to gravity. I could then see the balls experiencing the correct free-fall under gravity, with the correct bouncing-back from the floor of the domain. Both the time for the ball to hit the floor as well as the height reached after bouncing were in line with what physics predicts. Thus I knew that my time integration routines would be bug-free. Using some debug tracings, I also checked that the nearest-neighbour routines were working correctly.

I then wrote a couple of Python scripts to understand the different kernels better; I even plotted them using MatPlotLib. I felt better. A program I wrote was finally producing some output that I could in principle show someone else (rather than having just randomly exploding fluid particles). Even if it was doing only kernel calculations and not the actual SPH simulation. I had to feel [slightly] better, and I did.

At this stage, I stopped writing programs. I began thinking. [Yes, I do that, too.]

To cut a long story short, I ended up formulating two main research ideas concerning SPH. Both these ideas are unlike my usual ones.

Usually, when I formulate some new research idea, it is way too conceptual—at least as compared to the typical research reported in the engineering journals. Typically, at that stage (of my formulation of a new research idea), I am totally unable to see even an outline of what kind of a sequence of journal papers could possibly follow from it.

For instance, in the case of my diffusion equation-related result, it took me years before an outline for a good conference paper—almost like really speaking, at par with a journal paper—could at all evolve. I did have the essential argument ready. But I didn’t know what all context—the specifically mathematical context—would be expected in a paper based on that idea. I (and all the mathematicians I contacted) also had no idea as to how (or where) to go hunting for that context. And I certainly didn’t have any concrete idea as to how I would pull it all together to build a concrete and sufficiently rigorous argument. I knew nothing of that; I only knew that the instantaneous action-at-a-distance (IAD) was now dead; summarily dead. Similarly, in case of QM, I do have some new ideas, but I am still light-years away from deciding on a specific sequence of what kind of papers could be written about it, let alone have a good, detailed idea for the outline of the next journal paper to write on the topic.

However, in this case—this research on SPH—my ideas happen to be more like what [other] people typically use when they write papers for [even very high impact] journals those which lie behind the routine journal papers. So, papers should follow easily, once I work on these ideas.

Indeed, papers must follow those ideas. …There is another reason to it, too.

… Recently, I’ve come to develop an appreciation, a very deep kind of an appreciation, of the idea of having one’s own Google Scholar page, complete with a [fairly] recent photo, a verified email account at an educational institution (preferably with a .edu, or a .ac.in (.in for India) domain, rather than a .org or a .com domain), and a listing of one’s own h-index. [Yes, my own Google Scholar page, even if the h-Index be zero, initially. [Time heals all wounds.] I have come to develop that—an appreciation of this idea of having a Google Scholar page. … One could provide a link to it from one’s personal Web site, one could even cite the page in one’s CV, it could impress UGC/NBA/funding folks…. There are many uses to having a Google Scholar page.

…That is another reason why [journal] papers must come out, at least now.

And I expect that the couple of ideas regarding SPH should lead to at least a couple of journal papers.

Since these ideas are more like the usual/routine research, it would be possible to even plan for their development execution. Accordingly, let me say (as of today) that I should be able to finish both these papers within the next 4–5 months. [That would be the time-frame even if I have no student assistant. [Having a student assistant—even a very brilliant student studying at an IIT, say at IIT Bombay—would still not shorten the time to submission, neither would it reduce my own work-load any more than by about 10–20% or so. That’s the reason I am not planning on a student assistant on these ideas.]

But, yes, with all this activity in the recent past, and with all the planned activity, it is inevitable that papers would fall out. Papers must, in fact, fall out. …. Journal papers! [Remember Google Scholar?]

Of course, when it comes to execution, it’s a different story that even before I begin any serious work on them, I still have to first complete writing my CFD notes, and also have to write a few FDM, FVM and VoF/LevelSet programs scripts or OpenFOAM cases. Whatever I had written in the past, most of it was lost in my last HDD crash. I thus have a lot of territory to recover first.

Of course, rewriting notes/codes is fast. I could so rapidly progress on SPH this year—a full working C++ code in barely 2–3 weeks flat—only because I had implemented some MD (molecular dynamics) code in 2014, no matter how simple MD it was. The algorithms for collision detection and reflections at boundaries remain the same for all particles approaches: MD with hard disks, MD with LJ potential, and SPH. Even if I don’t have the previously written code, the algorithms are no longer completely new to me. As I begin to write code, the detailed considerations and all come back very easily, making the progress very swift, as far as programming is concerned.

When it comes to notes, I somehow find that writing them down once again takes almost the same length of time—just because you had taken out your notes earlier, it doesn’t make writing them down afresh takes any less time.

Thus, overall, recovering the lost territory would still take quite some effort and time.

My blogging would therefore continue to remain sparse even in the near future; expect at the most one more post this month (May 2016).

The work on the journal papers itself should begin in the late-June/early-July, and it should end by mid-December. It could. Nay, it must. … Yes, it must!

Papers must come out of all these activities, else it’s no research at all—it’s nothing. It’s a zero, a naught, a nothing, if there are no papers to show that you did research.

Papers must fall out! … Journal papers!!

A Song I Like:

(Western, Instrumental) “The rain must fall”
Composer: Yanni

[May be one quick editing pass later today, and I will be done with this post. Done on 12th May 2016.]

[E&OE]

# A bit about the Dirac delta (and the SPH)

“SPH” here means: Smoothed Particle Hydrodynamics. Here is the Wiki article on SPH [^] if all you want is to gain some preliminary idea (or better still, if that’s your purpose, just check out some nice YouTube videos after googling on the full form of the term).

If you wish to know the internals of SPH in a better way: The SPH literature is fairly large, but a lot of it also happens to be in the public domain. Here are a few references:

• A neat presentation by Maneti [^]
• Micky Kelager’s project report listed here [^]. The PDF file is here [(5.4 MB) ^]
• Also check out Cossins for a more in-depth working out of the maths [^].
• The 1992 review by Monaghan himself also is easily traceable on the ‘net
• The draft of a published book [(large .PDF file, 107 MB) ^] by William Hoover; this link is listed right on his home page [^]. Also check out another book on molecular dynamics which he has written and also put in the public domain.

For gentler introductions to SPH that come with pseudo-code, check out:

• Browne and Lewinder [(.PDF, 5.2 MB) ^], and
• David Bindel’s notes [(.PDF, ) ^].

I have left out several excellent introductory articles/slides by others, e.g. by Mathias Muller (and may expand on this list a day or two later).

The SPH theory begins with the identity:

$f(x) = \int\limits_{\Omega} \text{d}\Omega_{x'}\,f(x')\,\delta(x- x')$

where $\delta(x- x')$ is Dirac’s delta, and $x'$ is not a derivative of $x$ but a dummy variable mimicking $x$; for a diagrammatic illustration, see Maneti’s slides mentioned above.

It is thus, in connection with SPH (but not of QM) that I thought of going a little deeper with Dirac’s delta.

After some searches, I found an article by Balki on this topic [^], and knowing the author, immediately sat reading it. [Explanations and clarifications: 1. “Balki” means: Professor Balakrishnan of the Physics department of IIT Madras. 2. I know the author; the author does not know me. 3. Everyone on the campus calls him Balki (though I don’t know if they do that in his presence, too).] The link given here is to a draft version; the final print version is available for free from the Web site of the journal: [^].

A couple of days later, I was trying to arrange in my mind the material for an introductory presentation on SPH. (I was doing that even if no one has invited me yet to deliver it.) It was in this connection that I did some more searches on Dirac’s delta. (I began by going one step“up” the directory tree of the first result and thus landed at this directory [^] maintained by Dr. Pande of IIT Hyderabad [^]. … There is something to be said about keeping your directories brows-able if you are going share the entire content one way or the other; it just makes searching related contents easier!)

Anyway, thus, starting there, my further Google searches yielded the following articles/essays/notes: [^], [^], [^], [^], [^], [^], [^], and [^] . And, of course, the Wiki [^].

As any one would expect, some common points were of course repeated in each of these references. However, going through the articles/notes, though quite repetitive, didn’t get all that boring to me: each individual brings his own unique way of explaining a certain material, and Dirac’s delta being a concept that is both so subtle and so abstract, any person who [dare] attempts explaining it cannot help but bring his own individuality to that explanation. (Yes, the concept is subtle. The gifted American mathematician John von Neumann had spent some time showing how Dirac’s notions were mathematically faulty/untenable/not rigorous/something similar. … Happens.)

Anyway, as I expected, Balki’s article turned out to be the easiest and the most understanding-inducing a read among them all! [No, my attending IIT M had nothing to do with this expectation.]

Yet, there remained one minor point which was not addressed very directly in the above-mentioned references—not even by Balki. (Though his treatment is quite clear about the point, he seems to have skipped one small step I think is necessary.) The point I was looking for, is concerned with a more complete answer to this question:

Why is it that the $\delta$ is condemned to live only under an integral sign? Why can’t it have any life of its own, i.e., outside the integral sign?

The question, of course is intimately related to the other peculiar aspects of Dirac’s delta as well. For instance, as the tutorial at Pande’s site points out [^]:

The delta functions should not be considered to be an infinitely high spike of zero width since it scales as: $\int_{-\infty}^{\infty} a\,\delta(x)\,\text{d}x = a$.

Coming back to the caged life of the poor $\delta$, all authors give hints, but none jots down all the details of the physical (“intuitive”) reasoning lying behind this peculiar nature of the delta.

Then, imagining as if I am lecturing to an audience of engineering UG students led me to a clue which answers that question—to the detail I wanted to see. I of course don’t know if this clue of mine is mathematically valid or not. … It’s just that I “day-dreamt” one form of a presentation, found that it wouldn’t be hitting the chord with the audience and so altered it a bit, tried “day-dreaming” again, and repeated the process some 3–4 times over the past week. Finally, this morning, I got to the point where I thought I now have got the right clue which can make the idea clearer to the undergraduates of engineering.

I am going to cover that point (the clue which I have) in my next post, which I expect to write, may be, next week-end or so. (If I thought I could write that post without drawing figures, I would have written the answer right away.) Anyway, in the meanwhile, I would like to share all these references on SPH and on Dirac’s delta, and bring the issue (i.e., the question) to your attention.

… No, the point I have in mind isn’t at all a major one. It’s just that it leads to a presentation of the concept that is more direct than what the above references cover. (I can’t better Balki, but I can fill in the gaps in his explanations—at least once in a while.)

Anyway, if you know of any other direct and mathematically valid answers to that question, please point them out to me. Thanks in advance.

A Song I Like:

(Marathi) “mana chimba paavasaaLi, jhaaDaat rang ole…”
Music: Kaushal Inamdar
Lyrics: N. D. Mahanor
Singer: Hamsika Iyer

[E&OE]

# Conservation of angular momentum isn’t [very] fundamental!

What are the conservation principles (in physics)?

In the first course on engineering mechanics (i.e. the mechanics of rigid bodies) we are taught that there are these three conservation principles: Conservation of: (i) energy, (ii) momentum, and (iii) angular momentum. [I am talking about engineering programs. That means, we live entirely in a Euclidean, non-relativistic, world.]

Then we learn mechanics of fluids, and the conservation of (iv) mass too gets added. That makes it four.

Then we come to computational fluid dynamics (CFD), and we begin to deal with only three equations: conservation of (i) mass, (ii) momentum, and (iii) energy. What happens to the conservation of the angular momentum? Why does the course on CFD drop it? For simplicity of analysis?

Ask that question to postgraduate engineers, even those who have done a specialization in CFD, and chances are, a significant number of them won’t be able to answer that question in a very clear manner.

Some of them may attempt this line of reasoning: That’s because in deriving the fluids equations (whether for a Newtonian fluid or a non-Newtonian one), the stress tensor is already assumed to be symmetrical: the shear stresses acting on the adjacent faces are taken to be equal and opposite (e.g. $\sigma_{xy} = \sigma_{yx}$). The assumed equality can come about only after assuming conservation of the angular momentum, and thus, the principle is already embedded in the momentum equations, as they are stated in CFD.

If so, ask them: How about a finite rotating body—say a gyroscope? (Assume rigidity for convenience, if you wish.) Chances are, a great majority of them will immediately agree that in this case, however, we have to apply the angular momentum principle separately.

Why is there this difference between the fluids and the finite rotating bodies? After all, both are continua, as in contrast to point-particles.

Most of them would fall silent at this point. [If not, know that you are talking with someone who knows his mechanics well!]

Actually, it so turns out that in continua, the angular momentum is an emergent/derivative property—not the most fundamental one. In continua, it’s OK to assume conservation of just the linear momentum alone. If it is satisfied, the conservation of angular momentum will get satisfied automatically. Yes, even in case of a spinning wheel.

Don’t believe me?

Let me direct you to Chad Orzel; check out here [^]. Orzel writes:

[The spinning wheel] “is a classical system, so all of its dynamics need to be contained within Newton’s Laws. Which means it ought to be possible to look at how angular momentum comes out of the ordinary linear momentum and forces of the components making up the wheel. Of course, it’s kind of hard to see how this works, but that’s what we have computers for.” [Emphasis in italics is mine.]

He proceeds to put together a simple demo in Python. Then, he also expands on it further, here [^].

Cool. If you think you have understood Orzel’s argument well, answer this [admittedly deceptive] question: How about point particles? Do we need a separate conservation principle for the angular momentum, in addition to that for the linear momentum at least in their case? How about the earth and the moon system, granted that both can be idealized as point particles (the way Newton did)?

A Song I Like:

(Hindi) “baandhee re kaahe preet, piyaa ke sang”
Singer: Sulakshana Pandit
Music: Kalyanji-Anandji
Lyrics: M. G. Hashmat

[E&OE]

/