GithubHelp home page GithubHelp logo

quarree100 / modeliquarree Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 7.0 97.42 MB

Repository for work in Quarree100 based on Modelica

License: GNU General Public License v3.0

Batchfile 0.01% Shell 0.01% Python 0.97% Modelica 20.80% Motoko 78.23%

modeliquarree's Introduction

modeliquarree (Modelica-Quarree100)

Repository for work with Modelica in the project Quarree100.

district_model

This directory is for the main modelica package of Quarree100, the district model. It allows simulation of the energy system with all its major components in OpenModelica and Dymola.

Examples

This directory contains general examples for the work with OpenModelica and Python. BouncingBall.py implements several ways of connecting Python to Modelica Simulations and Functional Mock-up Units (FMUs), for example through OMPython (OpenModelica Python Interface). It uses the standard BouncingBall Modelica example project.

HP_testbench

Careful: Until issue #5 Update heatpump testbench to AixLib 0.9.1 has been resolved, this part is not fully functional!

This directory contains a Python package called hptestbench, which allows simulating heatpumps with OpenModelica or FMUs, in order to evaluate their performance and integrate the results in other workflows. The main purpose is to provide e.g. COP timeseries for use in oemof optimizations. hptestbench is designed to be a self-contained Python package. It provides the necessary files for installation from source, as well as both an OpenModelica model and an equivalent FMU. Private data required for Quarree100 and not shared on GitHub can be automatially loaded, too. hptestbench makes sure the necessary replacements are made.

Installation

After cloning the repository from GitHub, you can install the package from source with either pip:

python setup.py install

... or conda (making sure all dependency packages are installed):

conda build conda.recipe
conda install hptestbench --use-local

... or you can "install" it with conda's development mode:

conda develop .

This may be the preferred option, since it just registers a link to the Git directory. After any changes are made, no new installation is required. Since this way no dependencies are installed, you may find the file ''requirements.txt'' useful for installing those.

You can now simulate FMUs with pyfmi. If you want to simulate via OpenModelica, both OpenModelica itself and OMPython have to be installed manually (since OMPython is not available through conda).

Please note:

OMPython changed the input style for functions like setSimulationOptions(), setParameters(), etc. dramatically after v3.1.2. In order to be future-proof, this package requires the latest version from https://github.com/OpenModelica/OMPython/archive/master.zip (which is different from the version shipped with the Windows installer of OpenModelica!)

Actions

Please refer to the workflow implemented as a GitHub action for the complete installation instructions:

.github\workflows\heatpump_testbench.yml

This action serves as a test that is executed on each commit, making sure both installation and simulation are working properly.

Usage

Examples for how to use the testbench can be found in HP_testbench\conda.recipe\run_test.py and HP_testbench\hptestbench\__main__.py

import hptestbench
# Create our testbench
bench = hptestbench.testbench()

# Optionally, install a specific heat pump
bench.install_HP('Q100_air_water_001')  # optional

# Run the simulation with Modelica
bench.test_with_modelica(make_FMU=True)

# (or) Run the simulation via the functional mockup interface (FMI)
bench.test_with_FMU()

# Evaluate the results
data = bench.evaluate()
COP_mean = data['heatPump1.CoP_out'].mean()

modeliquarree's People

Contributors

jnettels avatar jwalbrunn avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

modeliquarree's Issues

Ensure compatibility with different program versions

Track the compatibility of the different models with different versions of OpenModelica and Dymola.

"FMU" means: The functional mockup unit can be created by that program version and works with pyfmi

Reflects status at b01a639

Model OpenModelica 1.16.2 OpenModelica 1.18.0 Dymola 2021
Gesamt_Sim_noLP
Gesamt_Sim_noLP (FMU) not tested not tested not tested
Gesamt_Sim_ExcelReadIn ☐ (crashes at 5.7s)
Gesamt_Sim_ExcelReadIn (FMU) not tested not tested not tested
FMU_PhyModel
FMU_PhyModel (FMU) not tested
FMU_PhyModel_sorted
FMU_PhyModel_sorted (FMU) not tested
ElectrolysisSystem
ElectrolysisSystem (FMU) not tested

Test exporting a Python simulation to an FMU

As discussed, we might need to be able to export a Python simulation to an FMU at some point.
While simulating Modelica models #1 and FMUs #2 with Python is very straight forward, creating an FMU from Python code seems more complicated.

It is possible though, and this might be a good starting point:
https://pypi.org/project/SimulatorToFMU/
https://github.com/LBNL-ETA/SimulatorToFMU

While the published version includes a note that it works with Python 2.7, the GitHub project has a development branch with support for Python 3.7. See the discussion here:
https://groups.google.com/forum/#!topic/simulatortofmu/P3WE1m2vvBs

Note: I am not planning to work on this any time soon, I am just creating this issue for reference. Someone who actually simulates in Python should assign this to themselfes.

Add Quarree100 district model to repository

