-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from CURENT/misc
Quick fix on DCOPF series
- Loading branch information
Showing
13 changed files
with
85 additions
and
40 deletions.
There are no files selected for viewing
Binary file not shown.
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
Binary file not shown.
Binary file not shown.
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
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
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
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
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 |
---|---|---|
@@ -1,23 +1,52 @@ | ||
import logging | ||
import unittest | ||
|
||
import numpy as np | ||
|
||
import ams | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TestKnownResults(unittest.TestCase): | ||
# NOTE: DCOPF objective values are from MATPOWER v8.0b1 | ||
sets = ( | ||
(ams.get_case('matpower/case14.m'), 7642.59177699), | ||
(ams.get_case('matpower/case39.m'), 41263.9486962204), | ||
(ams.get_case('matpower/case118.m'), 125947.8814179), | ||
) | ||
|
||
def test_known_results(self): | ||
for case, obj in self.sets: | ||
sp = ams.load(case, setup=True, no_output=True) | ||
sp.DCOPF.run(solver='ECOS') | ||
msg = f'Case: {case}; Result: {sp.DCOPF.obj.v}; Expected: {obj}' | ||
logger.info(msg) | ||
self.assertAlmostEqual(sp.DCOPF.obj.v, obj, places=2) | ||
# NOTE: Baseline comes from MATPOWER v8.0b1 | ||
# NOTE: when using ECOS in this case, the accuracy is ralatively low | ||
|
||
def test_known_case14(self): | ||
case = ams.get_case('matpower/case14.m') | ||
sp = ams.load(case, setup=True, no_output=True) | ||
sp.DCOPF.run(solver='ECOS') | ||
self.assertAlmostEqual(sp.DCOPF.obj.v, 7642.59177715644, places=2) | ||
|
||
aBus_mp = np.array([ | ||
-0.0, -0.088451789, -0.22695322, -0.18549695, | ||
-0.15942929, -0.25995018, -0.24348912, -0.24348912, | ||
-0.27468284, -0.2795552, -0.27334388, -0.27941265, | ||
-0.28242718, -0.30074116,]) | ||
aBus_mp -= aBus_mp[0] | ||
|
||
aBus = sp.DCOPF.aBus.v - sp.DCOPF.aBus.v[0] | ||
self.assertTrue(np.allclose(aBus, aBus_mp, atol=1e-4)) | ||
|
||
pg_mp = np.array([ | ||
2.2096769, 0.38032305, 0.0, 0.0, 0.0]) | ||
pg = sp.DCOPF.pg.v | ||
self.assertTrue(np.allclose(pg, pg_mp, atol=1e-4)) | ||
|
||
def test_known_case39(self): | ||
case = ams.get_case('matpower/case39.m') | ||
sp = ams.load(case, setup=True, no_output=True) | ||
sp.DCOPF.run(solver='ECOS') | ||
self.assertAlmostEqual(sp.DCOPF.obj.v, 41263.94078592735, places=2) | ||
|
||
pi = sp.DCOPF.pi.v / sp.config.mva | ||
self.assertTrue(np.all(np.isclose(pi, 13.51692, atol=1e-2))) | ||
|
||
def test_known_case118(self): | ||
case = ams.get_case('matpower/case118.m') | ||
sp = ams.load(case, setup=True, no_output=True) | ||
sp.DCOPF.run(solver='ECOS') | ||
self.assertAlmostEqual(sp.DCOPF.obj.v, 125947.8814181522, places=2) | ||
|
||
pi = sp.DCOPF.pi.v / sp.config.mva | ||
self.assertTrue(np.all(np.isclose(pi, 39.38136794580036, atol=1e-2))) |