-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include c library files from external Modelica libraries
*simplify usage of subprocess.Popen() * add linearization test Co-authored-by: arun3688 <[email protected]>
- Loading branch information
Showing
2 changed files
with
94 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import OMPython | ||
import tempfile, shutil, os | ||
import pytest | ||
|
||
class Test_Linearization: | ||
def loadModel(self): | ||
self.tmp = tempfile.mkdtemp(prefix='tmpOMPython.tests') | ||
with open("%s/linearTest.mo" % self.tmp, "w") as fout: | ||
fout.write(""" | ||
model linearTest | ||
Real x1(start=1); | ||
Real x2(start=-2); | ||
Real x3(start=3); | ||
Real x4(start=-5); | ||
parameter Real a=3,b=2,c=5,d=7,e=1,f=4; | ||
equation | ||
a*x1 = b*x2 -der(x1); | ||
der(x2) + c*x3 + d*x1 = x4; | ||
f*x4 - e*x3 - der(x3) = x1; | ||
der(x4) = x1 + x2 + der(x3) + x4; | ||
end linearTest; | ||
""") | ||
|
||
def __del__(self): | ||
shutil.rmtree(self.tmp, ignore_errors=True) | ||
|
||
def test_example(self): | ||
self.loadModel() | ||
filePath = os.path.join(self.tmp,"linearTest.mo").replace("\\", "/") | ||
print(filePath) | ||
mod = OMPython.ModelicaSystem(filePath, "linearTest") | ||
[A, B, C, D] = mod.linearize() | ||
expected_matrixA = [[-3, 2, 0, 0], [-7, 0, -5, 1], [-1, 0, -1, 4], [0, 1, -1, 5]] | ||
assert A == expected_matrixA, f"Matrix does not match the expected value. Got: {A}, Expected: {expected_matrixA}" | ||
assert B == [], f"Matrix does not match the expected value. Got: {B}, Expected: {[]}" | ||
assert C == [], f"Matrix does not match the expected value. Got: {C}, Expected: {[]}" | ||
assert D == [], f"Matrix does not match the expected value. Got: {D}, Expected: {[]}" | ||
|