Skip to content

Commit

Permalink
Merge branch 'refs/heads/devel' into devel_convert_map_widget
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/workspace.xml
  • Loading branch information
SanPen committed Jul 8, 2024
2 parents 9fc00e4 + 909aa4e commit 38f28db
Show file tree
Hide file tree
Showing 37 changed files with 93 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ def update_nexus(self, pos):
Update the nexus line that joins the parent and this object
:param pos: position of this object
"""
parent = self.parentItem()
rect = parent.rect()
term = parent.get_terminal()
parent_pt = self.parentItem().get_nexus_point()
self.nexus.setLine(
pos.x() + self.w / 2,
pos.y(),
parent.x() + rect.width() / 2,
parent.y() + rect.height() + term.h / 2,
parent_pt.x(),
parent_pt.y(),
)
self.setZValue(-1)
self.nexus.setZValue(-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import numpy as np
from typing import Union, TYPE_CHECKING, List, Dict
from PySide6 import QtWidgets
from PySide6.QtCore import Qt, QPoint, QRectF, QRect
from PySide6.QtCore import Qt, QPoint, QRectF, QRect, QPointF
from PySide6.QtGui import QPen, QCursor, QIcon, QPixmap, QBrush, QColor
from PySide6.QtWidgets import QMenu, QGraphicsSceneMouseEvent

Expand Down Expand Up @@ -145,6 +145,14 @@ def __init__(self,

self.set_position(x, y)

def get_nexus_point(self) -> QPointF:
"""
Get the connection point for the chldren nexus line
:return: QPointF
"""
return QPointF(self.x() + self.rect().width() / 2.0,
self.y() + self.rect().height() + self._terminal.h / 2.0)

def recolour_mode(self) -> None:
"""
Change the colour according to the system theme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import numpy as np
from typing import Union, TYPE_CHECKING, List, Dict
from PySide6 import QtWidgets
from PySide6.QtCore import Qt, QPoint, QRectF, QRect
from PySide6.QtCore import Qt, QPoint, QRectF, QRect, QPointF
from PySide6.QtGui import QPen, QCursor, QIcon, QPixmap, QBrush, QColor
from PySide6.QtWidgets import QMenu, QGraphicsSceneMouseEvent

Expand Down Expand Up @@ -133,6 +133,14 @@ def __init__(self,

self.set_position(x, y)

def get_nexus_point(self) -> QPointF:
"""
Get the connection point for the chldren nexus line
:return: QPointF
"""
return QPointF(self.x() + self.rect().width() / 2.0,
self.y() + self.rect().height() + self._terminal.h / 2.0)

def recolour_mode(self) -> None:
"""
Change the colour according to the system theme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import numpy as np
from typing import Union, TYPE_CHECKING, List, Dict
from PySide6 import QtWidgets
from PySide6.QtCore import Qt, QPoint
from PySide6.QtCore import Qt, QPoint, QPointF
from PySide6.QtGui import QPen, QCursor, QIcon, QPixmap
from PySide6.QtWidgets import QMenu, QGraphicsSceneMouseEvent

Expand Down Expand Up @@ -108,6 +108,7 @@ def __init__(self,
self._terminal = RoundTerminalItem('s', parent=self, editor=self.editor, h=20, w=20) # , h=self.h))
self._terminal.setPen(QPen(Qt.transparent, self.pen_width, self.style, Qt.RoundCap, Qt.RoundJoin))
self._terminal.setPos(QPoint(15, 15))
self._terminal_mid_point = QPoint(20, 20) # (15, 15) + (20, 20) / 2

self.setPen(QPen(Qt.transparent, self.pen_width, self.style))
self.setBrush(Qt.transparent)
Expand All @@ -118,6 +119,14 @@ def __init__(self,
self.set_position(x, y)
self.setRect(0.0, 0.0, self.w, self.h)

def get_nexus_point(self) -> QPointF:
"""
Get the connection point for the chldren nexus line
:return: QPointF
"""
return QPointF(self.x() + self._terminal_mid_point.x(),
self.y() + self._terminal_mid_point.y())

def recolour_mode(self) -> None:
"""
Change the colour according to the system theme
Expand Down
8 changes: 2 additions & 6 deletions src/GridCal/Gui/Main/SubClasses/Settings/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def change_theme_mode(self) -> None:
additional_qss="QToolTip {color: white; background-color: black; border: 0px; }")

# note: The 0px border on the tooltips allow it to render properly

diagram = self.get_selected_diagram_widget()
if diagram is not None:
for diagram in self.diagram_widgets_list:
if isinstance(diagram, SchematicWidget):
diagram.set_dark_mode()

Expand All @@ -131,9 +129,7 @@ def change_theme_mode(self) -> None:
additional_qss="QToolTip {color: black; background-color: white; border: 0px;}")

# note: The 0px border on the tooltips allow it to render properly

diagram = self.get_selected_diagram_widget()
if diagram is not None:
for diagram in self.diagram_widgets_list:
if isinstance(diagram, SchematicWidget):
diagram.set_light_mode()

