## Analyze Architecture

Perform static analysis on a System Composer™ architecture to evaluate characteristics of the system.

*Analysis* is a method for quantitatively
evaluating an architecture for certain characteristics. Static analysis analyzes the structure
of the system. Static analysis uses an analysis function and parametric values of properties
captured in the system model.

Use analyses to calculate overall reliability, mass roll-up, performance, or thermal characteristics of a system, or to perform a SWaP analysis.

Write static analyses based on element properties to perform data-driven trade studies and verify system requirements. Consider an electromechanical system where there is a trade-off between cost and weight, and lighter components tend to cost more. The decision process involves analyzing the overall cost and weight of the system based on the properties of its elements, and iterating on the properties to arrive at a solution that is acceptable both from the cost and weight perspective.

The analysis workflow consists of these steps:

Define a profile containing a set of stereotypes that describe some analyzable properties (for example, cost and weight).

Apply the profile to an architecture model and add stereotypes from that profile to elements of the model (components, ports, or connectors).

Specify values for the properties on those elements.

Write an analysis function to compute values necessary for the trade study. This is a static constraint solver for parametrics and values of related properties captured in the system model.

Create an instance of the architecture model, which is a tree of elements, corresponding to the model hierarchy with all shared architectures expanded and a variant configuration applied. Use the

**Instantiate Architecture Model**tool.Run the analysis function and then see analysis calculations and results in the

**Analysis Viewer**tool.

### Set Properties for Analysis

This example shows how to enable analysis by adding stereotypes to model elements and setting property values. The model provides the basis to analyze the trade-off between total cost and weight of the components in a simple architecture model of a robot system. For more information, see Simple Roll-Up Analysis Using Robot System with Properties.

#### Open the Model

Open the `RobotPhysicalArchitecture`

architecture model.

#### Import Profile

Enable analysis of properties by first importing a profile. In the toolstrip, navigate
to **Modeling** > **Profiles** > **Import** and browse to the profile to import it.

#### Apply Stereotypes to Model Elements

Apply stereotypes to all model elements that are part of the analysis. Use the Apply
Stereotypes dialog to apply stereotypes to all elements of a certain type. Navigate to **Modeling** > **Apply Stereotypes**. In Apply Stereotypes, from **Apply stereotype(s) to**,
select `Components`

. From **Scope**, select
`This layer`

. For more information, see Use Apply Stereotypes Dialog to Batch Apply Stereotypes.

**Tip**

Make sure you apply the stereotype to the top-level component if a cumulative value is to be computed.

#### Set Property Values

Set property values for each model element in the **Property
Inspector**. To open the **Property
Inspector**, navigate to **Modeling** > **Property Inspector**.

Select the model element.

In the

**Property Inspector**, expand the stereotype name and type values for properties.

### Create a Model Instance for Analysis

Create an instance of the architecture model that you can use for analysis.

An *instance* is an occurrence of an
architecture model element at a given point in time.

An instance freezes the active variant or model reference of the component in the instance model.

An *instance model* is a collection of
instances.

You can update an instance model with changes to a model, but
the instance model will not update with changes in active variants or model references. You can
use an instance model, saved in a `MAT`

file, of a System Composer architecture model for analysis.

Navigate to **Modeling** > **Analysis Model** to open the **Instantiate
Architecture Model** tool. Specify all the parameters required to create and view an
analysis model.

The **Select Stereotypes** tree lists the
stereotypes of all profiles that have been loaded in the current session and allows you to
select those whose properties should be available in the instance model. You can browse for an
analysis function, create a new analysis function, or skip analysis at this point. If the
analysis function requires inputs other than elements in the model, such as an exchange rate to
compute cost, enter it in **Function arguments**. Select a mode for iterating
through model elements, for example, `Bottom-up`

to move from the
leaves of the tree to the root. **Strict Mode** ensures elements in the
instantiated model get properties only if the corresponding element in the composition model has
the stereotype applied.

Click **Instantiate** to create the instantiated architecture model
and launch the **Analysis
Viewer** tool.

The **Analysis Viewer** shows all elements in the
first column. The other columns show properties for all stereotypes chosen for the current
instance. If a property is not part of a stereotype applied to an element, that field is greyed
out. You can use the **Filter** button to hide properties for certain
stereotypes. When you select an element, **Instance Properties** shows the
stereotypes and property values of the element. You can save an instance in a MAT-file and open
it again in the **Analysis Viewer**.

