How can I more closely control which blocks are replaced when using Simulink Design Verifier?

5 views (last 30 days)
I have a custom library block which is essentially a masked 'SubSystem' block with some incompatible MATLAB Function blocks inside. I was looking into how to perform 'Block Replacement' to enable Simulink Design Verifier test case generation for a model containing this incompatible library block.
The documentation suggests that the only way we can filter the blocks for replacement is using the 'Block Type' as shown in the 'Block Replacement for Unsupported Blocks' example:
The line in question is:
rule.blockType = 'Sqrt';
If I set this to 'SubSystem', would that not replace every block of type 'SubSystem' in my model? How can I be more specific to avoid replacing the wrong blocks?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Aug 2020
This can be achieved by leveraging the 'replacementTestFunction' as seen in this part of the same example:
This function provides a great deal of control over which blocks are selected or ignored when using the block replacement workflow. The line:
rule.blockType = 'Sqrt';
determines which blocks are passed to the 'replacementTestFunction'. In this example, the 'Sqrt' blocks are passed in on the line:
rule.isReplaceableCallBack = @replacementTestFunction;
In order to demonstrate the flexibility, let us modify the model associated with the example to have a second 'Sqrt' block: 
Since the goal is to replace only the block called 'Replace Me', modify the 'replacementTestFunction' inside the 'sldvdemo_custom_blkrep_rule_sqrt.m' script:
function out = replacementTestFunction(blockH)
out = false;
acceptedOutDataTypeStr = {'double','single',...
'Inherit: Inherit via back propagation',...
'Inherit: Same as first input'};
outDataTypeStr = get_param(blockH,'OutDataTypeStr');
I = strncmp(outDataTypeStr,acceptedOutDataTypeStr,length(outDataTypeStr));
if ~isempty(I)
portDataTypes = get_param(blockH,'CompiledPortDataTypes');
out = any(strcmp(portDataTypes.Inport,{'double','single'})) && ...
strcmp(portDataTypes.Inport,portDataTypes.Outport) && ...
strcmp(get_param(blockH, 'Name'), 'Replace Me');
end
end
 
Note the line 'strcmp(get_param(blockH, 'Name'), 'Replace Me')'. This targets, specifically the 'Sqrt' block called 'Replace Me' and ignores the other.
When running the rest of that demo, it produces a warning from Simulink Design Verifier stating that the specified model is 'Partially Compatible' with Simulink Design Verifier. This is expected as one of two 'Sqrt' blocks have been eliminated. The one named 'Replace Me' has been removed while the other 'Sqrt' is still in the model and not compatible with Simulink Design Verifier.
The report under 'Block Replacements' shows:
which indicated that the customized rule has replaced only the 'Replace Me' block as opposed to both 'Sqrt' blocks.
This workflow can be easily expanded. Modifying the 'replacementTestFunction' enables the specification of any:
  • Arbitrary condition
  • Combinations of conditions 
These conditions allow for specific subsets of blocks to be replaced without touching others, even if the blocks are of the same type.  

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!