Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer committed May 27, 2024
1 parent 03112f5 commit 51ad005
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2023, Dassault Systèmes. All rights reserved.
Copyright (c) 2024, Dassault Systèmes. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,34 @@ To run the tests, right click on the `ExternalLibraryTest` project, select `Set

To build a shared library that calls Python follow the steps above, but after you pressed `Configure`, select `EXTERNAL_LANGUAGE=Python` and set `PYTHON_HOME=C:/Anaconda3` (assuming that you installed Anaconda Python 3.7 in `C:/Anaconda3`).

To install the Python library in development mode run `pip install -e Python` in the root of the repository. This will allow you edit the Python code without reinstalling the library.
To install the Python library in development mode run `pip install -e Python` in the root of the repository.
This will allow you edit the Python code without reinstalling the library.

Run `ExternalLibraryTest` in Visual Studio to check if everything is set up correctly.
In order use load the Python binaries and their dependencies two environment variables need to be for the process loading the `ExternalLibrary.dll`.

`PYTHONHOME` needs to point to the folder that contains the Python executable.
It can retrieved by running `which python`.

`PATH` needs to contain all folders that contain Python binaries and dependencies.
For Conda environments these can be retrived by running `set PATH` inside a Conda prompt.

On the `ExternalLibraryTest` project in Visual Studio right-click and selct `Properties > Configuration Properties > Debugging`.
In `Environment` set the two environment variables and run the project to check if everything is set up correctly.

## Modelica library

The Modelica library is the same for both the C++ and the Python backend. It contains a Modelica function `libraryFunction` that can be used e.g. to load data at the beginning of a simulation and an ExternalObject `LibraryObject` to connect to external code during the simulation (e.g. to inter- or extrapolate using special algorithms).
The Modelica library is the same for both the C++ and the Python backend.
It contains a Modelica function `libraryFunction` that can be used e.g. to load data at the beginning of a simulation and an ExternalObject `LibraryObject` to connect to external code during the simulation (e.g. to inter- or extrapolate using special algorithms).

![Modelica library](ExternalLibrary/Resources/Images/ExternalLibrary.png)

After loading the `ExternalLibrary` package in Dymola, go to `Commands` and run `Advanced.CompileWith64=2` to compile 64-bit binaries and `Modelica.Utilities.System.setEnvironmentVariable("PYTHONHOME", "C:/Anaconda3")`, so the shared library knows where to search for the Python installation.
After loading the `ExternalLibrary` package in Dymola, go to `Commands` and run `Advanced.CompileWith64=2` to compile 64-bit binaries and `Modelica.Utilities.System.setEnvironmentVariable("PYTHONHOME", ...)` and `Modelica.Utilities.System.setEnvironmentVariable("PATH", ...)` (see previous section), so the shared library knows where to search for the Python installation and dependencies.

To run the function with the default parameters, right click `libraryFunction` and select `Run Function...` and then `Execute`.
To run the function with the default parameters, right click `externalLibraryFunction` and select `Run Function...` and then `Execute`.

The `LibraryObjectExample` demonstrates the use of the external object.
The `ExternalLibraryFunctionExample` and `ExternalLibraryObjectExample` demonstrates the use of the external function and object respectively.

## License

Copyright © 2023 Dassault Systèmes.
Copyright © 2024 Dassault Systèmes.
The code is released under the [2-Clause BSD license](LICENSE.txt).

0 comments on commit 51ad005

Please sign in to comment.