Skip to content

Commit

Permalink
accessing p, q, and i values for from and to buses
Browse files Browse the repository at this point in the history
  • Loading branch information
Jain, Milan committed Sep 3, 2024
1 parent 19d923c commit 14db522
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 6 additions & 1 deletion python/src/dsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ def network_analytics_dump(ds_app):
ds_app.getBranchInfoInt(branch, "BRANCH_ELEMENTS"),
ds_app.getBranchInfoInt(branch, "BRANCH_INDEX"),
ds_app.getBranchInfoString(branch, "BRANCH_NAME"),
ds_app.getBranchInfoReal(branch, "BRANCH_LENGTH"))
ds_app.getBranchInfoReal(branch, "BRANCH_LENGTH"),
ds_app.getBranchInfoReal(branch, 'BRANCH_FROM_P_CURRENT'),
ds_app.getBranchInfoReal(branch, 'BRANCH_FROM_Q_CURRENT'),
ds_app.getBranchInfoReal(branch, 'BRANCH_TO_P_CURRENT'),
ds_app.getBranchInfoReal(branch, 'BRANCH_TO_Q_CURRENT')
)



Expand Down
24 changes: 18 additions & 6 deletions python/src/grid2op_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def load_grid(self,
# solve the power flow - to load the grid data
print('=========== Before Solving Power Flow ===================')
print(full_path)
self._hadapp.solvePowerFlowBeforeDynSimu(full_path, -1) # 0 inidcates that solves the first raw file for power flow, the xml file supports multiple power flow raw files read in
self._hadapp.solvePowerFlowBeforeDynSimu(full_path, 0) # 0 inidcates that solves the first raw file for power flow, the xml file supports multiple power flow raw files read in
print ('Finished Solving Power Flow')
self._hadapp.readGenerators();
self._hadapp.readSequenceData();
Expand Down Expand Up @@ -340,26 +340,36 @@ def runpf(self, is_dc : bool=False):

# load and generator data
self._grid.res_load = self._grid.load[["p_mw", "q_mvar"]]
self._grid.res_gen = self._grid.gen[["p_mw", "q_mvar", "vm_pu"]]
self._grid.res_gen = self._grid.gen[["p_mw", "q_mvar", "vm_pu"]] # p and q also gets multiplied by 100 - CASE_SBASE

# line level data
# line level data - lines and branches could be different. The two end points can have multiple lines but only one branch.
nbranch = self._hadapp.totalBranches()
vm_from_pu = []
vm_to_pu = []
#
for branch in range(0, nbranch):
(f, t) = self._hadapp.getBranchEndpoints(branch)
# from voltage
from_bus = self._grid.bus.index[self._grid.bus['id'] == f].values[0]
vm_from_pu.append(self._hadapp.getBusInfoReal(from_bus, 'BUS_VOLTAGE_MAG'))
vm_from_pu.append(self._hadapp.getBusInfoReal(from_bus, 'BUS_VOLTAGE_MAG')) # * Bus_basekV

# to voltage
to_bus = self._grid.bus.index[self._grid.bus['id'] == t].values[0]
vm_to_pu.append(self._hadapp.getBusInfoReal(to_bus, 'BUS_VOLTAGE_MAG'))
vm_to_pu.append(self._hadapp.getBusInfoReal(to_bus, 'BUS_VOLTAGE_MAG')) # * Bus_basekV

# branch values
print(
"====================BRANCH P and Q values===================",
self._hadapp.getBranchInfoReal(branch, 'BRANCH_FROM_P_CURRENT'),
self._hadapp.getBranchInfoReal(branch, 'BRANCH_FROM_Q_CURRENT'),
self._hadapp.getBranchInfoReal(branch, 'BRANCH_TO_P_CURRENT'),
self._hadapp.getBranchInfoReal(branch, 'BRANCH_TO_Q_CURRENT')
)

# convert to data frame
self._grid.res_line = self._random_data_generator(self._grid.line.shape[0], columns=self._grid.res_line.columns)
self._grid.res_line["vm_from_pu"] = vm_from_pu
self._grid.res_line["vm_to_pu"] = vm_to_pu
self._grid.res_line["vm_to_pu"] = vm_to_pu # * Bus_basekV

# transformer data
self._grid.res_trafo = self._random_data_generator(self._grid.trafo.shape[0], columns=self._grid.res_trafo.columns)
Expand All @@ -376,6 +386,7 @@ def runpf(self, is_dc : bool=False):
for l in range(self._hadapp.numLoads(bus)):
# load list
print(f"Load {self._hadapp.getBusInfoString(bus, 'LOAD_ID', l)} P(MW): {self._hadapp.getBusInfoReal(bus, 'LOAD_PL_CURRENT', l)}")
print(f"Load {self._hadapp.getBusInfoString(bus, 'LOAD_ID', l)} Q(MW): {self._hadapp.getBusInfoReal(bus, 'LOAD_QL_CURRENT', l)}")

# print(self._grid.trafo, self._grid.res_trafo)
sys.exit(1)
Expand Down Expand Up @@ -492,6 +503,7 @@ def lines_or_info(self)-> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
q_or = self._aux_get_line_info("q_from_mvar", "q_hv_mvar")
v_or = self._aux_get_line_info("vm_from_pu", "vm_hv_pu") # in pu
a_or = self._aux_get_line_info("i_from_ka", "i_hv_ka") * 1000 # grid2op expects amps (A) pandapower returns kilo-amps (kA)
# * 100 / kV (TAmps)

# get the voltage in kV (and not in pu)
bus_id = np.concatenate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ void gridpack::dynamic_simulation::DSFullApp::resetPower()
void gridpack::dynamic_simulation::DSFullApp::updateData()
{
p_factory->updateData();
p_factory->dumpData();
// p_factory->dumpData();
}

/**
Expand Down

0 comments on commit 14db522

Please sign in to comment.