Define Model Parameter as Variable

十年热恋 提交于 2019-12-13 01:08:22

问题


I am attempting to define the parameter of a model (block) as a variable. For example:

Real WallThickness = 0.5;
Real WallConductance = 10*WallThickness;
Modelica.Thermal.HeatTransfer.Components.ThermalConductor TopPanelConductor(G=WallConductance);

I would like to define "G" so that it remains constant throughout the simulation but the coefficient is updated prior to the simulation based on the other variable "WallThickness". When defining the ThermalConductor parameter "G" as a variable in the model, which is being calculated elsewhere, I get the error message:

The variability of the definition equation:
TopPanelConductor.G = WallConductance;
is higher than the declared variability of the variables.

I would like to define the parameters of a model as a variable. This allows me to create parametric definitions as the geometry of the all changes. Is there a way I can make this definition work?


回答1:


You mean the geometry changes during simulation? If so, you'll have to rewrite the ThermalConductor model to work with a variable G, because a variable cannot be assigned to a parameter. A variable may vary during the course of simulation. A parameter is fixed at the start of simulation, but can be changed from run to run without recompiling the model, which allows for quicker iteration/design work.

Note that you can also calculate a parameter from other parameters that you define, e.g. to calculate a heat transfer coefficient from a given wall thickness (which you vary from simulation run to simulation run).




回答2:


An alternative to re-writing the component models is to make the parameter study/variation outside the simulation model. There are at least three approaches:

  1. Export your system model as an FMU (Co-simulation). Import it in Python w. PyFmi and write for loops that vary the parameter value for each iteration. See for example http://www.jmodelica.org/assimulo_home/pyfmi_1.0/pyfmi.examples.html. This is not as complicated as it might sound.
  2. Make the parameter variation loop in a Modelica Script (mos file). I don't have much experience with this though.
  3. If you are varying geometrical parameters in order to find an optimum of some kind you can use the Optimization Library which is shipped with Dymola (as of version 2017 FD01).

Using one of the above suggestions you can reuse all the components from MSL out of the box.

Best regards, Rene Just Nielsen




回答3:


There is a heirachery for varaibales/parameters that restrict their use. As you are now aware, parameters are not permitted to vary with within the simulations. Thus, you get the error stating that you are trying to define a parameter with a variable value or input variable.

If you need that functionality I would recommend duplicating the ThermalConductor and change the variable type:

parameter Modelica.SIunits.ThermalConductance G
    "Constant thermal conductance of material";

to

input  Modelica.SIunits.ThermalConductance G
"Constant thermal conductance of material" annotation (Dialog(group=”Input Variables”));

That all there is to it. Note the additional annotation on the input variable. By default inputs do not show up in the parameter GUI. The annotation will permit them to be seen just like parameters (be careful to clearly label it an input variable versus a parameter though!)

There is work underway that has completely redone the Thermal library but is not yet released and the most-straightforward approach would probably try what I have discussed.



来源:https://stackoverflow.com/questions/43128203/define-model-parameter-as-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!