Main Content

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 withSimscape™ 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 inHow 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 thecomponentkeyword, followed by the component name, and be terminated by theendkeyword.

Component files may contain the following sections, appearing in any order:

  • 宣言——declar包含所有成员的类ations 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 theendkeyword. For more information, see the component-related sections and links inDeclaring 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, seeDefine Relationship Between Component Variables and Nodes.

  • Structure — Declares the component connections for composite models. For more information, seeSpecifying Component Connections.

  • Equation — Declares the component equations for behavioral models. These equations may be conditional, and are applied throughout the simulation. For more information, seeDefining Component Equations.

  • Events — Manages the event updates. Event modeling lets you perform discrete changes on continuous variables. For more information, see离散事件建模.

  • Annotations — Lets you provide annotations in a component file that control various cosmetic aspects of a Simscape block generated from this component. Seeannotationsfor 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 inSelecting Component File Directly from Block. You can control the block name and appearance by using optional comments in the component file. For more information, seeCustomizing 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 inBuilding Custom Block Libraries. You can control the block names and appearance by using optional comments in the component file. For more information, seeCustomizing the Block Name and Appearance.

Related Examples

More About