/// <summary>
 /// Store original bus voltage magnitudes by BusID in oldVoltages.
 /// See <see cref="IResultsTransform.PreExperimentHook"/> for how this
 /// fits into the system.
 /// </summary>
 /// <param name="Network">The original, unexperimented network.</param>
 public void PreExperimentHook(NetworkModel Network)
 {
     oldVoltages = new Dictionary<string, Complex>();
     foreach (KeyValuePair<String, Bus> kvp in Network.Buses)
     {
         Bus bus = kvp.Value;
         oldVoltages.Add(bus.ID, bus.Voltage);
     }
 }
 public void ModelIntegrityAssertionsBalanced(NetworkModel network)
 {
     Assert.AreEqual(4, network.Buses.Count);
     Assert.AreEqual(4, network.Loads.Count);
     Assert.AreEqual(4, network.Lines.Count);
     Assert.AreEqual(1, network.Generators.Count);
     Assert.IsTrue(ConnectedToElemWithID(network.Buses["b1"], (IEnumerable<NetworkElement>)network.Lines, "b1b2"));
     Assert.IsTrue(ConnectedToElemWithID(network.Buses["b1"], (IEnumerable<NetworkElement>)network.Lines, "b1b3"));
     Assert.IsFalse(ConnectedToElemWithID(network.Buses["b1"], (IEnumerable<NetworkElement>)network.Lines, "b3b4"));
     Assert.AreEqual(network.Buses["b1"], network.Loads[0].ConnectedTo.Single());
 }
 /// <summary>
 /// Subtracts old bus voltage magnitudes from new bus voltage
 /// magnitudes. Note that this will screw around with the phases
 /// due to subtraction of magnitudes, not of complex vectors.
 /// </summary>
 /// <param name="Network">The network to transform.</param>
 public void PostExperimentHook(NetworkModel Network)
 {
     foreach (KeyValuePair<String, Bus> kvp in Network.Buses)
     {
         Bus bus = kvp.Value;
         if (oldVoltages.ContainsKey(bus.ID))
         {
             bus.Voltage = Complex.FromPolarCoordinates(bus.Voltage.Magnitude - oldVoltages[bus.ID].Magnitude,
                 bus.Voltage.Phase - oldVoltages[bus.ID].Phase);
         }
     }
 }
示例#4
0
 static void otherGraph(NetworkModel network)
 {
     #region ValueTransform
     var graph = new ValueTransformableTreeGraph(); //new graph
     graph.BusSizeMin = 2;
     graph.BusSizeMax = 10;
     graph.BusSizeTransform = bus => bus.VoltagePU.Magnitude;
     graph.BusColorTransform = bus => bus.VoltagePU.Magnitude;
     graph.RingEnabledTransform = bus => bus.ConnectedTo.OfType<Generator>().Any();
     graph.RingDistanceTransform = bus => 2; //constant
     graph.Network = network;
     #endregion
     GraphHostWindow.StartGraphHostWindow(graph);
 }
 public void ModelIntegrityAssertionsUnbalanced(NetworkModel network)
 {
     Assert.AreEqual(4, network.Buses.Count);
     Assert.AreEqual(4, network.Loads.Count);
     Assert.AreEqual(4, network.Lines.Count);
     Assert.AreEqual(1, network.Generators.Count);
     Assert.AreEqual(3, network.Buses["b1"].ConnectedToAnyPhase.Count());
     Assert.AreEqual(3, network.Buses["b1"].ConnectedToPhased.Count);
     //3 connections per line, 3 for the load.
     Assert.AreEqual(3+3+3, network.Buses["b1"].ConnectedToPhased.Values.SelectMany(x=>x).Count());
     //3 connections for one line, 2 for another, 2 for the load.
     Assert.AreEqual(3 + 2 + 2, network.Buses["b3"].ConnectedToPhased.Values.SelectMany(x => x).Count());
     foreach(var i in new[] {1,2,3,0})
         Assert.IsTrue(NetworkElement.ConnectionExists(network.Buses["b4"], 1, network.Loads[3], 1));
 }
示例#6
0
        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"]);
        }
