Skip to content

Commit

Permalink
Merge branch 'refs/heads/devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
SanPen committed Aug 2, 2024
2 parents dcdc54d + bb8e4cf commit b2bfac2
Show file tree
Hide file tree
Showing 130 changed files with 9,184 additions and 7,847 deletions.
1,096 changes: 615 additions & 481 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified Grids_and_profiles/grids/IEEE57.gridcal
Binary file not shown.
Binary file modified Grids_and_profiles/grids/Lynn 5 Bus pv.gridcal
Binary file not shown.
82 changes: 82 additions & 0 deletions examples/ieee9_Kriti.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import GridCalEngine.api as gce
import numpy as np
from GridCalEngine.Simulations.OPF.NumericalMethods.ac_opf import run_nonlinear_opf, ac_optimal_power_flow
from GridCalEngine.enumerations import TransformerControlType, AcOpfMode, ReactivePowerControlMode

from GridCalEngine.DataStructures.numerical_circuit import compile_numerical_circuit_at, NumericalCircuit
"""
from GridCalEngine.basic_structures import Vec
import GridCalEngine.Utils.NumericalMethods.autodiff as ad
from GridCalEngine.DataStructures.numerical_circuit import compile_numerical_circuit_at
from GridCalEngine.Utils.NumericalMethods.ips import interior_point_solver, IpsFunctionReturn
from GridCalEngine.Simulations.PowerFlow.power_flow_worker import multi_island_pf_nc
from typing import Callable, Tuple
import os
import pandas as pd
from scipy.sparse import csc_matrix as csc
from scipy.sparse import lil_matrix
"""
# User input - Weights for the two components of the Objective Function
wloss = 0.8
wred = 0.2

####---------- Create IEEE 9 bus system
grid = gce.MultiCircuit()
# grid.Sbase = 100

# AC Bus 1 with a generator
acbus1 = gce.Bus('ACBus_1', Vnom=345, is_slack=True, is_dc=False)
grid.add_bus(acbus1)
gen1 = gce.Generator('Gen1',P=72.3, vset=1.04, Pmin=10, Pmax=250, Qmin=-300, Qmax=300, Cost0=150, Cost=5, Cost2=0.11,enabled_dispatch=True)
grid.add_generator(acbus1, gen1)

# AC Bus 2 with a generator
acbus2 = gce.Bus('ACBus_2', Vnom=345, is_slack=False, is_dc=False)
grid.add_bus(acbus2)
gen2 = gce.Generator('Gen2', P=163, vset=1.025, Pmin=10, Pmax=300, Qmin=-300, Qmax=300, Cost0=600, Cost=1.2, Cost2=0.085,enabled_dispatch=True)
grid.add_generator(acbus2, gen2)

# AC Bus 3 with a generator
acbus3 = gce.Bus('ACBus_3', Vnom=345, is_slack=False, is_dc=False)
grid.add_bus(acbus3)
gen3 = gce.Generator('Gen3', P=85, vset=1.025, Pmin=10, Pmax=270, Qmin=-300, Qmax=300, Cost0=335, Cost=1, Cost2=0.1225,enabled_dispatch=True)
grid.add_generator(acbus3, gen3)

# AC Bus 4
acbus4 = gce.Bus('ACBus_4', Vnom=345, is_slack=False, is_dc=False)
grid.add_bus(acbus4)

# AC Bus 5 with a load
acbus5 = gce.Bus('ACBus_5', Vnom=345, is_slack=False, is_dc=False)
grid.add_bus(acbus5)
grid.add_load(acbus5, gce.Load('load1', P=90, Q=30))

# AC Bus 6
acbus6 = gce.Bus('ACBus_6', Vnom=345, is_slack=False, is_dc=False)
grid.add_bus(acbus6)

# AC Bus 7 with a load
acbus7 = gce.Bus('ACBus_7', Vnom=345, is_slack=False, is_dc=False)
grid.add_bus(acbus7)
grid.add_load(acbus7, gce.Load('load2', P=100, Q=35))

# AC Bus 8
acbus8 = gce.Bus('ACBus_8', Vnom=345, is_slack=False, is_dc=False)
grid.add_bus(acbus8)

# AC Bus 9 with a load
acbus9 = gce.Bus('ACBus_9', Vnom=345, is_slack=False, is_dc=False)
grid.add_bus(acbus9)
grid.add_load(acbus9, gce.Load('load3', P=125, Q=50))

# DC Bus 1
dcbus1 = gce.Bus('DCBus_1', Vnom=345, is_slack=False, is_dc=True)
grid.add_bus(dcbus1)

# DC Bus 2
dcbus2 = gce.Bus('DCBus_2', Vnom=345, is_slack=False, is_dc=True)
grid.add_bus(dcbus2)

nc = compile_numerical_circuit_at(circuit=grid)
print('')
54 changes: 17 additions & 37 deletions src/GridCal/Gui/Diagrams/MapWidget/Branches/map_line_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from __future__ import annotations

# import uuid
from typing import TYPE_CHECKING, List, Union

import logging
Expand All @@ -28,6 +30,7 @@
from GridCalEngine.Devices.Branches.line import Line
from GridCalEngine.enumerations import DeviceType
from GridCal.Gui.Diagrams.generic_graphics import GenericDiagramWidget
from GridCal.Gui.messages import error_msg

if TYPE_CHECKING:
from GridCal.Gui.Diagrams.MapWidget.Substation.node_graphic_item import NodeGraphicItem
Expand Down Expand Up @@ -158,39 +161,15 @@ def draw_all(self) -> None:
"""
self.clean()

diagram_locations: PointsGroup = self.editor.diagram.data.get(DeviceType.LineLocation.value, None)

# draw line locations
for elm in self.api_object.locations.data:
graphic_obj = self.editor.create_node(line_container=self,
api_object=elm,
lat=elm.lat, # 42.0 ...
lon=elm.long,
index=self.number_of_nodes()) # 2.7 ...

if diagram_locations is None:
# no locations found, use the data from the api object
# lat = elm.lat
# lon = elm.long
pass
else:

# try to get location from the diagram
# We will not take the location of the element in the database because we want to keep...
# ... the diagram separated from database
# diagram_location = diagram_locations.locations.get(elm.idtag, None)

# if diagram_location is None:
# # no particular location found, use the data from the api object
# # lat = elm.lat
# # lon = elm.long
# pass
# else:
# # Draw only what's on the diagram
# # diagram data found, use it

graphic_obj = self.editor.create_node(line_container=self,
api_object=elm,
lat=elm.lat, # 42.0 ...
lon=elm.long,
index=self.number_of_nodes()) # 2.7 ...

self.register_new_node(node=graphic_obj)
self.register_new_node(node=graphic_obj)

# second pass: create the segments
self.redraw_segments()
Expand All @@ -206,6 +185,7 @@ def removeNode(self, node: NodeGraphicItem):
self.editor.map.diagram_scene.removeItem(seg)

self.nodes_list.remove(node)
self.api_object.locations.remove(node.api_object)

for nod in self.nodes_list:
if nod.index > node.index:
Expand Down Expand Up @@ -291,7 +271,7 @@ def insert_new_node_at_position(self, index: int):
z=new_api_node_data.alt,
seq=new_api_node_data.seq,
name=new_api_node_data.name,
idtag=new_api_node_data.idtag,
idtag=None, # generates new UUID
code=new_api_node_data.code)

self.api_object.locations.data.insert(index, new_api_object)
Expand Down Expand Up @@ -434,11 +414,11 @@ def split_Line(self, index):
if 0 < index < len(self.api_object.locations.data) and len(self.api_object.locations.data) > 3:

ln1 = Line()
ln1.copyData(self.api_object)
ln1.set_data_from(self.api_object)
# ln1 = self.api_object.copy()

ln2 = Line()
ln2.copyData(self.api_object)
ln2.set_data_from(self.api_object)

first_list = self.api_object.locations.data[:index]
second_list = self.api_object.locations.data[index:]
Expand All @@ -457,6 +437,9 @@ def split_Line(self, index):
api_obj.long = self.nodes_list[idx].lon
idx = idx + 1

ln1.bus_from = self.api_object.bus_from
ln2.bus_to = self.api_object.bus_to

l1 = self.editor.add_api_line(ln1, original=False)
l2 = self.editor.add_api_line(ln2, original=False)

Expand All @@ -465,10 +448,7 @@ def split_Line(self, index):
return first_list, second_list
else:
# Handle invalid index
raise ValueError("Index out of range or invalid")

def merge_line(self):
return 0
error_msg("Index out of range or invalid", "split line")

def disable_line(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ def split_line(self):
elif self.second == self.container.substation_from() or self.first == self.container.substation_from():
self.container.insert_new_node_at_position(0)
else:
self.container.insert_new_node_at_position(self.first.index)
if self.first.index > self.second.index:
self.container.insert_new_node_at_position(self.second.index)
elif self.first.index < self.second.index:
self.container.insert_new_node_at_position(self.second.index)

# TODO implement
# self.editor.split_line(line_graphics=self)
Expand Down
55 changes: 16 additions & 39 deletions src/GridCal/Gui/Diagrams/MapWidget/Substation/node_graphic_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self,
# self.api_object: LineLocation = api_object
self.index = index

self.resize(r)
self.resize(r * 10)
self.setAcceptHoverEvents(True) # Enable hover events for the item
self.setFlag(QtWidgets.QGraphicsItem.GraphicsItemFlag.ItemIsMovable) # Allow moving the node
self.setFlag(QtWidgets.QGraphicsItem.GraphicsItemFlag.ItemIsSelectable) # Allow selecting the node
Expand All @@ -88,7 +88,6 @@ def __init__(self,

self.hovered = False
self.enabled = True
self.itemSelected = False

# Create a pen with reduced line width
self.change_pen_width(0.001)
Expand Down Expand Up @@ -173,13 +172,13 @@ def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
Event handler for mouse press events.
"""
super().mousePressEvent(event)

