## Heat Engines and Finite-Time Thermodynamics

If you completed the standard curriculum of physics, you should be familiar with the concept of a heat engine:

Moreover I bet you know that the maximum efficiency is achieved by a Carnot heat engine, for which the efficiency is:

$\displaystyle{\eta = 1 - \frac{T_c}{T_h}. \;\;\;\;\;\;\;\;\;\;\;\;\;\;\; (1)}$

You should also be aware that Carnot heat engine implies the processes involved to be reversible, which by turn means that the engine proceeds infinitely slowly. But if you are like me, chances are you haven’t made the final step to conclude that such engine is absolutely useless! Indeed, if it operates infinitely slowly then it has zero power. Since heat engines are made to do some actual work, zero power is not what we are looking for.

Thus we need a simple model which would take into account the finite time required by an engine to perform a cycle. Fortunately there is such a model by Curzon and Ahlborn. For an introduction to a finite-time thermodynamics I refer you to a book “Understanding non-equilibrium thermodynamics: foundations, applications, frontiers” by Georgy Lebon, David Jou and José Casas-Vázquez. The rest of the post follows it.

In essence Curzon and Ahlborn heat engine operates in a Carnot cycle, with two isotherms and two adiabats. However, the heat flux between various systems (cooler, working substance, heater) is governed by Newton’s law:

$\displaystyle{\frac{\text d Q_{12}}{\text d t} = \alpha_{12} (T_2 - T_1).}$

It is also assumed that these heat transfers are the only source of irreversibility in a system and their combined duration almost equals to the length of the whole cycle. Leaving aside calculations, we get for the power:

$\displaystyle{P(T_c, T_c, T_{h \to w}, T_{w \to c}) = \frac{T_{h \to w} - T_{w \to c}}{\dfrac{T_{h \to w}}{\alpha_{h,w}(T_h - T_{h \to w})} + \dfrac{T_{w \to c}}{\alpha_{w,c}(T_{w \to c} - T_c)}}, }$

the notation used is explained in this figure:

To find the maximum possible power given fixed $T_c$ and $T_h$ one have to solve the following system:

$\displaystyle{\frac{\!\!\! \partial P}{\partial T_{c \to w}} = 0, \;\;\;\; \frac{\!\!\! \partial P}{\partial T_{w \to h}} = 0.}$

If you are patient enough, you’ll ultimately get the efficiency, corresponding to $P_\text{max}$:

$\displaystyle{\eta_{\text{max power}} = 1 - \sqrt{\frac{T_c}{T_h}}. \;\;\;\;\;\;\;\;\;\;\;\;\;\;\; (2)}$

Surprisingly, the result does not depend on $\alpha_{c,w}$ or $\alpha_{w,h}$. As an illustration of differences between Carnot’s result (1) and the result of Curzon and Ahlborn (2) I’ll quote “Understanding non-equilibrium thermodynamics”:

As an illustration, consider a power station working, for instance, between heat reservoirs at 565 and 25 °C and having an efficiency of 36%. We want to evaluate this power station from the thermodynamic point of view. It follows from (1) that the Carnot’s maximum efficiency is 64.1%; our first opinion on the quality of the power station would be rather negative if Carnot’s efficiency is our standard for evaluation. However, according to (2), its efficiency at maximum power is 40%. Thus, if the objective of the power station is to work at maximum power output, it is seen that the efficiency is not bad compared to the 40% efficiency corresponding to this situation. We can therefore conclude that, to have realistic standards for evaluation of an actual heat engine, one needs to go beyond Carnot’s efficiency and to incorporate finite-time considerations.

If you got a taste for finite-time thermodynamics, I suggest you to read the book. Keep in mind, that power maximization might be not the only goal, for example one probably would like to minimize pollution or running cost of the plant. These topics are also discussed in that book.

I’ll conclude with a thought (or a question) of my own. It is obvious, that power, unlike efficiency, is an additive quantity. Hence one could combine several (let’s say n) low power, but efficient heat engines to produce a single engine. Roughly, the efficiency of such engine would remain high, but it’s power would increase n times. So I wonder is that the reason why to produce a powerful car engine one adds cylinders instead of increasing a power production of a single cylinder?

UPD I think John Carlos Baez is awesome, shame on me I’ve never heard about him before.

Usually I find it quite pointless to publish a post containing just a link. But not this time. The link I’m presenting (ta-ta!) is http://johncarlosbaez.wordpress.com/ . I was combing google blog search for GENERIC formalism when I came across the aforementioned blog.