Expand Down
6 changes: 3 additions & 3 deletions src/GridCalEngine/DataStructures/numerical_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,7 +1995,8 @@ def compile_numerical_circuit_at(circuit: MultiCircuit,
opf_results: Union[OptimalPowerFlowResults, None] = None,
use_stored_guess=False,
bus_dict: Union[Dict[Bus, int], None] = None,
areas_dict: Union[Dict[Area, int], None] = None) -> NumericalCircuit:
areas_dict: Union[Dict[Area, int], None] = None,
logger=Logger()) -> NumericalCircuit:
"""
Compile a NumericalCircuit from a MultiCircuit
:param circuit: MultiCircuit instance
Expand All @@ -2006,11 +2007,10 @@ def compile_numerical_circuit_at(circuit: MultiCircuit,
:param use_stored_guess: use the storage voltage guess?
:param bus_dict (optional) Dict[Bus, int] dictionary
:param areas_dict (optional) Dict[Area, int] dictionary
:param logger: Logger instance
:return: NumericalCircuit instance
"""

logger = Logger()

if circuit.get_connectivity_nodes_number() + circuit.get_switches_number():
# process topology, this
circuit.process_topology_at(t_idx=t_idx, logger=logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def run(self):
idx2b = self.options.bus_idx_to

# declare the numerical circuit
nc = compile_numerical_circuit_at(circuit=self.grid, t_idx=None)
nc = compile_numerical_circuit_at(circuit=self.grid, t_idx=None, logger=self.logger)

# declare the linear analysis
linear = LinearAnalysis(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def run(self) -> None:
la_driver.run()

# get the branch indices to analyze
nc = compile_numerical_circuit_at(self.grid)
nc = compile_numerical_circuit_at(self.grid, logger=self.logger)
br_idx = nc.branch_data.get_monitor_enabled_indices()
con_br_idx = nc.branch_data.get_contingency_enabled_indices()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def run_at(self, t_idx: Union[int, None] = None) -> ContinuationPowerFlowResults
t_idx=t_idx,
apply_temperature=self.pf_options.apply_temperature_correction,
branch_tolerance_mode=self.pf_options.branch_impedance_tolerance_mode,
opf_results=self.opf_results)
opf_results=self.opf_results,
logger=self.logger)

islands = nc.split_into_islands(ignore_single_node_islands=self.pf_options.ignore_single_node_islands)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def run(self):
nc = compile_numerical_circuit_at(
circuit=self.grid,
t_idx=None,
opf_results=self.opf_results
opf_results=self.opf_results,
logger=self.logger
)

analysis = LinearAnalysis(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def run(self):

nc = compile_numerical_circuit_at(circuit=self.grid,
t_idx=t,
opf_results=self.opf_time_series_results)
opf_results=self.opf_time_series_results,
logger=self.logger)

driver_ = LinearAnalysis(
numerical_circuit=nc,
Expand Down
3 changes: 2 additions & 1 deletion src/GridCalEngine/Simulations/NTC/ntc_opf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,8 @@ def run_linear_ntc_opf_ts(grid: MultiCircuit,
nc: NumericalCircuit = compile_numerical_circuit_at(circuit=grid,
t_idx=t, # yes, this is not a bug
bus_dict=bus_dict,
areas_dict=areas_dict)
areas_dict=areas_dict,
logger=logger)

# formulate the bus angles ---------------------------------------------------------------------------------
for k in range(nc.bus_data.nbus):
Expand Down
2 changes: 1 addition & 1 deletion src/GridCalEngine/Simulations/NTC/ntc_ts_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def opf(self):
print('Compiling cicuit...')

tm0 = time.time()
nc = compile_numerical_circuit_at(self.grid, t_idx=None)
nc = compile_numerical_circuit_at(self.grid, t_idx=None, logger=self.logger)
self.logger.add_info(f'Time circuit compiled in {time.time() - tm0:.2f} scs')
print(f'Time circuit compiled in {time.time() - tm0:.2f} scs')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ def run_nonlinear_opf(grid: MultiCircuit,
"""

# compile the system
nc = compile_numerical_circuit_at(circuit=grid, t_idx=t_idx)
nc = compile_numerical_circuit_at(circuit=grid, t_idx=t_idx, logger=logger)

if pf_init:
if Sbus_pf0 is None:
Expand Down
3 changes: 2 additions & 1 deletion src/GridCalEngine/Simulations/OPF/linear_opf_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,8 @@ def run_linear_opf_ts(grid: MultiCircuit,
nc: NumericalCircuit = compile_numerical_circuit_at(circuit=grid,
t_idx=global_t_idx, # yes, this is not a bug
bus_dict=bus_dict,
areas_dict=areas_dict)
areas_dict=areas_dict,
logger=logger)

# formulate the bus angles ---------------------------------------------------------------------------------
for k in range(nc.bus_data.nbus):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,13 +856,12 @@ def run_nonlinear_opf(grid: MultiCircuit,
:param Sbus_pf0: Sbus initial solution
:param voltage_pf0: Voltage initial solution
:param plot_error: Plot the error evolution
:param use_bound_slacks: add voltage module and branch loading slack variables? (default true)
:param logger: Logger object
:return: NonlinearOPFResults
"""

# compile the system
nc = compile_numerical_circuit_at(circuit=grid, t_idx=t_idx)
nc = compile_numerical_circuit_at(circuit=grid, t_idx=t_idx, logger=logger)

if pf_init:
if Sbus_pf0 is None:
Expand Down
3 changes: 2 additions & 1 deletion src/GridCalEngine/Simulations/PowerFlow/power_flow_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@ def multi_island_pf(multi_circuit: MultiCircuit,
opf_results=opf_results,
use_stored_guess=options.use_stored_guess,
bus_dict=bus_dict,
areas_dict=areas_dict
areas_dict=areas_dict,
logger=logger,
)
# print("Normal PowerFlow")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def run(self):
t_idx=None,
apply_temperature=self.pf_options.apply_temperature_correction,
branch_tolerance_mode=self.pf_options.branch_impedance_tolerance_mode,
opf_results=self.opf_results)
opf_results=self.opf_results,
logger=self.logger)

