Partition Data for Model Reference Hierarchy Using Data Dictionaries - MATLAB & Simulink (original) (raw)

When you use model referencing to break a large system of models into smaller components and subcomponents, you can create data dictionaries to segregate the_design data_. Design data is the set of workspace variables that the models use to specify block parameters and signal characteristics. For basic information about data dictionaries, see What Is a Data Dictionary?.

To take this component-based approach to data management, create a shared dictionary that contains common data and a separate dictionary for each component that contains the data needed by that component.

Open the Example Model and Load Design Data

Open the example model ex_SystemModel. This model is at the top of a reference hierarchy that includes the other example models.

Load the MAT files contained in the working directory to create design data in the base workspace.

load ProjectData_Contr.mat load ProjectData_ContrSub1.mat load ProjectData_ContrSub2.mat load ProjectData_ContrSubs.mat load ProjectData_Plant.mat load ProjectData_System.mat

Create a Dictionary for Each Component

This example shows how to partition design data into dictionaries. When you finish, each component in the system has a dictionary, and dictionary references allow the components to share data.

Explore Example Model Hierarchy

  1. In the model, update the diagram. Each bus signal in the model uses a Simulink.Bus object as a data type. The objects, SensorBus andCtrlBus, are in the base workspace.
    The referenced models ex_PlantComp_Lvl1 andex_ContrComp use the bus objects for root-level inputs and outputs, which means the plant and controller components share the objects.
  2. In the base workspace, double-click the Simulink.NumericType object namedFloatType. Signals, parameters, and other data items in the controller component use this shared data type.
  3. In the Model Explorer Model Hierarchy pane, expand the node ex_SystemModel.
    Click the Configurations node. In theContents pane, the node Reference to SimConfigSet appears.SimConfigSet is a Simulink.ConfigSet object in the base workspace. To maintain configuration parameter uniformity for simulation, all of the models in the hierarchy refer toSimConfigSet.
  4. Right-click the node Controller (ex_ContrComp) and select .
  5. In the Model Explorer Model Hierarchy pane, expand the new node ex_ContrComp. Click theConfigurations node.
    In the Contents pane, the nodeReference to CodeGenConfigSet appears.CodeGenConfigSet is a Simulink.ConfigSet object in the base workspace. To maintain configuration parameter uniformity for code generation, the models in the controller component refer toCodeGenConfigSet. The models in the plant component do not use CodeGenConfigSet.
  6. In the Model Hierarchy pane, selectBase Workspace. In theContents pane, right-click the variablediff and select . In the Select a system dialog box, select ex_SystemModel and clickOK. If you see a message about updating the diagram, click OK.
    In the Contents pane, the variablediff is used by Constant blocks in the models ex_ContrComp_Sub1_Lvl1 andex_ContrComp_Sub1_Lvl2, which make up the first controller subcomponent. Similarly, other models in the hierarchy share the base workspace variablescoeff, init,mu, and rho.

The table shows the models that share each variable in the base workspace.

Variable Name Models Using the Variable Scope of Sharing
CtrlBus Top-level models in the plant and controller components Shared globally by entire system
SensorBus Top-level models in the plant and controller components Shared globally by entire system
SimConfigSet All models in the hierarchy Shared globally by entire system
rho ex_PlantComp_Lvl2 ,ex_ContrComp_Sub1_Lvl2, andex_ContrComp_Sub2_Lvl2 Shared globally by entire system
mu ex_PlantComp_Lvl1 andex_PlantComp_Lvl2 Shared by models in the plant component
FloatType All models in the controller component Shared by controller component and subcomponents
CodeGenConfigSet All models in the controller component Shared by controller component and subcomponents
init ex_ContrComp_Sub1_Lvl2 andex_ContrComp_Sub2_Lvl1 Shared by controller subcomponents
diff ex_ContrComp_Sub1_Lvl1 andex_ContrComp_Sub1_Lvl2 Shared by models in the first controller subcomponent
coeff ex_ContrComp_Sub2_Lvl1 andex_ContrComp_Sub2_Lvl2 Shared by models in the second controller subcomponent

Suppose that separate teams of developers maintain the plant component and the controller components. You can use data dictionaries to store and scope the shared design data.

Create Shared Global Dictionary

Create a shared global data dictionary that contains the data shared globally by the entire system.

  1. In the Model Explorer, select > > .
  2. Set the new dictionary name to GlobalShare and click Save.
  3. In the Model Hierarchy pane, right-click theGlobalShare node and select .
  4. In the Model Hierarchy pane, selectBase Workspace. In theContents pane, select the design data that are shared globally by the entire system:CtrlBus, SensorBus, andrho.
  5. Right-click and select .
  6. In the Model Hierarchy pane, right-click theDesign Data node underGlobalShare and select .
  7. Similarly, copy SimConfigSet from theBase Workspace and copy to theConfigurations node underGlobalShare.

Create Dictionary for Plant Component

