exupero's blog
RSSApps

Heating cold water in smaller batches

In the previous post I simulated a bit of simple thermodynamics so we could explore beyond to the original solution. While we've been able to heat the cold water a few degrees warmer than the once-hot water, I'm curious how far we can go.

If we equalize the temperatures of all the cold water with all the hot water, they both come to 50°C:

(heat-cold-water
  {:amount 1 :temp 80}
  [{:amount 1 :temp 20}])
{:hot {:amount 1, :temp 50}, :cold {:amount 1, :temp 50}}

If we equalize the temperatures of half the cold water at a time, we bring the cold water up to 53⅓°C:

(heat-cold-water
  {:amount 1 :temp 80}
  [{:amount 0.5 :temp 20}
   {:amount 0.5 :temp 20}])
{:hot {:amount 1, :temp 46.66666666666667},
 :cold {:amount 1.0, :temp 53.333333333333336}}

And immersing thirds of the cold water brings the end result up to about 54⅔°C:

(heat-cold-water
  {:amount 1 :temp 80}
  [{:amount (float (/ 1 3)) :temp 20}
   {:amount (float (/ 1 3)) :temp 20}
   {:amount (float (/ 1 3)) :temp 20}])
{:hot {:amount 1, :temp 45.31249943422155},
 :cold {:amount 1.0000000298023224, :temp 54.68749953201041}}

It seems that heating smaller batches raises the final temperature, but with diminishing returns. What's the limit? Let's try immersing smaller and smaller powers of ten:

(heat-cold-water
  {:amount 1 :temp 80}
  (repeat 1e2 {:amount 1e-2 :temp 20}))
{:hot {:amount 1, :temp 42.18267273974715},
 :cold {:amount 1.0000000000000007, :temp 57.817327260252824}}
(heat-cold-water
  {:amount 1 :temp 80}
  (repeat 1e3 {:amount 1e-3 :temp 20}))
{:hot {:amount 1, :temp 42.08379825732898},
 :cold {:amount 1.0000000000000007, :temp 57.916201742675135}}
(heat-cold-water
  {:amount 1 :temp 80}
  (repeat 1e4 {:amount 1e-4 :temp 20}))
{:hot {:amount 1, :temp 42.07387006262998},
 :cold {:amount 0.9999999999999062, :temp 57.926129937374526}}
(heat-cold-water
  {:amount 1 :temp 80}
  (repeat 1e5 {:amount 1e-5 :temp 20}))
{:hot {:amount 1, :temp 42.072876833515096},
 :cold {:amount 0.9999999999980838, :temp 57.92712316626038}}

With 100,000 batches, the cold water rises to almost 58°C, but the temperature gains over using only 10,000 batches is negligible. 57.927°C seems to be pretty close to the limit.

To see the individual steps in the process, we can copy the definition of heat-cold-water from the previous post and change reduce to reductions:

(defn heat-cold-water-steps [hot colds]
  (reductions
    (fn [{:keys [hot cold]} new-cold]
      (let [[hot' cold'] (equalize-temperatures hot new-cold)]
        {:hot hot'
         :cold (if cold
                 (mix cold cold')
                 cold')}))
    {:hot hot :cold nil}
    colds))
(heat-cold-water-steps
  {:amount 1 :temp 80}
  [{:amount 0.25 :temp 20}
   {:amount 0.25 :temp 20}
   {:amount 0.25 :temp 20}
   {:amount 0.25 :temp 20}])
({:hot {:amount 1, :temp 80}, :cold nil}
 {:hot {:amount 1, :temp 68.0}, :cold {:amount 0.25, :temp 68.0}}
 {:hot {:amount 1, :temp 58.4}, :cold {:amount 0.5, :temp 63.2}}
 {:hot {:amount 1, :temp 50.72}, :cold {:amount 0.75, :temp 59.04}}
 {:hot {:amount 1, :temp 44.576}, :cold {:amount 1.0, :temp 55.424}})

The :cold field only tells us the temperature of the cold water that's been warmed up, not the net temperature of all the cold water if it were to be mixed back together, so let's make a function to calculate that:

(defn net-cold-temperature [{:keys [amount] :as warmed}]
  (if warmed
    (mix warmed {:amount (- 1 amount) :temp 20})
    {:amount 1 :temp 20}))
(net-cold-temperature {:amount 0.75 :temp 55.424})
{:amount 1.0, :temp 46.568}

From this data we can plot the temperature changes from beginning to end:

20°C22°C24°C26°C28°C30°C32°C34°C36°C38°C40°C42°C44°C46°C48°C50°C52°C54°C56°C58°C60°C62°C64°C66°C68°C70°C72°C74°C76°C78°C80°C

These two lines are mirror images of each other, which confirms the intuition that any heat which leaves the hot water is absorbed by the cold water (in an ideal system).

Looking at just the cold water, let's see how the curve changes as we warm it up in smaller batches. Here's the change over 4 batches, 16 batches, and 64 batches:

20°C22°C24°C26°C28°C30°C32°C34°C36°C38°C40°C42°C44°C46°C48°C50°C52°C54°C56°C58°C60°C62°C64°C66°C68°C70°C72°C74°C76°C78°C80°C

The improvement between 4 and 16 batches is noticeable, while between 16 and 64 batches is much less. Splitting down to 1,000 batches is within the marker width of 64's curve.

Having explored this system numerically, next I'd like to explore it analytically.