component

Component model keywords

Syntax

component
nodes
inputs
outputs
parameters
variables
components
function setup
branches
connections
equations

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 setup and equation sections.

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 Declaring 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 Declaring 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 Declaring 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 Declaring 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 are internal to the component; they will not appear in 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 Declaring 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.

function setup begins the setup section, which is terminated by an end keyword. Use this section for validating parameters, computing derived parameters, and setting initial conditions. See Defining Component Setup 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 Defining 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.

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
  function setup
    if k < 0
      error( 'Spring rate must be greater than zero' );
    end
  end
  branches
    t : r.t -> c.t;
  end
  equations
    w == r.w - c.w;
    t == k * theta;
    w == theta.der;
  end
end

See Also

domain

Was this topic helpful?