# Mistakes were made, part one

I said a couple of episodes back that I made some mistakes in the design and implementation of my furnace; fortunately they were mistakes from which I learned something, and that were fixable.

The first mistake I made was a consequence of my not clearly understanding the difference between propane-fueled and charcoal-fuels furnaces. To be clear, the relevant differences for the purposes of this mistake are:

# Royale With Cheese, plus, dividing temperatures

In reading over the previous posts I realized that I am switching between the metric and Imperial systems of measure at will. This is what I get for being a Canadian who has lived in the United States for sixteen years. When doing any kind of “scientific” calculation it is of course far easier to do in the metric system, where converting between litres and cubic centimeters is simply a matter of moving a decimal place. I have no intuition for how many fluid ounces are in a cubic foot; I always have to look it up. But when it comes to carpentry and oven temperatures, I’ve learned how in the Imperial system of inches and degrees Fahrenheit. I’ll probably continue to switch back and forth indiscriminately, so, sorry about that.

On the subject of Fahrenheit, a quick reminder. As I’ve described this project to people, they often ask if I am going to try to melt iron. No, I say, the temperatures are far too high; aluminum pours at 1400°F and iron melts at 2800°F. So far, three people have said “oh, so that’s twice as hot”, without stopping to think about their high school physics. Remember, you cannot divide one temperature by another.

Why not? First off, we don’t measure temperatures on an absolute scale. There are negative temperatures. If 1400°F is half as hot as 2800°F then clearly it is negative 40 times as hot as -35°F, and 14000 times as hot as 0.1°F! Neither of those make any sense.

This reason alone is sufficient to reject the idea that 2800°F is twice as hot as 1400°F. Now, we could convert to absolute scale. 1400°F is 1033 Kelvin,  2800°F is 1811 Kelvin, so the melting iron is about 80% hotter than the pouring aluminum, right?

But that’s not quite the right way to look at it either. We’re not starting with the metals at absolute zero to begin with. Room temperature is about 70°F, so the aluminum must have 1330 degrees of heat energy added to it, and the iron must have about 2730 degrees of heat energy, and that is just about twice as much, right?

But no, that’s not quite right either. The specific heat capacity — the amount of heat energy you have to add to a metal in order to raise its temperature by a given amount — is different for every metal, and iron’s specific heat capacity is about half that of aluminum; the same amount of energy increases the temperature of iron for two degrees for every one degree that it would increase the temperature of aluminum. So even though the temperature change of the iron is twice as much, it takes half as much energy, so it’s a wash, right?

Well, no, that’s not right either; somehow the furnace has to get up to the needed temperature and the furnace has to withstand that amount of heat. How efficiently the furnace transmits that heat into the melt is maybe an interesting theoretical question, but the fact is that the vast majority of the heat energy in the furnace is heating up stuff other than the melt.

And finally, we’re still not taking into account the latent heat of fusion! Normally when you put heat into an object, the amount of heat energy that goes in turns into an increase in temperature, in a linear fashion. That is, if putting in one unit of energy raises the temperature by one degrees, then putting in two units will raise it by two degrees. This ceases to be the case when the substance is melting (or freezing) or boiling (or condensing). When the object reaches the melting point it needs extra energy, called the latent heat of fusion (*), to overcome the stick-together-ness of the solid form; this energy breaks down the crystal structure of the solid, rather than increasing the temperature. And, like the specific heat capacity, the latent heat of fusion of a substance is a characteristic of the molecular structure of that substance. Aluminum has a much higher latent heat of fusion than iron: 398 kJ per kg, compared with 272. So, even though iron has to get a lot hotter to melt, it takes a lot less energy to get it from solid to liquid.

The long and the short of it is: don’t think of temperatures as things that you can multiply and divide, and even addition and subtraction is a bit dodgy when going over the melting point boundary.

———————————————————

