Skip to content

Commit

Permalink
load linearized model directly from file (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 authored Apr 30, 2024
1 parent 69a502e commit 891528c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class which means it will use OMCSessionZMQ by default. If you want to use
from collections import OrderedDict
import numpy as np
import pyparsing
import importlib


if sys.platform == 'darwin':
Expand Down Expand Up @@ -1766,11 +1767,10 @@ def linearize(self, lintime = None, simflags= None): # 22
# this function is called from the generated python code linearized_model.py at runtime,
# to improve the performance by directly reading the matrices A, B, C and D from the julia code and avoid building the linearized modelica model
try:
## add the generated linearfile directory to system path, as running from script does not find the module
## do not add the linearfile directory to path, as multiple execution of linearization will always use the first added path, instead execute the file
## https://github.com/OpenModelica/OMPython/issues/196
sys.path.append(os.path.dirname(linearFile))
from linearized_model import linearized_model
result = linearized_model()
module = importlib.machinery.SourceFileLoader("linearized_model", linearFile).load_module()
result = module.linearized_model()
(n, m, p, x0, u0, A, B, C, D, stateVars, inputVars, outputVars) = result
self.linearinputs = inputVars
self.linearoutputs = outputVars
Expand Down

0 comments on commit 891528c

Please sign in to comment.