Main Content

instantiate

Create analysis instance from specification

Description

example

instance = instantiate(model,properties,name) creates an instance of a model for analysis.

This function is part of the instance API that you can use to analyze the model iteratively, element by element. instance refers to the element instance on which the iteration is being performed.

example

instance = instantiate(model,profile,name) creates an instance of a model for analysis with all stereotypes in a profile.

example

instance = instantiate(___,Name,Value) creates an instance of a model for analysis with additional arguments.

Examples

collapse all

Instantiate all properties of a stereotype that will be applied to specific elements during instantiation.

Create a profile for latency characteristics.

profile = systemcomposer.profile.Profile.createProfile('LatencyProfile');

% Add base stereotype with properties
latencybase = profile.addStereotype('LatencyBase');
latencybase.addProperty('latency','Type','double');
latencybase.addProperty('dataRate','Type','double','DefaultValue','10');

% Add connector stereotype with properties
connLatency = profile.addStereotype('ConnectorLatency','Parent',...
'LatencyProfile.LatencyBase');
connLatency.addProperty('secure','Type','boolean');
connLatency.addProperty('linkDistance','Type','double');

% Add component stereotype with properties
nodeLatency = profile.addStereotype('NodeLatency','Parent',...
'LatencyProfile.LatencyBase');
nodeLatency.addProperty('resources','Type','double','DefaultValue','1');

% Add port stereotype with properties
portLatency = profile.addStereotype('PortLatency','Parent',...
'LatencyProfile.LatencyBase');
portLatency.addProperty('queueDepth','Type','double');
portLatency.addProperty('dummy','Type','int32');

Instantiate all properties of a stereotype.

model = systemcomposer.createModel('archModel',true); % Create new model

model.applyProfile('LatencyProfile'); % Apply profile to model

% Specify type of elements each stereotype can be applied on
NodeLatency = struct('elementKinds',['Component']);
ConnectorLatency = struct('elementKinds',['Connector']);
LatencyBase = struct('elementKinds',['Connector','Port','Component']);
PortLatency = struct('elementKinds',['Port']);

% Create the analysis structure
LatencyAnalysis = struct('NodeLatency',NodeLatency, ...
                'ConnectorLatency',ConnectorLatency, ...
                'PortLatency',PortLatency, ...
                'LatencyBase',LatencyBase);

% Create the properties structure      
properties = struct('LatencyProfile',LatencyAnalysis);

% Instantiate all properties of stereotype
instance = instantiate(model.Architecture,properties,'NewInstance')

Instantiate specific properties of a stereotype that will be applied to specific elements during instantiation.

Create a profile for latency characteristics.

profile = systemcomposer.profile.Profile.createProfile('LatencyProfile');

% Add base stereotype with properties
latencybase = profile.addStereotype('LatencyBase');
latencybase.addProperty('latency','Type','double');
latencybase.addProperty('dataRate','Type','double','DefaultValue','10');

% Add connector stereotype with properties
connLatency = profile.addStereotype('ConnectorLatency','Parent',...
'LatencyProfile.LatencyBase');
connLatency.addProperty('secure','Type','boolean');
connLatency.addProperty('linkDistance','Type','double');

% Add component stereotype with properties
nodeLatency = profile.addStereotype('NodeLatency','Parent',...
'LatencyProfile.LatencyBase');
nodeLatency.addProperty('resources','Type','double','DefaultValue','1');

% Add port stereotype with properties
portLatency = profile.addStereotype('PortLatency','Parent',...
'LatencyProfile.LatencyBase');
portLatency.addProperty('queueDepth','Type','double');
portLatency.addProperty('dummy','Type','int32');

Instantiate specific properties of a stereotype.

model = systemcomposer.createModel('archModel',true); % Create new model

model.applyProfile('LatencyProfile'); % Apply profile to model

% Specify some properties of stereotypes
NodeLatency = struct('elementKinds',["Component"], ...
                'properties',struct('resources',true));
ConnectorLatency = struct('elementKinds',["Connector"], ...
                'properties',struct('secure',true,'linkDistance',true));
LatencyBase = struct('elementKinds',[], ...
                'properties',struct('dataRate',true,'latency',false));
PortLatency = struct('elementKinds',["Port"], ...
                'properties',struct('queueDepth',true));
 
LatencyAnalysis = struct('NodeLatency',NodeLatency, ...
                'ConnectorLatency',ConnectorLatency, ...
                'PortLatency',PortLatency, ...
                'LatencyBase',LatencyBase);

% Create the properties structure      
properties = struct('LatencyProfile',LatencyAnalysis);

% Instantiate some properties of stereotype
instance = instantiate(model.Architecture,properties,'NewInstance')

Instantiate all stereotypes already in a profile that will be applied to elements during instantiation.

Create a profile for latency characteristics.

profile = systemcomposer.profile.Profile.createProfile('LatencyProfile');