(*) This has nothing whatsoever to do with nuclear fusion; the “fusion” in question is the fusion that a liquid undergoes when it freezes. The latent heat that you must remove from liquid water to “fuse” it into ice is the exact same amount of energy as the amount you must add to melt solid water, so the latent heat of fusion and the latent heat of melting are the same amount.

# An “is” operator puzzle, part one

It is possible for a program with some local variable `x`

`bool b = x is FooBar;`

to assign true to `b` at runtime, even though there is no conversion, implicit or explicit, from `x` to `FooBar` allowed by the compiler! That is to say that

`FooBar foobar = (FooBar)x;`

would not be allowed by the compiler in that same program.

Can you create a program to demonstrate this fact?

This is not a particularly hard puzzle but it does illustrate some of the subtleties of the `is` operator that we’ll discuss in the next episode.

# Mizzou castable refractory instructions

I’ve built my furnace; mistakes were made along the way which I’ll document in a later episode. I decided on a 10 3/4 inch outer diameter with a 2 inch wall. The furnace is 15 1/4 inches high, and 2 1/4 of that is the lid. Thus the bore is a cylinder 6 3/4 inches in diameter and 11 inches tall.

This took just slightly less than the complete contents of two 55-pound bags of “mizzou” castable refractory cement, which I obtained at Seattle Pottery Supply. Interestingly enough there were no instructions on the bag. Fortunately the (very informative) high temperature tools web site had detailed instructions, which I reproduce for you here:

• Material should be stored in a dry place.
• Porous back-up materials or wood forms should be waterproofed. Absorption of water can result in reduced flow for the product.
• Forms must be stout and water tight.
• This product is designed to be mixed with water and then poured/handcast into place.
• For best results, water should be maintained at 50-70F.
• Approximate Water For Installation: 55 lbs. to 5 pints of water.
• Mix for at least three minutes.
• For best results, wet mix temperature should be maintained at 60-75F.
• Minor adjustments to the amount of water are permissible to achieve desired flow.
• Do not exceed 11.0% water under any circumstances.
• Place material promptly.
• Do not trowel to slick finish.
• At temperatures above 60F, air cure, keeping surfaces damp and/or covered, for 16-24 hours typically or until a hard set has developed. Lower temperatures will increase the time before a hard set develops. The best results are achieved at curing temperatures of 90-110F.
• Keep material from freezing during air cure and preferably until a dryout can be initiated. Freezing of this product prior to water removal can cause structural damage.
• Never enclose a castable in a vapor-tight encasement as a dangerous steam explosion may result.

Typical dryout schedule for a single layer, 9” thick or less:

• Ambient to 250F at 75F per hour. Hold at 250F 1/2 hour per inch thickness.
• 250F to 500F at 75F per hour. Hold at 500F 1/2 hour per inch thickness.
• 500F to 1000F at 75F per hour. Hold at 1000F 1/2 hour per inch thickness
• 1000F to use temperature 75F per hour

I made a mold out of sheet metal for the inner and outer round surfaces, and plywood disks for the bottoms. The inner mold is held concentric with the outer mold by putting five or six two-inch pieces of wood around the circumference of the inner mold. As I mentioned in a previous episode, I soaked the wood in cooking spray, which was a convenient way to keep it from absorbing water.

The forces on the inner mold are going to be large when there’s eighty pounds of wet cement pushing on it, more than enough to collapse the flimsy sheet metal, so I filled the inner mold entirely with sand.

I mixed up the cement by putting ten pints — just under five liters — of water in a watering can; this made sure that I did not accidentally put in too much water. I slowly added the water to the cement powder, stirring with a hoe. For easy cleanup, I mixed it in a bin lined with some scrap plastic sheeting.

I then scooped the cement into the mold and rammed it down with one of the wooden sections used to keep the molds concentric, going from one section to the next. I rammed it down pretty hard, and even still, there were a fair number of air bubbles in the finished product. This is not fatal, or even all that undesirable; air pockets are good insulators and lower the thermal mass of the furnace. The risk is that if water gets stuck in a pocket then it could expand and crack the furnace or cause spalling. Ram it a lot.

