The graphical display doesn't agree with the text code in Dymola - modelica

I am reading the code of the Modelica Standard Library. As to the Modelica.Media.Examples.Utilities.ShortPipe, I found that the graphical display didn't agree with the text code.
As the following screenshot shows, I am not sure why there is 1e-05 in the graphical dialogue.

That is just an bad display when looking at parameters from package-browser in that Dymola version, and it will be corrected later (the 1e-5 actually originates in converting between Pascal and bar, and not incorrectly as I first thought in the start-value in the type).
It does not occur when you have dragged in a ShortPipe component to your model (and, of course, you normally should not use that ShortPipe component since it's designed for examples in the media-library).

Related

Modelica - VoltageController and PWM on a PMSM?

I'm trying to simulate a SMPM with a VoltageController and a PWM in OpenModelica. After looking for old threads on the subject I found this one: PI-Controller doesn't reach reference value with inverter and PMSM in Modelica
Basically, that's exactly what I'm looking for. However, after copying #marco 's code and pasting it into Modelica, I have an error as seen in the attached image.
The PWM block is not displayed here. and the VoltageToDutyCycle block is missing a connection.
Can someone help me what's going on there, or even send me an executable version?
Maybe I'm doing something wrong, since I'm still a beginner at Modelica I don't want to rule that out ;)
I corrected the answer, it should work now.
Keep in mind, that this code was written with Modelica Standard Library (MSL) 3.2.3. The current version is 4.0.0. Either use the old MSL or
convert to the new version.
The missing MySignalPWM block was just the original block from the MSL. The class path is fixed now.
Regarding the connection: there is nothing missing. The third boolean input is disabled, but OpenModelica still displays it. Other Modelica tools are smarter and do not show disabled connectors. The thermal port in the center of this component should also not be visible.

How to add unit conversions using Dymola

In Modelica Standard Library, the unit of SpecificEnergy and SpecificEnthalpy is "J/kg", but I'd like to use "kJ/kg" as the display unit, my first thought is to modify the Modelica Standard Library, but I am not sure if it will cause unexpectable issues, so I want to find a way to customize my own Modelica Standard Library. In this way, I could choose to use my own version or the standard one.
My question is: Is there some way like this?
In addition to using defineUnitConversion there is another possibility for prefixed units such as "kJ/kg" or "MJ/kg": just define a variable with that displayUnit in the model by creating e.g.,
SpecificEnthalphy myEnthalpy(displayUnit="MJ/kg")=...;
and then simulating the model.
No need to specify a conversion factor in this case (it is found automatically).
There are multiple possibilities to extend the unit conversions in Dymola. Probably the best is the one for the question asked is mentioned by Hans Olsson below, but you can as well
Create a function like this:
function unitConversions "Define unit conversions, which are currently not pre-defined by Dymola"
extends DymolaModels.Icons.Basic.Function;
algorithm
defineUnitConversion("J/kg", "kJ/kg", 1e-3);
// more conversions could be added here
end unitConversions;
After the function is executed, the conversion should be available for the current session of Dymola. So you need to run the function manually every time Dymola is started. This is actually one reason I asked this question - but there seems to be no answer until now.
As an alternative, you can modify E:\[Dymola_InstallPath]\insert\displayunit.mos and add the same line. This will be usable until you install a new version of Dymola, for which you will have to do the same modification...

It there a way to suppress results display of external function in MATLAB?

I'm using some third-party package on MATLAB for data analysis. It was compiled using C#, but by default it displayed the results. I want to suppress this display, but should modify the C codes to achieve this. As I'm not familiar with C# and thus it troubles me to re-compile the modified codes, I wonder whether there is a general way to suppress the display in MATLAB as it has provided a way for each built-in function.
Edit:
#bushmills is correct. The function evalc suggested in this thread works. But it can significantly slow down the computation. Is there a better way, for example, declare warning('off',msgid) at the beginning, to suppress display in current function?
Thanks.

Simulink backwards compatibility

I implemented a (medium to big) simulink model in v2012b.
I thought it would work also in 2010bSP2, but it didn't. Some mask blocks are not opening and other strange errors.
In previous versions of simulink there was a "save as simulink 201x" model to force compatibility, but I couldn't find it anymore in 2012b.
Any clues on how to avoid rework?
Starting with 2012b, and the new interface, they have moved the option to the menu:
File / Export Model to / Previous Version
The feature never seems to fully work, and I often get warnings when first loading a model into an older version, so I would recommend giving your model a thorough check over and test. I always save again from the correct version, to clear the warnings.
The refactoring for a New Simulink Version can show up at several points.
Your own libraries: There is a feature called "Forwarding Tables" that allows you to specify where a block in the new library is (I suppose you will have to refactor your libraries as well, and probably someone else uses those libraries too)
It sounds like a biiig hack (and it is) but i found it sometimes the path of lowest resistantce... Just open your model in the Editor of your choice and replace the block paths whith the common refactoring funcitons. It is terrible i know but Simulink really lacks of refactoring functions...

Searching for a concept like 'verbosity' in Modelica

I'm struggling with the size of output files for large Modelica models. Off course, I can protect some objects in order to remove them completely from the result file. However, that gives rise to two problems:
it's not possible to redeclare protected objects
if i want to test my model in detail (eg for a short time period), i need to declare those objects publicly again in order to see their variables
I wonder if there's a trick to set the 'verbosity' of a Modelica model. Maybe what I would like is a third keyword next to public, protected, eg. transparent. Then, when setting up a simulation, I want be able to set the verbosity level to 1, or 2 with the following effect:
1--> consider all transparentelements as protected
2--> consider all transparentelements as public
This effect would propagate to all models and submodels.
I don't think this already exists. But is there an easy workaround?
Thanks,
Roel
As Michael Tiller wrote above, this is not handled the same way in all Modelica tools and there is no definite answer. To give an OpenModelica-specific answer, it's possible to use simulate(ModelName,outputFilter="regex"), to store only the variables that fully match the given regex (default is .*, matching any variable).
Roel,
I know several people wrestling with this issue. At the moment, all of this depends on the tool being used. I don't know how other tools handle filtering of results, but in Dymola you control it (as you point out) by giving the signals special qualifiers (e.g. protected).
One thing I've done in the past is to extend from a model and then add a bunch of output signals for things I'm interested in. Then you can select "Outputs" in Dymola to make sure those get in the results file. This is far from perfect because a) listing everything you want can get tedious and b) referencing protected variables is not strictly allowed (although Dymola lets you get away with it but issues a warning).
At Dassault, we are actively discussing this idea and hope to provide some better functionality along these lines. It isn't clear whether such functionality will be strictly tool specific or whether it will involve the language somehow. But if it is language related, we will (of course) work with the design group to formulate a specification that other tool vendors can support as well.
In SystemModeler, you go to the Settings tab in the Experiment Browswer in Simulation Center. Click on Output on the bottom and select which variables to store.
(The options are state variables, derivatives, algebraic variables, parameters, protected variables and if you mark the Store simulation log-option, you'll get some interesting statistics on events over time and function evaluations, opening another possibility to track down parts of the simulation and model that creates more evaluations)
I am not sure if this helps you, but in Dymola you can go to Simulation->Setup->Output and mark a checkbox saying "Store Protected variables". That way it is possible to declare most variables as protected: during normal simulation they are not stored, but when debugging your model, you just mark that checkbox and they are stored.
Of course that is not the same as your suggested keyword transparent, but maybe it helps a little...
A bit late, but in Dymola 2013 FD01 and later you can select which variables to store based on names (and model names) using the annotation __Dymola_selections, and even filter on user-defined tags - so you could create a tag name "transparent" in the model. See "Matching and variable selections" in the manual.