# HyperScience

## Getting Gnuplot Working in J

I have been trying to get Gnuplot working in J under linux. It should be easy, as there are at least two packages in J for using Gnuplot. However, it appears both of these packages presume that the user is operating the language under windows.

The motivator for this is having a way of visualising data in J. The plot package is what I would usually use, but the plot package seems to be incompatible with the i3 window manager in linux. In JQt when I try to plot something the plot window seems to be generated and then immediately vanishes. I have not been able to work out why. At least in gnuplot the window is generated and stays in place until dismissed. Using, gnuplot, although more work, also generates better-looking plots.

My particular interest is in loading, processing and plotting data files. These are usually in tab-delimited or in comma-delimited form, so let’s make an example file using the following data that gnuplot can easily read.

For this example we will look at comparing two models for the drag on a spherical object travelling at supersonic speed, such as a meteor. If you want to know more about drag on objects travelling at high speed you might want to look at this paper. The drag on a sphere is usually characterised in terms of a non-dimensional quantity known as the drag coefficient, which is the quantity we have tabulated in our data file. The definition of the drag coefficient is

C_D = \frac{D}{0.5 \pi \rho u^2 r^2}

where $$C_D$$ indicates the drag coefficient, $$\rho$$ is the gas density, $$u$$ is the gas velocity and $$r$$ is the diameter of the sphere.

This data is saved in the comma-delimited text file ‘DragDataSpheres.csv’. The first column contains the Mach number of the flow, and the second column contains the drag coefficient.

0.22703679008802968, 0.4754504865676933
0.4289222926495784, 0.5029886144003781
0.612450731328545, 0.52777191664627
0.8164462412329196, 0.693557725580885
0.8726990369926486, 0.779240903758345
0.984149624840694, 0.8814834195623001
1.1685642666036478, 0.9643307478710026
1.4622350885781084, 1.0056430036376527
1.7918182355274597, 0.9999307917591553
2.084687254711646, 0.9887089287070719
2.651941628756867, 0.9552155161499962
2.890034857321303, 0.9550838516918039
3.0728458935037084, 0.9328629423630395
3.201345340681785, 0.9521467214705908
3.347653249833309, 0.9382409290784333
3.494045559278546, 0.9298650439303529
3.6039347416929006, 0.9298042757188796
3.7687685153144335, 0.9297131234016695
3.842365571432188, 0.951792240236996
3.97018981626056, 0.9268367613919297
4.097971860942075, 0.8991163289248247
4.372905817712245, 0.9127891765063343
4.83077741110539, 0.9125359756251952
5.05042917549353, 0.9041195783361327
5.251766076145945, 0.8957133090823157
5.892955107483774, 0.9064186423368754
6.5339753382341765, 0.9060641611032807
6.9369445405670005, 0.908606297949917
7.339913742899824, 0.9111484347965532
7.852476726619007, 0.8942751280774458
8.786872378315877, 0.9158782272562309
9.556138855363217, 0.918217803397956
9.775537418870218, 0.8932116843766618


There is an empirical formula to fit this data, and it is given by a sum of two exponentials:

C_D (M) = 2.1 e^{-1.2(M+0.35)}-8.9e^{-2.2(M+0.35)} + 0.92

In hypersonic theory there is an approximate method for calculating drag, due to the great Lester Lees, called the modified Newtonian method. There’s an interesting story to Newtonian methods. As the name suggests, the model was first postulated by Isaac Newton as a way of measuring drag forces at subsonic speeds. The fluid was considered as a series of particles that hit the object like bullets fired from a gun. When the particles collide with a surface they slip along the surface, only imparting the perpendicular component of their momentum to the object. This model never really took off because it was very inaccurate at subsonic speeds. However the approximation becomes pretty good at hypersonic speeds, and so is often used as a simple way of determining the drag force, because it has the advantage of being simple to determine analytically. So I guess that proves that Newton really was ahead of his time. Lees took Newton’s idea and made a modifying calibration factor that removes an offset inherent to the model by fitting the relationship to the pressure coefficient at the stagnation point of the object, which makes it quite accurate. For a sphere, the drag can be computed using the Modified Newtonian method using the equation

C_D = \frac{1}{2} \left( \frac{2}{\gamma M^2} \left( \left[ \frac{(\gamma + 1)^2 M^2}{4 \gamma M^2 -2(\gamma-1)} \right]^{\frac{\gamma}{\gamma-1}} \left[ \frac{1-\gamma + 2 \gamma M^2}{\gamma+1} \right] -1 \right) \right)

as explained in this paper.

We would like to prepare the data in J, then plot it and save it to a graphical file using Gnuplot. First, let’s just plot the first set of data from the file. The following J code sets the directory and then loads the CSV file columns into the variables M_data and CD_data.

1!:44 '/home/sean/ownCloud/Org/blog/Gnuplot/'

a =: 5 }. readcsv 'DragDataSpheres.csv'
'M_data CD_data' =: 0 ". each |:(0,1){"0 1 1 a

text =: 0 : 0
set term qt
set style data points
set datafile separator ","
set pointsize 2
plot "DragDataSpheres.csv" using 1:2 pt 6
set ylabel 'Drag coefficient'
set xlabel 'Mach number'
set nokey
pause 5
set term png
set out 'testplot.png'
rep
set out ''
set term qt
quit
)

text fwrites 'testplot.gnu'
2!:0 'gnuplot < testplot.gnu'


We put all of our gnuplot instructions in an adjective definition called ‘text’. The ‘pause 5’ instruction pauses for 5 seconds to give us enough time to examine the plot before it goes away. Now that we have this, we can plot our two functions

NB. C_D (M) = 2.1 e^{-1.2(M+0.35)}-8.9e^{-2.2(M+0.35)} + 0.92
CD_Fit =: (2.1 *  (^_1.2*(M_data+0.35))) - (8.9* (^_2.2*(M_data+0.35)))) + 0.92
CD_Fit

gamma =: 1.4
term1 =. 2%gamma * *: M_data
term2 =. (((*: M_data)*(*:gamma+1))%((4*gamma* *: M_data)-2*gamma-1))^gamma%gamma-1
term3 =. ((1-gamma) + 2*gamma* *: M_data)%(gamma+1)

CD_Mod_Newt =: 0.5*term1*(term2*term3)-1

(|:M_data,CD_data,CD_Fit,:CD_Mod_Newt) writecsv 'Compar.csv'


Note that I split the more complex modified Newtonian form into three separate terms before combining them. This eases debugging and also makes the probability of incorrectly parsing the right-to-left evaluation of the J code lower.

The three plots can be plotted together using the following gnuplot command…

text =: 0 : 0
set term qt
set style data points
set datafile separator ","
set pointsize 2
plot "Compar.csv" using 1:2 pt 6 t 'data', '' using 1:3 with lines lw 2 t 'empirical fit', '' using 1:4 with lines lt 4 lw 2 dashtype 2 t 'modified Newtonian'
set ylabel 'Drag coefficient'
set xlabel 'Mach number'
set yrange [0:1.2]
pause 10
set term pngcairo
set out 'Compar.png'
rep
set out ''
set term qt
quit
)


Note that it’s better to use the pngcairo terminal type than png. For some reason the latter will not do dashed lines, whereas the former will.

Physically, for those interested, it shows that the modified Newtonian theory is not as good a fit as the empirical curve fit at low Mach number, but it fits the behaviour well at Mach number of 5 or greater. The curve fit won’t help you at all if the ratio of specific heats $$\gamma$$ is not 1.4, but the modified Newtonian method can account for that, which makes it very useful in predicting drag.

To summarise: by loading data, doing the appropriate calculations and saving the data to a text file, we can plot the data from J using a system call to gnuplot, which will plot the raw data and any manipulations we choose to perform, combining the power of J for data analysis with the rich plotting functionality of gnuplot.

NB. Here is the full J source code

## Into the Supercontinuum

Some good news: we got funded to purchase a supercontinuum IR source and a high-speed IR camera. The idea is to couple the light source into a spectrometer after being absorbed by flow, allowing for fast and easy broadband absorption spectra.

I had hoped that NKT would have an IR supercontinuum source available, but apparently they have stopped supplying it for some reason (perhaps the power was lower than they would have liked, or there may have been other problems that I’m unaware of). I have managed to find a French supplier of these sources, so hopefully I’ll still be able to do it. It would be great to be able to see entire vibrational bands of CO2 and CO with this source. CO has bands at 2.3 microns and CO2 at 2.0, and both have bands around 4-4.5 microns. If I can hit that wavelength region, I should be able to hit both species and look at Mars entry problems in this region. The really nice thing about getting so much spectral information in the IR is that you can see any vibrational nonequilibrium in the flow, and absorption is strong, so low density flows can be measured.  It may be difficult to avoid water vapour at these wavelengths, however.

Now I need to do the maths to make sure that we get enough absorption signal and that the source puts enough light out to be detected by the camera over the intended wavelength range, and to find the filters I need to get to limit the detected wavelengths.

This would be a good project for an Australian PhD student with an interest in laser diagnostics and hypersonics. Contact me if you are interested.

## Org-babel for J

As part of my emacs org-mode work flow, I have been using org-babel for a while. This allows you to insert code blocks into org buffers and have those blocks be executed when your file is compiled. This is a really handy method for doing reproduceable research. For example, you can call the source code function in R to do the statistical calculations for data in a table. If the data in the table changes, so will the calculation of the output data change. This prevents the perennial problem of having data in one file (typically a spreadsheet) and not knowing whether the document you generated for a paper used the 12th of September or the 15th of September version of the spreadsheet. By having explicit links to data and to the algorithm that manipulates that data, you can explicitly record the calculations you used to produce your data. And so can anyone else if they want to. This is very important for producing believeable data.

Org-babel is built into emacs org-mode, and supports an amazing array of programming languages, from compiled languages like C to interpreted languages like python or MATLAB, to specialised scripting languages like awk or gnuplot.