Once it was done I wrapped it up in plastic for a day while the hydrating reactions hardened the cement. Since the hardening reaction requires water it’s important that the edges not dry out too early.

Then I removed the molds, wrapped the whole thing up in a damp towel and more plastic, put a 60 watt light bulb inside, and left it for a week.

After that, I made some increasingly hot fires in the furnace. There was almost no visible steam at any point and no cracking, so I think I’ve got myself a furnace here.

Next time: however, some mistakes were made.

# Wackiness ensues

This Twitter feed  answers the question “What would happen if Anders Hejlsberg and Barbara Liskov were forced to share an apartment[1. A single-threaded apartment, I’d assume.] in an “odd couple” style sitcom?”

Apparently I’m the “Kramer” of this sitcom. I hope I’m played by Ryan Gosling. Additional suggestions on casting the principal roles can be left in the comments.

# Out parameters and LINQ do not mix

What’s wrong with this code?

```var seq = new List<string> { "1", "blah", "3" };
int tmp;
var nums =
from item in seq
let success = int.TryParse(item, out tmp)
select success ? tmp : 0;```

The intention is pretty clear: take a sequence of strings and produce a sequence of numbers by turning the elements that can be parsed as numbers into those numbers and the rest into zero.

The C# compiler will give you a definite assignment error if you try this, which seems strange. Why does it do that? Well, think about what code the compiler will translate the last statement into:

```var nums =
seq.Select(item=>new {item, success = int.TryParse(item, out tmp)})
.Select(transparent => transparent.success ? tmp : 0);```

We have two method calls and two lambdas. Clearly the first lambda assigns tmp and the second reads it, but we have no guarantee whatsoever that the first call to `Select` invokes the lambda! It could, for some bizarre reason of its own, never invoke the lambda. Since the compiler cannot prove that tmp is definitely assigned before it is read, this program is an error.

So is the solution then to assign `tmp` in the variable declaration? Certainly not! That makes the program compile, but it is a “worst practice” to mutate a variable like this. Remember, that one variable is going to be shared by every delegate invocation! In this simple LINQ-to-Objects scenario it is the case that the delegates are invoked in the sensible order, but even a small change makes this nice property go out the window:

```int tmp = 0;
var nums =
from item in seq
let success = int.TryParse(item, out tmp)
orderby item
select success ? tmp : 0;
foreach(var num in nums)
Console.WriteLine(num);```

Now what happens?

We make an object that represents the query. The query object consists of three steps: do the `let` projection, do the sort, and do the final projection. Remember, the query is not executed until the first result from it is requested; the assignment to “nums” just produces an object that represents the query, not the results.[1. As I have often said, if I could tell new LINQ users just one thing, it is that fact: query expressions produce a query, not a result set.]

Then we execute the query by entering the body of the loop. Doing so initiates a whole chain of events, but clearly it must be the case that the entire `let` projection is executed from start to finish over the whole sequence in order to get the resulting pairs to be sorted by the `orderby` clause. Executing the `let` projection lambda three times causes `tmp` to be mutated three times. Only after the sort is completed is the final projection executed, and it uses the current value of `tmp`, not the value that `tmp` was back in the distant past!

So what is the right thing to do here? The solution is to write your own extension method version of `TryParse` the way it would have been written had there been nullable value types available in the first place:

```static int? MyTryParse(this string item) {
int tmp;
bool success = int.TryParse(item, out tmp);
return success ? (int?)tmp : (int?)null;
}```

And now we can say:

```var nums =
from item in seq
select item.MyTryParse() ?? 0;```

The mutation of the variable is now isolated to the activation of the method, rather than a side effect that is observed by the query. Try to always avoid side effects in queries.

Thanks to Bill Wagner for the question that inspired this blog entry.

Next time on FAIC: Wackiness ensues!