diff --git a/src/ditto/writers/opendss/__init__.py b/src/ditto/writers/opendss/__init__.py index b22cfbc..ee0c28a 100644 --- a/src/ditto/writers/opendss/__init__.py +++ b/src/ditto/writers/opendss/__init__.py @@ -34,3 +34,10 @@ ) from ditto.writers.opendss.profile import ProfileMapper from ditto.writers.opendss.components.distribution_solar import DistributionSolarMapper + +from ditto.writers.opendss.components.matrix_impedance_recloser import ( + MatrixImpedanceRecloserMapper, +) +from ditto.writers.opendss.equipment.matrix_impedance_recloser_equipment import ( + MatrixImpedanceRecloserEquipmentMapper, +) diff --git a/src/ditto/writers/opendss/components/distribution_branch.py b/src/ditto/writers/opendss/components/distribution_branch.py index 1e0a2ca..a9fd852 100644 --- a/src/ditto/writers/opendss/components/distribution_branch.py +++ b/src/ditto/writers/opendss/components/distribution_branch.py @@ -16,11 +16,11 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.LINES_FILE.value def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_buses(self): - self.opendss_dict["Bus1"] = self.model.buses[0].name - self.opendss_dict["Bus2"] = self.model.buses[1].name + self.opendss_dict["Bus1"] = self.get_opendss_safe_name(self.model.buses[0].name) + self.opendss_dict["Bus2"] = self.get_opendss_safe_name(self.model.buses[1].name) for phase in self.model.phases: if phase != Phase.N: self.opendss_dict["Bus1"] += self.phase_map[phase] diff --git a/src/ditto/writers/opendss/components/distribution_bus.py b/src/ditto/writers/opendss/components/distribution_bus.py index 5c32a55..f7e6858 100644 --- a/src/ditto/writers/opendss/components/distribution_bus.py +++ b/src/ditto/writers/opendss/components/distribution_bus.py @@ -14,7 +14,7 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.COORDINATE_FILE.value def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_coordinate(self): if hasattr(self.model.coordinate, "x"): diff --git a/src/ditto/writers/opendss/components/distribution_capacitor.py b/src/ditto/writers/opendss/components/distribution_capacitor.py index 2e76933..318f1bf 100644 --- a/src/ditto/writers/opendss/components/distribution_capacitor.py +++ b/src/ditto/writers/opendss/components/distribution_capacitor.py @@ -19,10 +19,10 @@ def map_in_service(self): self.opendss_dict["enabled"] = self.model.in_service def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_bus(self): - self.opendss_dict["Bus1"] = self.model.bus.name + self.opendss_dict["Bus1"] = self.get_opendss_safe_name(self.model.bus.name) num_phases = len(self.model.phases) for phase in self.model.phases: self.opendss_dict["Bus1"] += self.phase_map[phase] diff --git a/src/ditto/writers/opendss/components/distribution_load.py b/src/ditto/writers/opendss/components/distribution_load.py index 49ae2fa..3d9a0bf 100644 --- a/src/ditto/writers/opendss/components/distribution_load.py +++ b/src/ditto/writers/opendss/components/distribution_load.py @@ -20,7 +20,7 @@ def map_in_service(self): self.opendss_dict["enabled"] = self.model.in_service def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) profile_name = self.get_profile_name(self.model) if profile_name: @@ -28,7 +28,7 @@ def map_name(self): def map_bus(self): num_phases = len(self.model.phases) - self.opendss_dict["Bus1"] = self.model.bus.name + self.opendss_dict["Bus1"] = self.get_opendss_safe_name(self.model.bus.name) for phase in self.model.phases: self.opendss_dict["Bus1"] += self.phase_map[phase] # TODO: Should we include the phases its connected to here? diff --git a/src/ditto/writers/opendss/components/distribution_regulator.py b/src/ditto/writers/opendss/components/distribution_regulator.py index f5e81dd..cfd9098 100644 --- a/src/ditto/writers/opendss/components/distribution_regulator.py +++ b/src/ditto/writers/opendss/components/distribution_regulator.py @@ -17,7 +17,7 @@ def map_in_service(self): self.opendss_dict["enabled"] = self.model.in_service def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_buses(self): buses = [] @@ -27,7 +27,7 @@ def map_buses(self): if is_center_tapped: for i in range(len(self.model.buses)): bus = self.model.buses[i] - buses.append(bus.name) + buses.append(self.get_opendss_safe_name(bus.name)) dss_phases = "" for phase in self.model.winding_phases[0]: dss_phases += self.phase_map[phase] @@ -37,7 +37,7 @@ def map_buses(self): else: for bus in self.model.buses: - buses.append(bus.name) + buses.append(self.get_opendss_safe_name(bus.name)) for winding_phases in self.model.winding_phases: dss_phases = "" for phase in winding_phases: @@ -54,7 +54,7 @@ def map_winding_phases(self): def map_equipment(self): equipment = self.model.equipment - self.opendss_dict["XfmrCode"] = equipment.name + self.opendss_dict["XfmrCode"] = self.get_opendss_safe_name(equipment.name) def map_controllers(self): ... diff --git a/src/ditto/writers/opendss/components/distribution_solar.py b/src/ditto/writers/opendss/components/distribution_solar.py index 1ade817..f626c46 100644 --- a/src/ditto/writers/opendss/components/distribution_solar.py +++ b/src/ditto/writers/opendss/components/distribution_solar.py @@ -18,7 +18,7 @@ def map_in_service(self): self.opendss_dict["enabled"] = self.model.in_service def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) profile_name = self.get_profile_name(self.model) if profile_name: @@ -26,7 +26,7 @@ def map_name(self): def map_bus(self): num_phases = len(self.model.phases) - self.opendss_dict["Bus1"] = self.model.bus.name + self.opendss_dict["Bus1"] = self.get_opendss_safe_name(self.model.bus.name) for phase in self.model.phases: self.opendss_dict["Bus1"] += self.phase_map[phase] # TODO: Should we include the phases its connected to here? diff --git a/src/ditto/writers/opendss/components/distribution_transformer.py b/src/ditto/writers/opendss/components/distribution_transformer.py index f860599..1809d97 100644 --- a/src/ditto/writers/opendss/components/distribution_transformer.py +++ b/src/ditto/writers/opendss/components/distribution_transformer.py @@ -18,7 +18,7 @@ def map_in_service(self): self.opendss_dict["enabled"] = self.model.in_service def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_buses(self): buses = [] @@ -28,7 +28,7 @@ def map_buses(self): if is_center_tapped: for i in range(len(self.model.buses)): bus = self.model.buses[i] - buses.append(bus.name) + buses.append(self.get_opendss_safe_name(bus.name)) dss_phases = "" for phase in self.model.winding_phases[0]: dss_phases += self.phase_map[phase] @@ -38,7 +38,7 @@ def map_buses(self): else: for bus in self.model.buses: - buses.append(bus.name) + buses.append(self.get_opendss_safe_name(bus.name)) for winding_phases in self.model.winding_phases: dss_phases = "" for phase in winding_phases: @@ -55,4 +55,4 @@ def map_winding_phases(self): def map_equipment(self): equipment = self.model.equipment - self.opendss_dict["XfmrCode"] = equipment.name + self.opendss_dict["XfmrCode"] = self.get_opendss_safe_name(equipment.name) diff --git a/src/ditto/writers/opendss/components/distribution_vsource.py b/src/ditto/writers/opendss/components/distribution_vsource.py index 1dddd56..d1d7326 100644 --- a/src/ditto/writers/opendss/components/distribution_vsource.py +++ b/src/ditto/writers/opendss/components/distribution_vsource.py @@ -19,14 +19,14 @@ def map_in_service(self): self.opendss_dict["enabled"] = self.model.in_service def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) profile_name = self.get_profile_name(self.model) if profile_name: self.opendss_dict["Yearly"] = profile_name def map_bus(self): - self.opendss_dict["Bus1"] = self.model.bus.name + self.opendss_dict["Bus1"] = self.get_opendss_safe_name(self.model.bus.name) for phase in self.model.phases: self.opendss_dict["Bus1"] += self.phase_map[phase] @@ -71,7 +71,17 @@ def map_equipment(self): else: v_mag = voltage.magnitude - v_nom = rated_voltage.magnitude if num_phases == 1 else rated_voltage.magnitude * 1.732 + if self.model.bus.voltage_type == VoltageTypes.LINE_TO_GROUND: + if num_phases == 1: + v_nom = rated_voltage.magnitude + else: + v_nom = rated_voltage.magnitude * 1.732 + else: + if num_phases == 1: + v_nom = rated_voltage.magnitude / 1.732 + else: + v_nom = rated_voltage.magnitude + self.opendss_dict["Angle"] = angle.magnitude self.opendss_dict["pu"] = v_mag / v_nom self.opendss_dict["BasekV"] = v_nom diff --git a/src/ditto/writers/opendss/components/geometry_branch.py b/src/ditto/writers/opendss/components/geometry_branch.py index 606c8fe..3b6a3af 100644 --- a/src/ditto/writers/opendss/components/geometry_branch.py +++ b/src/ditto/writers/opendss/components/geometry_branch.py @@ -15,7 +15,7 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.LINES_FILE.value def map_equipment(self): - self.opendss_dict["Geometry"] = self.model.equipment.name + self.opendss_dict["Geometry"] = self.get_opendss_safe_name(self.model.equipment.name) def map_in_service(self): self.opendss_dict["enabled"] = self.model.in_service diff --git a/src/ditto/writers/opendss/components/matrix_impedance_branch.py b/src/ditto/writers/opendss/components/matrix_impedance_branch.py index 0a09e60..ee1ebf0 100644 --- a/src/ditto/writers/opendss/components/matrix_impedance_branch.py +++ b/src/ditto/writers/opendss/components/matrix_impedance_branch.py @@ -14,7 +14,7 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.LINES_FILE.value def map_equipment(self): - self.opendss_dict["LineCode"] = self.model.equipment.name + self.opendss_dict["LineCode"] = self.get_opendss_safe_name(self.model.equipment.name) def map_in_service(self): self.opendss_dict["enabled"] = self.model.in_service diff --git a/src/ditto/writers/opendss/components/matrix_impedance_fuse.py b/src/ditto/writers/opendss/components/matrix_impedance_fuse.py index ffcfe03..5d0274b 100644 --- a/src/ditto/writers/opendss/components/matrix_impedance_fuse.py +++ b/src/ditto/writers/opendss/components/matrix_impedance_fuse.py @@ -15,8 +15,11 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.FUSE_FILE.value def map_equipment(self): - self.opendss_dict["LineCode"] = self.model.equipment.name + self.opendss_dict["LineCode"] = self.get_opendss_safe_name(self.model.equipment.name) def map_is_closed(self): # Require every phase to be enabled for the OpenDSS line to be enabled. self.opendss_dict["Switch"] = "true" + + def map_in_service(self): + self.opendss_dict["enabled"] = self.model.in_service diff --git a/src/ditto/writers/opendss/components/matrix_impedance_recloser.py b/src/ditto/writers/opendss/components/matrix_impedance_recloser.py new file mode 100644 index 0000000..19cb40e --- /dev/null +++ b/src/ditto/writers/opendss/components/matrix_impedance_recloser.py @@ -0,0 +1,28 @@ +from gdm.distribution import DistributionSystem +from infrasys import Component + + +from ditto.writers.opendss.components.distribution_branch import DistributionBranchMapper +from ditto.enumerations import OpenDSSFileTypes + + +class MatrixImpedanceRecloserMapper(DistributionBranchMapper): + def __init__(self, model: Component, system: DistributionSystem): + super().__init__(model, system) + + altdss_name = "Line_LineCode" + altdss_composition_name = "Line" + opendss_file = OpenDSSFileTypes.SWITCH_FILE.value + + def map_equipment(self): + self.opendss_dict["LineCode"] = self.get_opendss_safe_name(self.model.equipment.name) + + def map_is_closed(self): + # Require every phase to be enabled for the OpenDSS line to be enabled. + self.opendss_dict["Switch"] = "true" + + def map_in_service(self): + self.opendss_dict["enabled"] = self.model.in_service + + def map_controller(self): + pass diff --git a/src/ditto/writers/opendss/components/matrix_impedance_switch.py b/src/ditto/writers/opendss/components/matrix_impedance_switch.py index 1b0737f..7d01b25 100644 --- a/src/ditto/writers/opendss/components/matrix_impedance_switch.py +++ b/src/ditto/writers/opendss/components/matrix_impedance_switch.py @@ -15,7 +15,7 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.SWITCH_FILE.value def map_equipment(self): - self.opendss_dict["LineCode"] = self.model.equipment.name + self.opendss_dict["LineCode"] = self.get_opendss_safe_name(self.model.equipment.name) def map_is_closed(self): # Require every phase to be enabled for the OpenDSS line to be enabled. diff --git a/src/ditto/writers/opendss/components/sequence_impedance_branch.py b/src/ditto/writers/opendss/components/sequence_impedance_branch.py index 47647a9..09d08df 100644 --- a/src/ditto/writers/opendss/components/sequence_impedance_branch.py +++ b/src/ditto/writers/opendss/components/sequence_impedance_branch.py @@ -15,7 +15,7 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.LINES_FILE.value def map_equipment(self): - self.opendss_dict["LineCode"] = self.model.equipment.name + self.opendss_dict["LineCode"] = self.get_opendss_safe_name(self.model.equipment.name) def map_in_service(self): self.opendss_dict["enabled"] = self.model.in_service diff --git a/src/ditto/writers/opendss/controllers/distribution_regulator_controller.py b/src/ditto/writers/opendss/controllers/distribution_regulator_controller.py index 77fb371..cd99164 100644 --- a/src/ditto/writers/opendss/controllers/distribution_regulator_controller.py +++ b/src/ditto/writers/opendss/controllers/distribution_regulator_controller.py @@ -17,8 +17,8 @@ def __init__(self, model: RegulatorController, xfmr_name: str, system: Distribut self.xfmr_name = xfmr_name def map_name(self): - self.opendss_dict["Name"] = self.model.name - self.opendss_dict["Transformer"] = self.xfmr_name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) + self.opendss_dict["Transformer"] = self.get_opendss_safe_name(self.xfmr_name) def map_delay(self): self.opendss_dict["TapDelay"] = self.model.delay.to("s").magnitude @@ -59,7 +59,7 @@ def map_bandwidth(self): def map_controlled_bus(self): self.opendss_dict[ "Bus" - ] = f"{self.model.controlled_bus.name}{self.phase_map[self.model.controlled_phase]}" + ] = f"{self.get_opendss_safe_name(self.model.controlled_bus.name)}{self.phase_map[self.model.controlled_phase]}" def map_controlled_phase(self): ... diff --git a/src/ditto/writers/opendss/equipment/bare_conductor_equipment.py b/src/ditto/writers/opendss/equipment/bare_conductor_equipment.py index d42f874..e4c0067 100644 --- a/src/ditto/writers/opendss/equipment/bare_conductor_equipment.py +++ b/src/ditto/writers/opendss/equipment/bare_conductor_equipment.py @@ -14,7 +14,7 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.WIRES_FILE.value def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_conductor_diameter(self): self.opendss_dict["Radius"] = self.model.conductor_diameter.magnitude / 2 diff --git a/src/ditto/writers/opendss/equipment/distribution_transformer_equipment.py b/src/ditto/writers/opendss/equipment/distribution_transformer_equipment.py index fdf154a..f51adf2 100644 --- a/src/ditto/writers/opendss/equipment/distribution_transformer_equipment.py +++ b/src/ditto/writers/opendss/equipment/distribution_transformer_equipment.py @@ -15,7 +15,7 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.TRANSFORMERS_FILE.value def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_pct_no_load_loss(self): self.opendss_dict["pctNoLoadLoss"] = self.model.pct_no_load_loss @@ -44,13 +44,20 @@ def map_windings(self): num_phases = winding.num_phases # rated_voltage nom_voltage = winding.rated_voltage.to("kV").magnitude - kvs.append(nom_voltage if num_phases == 1 else nom_voltage * 1.732) + voltage_type = winding.voltage_type + connection_type = winding.connection_type + nom_voltage = nom_voltage if voltage_type == "line-to-ground" else nom_voltage / 1.732 + kvs.append( + nom_voltage + if num_phases == 1 and connection_type != "DELTA" + else nom_voltage * 1.732 + ) # resistance pctRs.append(winding.resistance) # rated_power kVAs.append(winding.rated_power.to("kva").magnitude) # connection_type - conns.append(self.connection_map[winding.connection_type]) + conns.append(self.connection_map[connection_type]) # TODO: num_phases and is_grounded aren't included if self.model.is_center_tapped and i == len(self.model.windings): kvs.append(nom_voltage) diff --git a/src/ditto/writers/opendss/equipment/geometry_branch_equipment.py b/src/ditto/writers/opendss/equipment/geometry_branch_equipment.py index 40c2e1c..e0f0bb6 100644 --- a/src/ditto/writers/opendss/equipment/geometry_branch_equipment.py +++ b/src/ditto/writers/opendss/equipment/geometry_branch_equipment.py @@ -17,7 +17,7 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.LINECODES_FILE.value def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_common(self): units = [] @@ -58,7 +58,7 @@ def map_conductors(self): # conductor_type = 'tsdata' else: raise ValueError(f"Unknown conductor type {conductor}") - all_conductors.append(f"{conductor_type}.{conductor.name}") + all_conductors.append(f"{conductor_type}.{self.get_opendss_safe_name(conductor.name)}") self.opendss_dict["Conductors"] = all_conductors def map_insulation(self): diff --git a/src/ditto/writers/opendss/equipment/matrix_impedance_branch_equipment.py b/src/ditto/writers/opendss/equipment/matrix_impedance_branch_equipment.py index eec6e8f..d48b113 100644 --- a/src/ditto/writers/opendss/equipment/matrix_impedance_branch_equipment.py +++ b/src/ditto/writers/opendss/equipment/matrix_impedance_branch_equipment.py @@ -22,19 +22,31 @@ def map_common(self): self.opendss_dict["Units"] = "km" def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_r_matrix(self): r_matrix_ohms = self.model.r_matrix.to("ohm/km") - self.opendss_dict["RMatrix"] = r_matrix_ohms.magnitude + assert ( + abs(r_matrix_ohms.magnitude - r_matrix_ohms.T.magnitude).max() < 1e-6 + ), "RMatrix must be symmetric" + r_matrix_ohms = (r_matrix_ohms.magnitude + r_matrix_ohms.T.magnitude) / 2 + self.opendss_dict["RMatrix"] = r_matrix_ohms def map_x_matrix(self): x_matrix_ohms = self.model.x_matrix.to("ohm/km") - self.opendss_dict["XMatrix"] = x_matrix_ohms.magnitude + assert ( + abs(x_matrix_ohms.magnitude - x_matrix_ohms.T.magnitude).max() < 1e-6 + ), "XMatrix must be symmetric" + x_matrix_ohms = (x_matrix_ohms.magnitude + x_matrix_ohms.T.magnitude) / 2 + self.opendss_dict["XMatrix"] = x_matrix_ohms def map_c_matrix(self): c_matrix_nf = self.model.c_matrix.to("nanofarad/km") - self.opendss_dict["CMatrix"] = c_matrix_nf.magnitude + assert ( + abs(c_matrix_nf.magnitude - c_matrix_nf.T.magnitude).max() < 1e-6 + ), "CMatrix must be symmetric" + c_matrix_nf = (c_matrix_nf.magnitude + c_matrix_nf.T.magnitude) / 2 + self.opendss_dict["CMatrix"] = c_matrix_nf def map_ampacity(self): ampacity_amps = self.model.ampacity.to("ampere") diff --git a/src/ditto/writers/opendss/equipment/matrix_impedance_recloser_equipment.py b/src/ditto/writers/opendss/equipment/matrix_impedance_recloser_equipment.py new file mode 100644 index 0000000..f7a2977 --- /dev/null +++ b/src/ditto/writers/opendss/equipment/matrix_impedance_recloser_equipment.py @@ -0,0 +1,21 @@ +from gdm.distribution import DistributionSystem +from infrasys import Component + + +from ditto.writers.opendss.equipment.matrix_impedance_branch_equipment import ( + MatrixImpedanceBranchEquipmentMapper, +) +from ditto.enumerations import OpenDSSFileTypes + + +class MatrixImpedanceRecloserEquipmentMapper(MatrixImpedanceBranchEquipmentMapper): + def __init__(self, model: Component, system: DistributionSystem): + super().__init__(model, system) + + altdss_name = "LineCode_ZMatrixCMatrix" + altdss_composition_name = "LineCode" + opendss_file = OpenDSSFileTypes.SWITCH_CODES_FILE.value + + def map_controller(self): + # Not mapped in OpenDSS + pass diff --git a/src/ditto/writers/opendss/equipment/sequence_impedance_branch_equipment.py b/src/ditto/writers/opendss/equipment/sequence_impedance_branch_equipment.py index c830c7d..0eef05a 100644 --- a/src/ditto/writers/opendss/equipment/sequence_impedance_branch_equipment.py +++ b/src/ditto/writers/opendss/equipment/sequence_impedance_branch_equipment.py @@ -15,7 +15,7 @@ def __init__(self, model: Component, system: DistributionSystem): opendss_file = OpenDSSFileTypes.LINECODES_FILE.value def map_name(self): - self.opendss_dict["Name"] = self.model.name + self.opendss_dict["Name"] = self.get_opendss_safe_name(self.model.name) def map_common(self): self.opendss_dict["Units"] = "km" diff --git a/src/ditto/writers/opendss/opendss_mapper.py b/src/ditto/writers/opendss/opendss_mapper.py index fb83e1d..30b337e 100644 --- a/src/ditto/writers/opendss/opendss_mapper.py +++ b/src/ditto/writers/opendss/opendss_mapper.py @@ -87,3 +87,7 @@ def get_profile_name(self, component): profile_name = str(self.model.uuid) return profile_name + + def get_opendss_safe_name(self, name: str) -> str: + """Fix the name to be compatible with OpenDSS by replacing spaces and periods with underscores.""" + return name.replace(" ", "_").replace(".", "_") diff --git a/src/ditto/writers/opendss/write.py b/src/ditto/writers/opendss/write.py index f2a55b8..ae2188c 100644 --- a/src/ditto/writers/opendss/write.py +++ b/src/ditto/writers/opendss/write.py @@ -52,7 +52,11 @@ def _get_voltage_bases(self) -> list[float]: voltage_bases = [] buses: list[DistributionBus] = list(self.system.get_components(DistributionBus)) for bus in buses: - voltage_bases.append(bus.rated_voltage.to("kilovolt").magnitude * 1.732) + voltage_bases.append( + bus.rated_voltage.to("kilovolt").magnitude + if bus.voltage_type == "line-to-line" + else bus.rated_voltage.to("kilovolt").magnitude * 1.732 + ) return list(set(voltage_bases)) def write( # noqa