Main Content

component

Component model keywords

Syntax

component
nodes
inputs
outputs
parameters
variables
components
intermediates
branches
connections
equations
events
annotations

Description

component begins the component model class definition, which is terminated by an end keyword. Only blank lines and comments can precede component. You must place a component model class definition in a file of the same name with a file name extension of .ssc.

A component file consists of a declaration section, with one or more member declaration blocks, followed by implementation sections, such as branches, equations, events, and so on. The order of these sections does not matter.

Note

The file can contain multiple instances of declaration blocks or implementation sections of the same type, with the exception of the setup section. There may be no more than one setup section per component. However, starting in R2019a, using setup is not recommended. For better alternatives, see setup is not recommended.

The declarations section may contain any of the following member declaration blocks:

  • nodes begins a nodes declaration block, which is terminated by an end keyword. This block contains declarations for all the component nodes, which correspond to the conserving ports of a Simscape™ block generated from the component file. Each node is defined by assignment to an existing domain. See Declare Component Nodes for more information.

  • inputs begins an inputs declaration block, which is terminated by an end keyword. This block contains declarations for all the inputs, which correspond to the input Physical Signal ports of a Simscape block generated from the component file. Each input is defined as a value with unit. See Declare Component Inputs and Outputs for more information.

  • outputs begins an outputs declaration block, which is terminated by an end keyword. This block contains declarations for all the outputs, which correspond to the output Physical Signal ports of a Simscape block generated from the component file. Each output is defined as a value with unit. See Declare Component Inputs and Outputs for more information.

  • parameters begins a component parameters declaration block, which is terminated by an end keyword. This block contains declarations for component parameters. Parameters will appear in the block dialog box when the component file is brought into a block model. Each parameter is defined as a value with unit. See Declare Component Parameters for more information.

  • variables begins a variables declaration block, which is terminated by an end keyword. This block contains declarations for all the variables associated with the component. Variables will appear on the Variables tab of a block dialog box when the component file is brought into a block model.

    Variables can be defined either by assignment to an existing domain variable or as a value with unit. See Declare Component Variables for more information.

  • components begins a member components declaration block, which is terminated by an end keyword. This block, used in composite models only, contains declarations for member components included in the composite component. Each member component is defined by assignment to an existing component file. See Declaring Member Components for more information.

  • intermediates begins a declaration block of named intermediate terms, which is terminated by an end keyword. This block contains declarations of intermediate terms that can be reused in any equations section of the same component or of an enclosing composite component. See Using Intermediate Terms in Equations for more information.

branches begins the branches section, which is terminated by an end keyword. This section establishes relationship between the Through variables of the component and the domain. Relationship between the Across variables is established in the equation section. See Define Relationship Between Component Variables and Nodes for more information.

connections begins the structure section, which is terminated by an end keyword. This section, used in composite models only, contains information on how the constituent components’ ports are connected to one another, and to the external inputs, outputs, and nodes of the top-level component. See Specifying Component Connections for more information.

equations begins the equation section, which is terminated by an end keyword. This section contains the equations that define how the component works. See Defining Component Equations for more information.

events begins the events section, which is terminated by an end keyword. This section manages the event updates. See Discrete Event Modeling for more information.

annotations begins the annotations section, which is terminated by an end keyword. This section lets you provide annotations in a component file that control various cosmetic aspects of a Simscape block generated from this component. See annotations for more information.

Table of Attributes

For component model attributes, as well as declaration member attributes, see Attribute Lists.

Examples

This file, named spring.ssc, defines a rotational spring.

component spring
  nodes
    r = foundation.mechanical.rotational.rotational;
    c = foundation.mechanical.rotational.rotational;
  end
  parameters
    k = { 10, 'N*m/rad' };
  end
  variables
    theta = { 0, 'rad' };
    t = { 0, 'N*m' };
    w = { 0, 'rad/s' };
  end
  branches
    t : r.t -> c.t;
  end
  equations
    assert(k>0)
    w == r.w - c.w;
    t == k * theta;
    w == theta.der;
  end
end

Version History

Introduced in R2008b