Contents Previous Next Index
3 Creating Custom Modeling Components
In this chapter:
Understanding Custom Components
Creating Custom Components with Signal-Flow Behavior
Creating Custom Components with Physical Connections
Working with Custom Components in MapleSim
Example: Creating a Nonlinear Spring-Damper Custom Component
3.1 Understanding Custom Components
Creating custom components extends the MapleSim component library, enabling you to create custom modeling components based on the mathematical models that you define. Custom components can use signals, ports with associated physical domains, or a combination of the two. You can also create libraries of custom components and create custom components to contain particular subsystems with specialized functionality.
For a complete tutorial on how to create domain specific custom components, see Tutorial 5: Using the Custom Component Template.
There are several different Custom Component templates. These are found in the Templates palette, under the Add Apps or Templates tab (
Figure 3.1: The Add Apps or Templates tab
Creating a Simple Custom Component
The general process of creating a custom component for a MapleSim model consists of specifying the component equations for the custom component, component parameters and system model, specifying the port types and their values, and generating the component.
To create a custom component:
Start a new MapleSim model and select the Add Apps or Templates tab (
From the Templates palette, double-click on Custom Component.
Enter a name for the template in the Create Attachment window, and then click Create Attachment (
). Maple opens with the DAE Custom Component template.
In the Define Equations area, enter the equations for your custom component. Equations, parameters, and initial conditions are all entered here. Press Enter at the end of the line.
eq ≔ st=sat−sbt, 0=Fat + Fbt, Fat=piecewisest<0, K⋅st + B⋅ⅆⅆ tst,0,K = 1000, B = 10
In the Configuration section, select Parameters, click Refresh All, and then assign default values and types to model parameters.
Select Variables, click Refresh All, and then assign initial values and types for model variables.
Select Ports, and then add ports to the custom components by clicking Add Port. You can also control the layout of ports and the icon to use for the custom component.
It is possible to define custom ports. To do so, you must first define the custom port using the Custom Port app. Then you can use the custom port in this app. For a complete tutorial on how to use custom ports, see Example: Custom Ports in Chapter 6.
Provide the details for the port type, style, name, and port signals.
In the Component Generation section, enter a name for the component. This will be the name given to the custom component in the Components palette, under the Local Components tab (
) in MapleSim.
Click Generate MapleSim Component to create your component and to return to the MapleSim environment. The custom component now appears in the Local Components tab in the Components palette.
The Custom Component template is the most general template and is specifically designed to help you create custom components from algebraic expressions, differential equations, or systems of differential-algebraic equations. The Custom Component Template is a collection of pre-built controls and procedures associated specific Maple commands to easily create new MapleSim components. In addition to the Custom Component, the Modelica Custom Component allows for the creation of a custom component via user-provided Modelica code.
Custom Component templates are more than just containers for your equations. You can also access all of Maple’s functionality to further develop your equations before you generate the Custom Component for your model. This includes access to Maple’s programming language, symbolic algebra functionality, and documentation tools to instantly analyze and verify the behavior of your component.
By using the Custom Component Template, you create a custom component in Maple by performing the following tasks:
Attach a custom component template to your model.
Define and enter your governing equations and properties that determine the behavior of the component (for example, parameters and port variables).
Specify ports for your component.
Define the associated port variable mappings.
Map variables from your equations to the ports.
Generate the component and make it available in MapleSim.
Test and analyze your mathematical model.
The Custom Component Template contains pre-built controls that allow you to perform these tasks with the same validation as for built-in components, preventing invalid connections and parameter values.
Using The Custom Component Template
For details on using this template, refer to the help page Using the MapleSim DAE Custom Component Template.
3.2 Creating Custom Components with Signal-Flow Behavior
Custom components simplify model construction by reducing the need to connect many signal-flow components together. This example shows how to create a custom component for a simple signal-flow equation.
Creating a Simple Signal-Flow Custom Component
Create a custom component that implements the following equation:
To create a custom component
Start a new MapleSim model and then click Add Apps or Templates (
In the Templates palette, double-click on Custom Component.
Enter custom for the name of the attachment, and then click Create Attachment (
In the Define Equations section, enter the following equation:
Note: The equation here is enclosed in square brackets because eq must be assigned a list of equations.
Press Enter to register the equation.
Figure 3.2: Equations Defining a Custom Component
Tip: The equations in the custom component do not have to be rearranged into an explicit form. For example, you could replace the equation with:
eq≔xt+logxt2 = yt+zt;
for which there is no explicit solution for the output xt. MapleSim solves for xt automatically.
In the Configuration section, select Ports, and then click Refresh All to update the tables.
Click Clear All Ports.
Add three new ports by clicking Add Port three times and then drag them into following positions.
Figure 3.3: Port Mappings
Click on the top port on the left-hand side to select it.
From the Type drop-down list, select Real Signal. For the Style, select the in radio button. The port is given the default name real_i.
Next, associate a variable with the port signal. Select y(t) from the drop-down list as shown in Figure 3.4.
Figure 3.4: Variable to Port Mapping
Assign the remaining port mappings using the settings in Table 3.1.
From the Icon list, select Use default.
Under the Component Generation section, enter custom in the Name field.
Click Generate MapleSim Component. The custom component equations are generated and assigned to the model. The custom component icon appears in MapleSim under the Local Components tab, in the Components palette.
Figure 3.5: Generated Custom Component
Drag the custom component into the workspace from the Components palette as shown in Table 3.2.
Number of Components
Local Components (
) > Components
Library Components (
) > Signal Blocks > Sources > Real
Use default settings
Connect two signal sources to the input ports on the left, and then place a probe on the right-most port (right-click and select Attach Probe), as shown below.
Figure 3.6: Completed Custom Component Model
Click Run Simulation (
) in the Main Toolbar. When the simulation is complete, the following graph appears.
Advantages of Acausal Mapping
Even though the custom component ports are specified as Signal Inputs and Signal Outputs, MapleSim is truly acausal; signals can be inputs or outputs regardless of the pin type. For example, if xt and zt were specified, and a probe was placed on yt, MapleSim would automatically rearrange the specified equation into yt=xt+zt.
The concept of signal inputs and outputs are necessary for the code generation capabilities of MapleSim, since the code is 'causalized', MapleSim expects inputs and provides outputs.
Using Differential Equations in Custom Components
Instead of using library components for your model, you can also use differential equations to define your custom component. For example, Figure 3.7 shows the equations that describe the motion of two coupled mass-spring-dampers subjected to a driving force.
Figure 3.7: Double Mass-Spring-Damper Equations
Figure 3.8 shows how the parameters are mapped to component ports:
Figure 3.8: Port Mapping for Double Mass-Spring-Damper
3.3 Creating Custom Components with Physical Connections
When you create custom components based on physical connections, each connection port has two variables associated with it: the across variable and the through variable. The across variable represents the driving force in a system (temperature difference, pressure difference, voltage drop, velocity or relative angular velocity), while the through variable represents a flow of a conserved quantity (such as heat, mass, current, force or torque).
Characteristics of Through Variables
Characteristics of Across Variables
Conserved quantity (like heat or mass)
Has a direction of flow
Satisfies the relationship input = output + accumulation
Uniform across a domain
Drives the flow of the conserved quantity
Is a scalar
Defined as the difference between two points within a physical domain
Table 3.4 shows the mathematical relationships defining the connection between various across and through variables.
ⅆmⅆ t=π⁢D4⁢ρ128 L μ⋅P
ⅆQⅆ t=h⁢A T
Deriving the System Equations for a Resistor
Table 3.5 shows a model of a simple resistor with several variables and one parameter.
Voltage on the left port
Voltage on the right port
Ohm’s Law defines the relationship between the voltage and the current as:
Figure 3.9 shows the equations mapped to the custom component ports.
Figure 3.9: Resistor Port Mapping
The current, it, on the right port has a negative sign, representing flow out of the resistor. The current on the left port is positive, representing flow into the resistor. The resistance (R) is defined as a parameter available in the Properties tab (
3.4 Working with Custom Components in MapleSim
In MapleSim, you can work with a custom component in the same way as you would work with a subsystem. You can perform the following tasks:
Save a Custom Component as Part of the Current Model
Add a Custom Component to a Custom Library
Edit a Custom Component
Opening Custom Component Examples
When you save a model, the custom component is saved as part of the model. If you click the Edit menu > Prune Model... then any unused custom component definition will be removed from the model. To protect the custom component from potentially being cleaned up by the Prune Model feature, do one of the following:
Move the custom component from the Components palette of the Local Components tab to the Hierarchy palette.
Use the custom component in your model: drag the custom component from the Components palette to the Model Workspace.
For more information, see Using MapleSim > Building a Model > Pruning a Model in the MapleSim Help System.
If you want to use a custom component in a file other than the current model, add the component to a custom library. For more information, see Creating and Managing Custom Libraries.
If you want to edit a custom component that you have generated, make your changes in the corresponding Maple worksheet and regenerate the component.
To edit a custom component
In the MapleSim Model Workspace, double-click the custom component that you want to edit. The corresponding Custom Component Template opens in Maple.
In the Maple worksheet, edit the equations, properties, or port values.
At the bottom of the worksheet, click Generate MapleSim Component. Your changes are generated in the custom component displayed in MapleSim.
Save your changes in the .mw file and the .msim file where you added the custom component.
3.5 Example: Creating a Nonlinear Spring-Damper Custom Component
In this example, you will use the Custom Component Template to create a nonlinear spring-damper custom component. The equations defined in this example are based on the Translational Spring Damper component in MapleSim. In this case, the stiffness and damping coefficients are replaced with input functions to the component.
To obtain the governing relationships, you can start with a free-body diagram. The diagram for the spring-damper system is shown in the following figure.
Figure 3.10: Nonlinear Spring-Damper Custom Component
The end points, a and b, can be defined as the ports for the component; the equations are derived relative to these ports. Therefore, the general equation of motion is:
d⋅ ⅆⅆ t srelt+c⋅srelt=Ft
where d is the damping coefficient, c is the stiffness of the spring, and srel is the relative displacement between the two ports sa and sb, can be written as:
Also, an examination of the net force on the system shows that Ft=Fbt, where,
All of the above relationships are required to define the system behavior.
Opening the Custom Component Template
The Custom Component template is part of the MapleSim templates accessed from the Main Toolbar.
To open the custom component template:
In MapleSim, open the model to which you want to add the custom component.
Select the Add Apps or Templates tab (
Enter Nonlinear Spring-Damper as the name for the template and click Create Attachment (
). The Custom Component Template opens in Maple.
Defining the Component Name and Equations
You can now specify the name that will appear for the component in the MapleSim interface and define the equations.
To define the custom component:
In the Equations section, define the nonlinear system by entering the following equations.
eq ≔ dt*diffs_relt, t+ct*s_relt = Ft, s_relt = s_bt−s_at, v_relt = diffs_relt, t, Ft = F_bt, F_at+F_bt = 0;
Note that the equations are entered in a Maple list. The constants, d (damping) and c (stiffness), are replaced by the functions d(t) and c(t) to define them as input states to the system.
With your cursor on the equation, press Enter.
In the Configuration section, select Variables, and then click Refresh All to see an updated list of variables.
You can now assign these input and output variables to ports that you will include in your generated custom component.
Defining Component Ports
In the Ports section of the template, you assign input and output variables to ports that will appear in the generated component, and specify the layout of these ports.
To define the ports:
In the Configuration section, select Ports.
Click Add Port four times. Four squares appear on the diagram. These represent the ports that you will lay out and define.
Drag the ports to position them with one on each side and two on the top of the diagram.
Select the port on the left side of the diagram.
From the Type drop-down menu, select Translational.
For the style of the port, select b. The port's default name is tflange_b.
First, define the signal position. Ensure Position = unassigned is selected in the list under Signal. From the drop-down list under Signal, select s_b(t).
Next, define the signal force. Select Force = unassigned in the list under Signal. From the drop-down list under Signal, select F_b(t). The left port is now defined as a translational flange and associated with the position variable s_b(t) and force variable F_b(t).
Select the port on the right side of the diagram.
For the style of the port, select a. The port's default name is tflange_a.
First, define the signal position. Ensure Position = unassigned is selected in the list under Signal. From the drop-down list under Signal, select s_a(t).
Next, define the signal force. Select Force = unassigned in the list under Signal. From the drop-down list under Signal, select F_a(t). The right port is now defined as a translational flange and associated with the position variable s_a(t) and force variable F_a(t).
Select the port at the top left of the diagram and then do the following.
From the Type drop-down menu, select Real Signal.
For Style, select in.
Change Name to cin.
Under Signal, select c(t) from the drop-down list.
This port is now defined as a signal input and associated with the stiffness variable c(t).
Select the port at the top right of the diagram and then do the following:
Change Name to din.
Under Signal, select d(t) from the drop-down menu.
This port is now defined as a signal input and associated with the damping variable d(t).
From the Icon list, select Use default.
The ports will be displayed in this arrangement when you generate the custom component in MapleSim.
This step is optional.
In the Configuration section, select Dimensional Analysis, and then click Check Dimensions. Algebraic expressions in the system equations that are dimensionally inconsistent are displayed in the math-container.
To correct the dimensions, select Variables, and then assign the following dimensions for the system variables in the Type column:
For c(t), enter Force/Distance.
For d(t), enter Force/Velocity.
For F(t), enter Force.
For s_rel(t), enter Length.
For v_rel(t), enter Velocity.
Click Refresh All. The algebraic expressions Force/Distance and Force/Velocity are converted to the corresponding Modelica types, TranslationalSpringConstant and TranslationalDampingConstant, respectively (you could have entered these directly).
Select Dimensional Analysis, and then click Check Dimensions. The result should be the two equations shown below.
This is a benign inconsistency indicating that the real input signals cin(t) and din(t) actually have implied units.
Generating the Custom Component
Generate the custom component to add it to the component to the Components palette in the Local Components tab.
In the Component Generation section, enter NonLinearMSD in the Name text box.
Click Generate MapleSim Component. The generated custom component appears in MapleSim in the Components palette of the Local Components tab (
You can add the custom component to a model by dragging it into the Model Workspace as you would any other component.
Save your MapleSim model as NonlinearSpringDamper.msim. Tutorial 3: Modeling a Nonlinear Damper in Chapter 6 uses this custom component in a model.
Download Help Document
What kind of issue would you like to report? (Optional)