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 to 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 creating in this application?

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

You will learn how to:

  • Install all application parts
  • Run optimization models
  • Run Jupyter notebooks


This version is intended for the cloud or on-premise version of impact.

This guide explains how to install a custom function to your Modelon Impact Workspace and how to run the optimization examples with either Jupyter Notebook or said custom function.


This Tutorial assumes a valid license for the MA57 solver. If this license is not available, you may switch to the MUMPS solver. See here

Custom function🔗

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


  1. 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 ModelonImpact


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.


To run our JupyterNotebook optimization notebooks, first install the "Optimize Microgrid" custom function as described here and make sure that it runs.


Installing and running the Jupyter Notebook requires a minimum of familiarity with Python.

  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 models🔗

Microgrid library includes several example models placed within ThermalPower.MicroGrid.Examples. The whole package includes a 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. Make sure you followed the steps to install the custom functions explained here

  2. Create a new workspace "MicrogridTutorial".

  3. Duplicate ThermalPower.MicroGrid.Examples.Optimization.EconomicDispatch model into your workspace.

  4. Go to Experimentation mode and select custom function Optimize Microgrid.

  5. Run the simulation.

Switching solver🔗

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

If you do not have the "ma57" license, you may fail to run the Microgrid examples in TPL 1.24. 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 setttings, can be changed directly in the Modelica model "optimizer"