Skip to content



Most of the time, we rely on the traditional power grid as our main energy source. But when massive blackouts occur, organizations and communities need to rely on power systems that are secure and flexible.

Moreover, renewable energy sources like wind, photovoltaic power plants and others do not provide constant power output and they are dependent on the weather, causing power fluctuation in the power grids.

An example microgrid model (without optimization)

Microgrids which operate as part of the traditional grid or independently are an ingenious solution that can lead to fewer blackouts, greater cost savings, and less dependence on fossil fuels.

What are we building?

In this tutorial, we will show how to open and run a defined set of microgrid configurations with several specific control strategies equipped with dynamic optimization. It consists of Modelica models, Jupyter notebooks and optimization through Impact UI.

You will learn how to:

  • Run Jupyter notebooks
  • Run optimization models


This guide explains how to run the optimization examples with with built in custom function through Impact UI and how to run with Jupyter Notebook with a manually added custom function.

Optimization of models through Jupyter Notebooks🔗

To run our Jupyter Notebook optimization, install the "Optimize Microgrid" custom function as described below and make sure that it runs.

  1. Add Optimize Microgrid custom function by opening the ThermalPower library in Impact and downloading


  2. Open JupyterLab from the button (Apps) on the top right to upload the downloaded file to

~/impact/custom_functions ("~" refers to your home folder)

This can be done by dragging the file from your "Downloads" folder to the File Browser pane in JupyterLab.

  1. Restart the Modelon Impact server by signing off and on from Modelon Impact


The .py file needs to be on the top level. If .py files are in a subfolder (e.g. impact/custom_function/custom_functions) then Modelon Impact won’t find them.

  1. Microgrid optimization notebook can be found in the ThermalPower library in Impact at modelica://ThermalPower/Resources/Python/Microgrid/Microgrid-Optimization.ipynb

  2. Download modelica://ThermalPower/Resources/Python/Microgrid/Microgrid-Optimization.ipynb

  3. Upload it to any location in your home folder by opening JupyterLab from the button (Apps) on the top right and dragging the file to the file browser within Jupyter Lab (left pane)

  4. OpenMicrogrid-Optimization.ipynb in the JupyterLab app

  5. Navigate to the section "4.1. Workspace name and dependencies" and change the workspace name to the name of your actual workspace, by changing the line ws='Test2208' # workspace name

  6. Click the ⏩ button to execute all code cells in that notebook

Change the workspace name in the code cell of the Jupyter Notebook

Optimization of models through Impact UI🔗

The Microgrid library includes several example models placed within ThermalPower.MicroGrid.Examples. The whole package includes detailed documentation and description explaining the background, purpose and results of the specific examples.

Click here to find out, how to access the library documentation.

EconomicDispatch is an optimizable microgrid model

The optimization models can be run using below approach:

  1. Create a new workspace "MicrogridTutorial".

  2. Duplicate ThermalPower.MicroGrid.Examples.Simulation.EconomicDispatch model into your workspace.

  3. Go to Experimentation mode, select "Custom" under the Analysis tab and choose Thermalpower.Optimize.Microgrid 1.26 in the dropdown.

  1. Run the simulation.

Switching solver🔗

Modelon provides a commercial "ma57" solver on a trial basis to interested customers.


The ma57 solver is available at

Contact Modelon Sales team for more details.

If you do not have the "ma57" license, you may fail to run the Microgrid examples in TPL 1.26. In that case, change to the open source "mumps" solver by disabling the use_ma57 setting in the Modelica optimizer model. (see screenshot below)

The solver, like many other common optimization settings, can be changed directly in the Modelica model "optimizer"