The best feature for me is that org-mode can read from or write to org tables, allowing a seamless integration between code and document. However, this capability differs between programming languages. Some languages, like python and common lisp, seem to be very well catered for in this regard. However my favourite programming language, J, is rather less well catered for. In particular, there does not seem to be a built-in way to pass variables to and from the code block. Instead, you can run your code as if it were a script, and the source block will provide the last calculated value as an output. For example,

#+BEGIN_SRC j :exports both
NB. The square root of the sum of the squares of the numbers
NB. between 1 and 10
[a =: %: +/ *: 1 + i.10
#+END_SRC

#+RESULTS:
: 19.6214


The output, as stated by the comment, produces the Euclidean norm of the integers between 1 and 10 inclusive, which is 19.6214, and displays it as the result from evaluating the source block. However, for other programming languages one could supply a variable argument using the :var command in the header, to pass a variable argument to a function. So, for example, the 10 in the example above could be replaced by each of the values in the column of a table.

Like most things in emacs, the code for executing commands in code blocks is available as elisp. So, in theory, it should be possible to modify the existing elisp export code to pass variables, including rows and columns in tables, to a J function. At the moment though, my understanding of elisp is not sufficiently good to be able to work out how to do this, but it sounds like a very useful thing to do, and necessary if J is to be seriously used from within org-mode. If anyone has managed to do this, I’d be very interested to know how it’s done. If not, I’ll need to learn some more elisp and try to reverse engineer how it’s already been done for MATLAB code to see if I can do something equivalent for J.

Oh, and happy new year for 2021. I wanted to get one more blog entry done before the end of 2020, as an old-year’s resolution…

## The Pinebook Pro

I bought a Pinebook Pro way back in November of 2019. For those who don’t know, the Pinebook Pro is an ARM64 laptop made by Pine64, a company that develops ARM64 devices and harnesses the open source software community to develop code that can drive the hardware. It’s a really interesting business model, allowing the company to focus on hardware that meets the needs of the community.

For a long time I had been keen to get an arm64 laptop. I had previously owned a couple of Odroid XU4 single-baord computers that functioned very well as a little linux box for doing basic work, but they always required an available monitor. A laptop was more convenient. For a long time, the only options were chromebook computers, which seemed to involved a lot of messing around to get Linux operating on. I bought a Teres laptop from Olimex and built it, but it was not really fast enough for my work and I had battery problems with it.  So when Pine64 announced the development of a USD199 laptop with an ARM64 processor that was designed to run Linux, and that promised a thin form factor, 4 GB RAM and 64 or 128 GB EMMC storage, I was interested.

I have been using the device for about 8 months now. As an early adopter, I had the usual problems one might expext with an ARM-based linux: the trackpad was inaccurate, the device would not sleep properly, problems with wifi etc. Eventually the trackpad problems were helped by a firmware update. This was great, because the trackpad was nearly unuseable. My biggest problem was that my config files were kept on an owncloud server that was newer than the Debian version for the pineboook I was using, so I could not access these files, which were essential for my workflow. I transitioned from Debian to Manjaro, and the rolling updates solved that problem. The Manjaro folks seem to have really taken to this device, and the OS seems to work well. Figure 1 shows what the login screen looks like.

The device is plain black, with magnesium top and bottom surfaces.  The bezel and palmrest parts are plastic (more on this below).  It’s very light and the hinge is a little stiff, but holds the screen in place well. I personally like the fact that there is no logo, other than the pine logo on one of the keys that operates in place of a Windows key on a windows laptop.

Currently I am using the xfce version of Manjaro, with the i3 window manager, and I really like this combination. The regular updates get rid of many of the software problems, and about the only thing I would like would be better power consumption in sleep mode. Leaving the machine overnight in sleep mode still consumes about 70% of the battery power, which isn’t great. While working, though, I can get at least 7-8 hours use out of the device without resorting to any power reduction tricks. That’s good enough for my needs.

A couple of surprising things about this laptop: the keyboard and the screen. For 199, my expectations were certainly not high. But the screen is pretty good, with clarity and nice resolution. Also, despite the wacgrning you get when you order one of these, there were no broken pixels on it. The screen is better than the elitebooks I have used in the past, which were a lot more expensive. The keyboard is surprisingly good also, for a chiclet keyboard. It’s not a thinkpad, but it’s a lot better than a lot of other chiclet keyboards I have used, or the keyboard on my Surface Pro 4. The wireless is not strong, but it’s OK. The bluetooth also works as well as it ever does, at least for my bluetooth headphones, and the connection struggles at times if the CPU is being used for other tasks. The device has USB A and C ports, with the latter providing ethernet with the appropriate USB C dongle. One other neat thing is that the wifi and camera can be turned off in hardware with some key combinations. For those with privacy concerns, this is useful. There are some other problematic aspects of the Pinebook Pro. Even with the firmware update, the trackpad is not very good. It’s useable, but that’s about it. The speakers are poor, and are directed under the device. But the biggest problem is the structural integrity of the device itself. The plastic is thin and brittle, and after only about a month of gentle use, cracks started to form on the wrist rests, plastic started to break around the USB ports, and eventually the plastic around the trackpad, the power barrel, and near the hinges broke from the stresses generated when the cover was opened and closed. I had the ISO keyboard. Initially I superglued the cracks and sanded the case down, which helped with some of the problems, but they got worse and worse. Figure 2 shows the damage to my keyboard, with the cracks at the power port causing problems with opening the case. If you look carefully, there are some lighter lines at the bottom left that indicate where the superglue repairs were done. Eventually I had to buy a replacement ANSI keyboard that I installed (with firmware update) because I read on the forum that it was a better quality plastic than the plastic on the original ISO keyboard. That remains to be seen: it does not look any different to me. I suspect that I’ll have to get another keyboard in the future. The magnesium bottom and lid parts seem quite resiliant. To replace the keyboard you have to replace every board and cable on the computer, as they are screwed to the keyboard. However, I managed it, so it cannot be too hard (remember to peel the plastic from the keyboard connector). I think the physical strength of the palmrest part of the keyboard is probably the single biggest problem with this device. One other problem for users outside the USA is that they won’t send you a replacement battery. I suppose when the time comes I’ll need to get one from another supplier and get the wiring right. The problem with computer batteries needing to be sent inside a computer for overseas shipping seems to me to be a cop-out. If we are to take e-waste seriously, users should be able to easily upgrade all the components of their device, and the batteries in particular, as even rechargeable batteries are consumables. One of the best aspects of the Pinebook Pro is that components can easily be removed for replacement and upgrade. So the question I set out to answer is ‘Can the Pinebook Pro be a useful everyday computing device?’ For me, the answer is yes. For you, it may not be. It’s not a fast machine, by any means. The Surface Pro i5 runs rings around it, for example. But my needs for a computer are pretty simple. It runs Emacs, Firefox, GIMP and Inkscape well, and internet video is reasonably fast and smooth enough for YouTube. The delay is noticeable in CPU-heavy activities like compilation, but it’s not that bad. In fact, using the i3 window manager, it’s pretty zippy for the most part, with easy keyboard-based swapping between workspaces. I really like i3, and have it configured to easily provide the programs that I use on a day-to-day basis. Like all ARM64 devices, linux applications are not as well catered for as they are for Intel CPUs, but this situation will get better with time, in particular thanks to the popularity of single-board ARM computers like the Raspberry Pi. Despite this limitation, I’m able to do all the programming and text development needed for my scientific work on this device. I wouldn’t recommend doing CAD or playing graphical games on it, but for the text-based tasks I use linux for, it works well enough for my needs, and I really love the long battery life. My Surface Pro lasts about 1 hour on battery after 4 years of use, and it’s nearly physically impossible to replace the battery. In terms of hardware accessibility, the Pinebook Pro is great. I would definitely recommend the Pinebook Pro to tinkerers like me. It’s not for those who are nervous about taking a screwdriver to their laptop, or for those who want their operating system to ‘just work’ out of the box. It is a simple and easy-to-disassemble computer. I’ve been using it for serious work for about 6 months, and can see myself for continuing to do so, at least until the keyboard breaks again. I hope Pine64 keep improving the design and fabrication processes, developing a more robust machine that evolves with time. I love the modular design, and the Manjaro community are doing a great job making linux work for it. For USD199 (plus postage) this laptop’s not a bad deal at all. ## DSMC in J 1 ## Background & Motivation Some of my research involves flow having very low densities, or flows of moderate densities in very confined spaces, such as capillary tubes. These flows are known as rarefied flows. Rarefied flows have some interesting properties: in particular, flow can slip past boundaries, whereas at higher densities the flow would have zero velocity at a surface relative to the velocity at that surface (why cars remain dusty even when you drive them fast). In hypersonics, rarefied flows are interesting because as the flow is fast and the density is low, then fluid mechanical or chemical reaction changes can take place over similar time scales as the flow time past the object of interest. This leads to what are called nonequilibrium processes, where time scales can have an important effect on flow or on chemical reaction processes. ## The DSMC Method Because the computational solution of the fluid flow equations that treat fluids as a continuous medium assume no flow slip at surfaces, those models begin to fail when the flow gets rarefied. One very successful method for simulating rarefied flow is the direct simulation Monte Carlo (DSMC) method. This is a statistical model of flow, and was invented in the 1960s by the Australian aeronautical engineer Professor Graham Bird. I was fortunate to meet Professor Bird on several occasions later in his life (he died in 2018) and he was a very inspiring scientist. He continued to make significant contributions to rarefied flows right up to the end of his life. DSMC is a fairly straightforward simulation method based upon a statistical treatment of collisions in rarefied gases, and because it models collisions with walls, then the slip phenomenon automatically drops out of the simulation, provided the modelling of collisions of gas atoms or molecules with the wall are physically correct. Now the most obvious way to simulate the flow of a low density gas using a computer would be to keep track of the position and momentum of every nitrogen and oxygen molecule in an air flow, step forwards in time in very small increments, calculates trajectories for each molecule during this time step to determine whether individual molecules collide with each other or with surfaces and then implement some sort of model (like Newton’s laws) for how energy and momentum are transferred for whatever collisions that occur during the time step. This idea is called Molecular Dynamics (MD). It is very useful because of its simplicity and the transparency of the physical modelling involved, but it involves too much computation for all but the smallest flow volumes and all but the lowest densities – the flow domain has to be checked at each time step for collisions between each molecule and every other molecules. DSMC overcomes much of the problems of MD for larger flow volumes by making two very clever assumptions. The first is that the behaviour of very large collections of molecules can be simulated by considering the behaviour of a much smaller number of molecules, appropriately scaled. This alleviates the problem of dealing with astronomical numbers of physical molecules. The second assumption is that on average the behaviour of collisions between molecules can be explained by statistical means based upon knowledge of the relative speeds of the potential collision partners. Thus instead of having to solve the conservation of momentum and energy equations for each collision, the probability of collision and the post-collision trajectories can be calculated using random number generation, with the overall behaviour of the flow averaging out to the correct values. These two assumptions make DSMC capable of accurately simulating rarefied flow behaviour for a range of practical engineering problems. I will try to explain how I split the problem up and tested the components independently as I go through the design and implementation of DSMC. The implementation will be split among various posts as I go along (and as it’s being done in my spare time, this might take a while), and I’ll discuss how I decided to attempt different solutions that didn’t work, and the struggles to get an elegant and functional loopless code. I’m not an expert in either J or DSMC, just an enthusiastic amateur. But I hope that some people will find it interesting enough to begin their own investigation of this simulation method, or be inspired to take a closer look at the frankly beautiful J programming language. I teach a very basic version of the DSMC method to my hypersonics class, and this year I asked them to code up a simple solution as an assignment question. For this blog, I thought I would go through my method of implementing the simulation, so that those unfamiliar with molecular simulation may be tempted to try it out. To make the problem more fun for me, and because it’s a good match, I have decided to implement my solution in the J programming language. J is an array-based programming language, created by Kenneth Iverson and descended from APL, the first of the array-based languages. I chose J because, being an array-based language, it is very well suited to operation on arrays of large numbers of particles that are all doing similar things. Given that very few people know the J language, and that the intersection of those who are interested in J and are interested in DSMC has probably only one member (me) then this can be seen either as a tutorial for the J programming language that uses DSMC as an example application, or an explanation of simple DSMC that uses J as a method for describing the algorithms. My other goal in putting this together was to see if I could write some nice functional code in J that helps me cement my understanding of the DSMC method. The flowchart in Fig. 1 shows the algorithm at its simplest. A representative set of molecules is uniformly distributed across the flowfield, with randomised thermal velocities superimposed upon a bulk velocity. The thermal velocities are determined using a Boltzmann distribution as a function of the initial temperature of the gas. The flowfield itself is broken up into a group of collision cells that can be of arbitrary shape or size, with a fixed number of particles within the cell. The size of the cell is therefore dependent on the local density of the flow. These particles (which I will, for convenience, call molecules regardless of whether they are molecules or atoms) are each representative of millions to billions of actual particles in the flow. A very small time step, which depends on the size of the cell, is used to determine the motion of the molecules and, along with the relative velocities of pairs of molecules, the probability of collisions. Collisions with walls and with other molecules are simulated, and the particles are re-assigned to their new cells if they move from one cell to another. After this movement, the velocities of the particles in each cell are used to determine the flow properties in the cell, and the time is incremented by Δt again. This continues until either the flow has reached a steady state or a pre-assigned time has elapsed, at which point the code stops. As Fig. 1 and the description above indicates, the DSMC algorithm at heart is not complicated, although it should be pointed out that state-of-the-art DSMC implementations have many improvements to this simple model, to ensure that the code runs quickly and that cells or simulations are parallelised. Some real DSMC codes that you can download and use include Bird’s DS2V code or Michael Gallis’ SPARTA code, amongst others. I mention these ones specifically because they are directly downloadable so you can play with them. There is a lot of information available in books about the DSMC method. Some references that you should look at include Prof. Bird’s original text bird1995molecular and his more recent implementation book bird2013dsmc. Other more recent texts that cover the DSMC algorithm include those by Sharipov sharipov2015rarefied and by Boyd and Schwartzentruber boyd2017nonequilibrium. We have used DSMC for validation of a number of hypersonic separated flow configurations. Some references to this work include gai2019large, le2019rotational, prakash2018direct and hruschka2011comparison. Most of the textbooks mentioned above contain a fair amount of kinetic theory, because there is a lot of physics to be considered when dealing with collisions of molecules with each other and with surfaces. For the purposes of explaining the process of the DSMC algorithm, that extra detail is not necessary. Instead, I have used the paper by Alexander and Garcia alexander1997direct as the model for the DSMC method used here. The paper itself can be found on Prof. Alejandro Garcia’s web site (Paper), along with a lot of other interesting simulation papers. He has also written a book on numerical methods in physics which has one chapter dedicated to implementation of DSMC in Matlab or Python (or C++ or Fortran) if you prefer to avoid J or my explanations. Over time on this blog, the plan is to implement a simple DSMC simulation in J of the flow of low density gas through a heated capillary tube of square cross-section. Each one or two steps in Fig. 1 will be implemented and described in individual blog posts, building up to the final program. # Bibliography • [bird1995molecular] Bird, Molecular gas dynamics and the direct simulation of gas flows, Oxford, United Kingdom: Clarendon Press(Oxford Engineering Science Series,, (42), (1995). • [bird2013dsmc] Bird, The DSMC method, CreateSpace Independent Publishing Platform (2013). • [sharipov2015rarefied] Sharipov, Rarefied gas dynamics: fundamentals for research and practice, John Wiley & Sons (2015). • [boyd2017nonequilibrium] Boyd & Schwartzentruber, Nonequilibrium Gas Dynamics and Molecular Simulation, Cambridge University Press (2017). • [gai2019large] Gai, Prakash, Khraibut, Le Page & O’Byrne, Large scale hypersonic separated flows at moderate Reynolds numbers and moderate density, 100005, in in: AIP Conference Proceedings, edited by (2019) • [le2019rotational] Le Page, Barrett, O’Byrne & Gai, Rotational temperature imaging of a leading-edge separation in hypervelocity flow, 110001, in in: AIP Conference Proceedings, edited by (2019) • [prakash2018direct] Prakash, Gai & O’Byrne, A direct simulation Monte Carlo study of hypersonic leading-edge separation with rarefaction effects, Physics of Fluids, 30(6), 063602 (2018). • [hruschka2011comparison] Hruschka, O’Byrne & Kleine, Comparison of velocity and temperature measurements with simulations in a hypersonic wake flow, Experiments in fluids, 51(2), 407-421 (2011). • [alexander1997direct] Alexander & Garcia, The direct simulation Monte Carlo method, Computers in Physics, 11(6), 588-593 (1997). ## Hello, Org This is a test blog post for writing wordpress blog items using org-mode. I’m hoping this will let me populate my blog in a more seamless manner than editing it via the WordPress web interface. ## Introduction When Ι started this blog, I got an account with an ISP and installed WordPress using some kind of automatic template. The good thing about this is that I could start a blog without knowing what I was doing. The unfortunate part about it is that when I need to configure the blog, I have no idea whatsoever about how things are set up. Also, I would need to log in to the WordPress site and use their editor to build the pages. But what I really want to do is use org-mode directly to upload posts to my blog. As I do most of my work documentation it would be awesome to convert some of that to my web site. Fortunately some awesome person has already done the work to make this possible. It’s called Org2Blog, created by Puneeth Chaganti, and currently maintained by Grant Rettke. It’s an org-mode package that allows you to edit posts using org-mode markup and extensions. You can edit and upload the post without leaving emacs, which is great! The remainder of this post contains some fairly useless examples of this packages capabilities. ## Examples Figure 1 is an example of html import for images. One of the nice things about org-mode is you can specify different output parameters for images in pdf and html export formats. This can be handy for making things work in HTML. Here is an equation, in case you ever need to know the solution to a quadratic equation: $x = -b \pm \frac{\sqrt{b^2-4 a c}}{2a}$ • Here are some points • $$\LaTeX$$ is great to put inline into your blog, like $$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$ • Centered equations use two dollar signs, as opposed to inline equations like that above, which use only one $\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$ I have not yet done much to see what can be done with org-mode and wordpress. There are several things I don’t know how to do. For example, to center the image above I had to set margins, and if I were to caption it, the caption would be left aligned. I also don’t know how to number equations. References would be the next interesting thing to try hruschka2010two. Well, it seems that citations from a bibtex file will export to WordPress, but the citation style, based on the key, does not seem to change (ie I can’t get numbered or superscript citations). Nonetheless, I’m declaring the export sufficiently capable to be useful for most blog posting purposes. # Bibliography • [hruschka2010two] Hruschka, O’Byrne & Kleine, Two-component Doppler-shift fluorescence velocimetry applied to a generic planetary entry probe model, Experiments in Fluids, 48(6), 1109-1120 (2010). ## Reminiscences on programming I’ve just been thinking: programming computers has been a big part of my life ever since I was a child. The first computer I ever got to touch was a microbee computer in year 7. Before that I had seen some Atari 400s in Myer, and a TRS-80 at Tandy Electronics (Australia’s version of Radio Shack), but I was not allowed to play on them. Microbees were an Australian-made computer built specifically for the education market. For some reason our school had two of these. We were allowed to use some kind of word processor on it, but nobody at school seemed to know what to do with it. I don’t remember much about it other than using it made me want a computer. At around the same time as I was using the microbee at school, my father took early retirement from his job on the waterfront and we moved from Western Sydney to a very small town. I was about 12. My parents had never had much money, but they were keen on my education, and I was most likely constantly banging on about computers so one day to my amazement my Dad put down the unthinkable amount of950 on a Commodore 64 with disk drive and 1 floppy disk, and a programmer’s reference guide and we walked out of the store with it.  I guess that once we had brought the (relatively inexpensive) house he had one shot at buying something for each of us:  Mum got an olive-green IBM Selectric typewriter, Dad got an air conditioner and a monstrous Kreisler TV with roll-out wooden doors and I got the Commodore.  Then we were poor again!

I would set the computer up in front of the big TV and spend hours with it and the programmer’s reference guide.  My father refused to buy games (having spent so much on the machine) so any games were going to have to be made by me.  My limit on the computer was around 4 hours sitting cross-legged on the floor until I would lose all feeling in my legs or Dad would make me do some outside work (the house was a fixer-upper).  I had no idea what I was doing, but I read everything I could.  During those times nothing else mattered to me.  I learned to program in BASIC, and read all the copies of Byte Magazine and Creative Computing trying (usually without success) to make the type-in basic programs work.  On the odd occasions I’d save up to purchase Australian Personal Computer or one of the many British Commodore magazines to find out more about programming.  But my town was no silicon valley, and there was no internet.  The only person I knew who knew how computers worked was the Hungarian TV repair man, who had to come in to fix a problem with Dad’s pride and joy (which I’m sure he thought my computer was responsible for creating…).  This fellow explained to me how flip-flops worked, which was to me like learning the mysteries of some secret society.

At my school we also had computers: Apple II/es in the maths department and a 32 kB BBC micro in the library.  Again, nobody seemed to know what to do with them, but I was happy to fill the void.  I think I was the only student who ever got to use the BBC micro.  It was hooked up to a Telstra-run bulletin board service called VIATEL, if I remember correctly, which was a very primitive text-based centrally served prototype for the internet.  You could check the weather, share prices and other things.  I didn’t get much of a chance to look at it, though, because they charged about 10 cents per page of text downloaded, and in the first day of playing with it, I managed to rack up a bill of around \$65 in about an hour.  Before I had another chance to check my portfolio and play online poker I got called into the Vice Principal’s office and it was explained to me that I would no longer be using that computer…

We kept using the Apples, which were really nice machines.  Very sturdy construction, but only 8 colours on the display, compared to the amazing graphics and sound capability of the Commodore at home.  The sprite graphics were great.  I remember trying to program graphics on the Apple but getting nowhere.  I didn’t understand about things like memory mapping that would have really helped.  There was one older kid at the school (by the last name of Ward) who would make graphics of a sort by using lots of print statements strung together to make eg a car race track scroll down the page.  We looked down on these  ‘Wardy graphics’ programs as primitive, but at least he was able to make things that looked like animations, and he put so much time into it.

On the C64 you were limited to BASIC, although I knew that assembly language or a compiler was what all the professional programmers used.  But that stuff was certainly not readily available to me.  I think I will take to my grave the knowledge that POKE 53281,0 turned the background from the default blue to black, and that putting different numbers using the POKE command at location 53280 would do the same for the screen border.

Then one fateful day in 1985 I found a cartridge in the K-mart Albury bargain bin.  It was HES Forth, an implementation of the Forth programming language for the C-64.  Not only was it a much better language than Commodore basic, with a built-in line editor, but it also had a (somewhat unusual) assembler, so that now I could finally take full advantage of a computer by converting code to machine language!  I didn’t accomplish a lot, but I learnt a lot about computers and the Forth language paradigm.  In fact, I still use that language when teaching microcontroller-based instrumentation.    I remember trying to decipher the terse user manual with all its assumed knowledge, and trying to reverse engineer a prime number generating program that they included as a demo.  That really flicked a switch somewhere in my head and programming has varied somewhere between an obsession and an interest ever since.

The line editor from HES Forth for the c64

All the programming since has been trying to recreate the thrill of making a computer do something I want it to do, delighting in working out some trick to use the computer to model something.  In hindsight I’m glad my Dad refused to buy me any games, though some of those Infocom titles did look pretty sweet at the time.  Instead I got hooked on a pastime I still get great pleasure from some 35 years later.

Over the next indefinite period when I can find the time, I’ll write up a little programming project I’ve started to model the Direct Simulation Monte Carlo method for simulating rarefied flows, using my current favourite programming language: J.  I’ll try to split the task into little parts and explain what I’m doing at each step, in case the 13-year-old version of me is listening.  I guess that’s what made me think of writing this post.

## Marking pdf Assignments in Emacs

Most of the undergraduate student assignments I need to mark are numerical or analytical in nature.  The assignments are for small classes, and are often written on paper, and even if submitted electronically they are relatively easy to mark up on a tablet, because the answer is either correct or it isn’t.  But I recently had to mark a large number of assignments, for a course on the social context of engineering, where answers to questions are in paragraph form, and are fairly open-ended.  This requires explanation on my part for why marks were not allocated and suggestions on what would have made the answers better.

First time I did this I used a tablet and pen, and although it worked, it was very time consuming and messy to add comments.  Using Adobe Acrobat under Windows was not better, as I find the comment interface unwieldy when I have to use it a lot.  The most tedious aspect of this was that many of the comments were the same for large numbers of students, requiring you to type the same thing over and over again: this year I had around 75 students, with 6 pages and on average around 6 individual comments per page – a total of 2700 comments! Many of the mistakes were common to several students in the class.

In an attempt to improve the experience of marking these assignments, I looked at doing the marking in emacs, using two very simple tools: the pdf-tools package maintained by Andreas Politz, and the built-in registers of the editor.  If you do much marking up of pdfs, this may be of interest to you.

If you use emacs, and don’t currently use pdf-tools, you should.  It’s an easy install from the melpa archive, and it is a lot faster than the default pdf viewer DocView.  Most importantly, it has commands that are useful for marking up and annotating pdf files.  I have added the following commands to my init.el file to allow single-key commands in pdf-tools such as ‘h’ for highlight text, ‘s’ for strikeout and ‘t’ for text comment, as well as ‘d’ to delete existing comments.  I also have changed the default strikeout line from red to green, because red is so judgemental…

Configuration file settings for pdf-tools

When this is loaded, opening the pdf file provides a view just like that of a normal pdf-viewer, scaled to fit in the emacs window.  If I select text and hit ‘h’ I highlight that text in the pdf and get to edit a comment on the highlighted text in the minibuffer.  Pressing C-c C-c exits from the minibuffer and the comment can be seen when the cursor rolls over the highlighted text in the pdf.  Pressing ‘t’ does the same, but produces an icon in the pdf instead of the highlighted text.

Annotating in pdf-tools

Once mastered, this is a very quick way of adding comments or deleting text is very fast, as only a few keystrokes are required to add annotations, which are automatically timestamped and user stamped.  Note that I changed my user designation to anonymous here, as sometimes (eg if using for annotating review papers) it’s not desirable to identify.  By default it’s your username.

As I hinted previously, what makes this even more useful is the effectiveness in combination with emacs’ registers.  I had not really used these much previously, as I had no idea what one was supposed to do with them, but populating many pdfs with identical comments is one example of where they can be useful.

While editing a comment in the minibuffer, you can select it and type C-x-r-s-1 and it will save that text to register 1.  Then the next time you want to insert that text in a comment, you type C-x-r-i-1 and it will insert the text.  The box below gives the general idea.

Using emacs registers to recycle comments

The process can then be repeated as many times as necessary when needed in a comment.  The usual C-x C-s will save the pdf for you.  Another handy command is C-c C-a l, which lists the annotations.

This procedure is not flawless: there is a bug that comes up every so often (but not always) when editing existing annotations with pdf-tools, where the link to the animation is lost and the updated animation cannot be edited.  If this happens, kill the annotation minibuffer and make and delete another comment, then try again.  This works for me.  The only other thing I’d like to see from the excellent pdf-tools package for marking up documents is a carat symbol for insertion of text.  But I can use it perfectly well in its current form.

You can find out more about registers at https://www.emacswiki.org/emacs/Registers.

The source for pdf-tools is currently at https://github.com/politza/pdf-tools.

## Where my students go:

Sometimes I’m asked by prospective students where previous PhD students have ended up. This can be difficult to answer, and ex-students and ex-postdocs move from place to place, particularly in the early part of their career. Some of the first jobs that my PhD students (those I have been primary supervisor for) have landed are:

• Researcher at ISL Saint Louis in France (Robert Hruschka, 2012)
• Postdoc at the University of Queensland and Rocket Labs (Stefan Brieschenk, 2014)
• Postdoc in laser diagnostics and hypersonics at the Indian Institute of Science in Bangalore, followed by another postdoc on clean combustion diagnostics at King Abdullah University of Science and Technology (Yedhu Krishna, 2016)
• Engineer at SpaceX (Tremayne Kaseman, 2017)
• Postdoc funded through Australian Academy of Science and Japan Society for Promotion of Science in Japan, working on hypersonic experiments (Rounak Manoharan, 2017)
• Postdoc in hypersonics research at Oxford University (Laurent Le Page, 2019)
• Postdoc in photoacoustic spectroscopy for biomedical applications at a Chinese Research Institute (Rongkang Gao, 2018)

So it seems that most students have gone on to do science/engineering research and at good institutions. I’m proud of what they all have achieved both during and after their PhDs.

## Research notes

One of the problems I have been engaged with for many years now is the idea of how to keep a consistent record of my research that I can come back to years later and pick up where I left off.

Having thought a lot about this, I have some important criteria for such a record.  Lab notes must be

1. Future-proof (not dependent on proprietary software);
2. Based fundamentally on ASCII text;
3. Flexible enough to cope with a variety of experiment structures (one-off experiments, repetitive experiments, numerical experiments etc);
4. Easy to input and maintain;
5. Able to time-stamp the state of an experiment at the time it was performed;
6. Able to incorporate the source code used to analyse the data;
7. Able to facilitate collaboration with my group members and external colleagues;
8. Easy to transform into outputs like papers and presentations;

I have tried many different notetaking systems to achieve this, including commercial systems like LabArchives, Microsoft OneNote, Microsoft SharePoint, My own TikiWiki webpage, Zim desktop wiki, Tiddlywiki and others I have forgotten, but none of them could give me what I need according to the above 8 points.  I believe I now have a system that works the way I need it to for lab notes, though I know it is not for everyone: emacs org-mode.  I hope to write up a little more about org-mode in the future, and why I think it’s a great way to produce consistently high-quality, self-documenting research outputs.