Simulation subsystems provide a way to modularize simulation diagram code. By combining several functions into a subsystem, you reduce the amount of space needed on the simulation diagram, making the simulation easier to navigate visually. Simulation subsystems also are useful for validating, distributing, and reusing portions of the simulation diagram.
You can use many Simulation VIs and functions only on a simulation diagram, such as within a Control & Simulation Loop. Because simulation subsystems modularize simulation diagram code, you can use the Simulation VIs and functions in simulation subsystems as well. The entire block diagram of a simulation subsystem is pale yellow like the inside of a Control & Simulation Loop. When you use Simulation VIs and functions in a simulation subsystem, you place the VIs and functions directly on the subsystem block diagram rather than within a Control & Simulation Loop.
|Note You cannot use local variables in a simulation subsystem.|
You can run simulation subsystems as stand-alone VIs, within a Control & Simulation Loop or another simulation subsystem, or on a block diagram outside a Control & Simulation Loop.
When you run a simulation subsystem as a stand-alone VI, you configure the simulation parameters by selecting Operate»Configure Simulation Parameters to launch the Configure Simulation Parameters dialog box. You also can configure the execution and appearance of the subsystem by selecting File»VI Properties.
When running a simulation subsystem as a stand-alone VI, you can use standard LabVIEW debugging techniques, such as execution highlighting, breakpoints, probes, and single-stepping. You cannot use these techniques on a subsystem that is within another Control & Simulation Loop. You also cannot step into the subsystem. However, you can set a breakpoint on the entire subsystem by right-clicking the subsystem and selecting Breakpoint»Set Breakpoint from the shortcut menu. You also can use a probe or a custom probe to monitor the subsystem output.
The following image shows the simulation diagram of a simulation subsystem Newton.vi, which obtains the position of a mass by using Newton's Second Law of Motion.
In the previous simulation diagram, this subsystem has front panel controls and indicators, so you can run this subsystem by clicking the Run button. Because Newton.vi does not have a Control & Simulation Loop, you configure the parameters of this subsystem by selecting Operate»Configure Simulation Parameters.
If you run a simulation subsystem inside a Control & Simulation Loop, the simulation subsystem inherits the parameters from the Control & Simulation Loop.
The following image shows Newton.vi included within the Control & Simulation Loop of another simulation diagram.
In the previous image, the parameters of the Control & Simulation Loop override any parameters you configured specifically for Newton.vi.
|Note You create this subsystem and this VI in the Getting Started with Simulation tutorial.|
If you run a simulation subsystem on a block diagram outside a Control & Simulation Loop, the simulation subsystem executes one step of the ordinary differential equation (ODE) solver each time the simulation subsystem is called. For example, if you place the simulation subsystem in a Timed Loop, one step of the ODE solver executes at each iteration of the loop. You can use only fixed step-size ODE solvers for a simulation subsystem outside a Control & Simulation Loop. Specify the time step using the Step Size (s) configuration option of the subsystem.
|Tip If you create an application with a simulation subsystem inside a Timed Loop and then deploy the application to a real-time target, set the Step Size (s) of the subsystem equal to the period of the Timed Loop.|
When you place a simulation subsystem on a block diagram outside a Control & Simulation Loop, the icon of the simulation subsystem appears in the Express style by default. You can wire values to the parameters of the simulation subsystem to configure the simulation subsystem programmatically.
|Note The Static and Dynamic icon styles are disabled for subsystems outside a Control & Simulation Loop.|
You also can configure the parameters of the simulation subsystem interactively. Double-click the simulation subsystem to launch the configuration dialog box of that simulation subsystem. In this configuration dialog box, you can configure the specific parameters of the simulation subsystem as well as the following general simulation parameters:
These parameters are identical to parameters you can configure in the Configure Simulation Parameters dialog box of a Control & Simulation Loop. In the configuration dialog box of a simulation subsystem, these parameters appear as sub-items of the Simulation Parameters item in the Parameters tree. If the simulation subsystem already contains a parameter with the same name as one of the general simulation parameters listed above, LabVIEW appends the general simulation parameter name with an underscore.
The following image shows Newton.vi on a block diagram outside a Control & Simulation Loop.
In the previous image, the Timed Loop determines when Newton.vi executes the next step of the ODE solver. Because Newton.vi is outside a Control & Simulation Loop, you can configure the simulation parameters, including the ODE solver to use, by double-clicking the simulation subsystem.
If you run a simulation subsystem outside a Control & Simulation Loop, you can reinitialize the simulation subsystem by setting the Initialize input of the simulation subsystem to TRUE. This input restarts the ODE solver from the specified Initial Time (s). The Initialize input is available for a simulation subsystem only when the subsystem is not inside a Control & Simulation Loop or another simulation subsystem.
Enabled and triggered subsystems execute only when certain conditions are met. An enabled subsystem executes when a Boolean input to the subsystem receives a TRUE value. This input enables the subsystem. A triggered subsystem executes when an input signal to the subsystem crosses 0 or an offset from 0 that you specify. You can configure the subsystem to wait for the trigger signal to cross 0 on a rising slope, a falling slope, or either. The same subsystem can be both enabled and triggered.
You also can configure the behavior of specific outputs of an enabled or triggered subsystem by specifying the values those outputs return when the subsystem does not execute. This prevents a disabled subsystem from breaking the execution of the rest of the simulation diagram or VI.
To configure enabling or triggering for a subsystem, double-click the subsystem to display the Subsystem Configuration dialog box. Select Execution Control from the Parameters list and use the options under Parameter Information to configure the basic execution behavior of the subsystem. Select individual outputs from the Parameters list to configure the behavior of those outputs when the subsystem does not execute.
If you create one or more subsystems that perform the same operation on different data types, you can package those subsystems together to create a polymorphic subsystem. A polymorphic subsystem is a single VI that points to one or more subsystems, called instances. Each instance accepts a different data type for a single input or output terminal. LabVIEW automatically selects the correct instance based on the input data type.
For example, one subsystem could operate on a double-precision floating point number, while another subsystem performs the same operation on a 16-bit integer. Instead of placing both subsystems on the simulation diagram, you can create a polymorphic subsystem that automatically chooses the correct instance.
For a polymorphic subsystem to work, each instance of the polymorphic subsystem must be a simulation subsystem. You cannot create a polymorphic subsystem with both VIs and subsystems as instances. Also, each subsystem must have an identical connector pane pattern. Additionally, the names of corresponding input parameters for each instance must be identical.