Analyze an Architecture Model

A profile contains a set of model element stereotypes with custom properties. A stereotype can be applicable to components, ports, connections, and architectures, or it can be applicable to a specific element type, such as components. When a model element has a stereotype, you can specify property values as part of its architectural definition. Stereotypes and properties also make analysis of an architecture possible.

Each profile contains a set of stereotypes, and each stereotype comes with a set of properties.

The goal of this example is to compute the total cost of the system given the cost of its parts. The example profile is limited to this goal.

Load Architecture Model Profile

Load a profile to make stereotypes available for model elements.

  1. On the Model tab and in the Profiles section, select Manage and then from the drop-down, select Import .

  2. Browse to the examples folder. <matlabroot>\toolbox\systemcomposer\examples.

  3. Select simpleProfile.xml.

This profile contains these stereotypes.

StereotypeApplicationProperties
sysGeneralcomponents, ports, connectors

ID (integer, no units)

Note (string, no units)

sysComponentcomponents

weight (double, kg)

unitPrice (double, USD)

sysConnectorconnectors

length (double, m)

weight (double, kg/m)

unitPrice (double, USD/m)

Importing the profile makes stereotypes available to their applicable elements.

  • sysGeneral is a general stereotype, applicable to all element types, that enables adding generic properties such as an ID that helps identify the element throughout the design and implementation process, and a Note that project members can use to track any issues with the element.

  • sysComponent applies only to components, and includes properties such as weight and cost that contribute to the total weight and cost specifications of the robot system.

  • sysConnector stereotype applies to connectors, and includes price and weight properties defined per meter of length. These properties help compute the total weight and cost of the design in this particular example.

Apply Stereotypes to Model Elements

Add custom properties to a model element by applying a stereotype from a loaded profile. This procedure uses the model ex_RobotArch.slx.

  1. Open the example robot model with the MATALB command open_system('ex_RobotArch_props.slx').

  2. Open the Sensors component.

  3. On the Modeling tab and in the Profiles section, select Apply Stereotypes.

  4. In the Apply Stereotypes dialog box and from the Apply to list, select All elements. From the in list, select This layer.

    In the list of available stereotypes, select simpleProfile.sysGeneral. The stereotype sysGeneral is useful for tracking.

  5. Click Apply.

  6. In the Sensors component, select the GPS component. Right-click and select Apply Stereotype > simpleProfile.sysComponent.

    The stereotype sysComponent is useful for physical properties and cost. sysGeneral was selected in a previous step.

  7. Navigate to top of the model. Apply the sysComponent stereotype to the Sensors and Trajectory Planning components, and the top-level architecture model. Right-click each component or a space in the top-level, and select Apply Stereotype > simpleProfile.sysComponent.

  8. Apply the sysConnector stereotype to all connectors in the Sensors layer, the Trajectory Planning layer and the top model layer.

Set Properties

Set the property values to enable cost analysis. Follow this example for the GPS module.

  1. In the Sensors component, select GPS component.

  2. Open the Property Inspector. On the Modeling tab and in the Design section, select Property Editor.

  3. Expand the sysComponent stereotype to see the properties.

  4. Set unitPrice to 5 and press Enter.

  5. Similarly, for the GPSData connector properties, set the length to 0.05 and unitPrice to 0.1.

  6. Complete the model using the values in this table. If a property is not in the table, you can leave it blank as it has no effect on the analysis. Pin the Property Inspector to the editor to make it permanently visible during this operation.

    LayerElementPropertyValue
    Top layerEncoder connectorlength0.5
    unitPrice0.1
    SensorData connectorlength0.6
    unitPrice0.2
    MotionCommand connectorlength0.5
    unitPrice0.2
    Sensors componentunitPrice5
    Trajectory Planning componentunitPrice500
    Motion componentunitPrice750
    Sensors layerGyroData componentunitPrice50
    DataProcessing componentunitPrice500
    GPS componentunitPrice100
    GPSData connectorlength0.05
    unitPrice0.1
    MotionData connectorlength0.05
    unitPrice0.1
    RawData connectorlength0.05
    unitPrice0.1
  7. Save the model as ex_RobotArch_props.slx.

Perform an Analysis

Analyze the total cost for all components in the robot model.

  1. On the Modeling tab and in the Views section, select Analysis Model, and then from the drop-down list select Analysis Model.

  2. Add an analysis function. In the Analysis function box, enter the function name ex_RobotArch_analysis without an extension, and then click . A MATLAB function file is created and saved with the name ex_RobotArch_analysis.m.

    The analysis function includes constructs that get properties from model elements, given as a template. Modify this template to add the cost of individual elements to obtain total cost for their parent architecture. This function computes the cost for one model element.

    function ex_RobotArch_analysis(instance,varargin)
    
    if instance.isComponent()
        sysComponent_unitPrice = instance.getValue("sysComponent.unitPrice");
        for child = instance.Components
            comp_price = child.getValue("sysComponent.unitPrice");
            sysComponent_unitPrice = sysComponent_unitPrice + comp_price;
        end
        for child = instance.Connectors
            unitPrice = child.getValue("sysConnector.unitPrice");
            length = child.getValue("sysConnector.length");
            sysComponent_unitPrice = unitPrice*length + sysComponent_unitPrice;
        end
      instance.setValue("sysComponent.unitPrice",sysComponent_unitPrice)
    end
  3. Return to the Analysis screen and click Instantiate. The analysis viewer shows the properties of each model element.

  4. Select Bottomup as the iteration method and click Analyze.

    The cost of each element is added in a bottom-up manner to find the cost of the system. The result is written to the analysis instance and is visible in the Analysis Viewer.

Related Topics