{"id":39,"date":"2008-12-05T07:30:15","date_gmt":"2008-12-05T07:30:15","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2008\/12\/05\/the-answer-for-large-scale-modeling-model-reference\/"},"modified":"2017-01-02T15:56:39","modified_gmt":"2017-01-02T20:56:39","slug":"the-answer-for-large-scale-modeling-model-reference","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2008\/12\/05\/the-answer-for-large-scale-modeling-model-reference\/","title":{"rendered":"The Answer for Large Scale Modeling: Model Reference"},"content":{"rendered":"<p>Your model is someone else\u2019s component.\u00a0 The Model block<br \/>\nallows you to treat a Simulink model as a component within a larger system.\u00a0 In this<br \/>\npost I will discuss the basic concepts of <a\nhref=\"https:\/\/www.mathworks.com\/help\/releases\/R2008b\/toolbox\/simulink\/ug\/bq_5wvg-1.html\">model<br \/>\nreference<\/a> and look at what is new for R2008b.<\/p>\n<p><strong>What is Model Reference?<\/strong><\/p>\n<p>Model reference is the Model block from the Ports &amp;<br \/>\nSubsystems library.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q4\/mdlrefModelBlock.png\" alt=\"The Simulink model reference block\"><\/p>\n<p>When you use the Model block you must specify the model that<br \/>\nyou are referencing.\u00a0 This is how your model becomes a component in a larger simulation.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q4\/mdlrefEnterModelName.png\" alt=\"Model block requires the name of a model\"><\/p>\n<p>Models can reference models, which can reference models, and<br \/>\nso on.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q4\/mdlrefBasic.png\" alt=\"A model block has a model inside\"><\/p>\n<p><strong>Benefits of Hierarchy<\/strong><\/p>\n<p>Model reference lets you break up the hierarchy into<br \/>\nseparate models.\u00a0 These models can be simulated and built stand alone, which<br \/>\nmeans teams can independently develop components in parallel.\u00a0\u00a0 The benefits of<br \/>\nbreaking up the hierarchy in this way include:<\/p>\n<ul>\n<li>Fewer blocks in the top level system<\/li>\n<li>Simulation and testing of component models<\/li>\n<li>Incremental update diagram and code generation<\/li>\n<li>Interface specification for parallel development<\/li>\n<\/ul>\n<p>The cost to update a diagram is roughly proportional to the<br \/>\nnumber of blocks in the model.\u00a0 If you have a system of 10,000 blocks that<br \/>\nimplement your model, you might be able to add a layer of model reference to<br \/>\nencapsulate some systems, and reduce the number of blocks in the top model.\u00a0 When<br \/>\na model reference component runs in accelerator mode, it is a single block in<br \/>\nthe top model.\u00a0 That single block can hide hundreds or thousands of blocks<br \/>\nbeneath it.\u00a0 The initial cost to update that reference component will be<br \/>\nproportional to the number of blocks in that model, but once it is up to date,<br \/>\nthe top model can update more quickly.<\/p>\n<p>This leads to another major benefit, incremental rebuilds.\u00a0<br \/>\nWhen you make a change to a reference model, only that model needs to rebuild.\u00a0<br \/>\nThis is true for simulations and for Real-Time Workshop code generation.\u00a0 When<br \/>\nyou make a change to a model, only that model and other models that depend on<br \/>\nit will require a rebuild.\u00a0 This is where you can save time if you are only<br \/>\nchanging a small portion of the model reference hierarchy.<\/p>\n<p><strong>Modes of Simulation<\/strong><\/p>\n<p>Each model block can define its <a\nhref=\"https:\/\/www.mathworks.com\/help\/releases\/R2008b\/toolbox\/simulink\/ug\/bq_84fh-1.html#brcedw2\">simulation<br \/>\nmode<\/a>.\u00a0 This tells Simulink how that instance of the model runs.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q4\/mdlrefSimulationMode.png\" alt=\"Specify the Simulation mode on each model block instance\"><\/p>\n<p>Normal Mode \u2013 The reference model runs in interpreted mode, the<br \/>\nsame way a normal model runs when you are first building it.\u00a0 This mode for model<br \/>\nreference is helpful for debugging and when making changes to a reference<br \/>\ncomponent.\u00a0 Normal mode was added to the model reference block in R2007b.\u00a0<br \/>\nNormal mode is indicated by the empty triangles on the corners of the model<br \/>\nblock.<\/p>\n<p>Accelerator Mode \u2013 To a parent model, the accelerated model<br \/>\nbehaves like a single block.\u00a0 Simulink uses code generation technology to convert<br \/>\nthe referenced model into a MEX-file (simulation target), which the parent<br \/>\ncalls during the simulation.\u00a0 There is a one-time cost to generate that<br \/>\nMEX-file but subsequent simulations can be faster than normal mode.\u00a0<br \/>\nAccelerator mode is indicated with filled corners on the model blocks.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q4\/mdlrefNormAcc.png\" alt=\"Normal and accelerator model reference blocks\"><\/p>\n<p>Processor-in-the-loop (PIL) Mode \u2013 <em>NEW in R2008b<\/em> \u2013<br \/>\nPIL mode allows co-simulation of the reference model on another processor. This<br \/>\nenables the development of combination plant\/controller models using model<br \/>\nreference for components.\u00a0 When prototype controller hardware is available, you<br \/>\ncan generate production code for that target using Real-Time Workshop Embedded<br \/>\nCoder.\u00a0 In PIL mode Simulink creates a MEX-file that handles the execution of<br \/>\nthe production code.\u00a0 The top-level simulation is still in Simulink, but the<br \/>\ncode for the controller can be running on the actual hardware or in an instruction<br \/>\nset simulator\/emulator.\u00a0 PIL mode model blocks have filled triangles on the<br \/>\ncorners and include (PIL) below the name of the model.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q4\/mdlrefPIL.png\" alt=\"Processor-in-the-loop mode model reference\"><\/p>\n<p>Model reference PIL mode is a new capability however; people<br \/>\nhave been successful applying these workflows using xPC and other rapid<br \/>\nprototyping techniques with RTW for many years.\u00a0 The convenience of this<br \/>\napproach comes from preserving a single system model and just modifying the<br \/>\nsimulation mode of the model reference block.\u00a0 One might use normal mode when<br \/>\ndebugging the algorithm, accelerated mode for coverage testing and rapid test<br \/>\nvector generation, and finally PIL mode to verify the code running on the<br \/>\nactual hardware.\u00a0 Each of these steps requires minimal modifications to the<br \/>\noriginal system model. There are some <a\nhref=\"https:\/\/www.mathworks.com\/help\/releases\/R2008b\/toolbox\/ecoder\/ug\/brr9tb5-1.html#brr9tb5-4\">problems<br \/>\nthat only PIL mode can detect<\/a>.\u00a0 <\/p>\n<p><strong>Some History<\/strong><\/p>\n<p>Simulink included the model reference block in R14.\u00a0 At the time,<br \/>\npeople were finding that their models would grow so large that they couldn\u2019t<br \/>\nfit them into the memory on their systems.\u00a0\u00a0 The performance of update diagram<br \/>\nand RTW build was hitting limits of available RAM, and models continue to grow<br \/>\nin size.\u00a0 Model reference breaks up these problems and provides a scalable long-term<br \/>\nsolution for working with large models.<\/p>\n<p>How many levels of model reference hierarchy do you work<br \/>\nwith?\u00a0 Leave a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=39&amp;#comment\">comment<br \/>\nhere<\/a> and tell us your experience with model reference.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Your model is someone else\u2019s component.\u00a0 The Model block<br \/>\nallows you to treat a Simulink model as a component within a larger system.\u00a0 In this<br \/>\npost I will discuss the basic concepts of model<br \/>\nreference... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2008\/12\/05\/the-answer-for-large-scale-modeling-model-reference\/\">read more >><\/a><\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,66,24,16],"tags":[456,441],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/39"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":6188,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/39\/revisions\/6188"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}