예제 #1
0
        public static GaPoTNumVector operator *(GaPoTNumVector v1, GaPoTNumBiversor bv2)
        {
            var vector = new GaPoTNumVector();

            foreach (var term1 in v1.GetTerms())
            {
                foreach (var term2 in bv2.GetTerms())
                {
                    var scalarValue = term1.Value * term2.Value;

                    if (term2.IsScalar)
                    {
                        vector.AddTerm(
                            term1.TermId,
                            scalarValue
                            );

                        continue;
                    }

                    if (term1.TermId == term2.TermId1)
                    {
                        vector.AddTerm(
                            term2.TermId2,
                            scalarValue
                            );

                        continue;
                    }

                    if (term1.TermId == term2.TermId2)
                    {
                        vector.AddTerm(
                            term2.TermId1,
                            -scalarValue
                            );
                    }
                }
            }

            return(vector);
        }
예제 #2
0
        public static GaPoTNumVector operator -(GaPoTNumVector v)
        {
            var result = new GaPoTNumVector();

            foreach (var term in v._termsDictionary.Values)
            {
                result.AddTerm(term.TermId, -term.Value);
            }

            return(result);
        }
예제 #3
0
        public static GaPoTNumVector operator /(GaPoTNumVector v, double s)
        {
            s = 1.0d / s;

            var result = new GaPoTNumVector();

            foreach (var term in v._termsDictionary.Values)
            {
                result.AddTerm(
                    term.TermId,
                    term.Value * s
                    );
            }

            return(result);
        }
예제 #4
0
        private static GaPoTNumVector GaPoTNumParseVector(IronyParsingResults parsingResults, ParseTreeNode rootNode)
        {
            if (rootNode.ToString() != "spVector")
            {
                throw new SyntaxErrorException(parsingResults.ToString());
            }

            var vector = new GaPoTNumVector();

            var vectorNode = rootNode;

            foreach (var vectorElementNode in vectorNode.ChildNodes)
            {
                if (vectorElementNode.ToString() == "spTerm")
                {
                    //Term Form
                    var value = double.Parse(vectorElementNode.ChildNodes[0].FindTokenAndGetText());
                    var id    = int.Parse(vectorElementNode.ChildNodes[1].FindTokenAndGetText());

                    if (id < 0)
                    {
                        throw new SyntaxErrorException(parsingResults.ToString());
                    }

                    vector.AddTerm(id, value);
                }
                else if (vectorElementNode.ToString() == "spPolarPhasor")
                {
                    //Polar Phasor Form
                    var magnitude = double.Parse(vectorElementNode.ChildNodes[1].FindTokenAndGetText());
                    var phase     = double.Parse(vectorElementNode.ChildNodes[2].FindTokenAndGetText());
                    var id1       = int.Parse(vectorElementNode.ChildNodes[3].FindTokenAndGetText());
                    var id2       = int.Parse(vectorElementNode.ChildNodes[4].FindTokenAndGetText());

                    if (id1 < 0 || id2 != id1 + 1)
                    {
                        throw new SyntaxErrorException(parsingResults.ToString());
                    }

                    //Convert phase from degrees to radians
                    phase = phase.DegreesToRadians();

                    vector.AddPolarPhasor(id1, magnitude, phase);
                }
                else if (vectorElementNode.ToString() == "spRectPhasor")
                {
                    //Rectangular Phasor Form
                    var xValue = double.Parse(vectorElementNode.ChildNodes[1].FindTokenAndGetText());
                    var yValue = double.Parse(vectorElementNode.ChildNodes[2].FindTokenAndGetText());
                    var id1    = int.Parse(vectorElementNode.ChildNodes[3].FindTokenAndGetText());
                    var id2    = int.Parse(vectorElementNode.ChildNodes[4].FindTokenAndGetText());

                    if (id1 < 0 || id2 != id1 + 1)
                    {
                        throw new SyntaxErrorException(parsingResults.ToString());
                    }

                    vector.AddRectPhasor(id1, xValue, yValue);
                }
                else
                {
                    throw new SyntaxErrorException(parsingResults.ToString());
                }
            }

            return(vector);
        }