When the number of variables in any one module (or the root model) becomes large, it can be difficult to see the structure all at once and therefore understand it. A good way to manage this complexity is to use modules (see Working with Modules). The encapsulation functionality allows you to quickly create modules containing parts of model structure and connecting those to the place the original structure was located. For example, suppose you have to distinct parts of a model:
You could move population and its flows to one module, and Patients and its flows to another giving you:
The encapsulating functionality makes this easy.
Select the variables you want to put into a module. You can select by dragging over an area, or by holding down the shift key and clicking. You do not need to select connectors, the necessary connectors will be determined based on the variables you have selected.
After making your selection right click (or Ctrl-click/⌘-click) on one of the selected variables and select Encapsulate into Module in the menu that appears.
A new module will be created and the structure you have selected placed in that module. Any connections from variables not included in the selection will have a cross level ghost created for them in the new module. Any connections to variables not included in the selection will generate a new cross level ghost from the new module and that will in turn be connected to the non selected variable.
To encapsulate a sector click on the encapsulate () icon that appears on the top left next to the selection icon (). The contents of the sector will be moved into the module, and the module will be given the name of the sector.
The encapsulation process will create cross level ghosts to connect the newly encapsulated module with other variables in the place it was encapsulated from. If there were no such connections, this is not necessary and the encapsulation process is actually the same as a cut and paste into a module.
If the variables to be encapsulated include ghosts, corresponding ghosts may be created inside the new module. If, for example, the ghosts were of a stock that was not included in the selection or sector, inside the module they will appear as converters. This is because of the convention used to create cross level ghosts, and will not change model behavior.
Not everything can be successfully encapsulated, and when it won't work you will be given a message explaining why and nothing will happen.
Most importantly, stocks and flows must be kept together. If you include a stock, you need to include all of its flows. If you include a flow, you need to include all of the stocks the flow is connected to. A consequence of this is that any chain of stocks connected by flows must be kept intact. While it may be possible to modularize these by hand, the encapsulate process is not able to do this.
When you encapsulate structure the work is done relative to the module or root model from which you encapsulate. This means that there may be cross level ghosts placed that will connect in and out of the newly created modules. In some cases, these cross level ghosts may take something from one module to provide it to another. In this case you can remove the cross level ghost on the starting module and connect the two new modules directly by connecting the output from one to an input of another.
Changing such intermediate connections has no impact on model behavior; it is simply a mechanism to keep the model diagram less cluttered.