/// <summary> /// Connects this <see cref="PowerDeliveryElement"/> between <paramref name="bus1"/> /// and <paramref name="bus2"/> on matching <paramref name="phases"/>. /// </summary> /// <param name="bus1">The first <see cref="Bus"/> to connect to.</param> /// <param name="bus2">The second <see cref="Bus"/> to connect to.</param> /// <param name="phases">The phases to connect the <see cref="PowerDeliveryElement"/> /// to the <see cref="Bus"/>es on.</param> public void Connect(Bus bus1, Bus bus2, params int[] phases) { foreach (var phase in phases) { Connect(phase, bus1, phase, bus2, phase); } }
/// <summary> /// Connects this power conversion element in Wye to <paramref name="connectTo"/>. Each phase of the /// <see cref="PowerConversionElement"/>in <paramref name="pcElementPhases"/> is connected to the phase of the same index in /// <paramref name="busPhases"/>. /// </summary> /// <param name="connectTo">The <see cref="Bus"/> to connect this <see cref="PowerConversionElement"/> to.</param> /// <param name="pcElementPhases">The phases of this element that should be connected.</param> /// <param name="busPhases">The phases of <paramref name="connectTo"/> to connect to.</param> public void ConnectWye(Bus connectTo, IEnumerable<int> pcElementPhases, IEnumerable<int> busPhases) { foreach (var phasePair in pcElementPhases.Zip(busPhases,(pcElementPhase,busPhase) => new {pcElementPhase,busPhase})) { Connect(phasePair.pcElementPhase, connectTo, phasePair.busPhase); } }
public void Connect() { FakePCElement pcElem = new FakePCElement(); Bus b = new Bus("Test", Complex.Zero, 0, null); pcElem.Connect(1, b, 1); PairConnectionAssertions(pcElem, 1, b, 1); }
private static void TraceToSource(Bus FromBus, Bus BusThatStartedItAll, HashSet<Bus> busesInThisTrace, HashSet<Bus> busesOnPath) { //start at FromBus, take a step away from FromBus. //If we're at the source, add the path that we took to BusesOnRouteToSource. //If we're at a dead-end, then stop tracing this branch. //If we hit a bus that's already on the route, then terminate and add the branch. var connectedBuses = FromBus.ConnectedTo.OfType<Line>().Select(line => line.ConnectedTo.OfType<Bus>().Except(FromBus.Yield()).Single()) //all the buses neighbouring this one .Except(busesInThisTrace) //exclude any buses we've already touched in this trace ; foreach (var bus in connectedBuses) { if (busesOnPath.Contains(bus)) //we're connected to the target bus. no further processing required on this branch. { busesOnPath.UnionWith(busesInThisTrace.Except(BusThatStartedItAll.Yield())); continue; } else { //keep searching! HashSet<Bus> NextStepTraceList; if (connectedBuses.Count() == 1) //if this is the only possible way forward, then just keep using the same thingy. { NextStepTraceList = busesInThisTrace; } else { NextStepTraceList = new HashSet<Bus>(busesInThisTrace); } NextStepTraceList.Add(bus); TraceToSource(bus, BusThatStartedItAll, NextStepTraceList, busesOnPath); } } }
/// <summary> /// Obtains the direct line length between two buses. /// </summary> /// <param name="FromBus">The bus to trace from.</param> /// <param name="ToBus">The bus to find the line length to.</param> /// <returns>The line length, in metres.</returns> public static double GetDirectLengthBetweenBuses(Bus FromBus, Bus ToBus) { var busList = Tracing.BusesOnRouteToTarget(FromBus, ToBus); Dictionary<Bus, double> lengths = new Dictionary<Bus, double>(); Tracing.TraceFromWithCallback(ToBus, busList, (thisBus, line, nextBus) => lengths[nextBus] = (lengths.ContainsKey(thisBus) ? lengths[thisBus] : 0) + line.Length); return lengths[FromBus]; }
/// <summary> /// Obtains a list of all buses directly or indirectly connected to <paramref name="FromBus"/>, /// so long as they are connected in a fashion that does not rely upon the presence of any elements of /// <paramref name="BusesToExclude"/> /// </summary> /// <param name="FromBus">The <see cref="Bus"/> to trace from.</param> /// <param name="BusesToExclude">A set of <see cref="Bus"/>es that should be avoided in the trace operation.</param> /// <returns>A list of all buses directly or indirectly connected to <paramref name="FromBus"/>, /// so long as connection is not through any element in <paramref name="BusesToExclude"/>.</returns> public static IEnumerable<Bus> TraceWithoutCrossingBuses(Bus FromBus, IEnumerable<Bus> BusesToExclude) { var BusesInTrace = new HashSet<Bus>(FromBus.Yield()); var BusesInPath = new HashSet<Bus>(); _traceWithoutCrossingBuses(FromBus, new HashSet<Bus>(BusesToExclude), BusesInTrace, BusesInPath); BusesInPath.Add(FromBus); return BusesInPath; }
/// <summary> /// Instantiates a new <see cref="NetworkModel"/>. /// </summary> /// <param name="Buses">All the buses in the network.</param> /// <param name="Lines">All the lines in the network.</param> /// <param name="Loads">All the loads in the network.</param> /// <param name="Generators">All the generators in the network.</param> /// <param name="Losses">The losses (in kVA) across the whole network.</param> /// <param name="SourceBus">The source bus (fixed bus) of the network.</param> public NetworkModel(Dictionary<String, Bus> Buses, Collection<Line> Lines, Collection<Load> Loads, Collection<Generator> Generators, Complex Losses, Bus SourceBus) { this.Buses = Buses; this.Lines = Lines; this.Loads = Loads; this.Generators = Generators; this.LosseskVA = Losses; this.SourceBus = SourceBus; networkBounds = FindNetworkBounds(); }
/// <summary> /// Obtains a list of all buses that are directly on-route from /// <paramref name="FromBus"/> to <paramref name="TargetBus"/>. /// </summary> /// <param name="FromBus">The <see cref="Bus"/> to trace from.</param> /// <param name="TargetBus">The <see cref="Bus"/> to trace to.</param> /// <returns>A list of all buses that are directly on-route from /// <paramref name="FromBus"/> to <paramref name="TargetBus"/> (inclusive).</returns> public static IEnumerable<Bus> BusesOnRouteToTarget(Bus FromBus, Bus TargetBus) { //start at FromBus, take a step away from FromBus. //If we're at the source, add the path that we took to BusesOnRouteToSource. //If we're at a dead-end, then stop tracing this branch. //If we hit a bus that's already on the route, then terminate and add the branch. HashSet<Bus> results = new HashSet<Bus>(TargetBus.Yield()); HashSet<Bus> thisTrace = new HashSet<Bus>(FromBus.Yield()); TraceToSource(FromBus, FromBus, thisTrace, results); results.Add(FromBus); return (IEnumerable<Bus>)results; }
/// <summary> /// Connects the <see cref="PowerDeliveryElement"/> on the phases in <paramref name="bus1AndLinePhases"/> /// to the same phases on <paramref name="bus1"/>, and to the correspondingly-indexed phases <paramref name="bus2Phases"/> /// on <paramref name="bus2"/>. /// </summary> /// <example> /// The following code connects the <see cref="PowerDeliveryElement"/> to <paramref name="bus1"/> /// and <paramref name="bus2"/>, with the following phasing: /// <code> /// // key: line phase -> bus1 phase, bus2 phase /// // 1 -> 1, 2 /// // 2 -> 2, 3 /// // 3 -> 3, 1 /// myPowerDeliveryElement.Connect(bus1, new[] {1,2,3}, bus2, new[] {2,3,1}); /// </code></example> /// <param name="bus1">The first <see cref="Bus"/> to connect to. Shares common phases with the <see cref="PowerDeliveryElement"/>.</param> /// <param name="bus1AndLinePhases">The common phases to connect between the <see cref="PowerDeliveryElement"/> and the <see cref="Bus"/>.</param> /// <param name="bus2">The second <see cref="Bus"/> to connect to.</param> /// <param name="bus2Phases">Phase connections for <paramref name="bus2"/>.</param> public void Connect(Bus bus1, IEnumerable<int> bus1AndLinePhases, Bus bus2, IEnumerable<int> bus2Phases) { foreach (var phasePair in bus1AndLinePhases.Zip(bus2Phases, (phase1, phase2) => new { Bus1AndLinePhase = phase1, Bus2Phase = phase2 })) { NetworkElement.ConnectBetween(this, phasePair.Bus1AndLinePhase, bus1, phasePair.Bus1AndLinePhase, bus2, phasePair.Bus2Phase ); } }
public void PrepBalanced() { Dictionary<String, Bus> buses = new Dictionary<string, Bus>(); buses["b1"] = new Bus("b1", pr(132.79, 0), 132.79, new Point(0, 0)); buses["b2"] = new Bus("b2", pr(133.73, -0.1), 132.79, new Point(0, 0)); buses["b3"] = new Bus("b3", pr(133.55, -0.1), 132.79, new Point(0, 0)); buses["b4"] = new Bus("b4", pr(133.99, -0.1), 132.79, new Point(0, 0)); var lb1b2 = new Line("b1b2", 1); lb1b2.Connect(buses["b1"], buses["b2"]); var lb1b3 = new Line("b1b3", 2); lb1b3.Connect(buses["b1"], buses["b3"]); var lb2b4 = new Line("b2b4", 3); lb2b4.Connect(buses["b2"], buses["b4"]); var lb3b4 = new Line("b3b4", 4); lb3b4.Connect(buses["b3"], buses["b4"]); Collection<Line> lines = new Collection<Line>(); lines.Add(lb1b2); lines.Add(lb1b3); lines.Add(lb2b4); lines.Add(lb3b4); Generator g = new Generator("g4", new Complex(318000, 0)); g.Connect(buses["b4"]); Collection<Generator> generators = new Collection<Generator>(); generators.Add(g); Collection<Load> loads = new Collection<Load>(); var l1 = new Load("l1", new Complex(50000, 30990)); l1.Connect(buses["b1"]); var l2 = new Load("l2", new Complex(170000, 105350)); l2.Connect(buses["b2"]); var l3 = new Load("l3", new Complex(200000, 12940)); l3.Connect(buses["b3"]); var l4 = new Load("l4", new Complex(80000, 49580)); l4.Connect(buses["b4"]); loads.Add(l1); loads.Add(l2); loads.Add(l3); loads.Add(l4); model = new NetworkModel(buses, lines, loads, generators, new Complex(19580, -17810600), buses["b1"]); }
/// <summary> /// Connects this <see cref="PowerDeliveryElement"/> between two <see cref="Bus"/>es. This method is for /// building three-phase balanced networks. Use /// <see cref="Connect3Phase"/>, <see cref="Connect(int,Bus,int,Bus,int)"/>, <see cref="Connect(Bus,Bus,int[])"/> /// and <see cref="Connect(Bus,IEnumerable{int},Bus,IEnumerable{int})"/> for arbitrarily-phased networks. /// </summary> ///<param name="bus1">The <see cref="Bus"/> to connect on one side of this <see cref="PowerDeliveryElement"/>.</param> /// <param name="bus2">The <see cref="Bus"/> to connect on the other side of this <see cref="PowerDeliveryElement"/>.</param> public void Connect(Bus bus1, Bus bus2) { Connect3Phase(bus1, bus2); }
/// <summary> /// Connects this <see cref="PowerDeliveryElement"/> between two <see cref="Bus"/>es, /// on phases 1,2,3. /// </summary> ///<param name="bus1">The <see cref="Bus"/> to connect on one side of this <see cref="PowerDeliveryElement"/>.</param> /// <param name="bus2">The <see cref="Bus"/> to connect on the other side of this <see cref="PowerDeliveryElement"/>.</param> public void Connect3Phase(Bus bus1, Bus bus2) { Connect(bus1, bus2, 1, 2, 3); }
/// <summary> /// Traces from <paramref name="FromBus"/> along all buses in <paramref name="AllowedBuses"/>, /// and executing <paramref name="Callback"/> for every connection between two buses. /// </summary> /// <param name="FromBus">The bus to trace from.</param> /// <param name="AllowedBuses">All buses that are to be allowed in the trace.</param> /// <param name="Callback">A custom action to execute for every connection.</param> public static void TraceFromWithCallback(Bus FromBus, IEnumerable<Bus> AllowedBuses, Action<Bus, Line, Bus> Callback) { HashSet<Bus> thisTrace = new HashSet<Bus>(FromBus.Yield()); _traceFromWithCallback(FromBus, AllowedBuses, thisTrace, Callback); }
public void PrepUnbalanced() { Dictionary<String, Bus> buses = new Dictionary<string, Bus>(); buses["b1"] = new Bus("b1", pc3pr(130770, 0.4, 132860, -120.8, 134130, 120.6), 132.79, new Point(0, 0)); buses["b2"] = new Bus("b2", pc3pr(866380, 99.9, 83445, -21.2, 86499, -142.5), 132.79, new Point(0, 0)); buses["b3"] = new Bus("b3", pc3pr(94825, 14.5, 96205, -107.4, 98249, 134.2), 132.79, new Point(0, 0)); buses["b4"] = new Bus("b4", pc3pr(67374, 68.6, 65606, -54, 69131, -174), 132.79, new Point(0, 0)); var lb1b2 = new Line("b1b2", 1); lb1b2.Connect(buses["b1"], new[] { 1, 2, 3 }, buses["b2"], new[] { 2, 3, 1 }); var lb1b3 = new Line("b1b3", 2); lb1b3.Connect3Phase(buses["b1"], buses["b3"]); var lb2b4 = new Line("b2b4", 3); lb2b4.Connect3Phase(buses["b2"], buses["b4"]); var lb3b4 = new Line("b3b4", 4); lb3b4.Connect(buses["b3"], buses["b4"], new[] { 1, 2 }); Collection<Line> lines = new Collection<Line>(); lines.Add(lb1b2); lines.Add(lb1b3); lines.Add(lb2b4); lines.Add(lb3b4); Generator g = new Generator("g4", pc3(106000, 0.9797, 106000, -1.3930, 106000, 0.4265)); g.ConnectWye(buses["b4"]); Collection<Generator> generators = new Collection<Generator>(); generators.Add(g); Collection<Load> loads = new Collection<Load>(); var l1 = new Load("l1", pc3(16382, 10280, 16852, 10108, 16766, 10601)); l1.ConnectWye(buses["b1"], 1, 2, 3); var l2 = new Load("l2", pcV(2, 85000, 52674, 3, 85000, 52675)); l2.ConnectWye(buses["b2"], 2, 3); var l3 = new Load("l3", pcV(1, 200000, 12940)); l3.ConnectWye(buses["b3"], 1, 2); var l4 = new Load("l4", pc3(26666, 16527, 26666, 16527, 26666, 16527)); l4.ConnectWye(buses["b4"], 1, 2, 3); loads.Add(l1); loads.Add(l2); loads.Add(l3); loads.Add(l4); model = new NetworkModel(buses, lines, loads, generators, new Complex(140424, 692575), buses["b1"]); }
private static void _traceFromWithCallback(Bus FromBus, IEnumerable<Bus> AllowedBuses, HashSet<Bus> busesInThisTrace, Action<Bus, Line, Bus> Callback) { var connectedBuses = FromBus.ConnectedTo.OfType<Line>().Select(line => Tuple.Create(line, line.ConnectedTo.OfType<Bus>().Except(FromBus.Yield()).Single())) //all the buses neighbouring this one .Where(t => !busesInThisTrace.Contains(t.Item2) && AllowedBuses.Contains(t.Item2)) //exclude any buses we've already touched in this trace, and any buses that aren't in the allowed set. ; foreach (var bus in connectedBuses) { Callback(FromBus, bus.Item1, bus.Item2); //keep searching! HashSet<Bus> NextStepTraceList = connectedBuses.Count() == 1 ? busesInThisTrace : new HashSet<Bus>(busesInThisTrace); NextStepTraceList.Add(bus.Item2); _traceFromWithCallback(bus.Item2, AllowedBuses, NextStepTraceList, Callback); } }
private static void _traceWithoutCrossingBuses(Bus FromBus, HashSet<Bus> ExcludeList, HashSet<Bus> busesInThisTrace, HashSet<Bus> busesOnPath) { var connectedBuses = FromBus.ConnectedTo.OfType<Line>().Select(line => line.ConnectedTo.OfType<Bus>().Except(FromBus.Yield()).Single()) //all the buses neighbouring this one .Except(busesInThisTrace) //exclude any buses we've already touched in this trace ; if (connectedBuses.Count() == 0) { busesOnPath.UnionWith(busesInThisTrace); return; } foreach (var bus in connectedBuses) { if (ExcludeList.Contains(bus)) //we're connected to the target bus. end the thread. { continue; } else { //keep searching! HashSet<Bus> NextStepTraceList; if (connectedBuses.Count() == 1) //if this is the only possible way forward, then just keep using the same thingy. { NextStepTraceList = busesInThisTrace; } else { NextStepTraceList = new HashSet<Bus>(busesInThisTrace); } NextStepTraceList.Add(bus); _traceWithoutCrossingBuses(bus, ExcludeList, NextStepTraceList, busesOnPath); } } }
/// <summary> /// Connects this <see cref="PowerConversionElement"/> to a <see cref="Bus"/>. /// This is the connection method for three-phase balanced networks. Use /// <see cref="O:ElecNetKit.NetworkModelling.PowerConversionElement.ConnectWye" /> and <see cref="Connect(int,Bus,int)"/> /// for arbitrarily-phased networks. /// </summary> /// <param name="connectTo">The <see cref="Bus"/> to connect to.</param> /// <overloads>There are multiple overloads for this method:</overloads> public void Connect(Bus connectTo) { ConnectWye(connectTo, 1, 2, 3); }
/// <summary> /// Connects a phase of a power conversion element between two phases of a single <see cref="Bus"/>. /// </summary> /// <param name="thisPhase">The phase of this <see cref="PowerConversionElement"/> to connect between phases of the bus.</param> /// <param name="connectTo">The bus to connect <paramref name="thisPhase"/> of this <see cref="PowerConversionElement"/> to.</param> /// <param name="connectToPhasePrimary">The primary phase of the bus to connect to. Should be an active phase.</param> public void Connect(int thisPhase, Bus connectTo, int connectToPhasePrimary) { base.Connect(thisPhase, connectTo, connectToPhasePrimary); }
/// <summary> /// Connects this power conversion element in Wye to <paramref name="connectTo"/>. Each phase of /// the <see cref="PowerConversionElement"/> specified in <paramref name="phases"/> will be connected /// to the corresponding active phase. /// </summary> /// <param name="connectTo">The <see cref="Bus"/> that the <see cref="PowerConversionElement"/> should connect to.</param> /// <param name="phases">The phases of the <see cref="PowerConversionElement"/> and the active phases of the <see cref="Bus"/> /// to connect on.</param> /// <overloads>There are multiple overloads for this method:</overloads> public void ConnectWye(Bus connectTo, params int[] phases) { if (phases.Length == 0) phases = new[] { 1, 2, 3 }; ConnectWye(connectTo, phases, phases); }
/// <summary> /// Connects <paramref name="thisPhase"/> of this <see cref="PowerDeliveryElement"/> between /// <paramref name="bus1Phase"/> of <paramref name="bus1"/> and <paramref name="bus2Phase"/> /// of <paramref name="bus2"/>. /// </summary> /// <param name="thisPhase">The phase of this element to connect.</param> /// <param name="bus1">The <see cref="Bus"/> to connect on one side of this <see cref="PowerDeliveryElement"/>.</param> /// <param name="bus1Phase">The phase of <paramref name="bus1"/> to connect to.</param> /// <param name="bus2">The <see cref="Bus"/> to connect on the other side of this <see cref="PowerDeliveryElement"/>.</param> /// <param name="bus2Phase">The phase of <paramref name="bus2"/> to connect to.</param> public void Connect(int thisPhase, Bus bus1, int bus1Phase, Bus bus2, int bus2Phase) { NetworkElement.ConnectBetween(this, thisPhase, bus1, bus1Phase, bus2, bus2Phase); }