{
 "format": "stockflow-1",
 "id": "lib-bathtub",
 "name": "The bathtub",
 "notes": "A bathtub is a stock: it fills when more water comes in than goes out, and empties when more goes out than comes in. Try this: the tap is turned down after 5 minutes, but the water still keeps rising for a while. Why? Because the level only falls when the drain takes away MORE than the tap brings. Change Tap_Later and the plughole size (Drain_Speed) and watch where the level settles. Then make the plughole small (0.05) and keep the tap at 12: the tub fills up to the rim and the rest runs over onto the floor. Overflow is a flow too. Time unit: minutes.",
 "sim": {
  "start": 0,
  "stop": 40,
  "dt": 0.25,
  "unit": "minutes"
 },
 "elements": [
  {
   "id": "b1",
   "type": "stock",
   "name": "Water_in_Tub",
   "eq": "20",
   "x": 420,
   "y": 260,
   "units": "litres",
   "doc": "How much water is in the bathtub. It only changes through the tap and the drain.",
   "nonneg": true
  },
  {
   "id": "b2",
   "type": "flow",
   "name": "Tap",
   "eq": "IF TIME < Turn_Down_Time THEN Tap_Full ELSE Tap_Later",
   "from": null,
   "to": "b1",
   "fx": 200,
   "fy": 260,
   "units": "litres/minute",
   "doc": "Water coming in from the tap.",
   "biflow": false
  },
  {
   "id": "b3",
   "type": "flow",
   "name": "Drain",
   "eq": "Water_in_Tub*Drain_Speed",
   "from": "b1",
   "to": null,
   "tx": 660,
   "ty": 260,
   "units": "litres/minute",
   "doc": "Water running out of the plughole. More water in the tub pushes harder, so it drains faster.",
   "biflow": false
  },
  {
   "id": "b4",
   "type": "stock",
   "name": "Water_on_the_Floor",
   "eq": "0",
   "x": 420,
   "y": 520,
   "units": "litres",
   "doc": "Water that ran over the rim. A stock nobody wanted.",
   "nonneg": true
  },
  {
   "id": "b5",
   "type": "flow",
   "name": "Overflow",
   "eq": "MAX(0, Tap - Drain + (Water_in_Tub - Tub_Size)/DT)",
   "from": "b1",
   "to": "b4",
   "units": "litres/minute",
   "doc": "When the tub is full, whatever the drain cannot take runs over the rim.",
   "biflow": false
  },
  {
   "id": "b6",
   "type": "aux",
   "name": "Tub_Size",
   "eq": "150",
   "x": 640,
   "y": 420,
   "units": "litres",
   "doc": "How much the tub holds up to the rim.",
   "slider": {
    "min": 80,
    "max": 300,
    "step": 10,
    "kind": "assumption"
   }
  },
  {
   "id": "b7",
   "type": "aux",
   "name": "Tap_Full",
   "eq": "12",
   "x": 120,
   "y": 120,
   "units": "litres/minute",
   "doc": "How fast the tap runs at first.",
   "slider": {
    "min": 0,
    "max": 20,
    "step": 1,
    "kind": "decision"
   }
  },
  {
   "id": "b8",
   "type": "aux",
   "name": "Tap_Later",
   "eq": "9",
   "x": 260,
   "y": 120,
   "units": "litres/minute",
   "doc": "How fast the tap runs after you turn it down.",
   "slider": {
    "min": 0,
    "max": 20,
    "step": 1,
    "kind": "decision"
   }
  },
  {
   "id": "b9",
   "type": "aux",
   "name": "Turn_Down_Time",
   "eq": "5",
   "x": 190,
   "y": 400,
   "units": "minutes",
   "doc": "When you turn the tap down.",
   "slider": {
    "min": 0,
    "max": 20,
    "step": 1,
    "kind": "decision"
   }
  },
  {
   "id": "b10",
   "type": "aux",
   "name": "Drain_Speed",
   "eq": "0.15",
   "x": 640,
   "y": 120,
   "units": "per minute",
   "doc": "Share of the water that drains away each minute (the plughole size).",
   "slider": {
    "min": 0.02,
    "max": 0.3,
    "step": 0.01,
    "kind": "assumption"
   }
  }
 ],
 "plots": [
  "b1",
  "b2",
  "b3",
  "b4"
 ],
 "summary": {
  "kpis": [
   {
    "name": "Water_in_Tub",
    "agg": "max",
    "label": "Highest water level",
    "better": "low",
    "format": "num"
   },
   {
    "name": "Water_in_Tub",
    "agg": "final",
    "label": "Water at the end",
    "better": "low",
    "format": "num"
   },
   {
    "name": "Water_on_the_Floor",
    "agg": "final",
    "label": "Water on the floor",
    "better": "low",
    "format": "num"
   }
  ]
 },
 "scenarios": [
  {
   "id": "bs1",
   "name": "Turn down to 9",
   "values": {
    "Tap_Later": 9
   }
  },
  {
   "id": "bs2",
   "name": "Turn off completely",
   "values": {
    "Tap_Later": 0
   }
  },
  {
   "id": "bs3",
   "name": "Small plughole: overflow",
   "values": {
    "Tap_Later": 12,
    "Drain_Speed": 0.05
   }
  }
 ]
}