Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for initializing and terminating ME FMUs #295

Merged
merged 20 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
afceb10
Added work in progress
modelonrobinandersson Feb 14, 2025
da8d9fb
More work in progress
modelonrobinandersson Feb 17, 2025
bc75c62
Added work in progress, DLL is connected and seems to work
modelonrobinandersson Feb 17, 2025
ba62c2e
M Fixed blank spaces
modelonrobinandersson Feb 17, 2025
9e20406
Removed print-statement, added simple test
modelonrobinandersson Feb 17, 2025
0bf19b6
Fixed some issues with callbacks and added another test
modelonrobinandersson Feb 18, 2025
8a46013
Added instantiation and test for instantiation
modelonrobinandersson Feb 18, 2025
732ba1f
Added support for initializing FMI3 ME FMUs
modelonrobinandersson Feb 19, 2025
3f1939e
Fixed readability and docstrings
modelonrobinandersson Feb 19, 2025
a0ef9a7
Fixed issue with redeclared variable
modelonrobinandersson Feb 19, 2025
a4ac66b
Added some blank spaces
modelonrobinandersson Feb 19, 2025
2b3b66e
Fixed review comments
modelonrobinandersson Feb 20, 2025
90e950a
Implemented reset fully, added terminate, free and destroy dll
modelonrobinandersson Feb 20, 2025
eed36b2
Updated init test to also use reset and terminate
modelonrobinandersson Feb 20, 2025
79f032b
Added tests for enter continuous time mode and enter event mode
modelonrobinandersson Feb 21, 2025
b5887de
Improved handling of model identifier
modelonrobinandersson Feb 24, 2025
d9ae5a4
Added test for illegal call sequence
modelonrobinandersson Feb 24, 2025
6e58cb5
Added more tests
modelonrobinandersson Feb 24, 2025
bd8d8ad
Updated build.yml to use latest FMIL
modelonrobinandersson Feb 24, 2025
fdfca59
Removed some unnecessary newlines
modelonrobinandersson Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
- name: Install fmilib
run: |
cd /tmp
curl -fSsL https://github.com/modelon-community/fmi-library/archive/3.0a4.tar.gz | tar xz
cd fmi-library-3.0a4
curl -fSsL https://github.com/modelon-community/fmi-library/archive/3.0a5.tar.gz | tar xz
cd fmi-library-3.0a5
sed -i "/CMAKE_INSTALL_PREFIX/d" CMakeLists.txt
mkdir -p build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
Expand Down
10 changes: 5 additions & 5 deletions src/pyfmi/fmi2.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ cdef class WorkerClass2:
cpdef verify_dimensions(self, int dim)

cdef object _load_fmi2_fmu(
fmu,
object log_file_name,
str kind,
int log_level,
fmu,
object log_file_name,
str kind,
int log_level,
int allow_unzipped_fmu,
FMIL.fmi_import_context_t* context,
FMIL.fmi_import_context_t* context,
bytes fmu_temp_dir,
FMIL.jm_callbacks callbacks,
list log_data
Expand Down
15 changes: 7 additions & 8 deletions src/pyfmi/fmi2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ from pyfmi.fmi_base import (
from pyfmi.exceptions import (
FMUException,
InvalidBinaryException,
InvalidXMLException,
InvalidXMLException,
InvalidVersionException
)
from pyfmi.common.core import create_temp_dir
Expand Down Expand Up @@ -1185,7 +1185,6 @@ cdef class FMUModelBase2(FMI_BASE.ModelBase):

self._t = start_time
self._last_accepted_time = start_time
self._relative_tolerance = tolerance

self._log_handler.capi_start_callback(self._max_log_size_msg_sent, self._current_log_size)
status = FMIL2.fmi2_import_setup_experiment(self._fmu,
Expand All @@ -1206,7 +1205,7 @@ cdef class FMUModelBase2(FMI_BASE.ModelBase):
status = FMIL2.fmi2_import_reset(self._fmu)
self._log_handler.capi_end_callback(self._max_log_size_msg_sent, self._current_log_size)
if status != 0:
raise FMUException('An error occured when reseting the model, see the log for possible more information')
raise FMUException('An error occured when resetting the model, see the log for possible more information')

#Default values
self._t = None
Expand Down Expand Up @@ -5172,12 +5171,12 @@ cdef class WorkerClass2:
return ret

cdef object _load_fmi2_fmu(
fmu,
object log_file_name,
str kind,
int log_level,
fmu,
object log_file_name,
str kind,
int log_level,
int allow_unzipped_fmu,
FMIL.fmi_import_context_t* context,
FMIL.fmi_import_context_t* context,
bytes fmu_temp_dir,
FMIL.jm_callbacks callbacks,
list log_data
Expand Down
25 changes: 17 additions & 8 deletions src/pyfmi/fmi3.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ cdef class FMUModelBase3(FMI_BASE.ModelBase):
cdef FMIL3.fmi3_import_t* _fmu
cdef FMIL3.fmi3_fmu_kind_enu_t _fmu_kind
cdef FMIL.fmi_version_enu_t _version


# Internal values
cdef object _fmu_full_path
cdef public float _last_accepted_time
cdef public object _enable_logging
cdef object _fmu_full_path
cdef object _modelName
cdef object _t
cdef int _allow_unzipped_fmu
cdef int _allocated_context, _allocated_xml
cdef int _allocated_context, _allocated_dll, _allocated_fmu, _allocated_xml

cdef int _initialized_fmu
cdef object _has_entered_init_mode # this is public in FMI2 but I don't see why

cdef class FMUModelME3(FMUModelBase3):
pass
cdef FMIL.size_t _nEventIndicators
cdef FMIL.size_t _nContinuousStates

cdef void _cleanup_on_load_error(
FMIL3.fmi3_import_t* fmu_3,
Expand All @@ -46,12 +55,12 @@ cdef void _cleanup_on_load_error(
)

cdef object _load_fmi3_fmu(
fmu,
object log_file_name,
str kind,
int log_level,
fmu,
object log_file_name,
str kind,
int log_level,
int allow_unzipped_fmu,
FMIL.fmi_import_context_t* context,
FMIL.fmi_import_context_t* context,
bytes fmu_temp_dir,
FMIL.jm_callbacks callbacks,
list log_data
Expand Down
Loading