def create_power_transformer_end(network: NetworkService, pt: PowerTransformer, t: Terminal, end_number: int = 0, **kwargs) -> PowerTransformerEnd: en = end_number if end_number > 0 else t.sequence_number te = PowerTransformerEnd(mrid=f"{pt.mrid}_e{en}", power_transformer=pt, terminal=t, end_number=en, **kwargs) pt.add_end(te) network.add(te) return te
def create_power_transformer_for_connecting(network: NetworkService, mrid: str = "", num_terms: int = 0, phases: PhaseCode = PhaseCode.ABCN, num_usagepoints: int = 0, num_meters: int = 0, end_args: List[Dict] = None) -> PowerTransformer: """ `end_args` A list of dictionaries, each of which is passed to `create_power_transformer_end` for every terminal created. Possible kwargs are anything that can be passed to the `PowerTransformerEnd` constructor. Keep in mind CIM recommends the HV end is first in the list. """ if not mrid: mrid = CopyableUUID() pt = PowerTransformer(mrid, name="test powertransformer") terminals = create_terminals(network, pt, num_terms, phases) for eargs, t in zip(end_args, terminals): create_power_transformer_end(network, pt, t, **eargs) for i in range(num_usagepoints): up = UsagePoint(f"{mrid}-up{i}") pt.add_usage_point(up) up.add_equipment(pt) for j in range(num_meters): meter = create_meter(network, f"{mrid}-up{i}-m{j}") up.add_end_device(meter) meter.add_usage_point(up) network.add(up) network.add(pt) return pt
def test_powertransformer_voltages(self): bv11k = BaseVoltage(nominal_voltage=11000) pt = PowerTransformer(base_voltage=bv11k) t1 = Terminal(conducting_equipment=pt) pte = PowerTransformerEnd(power_transformer=pt, base_voltage=bv11k, terminal=t1) pt.add_end(pte) assert pt.get_base_voltage(t1) is pte.base_voltage is t1.base_voltage
def add_dyn11_trafo(self, connectivity_node, mrid: str = None, wiring_supplier=None, **kwargs): mrid = _get_mrid(mrid) rtc1 = gen_tap_changer(high_step=4, low_step=1, step_voltage_increment=0.25, step=2) end1 = gen_trafo_end(rated_s=200, rated_u=22000, r=100, x=200, r0=10, x0=20, winding=WindingConnection.D, tap_changer=rtc1) rtc2 = gen_tap_changer(high_step=4, low_step=1, step_voltage_increment=0.25, step=2) end2 = gen_trafo_end(rated_s=100, rated_u=11000, r=50, x=100, r0=5, x0=10, winding=WindingConnection.Yn, tap_changer=rtc2) terms = self.gen_terminals(2, connectivity_node, mrid=mrid, wiring_supplier=wiring_supplier) trafo = PowerTransformer(mrid=mrid, vector_group=VectorGroup.DYN11, ends=[end1, end2], terminals=terms, **kwargs) self.network.add(trafo) return AddResult(trafo, terms[1].connectivity_node)
def create_hierarchy(): ns = NetworkService() region = GeographicalRegion(name='Region1') sub_region = SubGeographicalRegion(name='SubRegion1', geographical_region=region) region.add_sub_geographical_region(sub_region) substation = Substation(name='Sub1', sub_geographical_region=sub_region) sub_tx = PowerTransformer(name='tx1') sub_tx.add_container(substation) substation.add_equipment(sub_tx) feeder = Feeder(name='Feeder1', normal_energizing_substation=substation) breaker = Breaker(name='b1') breaker.add_container(feeder) feeder.add_equipment(breaker) ## Adding all the objects to the NetworkService ns.add(breaker) ns.add(feeder) ns.add(substation) ns.add(sub_tx) ns.add(sub_region) ns.add(region) return ns
def test_resolves_pt_pti(): ns = NetworkService() pti = PowerTransformerInfo() pt = PowerTransformer() pt.asset_info = pti br = resolver.power_transformer_info(pt) ns.resolve_or_defer_reference(br, pti.mrid) assert pti.mrid in ns.get_unresolved_reference_mrids(br) ns.add(pt) pt_fetched = ns.get(pt.mrid) assert pt_fetched.asset_info == pti ns = NetworkService() ns.add(pti) ns.resolve_or_defer_reference(resolver.power_transformer_info(pt), pti.mrid) assert len(list(ns.get_unresolved_reference_mrids(br))) == 0 ns.add(pt) pt_fetched = ns.get(pt.mrid) assert pt_fetched.asset_info == pti
def create_feeder(): """ Creates a small feeder based on https://bitbucket.org/zepben/cimdemo/src/master/lv_simple_net.png. :return: A NetworkService representing the feeder. """ # Create the network. This will be used for sending all components of the feeder. network = NetworkService() # A network has multiple BaseVoltage's, each used to represent the intended nominal voltage of equipment operating # on a segment of the network. bv_11kv = BaseVoltage(mrid='11kv', nominal_voltage=11000, name='11kV') # We must add the BaseVoltage to the network directly if any ConductingEquipment relies on it. network.add(bv_11kv) # There is no required order for adding equipment to the network, as long as its dependencies are satisfied. # In this example, we will start with the main EnergySource, working towards the leaf nodes in the network # in a depth-first traversal. # Geographic coordinates and location details are stored as a Location against any type extending # PowerSystemResource. energy_source_loc = Location(mrid='es-loc') energy_source_loc.add_point(PositionPoint(152.9100276,-31.43952262)) network.add(energy_source_loc) # Create the EnergySource, specifying any desired parameters plus passing in our BaseVoltage, EnergySourcePhase's, # Location, and Terminals. Note that terminals accepts a list of Terminals, however an EnergySource only has one. energy_source = EnergySource(mrid='EnergySource', name='Source', base_voltage=bv_11kv, voltage_magnitude=11000, voltage_angle=0.0, location=energy_source_loc) # Note that all types extending IdentifiedObject take an mrid. If it is not provided, a UUID will be generated # for you. We create a Terminal specifying its phase and connectivity_node. The ConnectivityNode will also # receive a reference to the Terminal as part of the constructor. es_t1 = Terminal(mrid='es-t1', phases=PhaseCode.ABC, conducting_equipment=energy_source) # This is the starting ConnectivityNode in our network # At a bare minimum, at least one connectivity node and one Terminal is required for an EnergySource to be # connected to the network. Note however that the network will allow you to add disconnected equipment if that # suits your use case. # NetworkService.connect_by_mrid is a helper method that will create a ConnectivityNode in the NetworkService for # the given mRID (in this case, SourceNode), and connect the passed in Terminal to it (es_t1). # You should ensure you always call connect_by_mrid or connect_by_terminal, as this keeps the references between # the ConnectivityNode and Terminal in sync. network.connect_by_mrid(es_t1, "SourceNode") # Any ConductingEquipment must have its terminals added to it before being utilised. This can be performed through # the constructor via the terminals_ parameter, or added after initialisation like below. The Terminal must also # have its conducting_equipment specified for add_terminal() to succeed. energy_source.add_terminal(es_t1) network.add(es_t1) # An EnergySource has an EnergySourcePhase representing each phase it supplies. This is primarily used for tracing, # however more attributes will be added at a later date. es_phases = [EnergySourcePhase(mrid="esp1", energy_source=energy_source, phase=SinglePhaseKind.A), EnergySourcePhase(mrid="esp2", energy_source=energy_source, phase=SinglePhaseKind.B), EnergySourcePhase(mrid="esp3", energy_source=energy_source, phase=SinglePhaseKind.C)] for phase in es_phases: energy_source.add_phase(phase) network.add(phase) network.add(energy_source) # Create the PowerTransformer # Note BaseVoltage is not used for the PowerTransformer as it has two separate voltages. rated_u must be populated # on both ends. power_transformer = PowerTransformer(mrid="PowerTransformer", vector_group=VectorGroup.DYN11) delta_pt_end = PowerTransformerEnd(mrid="delta-pt-end", rated_s=800000, rated_u=11000, connection_kind=WindingConnection.D, power_transformer=power_transformer) delta_tap_changer = RatioTapChanger(mrid="rtc1", high_step=4, low_step=1, step=2.0, neutral_step=2, normal_step=2, step_voltage_increment=0.25, transformer_end=delta_pt_end) delta_pt_end.ratio_tap_changer = delta_tap_changer network.add(delta_tap_changer) network.add(delta_pt_end) wye_pt_end = PowerTransformerEnd(mrid="wye-pt-end", rated_s=800000, rated_u=416, connection_kind=WindingConnection.Yn, power_transformer=power_transformer) wye_tap_changer = RatioTapChanger(mrid="rtc2", high_step=2, low_step=1, step=2.0, neutral_step=2, normal_step=2, step_voltage_increment=0.5, transformer_end=wye_pt_end) wye_pt_end.ratio_tap_changer = wye_tap_changer network.add(wye_tap_changer) network.add(wye_pt_end) # Terminals are required on the PowerTransformer, corresponding to each PowerTransformerEnd # Note that ordering of the Terminals is significant, and must correspond with the ordering of the ends. delta_terminal = Terminal(mrid='pt-t1', phases=PhaseCode.ABC, conducting_equipment=power_transformer) # Connect the terminal to the source ConnectivityNode network.connect_by_mrid(delta_terminal, 'SourceNode') power_transformer.add_terminal(delta_terminal) network.add(delta_terminal) # Set the terminal on the Delta PowerTransformerEnd (This allows us to correlate the Terminal with the voltage) delta_pt_end.terminal = delta_terminal # The wye Terminal is connected to the Bus 0 ConnectivityNode wye_terminal = Terminal(mrid='pt-t2', phases=PhaseCode.ABCN, conducting_equipment=power_transformer) # Connect the terminal to the ConnectivityNode network.connect_by_mrid(wye_terminal, 'Bus 0') power_transformer.add_terminal(wye_terminal) network.add(wye_terminal) # Set the terminal on the WYE PowerTransformerEnd (This allows us to correlate the Terminal with the voltage) wye_pt_end.terminal = wye_terminal # Location pt_loc = Location(mrid='pt-loc') pt_loc.add_point(PositionPoint(152.9100276,-31.43952262)) power_transformer.location = pt_loc network.add(pt_loc) # Add the ends to the network power_transformer.add_end(delta_pt_end) power_transformer.add_end(wye_pt_end) # Add the PowerTransformer to the network network.add(power_transformer) # Create the Breaker. It requires a new BaseVoltage of 416V # Note Breaker constructor defaults all switch states to CLOSED. bv_416v = BaseVoltage(mrid="416v", nominal_voltage=416, name="0.416kV") network.add(bv_416v) # Create a location for the Breaker breaker_loc = Location(mrid='breaker-loc') breaker_loc.add_point(PositionPoint(152.9100276,-31.43952262)) network.add(breaker_loc) breaker = Breaker(mrid="Breaker", base_voltage=bv_416v, location=breaker_loc) t1 = Terminal(mrid='br-t1', phases=PhaseCode.ABCN, conducting_equipment=breaker) network.connect_by_mrid(t1, 'Bus 0') breaker.add_terminal(t1) network.add(t1) t2 = Terminal(mrid='br-t2', phases=PhaseCode.ABCN, conducting_equipment=breaker) network.connect_by_mrid(t2, 'Bus 1') breaker.add_terminal(t2) network.add(t2) # Add the Breaker to the network network.add(breaker) # Create first AcLineSegment with a PerLengthSequenceImpedance and Location with two position_points # The properties of the conductor are contained in a PerLengthSequenceImpedance. All amounts are per metre. plsi_1 = PerLengthSequenceImpedance(mrid="4c_70", r=466.0, x=71.0, r0=1505.0, x0=83.0) network.add(plsi_1) # A line typically has two longlats representing each terminal point. Note these must be added in order and # correspond to the matching Terminal. acls1_loc = Location(mrid="acls1-loc") acls1_loc.add_point(PositionPoint(152.9144265,-31.43913816)) acls1_loc.add_point(PositionPoint(152.910199,-31.439523)) network.add(acls1_loc) acls1 = AcLineSegment(mrid="acls1",name="acls1", base_voltage=bv_416v, length=31.71938, per_length_sequence_impedance=plsi_1, location=acls1_loc) # Create and add the Terminal's for this ACLS acls1_t1 = Terminal(mrid='acls1-t1', phases=PhaseCode.ABCN, conducting_equipment=acls1) network.connect_by_mrid(acls1_t1, "Bus 1") acls1.add_terminal(acls1_t1) network.add(acls1_t1) acls1_t2 = Terminal(mrid='acls1-t2', phases=PhaseCode.ABCN, conducting_equipment=acls1) network.connect_by_mrid(acls1_t2, "Bus 25") acls1.add_terminal(acls1_t2) network.add(acls1_t2) # Add the ACLS to the network after adding all its dependencies network.add(acls1) # Create the rest of the lines. These are all quite similar to above. create_lines(network, bv_416v, "Bus 25", plsi_1) # Create first EnergyConsumer on 230V with a single phase bv_230v = BaseVoltage(mrid="230v", nominal_voltage=230, name="0.23kV") network.add(bv_230v) # Each EnergyConsumer has a list of phases it is connected on. These are optional and only used to # specify additional properties per phase when they are known. ecp = [EnergyConsumerPhase(mrid='ecp1', phase=SinglePhaseKind.A, p_fixed=800.0, q_fixed=200.0)] network.add(ecp[0]) # Creaote the EnergyConsumer's Location ec1_loc = Location(mrid="ec1-loc") ec1_loc.add_point(PositionPoint(152.9172589,-31.44307421)) network.add(ec1_loc) energy_consumer1 = EnergyConsumer(mrid="EnergyConsumer1", p=1000, q=334.27413609633844, name="Load 1", phase_connection=PhaseShuntConnectionKind.Y, energy_consumer_phases=ecp, base_voltage=bv_230v, location=ec1_loc) # Create and add the Terminal, Note that the ConnectivityNode will be retrieved from the network (Bus 34 was created in create_lines()) ec1_t1 = Terminal(mrid='ec1-t1', phases=PhaseCode.A, conducting_equipment=energy_consumer1) network.connect_by_mrid(ec1_t1, "Bus 34") energy_consumer1.add_terminal(ec1_t1) network.add(ec1_t1) # Add the energy consumer to the network network.add(energy_consumer1) # Create PV EnergySource with a single phase and a location esp = [EnergySourcePhase(mrid='esp4', phase=SinglePhaseKind.A)] network.add(esp[0]) es2_loc = Location(mrid="es2-loc") es2_loc.add_point(PositionPoint(152.9172589,-31.44307421)) network.add(es2_loc) energy_source_pv = EnergySource(mrid="PV-DG", name='PV Distributed Generator', base_voltage=bv_230v, voltage_magnitude=416, voltage_angle=9.0, energy_source_phases=esp, location=es2_loc) es2_t1 = Terminal(mrid='es2-t1', phases=PhaseCode.A, conducting_equipment=energy_source_pv) network.connect_by_mrid(es2_t1, "Bus 34") energy_source_pv.add_terminal(es2_t1) network.add(es2_t1) # Add the EnergySource to the network. network.add(energy_source_pv) # Create second EnergyConsumer with a single phase of B and a Location. ecp = [EnergyConsumerPhase(mrid="ecp2", phase=SinglePhaseKind.B, p_fixed=800.0, q_fixed=200.0)] network.add(ecp[0]) ec2_loc = Location(mrid="ec2-loc") ec2_loc.add_point(PositionPoint(152.9121734,-31.44320236)) network.add(ec2_loc) energy_consumer2 = EnergyConsumer(mrid="EnergyConsumer2", p=1000, q=334.27413609633844, name="Load 2", phase_connection=PhaseShuntConnectionKind.Y, energy_consumer_phases=ecp, base_voltage=bv_230v, location=ec2_loc) # Create and connect the Terminal. ec2_t1 = Terminal(mrid='ec2-t1', phases=PhaseCode.B, conducting_equipment=energy_consumer2) network.connect_by_mrid(ec2_t1, "Bus 47") energy_consumer2.add_terminal(ec2_t1) network.add(ec2_t1) # Add the EnergyConsumer to the network network.add(energy_consumer2) # Create third EnergyConsumer with a single phase A and a Location. ecp = [EnergyConsumerPhase(mrid="ecp3", phase=SinglePhaseKind.A, p_fixed=800.0, q_fixed=200.0)] network.add(ecp[0]) ec3_loc = Location(mrid="ec3-loc", position_points=[PositionPoint(152.9151775,-31.43624552)]) network.add(ec3_loc) energy_consumer3 = EnergyConsumer(mrid="EnergyConsumer3", p=1000, q=334.27413609633844, name="Load 3", phase_connection=PhaseShuntConnectionKind.Y, energy_consumer_phases=ecp, base_voltage=bv_230v, location=ec3_loc) ec3_t1 = Terminal(mrid='ec3-t1', phases=PhaseCode.A, conducting_equipment=energy_consumer3) network.connect_by_mrid(ec3_t1, "Bus 70") energy_consumer3.add_terminal(ec3_t1) network.add(ec3_t1) # Add the last energy consumer to the network network.add(energy_consumer3) # Our network is complete and connected. Next we must send it. return network
def test_powertransformer_asset_info(self): pti = PowerTransformerInfo(mrid="pti", name="pti") pt = PowerTransformer("pt") pt.asset_info = pti assert pt.asset_info is pti