OpenModelica Users Guide Version 2012-03-29


Chapter 6 Model Import and Export with FMI 1.0



Download 0.95 Mb.
Page15/23
Date28.01.2017
Size0.95 Mb.
#9043
1   ...   11   12   13   14   15   16   17   18   ...   23

Chapter 6

Model Import and Export with FMI 1.0


The new standard for model exchange with Functional Mockup Interface (FMI) 1.0 allows export of pre-compiled models, i.e., C-code or binary code, from a tool for import in another tool, and vice versa. The FMI model exchange standard is Modelica independent. Import and export works both between different Modelica tools, or between certain non-Modelica tools and Modelica tools. OpenModelica supports FMI 1.0 import as well as FMI 1.0 export.

6.1FMI Import


To import the FMU package use the OpenModelica command importFMU(“fmufile”, “outputdirectory”) from command line interface, OMShell, OMNotebook or MDT. The importFMU command is also integrated with OMEdit. Select FMI > Import FMI the FMU package is extracted in the directory specified by outputdirectory, since the outputdirectory parameter is optional so if its not specified then the current directory of omc is used. You can use the cd() command to see the current location.

The FMI Import is currently a prototype. It was implemented on the Windows 7 x64 platform under the MinGW environment. The prototype has been tested in OpenModelica 1.8.1 (revision-10129) with several examples. A more fullfleged version for FMI Import will be released in the near future. The present version can be used as a stand-alone FMU import for Modelica simulators.




Figure 6 50: Example of FMU Import in OpenModelica where a bouncing ball model is imported.

6.2FMI Export


To export the FMU use the OpenModelica command translateModelFMU(ModelName) from command line interface, OMShell, OMNotebook or MDT. The export FMU command is also integrated with OMEdit. Select FMI > Export FMI the FMU package is generated in the current directory of omc. You can use the cd() command to see the current location.

After the command execution is complete you will see that a file ModelName.fmu has been created. As depicted in Figure 6-2, we first changed the current directory to C:/OpenModelica1.7.0/bin , then we loaded a Modelica file with BouncingBall example model and finally created an FMU for it using the translateModelFMU call.





Figure 6 51: OMShell screenshot for creating an FMU

A log file for FMU creation is also generated named ModelName_FMU.log. If there are some errors while creating FMU they will be shown in the command line window and logged in this log file as well.



Chapter 7

OMOptim – Optimization with OpenModelica

7.1Introduction


OMOptim is a tool dedicated to optimization of Modelica models. By optimization, one should understand a procedure which minimizes/maximizes one or more objectives by adjusting one or more parameters.

OMOptim 0.9 contains meta-heuristic optimization algorithms which allow optimizing all sorts of models with following functionalities:



  • One or several objectives optimized simultaneously

  • One or several parameters (integer or real variables)

However, the user must be aware of the large number of simulations an optimization might require.

7.2Preparing the Model


Before launching OMOptim, one must prepare the model in order to optimize it.

7.2.1Parameters


An optimization parameter is picked up from all model variables. The choice of parameters can be done using the OMOptim interface.

For all intended parameters, please note that:



  • The corresponding variable is constant during all simulations. The OMOptim optimization in version 0.9 only concerns static parameters’ optimization i.e. values found for these parameters will be constant during all simulation time.

  • The corresponding variable should play an input role in the model i.e. its modification influences model simulation results.

7.2.2Constraints


If some constraints should be respected during optimization, they must be defined in the Modelica model itself.

For instance, if mechanical stress must be less than 5 N.m-2, one should write in the model:

assert( mechanicalStress < 5, “Mechanical stress too high”);

If during simulation, the variable mechanicalStress exceeds 5 N.m-2, the simulation will stop and be considered as a failure.


7.2.3Objectives


As parameters, objectives are picked up from model variables. Objectives’ values are considered by the optimizer at the final time.

7.3Set problem in OMOptim

7.3.1Launch OMOptim


OMOptim can be launched using the executable placed in OpenModelicaInstallationDirectory/bin/ OMOptim/OMOptim.exe. Alternately, choose OpenModelica > OMOptim from the start menu.

7.3.2Create a new project


To create a new project, click on menu File -> New project

Then set a name to the project and save it in a dedicated folder. The created file created has a .min extension. It will contain information regarding model, problems, and results loaded.


7.3.3Load models


First, you need to load the model(s) you want to optimize. To do so, click on Add .mo button on main window or select menu Model -> Load Mo file…

When selecting a model, the file will be loaded in OpenModelica which runs in the background.

While OpenModelica is loading the model, you could have a frozen interface. This is due to multi-threading limitation but the delay should be short (few seconds).

You can load as many models as you want.

If an error occurs (indicated in log window), this might be because:


  • Dependencies have not been loaded before (e.g. modelica library)

  • Model use syntax incompatible with OpenModelica.

7.3.3.1Dependencies


OMOptim should detect dependencies and load corresponding files. However, it some errors occur, please load by yourself dependencies. You can also load Modelica library using Model->Load Modelica library.

When the model correctly loaded, you should see a window similar to Figure 7 -52.



Figure 7 52. OMOptim window after having loaded model.


7.3.4Create a new optimization problem


Problem->Add Problem->Optimization

A dialog should appear. Select the model you want to optimize. Only Model can be selected (no Package, Component, Block…).

A new form will be displayed. This form has two tabs. One is called Variables, the other is called Optimization.
Figure 7 53. Forms for defining a new optimization problem.

7.3.4.1List of Variables is Empty


If variables are not displayed, right click on model name in model hierarchy, and select Read variables.


Figure 7 54. Selecting read variables, set parameters, and selecting simulator.

7.3.5Select Optimized Variables


To set optimization, we first have to define the variables the optimizer will consider as free i.e. those that it should find best values of. To do this, select in the left list, the variables concerned. Then, add them to Optimized variables by clicking on corresponding button ().

For each variable, you must set minimum and maximum values it can take. This can be done in the Optimized variables table.


7.3.6Select objectives


Objectives correspond to the final values of chosen variables. To select these last, select in left list variables concerned and click button of Optimization objectives table.

For each objective, you must:



  • Set minimum and maximum values it can take. If a configuration does not respect these values, this configuration won’t be considered. You also can set minimum and maximum equals to “-“ : it will then

  • Define whether objective should be minimized or maximized.

This can be done in the Optimized variables table.

7.3.7Select and configure algorithm


After having selected variables and objectives, you should now select and configure optimization algorithm. To do this, click on Optimization tab.

Here, you can select optimization algorithm you want to use. In version 0.9, OMOptim offers three different genetic algorithms. Let’s for example choose SPEA2Adapt which is an auto-adaptative genetic algorithm.



By clicking on parameters… button, a dialog is opened allowing defining parameters. These are:

  • Population size: this is the number of configurations kept after a generation. If it is set to 50, your final result can’t contain more than 50 different points.

  • Off spring rate: this is the number of children per adult obtained after combination process. If it is set to 3, each generation will contain 150 individual (considering population size is 50).

  • Max generations: this number defines the number of generations after which optimization should stop. In our case, each generation corresponds to 150 simulations. Note that you can still stop optimization while it is running by clicking on stop button (which will appear once optimization is launched). Therefore, you can set a really high number and still stop optimization when you want without losing results obtained until there.

  • Save frequency: during optimization, best configurations can be regularly saved. It allows to analyze evolution of best configurations but also to restart an optimization from previously obtained results. A Save Frequency parameter set to 3 means that after three generations, a file is automatically created containing best configurations. These files are named iteraion1.sav, iteration2.sav and are store in Temp directory, and moved to SolvedProblems directory when optimization is finished.

  • ReinitStdDev: this is a specific parameter of EAAdapt1. It defines whether standard deviation of variables should be reinitialized. It is used only if you start optimization from previously obtained configurations (using Use start file option). Setting it to yes (1) will, in most of cases, lead to a spread research of optimized configurations, forgetting parameters’ variations’ reduction obtained in previous optimization.

7.3.7.1Use start file


As indicated before, it is possible to pursue an optimization finished or stopped. To do this, you must enable Use start file option and select file from which optimization should be started. This file is an iteration_.sav file created in previous optimization. It is stored in corresponding SolvedProblems folder (iteration10.sav corresponds to the tenth generation of previous optimization).

Note that this functionality can only work with same variables and objectives. However, minimum, maximum of variables and objectives can be changed before pursuing an optimization.

7.3.8Launch


You can now launch Optimization by clicking Launch button.

7.3.9Stopping Optimization


Optimization will be stopped when the generation counter will reach the generation number defined in parameters. However, you can still stop the optimization while it is running without loosing obtained results. To do this, click on Stop button. Note that this will not immediately stop optimization: it will first finish the current generation.

This stop function is especially useful when optimum points do not vary any more between generations. This can be easily observed since at each generation, the optimum objectives values and corresponding parameters are displayed in log window.




Download 0.95 Mb.

Share with your friends:
1   ...   11   12   13   14   15   16   17   18   ...   23




The database is protected by copyright ©ininet.org 2024
send message

    Main page