class ApplicationExample "An application example"
    extends Modelica.Icons.Information;

    annotation (Documentation(info = "<html>\n<p>\nIn this section a more realistic, still simple, application example\nis given, to demonstrate various features of the StateGraph library.\nThis example shows the control of a two tank system from the master thesis\nof Isolde Dressler\n(<a href=\"modelica://Modelica.StateGraph.UsersGuide.Literature\">see literature</a>).\n</p>\n<p>\nIn the following figure the top level of the model is shown.\nThis model is available as StateGraph.Examples.ControlledTanks.\n</p>\n\n<p>\n<img src=\"modelica://Modelica/Resources/Images/StateGraph/Examples/ControlledTanks1.png\">\n</p>\n\n<p>\nIn the right part of the figure, two tanks are shown. At the top part,\na large fluid source is present from which fluid can be filled in\n<strong>tank1</strong> when <strong>valve1</strong> is open. Tank1 can be emptied via\n<strong>valve2</strong> that is located in the bottom of tank2 and\nfills a second <strong>tank2</strong> which in turn is emptied via\n<strong>valve3</strong>. The actual levels of the tanks are measured\nand are provided as signals <strong>level1</strong> and <strong>level2</strong>\nto the <strong>tankController</strong>.\n</p>\n<p>\nThe <strong>tankController</strong> is controlled by three buttons,\n<strong>start</strong>, <strong>stop</strong> and <strong>shut</strong> (for shutdown)\nthat are mutually exclusive. This means that whenever one button is\npressed (i.e., its state is <strong>true</strong>) then the other two\nbuttons are not pressed (i.e., their states are <strong>false</strong>).\nWhen button <strong>start</strong> is pressed, the \"normal\" operation\nto fill and to empty the two tanks is processed:\n</p>\n<ol>\n<li> Valve 1 is opened and tank 1 is filled.</li>\n<li> When tank 1 reaches its fill level limit,\n     valve 1 is closed.</li>\n<li> After a waiting time, valve 2 is\n     opened and the fluid flows from tank 1 into tank 2.</li>\n<li> When tank 1 is empty, valve 2 is closed.</li>\n<li> After a waiting time, valve 3 is opened and\n     the fluid flows out of tank 2</li>\n<li> When tank 2 is empty, valve 3 is closed</li>\n</ol>\n<p>\nThe above \"normal\" process can be influenced by the following\nbuttons:\n</p>\n<ul>\n<li> Button <strong>start</strong> starts the above process.\n     When this button is pressed after a \"stop\" or\n     \"shut\" operation, the process operation continues.\n     </li>\n<li> Button <strong>stop</strong> stops the above process by\n     closing all valves. Then, the controller waits for\n     further input (either \"start\" or \"shut\" operation).</li>\n<li> Button <strong>shut</strong> is used to shutdown the process,\n     by emptying at once both tanks. When this is achieved,\n     the process goes back to its start configuration.\n     Clicking on \"start\", restarts the process.</li>\n</ul>\n<p>\nThe implementation of the <strong>tankController</strong> is shown in\nthe next figure:\n</p>\n\n<p>\n<img src=\"modelica://Modelica/Resources/Images/StateGraph/Examples/ControlledTanks2.png\">\n</p>\n\n<p>\nWhen the \"<strong>start</strong>\" button is pressed, the stateGraph is\nwithin the CompositeStep \"<strong>makeProduct</strong>\". During normal\noperation this CompositeStep is only left, once tank2 is empty.\nAfterwards, the CompositeStep is at once re-entered.\n</p>\n<p>\nWhen the \"<strong>stop</strong>\" button is pressed, the \"makeProduct\"\nCompositeStep is at once terminated via the \"<strong>suspend</strong>\" port\nand the stateGraph waits in step \"<strong>s2</strong>\" for further\ncommands. When the \"<strong>start</strong>\" button is pressed, the CompositeStep\nis re-entered via its <strong>resume</strong> port and the \"normal\"\noperation continues at the state where it was aborted by the\nsuspend transition. If the \"<strong>shut</strong>\" button is pressed,\nthe stateGraph waits in the \"<strong>emptyTanks</strong>\" step, until\nboth tanks are empty and then waits at the initial step\n\"<strong>s1</strong>\" for further input.\n</p>\n<p>\nThe opening and closing of valves is <strong>not</strong> directly\ndefined in the stateGraph. Instead via the \"<strong>setValveX</strong>\"\ncomponents, the Boolean state of the valves are computed.\nFor example, the output y of \"setValve2\" is computed as:\n</p>\n<pre>\n  y = or\n</pre>\n<p>\ni.e., valve2 is open, when step \"makeProduct.fillTank2 or when\nstep \"emptyTanks\" is active. Otherwise, valve2 is closed.\n</p>\n</html>"));
end ApplicationExample;