Thermostat
WHAT IS IT?
This is a model of the way a thermostat regulates temperature. This model has potential applications in both math and physics classes (see below).
HOW IT WORKS
Turtles have temperatures (which starts out on average at the temperatures set on the initialtemp slider). The move around randomly and when they collide with other turtles they average their temperatures. They can also lose heat to the outside if the insulation sliders is set to less than 100 (this slider controls the percent of "heat" that they lose when they touch the outside grey walls - which is also influenced by the outside temperature set on the cold slider). There is a heat source on the left hand side (indicated in red). The temerature of this heat source is set by the heat slider. When the heater is on (the wall is red) and turtles run into this wall they become the temperature set on the heat slider.
When the thermostat is on (the regulate button is pressed down), then the heater will turn off if the MEASURED temperatures is above the desired temperature (plus the tolerance). It will turn back on when the temperature drops below the desired temperature (minus the tolerance).
With regard to the MEASURED temperature, you will see that there are a few white patches in the box. You can think of these as probes which measure temperature (thermometers). They calculate the temperature of the turtles that run over them by storing the temperature of the last turtle that ran over them. You can change the number and placement of the probes by simply painting or erasing white patches on the canvas (and hitting setup again). Depending on the number and placement of the probes, the measured temperature of these probes may be closer or further from the global temperature (indicated on the global temp monitor - and calculated by the actual average of all of the turtles' temperatures.
The graph shows the measured (red) and actual (blue) temperatures over time.
The print_data button will output the actual and measured temperatures to a table in the output window, which can be saved and analyzed in the spreadsheet or stats package of your choice.
EXPLORATIONS
This project can be explored as an engineering/physics project to see how you might design temperature probes to get the best estimate of actual temperatures under a variety of conditions. You might set costs for each probe (white spot), and add a counter for this. You could also imagine that the costs of going under or over are different and figure out a way to calculate this deviation from the outputted data in your spreadsheet. In a math class you might investigate sampling properties, or even go ahead and try to design a more sophisticated moving average procedure (that stored and used the last 2, 3, 4... turtles that ran over them) for the probes.
Turtle procedures
turtles-own [energy totalenergy]
;when turtles go they move forward proportional to their energy
;then they turn a litle randomly
;check the patched to see if they are on a heater or thermostat
;and finally check for collisions with other agents
to go
fd (energy / 100)
rt random 10 lt random 10
check-patches
scale-color red energy 0 100
avgtemp
end
;when turtles move they check patches for three things
; 1 - they check for walls that they bounce off of
; 2 - they check for red patches which cause them to heat up
; 3 - they report their temperature to white patches
to check-patches
if pc-ahead = gray or pc-ahead = (gray - 1) [
setenergy (energy +
((1 - insulation / 100) * cold + (insulation / 100) * energy)
) / 2
rt 180]
if pc-ahead = red [heat-up rt 180]
if pc = white [settemp energy]
end
;when molecules heat up they average their temperature with the source
to heat-up
setenergy (energy + heat) / 2
end
;when turtles average their temperature they collide with another turtle and each set their energy to the average
to avgtemp
grab one-of-turtles-here
[settotalenergy energy + energy-of partner
setenergy totalenergy / 2
setenergy-of partner energy
]
end
(
Observer procedures
patches-own [temp]
globals [seconds]
;in setup turtles are created and placed within the box
;the file is also set up for writing data to
to setup
ct
co
create-and-do 100
[setxy ((random 37) - 18) ((random 37) - 18)
setenergy initialtemp - 5 + random 11
scale-color red energy 0 100
seth random 360]
ask-patches [settemp initialtemp if pc = gray - 1 [setpc red]]
setseconds 0
type "time"
type ","
type "calculated temp"
type ","
print "actual temp"
writedata
clearplots
end
;the thermostat procedure is used to control the heat source
;if the temperature that is measured in the white patches is too high the heat source shuts off
;when it is too low the heat source comes back on
to thermostat
if (average-of-patches-with [pc = white] [temp]) > (desiredtemp + tolerance)
[turnoff]
if (average-of-patches-with [pc = white] [temp]) < (desiredtemp - tolerance)
[turnon]
end
;when the heat source goes off the red patches turn grayish
to turnoff
ask-patches [if pc = red [setpc gray - 1]]
end
;when the heat source goes back on the grayish patches turn red
to turnon
ask-patches [if pc = (gray - 1) [setpc red]]
end
;handles writing data to the file
to writedata
type seconds
type ","
type average-of-patches-with [pc = white] [temp]
type ","
print average-of-turtles [energy]
end
