コード例 #1
0
        Complex CalculateCurrentForDistributionGenerator(Node node, IEnumerable <Complex> childCurrents, Dictionary <long, LoadFlowResult> lf)
        {
            DistributionGenerator dg = node.IO as DistributionGenerator;

            if (dg == null || dg.Terminals.Count != 1)
            {
                return(Complex.NaN());
            }

            Terminal t = Get(dg.Terminals[0]) as Terminal;

            if (t == null)
            {
                return(Complex.NaN());
            }

            LoadFlowResult lfr;

            if (!lf.TryGetValue(t.ConnectivityNode, out lfr))
            {
                return(Complex.NaN());
            }

            double  ur = lfr.Get(LoadFlowResultType.UR);
            double  ui = lfr.Get(LoadFlowResultType.UI);
            Complex i  = GetPowerForDistributionGenerator(dg).Divide(new Complex(ur, -ui));

            return(i);
        }
コード例 #2
0
        public void EqualityLineCdfTest(int noPointsToSample, int min, int max)
        {
            // this test on home pc can do 10^7 samples in < 3 secs.
            string pdfName = "equality";
            string cdfname = "cdfName";
            ISingleVariableFunction <double, int> function = new EqualityPdf();
            var randomActor = Sys.ActorOf(RandomDoubleActor.CreateProps(new System.Random()));
            var generator   = Sys.ActorOf(DistributionGenerator.CreateProps(randomActor), DistributionGenerator.Name);

            var tp = CreateTestProbe();

            generator.Tell(new DistributionGenerator.SubscribeToPdfAdded(), tp);
            generator.Tell(new DistributionGenerator.AddProbabilityDensityFunction(pdfName, function), tp);

            var pdfAdded = tp.ExpectMsg <DistributionGenerator.PdfFunctionAdded>();

            generator.Tell(new DistributionGenerator.SubscribeToCdfAdded(), tp);
            generator.Tell(new DistributionGenerator.GenerateCdfFromPdf(cdfname, pdfName, min, max, noPointsToSample));

            var cdfAdded = tp.ExpectMsg <DistributionGenerator.CdfFunctionAdded>();

            string distributionName = "testDistribution";

            generator.Tell(new DistributionGenerator.Generate(distributionName, cdfname, noPointsToSample));
            generator.Tell(new DistributionGenerator.SubscribeToDistributionGenerated(), tp);

            var generatedMessage = tp.ExpectMsg <DistributionGenerator.DistributionGenerated>();

            Assert.AreEqual(distributionName, generatedMessage.DistributionName);
            Assert.IsTrue(generatedMessage.Distribution.Min() >= min);
            Assert.IsTrue(generatedMessage.Distribution.Max() <= max);
            Assert.AreEqual(noPointsToSample, generatedMessage.Distribution.Length);
        }
コード例 #3
0
        public void TestGenerateAscendingDistribution()
        {
            var generator = new DistributionGenerator();

            int[] array = generator.GenerateAscendingDistribution(5);
            Assert.IsTrue(array[0] < array[1] && array[1] < array[2]);
        }
コード例 #4
0
        public void CallGeneratorWithMinMaxNoResults(int min, int max, int noResults)
        {
            string functionName = "equality";
            ISingleVariableFunction <int, double> function = new EqualityCdf(min, max);
            var randomActor = Sys.ActorOf(RandomDoubleActor.CreateProps(new System.Random()));
            var generator   = Sys.ActorOf(DistributionGenerator.CreateProps(randomActor), DistributionGenerator.Name);

            var tp = CreateTestProbe();

            generator.Tell(new DistributionGenerator.SubscribeToCdfAdded(), tp);
            generator.Tell(new DistributionGenerator.AddCumulativeDistributionFunction(functionName, function), tp);

            var msg = tp.ExpectMsg <DistributionGenerator.CdfFunctionAdded>();

            Assert.AreEqual(functionName, msg.FunctionName);

            string distributionName = "testDistribution";

            generator.Tell(new DistributionGenerator.Generate(distributionName, functionName, noResults));
            generator.Tell(new DistributionGenerator.SubscribeToDistributionGenerated(), tp);

            var generatedMessage = tp.ExpectMsg <DistributionGenerator.DistributionGenerated>();

            Assert.AreEqual(distributionName, generatedMessage.DistributionName);
            Assert.IsTrue(generatedMessage.Distribution.Min() >= min);
            Assert.IsTrue(generatedMessage.Distribution.Max() <= max);
            Assert.AreEqual(noResults, generatedMessage.Distribution.Length);
        }
コード例 #5
0
        Complex GetPowerForDistributionGenerator(DistributionGenerator dg)
        {
            float re = float.NaN;
            float im = float.NaN;

            for (int i = 0; i < dg.Measurements.Count; ++i)
            {
                Analog analog = Get(dg.Measurements[i]) as Analog;

                if (analog == null)
                {
                    continue;
                }

                switch (analog.MeasurementType)
                {
                case MeasurementType.ActivePower:
                    if (!analogs.TryGetValue(analog.GID, out re))
                    {
                        re = analog.NormalValue;
                    }

                    break;

                case MeasurementType.ReactivePower:
                    if (!analogs.TryGetValue(analog.GID, out im))
                    {
                        im = analog.NormalValue;
                    }

                    break;
                }
            }

            if (float.IsNaN(re) || float.IsNaN(im))
            {
                float ratedS = dg.RatedPower;
                float ratedP = ratedS * dg.RatedCosPhi;
                float ratedQ = (float)(ratedS * Math.Sqrt(1 - dg.RatedCosPhi * dg.RatedCosPhi));

                re = ratedP;
                im = ratedQ;
            }

            return(new Complex(-re, -im));
        }
コード例 #6
0
        void PopulateDistributionGeneratorProperties(DistributionGenerator x, ResourceDescription rd)
        {
            PopulateConductingEquipmentProperties(x, rd);

            if (x.RatedCosPhiHasValue)
            {
                rd.AddProperty(new FloatProperty(ModelCode.DISTRIBUTIONGENERATOR_RATEDCOSPHI, x.RatedCosPhi));
            }

            if (x.RatedPowerHasValue)
            {
                rd.AddProperty(new FloatProperty(ModelCode.DISTRIBUTIONGENERATOR_RATEDPOWER, x.RatedPower));
            }

            if (x.RatedVoltageHasValue)
            {
                rd.AddProperty(new FloatProperty(ModelCode.DISTRIBUTIONGENERATOR_RATEDVOLTAGE, x.RatedVoltage));
            }
        }