Main Content

Reuse Compilation Artifacts of Individual Simscape Blocks

If your model contains multiple instances of the same Simscape™ block, you can use the simscape.reuse.setConfig function to make all or some of these instances reusable.

When you enable scalable compilation for a model, all referenced subsystems or linked subsystems included in the model are by default treated by the compiler as reusable components. You can selectively disable scalable compilation of these subsystems, as described in Determine Optimal Complexity Level for Reusable Components.

In contrast, with library and custom Simscape blocks, you must enable them for scalable compilation individually. Most library blocks do not have enough complexity for a model to benefit from reusing their artifacts in scalable compilation. Use sscScalableAdvisor to see whether enabling scalable compilation for particular blocks reduces the overall compilation time.

To enable scalable compilation for a specific block within a model, type :

simscape.reuse.setConfig(blockPath,'on')

where blockPath is the path to a block from the root of the model.

This setting affects only the specified instance of the block. To enable scalable compilation for all instances of a particular block in the model, use the find_system function in conjunction with simscape.scalable.setBlockConfig, for example:

load_system('ssc_fluid_vaporization_in_pipe')
all_pipes = find_system('ssc_fluid_vaporization_in_pipe','MaskType','Pipe (2P)')
all_pipes =

  5×1 cell array

    {'ssc_fluid_vaporization_in_pipe/Pipe Segment 1/Pipe (2P)'}
    {'ssc_fluid_vaporization_in_pipe/Pipe Segment 2/Pipe (2P)'}
    {'ssc_fluid_vaporization_in_pipe/Pipe Segment 3/Pipe (2P)'}
    {'ssc_fluid_vaporization_in_pipe/Pipe Segment 4/Pipe (2P)'}
    {'ssc_fluid_vaporization_in_pipe/Pipe Segment 5/Pipe (2P)'}
for i=1:length(all_pipes)
simscape.reuse.setConfig(all_pipes{i},'on')
end 

This series of commands enables scalable compilation for all the Pipe (2P) blocks in the model.

To restore the default setting, type:

simscape.reuse.setConfig(blockPath,'off')

To query the block setting, type:

setting = simscape.reuse.getConfig(blockPath)

This block parameter setting takes effect only if component reuse during compilation is enabled for the whole model. Then, the compiler tries to reuse compilation artifacts of individual blocks with the on setting, but does not consider blocks with the off setting reusable.

The Components field in the Advisory tool report provides the reuse statistics. For example:

r = sscScalableAdvisor('ssc_fluid_vaporization_in_pipe')
r = 

ScalableReport for model 'ssc_fluid_vaporization_in_pipe'

          TotalModelCompilationTime: 9.9268
            SimscapeCompilationTime: 8.6089
                         PeakMemory: '29 MB'

    ScalableSimscapeCompilationTime: 9.0798
                 ScalablePeakMemory: '17 MB'

                         Subsystems: [0×4 table]
                         Components: [1×4 table]
r.Components
ans =

  1×4 table

                                                Total Instances    Compiled Instances    Reuse       Details  
                                                _______________    __________________    ______    ___________

    foundation.two_phase_fluid.elements.pipe           5                   1             "100%"    {1×5 table}

Related Topics