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 Define a New Physical Domain.
To create a new custom component, define a component model class by writing a component file.
A component file must begin with the
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
For more information, see the component-related sections 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.
Setup — Prepares the component for simulation.
The body of the
setup function can contain assignment
and so on. The
setup function is executed once
for each component instance during model compilation. It takes no
arguments and returns no arguments. For more information, see Defining Component Setup.
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.
Another type of a custom block is an environment block that acts as a source of domain-wide parameters. For example, you can create a Hydraulic Temperature block that supplies the temperature parameter to the rest of the model.
Note The Foundation hydraulic domain does not contain a temperature parameter. You would have to create a customized hydraulic domain where this parameter is declared. Components using your own customized hydraulic domain cannot be connected with the components using the Simscape Foundation hydraulic domain. Use your own customized domain definitions to build complete libraries of components to be connected to each other.
You create environment components similar to behavioral components,
by writing a component file that consists of the declaration, setup,
and equation sections. However, to indicate that this component supplies
the parameter value to the rest of the model, set the
of this component to
source. For more information,
see Working with Domain Parameters and Attribute Lists.
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 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.