Skip to content

Commit

Permalink
Merge pull request #124 from NREL/develop-new
Browse files Browse the repository at this point in the history
Develop new
  • Loading branch information
AadilLatif authored Aug 8, 2023
2 parents ce58caf + 829cc4b commit 8d2003d
Show file tree
Hide file tree
Showing 23 changed files with 1,255 additions and 338 deletions.
2 changes: 1 addition & 1 deletion PyDSS/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.2.8"
__version__ = "2.2.9"

from PyDSS.utils.timing_utils import timer_stats_collector
from . import *
125 changes: 98 additions & 27 deletions PyDSS/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,62 +36,141 @@ class VisualizationType(enum.Enum):
NETWORK_GRAPH = "NetworkGraph"

class ControllerType(enum.Enum):
FAULT_CONTROLLER = "FaultController"
GENERATOR_CONTROLLER = "GenController"
MOTOR_STALL = "MotorStall"
MOTOR_STALL_SIMPLE = "MotorStallSimple"
PV_CONTROLLER = "PvController"
PV_DYNAMIC = "PvDynamic"
PV_FREQUENCY_RIDETHROUGH = "PvFrequencyRideThru"
PV_VOLTAGE_RIDETHROUGH = "PvVoltageRideThru"
SOCKET_CONTROLLER = "SocketController"
STORAGE_CONTROLLER = "StorageController"
XMFR_CONTROLLER = "xmfrController"
MOTOR_STALL = "MotorStall"
PV_VOLTAGE_RIDETHROUGH = "PvVoltageRideThru"
FAULT_CONTROLLER = "FaultController"
THERMOSTATIC_LOAD_CONTROLLER = "ThermostaticLoad"
GENERATOR_CONTROLLER = "GenController"

XMFR_CONTROLLER = "xmfrController"

CONTROLLER_TYPES = tuple(x.value for x in ControllerType)
CONFIG_EXT = ".toml"


class ExportMode(enum.Enum):
BY_CLASS = "ExportMode-byClass"
BY_ELEMENT = "ExportMode-byElement"
SUBSCRIPTIONS = 'Subscriptions'
EXPORTS = "Exports"


def filename_from_enum(obj):
return obj.value + CONFIG_EXT


TIMESERIES_PLOT_FILENAME = filename_from_enum(VisualizationType.TIMESERIES_PLOT)
FAULT_CONTROLLER_FILENAME = filename_from_enum(ControllerType.FAULT_CONTROLLER)
GENERATOR_CONTROLLER_FILENAME = filename_from_enum(ControllerType.GENERATOR_CONTROLLER)
MOTOR_STALL_FILENAME = filename_from_enum(ControllerType.MOTOR_STALL)
MOTOR_STALL_SIMPLE_FILENAME = filename_from_enum(ControllerType.MOTOR_STALL_SIMPLE)
PV_CONTROLLER_FILENAME = filename_from_enum(ControllerType.PV_CONTROLLER)
PV_DYNAMIC_FILENAME = filename_from_enum(ControllerType.PV_DYNAMIC)
PV_FREQUENCY_RIDETHROUGH_FILENAME = filename_from_enum(ControllerType.PV_FREQUENCY_RIDETHROUGH)
PV_VOLTAGE_RIDETHROUGH_FILENAME = filename_from_enum(ControllerType.PV_VOLTAGE_RIDETHROUGH)
SOCKET_CONTROLLER_FILENAME = filename_from_enum(ControllerType.SOCKET_CONTROLLER)
STORAGE_CONTROLLER_FILENAME = filename_from_enum(ControllerType.STORAGE_CONTROLLER)
SOCKET_CONTROLLER_FILENAME = filename_from_enum(ControllerType.XMFR_CONTROLLER)
XMFR_CONTROLLER_FILENAME = filename_from_enum(ControllerType.SOCKET_CONTROLLER)
THERMOSTATIC_LOAD_CONTROLLER_FILENAME = filename_from_enum(ControllerType.THERMOSTATIC_LOAD_CONTROLLER)
XMFR_CONTROLLER_FILENAME = filename_from_enum(ControllerType.XMFR_CONTROLLER)

TIMESERIES_PLOT_FILENAME = filename_from_enum(VisualizationType.TIMESERIES_PLOT)
EXPORT_BY_CLASS_FILENAME = filename_from_enum(ExportMode.BY_CLASS)
EXPORT_BY_ELEMENT_FILENAME = filename_from_enum(ExportMode.BY_ELEMENT)
EXPORTS_FILENAME = filename_from_enum(ExportMode.EXPORTS)


DEFAULT_SUBSCRIPTIONS_FILE = os.path.join(
DEFAULT_FAULT_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"ExportLists",
SUBSCRIPTIONS_FILENAME,
"pyControllerList",
FAULT_CONTROLLER_FILENAME,
)
DEFAULT_SIMULATION_SETTINGS_FILE = os.path.join(
DEFAULT_GENERATOR_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
SIMULATION_SETTINGS_FILENAME,
"pyControllerList",
GENERATOR_CONTROLLER_FILENAME,
)
DEFAULT_CONTROLLER_CONFIG_FILE = os.path.join(
DEFAULT_MOTOR_STALL_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"pyControllerList",
MOTOR_STALL_FILENAME,
)
DEFAULT_PV_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"pyControllerList",
PV_CONTROLLER_FILENAME,
)
DEFAULT_PV_DYNAMIC_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"pyControllerList",
PV_DYNAMIC_FILENAME,
)
DEFAULT_PV_FREQUENCY_RIDETHROUGH_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"pyControllerList",
PV_FREQUENCY_RIDETHROUGH_FILENAME,
)
DEFAULT_PV_VOLTAGE_RIDETHROUGH_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"pyControllerList",
PV_VOLTAGE_RIDETHROUGH_FILENAME,
)
DEFAULT_SOCKET_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"pyControllerList",
SOCKET_CONTROLLER_FILENAME,
)
DEFAULT_STORAGE_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"pyControllerList",
STORAGE_CONTROLLER_FILENAME,
)
DEFAULT_THERMOSTATIC_LOAD_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"pyControllerList",
THERMOSTATIC_LOAD_CONTROLLER_FILENAME,
)
DEFAULT_XMFR_CONTROLLER_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"pyControllerList",
XMFR_CONTROLLER_FILENAME,
)

DEFAULT_SUBSCRIPTIONS_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
"ExportLists",
SUBSCRIPTIONS_FILENAME,
)
DEFAULT_SIMULATION_SETTINGS_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
"defaults",
SIMULATION_SETTINGS_FILENAME,
)

DEFAULT_VISUALIIZATION_CONFIG_FILE = os.path.join(
os.path.dirname(getattr(PyDSS, "__path__")[0]),
"PyDSS",
Expand Down Expand Up @@ -133,31 +212,23 @@ def filename_from_enum(obj):
"Monte_Carlo",
MONTE_CARLO_SETTINGS_FILENAME,
)


class ControlMode(enum.Enum):
"""Supported control modes"""
STATIC = "Static"
TIME = "Time"


class DataConversion(enum.Enum):
NONE = "none"
ABS = "abs"
ABS_SUM = "abs_sum"
SUM = "sum"
SUM_REAL = "sum_real"
SUM_ABS_REAL = "sum_abs_real"


class DatasetPropertyType(enum.Enum):
PER_TIME_POINT = "per_time_point" # data is stored at every time point
FILTERED = "filtered" # data is stored after being filtered
METADATA = "metadata" # metadata for another dataset
TIME_STEP = "time_step" # data are time indices, tied to FILTERED
VALUE = "value" # Only a single value is written for each element


class FileFormat(enum.Enum):
"""Supported file formats"""
CSV = "csv"
Expand Down
3 changes: 3 additions & 0 deletions PyDSS/dataset_buffer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Contains DatasetBuffer"""

from cmath import nan
import logging

import numpy as np
Expand All @@ -10,6 +11,7 @@
from PyDSS.utils.utils import make_timestamps



KiB = 1024
MiB = KiB * KiB
GiB = MiB * MiB
Expand Down Expand Up @@ -143,6 +145,7 @@ def max_num_bytes(self):

def write_value(self, value):
"""Write the value to the internal buffer, flushing when full."""

self._buf[self._buf_index] = value
self._buf_index += 1
if self._buf_index == self.chunk_count:
Expand Down
30 changes: 23 additions & 7 deletions PyDSS/defaults/pyControllerList/MotorStall.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
["Load.motor_p1ulv281"]
ratedKW = 7.0
["Load.motor_1"]
Kp1 = 0.0
Np1 = 1.0
Kp2 = 12.0
Np2 = 3.2
Kq1 = 6.0
Nq1 = 2.0
Kq2 = 11.0
Nq2 = 2.5
Tth = 4.0
Frst = 0.20
LFadj = 0.0
Tth1t = 0.5
Tth2t = 1.3
Pfault = 3.0
Qfault = 1.0
Vstall = 0.55
Vbreak = 0.86
Vrstrt = 0.95
Tstall = 0.032
Trestart = 0.3
ratedKW = 7.00
ratedPF = 0.939
Pfault = 2.737
Qfault = 4.743
Vstall = 0.5979
Tprotection = 19.5
Treconnect = 7.5
R_stall_pu = 0.10
8 changes: 8 additions & 0 deletions PyDSS/defaults/pyControllerList/MotorStallSimple.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
["Load.motor_p1ulv281"]
ratedKW = 7.0
ratedPF = 0.939
Pfault = 2.737
Qfault = 4.743
Vstall = 0.5979
Tprotection = 19.5
Treconnect = 7.5
47 changes: 47 additions & 0 deletions PyDSS/defaults/pyControllerList/PvDynamic.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
["Generator.pvgui_mpx000460267"]
DER_ID = "10"
STEADY_STATE = false
RATED_POWER_AC_VA = 1000.0
RATED_POWER_DC_WATTS = 1000.0
MPPT_ENABLE = true
RAMP_ENABLE = true
VOLT_VAR_ENABLE = true
LVRT_ENABLE = true
HVRT_ENABLE = true
LFRT_ENABLE = false
DO_EXTRA_CALCULATIONS = true
use_frequency_estimate = true
jacFlag = true
UPDATE_MODULE_PARAMETRS = false
Np = 500
Ns = 400
Vdcmpp0 = 850.0
Vdcmpp_max = 850.0
Vdcmpp_min = 650.0
UPDATE_INVERTER_PARAMETRS = false
Vdcrated = 650.0
Ioverload = 1.1
Vrmsrated = 197.0
Iramp_max_gradient_imag = 1.0
Iramp_max_gradient_real = 1.0
UPDATE_CIRCUIT_PARAMETRS = false
Rf_actual = 0.002
Lf_actual = 0.000025
C_actual = 3e-05
Z1_actual_real = 0.0019
Z1_actual_imag = 0.0561
R1_actual = 0.0019
X1_actual = 0.0561
UPDATE_CONTROLLER_PARAMETRS = false
Kp_GCC = 12000.0
Ki_GCC = 2000.0
Kp_DC = -2.0
Ki_DC = -10.0
Kp_Q = 0.2
Ki_Q = 10.0
wp = 200000.0
UPDATE_STEADYSTATE_PARAMETRS = false
iaI0 = 0.001
iaR0 = 1.0
maI0 = 0.0
maR0 = 0.89
46 changes: 46 additions & 0 deletions PyDSS/defaults/pyControllerList/PvFrequencyRideThru.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
["Generator.pv_1"]
Category = "test"
Control1 = "None"
Control2 = "None"
Control3 = "None"
kV = nan
kVA = 4
maxKW = 4
KvarLimit = 1.76
"%PCutin" = 10
"%PCutout" = 10
UcalcMode = "Max"
Priority = "Equal"
"Enable PF limit" = false
pfMin = 0.95
"Follow standard" = "1547-2018"
"Ride-through Category" = "Category I"
"Category I Low Frequency Droop" = false
"OF2 - Hz" = 62.0
"OF2 CT - sec" = 0.16
"OF1 - Hz" = 61.2
"OF1 CT - sec" = 300
"UF1 - Hz" = 58.5
"UF1 CT - sec" = 300
"UF2 - Hz" = 56.5
"UF2 CT - sec" = 0.16
"db_UF" = 0.036
"db_OF" = 0.036
"k_UF" = 0.05
"k_OF" = 0.05
"minKW" = 0
"Reconnect deadtime - sec" = 3000
"Reconnect Pmax time - sec" = 300
#"Permissive operation" = "Current limited" # not needed
"May trip operation" = "Ride-Through" #"Trip" #"Ride-Through" #
#"Multiple disturbances" = "Trip" #not needed?
alpha = 0.9
beta = 0.3
uMin = 0.95
uDbMin = 0.97
uDbMax = 1.03
uMax = 1.05
uMinC = 1.06
uMaxC = 1.1
PminVW = 0.5
CurtMode = "Rated Power"
7 changes: 7 additions & 0 deletions PyDSS/defaults/pyControllerList/ThermostaticLoad.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
["Load.load_1"]
Tmax = 30.0
Tmin = 25.0
kw = 5.0
R = 1.0
C = 1.0
mu = 0.9
8 changes: 6 additions & 2 deletions PyDSS/helics_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,14 @@ def updateHelicsSubscriptions(self):
value = helics.helicsInputGetInteger(sub_info['Subscription'])

if value and value != 0:
if value > 1e6 or value < -1e6:
# #print("YO HERE")
value = 1.0

value = value * sub_info['Multiplier']

dssElement = self._objects_by_element[element_name]
dssElement.SetParameter(sub_info['Property'], value)
# #print(sub_info['Property'], value)
dssElement.SetParameter(sub_info['Property'], value)

self._logger.info('Value for "{}.{}" changed to "{}"'.format(
element_name,
Expand Down
2 changes: 1 addition & 1 deletion PyDSS/naerm.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ def naerm_to_pydss(naerm_name):
if __name__ == '__main__':

name = 'PyDSS_x/circuit/heco19021/power_real/double'
print(get_naerm_value([34,45],'PyDSS_x/circuit/heco19021/power_imag/double' ))
#print(get_naerm_value([34,45],'PyDSS_x/circuit/heco19021/power_imag/double' ))
Loading

0 comments on commit 8d2003d

Please sign in to comment.