Thanks to the work of @jwalbrunn we now have a working district model for Quarree100. To complete my task of adding that modelica package to this repository, these are the necessary steps:

  • ea55083 Initial commit of Quarree100 district model modelica files
  • c922b66 Move contents of package.mo to individual files. It still contained all of the used information, while the existing files Simulations.mo and Components.mo were not actually used anymore
  • ceb510e Introduce user personalized inputData records, see below
  • Minor fixes for OpenModelica d163b26, b3355dd
  • 2ae6ec5 Rename the modelica package to Q100_DistrictModel
  • Ensure compatibility with OpenModelica. Specifically, I got multiple errors from AixLib like
    [AixLib.FastHVAC.Components.Storage.HeatStorageVariablePorts: 164:3-171:26]: Non-array modification ‘"K"‘ for array component ‘unit‘, possibly due to missing ‘each‘. These were easy to fix locally and are fixed here jnettels/AixLib@422e0f0

About introducing user personalized inputData records: Dealing with absolute paths to our input files is not pretty, but this approach gives us some options. One option is the following: Create a separate Q100_Sim_jzimmer.mo file somewhere else with this content. We simply extend the original simulation and only redeclare the inputData record.

package Q100_Sim_jzimmer
  extends Modelica.Icons.ExamplesPackage;

  model Q100_Sim_jzimmer
    extends Q100_DistrictModel.Simulations.SIM_RI_Schema(redeclare 
        Q100_DistrictModel.Data.inputData_jzimmer inputData);
  end Q100_Sim_jzimmer;
end Q100_Sim_jzimmer;

You would not track this file with git. And you do not need to change the hardcoded paths every time you push or pull.

Update heatpump testbench to AixLib 0.9.1

The Modelica project heatpump testbench was initially based on AixLib 0.7.3. This shows how a tight integration of Python and Modelica is possible, e.g. preparing a simulation by swapping heatpump base data and simulation via Python.

With AixLib 0.9.1, there are currently two issues preventing a seamless update:

  • AixLib 0.9.1 is not fully compatible with OpenModelica. AixLib.DataBase.ThermalMachines.Chiller.ChillerBaseDataDefinition causes an error in OpenModelica, while it works in Dymola. There is an easy workaround, but currently the authors seem unwilling to include it, since it makes the code somewhat less elegant. See issue "FastHVAC heat pump does not run in OpenModelica" 864 in https://github.com/RWTH-EBC/AixLib (I do not want to link directly, because that reference would be shown there). I tried to be as polite as I can possibly be, but I do not agree with their decision. Fortunately, we do not need the chiller function, so we can work around the issue.
  • Replacing the heat pump data programmatically via Python is an essential part of the testbench. Due to changes to the heatpump model in 0.9.1, this data selection is now contained in a redeclare statement. This syntax of the Modelica standard is not fully supported by OpenModelica (Dymola handles it just fine), so there is no command to replace this information. See this for more details: https://stackoverflow.com/questions/62168453. An update with that feature is being worked on, but we can only wait patiently for it to happen.

Naming control_opt_SI_BooleanSI causes error

The following error occurred when trying to run the district model under Linux:

[.../Q100_DistrictModel/Components.mo:252:5-253:117:writable] Warning: Component control_opt_SI_BooleanSI in env: Q100_DistrictModel.Components.Producer_HePu_opt$HePu_Air has the same name as its type Q100_DistrictModel.Components.control_opt_SI_BooleanSI.

Test district model with Python

We want to be able to use python for automated tests of the Modelica district model.

  • 8256f6e Add Python script for testing
  • ff31920 Add GitHub workflow that runs the Python test for every commit

Test controling FMI simulations with Python

To start our work with Modelica, we need to understand what interfaces exist for the Functional Mock-Up Interface (FMI) and Python.

With 33bf438, the BouncingBall example has been expanded to show how to simulate a Functional Mock-Up Unit (FMU) with Python. For this, https://pypi.org/project/PyFMI/ can be used:

conda install pyfmi

Please note: With the first installation of PyFMI from Anaconda, the following error appeared when trying to simulate:

pyfmi.common.algorithm_drivers.InvalidAlgorithmOptionException: 'Invalid algorithm options object: The solver: CVode is unknown.'

This fixed it (updates the simulation algorithm assimulo to a more recent version):

conda install -c conda-forge assimulo

Test controling Modelica simulations with Python

To start our work with Modelica, we need to understand what interfaces exist for Modelica and Python.

The BouncingBall example is used to demonstrate two ways of controling Modelica simulations with Python:

  1. Create a ModelicaSystem object which provides functions to load, configure and simulate a model. Plotting is done with Python.
  2. Use calls to the OpenModelica command line interface to load, simulate and plot a model.

Number 1 allows a very tight integration into a Python workflow, whereas 2 is a more general solution that requires less setup.

See the example here, added with 8c95a66:
https://github.com/quarree100/modeliquarree/blob/master/examples/BouncingBall.py

Create heatpump testbench

Create a Python package called hptestbench, which allows simulating heatpumps with OpenModelica or FMUs, in order to evaluate their performance and integrate the results in other workflows. The main purpose is to provide e.g. COP timeseries for use in oemof optimizations.
hptestbench is designed to be a self-contained Python package. It provides the necessary files for installation from source, as well as both an OpenModelica model and an equivalent FMU. Private data required for Quarree100 and not shared on GitHub can be automatially loaded, too. hptestbench makes sure the necessary replacements are made.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.