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

Posted 2 years ago
3032 Views
|
9 Replies
|
0 Total Likes
|
 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
9 Replies
Sort By:
Posted 2 years ago
 yes. You refer to it as the block name, a dot, and the parameter. For example, Block2.value in your other block. Yes. right-click and select "Change Type..."
Posted 2 years ago
 Thanks for your quick answers Neil. Using the 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 contains a block with parameter . As you see on my screenshot 2, this parameter cannot be accessed from the block that contains an instance of the block. Imagine that this order is instantiated N times with different values for , I want an easy way to access it. So far, I use the trick illustrated in the screenshot 3, I define a parameter for the block and set the value of to . So, when I instantiate the N times in , I can easily input a different order value for each instance just by clicking on the block. Don't know if all this makes sense.... Attachments:
Posted 2 years ago
 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 2 years ago
 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 2 years ago
 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 2 years ago
 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 2 years ago
 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). Attachments: