I developed a block which behaves incorrectly if the user chooses a fixed-step solver.
Is it possible for the block to check which solver is being used, and notify the user if a fixed-step solver is being used?
I developed a block which behaves incorrectly if the user chooses a fixed-step solver.
Is it possible for the block to check which solver is being used, and notify the user if a fixed-step solver is being used?
Copyright © 2021 Jogjafile Inc.
Short version
This is definitely possible! You can use the callback-function
StartFcn
in the model properties (or in the block itself). This function is being executed each time the model is being simulated. Then add a check for the solver-type that throws an error if it is set toFixed-step
.Here is the code to add:
This throws the following error in the Diagnostic Viewer when your model's name is
test
:Detailed explanation of the code
We get the name of the top-level Simulink system by executing
bdroot
. This system name is then used for the call to get the solver-type withget_param(bdroot,'SolverType')
. Then we usestrcmp
to compare the returned string with'Fixed-step'
. If the current solver is fixed-step thenstrcmp
returns1
, so we enter the if-statement and throw the error with theerror
-function.Add it to a block
To add the callback-function to a block, right-click the block, then on Properties as shown in the screenshot below:
And then go to Callbacks -> StartFcn and paste the code:
Add it to a model
To add the callback-function to the model click on Model Properties as shown in the screenshot below:
And then go to Callbacks -> StartFcn and paste the code:
That's it. I hope it helps...