If you make changes in the model while an instance is open, you can synchronize the
instance with the model. **Update** pushes the changes from the instance
to the model. **Refresh** pulls changes to the instance from the model.
Unsynchronized changes are shown in a different color. Selecting a single element enables
the option to **Update Element**.

### Write Analysis Function

Write a function to analyze the architecture model using instances. An analysis function quantitatively evaluates an architecture for certain characteristics.

An *analysis function* is a MATLAB^{®} function that computes values necessary to evaluate the architecture using the
properties of each element in the model instance.

Use an analysis function to calculate the result of an analysis.

For more information, see Analysis Function Constructs.

You can add an analysis function as you set up the analysis instance model. After you
select the stereotypes of interest, create a template function by clicking
next to the **Analysis function** field.
The generated M-file includes the code to obtain all property values from all stereotypes
that are subject to analysis. The analysis function operates on a single element — aggregate
values are generated by iterating this function over all elements in the model when you run
the analysis using the **Analysis
Viewer** tool.

function CostAndWeightRollupAnalysis(instance,varargin) % Analysis function for the RobotPhysicalArchitecture.slx example % Calculate total price if instance.isComponent() && ~isempty(instance.Components)... && instance.hasValue('SystemProfile.PhysicalElement.UnitCost') sysComponent_unitPrice = 0; for child = instance.Components if child.hasValue('SystemProfile.PhysicalElement.UnitCost') comp_price = child.getValue('SystemProfile.PhysicalElement.UnitCost'); sysComponent_unitPrice = sysComponent_unitPrice + comp_price; end end instance.setValue('SystemProfile.PhysicalElement.UnitCost',sysComponent_unitPrice); end

In the generated file, `instance`

is the instance of the element on
which the analysis function runs currently. You can perform these operations for
analysis:

Access a property of the instance:

`instance.getValue("<profile>.<stereotype>.<property>")`

Set a property of an instance:

`instance.setValue("<profile>.<stereotype>.<property>",value)`

Access the subcomponents of a component:

`instance.Components`

Access the connectors in component:

`instance.Connectors`

The `getValue`

function generates an error if the property does not exist. You can
use `hasValue`

to query whether elements in the model have the properties before
getting the value.

As an example, this code computes the weight of a component as a sum of the weights of its subcomponents.

% Calculate total weight if instance.isComponent() && ~isempty(instance.Components)... && instance.hasValue('SystemProfile.PhysicalElement.UnitWeight') weight = 0; for child = instance.Components if child.hasValue('SystemProfile.PhysicalElement.UnitWeight') subcomp_weight = child.getValue('SystemProfile.PhysicalElement.UnitWeight'); weight = weight + subcomp_weight; end end instance.setValue('SystemProfile.PhysicalElement.UnitWeight',weight); end

Once the analysis function is complete, add it to the analysis under the
**Analysis function** box. An analysis function can take additional input
arguments, for example, a conversion constant if the weights are in different units in
different stereotypes. When this code runs for all components recursively, starting from the
deepest components in the hierarchy to the top level, the overall weight of the system is
assigned to the `weight`

property of the top-level component.

### Run Analysis Function

Run an analysis function using the **Analysis
Viewer**.

Select or change the analysis function using the

**Analyze**menu.Select the iteration method.

`Pre-order`

— Start from the top level, move to a child component, and process the subcomponents of that component recursively before moving to a sibling component.`Top-Down`

— Like pre-order, but process all sibling components before moving to their subcomponents.`Post-order`

— Start from components with no subcomponents, process each sibling, and then move to parent.`Bottom-up`

— Like post-order, but process all subcomponents at the same depth before moving to their parents.

The iteration method depends on what kind of analysis is to be run. For example, for an analysis where the component weight is the sum of the weights of its components, you must make sure the subcomponent weights are computed first, so the iteration method must be bottom-up.

Click the

**Analyze**button.

System Composer runs the analysis function over each model element and computes results. The
computed properties are highlighted yellow in the **Analysis
Viewer**.

Here, the total cost of the system is `5100 dollars`

and the total
weight is `55 kg`

.

## See Also

### Tools

### Objects

### Functions

`iterate`

|`instantiate`

|`deleteInstance`

|`update`

|`refresh`

|`save`

|`loadInstance`

|`lookup`

|`getValue`

|`setValue`

|`hasValue`