Creating Custom Components
Component Types and Prerequisites
In physical modeling, there are two types of models:
Behavioral — A model that is implemented based on its physical behavior, described by a system of mathematical equations. An example of a behavioral block implementation is the Variable Orifice block.
Composite — A model that is constructed out of other blocks, connected in a certain way. An example of a composite, or structural, block implementation is the 4-Way Directional Valve block (available with Simscape™ Fluids™ Isothermal block libraries), which is constructed based on four Variable Orifice blocks.
Simscape language lets you create new behavioral and composite models when your design requirements are not satisfied by the libraries of standard blocks provided with Simscape and its add-on products.
A prerequisite to creating components is having the appropriate domains for the component nodes. You can use Simscape Foundation domains or create your own, as described in How to Define a New Physical Domain.
How to Create a New Component
To create a new custom component, define a component model class by writing a component file.
A component file must begin with the
component keyword, followed by
the component name, and be terminated by the
Component files may contain the following sections, appearing in any order:
Declaration — Contains all the member class declarations for the component, such as parameters, variables, nodes, inputs, and outputs. Each member class declaration is a separate declaration block, which begins with the appropriate keyword (corresponding to the member class) and is terminated by the
endkeyword. For more information, see the component-related sections and links in Declaring Domains and Components.
Branches — Establishes the relationship between the component variables and nodes. This relationship connects the Through and Across variables declared inside the component to the domain Through and Across variables. For more information, see Define Relationship Between Component Variables and Nodes.
Structure — Declares the component connections for composite models. For more information, see Specifying Component Connections.
Equation — Declares the component equations for behavioral models. These equations may be conditional, and are applied throughout the simulation. For more information, see Defining Component Equations.
Events — Manages the event updates. Event modeling lets you perform discrete changes on continuous variables. For more information, see Discrete Event Modeling.
Annotations — Lets you provide annotations in a component file that control various cosmetic aspects of a Simscape block generated from this component. See
annotationsfor more information.
Generating a Custom Block from a Component File
After you have created a textual component file, you can deploy it directly into a block diagram using the workflows described in Selecting Component File Directly from Block. You can control the block name and appearance by using optional comments in the component file. For more information, see Customizing the Block Name and Appearance.
Adding a Custom Block Library
Adding a custom block library involves creating new components that model the desired physical behavior and structure. It may involve creating a new physical domain if the Simscape Foundation domain definitions do not satisfy your modeling requirements.
After you have created the textual component files, convert them into a library of blocks using the procedure described in Building Custom Block Libraries. You can control the block names and appearance by using optional comments in the component file. For more information, see Customizing the Block Name and Appearance.
- Mechanical Component — Spring
- Electrical Component — Ideal Capacitor
- No-Flow Component — Voltage Sensor
- Grounding Component — Electrical Reference
- Composite Component — DC Motor