コード例 #1
0
        //TODO: This requires more acceleration (try to build the expressions then evaluate once per basis blade id for result_mv)
        //private GAMultivectorCoefficients BilinearProduct(GAMultivectorCoefficients mv1, GAMultivectorCoefficients mv2, Func<int, int, bool> term_discard_function)
        //{
        //    if (mv1.GASpaceDim != mv2.GASpaceDim || mv1.GASpaceDim != GASpaceDim)
        //        throw new GMacSymbolicException("Multivector size mismatch");

        //    GAMultivectorCoefficients mv = GAMultivectorCoefficients.CreateZero(mv1.GASpaceDim);

        //    foreach (var term1 in mv1)
        //    {
        //        int id1 = term1.Key;
        //        MathematicaScalar coef1 = term1.Value;

        //        foreach (var term2 in mv2.FilterTermsUsing(id1, term_discard_function))
        //        {
        //            int id2 = term2.Key;
        //            MathematicaScalar coef2 = term2.Value;

        //            int id = id1 ^ id2;

        //            if (GAUtils.IDs_To_EGP_Sign(id1, id2))
        //                mv[id] -= coef1 * coef2 * _BasisBladesSignatures[id];
        //            else
        //                mv[id] += coef1 * coef2 * _BasisBladesSignatures[id];
        //        }
        //    }

        //    return mv;
        //}
        private GaMultivector BilinearProduct(GaMultivector mv1, GaMultivector mv2, Func <int, int, bool> termDiscardFunction)
        {
            if (mv1.GaSpaceDim != mv2.GaSpaceDim || mv1.GaSpaceDim != GaSpaceDimension)
            {
                throw new GMacSymbolicException("Multivector size mismatch");
            }

            var terms1 = mv1.ToStringsDictionary();

            var terms2 = mv2.ToStringsDictionary();

            var accumExprDict = new Dictionary <int, ListComposer>();

            foreach (var term1 in terms1)
            {
                var id1   = term1.Key;
                var coef1 = term1.Value;

                foreach (var term2 in terms2.FilterTermsUsing(id1, termDiscardFunction))
                {
                    var id2   = term2.Key;
                    var coef2 = term2.Value;

                    var resultId = id1 ^ id2;
                    var sigId    = id1 & id2;

                    var resultCoefDelta =
                        EuclideanUtils.Times(
                            coef1,
                            coef2,
                            _basisBladesSignatures[sigId].MathExpr.ToString(),
                            FrameUtils.IsNegativeEGp(id1, id2)
                            );

                    accumExprDict.AddTerm(resultId, resultCoefDelta);
                }
            }

            return(accumExprDict.ToMultivector(mv1.GaSpaceDim));
        }
コード例 #2
0
ファイル: GAOuterMorphismFull.cs プロジェクト: phreed/GMac
        //TODO: This requires more acceleration (try to build the expressions then evaluate once per basis blade id for result_mv)
        //public override GAMultivectorCoefficients Transform(GAMultivectorCoefficients mv1)
        //{
        //    if (mv1.GASpaceDim != this.DomainGASpaceDim)
        //        throw new GMacSymbolicException("Multivector GA space dimension does not agree with domain GA space dimension");

        //    GAMultivectorCoefficients result_mv = GAMultivectorCoefficients.CreateZero(CodomainGASpaceDim);

        //    foreach (var term1 in mv1)
        //    {
        //        var coef1 = term1.Value;

        //        var mv2 = _TransformedBasisBlades[term1.Key];

        //        foreach (var term2 in mv2)
        //        {
        //            var coef2 = term2.Value;

        //            var result_id = term2.Key;

        //            result_mv[result_id] += coef1 * coef2;
        //        }
        //    }

        //    return result_mv;
        //}

        public override GaMultivector Transform(GaMultivector mv1)
        {
            if (mv1.GaSpaceDim != DomainGaSpaceDim)
            {
                throw new GMacSymbolicException("Multivector GA space dimension does not agree with domain GA space dimension");
            }

            var accumExprDict = new Dictionary <int, ListComposer>();

            var terms1 = mv1.ToStringsDictionary();

            foreach (var term1 in terms1)
            {
                var terms2 = _transformedBasisBlades[term1.Key].ToStringsDictionary();

                foreach (var term2 in terms2)
                {
                    accumExprDict.AddTerm(term2.Key, EuclideanUtils.Times(term1.Value, term2.Value));
                }
            }

            return(accumExprDict.ToMultivector(CodomainGaSpaceDim));
        }