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.
Term | Definition |
---|---|
Member |
|
Member class |
|
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 Class | Applicable Model Classes | MATLAB Class of Expression | Expression Meaning | Writable |
---|---|---|---|---|
parameters | domain component | Numerical value with unit | Default value | Yes |
variables | domain component | Numerical value with unit | Nominal value and default initial condition | Yes |
inputs | component | Scalar, vector, or matrix double value with unit, or untyped | Default value, if typed | No |
outputs | component | Scalar, vector, or matrix double value with unit, or untyped | Default value, if typed | No |
nodes | component | Instance of a node associated with a domain | Type of domain | No |
components | component | Instance of a component class | Member 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' }
.