calculation_inputs = numerical_circuit.split_into_islands(
ignore_single_node_islands=self.pf_options.ignore_single_node_islands)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ def multi_island_sigma(multi_circuit: MultiCircuit,
nc = compile_numerical_circuit_at(circuit=multi_circuit,
apply_temperature=options.apply_temperature_correction,
branch_tolerance_mode=options.branch_impedance_tolerance_mode,
opf_results=None)
opf_results=None,
logger=logger)
results.bus_names = nc.bus_data.names

calculation_inputs = nc.split_into_islands(ignore_single_node_islands=options.ignore_single_node_islands)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def run(self):
n = len(self.grid.buses)
m = self.grid.get_branch_number()

numerical_circuit = compile_numerical_circuit_at(self.grid)
numerical_circuit = compile_numerical_circuit_at(self.grid, logger=self.logger)
self.results = StateEstimationResults(n=n,
m=m,
bus_names=numerical_circuit.bus_names,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def run(self):

# compile
# print('Compiling...', end='')
nc = compile_numerical_circuit_at(self.grid, t_idx=None)
nc = compile_numerical_circuit_at(self.grid, t_idx=None, logger=self.logger)
calculation_inputs = nc.split_into_islands(ignore_single_node_islands=self.options.ignore_single_node_islands)

self.results = CascadingResults(self.cascade_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def run(self):
self.tic()

# compile the numerical circuit
numerical_circuit = compile_numerical_circuit_at(self.grid, t_idx=None)
numerical_circuit = compile_numerical_circuit_at(self.grid, t_idx=None, logger=self.logger)

evt = get_reliability_scenario(numerical_circuit,
horizon=1)
Expand Down
11 changes: 7 additions & 4 deletions src/GridCalEngine/Simulations/Stochastic/reliability_iterable.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from GridCalEngine.Simulations.PowerFlow.power_flow_worker import PowerFlowOptions, multi_island_pf_nc, PowerFlowResults
from GridCalEngine.Devices.multi_circuit import MultiCircuit
from GridCalEngine.DataStructures.numerical_circuit import compile_numerical_circuit_at
from GridCalEngine.basic_structures import Vec, IntVec
from GridCalEngine.basic_structures import Vec, IntVec,Logger


def get_transition_probabilities(lbda: Vec, mu: Vec) -> Tuple[Vec, Vec]:
Expand All @@ -46,7 +46,8 @@ class ReliabilityIterable:

def __init__(self, grid: MultiCircuit,
forced_mttf: Union[None, float] = None,
forced_mttr: Union[None, float] = None):
forced_mttr: Union[None, float] = None,
logger: Logger = Logger()):
"""
:param grid: MultiCircuit
Expand All @@ -61,11 +62,13 @@ def __init__(self, grid: MultiCircuit,
# time index
self.t_idx = 0

self.logger = logger

# declare the power flow options
self.pf_options = PowerFlowOptions()

# compile the time step
nc = compile_numerical_circuit_at(self.grid, t_idx=None)
nc = compile_numerical_circuit_at(self.grid, t_idx=None, logger=logger)

# compute the transition probabilities
if forced_mttf is None:
Expand All @@ -90,7 +93,7 @@ def __next__(self) -> Tuple[IntVec, PowerFlowResults]:
raise StopIteration

# compile the time step
nc = compile_numerical_circuit_at(self.grid, t_idx=self.t_idx)
nc = compile_numerical_circuit_at(self.grid, t_idx=self.t_idx, logger=self.logger)

# determine the Markov states
p = np.random.random(nc.nbr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def run_single_thread_mc(self, use_lhs=False):
t_idx=None,
apply_temperature=False,
branch_tolerance_mode=BranchImpedanceMode.Specified,
opf_results=self.opf_time_series_results)
opf_results=self.opf_time_series_results,
logger=self.logger)

mc_results = StochasticPowerFlowResults(n=numerical_circuit.nbus,
m=numerical_circuit.nbr,
Expand Down
Loading

0 comments on commit 38f28db

Please sign in to comment.