Main Content

Switch Between Different Source Components

This example shows how you can try out several variants of a component in your model by pointing the Simscape Component block to different component files.

The component files used in this example are capacitor models with different levels of fidelity, to allow exploration of the effect of losses and nonlinearity. The source files are part of your product installation, located in the following namespace folder:

matlabroot/toolbox/physmod/simscape/supporting_files/example_libraries/+Capacitors

where matlabroot is the MATLAB® root folder on your machine, as returned by entering

matlabroot

in the MATLAB Command Window. For more information about these capacitor models, see Case Study — Basic Custom Block Library.

To test capacitor models of different fidelity:

  1. To create a new model with optimal settings for physical modeling, in the MATLAB Command Window, type:

    ssc_new
  2. Open the Simscape > Utilities library and add the Simscape Component block to your model. At first, the block does not point to any component file, therefore it does not have any ports and the block icon says Unspecified.

  3. Double-click the block to open the source file selector dialog box.

  4. Click and navigate to the folder containing the capacitor component files.

  5. Select the IdealCapacitor.ssc file and click Open. The name of the source file appears in the text field of the source file selector dialog box, and the block name, description, and the link to source code appear in the Description pane.

    Note

    Because the component file resides in a namespace, the file name in the selector dialog box field is the full name, starting from the namespace root.

  6. Close the block dialog box. The block icon gets updated, based on the selected source component.

    Note

    The +Capacitors namespace folder contains image files, with the names corresponding to the Simscape™ component files, that define customized block icons. Therefore, when you point the Simscape Component block to the IdealCapacitor.ssc source file, it uses the IdealCapacitor.jpg in the same folder as the block icon. For details, see Customize the Block Icon.

  7. Build the test model and connect the blocks as shown in the following diagram.

  8. Open the scope and simulate the model.

    The Simscape Component block points to an ideal capacitor component. Simulation results show that, when the switch is flipped at t=5 seconds, the capacitor delivers 2.5 A to the load.

  9. To switch to another capacitor model, open the Simscape Component block dialog box and click Description. It displays the currently selected component.

  10. Click . The browser opens in the +Capacitors folder, because it contains the currently selected component.

  11. Select the IdealUltraCapacitor.ssc file and click Open. The name of the source file appears in the text field of the source file selector dialog box, and the block name, description, and the link to source code appear in the Description pane.

  12. Close the block dialog box. The block icon in the model diagram updates to reflect the new source component.

  13. Rerun the simulation.

    Simulation results show that, when the switch is flipped at t=5 seconds, the current delivered to the load is less than 2.5 A.

  14. To make the effect more pronounced, open the block dialog box and increase the Rate of change of C with voltage V parameter value to 0.8 F/V.

Related Examples

More About