Storing and choosing between sets of parameters
6 次查看(过去 30 天)
显示 更早的评论
Hello!
I've looked into the issue for over an hour now, and still can't seem to find the correct search terms relating to my (easy) problem. Here goes:
in an engine simulation, I got a model of the actual engine block as well as attached machinery (turbocharger). The engine, as well as the turbocharger, have parameters that they run on, e.g. lengths, volumes etc. In the model, actual real-life parameters are used. For example, a certain engine X has a set of parameters. Between simulations, the engine should be swappable. For example, a drop-down menu offers the choice between the engines, and thus the user can quickly pick engine Y and run the simulation with the set of parameters for engine Y. There is no need for them to be tunable during simulation. Lastly, an option should be incorporated that lets the user input arbitrary parameters into the about 10 fields. The engine and turbocharger components are not related and should be editable independently.
This is currently solved using masks. A popup occurs double-clicking, it does exactly what is described above. However, the engine parameters are hardcoded into the contained callback function; that means that it explicitly says 'Volume V_1 of engine X = 123', 'Volume V_2 of engine Y = 321' and so forth...
Ideally, I'd love to have a centralised GUI where I can edit engines (and turbines etc...) and their parameters, and add new ones, and have a great overview. I imagine something similar to the Data Dictionary, which I use for global data. Then, the engine can have a mask with a simple drop-down menu of options, fetching data from somewhere else (so that there's no data in the mask itself). Currently, in order to add a new alternative for an engine, you'd actually have to dig into the mask and add the data there. It is also fragmented, meaning that e.g. the intake manifold is a model separate to the engine itself, but its volume is of course changing (in real-life at least) by changing the engine; right now, you'd have to edit the two masks separately.
I've finally stumbled upon Variants of subsystems, but they seem to be about altering actual methods (like switching between different controllers); in my case, the calculations ought to be the same, just the very simple parameters change. That is why I'm uncertain whether Variants are the correct solution here.
With a Structure, it seems like I'd have to retype the parameter names each time? It doesn't seem to be the most elegant or robust way.
A lookup table was advised against by a more experienced user helping me (I honestly don't know what that is anyway).
So, a lot of text from a newbie. I imagine the solution is super simple..
Thanks a lot!
0 个评论
采纳的回答
Harish Vavilla
2019-3-22
编辑:Harish Vavilla
2019-4-10
Hello Alexander,
R2019a has this new feature called Instance parameters which is specifically addressing your problem where the Algorithm is same but the data can be a variant.
Lets Say our Tunable parameters for E1 and E2 engines are designated as V11, V12, v13, … V110 and V21, V22, v23, … V210.
If you have R2019a,
If the Algorithm for both the engines is same then Lets call it myEngineAlgorithm with 10 different tunable parameters(V1,V2…V10). Now go to the Model workspace of this Model using Model explorer and select the Argument Check box in the List view for these 10 parameters which makes them now as Instance specific parameters.
See the following link here if you need more information about how to make a parameter as instance specific.
Now Create a Another Model where you have two Model reference blocks(model1, model2) to the myEngineAlgorithm model we just created.
Open the block parameter dialog box for model1 and select the Instance parameters tab you can configure it to have the Values of V11 ...V110.
Repeat the same thing for model2 as well.
Using If block on a MATLAB variable ‘control’ in Base Workspace you can switch between these two Model Reference Blocks for simulating the output of different engines.
If you have an earlier version than R2019a,
As global data:
myEngineAlgorithm should take the Values of V1..V10 from Global WorkSpace (Base WorkSpace or Data Dictionary attached to the model).
Now Create a Model reference similar to what we discussed in the previous example for R2019a. You need to have an extra step to over ride the values of your Tunable parameters as a matlab(.m) script which you run before running the model.
1 个评论
Harish Vavilla
2019-4-10
For detailed documentation on how to specify different values for several instances of a model, which I believe is what the question is all about, please following the following links:
From 19a Link will be : https://www.mathworks.com/help/simulink/ug/parameterize-referenced-models.html#f4-141806
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Choose and Parameterize Blocks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!