I am using Thermal Power Library from Modelon. There is a condenser component in the Thermal Power Library which is used for the modeling of power plants.
The default heat transfer area for the wall_2 in the condenser component is 0.8*A_heat_tot, the variable of A_heat_tot is an inner variable in the condenser component, but when I try to use this variable, there is an error showing that this variable isn’t defined.
My question is that If I can use the inner variable directly. If not, how should I use it?
Short answer: You need to address the variable with its full path, i.e. wall_2.A_heat_tot.
A_heat_tot is define in StandardWall and can thus be referred to directly inside the class. However, when you are making changes to A_heat from outside the instance of StandardWall (i.e. outside wall_2) you must point to the origin of A_heat_tot since it is otherwise not known in the scope from which you are trying to use it.
Likewise, if you are making the modification in you simulation model (Preheater_Model_Validation2) you must use the full path, i.e. hex.wall_2.A_heat = hex.A_heat_tot
By the way, this has nothing to do with the inner qualifier in the Modelica language.
Related
I'm using the pedistrian library in anylogic and want to implement different target locations for different agents in the block PedGoTo. I tried to use setPos(x,y) for TargetLines and setPos(x,y,z) for rectangular areas. Both did not work and the message "Markup element is already initialized and cannot be modified. Please use constructor without arguments, perform setup and finally call initialize() function" made me try another method. I tried to use point(x,y) as a target. This works fine by defining a parameter for both X and Y and overwriting the values during the simulation. Every time a value is changed the next agent has a new target location.
But, the point(x,y) has no z or level parameter. So I assume that it is only working with targets in the same level as the agent release point. There is no way to define another level for the target by using point(x,y).
My Question is: how can I define a target dynamically during runtime in a level which is different from the agent release point level?
Thanks for any help!
I can use both blocks for getting output from simulink to matlab, but if there are two of them there should be difference in the way they are used but I can not figure it out.
Using an Outport block allows you to,
use your model as a Model Reference
when generating code (using Simulink Coder) from the model, interface the model with other code
If you're not needing to do either of the above - for instance you only want to dump data to the MATLAB Workspace - then the To Workspace block is arguably easier to use. Plus it shows the user what the resulting variable will be without them having to open the model properties window.
Note also that To Workspace can be used at any level of model hierarchy, whereas Outport can only be used to get data out of the highest level of a model. (Outport are used in SubSystems but to interface a sub-level of a model to a higher level, not to get data out of the model.)
I'm porting a large Simulink model from Simulink R2010a → R2017b.
The main model is basically a glue-layer for many interwoven reference models. My objective is to generate a standalone executable out of this main model using Coder.
Parameter tunability in this context is not done via the Signals and Parameters section on the Optimization tab in the Model Configuration Parameters dialog (as is the case in stand-alone models), but rather, via constructing Simulink.Parameter objects in the base workspace, and referencing those in the respective referenced models, or in their respective model workspaces.
Now, AFAIK, in R2010a it was enough to set
new_parameter.RTWInfo.StorageClass = 'Auto';
new_parameter.RTWInfo.CustomStorageClass = 'Define';
to make the parameter non-tunable and convert it into a #define in the generated code. In R2017b, this is no longer allowed; the StorageClass must be 'Custom' if you set a non-empty CustomStorageClass:
new_parameter.CoderInfo.StorageClass = 'Custom'; % <- can't be 'Auto'
new_parameter.CoderInfo.CustomStorageClass = 'Define';
But apparently, this does not make the parameter non-tunable:
Warning: Parameter 'OutPortSampleTime' of '[...]/Rate Transition1' is non-tunable but refers to tunable variables (Simulation_compiletimeConstant (base workspace))
I can't find anything in the R2017b documentation on making parameters non-tunable, programatically; I can only find how to do it in stand-alone models via the dialog, but that's not what I want here.
Can anyone point me in the right direction?
NOTE: Back in the day, Simulink Coder was called Real-Time Workshop (well, Real-time Workshop split into Coder and several other things), hence the difference RTWInfo vs. CoderInfo. Note that RTWInfo still works in R2017b, but issues a warning and gets converted into Coderinfo automatically.
In generated code it should appear as #define, the way you specified it.
https://www.mathworks.com/help/rtw/ug/choose-a-built-in-storage-class-for-controlling-data-representation-in-the-generated-code.html
Btw, yes, it's a bit confusing, because in m-file you specify CustomStorageClass = 'Define';, in GUI you specify Storage class as Define (custom), but in documentation they say Storage Class as Defined.
I am not sure why warning about tunability shows up.
I'm new to Matlab and SIMULINK, and I know that this might be easy. But I just can't find the answer on the internet.
I'm building a SIMULINK model (group of blocks) and I want to set the values inside the blocks as variables so I can maybe control it from an m file or something. How can I do this?
As #rayryeng has pointed out you can just type the name of a variable in place of the parameter value of blocks, and then whatever value that variable is set to in your Matlab workspace will be used.
Whenever I do this, I like to set default values of the variables in the models intialization callback function details here. That way your model is portable and will run on it's own.
In the simulink model,
In the 'Value' field of a Constant Block, enter the variable name. The constant block will then look like this: (see uplim and lowlim)
Now, whenever you wish to change the variable's value, execute the following commands through an m-file:
Let's assume the variable's name is pressure and the new value is 5.
assignin('base','pressure',5);
set_param('path of constant block','Value','pressure');
The path to a constant block (or any simulink block) looks something like this: modelname/Constant2 (considering it is the top level of your model; Constant Block number can vary)
I am currently coding a new library with several models in it (I am used to Matlab, but not to Simulink). I am able to create a model with block parameters, let's say parameter 'p', and a callback function (initfct) which uses this parameter to compute specific values used inside my model (let say a simple gain K=K(p)).
My problem is that my parameter 'p' and 'K' are available directly on the workspace, what I don't want to. Moreover, if I use twice or more this model in a system, the two models share always the same 'K', which also I don't want to.
So how I can make these variables 'p' and 'K' independent when I use my custom model several time, and to prevent these variables to be viewed in the workspace ?
Should I use "Reference models", but I am not familiar with this feature ... ?
Thanks for you answer,
Michael
Within a callback, gcb returns the path to the block which currently executes the callback. Having the path, you can use get_param to access the parameters.
Just for demonstation purposes, insert the following to the MoveFcn of a delay block:
set_param(gcb,'DelayLength',num2str(randi(10)))
It will randomly change the delay whenever the block is moved.
I am not sure if my answer explains everything you need. It might be that you also need a Mask. If you think this answer is incomplete, please update your question and include a small example model demonstrating your problem.
Thanks, with your help I was able to solve the problem.
To be more specific if someone else has the same problem : you need in your mask to declare also internal variables used by the callback function. Unchecked the relevant options so that they not appear as standard input parameters of your model.
My problem was also to use num2str instead of mat2str (when the gain was a matrix acting on multiple inputs).