To make things clear the physics of complex systems is the only thing I care about. All that stuff about Haskell, symbolic computations or math in general is nothing more but my way and tools to the theory that would describe the world around me. Indeed geophysics textbook is one of my favorite books. And of course I’m concerned with what is happening to my world, my planet.

That’s why John Baez‘s blog caught my attention. The author is a rather famous physicist who has a relevant knowledge in the field of complex systems and who may share the views on the environment similar to mine [1]. Thus I’m going to spend quite a time reading his blog and works.

[1] There is even a good documentary film by Ed Watkins “Into The Cool” (password: Montana). Amazingly as far as I understand this documentary was part of Ed Watkins’ MFA. If you want to introduce your friends who are not very good at physics to the thermodynamical view on our environment, just show them the film.

## Probably the best source of information about symbolic computations

Yesterday I came across the sci.math.symbolic Usenet group and it seems to provide almost every bit of information about symbolic computations and computer algebra systems. This newsgroup dates back to 1986 so search it to find answers.

With this newsgroup I learned about lots of interesting stuff I wasn’t even aware of. Among it are Rubi (Rule-Based Integrator) and a poor’s man integrator. I really like the picture on the latter site. I’ve also found some good references to articles and books, for example a good introduction to expression simplification.

Google Groups’ web interface to Usenet doesn’t filter spam. To cope with this difficulty I use Pan newsreader. As a server I use http://www.eternal-september.org/ Here is how Pan looks:

Unfortunately I couldn’t find a server which would provide 20 years archive of the newsgroup, 5 years at most. Besides Google Groups sci. math.symbolic can also be read at mathforum.org

To sum up if you want to write your own CAS sci.math.symbolic is the point to start.

## Haskell Repa Package. Some Traverse Examples

This post provides some simple examples of the traverse function from the repa package. I found this function to look quite tricky and even frightening for a newbie so I share my experience with it. The repa package itself is so unbelievably awesome that I won’t tell anything about it, if you are interested check Repa tutorial.

We will need some dummy arrays to illustrate the usage of traverse. They will be provided by genArr function:

import Data.Array.Repa as R

genArr :: Int -> Array DIM1 Int
genArr n = fromList (Z :. n) [1..n]


Thus

*Main> genArr 12
[1,2,3,4,5,6,7,8,9,10,11,12]

As usual, the best point to start studying a function is a type of that function. From repa sources:

-- Generic Traversal -----------------------------------------------------------------------------
-- | Unstructured traversal.
traverse
:: forall sh sh' a b
.  (Shape sh, Shape sh', Elt a)
=> Array sh a                     -- ^ Source array.
-> (sh  -> sh')                   -- ^ Function to produce the extent of the result.
-> ((sh -> a) -> sh' -> b)        -- ^ Function to produce elements of the result.
--   It is passed a lookup function to get elements of the source.
-> Array sh' b

{-# INLINE traverse #-}
traverse arr transExtent newElem
= arr deepSeqArray
fromFunction (transExtent (extent arr)) (newElem (arr !))


It is readily seen that traverse requires three arguments. The first one is the array to be traversed. The second argument serves to specify the shape of the output array (from the shape of the input array). If these two shapes are the same, then the second argument should be id. The third argument might be the most confusing, it is in charge of filling the output array.

Now we come with the first example — how to produce an identical array with traverse:

identicalArray arr = traverse arr id id

A slightly less stupid example — how to get the first s elements of an array:

firstS s arr = traverse arr (const $Z :. s) id  *Main> firstS 4$ genArr 12
[1,2,3,4]

The next example provides the function that adds to each element of an array its index:

plusI arr = traverse arr id $\f (Z :. i) -> f (Z :. i) + i  You might be confused with the last argument. If you are puzzled (like I was) “what does that f mean?” the answer is indeed provided by documentation — “… function to get elements of the source”. That is it is just index arr function and you may read \f (Z :. i) -> f (Z :. i) + i  in the last example as \arr ! (Z :. i) -> arr ! (Z :. i) + i  If you are not familiar with \f(x) -> ... syntax it is equivalent to \f -> \x -> ... . And finally some justification: *Main> plusI$ genArr 12
[1,3,5,7,9,11,13,15,17,19,21,23]

## HyperDoc fonts problem in Ubuntu 11.04

In a fresh installation of Natty Narwhal HyperDoc (both in FriCAS and Axiom) seems to miss some fonts:

(HyperDoc) Cannot load font -adobe-courier-medium-r-normal--18-*-*-*-m-*-iso8859-1 ; using default.
(HyperDoc) Cannot load font -adobe-courier-bold-r-normal--18-*-*-*-m-*-iso8859-1 ; using default.

As a result HyperDoc uses some small poorly visible fonts. To solve the problem one should actually install these fonts. I’m not sure where are they exactly, but installing the following packages helps:

xfonts-100dpi
xfonts-75dpi

## HyperDoc Customization

Before I actually resolved the issue described above I’ve tried to customize HyperDoc via .Xdefaults file, as described in the Axiom Book. I should say that after all I use the default HyperDoc with the proper default fonts — it has its charm.

Nevertheless here are some hints on tuning HyperDoc. First of all, the right file is .Xresources rather than .Xdefaults (this is valid at least for Ubuntu). This file should be placed into your home directory. I’ve made a template for it based on Axiom book, which you can download. Note that comments are preceded by ! (bang) instead of #.

You probably will be interested in fonts available for you. Issue

xlsfonts

command to get the list of X fonts installed. After everything is done with .Xresources you can update your configuration on the fly with

xrdb -merge ~/.Xresources

## Animation With Gnuplot. Animating Pendulum

Gnuplot can be used to produce animations in gif format. You only need to choose the appropriate terminal:

set terminal gif animate delay 4

Here delay 4 means that there will be 0.01 × 4 seconds between frames in your animation (1 / 0.04 = 25 frames per second). But what is the frame in gnuplot? Basically it is a plot command, so for 100 frames you need 100 plot commands. For example the following code

set terminal gif animate delay 4
set output "TrigAnimation.gif"
set xrange [-3:3]
set yrange [-3:3]

plot 1.0 * sin(x)
plot 0.9 * sin(x)
plot 0.8 * sin(x)
plot 0.7 * sin(x)
plot 0.6 * sin(x)
plot 0.5 * sin(x)
plot 0.4 * sin(x)
plot 0.3 * sin(x)
plot 0.2 * sin(x)
plot 0.1 * sin(x)
plot 0.0 * sin(x)
plot -0.1 * sin(x)
plot -0.2 * sin(x)
plot -0.3 * sin(x)
plot -0.4 * sin(x)
plot -0.5 * sin(x)
plot -0.6 * sin(x)
plot -0.7 * sin(x)
plot -0.8 * sin(x)
plot -0.9 * sin(x)
plot -1.0 * sin(x)
plot -1.0 * sin(x)
plot -0.9 * sin(x)
plot -0.8 * sin(x)
plot -0.7 * sin(x)
plot -0.6 * sin(x)
plot -0.5 * sin(x)
plot -0.4 * sin(x)
plot -0.3 * sin(x)
plot -0.2 * sin(x)
plot -0.1 * sin(x)
plot 0.0 * sin(x)
plot 0.1 * sin(x)
plot 0.2 * sin(x)
plot 0.3 * sin(x)
plot 0.4 * sin(x)
plot 0.5 * sin(x)
plot 0.6 * sin(x)
plot 0.7 * sin(x)
plot 0.8 * sin(x)
plot 0.9 * sin(x)
plot 1.0 * sin(x)

produces this animation:

Obviously such input files should be generated by some script. You can use any language you like, as for me I prefer Haskell.

Gnuplot is not very good at optimization, the resulting gif’s prove to be quite large. Use gifsicle to improve the output:

gifsicle -O TrigAnimation.gif -o TrigAnimationOpt.gif

## Animating pendulum.

It is a common situation when your graphics is presented by a collection of points rather than a combination of elementary functions. Data files are used in a case of static graphics, but it is unpractical to have hundreds of files to make an animation. Fortunately gnuplot allows to embed data right into the plot files. Gnuplot provides some dummy file names to use in the plot command, ‘-‘ is among them. Read more in the gnuplot documentation.

Now I show you how to create a simple animation of a pendulum. The pendulum is represented as a two-point curve (thus not a curve actually). The code should be self-explanatory:

set terminal gif animate delay 4
set size ratio -1
set output "1.gif"
set xrange [-1:1]
set yrange [-1.5:0.5]
set nokey
unset xtics
unset ytics
unset border

plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.479425538604203 -0.8775825618903728
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4780215428037317 -0.8783481112950264
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4738112432235755 -0.880626428058419
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.466800091497177 -0.8843628636358648
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4569984452008731 -0.8894674929889145
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4444233976367903 -0.8958168583103197
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4291011875307727 -0.9032564258612726
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.411070043719281 -0.9116037621448413
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.39038328875162626 -0.9206524251113796
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.3671125020501049 -0.9301765482092696
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.34135052959363993 -0.9399360701378268
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.3132141245325882 -0.9496825323197665
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.28284601279603805 -0.9591653314446803
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.25041620009002624 -0.9681382787249309
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.21612237137479443 -0.9763662840304019
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.18018927968938878 -0.9836319552988401
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.14286707582542332 -0.9897418848594277
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.10442859068998299 -0.9945323873290924
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
6.516564435982236e-2 -0.9978744604383706
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
2.538451549059462e-2 -0.9996777612677537
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-1.4599242492294932e-2 -0.9998934253802508
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-5.446641018931241e-2 -0.9985156033638581
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-9.389988024412708e-2 -0.9955816453160126
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.13259033778420903 -0.991170924879392
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.17024158285333169 -0.9854023561305261
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.20657525765157456 -0.9784307144229404
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.24133477963819308 -0.9704419220834314
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.2742883317339307 -0.9616474983457385
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.30523081908567273 -0.9522783978859802
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.33398476377996117 -0.9425784728938188
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.36040017012922443 -0.9327977901832883
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.38435344967278007 -0.9231860190257615
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.40574554346496705 -0.9139860797399042
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4244994170709183 -0.9054282107966652
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4405571294313594 -0.897724576753472
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4538766898188645 -0.8910645040843397
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.46442891776070894 -0.8856103998641934
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4721945099925054 -0.8814943815662909
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.47716149765074795 -0.8788156263743239
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.47932324770880824 -0.8776384359210121
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4786771269229756 -0.8779910068792081
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4752239060969425 -0.879864898194015
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.46896793905072987 -0.8832151901674421
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4599181059834833 -0.8879613368770993
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4480894666027533 -0.8939887191232673
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4335055261209907 -0.9011509079075286
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.4162009787116262 -0.9092726463055426
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.39622476005888 -0.9181535489863789
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.3736432150517507 -0.9275725027434735
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.34854317024090886 -0.9372927282756529
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.3210346949893786 -0.9470674340368148
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.29125334152958837 -0.9566459590924162
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.2593616730493598 -0.9657802661853456
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.22554992036894558 -0.9742316117954509
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.19003565073796863 -0.9817771903281298
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.15306238479954642 -0.9882165280744274
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-0.11489715692351263 -0.9933773921983999
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-7.582707619422498e-2 -0.9971209828881524
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
-3.615500611251265e-2 -0.9993461940353824
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
3.805463882176116e-3 -0.9999927591961061
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
4.373553683599171e-2 -0.9990431436217695
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
8.331696676262787e-2 -0.996523097097842
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.12223779166032502 -0.992500842463122
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.16019777720348488 -0.98708493665898
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.1969133260708594 -0.9804209004380269
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.23212164232239355 -0.9726867651847406
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.26558398755025286 -0.9640877271062562
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.2970879220015215 -0.9548501278215434
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.3264484852335553 -0.9452149948496994
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.3535083327039177 -0.9354313757346908
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.37813690285309487 -0.9257496868488096
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.40022874013637655 -0.9164152746265466
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.419701140356899 -0.9076623561562519
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4364913137554178 -0.8997084711261029
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4505532778015728 -0.8927495415077281
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.46185469556473024 -0.8869556021497415
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.470373867702006 -0.8824672371159485
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4760970677973522 -0.8793927348089495
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4790163836587343 -0.877805960441434
e
plot '-' with linespoints lw 1 pt 7 ps 1 lc rgb "black"
0 0
0.4791281930259268 -0.8777449371245102
e

After the optimization with gifsicle we finally get

Posted in Tips | Tagged , | 4 Comments

## BZFlag is Dead. Or not yet?

This is a rather empty post, just some sad news. BZflag is an open source online 3D tank game which was developed (and played) since ~1993. The last version from the 2.0 branch (2.0.16) was released in April 2010 and still there is quite a number of active players. However, the development of a long-awaited 3.0 branch is stalled and definitely is not going to be resumed.

Now some talks are being held to replace BZFlag with a new project. I hope for a glorious return of BZFLag.