Main Content

Declaring Domains and Components

Declaration Section Purpose

Both domain and component files contain a declaration section:

  • The declaration section of a domain file is where you define the Through and Across variables for the domain. You can also define the domain-wide parameters, if needed.

  • The declaration section of a component file is where you define all the variables, parameters, nodes, inputs, and outputs that you need to describe the connections and behavior of the component. These are called member declarations.

    In order to use a variable, parameter, and so on, in other sections of a component file (such as branches or equations), you have to first define it in the declaration section.

Definitions

The declaration section of a Simscape™ file may contain one or more member declarations.

TermDefinition
Member
  • A member is a piece of a model’s declaration. The collection of all members of a model is its declaration.

  • It has an associated data type and identifier.

  • Each member is associated with a unique member class. Additionally, members may have some specific attributes.

Member class
  • A member class is the broader classification of a member.

  • The following is the set of member classes: variables (domain or component variables), parameters, inputs, outputs, nodes, components. The components member class, not to be confused with the component model class, is discussed in Declaring Member Components.

  • Two members may have the same type, but be of different member classes. For example, a parameter and an input may have the same data type, but because they are of different member classes, they behave differently.

Member Declarations

The following rules apply to declaring members:

  • Like the MATLAB® class system, declared members appear in a declaration block:

    <ModelClass> <Identifier>
       <MemberClass>
          % members here
       end
       ...
    end
  • Unlike the MATLAB class system, <MemberClass> may take on any of the available member classes and dictates the member class of the members defined within the block.

  • Like the MATLAB class system, each declared member is associated with a MATLAB identifier, <Identifier>. Unlike the MATLAB class system, members must be declared with a right-hand side value.

    <ModelClass> <Identifier>
       <MemberClass>
          <Identifier> = <Expression>;
          % more members
       end
       ...
    end
  • <Expression> on the right-hand side of the equal sign (=) is a MATLAB expression. It could be a constant expression, or a call to a MATLAB function.

  • The MATLAB class of the expression is restricted by the class of the member being declared. Also, the data type of the expression dictates data type of the declared member.

Member Summary

The following table provides the summary of member classes.

Member ClassApplicable Model ClassesMATLAB Class of ExpressionExpression MeaningWritable
parametersdomain
component
Numerical value with unitDefault valueYes
variablesdomain
component
Numerical value with unitNominal value and default initial conditionYes
inputscomponentScalar, vector, or matrix double value with unit, or untypedDefault value, if typedNo
outputscomponentScalar, vector, or matrix double value with unit, or untypedDefault value, if typedNo
nodescomponentInstance of a node associated with a domainType of domainNo
componentscomponentInstance of a component classMember component included in a composite model (see Declaring Member Components)No

Declaring a Member as a Value with Unit

In Simscape language, declaration members such as parameters, variables, inputs, and outputs, are represented as a value with associated unit. The syntax for a value with unit is essentially that of a two-member value-unit cell array:

 { value , 'unit' }

where value is a real matrix, including a scalar, and unit is a valid unit string, defined in the unit registry, or 1 (unitless). Depending on the member type, certain restrictions may apply. See respective reference pages for details.

For example, this is how you declare a parameter as a value with unit:

par1 = { value , 'unit' };

As in MATLAB, the comma is not required, and this syntax is equivalent:

 par1 = { value 'unit' };

To declare a unitless parameter, you can either use the same syntax:

 par1 = { value , '1' };

or omit the unit and use this syntax:

 par1 = value;

Internally, however, this parameter will be treated as a two-member value-unit cell array { value , '1' }.

Related Topics