示例#7
0
        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"]);
        }
        /// <summary>
        /// Draws all the network lines.
        /// </summary>
        /// <param name="Network">The network from which to draw buses.</param>
        /// <param name="colorMap">A map of the colours to use from the specified gradient.</param>
        /// <param name="drawingContext">The target that we should draw to.</param>
        protected void DrawLines(NetworkModel Network, AdaptiveGradientMap<Tuple<Brush, Pen>> colorMap, DrawingContext drawingContext)
        {
            //Draw all the lines.
            foreach (Line line in Network.Lines)
            {
                if (line.ConnectedTo.Count() != 2)
                    continue;
                Bus bus1 = (Bus)line.ConnectedTo.ElementAt(0);
                Bus bus2 = (Bus)line.ConnectedTo.ElementAt(1);

                if (!(bus1.Location.HasValue && bus2.Location.HasValue))
                    continue;

                //color based on average value.
                var bCol1 = BusVisibleTransform(bus1) ? BusColorTransform(bus1) : 0;
                var bCol2 = BusVisibleTransform(bus2) ? BusColorTransform(bus2) : 0;

                double v_avg = (bCol1 + bCol2) / 2;
                drawingContext.DrawLine(
                    colorMap.Map(v_avg).Item2, //choose the right color for the value
                    ScaledLocation(bus1.Location.Value), //scale the locations to image coordinates.
                    ScaledLocation(bus2.Location.Value)
                    );
            }
        }
        /// <summary>
        /// Draws all the network buses, using the specified value transforms.
        /// </summary>
        /// <param name="Network">The network from which to draw buses.</param>
        /// <param name="colorMap">A map of the colours to use from the specified gradient.</param>
        /// <param name="busSizeLimits">The limits of <see cref="BusSizeTransform"/>,
        /// used for scaling from that space to
        /// [<see cref="BusSizeMin"/>, <see cref="BusSizeMax"/>].</param>
        /// <param name="ringColorPen">A pen for drawing rings.</param>
        /// <param name="drawingContext">The target that we should draw to.</param>
        protected void DrawBuses(NetworkModel Network, AdaptiveGradientMap<Tuple<Brush, Pen>> colorMap, Limits busSizeLimits, Pen ringColorPen, DrawingContext drawingContext)
        {
            //Draw all the buses.
            foreach (var bus in Network.Buses.Values)
            {
                if (!(BusVisibleTransform(bus) && bus.Location.HasValue))
                    continue;
                var bSize = busSizeLimits.ValueScaledToLimits(BusSizeTransform(bus));
                //value-dependant fill, no outline, centre is scaled, radius of 2 (small dots).
                drawingContext.DrawEllipse(
                    colorMap.Map(BusColorTransform(bus)).Item1,
                    null, ScaledLocation(bus.Location.Value), bSize, bSize);

                //Bus Ring
                if (RingEnabledTransform(bus))
                {
                    var ringRadius = RingDistanceFromCenter ?
                        /*true*/ RingDistanceTransform(bus) :
                        /*false*/ bSize + RingDistanceTransform(bus);

                    drawingContext.DrawEllipse(null, ringColorPen,
                        ScaledLocation(bus.Location.Value), ringRadius, ringRadius);
                }
            }
        }
        /// <summary>
        /// Builds a gradient map based upon <see cref="BusColorGradient"/> and
        /// <see cref="BusColorTransform"/> for the data in this network.
        /// </summary>
        /// <param name="Network">The network that data should be taken from.</param>
        /// <returns>A map of gradients.</returns>
        protected AdaptiveGradientMap<Tuple<Brush, Pen>> BuildGradientMap(NetworkModel Network)
        {
            //1. Setup adaptive gradient.
            BusColorGradient.ResetAutoData();
            foreach (var b in Network.Buses.Values)
                BusColorGradient.ProcessData(BusColorTransform(b));

            AdaptiveGradientMapBuilder mapBuilder = new AdaptiveGradientMapBuilder(BusColorGradient);

            AdaptiveGradientMap<Tuple<Brush, Pen>> colorMap = mapBuilder.BuildGradientMap(c =>
            {
                Brush b = new SolidColorBrush(c);
                b.Freeze();
                Pen p = new Pen(b, LineThickness);
                p.Freeze();
                return new Tuple<Brush, Pen>(b, p);
            });
            return colorMap;
        }
示例#11
0
        /// <summary>
        /// Runs the simulation, and an experiment (<see cref="IExperimentor"/>, if specified), and 
        /// applies a results transform (<see cref="IResultsTransform"/>, if specified). After simulation
        /// has been run, the network can be retrieved for plotting/analysis.
        /// </summary>
        public void Execute()
        {
            simulator.PrepareNetwork(NetworkFilename);

            if (!CacheNetwork || _initialNetwork == null)
            {
                _initialNetwork = simulator.GetNetworkModel();
                Network = _initialNetwork;
            }

            //if we're supposed to be running an Experiment,
            if (ExperimentDriver != null)
            {
                //Notify the Results Transformer of preliminary (pre-experiment)
                // results.
                if (ResultsTransformer != null)
                {
                    ResultsTransformer.PreExperimentHook(_initialNetwork);
                }
                //Run the Experiment commands.
                foreach (String str in ExperimentDriver.Experiment(_initialNetwork))
                {
                    simulator.RunCommand(str);
                }

                //Solve the network again.
                Network = simulator.GetNetworkModel();
            }
            //If we're using a Results Transformer, use it to finalise results.
            if (ResultsTransformer != null)
            {
                ResultsTransformer.PostExperimentHook(Network);
            }
        }
示例#12
0
 /// <summary>
 /// Forces the pre-experiment network to be recalculated.
 /// </summary>
 public void ClearNetworkCache()
 {
     _initialNetwork = null;
 }