{
 "format": "stockflow-1",
 "id": "lib-shower",
 "name": "Too cold, too hot: the shower",
 "notes": "You feel the water a few seconds after you move the tap. If you keep turning until it feels right, you have already turned too far, so it overshoots: too hot, then too cold, then too hot again. The delay plus impatience makes the swing. Try: lower Impatience, or a shorter Pipe_Delay. The same pattern explains why heating, stock levels in shops, and even pig prices go up and down. Time unit: seconds.",
 "sim": {
  "start": 0,
  "stop": 90,
  "dt": 0.1,
  "unit": "seconds"
 },
 "elements": [
  {
   "id": "s1",
   "type": "stock",
   "name": "Tap_Position",
   "eq": "0",
   "x": 300,
   "y": 300,
   "units": "fraction",
   "doc": "0 = fully cold, 1 = fully hot.",
   "nonneg": true
  },
  {
   "id": "s2",
   "type": "flow",
   "name": "Turning_the_Tap",
   "eq": "MAX(-Tap_Position/0.5, MIN((1 - Tap_Position)/0.5, (Wanted_Temperature - Water_Temperature)*Impatience))",
   "from": null,
   "to": "s1",
   "fx": 100,
   "fy": 300,
   "units": "per second",
   "doc": "You turn towards hot when the water feels too cold, and towards cold when it is too hot. The tap cannot turn past fully hot or fully cold.",
   "biflow": true
  },
  {
   "id": "s3",
   "type": "aux",
   "name": "Tap_Temperature",
   "eq": "Cold_Water + (Hot_Water - Cold_Water)*MIN(1, Tap_Position)",
   "x": 480,
   "y": 180,
   "units": "°C",
   "doc": "Temperature of the water leaving the tap."
  },
  {
   "id": "s4",
   "type": "aux",
   "name": "Water_Temperature",
   "eq": "DELAY3(Tap_Temperature, Pipe_Delay, Cold_Water)",
   "x": 680,
   "y": 300,
   "units": "°C",
   "doc": "What you feel: the tap water, but a few seconds later because it has to travel up the pipe."
  },
  {
   "id": "s5",
   "type": "aux",
   "name": "Wanted_Temperature",
   "eq": "38",
   "x": 560,
   "y": 440,
   "units": "°C",
   "doc": "The temperature you want.",
   "slider": {
    "min": 30,
    "max": 45,
    "step": 1,
    "kind": "assumption"
   }
  },
  {
   "id": "s6",
   "type": "aux",
   "name": "Impatience",
   "eq": "0.02",
   "x": 200,
   "y": 140,
   "units": "per °C per second",
   "doc": "How hard you turn the tap for each degree it feels wrong.",
   "slider": {
    "min": 0.002,
    "max": 0.08,
    "step": 0.002,
    "kind": "decision"
   }
  },
  {
   "id": "s7",
   "type": "aux",
   "name": "Pipe_Delay",
   "eq": "4",
   "x": 680,
   "y": 140,
   "units": "seconds",
   "doc": "How long water takes from the tap to the shower head.",
   "slider": {
    "min": 0.5,
    "max": 10,
    "step": 0.5,
    "kind": "assumption"
   }
  },
  {
   "id": "s8",
   "type": "aux",
   "name": "Cold_Water",
   "eq": "12",
   "x": 380,
   "y": 60,
   "units": "°C",
   "doc": "Cold water temperature."
  },
  {
   "id": "s9",
   "type": "aux",
   "name": "Hot_Water",
   "eq": "60",
   "x": 560,
   "y": 60,
   "units": "°C",
   "doc": "Hot water temperature."
  },
  {
   "id": "s10",
   "type": "aux",
   "name": "Error",
   "eq": "ABS(Wanted_Temperature - Water_Temperature)",
   "x": 860,
   "y": 420,
   "units": "°C",
   "doc": "How far the water is from what you want."
  }
 ],
 "plots": [
  "s4",
  "s3",
  "s1"
 ],
 "summary": {
  "kpis": [
   {
    "name": "Water_Temperature",
    "agg": "max",
    "label": "Hottest moment",
    "better": "low",
    "format": "num"
   },
   {
    "name": "Error",
    "agg": "avg",
    "label": "Average error",
    "better": "low",
    "format": "num"
   }
  ]
 },
 "scenarios": [
  {
   "id": "ss1",
   "name": "Impatient",
   "values": {
    "Impatience": 0.02
   }
  },
  {
   "id": "ss2",
   "name": "Patient",
   "values": {
    "Impatience": 0.005
   }
  }
 ]
}