{"id":5104,"date":"2014-01-31T09:00:10","date_gmt":"2014-01-31T14:00:10","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=5104"},"modified":"2014-01-29T22:23:42","modified_gmt":"2014-01-30T03:23:42","slug":"beautiful-bellagio-simulation","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2014\/01\/31\/beautiful-bellagio-simulation\/","title":{"rendered":"Beautiful Bellagio Simulation"},"content":{"rendered":"\r\n\r\n<div class=\"content\"><!--introduction--><p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620\">Greg's<\/a> pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44661-bellagio-fountain-simulation\">Bellagio Fountain Simulation<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/277797\">John Hedengren<\/a> and friends.<\/p><p>How would you develop the complex choreography for The Fountains of Bellagio without getting wet?<\/p><p>This <a href=\"http:\/\/youtu.be\/HjGvwS9WyuU\">video<\/a> associated with this entry has an elegant description of how you might go about constructing a simulation for this very purpose.<\/p><p>I&#8217;m not one to get too excited, but this submission really struck a chord with me, and reminded me how we can do some pretty cool things with Simulink.<\/p><p>I spend most of my days working on simulations of motors and their controllers. (Actually to be honest, I spend more time managing files used for the simulation of motors than creating the simulations, but that&#8217;s a discussion for another day). It is nice to be reminded that engineers can solve some really interesting problems using tools like MATLAB and Simulink. Not that spinning motor is always dull, but it doesn&#8217;t make for very good animations.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#d0d0a4fa-231e-449d-b194-815b9a9b4d45\">Simple Simulations are Better than Complex<\/a><\/li><li><a href=\"#5bea7507-81c3-4e62-a79c-602493171915\">Why is Simulink Valuable for this?<\/a><\/li><li><a href=\"#16b80c61-3305-41a8-9341-27a5ebb5a58c\">How Can We Make the Model Easier to Look At?<\/a><\/li><\/ul><\/div><h4>Simple Simulations are Better than Complex<a name=\"d0d0a4fa-231e-449d-b194-815b9a9b4d45\"><\/a><\/h4><p>But wait! Doesn&#8217;t the model contain 100 fountains? And there are lines going everywhere, doesn&#8217;t that make it complex?<\/p><p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/beautiful_bellagio_sim\/fountain_system_model.png\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/beautiful_bellagio_sim\/fountain_system_model.png\"\r\nwidth=600><\/a>\r\n<br><i>(Click on image to enlarge)<\/i>\r\n<\/p><p>Okay, maybe it looks complicated. I&#8217;ll address that in the last section. However I really like the approach that John and his colleagues took of breaking the hundreds of fountain jets down to a simpler problem, and used relatively simple models to describe the jet dynamics.<\/p><p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/beautiful_bellagio_sim\/jet_model.png\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/beautiful_bellagio_sim\/jet_model.png\"\r\nwidth=600><\/a>\r\n<br><i>(Click on image to enlarge)<\/i>\r\n<\/p><p>John and his colleagues derived a second order transfer function to represent the relationship between the force of the jet and the height of the jet above the surface of the water reservoir. In addition they calculate the force using some lumped parameter analysis to estimate the dynamics of the water pump and the jet.<\/p><p>Sure, one could use sophisticated fluid dynamics models to get lots more detail. But more complex models require more time to create, and generally more time to run. Why spend all of that time and energy when you can get pretty close with a far simpler set of models. Remember the fundamental law of production:<\/p><p>$$Time = Money$$<\/p><h4>Why is Simulink Valuable for this?<a name=\"5bea7507-81c3-4e62-a79c-602493171915\"><\/a><\/h4><p>Simulink really offers a couple of elements that are difficult to find elsewhere.<\/p><p>First it provides a graphical language to lay out the relationships of the various system components.<\/p><p>Second it provides a means to create custom models of these components, and test the components independent of the system model.<\/p><p>And third, you can use MATLAB to <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/sim.html\">automate the simulation<\/a> and retrieve the simulation data to create custom graphics so you can describe the results to your manager or customer in a concrete fashion.<\/p><h4>How Can We Make the Model Easier to Look At?<a name=\"16b80c61-3305-41a8-9341-27a5ebb5a58c\"><\/a><\/h4><p>Since I often have to develop models that I share with other people, I spend a lot of time thinking about how to present models and code in a way that&#8217;s easy to understand.<\/p><p>There are a number of features that could potentially make the larger system model easier to look at. However, each has its trade-off.<\/p><div><ul><li><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/foreachsubsystem.html\">For-Each subsystem<\/a>  to replicate instances of the same system component for different inputs.<\/li><\/ul><\/div><p>For example, you could have just three blocks representing the different types of fountain jets. Each block would represent multiple instances of each type of jet.<\/p><p>The tradeoff is you now have to understand the semantics of this particular type of subsystem in Simulink. It makes the diagram more abstract, so while it might look prettier, it could be more difficult to understand, especially if your audience isn&#8217;t familiar with Simulink.<\/p><div><ul><li><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/virtual-signals.html#brp5v4k-1\">Signals as vectors<\/a> allow you to concatenate information that is travelling to the same location in a single line.<\/li><\/ul><\/div><p>This makes most sense in the context of the For-Each subsystem where each element in the signal vector represents an input to a different instance of the jet model.<\/p><p>Again the trade-off is neatness for abstraction. You have fewer lines in the diagram, but each line contains more information that can be difficult to surmise just by looking at the diagram.<\/p><div><ul><li><a href=\"https:\/\/www.mathworks.com\/products\/stateflow\/\">Stateflow<\/a> to develop the sophisticated logic required to turn various jets on and off at specific intervals.<\/li><\/ul><\/div><p>Stateflow is a graphical way to represent the flow of logic. It includes the ability to manage the particular state of a system (such as a switch which can be on or off) as well as the conditions to transition between the various states (turn switch on when it is dark).  Those conditions can include the notion of time as well (turn on the switch after 5 seconds).<\/p><p>In this case I believe the trade-off might be reversed from the other two suggestions. It may be easier for someone to understand the logic if Stateflow is used as it may reduce the abstraction introduced by elements like variable delays, but requires the model designer to learn another graphical language to develop the model.<\/p><p><b>Comments<\/b><\/p><p>If you would like to leave any comments regarding this post, please click <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=5104#respond\">here<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_1080ac5c3a6e4638869dfb06e3544312() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='1080ac5c3a6e4638869dfb06e3544312 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 1080ac5c3a6e4638869dfb06e3544312';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2014 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_1080ac5c3a6e4638869dfb06e3544312()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><\/div><!--\r\n1080ac5c3a6e4638869dfb06e3544312 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620\r\n% Greg's> pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44661-bellagio-fountain-simulation\r\n% Bellagio Fountain Simulation> by \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/277797 John\r\n% Hedengren> and friends. \r\n%\r\n% How would you develop the complex choreography\r\n% for The Fountains of Bellagio without getting wet? \r\n%\r\n% This\r\n% <http:\/\/youtu.be\/HjGvwS9WyuU video> associated with this entry has an\r\n% elegant description of how you might go about constructing a simulation\r\n% for this very purpose. \r\n%\r\n% I\u00e2\u20ac\u2122m not one to get too excited, but this\r\n% submission really struck a chord with me, and reminded me how we can do\r\n% some pretty cool things with Simulink. \r\n%\r\n% I spend most of my days working on\r\n% simulations of motors and their controllers. (Actually to be honest, I\r\n% spend more time managing files used for the simulation of motors than\r\n% creating the simulations, but that\u00e2\u20ac\u2122s a discussion for another day). It is\r\n% nice to be reminded that engineers can solve some really interesting\r\n% problems using tools like MATLAB and Simulink. Not that spinning motor is\r\n% always dull, but it doesn\u00e2\u20ac\u2122t make for very good animations.\r\n% \r\n%% Simple Simulations are Better than Complex \r\n% But wait! Doesn\u00e2\u20ac\u2122t the model\r\n% contain 100 fountains? And there are lines going everywhere, doesn\u00e2\u20ac\u2122t that\r\n% make it complex? \r\n%\r\n% <html>\r\n% <a href=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/beautiful_bellagio_sim\/fountain_system_model.png\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/beautiful_bellagio_sim\/fountain_system_model.png\"\r\n% width=600><\/a>\r\n% <br><i>(Click on image to enlarge)<\/i>\r\n% <\/html>\r\n%\r\n% Okay, maybe it looks complicated. I\u00e2\u20ac\u2122ll\r\n% address that in the last section. However I really like the approach that\r\n% John and his colleagues took of breaking the hundreds of fountain jets\r\n% down to a simpler problem, and used relatively simple models to describe\r\n% the jet dynamics. \r\n%\r\n% <html>\r\n% <a href=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/beautiful_bellagio_sim\/jet_model.png\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/beautiful_bellagio_sim\/jet_model.png\"\r\n% width=600><\/a>\r\n% <br><i>(Click on image to enlarge)<\/i>\r\n% <\/html>\r\n%\r\n% John and his\r\n% colleagues derived a second order transfer function to represent the\r\n% relationship between the force of the jet and the height of the jet above\r\n% the surface of the water reservoir. In addition they calculate the force\r\n% using some lumped parameter analysis to estimate the dynamics of the\r\n% water pump and the jet. \r\n%\r\n% Sure, one could use sophisticated fluid dynamics\r\n% models to get lots more detail. But more complex models require more time\r\n% to create, and generally more time to run. Why spend all of that time and\r\n% energy when you can get pretty close with a far simpler set of models.\r\n% Remember the fundamental law of production:\r\n% \r\n% $$Time = Money$$\r\n% \r\n\r\n%% Why is Simulink Valuable for this? \r\n% Simulink really offers a couple of\r\n% elements that are difficult to find elsewhere. \r\n%\r\n% First it provides a\r\n% graphical language to lay out the relationships of the various system\r\n% components. \r\n%\r\n% Second it provides a means to create custom models of these\r\n% components, and test the components independent of the system model. \r\n%\r\n% And\r\n% third, you can use MATLAB to <https:\/\/www.mathworks.com\/help\/simulink\/slref\/sim.html automate the\r\n% simulation> and retrieve the simulation data to create custom graphics so\r\n% you can describe the results to your manager or customer in a concrete\r\n% fashion. \r\n\r\n%% How Can We Make the Model Easier to Look At? \r\n% Since I often have\r\n% to develop models that I share with other people, I spend a lot of time\r\n% thinking about how to present models and code in a way that\u00e2\u20ac\u2122s easy to\r\n% understand. \r\n%\r\n% There are a number of features that could potentially make\r\n% the larger system model easier to look at. However, each has its\r\n% trade-off. \r\n%\r\n% * <https:\/\/www.mathworks.com\/help\/simulink\/slref\/foreachsubsystem.html\r\n% For-Each subsystem>  to replicate instances of the same system component\r\n% for different inputs.\r\n% \r\n% For example, you could have just three blocks representing the different\r\n% types of fountain jets. Each block would represent multiple instances of\r\n% each type of jet.\r\n% \r\n% The tradeoff is you now have to understand the semantics of this\r\n% particular type of subsystem in Simulink. It makes the diagram more\r\n% abstract, so while it might look prettier, it could be more difficult to\r\n% understand, especially if your audience isn\u00e2\u20ac\u2122t familiar with Simulink.\r\n% \r\n% * <https:\/\/www.mathworks.com\/help\/simulink\/ug\/virtual-signals.html#brp5v4k-1\r\n% Signals as vectors> allow you to concatenate information that is\r\n% travelling to the same location in a single line.\r\n% \r\n% This makes most sense in the context of the For-Each subsystem where each\r\n% element in the signal vector represents an input to a different instance\r\n% of the jet model.\r\n% \r\n% Again the trade-off is neatness for abstraction. You have fewer lines in\r\n% the diagram, but each line contains more information that can be\r\n% difficult to surmise just by looking at the diagram.\r\n% \r\n% * <https:\/\/www.mathworks.com\/products\/stateflow\/  Stateflow> to develop\r\n% the sophisticated logic required to turn various jets on and off at\r\n% specific intervals.\r\n% \r\n% Stateflow is a graphical way to represent the flow of logic. It includes\r\n% the ability to manage the particular state of a system (such as a switch\r\n% which can be on or off) as well as the conditions to transition between\r\n% the various states (turn switch on when it is dark).  Those conditions\r\n% can include the notion of time as well (turn on the switch after 5\r\n% seconds).\r\n% \r\n% In this case I believe the trade-off might be reversed from the other two\r\n% suggestions. It may be easier for someone to understand the logic if\r\n% Stateflow is used as it may reduce the abstraction introduced by elements\r\n% like variable delays, but requires the model designer to learn another\r\n% graphical language to develop the model.\r\n\r\n%%\r\n% *Comments*\r\n%\r\n% If you would like to leave any comments regarding this post, please click \r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=5104#respond here>. \r\n##### SOURCE END ##### 1080ac5c3a6e4638869dfb06e3544312\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n\r\nGreg's pick this week is Bellagio Fountain Simulation by John Hedengren and friends.How would you develop the complex choreography for The Fountains of Bellagio without getting wet?This video... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2014\/01\/31\/beautiful-bellagio-simulation\/\">read more >><\/a><\/p>","protected":false},"author":44,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5104"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=5104"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5104\/revisions"}],"predecessor-version":[{"id":5110,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5104\/revisions\/5110"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=5104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=5104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=5104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}