From the Modelica documentation, it seems annotation Evaluate only has an effect on parameters:
https://build.openmodelica.org/Documentation/ModelicaReference.Annotations.Evaluate.html
Using the Dymola variable editor, I can conveniently set the annotation on any variable/instance, see screenshot below. Does this have any effect or is the annotation just ignored?
If applied to the instance of a class, will the parameters in that class be evaluated, to the value set by the modifier (in the example screenshot, e.g. parameter yMax)?
The parameters of the class will be evaluated, https://specification.modelica.org/master/annotations.html#modelica:Evaluate
This was added in Modelica 3.5 (and supported earlier in Dymola with some minor differences that don't appear if you only use Evaluate=true - see https://github.com/modelica/ModelicaSpecification/pull/2771 for details).
Related
All parameters are always exported as "tunable" by FMUexport from Dymola. In many places this cannot be changed to "fixed" at all, because (sub)components from libraries are locked against it. So our next tool tries to use degrees of freedom which do not exist. Is it possible to reverse the behaviour so that all parameters are initially set as "fixed"? Or is it possible to set all parameters to "fixed" at once, even those in library blocks?
Two flags in Dymola come to my mind that could have an effect:
Evaluate = true
Advanced.EvaluateAlsoTop = true;
Both can be set via the GUI:
They do have influence on the definition of the variable in the FMU's XML file. They change "causality" and "variability". Though I'm not sure they do exactly what you want.
Likely it would make sense to set only Evaluate = true and propagate all the parameters that shall be "tunable" to the top level...
In dymola, when I simulated a model, I got an error showing that the parameter for some function is wrong, and the log showed the function calling stack, so I changed to the "used classes" view to show all the code used, but I didn't find any usage of the function showed in the error message.
My question is that how should I find the usage of this function in my model?
For tph1 it is likely that the problem is that it is called indirectly, and called functions are as default not included in the "Used Classes", but that can be changed in the context menu of used classes (i.e. right-click):
(Note that the names in the dialog vary slightly depending on Dymola version.)
The function with a name ending in _der is likely an automatically generated derivative-function - based on the name before _der. (Using automatic/algorithmic differentiation.)
But using dsmodel.mof is also a possibility.
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.
First of all, matlab version is 2011b, so I cannot use Simulink.MaskParameters class.
I have one simulink mask and some parameters inside. I need to determine in my function for each parameter if it is "evaluable" or "tunable".
Those two things are two checkboxes in the mask parameters dialog which you can select for any parameter.
For "tunable", there's the MaskTunableValues property. For "enable", there's the "MaskEnables" property.
Do you know if there's a way to programmatically access the same property but for "evaluate" ?
Thanks
#Phil Goddard's answer shows you how to find the parameter. To complete the answer, the actual parameter is MaskVariables. Evaluate flag is embedded into the MaskVariables string. It is not straightforward to modify this. For example for two parameters MaskVariables string contains something like this:
"a=#1;b=&2;"
In this string the # sign indicates evaluation. Based on that, parameter a is evaluated and parameter b is not. If you want to change the evaluate flag, you need to set this string for MaskVariables parameter exactly how it was except for # or & signs.
For more information see R2011b documentation for mask parameters at https://www.mathworks.com/help/releases/R2011b/toolbox/simulink/slref/f23-18517.html. Towards the bottom of the page there is more detail about MaskVariables parameter.
You're using too old a release for most people to be able to give you an exact solution, however, I'm sure (from memory) that this parameter is available.
If you click on the mask to select the block, then go to the MATLAB command line and type
get_param(gcb,'ObjectParameters')
you'll get a list of all the block properties. (You may already know that since you're aware of MaskTunableValues and MaskEnables.) Near the bottom of that list are all of the properties related to the mask.
Now manually look at each/all of those properties, e.g.
get_param(gcb,'MaskTunableValues')
and you'll find that one of them is a structure that contains the information that you're looking for. (You may need to dig down into the structure to find the specific info.)
Answer for versions > 2011b (tested on 2014b):
Ok found it, actually the matlab documentation is REALLY unclear regarding the Simulink.MaskParameter class and here is how it works:
First, get the Mask class from your block:
mask = Simulink.Mask.get(gcb)
The Mask class is a structure containing all mask parameters:
parameters = mask.Parameters(:)
parameters is a (array of) Simulink.MaskParameter object which will contains all the necessary properties, including Evaluate.
I am using some components from the Modelica Standard Library (MSL) in my simulations. These components each have some parameters. For example, Modelica.Fluid.Sources.MassFlowSource_T has a parameter m_flow. Usually, parameters can be changed between simulation runs without re-compilation. This is not the case for m_flow, because it has an annotation(Evaluate=true), so it is used for symbolic processing.
Is it possible to change the annotations of parameters at instantiation? I tried the following, but it didn't work.
Modelica.Fluid.Sources.MassFlowSource_T source2(
redeclare package Medium = Medium2,
nPorts=1,
m_flow=22.17 annotation(Evaluate=false));
Of course there are workarounds, like making a copy first and changing the annotation there or using use_m_flow_in=true and a constant source block.
As far as I know this is not possible with current Modelica Specification.
Some tools might support it if you extend MassFlowSource_T:
model MassFlowSource_T_2
extends Modelica.Fluid.Sources.MassFlowSource_T;
// declare m_flow here again with annotation(Evaluate=false);
end MassFlowSource_T_2;
use MassFlowSource_T_2 when you declare source2.
There is some work in progress to extend the way annotations are specified/handled
but it will be a while until it makes it into the Modelica Specification:
https://trac.modelica.org/Modelica/ticket/1293 (not open to the public yet).