Me and @Neil Singer had an interesting discussion regarding the best practices on how to collect different parameter values together in SystemModeler.
This can be useful in many different cases, for example: Your smart phone battery for example might have different performance characteristics than that of another model. So if you were to create a model of the battery discharge of your phone during the day, you could specify different parameter values from different battery manufacturers and compare different scenarios to each other.
So we have different parameters values that belong together and want to use theses in a model. We can of course go in and change each individual place were those parameters are used, but if you want to scale this up, that can become cumbersome.
Lets use a very simple example to illustrate this: a mass attached to a spring with a force that pushes on the mass. This model and everything I describe here is attached to this post so you can try it out for yourself.
Now, say we have different parameters sets containing values for the magnitude of the force, the mass of the mass and the spring constant. In Modelica, we can collect all these parameter values into a record.
I created a record called Set1.
Now this record can be added to the model by dragging and dropping it into the diagram view. Note that records will not show up in the diagram view by default, but you can drag it into the diagram view from the Component Browser (to the right in Model Center).
All the parameter values now be taken directly from the record (as indicated by the parameter labels in the diagram above). You can now easily switch between different records, either from the text view, or by right clicking the record component and choosing Change Type. Change the type to the record of your choice, containing the parameter set you want to use.
Tip: You can drag and drop a record from the Class Browser into the text field of this dialog.
Another way to change the record is to declare it as a parameter. Either use the text view and preface the component declaration with the keyword parameter or right click the component (from the diagram view or the component browser) and choose Properties. Now you can set it to a parameter in the Attributes section:
The record can now be specified in the General tab of Model Center. You need to use brackets at the end round brackets at the end of the declaration and the new record must be type compatible to the one which was initially declared.
What is nice about having it as a parameter is that you can set different choices that can be used. This information is put in the annotation for the component declaration, for example:
annotation(choices(choice = ParameterSets.Records.Set1() "Set 1", choice = ParameterSets.Records.Set2() "Set 2", choice = ParameterSets.Records.Set2Alt() "Set 2 alternative"))
Now these choices can be selected from a drop down menu:
With that, you can have a drop-down menu to choose different engine models for your car (now if only it was as easy in real life to get a Ferrari engine....)
This of course only changes the parameter values. If you want to change the whole structure of the model, you can do that to but it is outside of the scope of this discussion. If anyone in interested, I would recommend checking out the Golf and Soccer downloadable model where that functionality is used.
Tip: in SystemModeler 4.3, our web examples are available directly in product, the Golf and Soccer model can be found in the class browser, under EducationalExamples > Physics.
Attachments: