Skip to content

Commit

Permalink
5.1.27
Browse files Browse the repository at this point in the history
  • Loading branch information
SanPen committed Sep 12, 2024
1 parent 121a9b5 commit e765631
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 281 deletions.
388 changes: 157 additions & 231 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/GridCal/Gui/ProfilesInput/profile_dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ def import_profile(self):
cols = [str(x).strip() for x in self.original_data_frame.columns.values]
self.original_data_frame.columns = cols

# replace NaN
self.original_data_frame.fillna(0, inplace=True)

# set the profile names list
self.profile_names = np.array([str(e).strip() for e in self.original_data_frame.columns.values],
dtype=object)
Expand Down
2 changes: 1 addition & 1 deletion src/GridCal/Gui/TowerBuilder/LineBuilderDialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def add_wire_to_tower(self):
sel_idx = idx.row()

if sel_idx > -1:
selected_wire = self.wires_table.wires[sel_idx].copy()
selected_wire: Wire = self.wires_table.wires[sel_idx].copy()
self.tower_driver.add(WireInTower(selected_wire))
else:
self.msg('Select a wire in the wires catalogue')
Expand Down
55 changes: 39 additions & 16 deletions src/GridCal/Gui/TowerBuilder/table_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from typing import Union
from typing import Union, List
from PySide6 import QtCore
from GridCalEngine.Devices.Branches.wire import Wire
from GridCalEngine.Devices.Branches.overhead_line_type import OverheadLineType, WireInTower
Expand All @@ -32,20 +32,23 @@


class WiresTable(QtCore.QAbstractTableModel):
"""
Wires table for the tower
"""

def __init__(self, parent=None):

QtCore.QAbstractTableModel.__init__(self, parent)

self.header = ['Name', 'R (Ohm/km)', 'GMR (m)', 'max current (kA)']

self.index_prop = {0: 'name', 1: 'r', 2: 'gmr', 3: 'max_current'}
# self.index_prop = {0: 'name', 1: 'r', 2: 'GMR', 3: 'max_current'}

self.converter = {0: str, 1: float, 2: float, 3: float}

self.editable = [True, True, True, True]

self.wires = list()
self.wires: List[Wire] = list()

def add(self, wire: Wire):
"""
Expand Down Expand Up @@ -102,8 +105,17 @@ def data(self,

if index.isValid():
if role == QtCore.Qt.ItemDataRole.DisplayRole:
val = getattr(self.wires[index.row()], self.index_prop[index.column()])
return str(val)
wire = self.wires[index.row()]
if index.column() == 0:
return wire.name
elif index.column() == 1:
return str(wire.R)
elif index.column() == 2:
return str(wire.GMR)
elif index.column() == 3:
return str(wire.max_current)

return ""
return None

def headerData(self,
Expand All @@ -122,17 +134,28 @@ def setData(self, index, value, role=QtCore.Qt.ItemDataRole.DisplayRole):
:param value:
:param role:
"""
if self.editable[index.column()]:
wire = self.wires[index.row()]
attr = self.index_prop[index.column()]

if attr == 'tower_name':
if self.is_used(value):
pass
else:
setattr(wire, attr, self.converter[index.column()](value))
else:
setattr(wire, attr, self.converter[index.column()](value))
# if self.editable[index.column()]:
# wire = self.wires[index.row()]
# # attr = self.index_prop[index.column()]
#
# if attr == 'tower_name':
# if self.is_used(value):
# pass
# else:
# wire.
# setattr(wire, attr, self.converter[index.column()](value))
# else:
# setattr(wire, attr, self.converter[index.column()](value))
#
# wire = self.wires[index.row()]
# if index.column() == 0:
# return wire.name
# elif index.column() == 1:
# return str(wire.R)
# elif index.column() == 2:
# return str(wire.GMR)
# elif index.column() == 3:
# return str(wire.max_current)

return True

Expand Down
2 changes: 1 addition & 1 deletion src/GridCal/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_current_year_ = datetime.datetime.now().year

# do not forget to keep a three-number version!!!
__GridCal_VERSION__ = "5.1.26"
__GridCal_VERSION__ = "5.1.27"

url = 'https://github.com/SanPen/GridCal'

Expand Down
59 changes: 35 additions & 24 deletions src/GridCalEngine/Devices/Branches/overhead_line_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# You should have received a copy of the GNU Lesser General Public License
# 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

from typing import List
import numpy as np
from numpy import pi, log, sqrt
from matplotlib import pyplot as plt
Expand All @@ -34,6 +37,9 @@


class WireInTower:
"""
Wire -> Tower association
"""

def __init__(self, wire: Wire, xpos=0, ypos=0, phase=1):
"""
Expand All @@ -43,22 +49,22 @@ def __init__(self, wire: Wire, xpos=0, ypos=0, phase=1):
:param ypos: y position in m
:param phase: 0->Neutral, 1->A, 2->B, 3->C
"""
self.wire = wire
self.wire: Wire = wire

self.name = wire.name
self.name: str = wire.name

self.xpos = xpos
self.xpos: float = xpos

self.ypos = ypos
self.ypos: float = ypos

self.phase = phase
self.phase: int = phase

self.device_type = DeviceType.WireDevice


class OverheadLineType(EditableDevice):

def __init__(self, name='Tower', idtag=None):
def __init__(self, name='Tower', idtag: str | None = None):
"""
Overhead line editor
:param name: name
Expand All @@ -70,7 +76,7 @@ def __init__(self, name='Tower', idtag=None):
device_type=DeviceType.OverheadLineTypeDevice)

# list of wires in the tower
self.wires_in_tower = list()
self.wires_in_tower: List[WireInTower] = list()

self.Vnom = 1.0

Expand Down Expand Up @@ -184,9 +190,9 @@ def plot(self, ax=None):
if n > 0:
x = np.zeros(n)
y = np.zeros(n)
for i, wire in enumerate(self.wires_in_tower):
x[i] = wire.xpos
y[i] = wire.ypos
for i, wire_tower in enumerate(self.wires_in_tower):
x[i] = wire_tower.xpos
y[i] = wire_tower.ypos

ax.plot(x, y, '.')
ax.set_title('Tower wire position')
Expand Down Expand Up @@ -216,7 +222,7 @@ def check(self, logger=Logger()):
if wire_i.ypos != 0.0:
all_y_zero = False

if wire_i.wire.gmr < 0:
if wire_i.wire.GMR < 0:
logger.add('The wires' + wire_i.name + '(' + str(i) + ') has GRM=0 which is impossible.')
return False

Expand Down Expand Up @@ -262,18 +268,18 @@ def compute(self):

if all_ok:
# Impedances
self.z_abcn, \
self.z_phases_abcn, \
self.z_abc, \
self.z_phases_abc, \
self.z_seq = calc_z_matrix(self.wires_in_tower, f=self.frequency, rho=self.earth_resistivity)
(self.z_abcn,
self.z_phases_abcn,
self.z_abc,
self.z_phases_abc,
self.z_seq) = calc_z_matrix(self.wires_in_tower, f=self.frequency, rho=self.earth_resistivity)

# Admittances
self.y_abcn, \
self.y_phases_abcn, \
self.y_abc, \
self.y_phases_abc, \
self.y_seq = calc_y_matrix(self.wires_in_tower, f=self.frequency, rho=self.earth_resistivity)
(self.y_abcn,
self.y_phases_abcn,
self.y_abc,
self.y_phases_abc,
self.y_seq) = calc_y_matrix(self.wires_in_tower, f=self.frequency, rho=self.earth_resistivity)

# compute the tower rating in kA
self.Imax = self.compute_rating()
Expand Down Expand Up @@ -330,7 +336,7 @@ def get_values(self, Sbase, length):

return R1, X1, B1, R0, X0, B0, rate

def __str__(self):
def __str__(self) -> str:
return self.name


Expand Down Expand Up @@ -510,7 +516,12 @@ def calc_z_matrix(wires: list, f=50, rho=100):
for i, wire_i in enumerate(wires):

# self impedance
z_prim[i, i] = z_ii(r_i=wire_i.wire.r, x_i=wire_i.wire.x, h_i=wire_i.ypos, gmr_i=wire_i.wire.gmr, f=f, rho=rho)
z_prim[i, i] = z_ii(r_i=wire_i.wire.R,
x_i=wire_i.wire.X,
h_i=wire_i.ypos,
gmr_i=wire_i.wire.GMR,
f=f,
rho=rho)

# mutual impedances
for j, wire_j in enumerate(wires):
Expand Down Expand Up @@ -583,7 +594,7 @@ def calc_y_matrix(wires: list, f=50, rho=100):

# self impedance
if wire_i.ypos > 0:
p_prim[i, i] = one_two_pi_e0 * log(2 * wire_i.ypos / (wire_i.wire.gmr + 1e-12))
p_prim[i, i] = one_two_pi_e0 * log(2 * wire_i.ypos / (wire_i.wire.GMR + 1e-12))
else:
p_prim[i, i] = 0
print(wire_i.name, 'has y=0 !')
Expand Down
10 changes: 7 additions & 3 deletions src/GridCalEngine/Devices/Branches/wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ def __init__(self, name='', idtag: Union[str, None] = None,
max_current: float = 1.0,
stranding: str = "",
material: str = "",
diameter: float = 0.0):
diameter: float = 0.0,
code: str = ""):
"""
Wire definition
:param name: Name of the wire type
:param gmr: Geometric Mean Radius (m)
:param r: Resistance per unit length (Ohm / km)
:param x: Reactance per unit length (Ohm / km)
:param max_current: Maximum current of the conductor in (kA)
:param stranding: Stranding of the wire type
:param material: Material of the wire type
:param diameter: Diameter of the wire type
:param code: Code of the wire type
"""

EditableDevice.__init__(self,
name=name,
idtag=idtag,
code='',
code=code,
device_type=DeviceType.WireDevice)

# self.wire_name = name
Expand Down
10 changes: 10 additions & 0 deletions src/GridCalEngine/Devices/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,13 @@ def set_sparse_data_from_data(self, indptr, data):
:param data: array of data values
"""
self._sparse_array.set_sparse_data_from_data(indptr=indptr, data=data)

def fix_nan(self, default_value: float = 0.0):
"""
Replace NaN values with default value in-place
:param default_value: some value to replace the NaN with
"""
if self.dtype == float:
if not self._is_sparse:
if self._dense_array is not None:
np.nan_to_num(self._dense_array, nan=default_value) # this is supposed to happen in-place
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from GridCalEngine.basic_structures import IntVec, StrVec
from GridCalEngine.enumerations import EngineType, ContingencyMethod
from GridCalEngine.Devices.multi_circuit import MultiCircuit
from GridCalEngine.Simulations.LinearFactors.linear_analysis import LinearMultiContingencies
from GridCalEngine.Simulations.LinearFactors.linear_analysis_options import LinearAnalysisOptions
from GridCalEngine.Simulations.LinearFactors.linear_analysis_ts_driver import LinearAnalysisTimeSeriesDriver
from GridCalEngine.Simulations.ContingencyAnalysis.contingency_analysis_driver import (ContingencyAnalysisOptions,
Expand Down Expand Up @@ -107,8 +106,6 @@ def run_contingency_analysis(self) -> ContingencyAnalysisTimeSeriesResults:
clustering_results=self.clustering_results
)

# linear_multiple_contingencies = LinearMultiContingencies(grid=self.grid)

cdriver = ContingencyAnalysisDriver(grid=self.grid,
options=self.options,
linear_multiple_contingencies=None # it is computed inside
Expand Down
2 changes: 1 addition & 1 deletion src/GridCalEngine/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_current_year_ = datetime.datetime.now().year

# do not forget to keep a three-number version!!!
__GridCalEngine_VERSION__ = "5.1.26"
__GridCalEngine_VERSION__ = "5.1.27"

url = 'https://github.com/SanPen/GridCal'

Expand Down
2 changes: 1 addition & 1 deletion src/GridCalServer/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_current_year_ = datetime.datetime.now().year

# do not forget to keep a three-number version!!!
__GridCalServer_VERSION__ = "5.1.26"
__GridCalServer_VERSION__ = "5.1.27"

url = 'https://github.com/SanPen/GridCal'

Expand Down

0 comments on commit e765631

Please sign in to comment.