simulink/simscape final state 'cannot find a matching block state to element 135' output by the same model

5 views (last 30 days)
I have a model that contains some simulink and simcape model.
The gist is: initail simulation from T0 to T1, perfrom some analysis, then restart at T1 and run to T2, etc. But this breaks when restarting T1. Kindly note: This intermediate analysis affects workspace parameters that affect values of e.g. electrical resistances in the model.
cset = getConfigSet( gcs, 'Configuration1' );
set_param(cset, 'Solver','VariableStepAuto')
set_param(cset, 'SolverName','VariableStepAuto')
set_param(cset, 'LoadInitialState','off');
set_param(cset, 'StateSaveName', 'state_history');
set_param(cset, 'SaveFinalState','on')
set_param(cset, 'FinalStateName','xFinal')
set_param(cset,'StartTime', string(T0) );
set_param(cset,'StopTime', string(T1) );
simOUT = sim( gcs, cset );
set_param(cset, 'LoadInitialState','on')
set_param(cset,'InitialState', 'xFinal')
set_param(cset,'StartTime', string(T1) );
set_param(cset,'StopTime', string(T2) );
simOUT = sim( gcs, cset );
The first run is fine. everything looks fine. The second model call yields:
Unable to load the specified initial state for model 'your_model'. Cannot find a matching block state
corresponding to element 135 of signals structure array.
Nothing has changed in the model, and the error sound like as if a block has simply vanished.
This is field is present in the first run's output:
ans =
struct with fields:
values: 16.6848539456316
dimensions: 1
label: 'CSTATE'
blockName: 'your_model/comp1/C'
stateName: 'your_model.comp1.C.p.v'
inReferencedModel: 0
and is the exact same thing stored in 'xFinal' that's parsed to the model workspace and pushed as an initial state.
I'm wondering if restarting models with simscape elements need further considerations than those shown in :

Accepted Answer

Paul on 15 Sep 2020
Edited: Paul on 15 Sep 2020
Are you trying to use operatining points? If you are:
Comparing your code to the examples in that link to the doc two things stand out ....
In your first call to sim do you need 'SaveOperatingPoint', 'on' ?
In your second call to sim, should you be setting the initial time to T1? The doc explicitly says:
"The start time value must remain 0.0 (that value was the start time of the original simulation). The software stores the original simulation start time in xFinal. This value must match the start time of the current simulation to enable restoration of the simulation state." So in your case maybe you should set the start time to T0 in the second call to sim.
I also came across this tip: Before you save the operating point, disable the Block Reduction parameter in Configuration Settings > Simulation Target > Advanced Parameters.
jessupj on 17 Sep 2020
Edited: jessupj on 17 Sep 2020
gcs isn't defined either, unless the model has been opened. what i've provided is a relevant snippet of ~400lines of code plus calls to subfunctions rather than the actual code which is, naturally, messy.
surely i meant 'assign(modelworkspace,...' in those lines
block values, i mean thinks like the capacitance of a capacitor, or the resistance of a resistor. amplitude of a sine wave block i guess is similar.
as far as 'compilation time interpretation' vs 'run-time interpretation' of parameters. the simscape blocks (and maybe it's true of simulink in general --. all our stuff is electrical analogs of fluids so we're using simulink) have a setting depicted in is image:
i'm sure there is a better word
i didn't try to too hard (yet) to get a model operating point method set, although i think jiang's advice was leading that way also. i only tried it once, and taht was when i got the error that the model had been changed -- since the values changed were set to compilation-time interpretation -- and the error suggtested i rerun the spin-up (or whatever you call the t=0 to t=operating point simulation) to resolve the problem

Sign in to comment.

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 15 Sep 2020
This is frustrating! Try this, note the difference between 'Save complete SimState in final state' and 'Save Final States'
Fangjun Jiang
Fangjun Jiang on 16 Sep 2020
Maybe you should consider a different approach. Use set_param(Model,'SimulationCommand','Pause') to pause the simulation, change parameters, update model and then continue the simulation. The pause can be triggered by a callback function of a block in the model, which compares the clock with T1.

Sign in to comment.


Find more on Foundation and Custom Domains in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!