Main Content

Analyze Architecture Model with Analysis Function

With properties specified on model elements, you can use MATLAB® to perform analysis and calculate total cost for all elements within the design. You can then create additional derived requirements for the designers of individual components in the system, such as Trajectory Planning or Sensors.

Perform static analyses based on element properties to perform data-driven trade studies and verify system requirements. Consider a robot architecture model where total cost is a consideration. For this tutorial, you will use the mobile robot architecture model with properties to perform static analysis.

For more information about the model-based systems engineering workflow within System Composer™, see Compose and Analyze Systems Using Architecture Models.

Mobile Robot Architecture Model with Properties

This example shows a mobile robot architecture model with stereotypes applied to components and properties defined.

Perform Analysis

Analyze the total cost for all components in the robot model. This procedure uses the model ex_RobotArch_props.slx.

  1. Navigate to Modeling > Analysis Model to open the Instantiate Architecture Model tool.

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

    Instantiate architecture model screen with all stereotypes selected. Configure analysis to use iteration order bottom-up.

    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 and obtain total cost for their parent architecture. This function computes the cost for one model element as a total of its own cost and the cost of all of its child components. Copy and paste the function below into your analysis function.

    function ex_RobotArch_analysis_new(instance,varargin)
        
        if instance.isComponent()
            if instance.hasValue("sysBaseStereotype.unitPrice")
                sysComponent_totalPrice = instance.getValue("sysBaseStereotype.unitPrice");
            else
                sysComponent_totalPrice = 0;
            end
            if ~isempty(instance.Components)        
                for child = instance.Components
                    if child.hasValue("sysBaseStereotype.totalPrice")
                        comp_price = child.getValue("sysBaseStereotype.totalPrice");
                        sysComponent_totalPrice = sysComponent_totalPrice + comp_price;
                    end
                end
            end
            sysPort_totalPrice = 0;
            for port = instance.Ports
                if port.hasValue("sysBaseStereotype.unitPrice")
                    unitPrice = port.getValue("sysBaseStereotype.unitPrice");
                    sysPort_totalPrice = sysPort_totalPrice + unitPrice;
                end
            end
            sysConnector_totalPrice = 0;
            for connector = instance.Connectors
                if connector.hasValue("sysBaseStereotype.unitPrice")
                    unitPrice = connector.getValue("sysBaseStereotype.unitPrice");
                    length = connector.getValue("sysConnector.length");
                    sysConnector_totalPrice = sysConnector_totalPrice + unitPrice*length;
                end
            end
            if (instance.hasValue("sysBaseStereotype.totalPrice"))
                totalPrice = sysComponent_totalPrice + ...
                             sysPort_totalPrice + sysConnector_totalPrice;
                instance.setValue("sysBaseStereotype.totalPrice",totalPrice);
            end
        end
    end
    
  3. Return to the Instantiate Architecture Model tool, select all the stereotypes, and click Instantiate. The Analysis Viewer opens and shows the properties of each model element. The default values for the start of the analysis are taken from the property values you entered when you attached the stereotype to the model and edited their values.

  4. In the Analysis section, select BottomUp as the iteration method, then click Analyze.

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

    Analysis viewer with data.

    The total costs are highlighted in yellow as computed values. The top row represents the grand total for the ex_RobotArch_props architecture.

Related Topics