% Add base stereotype with properties
latencybase = profile.addStereotype('LatencyBase');
latencybase.addProperty('latency','Type','double');
latencybase.addProperty('dataRate','Type','double','DefaultValue','10');

% Add connector stereotype with properties
connLatency = profile.addStereotype('ConnectorLatency','Parent',...
'LatencyProfile.LatencyBase');
connLatency.addProperty('secure','Type','boolean');
connLatency.addProperty('linkDistance','Type','double');

% Add component stereotype with properties
nodeLatency = profile.addStereotype('NodeLatency','Parent',...
'LatencyProfile.LatencyBase');
nodeLatency.addProperty('resources','Type','double','DefaultValue','1');

% Add port stereotype with properties
portLatency = profile.addStereotype('PortLatency','Parent',...
'LatencyProfile.LatencyBase');
portLatency.addProperty('queueDepth','Type','double');
portLatency.addProperty('dummy','Type','int32');

Instantiate all stereotypes in a profile.

model = systemcomposer.createModel('archModel',true); % Create new model

model.applyProfile('LatencyProfile'); % Apply profile to model

% Instantiate all stereotypes in profile
instance = instantiate(model.Architecture,'LatencyProfile','NewInstance')

This example shows an instantiation for analysis for a system with latency in its wiring. The materials used are copper, fiber, and WiFi.

Create a Latency Profile with Stereotypes and Properties

Create a System Composer profile with a base, connector, component, and port stereotype. Add properties with default values to each stereotype as needed for analysis.

profile = systemcomposer.profile.Profile.createProfile('LatencyProfile');

% Add base stereotype with properties
latencybase = profile.addStereotype('LatencyBase');
latencybase.addProperty('latency','Type','double');
latencybase.addProperty('dataRate','Type','double','DefaultValue','10');

% Add connector stereotype with properties
connLatency = profile.addStereotype('ConnectorLatency','Parent',...
'LatencyProfile.LatencyBase');
connLatency.addProperty('secure','Type','boolean','DefaultValue','true');
connLatency.addProperty('linkDistance','Type','double');

% Add component stereotype with properties
nodeLatency = profile.addStereotype('NodeLatency','Parent',...
'LatencyProfile.LatencyBase');
nodeLatency.addProperty('resources','Type','double','DefaultValue','1');

% Add port stereotype with properties
portLatency = profile.addStereotype('PortLatency','Parent',...
'LatencyProfile.LatencyBase');
portLatency.addProperty('queueDepth','Type','double','DefaultValue','4.29');
portLatency.addProperty('dummy','Type','int32');

Instantiate Using Analysis Function

Create a new model and apply the profile. Create components, ports, and connections in the model. Apply stereotypes to the model elements. Finally, instantiate using the analysis function.

model = systemcomposer.createModel('archModel',true); % Create new model
arch = model.Architecture;

model.applyProfile('LatencyProfile'); % Apply profile to model

% Create components, ports, and connections
components = addComponent(arch,{'Sensor','Planning','Motion'});
sensorPorts = addPort(components(1).Architecture,{'MotionData','SensorData'},{'in','out'});
planningPorts = addPort(components(2).Architecture,{'SensorData','MotionCommand'},{'in','out'});
motionPorts = addPort(components(3).Architecture,{'MotionCommand','MotionData'},{'in','out'});
c_sensorData = connect(arch,components(1),components(2));
c_motionData = connect(arch,components(3),components(1));
c_motionCommand = connect(arch,components(2),components(3));

% Clean up canvas
Simulink.BlockDiagram.arrangeSystem('archModel'); 

% Batch apply stereotypes to model elements
batchApplyStereotype(arch,'Component','LatencyProfile.NodeLatency');
batchApplyStereotype(arch,'Port','LatencyProfile.PortLatency');
batchApplyStereotype(arch,'Connector','LatencyProfile.ConnectorLatency');

% Instantiate using the analysis function
instance = instantiate(model.Architecture,'LatencyProfile','NewInstance', ...
'Function',@calculateLatency,'Arguments','3','Strict',true, ...
'NormalizeUnits',false,'Direction','PreOrder')
instance = 
  ArchitectureInstance with properties:

        Specification: [1x1 systemcomposer.arch.Architecture]
             IsStrict: 1
       NormalizeUnits: 0
     AnalysisFunction: @calculateLatency
    AnalysisDirection: PreOrder
    AnalysisArguments: '3'
      ImmediateUpdate: 0
           Components: [1x3 systemcomposer.analysis.ComponentInstance]
                Ports: [0x0 systemcomposer.analysis.PortInstance]
           Connectors: [1x3 systemcomposer.analysis.ConnectorInstance]
                 Name: 'NewInstance'

Inspect Component, Port, and Connector Instances

Get properties from component, port, and connector instances.

defaultResources = instance.Components(1).getValue('LatencyProfile.NodeLatency.resources')
defaultResources = 1
defaultSecure = instance.Connectors(1).getValue('LatencyProfile.ConnectorLatency.secure')
defaultSecure = logical
   1

