Simscape File Types and Structure
The Simscape™ language lets you define custom components, domains, and functions as textual files, and then base your physical models on these files.
Simscape File Type
The Simscape file is a dedicated file type in the MATLAB® environment. It has the extension .ssc
.
The Simscape file contains language constructs that do not exist in MATLAB. They are specific to modeling physical objects. However, the Simscape file incorporates the basic MATLAB programming syntax at the lowest level.
Simscape files must reside in a +namespace folder on the MATLAB path:
folder_on_the_path/+
MyNamespace
/MyComponent
.sscfolder_on_the_path/+
MyNamespace
/+Subnamespace
/.../MyComponent
.ssc
For more information on packaging your Simscape files, see Organizing Your Simscape Files.
File and Model Types
There are two types of Simscape files that correspond to the two model types:
Domain models describe the physical domains through which component models exchange energy and data. These physical domains correspond to port types, for example, translational, rotational, electrical, and so on.
Component models describe the physical components that you want to model, that is, they correspond to Simscape blocks.
For example, to implement a variable area hydraulic orifice that is different from the
Local Restriction (TL) block in the Simscape Foundation library, you can create a component model,
MyVarOrifice.ssc
, based on the thermal liquid domain included in the
Foundation library. However, you can also implement a simple thermohydraulic orifice by
creating a domain model first, t_hyd.ssc
(a custom hydraulic domain that
accounts for fluid temperature), and then create the component model that references it,
MyThhOrifice.ssc
, as well as all the other component models based on
this custom domain and needed for modeling thermohydraulic systems. For an example, see
Custom Library with Propagation of Domain Parameters.
The third file type, function files, represents Simscape functions. Simscape functions model a class of pure first-order mathematical functions with explicit input-output relationship. Their purpose is to reuse expressions in equations and member declarations of multiple components.
Model File Structure
Each model is defined in its own file of the same name with a .ssc
extension. For example, MyComponent
is defined in
MyComponent.ssc
. A model may be a domain model or a component model.
Each Simscape file starts with a line specifying the model class and identifier:
ModelClass Identifier
where
ModelClass
is eitherdomain
orcomponent
Identifier
is the name of the model
For example:
domain rotational
or
component spring
A Simscape file splits the model description into the following pieces:
Interface or Declaration — Declarative section similar to the MATLAB class system declarations:
For domain models, declares variables (Across and Through) and parameters
For component models, declares nodes, inputs and outputs, parameters, and variables
Implementation (only for component models) — Describes run-time functionality of the model. Implementation consists of the following sections:
Structure — For composite components, describes how the constituent components' ports are connected to one another and to the external inputs, outputs, and nodes of the top-level component. Executed once for each instance of the component in the top-level model during model compilation.
Equations — For behavioral components, describes underlying equations. Executed throughout simulation.
Events — For discrete event modeling, lets you perform discrete changes on continuous variables. Executed throughout simulation.
Note
A component file can contain any combination of these implementation sections. For an example of a component that combines behavioral and structural elements, see Composite Component with Equations — RMS Voltage Sensor.
A domain file can also sometimes contain an
equations
section. For more information, see Domain Equations.
Like the MATLAB class system, these constructs and functions act on a specific instance of the class. Unlike the MATLAB class system, the object is not passed as the first argument to function. This reduces syntax with no loss of functionality.