simulink/simscape final state 'cannot find a matching block state to element 135' output by the same model
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
jessupj
el 15 de Sept. de 2020
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 );
assignin('base','xFinal',simOUT.get('xFinal'))
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:
simOUT.xFinal.signals(135)
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 : https://www.mathworks.com/help/simulink/slref/saving-and-restoring-simulation-operating-point.html
0 comentarios
Respuesta aceptada
Paul
el 15 de Sept. de 2020
Editada: Paul
el 15 de Sept. de 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.
7 comentarios
Paul
el 17 de Sept. de 2020
I'm glad you got it working the way you want, but if you don't mind I still have some questions so I can learn from your experience.
"I was changing block values by manipulating workspace variables." What exactly do you mean by "block values?"
Are you talking about dialog parameters like Amplitude in a Sine Wave block? Or are you talking about other parameters that you can only set via set_param?
Variables in which workspace? The model workspace or the base workspace or something else?
"All blocks were set for compilation time, rather than run-time interpretation."
I'm not familiar witth this terminology. How do you change from compilation time to run-time interpretation? Are yout talking about in-lined vs tunable pararameters?
In your code snippet the variable modelworkspace isn't used?
The next line is:
assignin(gcs,'B',B)
At this point, B is not defined, perhaps it's defined earlier?
How does assignin work with gcs being the first argument? For your use case, I would have expected the first argument to be either 'base', 'caller' or a Simulink.ModelWorkspace object, none of which is returned by gcs (I don't believe). Same question for the later call to assignin. Maybe I don't understand all of the usages of assignin.
I guess you decided to not use the operating point approach. Is that because it wasn't needed or because it didn't suit your needs.
Finally, for the approach that you are using did you find anything in the doc pages that tell you what changes are and are not valid to make after the first call to sim and before the second call to sim?
Más respuestas (1)
Fangjun Jiang
el 15 de Sept. de 2020
This is frustrating! Try this, note the difference between 'Save complete SimState in final state' and 'Save Final States'
2 comentarios
Fangjun Jiang
el 16 de Sept. de 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.
Ver también
Categorías
Más información sobre Nonlinear Operators en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!