defaultQueueDepth = instance.Components(1).Ports(1).getValue('LatencyProfile.PortLatency.queueDepth')
defaultQueueDepth = 4.2900

Clean Up

Uncomment the following code and run to clean up the artifacts created by this example:

% bdclose('archModel')
% systemcomposer.profile.Profile.closeAll

Input Arguments

collapse all

Model architecture from which instance is generated, specified as a systemcomposer.arch.Architecture object.

Example: model.Architecture

Stereotype properties, specified as a structure containing profile, stereotype, and property information. Use properties to specify which stereotypes and properties need to be instantiated.

Data Types: struct

Name of instance generated from the model, specified as a character vector.

Example: 'NewInstance'

Data Types: char

Profile name, specified as a character vector.

Example: 'LatencyProfile'

Data Types: char

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: instantiate(model.Architecture,'LatencyProfile','NewInstance','Function',@calculateLatency,'Arguments','3','Strict',true,'NormalizeUnits',false,'Direction','PreOrder')

Whether to normalize value based on units, if any, specified in property definition upon instantiation, specified as the comma-separated pair consisting of 'NormalizeUnits' and a logical 1 (true) to normalize or 0 (false) to do nothing.

Example: instantiate(model.Architecture,'LatencyProfile','NewInstance','NormalizeUnits',true)

Data Types: logical

Analysis function, specified as the comma-separated pair consisting of 'Function' and the MATLAB function handle to be executed when analysis is run.

Analysis arguments, specified as the comma-separated pair consisting of 'Arguments' and a character vector or a cell array of character vectors of optional arguments to the analysis function.

Data Types: char

Analysis direction, specified as the comma-separated pair consisting of 'Direction' and a character vector.

Data Types: char

Whether instances only get properties if the instance's specification has the stereotype applied, specified as the comma-separated pair consisting of 'Strict' and a logical 1 (true) or 0 (false).

Data Types: logical

Output Arguments

collapse all

Element instance, returned as a systemcomposer.analysis.ArchitectureInstance object.

More About

collapse all

Definitions

TermDefinitionApplicationMore Information
architectureA System Composer™ architecture represents a system of components and how they interface with each other structurally and behaviorally. You can represent specific architectures using alternate views.

Different types of architectures describe different aspects of systems:

  • Functional architecture describes the flow of data in a system.

  • Logical architecture describes the intended operation of a system.

  • Physical architecture describes the platform or hardware in a system.

Compose Architecture Visually
modelA System Composer model is the file that contains architectural information, including components, ports, connectors, interfaces, and behaviors.

Perform operations on a model:

  • Extract the root level architecture contained in the model.

  • Apply profiles.

  • Link interface data dictionaries.

  • Generate instances from model architecture.

System Composer models are stored as .slx files.

Create an Architecture Model
componentA component is a nontrivial, nearly-independent, and replaceable part of a system that fulfills a clear function in the context of an architecture. A component defines an architecture element, such as a function, a system, hardware, software, or other conceptual entity. A component can also be a subsystem or subfunction.Represented as a block, a component is a part of an architecture model that can be separated into reusable artifacts.Components
portA port is a node on a component or architecture that represents a point of interaction with its environment. A port permits the flow of information to and from other components or systems.

There are different types of ports:

  • Component ports are interaction points on the component to other components.

  • Architecture ports are ports on the boundary of the system, whether the boundary is within a component or the overall architecture model.

Ports
connectorConnectors are lines that provide connections between ports. Connectors describe how information flows between components or architectures.A connector allows two components to interact without defining the nature of the interaction. Set an interface on a port to define how the components interact.Connections

TermDefinitionApplicationMore Information
stereotypeA stereotype is a custom extension of the modeling language. Stereotypes provide a mechanism to extend the architecture language elements by adding domain-specific metadata.Apply stereotypes to the root level architecture, component architecture, connectors, ports, and interfaces of a model. Stereotypes provide model elements within the architecture a common set of property fields, such as mass, cost, and power.Define Profiles and Stereotypes
profileA profile is a package of stereotypes to create a self-consistent domain of model element types.Apply profiles to a model through the Profile Editor. You can store stereotypes for a project in one profile or in several. Profiles are stored in .xml files when they are saved.Use Stereotypes and Profiles
propertyA property is a field in a stereotype. For each model element the stereotype is applied to, specific property values are specified.Use properties to store quantitative characteristics, such as weight or speed, that are associated with a model element. Properties can also be descriptive or represent a status.Set Properties

TermDefinitionApplicationMore Information
analysisAnalysis 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 analysis to calculate overall reliability, mass roll-up, performance, or thermal characteristics of a system, or to perform a SWaP analysis.Analyze Architecture
instanceAn instance is an occurrence of an architecture model at a given point of time.You can update an instance with changes to a model, but the instance will not update with changes in active variants or model references. You can use an instance, saved in an .MAT file, of a System Composer architecture model for analysis.Create a Model Instance for Analysis

Introduced in R2019a