This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Partition a Model

You can make your model real-time capable by dividing the computational cost for simulation between multiple processors via model partitioning. Computational cost is a measure of the number and complexity of tasks that a central processing unit (CPU) performs per time step during a simulation. A high computational cost can slow simulation execution speed and cause overruns when you simulate in real time on a single CPU.

Typically, you can lower computational costs enough for real-time simulation on a single processor by adjusting model fidelity and solver settings using methods described in Real-Time Model Preparation Workflow. However, it is possible that there is no combination of model complexity and solver settings that can make your model real-time capable on a single CPU on your target machine. If your real-time simulation using a single CPU does not run to completion, or if the results from the simulation are not acceptable, partition your model. You can run a partitioned model using a single, multi-core target machine or multiple, single-core target machines.

This example shows you how to partition your model into two discrete subsystems, one that contains the plant, and one that contains the controller, for parallel processing on individual real-time CPUs.

  1. Open the model. At the MATLAB® command prompt, enter

    model = 'ssc_hydraulic_actuator_digital_control';
    open_system(model)

    In addition to signal routing and monitoring blocks, the model contains these blocks:

    • Command Signal — A Signal Builder block that generates the input reference signal, r.

    • Sum — A block that compares the reference signal, r, from the Command Signal block to the output signal, y, from the Hydraulic Actuator to generate the error, x, that is r - y = x.

    • Controller — A continuous Transfer Fcn block. The Numerator coefficients and Denominator coefficients parameters for this block are specified by the variables num and den.

    • Transport Delay — A block that simulates time delay for a continuous input signal. The block is not labeled in this model. To show hidden automatic names, on the Simulink® editor menu bar, click Display and clear Hide Automatic Names.

    • Linearization I/O — A subsystem that linearizes the model about an operating point.

    • Hydraulic Actuator — A subsystem that contains the Simscape™ plant model.

  2. Examine the variables in the workspace by clicking each variable in turn.

    • The variable for sample time, ts = 0.001.

    • The Numerator coefficients parameter, num = -0.5.

    • The Denominator coefficients parameter, den = [0.001 1].

    • The variable ClosedLoop = 1.

  3. Simulate the model and open the Load Position scope to examine the results.

    sim(model)
    open_system([model, '/Load Position'])

    The output from the hydraulic actuator matches the command signal.

  4. Eliminate items that add to the computational cost but which do not affect the results of real-time simulation. In the example model, because the closed loop gain is 1, such items include the Linearization I/O points, In1, and In2 blocks. Delete the three blocks and the lines that interconnect them.

  5. Configure the model for visualization.

    1. Delete the Mux block.

    2. Delete the Goto and From blocks that are named Cmd.

    3. Connect the Load Position Scope block to the output signal from the Hydraulic Actuator.

    4. Add a second Scope block.

    5. Connect the new Scope block to the unconnected connection line from the Command Signal.

    6. Change the name of the new Scope block to Reference.

  6. Replace the Transport Delay block with a Unit Delay block.

    1. Delete the Transport Delay block and the open ended connection line that is connected to the outport of the block.

    2. Add the Unit Delay block from the Simulink Discrete library and connect it to the input port of the Hydraulic Actuator Subsystem.

    3. For the Sample time (-1 for inherited) parameter of the Unit Delay block, specify ts.

  7. Replace the Controller block with a Discrete Transfer Fcn block from the Simulink Discrete library.

    1. Delete the Controller block.

    2. Click in the model window and enter discrete transfer fcn. When the dropdown menu that contains the block appears, click Discrete Transfer Fcn.

    3. Connect the new block to the open-ended connection line from the Sum block.

    4. Connect the outport of the new block to the inport of the Unit Delay block.

    5. Specify parameters for the discrete controller using a Tustin transformation of the original, continuous transfer function.

      1. At the MATLAB command line, save new variables based on the original coefficients:

        k = num;
        alpha = den(1,1);

      2. For the Discrete Transfer Fcn block Numerator parameter, specify [k*ts k*ts].

      3. For the Denominator parameter, specify [2*alpha+ts ts-2*alpha].

      4. For the Sample time (-1 for inherited) parameter, specify ts.

  8. Provide digital sampling for continuous time measurements using Zero-Order Hold blocks.

    1. Add Zero-Order Hold blocks to both signals that are input to the Sum block.

    2. For the Sample time (-1 for inherited) parameter of both Zero-Order Hold blocks, specify ts.

  9. Connect the blocks as shown in the figure.

  10. Simulate the model and open the Load Position scope to see how the modifications affect the results.

    sim(model)
    open_system([model, '/Load Position'])

    The output from the hydraulic actuator matches the original results.

  11. Configure the solvers.

    1. To configure the global solver, open the model configuration parameters, and in the Solver pane:

      • Set the solver Type to Fixed-step.

      • Set the Solver to discrete (no continuous states).

      • Specify ts for the Fixed-step size (fundamental sample time) parameter.

      • Click OK.

    2. To configure the local solver, open the Hydraulic Actuator subsystem and update these parameters for the Solver Configuration block:

      • Select the option to Use local solver.

      • Specify ts for the Sample time.

      • Select the option to Use fixed-cost runtime consistency iterations.

      • Click OK.

  12. Partition the model into two subsystems:

    1. Create a subsystem that contains these blocks:

      • Command Signal

      • Reference

      • Zero-Order Hold

      • Sum

      • Discrete Transfer Fcn

      • Unit Delay

    2. Label the subsystem Controller Subsystem.

    3. Open the Controller Subsystem.

    4. Rename the Out1 Outport block as u.

    5. Rename the In1 Inport block as y.

    6. Navigate to the top model.

    7. Create a second subsystem that contains these blocks:

      • Hydraulic Actuator

      • Zero-Order Hold1

      • Load Position

    8. Label the subsystem Plant Subsystem.

    9. Open the Plant Subsystem.

    10. Rename the Out1 Outport block as u_plant.

    11. Rename the In1 Inport block as y_plant.

    12. To see the partitioned subsystems, navigate to the top model.

    This model is partitioned for concurrent execution. To learn how to add tasks, and map individual tasks to partitions, see Partition Your Model Using Explicit Partitioning (Simulink).

See Also

| |

Related Examples

More About

External Websites