Message Boards Message Boards

0
|
7682 Views
|
9 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Propagate a parameter of a block to a higher level block in WSM?

Posted 8 years ago

Hi, My question is two-fold and relates to functionalities provided by Dymola: 1) Does WSM enable me to propagate a parameter of a block to a higher level block? 2) Does WSM provides a right click option to replace a block in a model with an existing block from a library without reconnecting it?

Cheers,

Romain

POSTED BY: Romain Pinquié
9 Replies

Thanks all for your relies. Indeed, there are numerous modelling alternatives to get the expected results, but I think the option "propagate" is a nice-to-have feature for the next release.

Cheers

POSTED BY: Romain Pinquié

Yes that that would be a really useful feature.

POSTED BY: Otto Tronarp

I like Otto 's solution of manually entering them in the text view of the father. It saves from having to create a father parameter for each son, and they are all in one place for editing and checking (my original answer assumed that you know a relationship between the sons when you make the father model and it could be expressed as an equation).

One other way is to have each son take its k value on an input connector and wire each son to a parameter that is a vector. See the enclosed model. I showed two ways of doing this. The first way is "self documenting" while the second way has fewer blocks.

The k parameters are set in the general tab of the father model as a vector in radians (but display as degrees in the son).

enter image description here

Attachments:
POSTED BY: Neil Singer

Regarding the original question, there is no convenient way of lifting a parameter to a higher level, so you do have to resort to manual work like you did:

model son
  parameter Modelica.SIunits.Angle k;
  Modelica.Blocks.Sources.Constant const(y(unit = "rad"), k(unit = "rad", displayUnit = "deg") = k) annotation(Placement(visible = true, transformation(origin = {-20, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
end son;

However, you can do deep modifications. If you double click on son in screenshot 2 and select the constant block you can set a value for k. In Modelica code that would look like this:

model father
  son son1(const.k = 5);
end father;
POSTED BY: Otto Tronarp

I also note you are using deg to rad conversion. In most cases you don't need that because if you use a block that specifies units, you can choose your unit when you enter parameters in the dialog. For example, you make your parameter extend the class of a known unit so not only is that the default unit, but in the dialog when you enter the parameter you can change the unit and systemmodeler will do an automatic conversion.

POSTED BY: Neil Singer

If you want to be able to specify the constant in degrees instead of radians (and the do the calculation in radians) a better way is to add a unit modifier to the k parameter, which you currently only can do in text mode. It would look something like this (for consistency I added a unit modifier to the output as well, note the displayUnit part will be automatically added when you change the display unit in the GUI).

model son
  Modelica.Blocks.Sources.Constant const(y(unit = "rad"), k(unit = "rad", displayUnit = "deg");
end son;
Attachments:
POSTED BY: Otto Tronarp

Romain,

Sorry, I was not clear in my short answer to you but you can do what you want. I would send a model but I will not be near my computer until later. Look at the model I posted in this thread. Note that each "son" block has a unique name. In my model I have two masses ("mass" and "mass1"). Both masses are the exact same block and each has a parameter "m". I set one mass to be always twice the mass of the other by referring to "mass.m" in the parameter field for "mass1". Before running the model I only need to set the parameter, m, for "mass" and the other ("mass1.m") is automatically determined.

Furthermore, you can add parameter (s) to your model at the top level. If you do this you can then use your new parameters in many blocks underneath it. For example, let's say I wanted to set the total mass of block "mass" and "mass1", I could create parameter "totalmass" and then define the parameter, m in mass and mass1 with two different equations in terms of totalmass and any other masses in the model.

Let me know if this is unclear and I will upload a model.

POSTED BY: Neil Singer

Thanks for your quick answers Neil. Using the <Block.parameter> does not correspond to the way I want to model. Indeed, some people do not want to or should not modify the code when blocks are pre-existing. In my screenshot 1, the block <Son> contains a block <RealConstant> with parameter <k>. As you see on my screenshot 2, this parameter <k> cannot be accessed from the <Father> block that contains an instance of the <Son> block. Imagine that this order is instantiated N times with different values for <k>, I want an easy way to access it. So far, I use the trick illustrated in the screenshot 3, I define a parameter <Kparam> for the block <Son> and set the value of <k> to <Kparam>. So, when I instantiate the <Son> N times in <Father>, I can easily input a different order value for each instance just by clicking on the <Son> block. Don't know if all this makes sense....

Attachments:
POSTED BY: Romain Pinquié
  1. yes. You refer to it as the block name, a dot, and the parameter. For example, Block2.value in your other block.

  2. Yes. right-click and select "Change Type..."

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract