Skip to content

Commit

Permalink
Merge pull request #47 from NREL/kd/fix-getI-getV
Browse files Browse the repository at this point in the history
Fix getI and getV functions
  • Loading branch information
kdheepak authored Jan 16, 2019
2 parents 5d75937 + 0a9d7ed commit ce9a7f2
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 57 deletions.
4 changes: 2 additions & 2 deletions opendssdirect/YMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def VVector():
def getI():
"""Get the data from the internal Current pointer"""
IvectorPtr = IVector()
return ffi.unpack(IvectorPtr, NumNodes() + 1)
return ffi.unpack(IvectorPtr, (NumNodes() + 1) * 2)


def getV():
"""Get the data from the internal Voltage pointer"""
VvectorPtr = VVector()
return ffi.unpack(VvectorPtr, NumNodes() + 1)
return ffi.unpack(VvectorPtr, (NumNodes() + 1) * 2)


def SolveSystem(NodeV):
Expand Down
195 changes: 140 additions & 55 deletions tests/test_opendssdirect.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
import pytest as pt
import os
import sys
import pandas as pd
from pandas.util.testing import assert_dict_equal
import numpy as np
import six

current_directory = os.path.dirname(os.path.realpath(__file__))
PATH_TO_DSS = os.path.abspath(
Expand Down Expand Up @@ -202,15 +200,14 @@ def test_configuration():
# Note COM's AllowForms can only be disabled and it ignores
# the user's command to reallow forms if they were previously
# disabled.
assert dss.Basic.AllowForms() == False, "Allow forms should be disabled by default"
assert dss.Basic.AllowForms() is False, "Allow forms should be disabled by default"

dss.Basic.AllowForms(True)
assert dss.Basic.AllowForms() == True
assert dss.Basic.AllowForms() is True

dss.Basic.AllowForms(False)
assert dss.Basic.AllowForms() == False
assert dss.Basic.AllowForms() is False



def test_13Node(dss):

Expand Down Expand Up @@ -238,7 +235,7 @@ def test_13Node(dss):

def test_13Node_Basic(dss):

assert dss.Basic.AllowForms() == False
assert dss.Basic.AllowForms() is False
assert dss.Basic.Classes() == [
u"Solution",
u"LineCode",
Expand Down Expand Up @@ -423,6 +420,8 @@ def test_13Node_Bus(dss):
],
decimal=4,
)
# TODO: this should not be sorted, we should define the order of the results
assert sorted(dss.YMatrix.getV()[2:]) == sorted(dss.Circuit.AllBusVolts())


def test_13Node_Circuit(dss):
Expand Down Expand Up @@ -5321,59 +5320,103 @@ def test_ymatrix(dss):
]
),
)

expected_V = [
0.0,
0.0,
57502.68619173075,
33189.47560805492,
-10.988873472987157,
33189.47560805494,
-10.988873472980917,
-66394.8688498055,
-57491.69731825777,
33205.393254709095,
2401.5627723087614,
-0.4669003619615109,
-57491.69731825776,
33205.39325470909,
2401.562772308761,
-0.46690036196087287,
-1201.2376783493826,
-2079.7175117533034,
-1200.31160042552,
2080.141938589097,
2536.3561173511703,
-0.5793274158645817,
-2079.717511753304,
-1200.3116004255196,
2080.1419385890968,
2536.35611735117,
-0.579327415864084,
-1246.25987615131,
-2157.487712670567,
-1267.5877682936239,
2196.935536435069,
-2157.4877126705674,
-1267.5877682936236,
2196.9355364350686,
2426.4227635494685,
-109.96859964562864,
-1300.01934372635,
-2096.2844127873723,
-1120.4211783202531,
2128.6024323393126,
-109.96859964562768,
-1300.0193437263497,
-2096.2844127873727,
-1120.421178320253,
2128.602432339312,
273.12043190753747,
-15.653612485262295,
-149.22103967628902,
-236.2879586961411,
-124.73842715841117,
-15.653612485262233,
-149.221039676289,
-236.28795869614112,
-124.73842715841113,
242.00723011013307,
2350.0727132732495,
-221.08573964636093,
2350.072713273249,
-221.08573964636037,
-1338.4057884569054,
-2109.79926873945,
-1015.400115391676,
2083.111524683725,
-1295.6861264459194,
-2109.799268739451,
-1015.4001153916763,
2083.1115246837244,
-1295.686126445919,
-2078.3661532376227,
-1296.2432698471696,
-2073.159564606237,
-1296.2432698471694,
-2073.1595646062365,
-1121.7870803503151,
2124.3512160900596,
-1015.4001096022037,
2083.111507606074,
2350.0726913632457,
-221.08573234457813,
2333.493783338756,
-229.76132301856697,
-1347.9836973508538,
-2110.4122812917285,
-1013.9611656277061,
2078.6439955795977,
-1002.1192290632004,
2078.7490540767426,
2332.4226357124753,
-217.315297134126,
2407.051035303729,
-145.3762181110123,
-1312.3022035419076,
-2102.371437004225,
-1082.9954874709554,
2116.1047513838107,
2433.846944169107,
-107.52581738463071,
-1300.7631166862307,
-2101.2693421622234,
-1123.5616047423157,
2134.1366227595295,
2350.0727418747815,
-221.08575715699388,
-1338.4058117088837,
-2109.7992962044323,
-1015.4001197194408,
2083.111559417906,
-1122.3854662972221,
2129.559591256956,
-1338.4057922959526,
-2109.7992630653534,
2345.3836609834,
-221.6058883507038,
-1009.562139171098,
2080.528335732232,
]

expected_I = [
45.06951001845606,
24.808808468458462,
69802.42815021456,
-72191.0872076774,
-97420.52952591192,
45.06951001842762,
24.808808468443384,
69802.42815021457,
-72191.08720767738,
-97420.52952591189,
-24355.132407117453,
27618.10139734252,
96546.21962200986,
27618.101397342507,
96546.21962200984,
0.0,
0.0,
0.0,
Expand All @@ -5392,22 +5435,64 @@ def test_ymatrix(dss):
0.0,
0.0,
0.0,
-13.835382498621925,
10.728150694675378,
-8.968242194252412,
-3.4169800644838233,
-3.1253287196529698,
-13.83538249862238,
10.728150694675719,
-8.968242194252525,
-3.416980064483795,
-3.1253287196529413,
-18.472388556181386,
-2.6675923553345626,
3.8325352754590654,
-0.4671256788091398,
-1.9482821746922383,
3.1347180341436953,
3.832535275459094,
-0.4671256788091469,
-1.9482821746922525,
3.1347180341437095,
-1.8842531007668413,
-3.3143940171116526,
-1.32120707207174,
7.105427357601002e-15,
7.105427357601002e-15,
-7.105427357601002e-15,
-7.105427357601002e-15,
0.2587373173690999,
-1.0386532600475533,
-0.2587373173690999,
1.0386532600475533,
-9.012548999300577,
4.595887907960702,
-3.0888978934500315,
-0.8862753821772245,
-1.9605308838638749,
-10.932799880696791,
0.028157771758481887,
-3.016045651431398,
0.0,
0.0,
0.06462474225171722,
-0.04346468945275728,
-1.7990183461979612,
-0.9604487876225356,
-0.05797062518124507,
-1.0832442019763704,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
]

actual_Y_data = dss.YMatrix.getYsparse()
Expand Down

0 comments on commit ce9a7f2

Please sign in to comment.