Libraries, model workspace, base workspace and how to parameterize my models

8 views (last 30 days)
Hello everybody,
I am building a library (with sublibraries) of models that will eventually be used as parts in simulations of industrial equipment.
Although it is not exactly this way, let us consider this hierarchy:
* Motors/
* -- Diesel_A31
* -- Diesel_A32
* Powertrains/
* -- PT03
* -- PT10
Now the question is that every model should be able to run independently, but all the models make use of constants such as for example:
  • Gravity (both for motors and powertrains)
  • Themodynamical properties from air in normal conditions (only for motors, nor for Powertrains)
and parameters, like:
  • Air temperature (both for motors and powertrains the same), would be a "whole simulation" parameter
  • Horsepower (only for motors, for every motor potentially different, for every instance of the model the same)
  • Initial position of the cilinder (only for motors, for every instance different)
Now the question is how do I manage and store all this information in the library and the models that reside inside each library or sub-library.
  • Global workspace? Please no
  • Model workspace? It looks like my models haven't got a model workspace, maybe since they are in a library
  • Mask parameters? I would rather be able to write them down in a text file where I could explain the meaning of each parameter. The number of parameters is too high anyway. I think that the initial position of the cilinder could be a mask parameter.
And would it be possible to make the parameters accesible to the model without the user actually intervining? I try to keep in mind that the model should be able to work independently without the user having to look under the mask or perform any action.
Even though the problem is not very clear either to me, I hope I was able to state the question clearly.
Any help or experience in this regard would be greatly appreciated.

Accepted Answer

Jarrod Rivituso
Jarrod Rivituso on 6 May 2011
Hi Carlos,
Is there any specific reason you have decided on using libraries for this? It sounds like you'd have a much easier time using model references.
With model references, each component (Diesel_A31, Diesel_A32, PT03, etc.) would be it's own separate model. This means each component would
  • Have its own Model Workspace where you could store local data
  • Be capable of running as a standalone simulation
If you use subsystems stored in libraries for these components, then the only local workspace those subsystems have for parameters is the Mask Workspace.
What's very nice about the Model Workspace over the Mask Workspace is that you can define either a MAT-file or a MATLAB script as the data source for the Model Workspace. So, you could write all your parameters for a given component in a MATLAB script and then tell the Model Workspace to use that MATLAB script as its data source.
Does that make sense?

More Answers (2)

Kaustubha Govind
Kaustubha Govind on 9 May 2011
I am partial to the Mask Parameters option, because it doesn't pollute the Model Workspace and allowing the blocks to run independently. Why not simply return all the parameters from a shared MATLAB function, and run that function in the Mask Initialization? I guess the downside is that each block will have its own copy of the data, but I also think of it as an advantage, because the block has complete control over its data.
Alternatively, you could assign the parameter values directly in the Model Workspace from the block mask (you could check if the variable already exists before attempting to define a parameter) - but this is roundabout and not transparent to the user, since most people tend not to examine the model workspace and could potentially define conflicting parameters in the base workspace (which are always overrided by the model workspace variables, causing confusion).

Carlos Martinez
Carlos Martinez on 10 May 2011
Model references turned up to be juts fine for the moment: I can keep the configuration from every model in its own workspace through the automatically loaded "m-file" and the only problem I ran into was with algebraic loops that encompassed several models (I think that was it..).
For the moment I only cannot find how all the code inside the models (Level2 S-files and Embedded Matlab) can share the access to some constants:
  • Simulation-dependant: external temperature
  • Really constant: normal gas conditions (temperature, pressure, gas constant)
I am going to try to use this idea of structure parameters. Wish me luck!
  1 Comment
Jarrod Rivituso
Jarrod Rivituso on 20 May 2011
For the "really constant" stuff, I would use parameters in the base workspace (it is, after all, a workspace that can be accessed by all models).
For the external temperature - if it really does vary a lot during the simulation then I would consider adding it as an input signal to the models that require it.
Hope this helps!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!