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 SimHydraulics® 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 Creating 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 typically contain the following sections:
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.
Setup — Prepares the component for simulation.
The body of the
setup function can contain assignment
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 Creating Composite Components.
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.
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.
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 from Simscape Component Files. 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.