Create a data dictionary for data shared by models in the Plant component. Add a reference from this dictionary to the shared global dictionary.

  1. In the Model Explorer, select > > .
  2. Set the new dictionary name to Plant and clickSave.
  3. In the Model Hierarchy pane, select the nodePlant. In the Dialog pane, underReferenced Dictionaries, clickAdd.
  4. Double-click GlobalShare.sldd.
  5. In the Model Hierarchy pane, right-click the node Plant and select .

Link the Plant component to its component dictionary then migrate data shared by models in the Plant component from the base workspace to the dictionary.

  1. Open the model ex_PlantComp_Lvl1.
  2. In the model, update the diagram.
  3. If the Diagnostic Viewer displays an error for multiple inconsistent definitions of SimConfigSet, selectUpdate others to match next to theGlobalShare instance. This fix updates other definitions to be consistent with the GlobalShare definition.
  4. In the Modeling tab, underDesign, click Link to Data Dictionary.
  5. In the dialog box, click Browse.
  6. Double-click Plant.sldd.
  7. In the Model Properties dialog box, clickApply. Click Change all models in response to the message about linking referenced models.
  8. In the Model Properties dialog box, clickMigrate data.
  9. In the Migrate Data dialog box, select Include data from referenced models and then clickMigrate.
  10. (Optional) In the Model Properties dialog box, clear Enable model access to base workspace.
  11. Remove the previous method for loading model data. In theModel Properties dialog box, on theCallbacks tab, clear thePreLoadFcn for the model.
  12. Click OK.

Create Dictionary for Controller Component

Create a data dictionary that contains the data shared by models in the controller component. This dictionary can also reference the shared global dictionary.

  1. In the Model Explorer, select > > .
  2. Set the new dictionary name to Controller and click Save.
  3. In the Model Hierarchy pane, select the nodeController. In the Dialog pane, underReferenced Dictionaries, clickAdd.
  4. Double-click GlobalShare.sldd.
  5. In the Model Hierarchy pane, right-click the node Controller and select .

Link the Controller component to its component dictionary then migrate data shared by models in the Controller component from the base workspace to the dictionary.

  1. Open the model ex_ContrComp.
  2. If the Diagnostic Viewer displays an error for multiple inconsistent definitions of SimConfigSet, selectUpdate others to match next to theGlobalShare instance.
  3. In the Modeling tab, underDesign, click Link to Data Dictionary.
  4. In the dialog box, click Browse.
  5. Double-click Controller.sldd.
  6. In the Model Properties dialog box, clickApply. Click Change all models in response to the message about linking referenced models.
  7. In the Model Properties dialog box, clickMigrate data.
  8. In the Migrate Data dialog box, select Include data from referenced models and then clickMigrate.
  9. (Optional) In the Model Properties dialog box, clear Enable model access to base workspace.
  10. Remove the previous method for loading model data. In theModel Properties dialog box, on theCallbacks tab, clear thePreLoadFcn for the model.
  11. Click OK.

Finally, link the top model to the global dictionary.

  1. Open the model ex_SystemModel.
  2. In the Modeling tab, underDesign, click Link to Data Dictionary.
  3. In the dialog box, click Browse.
  4. Double-click GlobalShare.sldd.
  5. In the Model Properties dialog box, clickOK. Click Change this model only in response to the message about linking referenced models.

Inspect Data Storage

In the Model Explorer Model Hierarchy pane, select the dictionary node Plant. In the Contents pane, to view the contents of Plant.sldd, click Show Current System and Below . The contents of the Design Data and Configurations sections appear.

The Contents pane of Model Explorer with Design Data and Configuration sections from Plant.sldd displayed

Similarly, view the contents of Controller.sldd.

The Contents pane of Model Explorer with Design Data and Configuration sections from Controller.sldd displayed

The DataSource column shows the variables and objects that each dictionary stores.

All of the globally shared variables, such as CtrlBus andSensorBus, reside in GlobalShare.sldd. The variable init, which both of the controller subcomponents share, resides in Controller.sldd.

If the development team assigned to the controller component must make changes to the globally shared variables, they access the GlobalShare dictionary file. Similarly, if the team must make changes to the variableinit, they must access the Controller dictionary file.

Inspect Dictionary Hierarchy

To view the entire dictionary and model hierarchy, perform a dependency analysis.

  1. Open your saved model ex_SystemModel.
  2. On the Modeling tab, in theDesign section, click Dependency Analyzer.

Dependency analyzer that displays the dictionary and model hierarchy

The system model, ex_SystemModel, is linked to the dictionary GlobalShare.sldd. The plant component and the controller component are each linked to a separate dictionary. To access the shared data, the component dictionaries reference the dictionaryGlobalShare.sldd. These dictionaries form a reference hierarchy.

Strategies to Discover Shared Data

To learn how the models in a model reference hierarchy share data, use these techniques:

See Also

Topics