Please enable JavaScript to view this site.

Vensim Help

We have looked at two models in this chapter and one of them required the use of Runge-Kutta integration in order to get good results.  We did not use Runge-Kutta on the Thermostat model and there was a reason for that.

Runge-Kutta Simulation for the Thermostat Model

(thrmst2.mdl)

The results for the Thermostat model were obtained using Euler integration.  If you try to simulate this model using RK4 Auto you will get the messages:

. . . . . . . . . . and the results:

This is different from our previous results, and clearly wrong.  Temperature is flat for long periods of time during which the furnace does not appear to be on.  As we have formulated this model it is inherently discontinuous, and Runge-Kutta integration is not going to help.  The flat spots in Temperature are the result of computations within TIME STEP.  What is happening is that during computation the trigger point to turn the furnace on is reached.  However, furnace was on remains at 0 during this time because it is a discrete delay and discrete delays change only at TIME  STEP.  

It is not possible to look inside of the integration technique, but we can reformulate the model slightly to get a picture of what is happening (thrmst2.vmf).  We introduce a new variable sampled  furnace  is  on that is the same as furnace is on at the old TIME STEP, but retains that value when TIME STEP is made smaller.  This is done with the equation:

sampled furnace is on = SAMPLE IF TRUE(MODULO(Time,0.0625) = 0,

       furnace is on,furnace is on)

This equation forces sampled furnace is on to hold its value until Time is a multiple of 0.0625, then switch to the new value. furnace was on is rewritten to depend on sampled  furnace  is  on

furnace was on = DELAY FIXED(sampled furnace is on,0,0)

This model has exactly the same behavior as the first model when TIME STEP is .0625.  However, if we set TIME  STEP to 1/1024 ( 0.0009765625) and reduce the length to 1 (we have also set OUTSIDE  TEMPERATURE to 34) we get:

There is a flat spot in temperature during which the furnace cycles from on to off at every time step (appearing as a dark rectangle).  If we zoom in on this time period (by holding down the shift key and dragging the mouse) we can look at the causes of furnace is on.

If you look at the time scale you will see that we are focused in on a very short period of time. Temperature is very nearly constant.  The furnace is switching on and off to hold it constant. Furnace was on remains 0.  The reason that furnace was on remains 0 as long as it does is because it is sampled only at multiples of .0625.  Since the furnace is flickering on and off, it can take a while to catch the instant in which the furnace is on and switch to searching for the shutoff condition.

It is important to emphasize that what we are investigating here is the behavior of simulation techniques for this model, and not the behavior of the physical system.  Were we to attempt the construction of a thermostat without a buffer zone these issues would apply directly to the physical system.