selected_items = self.editor.map.view._scene.selectedItems()
if len(selected_items) < 2:
self.setSelected(True)
if self.enabled:
self.editor.map.view.disableMove = True
if event.button() == Qt.RightButton:
pass
elif event.button() == Qt.LeftButton:
self.selectItem()

def mouseReleaseEvent(self, event):
"""
Expand All @@ -190,11 +189,15 @@ def mouseReleaseEvent(self, event):
self.updateDiagram()
self.editor.map.view._scene.update()

selected_items = self.editor.map.view._scene.selectedItems()
if len(selected_items) < 2:
self.setSelected(True)

def hoverEnterEvent(self, event: QtWidgets.QGraphicsSceneHoverEvent) -> None:
"""
Event handler for when the mouse enters the item.
"""
self.editor.inItem = True
self.editor.map.view.inItem = True
self.hovered = True
self.setNodeColor(QColor(Qt.red), QColor(Qt.red))
QApplication.instance().setOverrideCursor(Qt.PointingHandCursor)
Expand All @@ -203,7 +206,7 @@ def hoverLeaveEvent(self, event: QtWidgets.QGraphicsSceneHoverEvent) -> None:
"""
Event handler for when the mouse leaves the item.
"""
self.editor.inItem = False
self.editor.map.view.inItem = False
self.hovered = False
self.setDefaultColor()
QApplication.instance().restoreOverrideCursor()
Expand All @@ -217,45 +220,22 @@ def contextMenuEvent(self, event: QGraphicsSceneContextMenuEvent):
menu = QMenu()

add_menu_entry(menu=menu,
text="Add",
text="Merge",
icon_path="",
function_ptr=self.AddFunction)
function_ptr=self.MergeFunction)

add_menu_entry(menu=menu,
text="Split",
icon_path="",
icon_path=":/Icons/icons/divide.svg",
function_ptr=self.SplitFunction)

add_menu_entry(menu=menu,
text="Merge",
icon_path="",
function_ptr=self.MergeFunction)

add_menu_entry(menu=menu,
text="Remove",
icon_path="",
text="Delete",
icon_path=":/Icons/icons/delete.svg",
function_ptr=self.RemoveFunction)

menu.exec_(event.screenPos())

def selectItem(self):
"""
:return:
"""
if not self.itemSelected:
self.editor.map.view.selectedItems.append(self)
self.setNodeColor(QColor(Qt.yellow), QColor(Qt.yellow))
self.itemSelected = True

def deSelectItem(self):
"""
:return:
"""
self.itemSelected = False
self.setDefaultColor()

def AddFunction(self):
"""
Expand Down Expand Up @@ -312,10 +292,7 @@ def setDefaultColor(self) -> None:
:return:
"""
# Example: color assignment
if self.itemSelected:
self.setNodeColor(QColor(Qt.yellow), QColor(Qt.yellow))
else:
self.setNodeColor(self.colorInner, self.colorBorder)
self.setNodeColor(self.colorInner, self.colorBorder)

def getPos(self) -> QPointF:
"""
Expand Down
Loading

0 comments on commit b2bfac2

Please sign in to comment.