Ejemplo n.º 1
0
        ///Select the signature definition method of the current frame
        private GaFrame translate_Frame_Signature(ParseTreeNode node)
        {
            var subnode = node.ChildNodes[0];

            switch (subnode.ToString())
            {
            case GMacParseNodeNames.FrameSignatureEuclidean:
                return(GaFrame.CreateEuclidean(_vSpaceDim));

            case GMacParseNodeNames.FrameSignatureIpm:
                return(translate_Frame_Signature_IPM(subnode));

            case GMacParseNodeNames.FrameSignatureCbm:
                return(translate_Frame_Signature_CBM(subnode));

            case GMacParseNodeNames.FrameSignatureOrthonormal:
                return(translate_Frame_Signature_Orthonormal(subnode));

            case GMacParseNodeNames.FrameSignatureOrthogonal:
                return(translate_Frame_Signature_Orthogonal(subnode));

            case GMacParseNodeNames.FrameSignatureReciprocal:
                return(translate_Frame_Signature_Reciprocal(subnode));

            default:
                return(CompilationLog.RaiseGeneratorError <GaFrame>("Illegal frame signature definition", subnode));
            }
        }
Ejemplo n.º 2
0
        ///Set the signature of the current frame to a signature vector (diagonal IPM)
        private GaFrame translate_Frame_Signature_Orthogonal(ParseTreeNode node)
        {
            var bvSigVector = MathematicaVector.Create(Cas, GenUtils.Translate_StringLiteral(node.ChildNodes[0]));

            if (bvSigVector.Size != _vSpaceDim)
            {
                CompilationLog.RaiseGeneratorError <int>("Expecting a vector with " + _vSpaceDim + " items", node.ChildNodes[0]);
            }

            return(GaFrame.CreateOrthogonal(bvSigVector));
        }
Ejemplo n.º 3
0
        ///Set the signature of the current frame to a signature vector of +1's and -1's (diagonal IPM)
        private GaFrame translate_Frame_Signature_Orthonormal(ParseTreeNode node)
        {
            var bvSigString = GenUtils.Translate_StringLiteral(node.ChildNodes[0]).Trim();

            if (bvSigString.Count(c => c == '+' || c == '-') != _vSpaceDim || bvSigString.Length != _vSpaceDim)
            {
                CompilationLog.RaiseGeneratorError <int>("Expecting a vector of " + _vSpaceDim + @" (+\-) items", node.ChildNodes[0]);
            }

            return(GaFrame.CreateOrthonormal(bvSigString));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a child frame
        /// </summary>
        /// <param name="frameName"></param>
        /// <param name="basisVectorsNames"></param>
        /// <param name="attachedSymbolicFrame"></param>
        /// <returns></returns>
        internal GMacFrame DefineFrame(string frameName, string[] basisVectorsNames, GaFrame attachedSymbolicFrame)
        {
            var newFrame = new GMacFrame(frameName, ChildSymbolScope, attachedSymbolicFrame);

            GMacRootAst.FramesCount++;

            newFrame.DefineFrameMultivector();

            newFrame.DefineBasisVectors(basisVectorsNames);

            return(newFrame);
        }
Ejemplo n.º 5
0
        ///Set the signature of the current frame to be defined by IPM
        private GaFrame translate_Frame_Signature_IPM(ParseTreeNode node)
        {
            //Read the IPM symbolic matrix
            var ipmMatrix = MathematicaMatrix.Create(Cas, GenUtils.Translate_StringLiteral(node.ChildNodes[0]));

            if (ipmMatrix.IsSymmetric() == false || ipmMatrix.Rows != _vSpaceDim)
            {
                CompilationLog.RaiseGeneratorError <int>("Expecting a square symmetric matrix with " + _vSpaceDim + " rows", node.ChildNodes[0]);
            }

            return(GaFrame.CreateFromIpm(ipmMatrix));
        }
Ejemplo n.º 6
0
        private GMacFrame DefineFrame(string frameName, string[] basisVectorsNames, GaFrame attachedSymbolicFrame, bool defineDefaultObjects)
        {
            if (Context.GMacRootAst.FramesCount + 1 > GMacCompilerFeatures.MaxFramesNumber)
            {
                CompilationLog.RaiseGeneratorError <int>($"Can't define more than {GMacCompilerFeatures.MaxFramesNumber} frames", RootParseNode);
            }

            var frame = Context.ParentNamespace.DefineFrame(frameName, basisVectorsNames, attachedSymbolicFrame);

            if (defineDefaultObjects)
            {
                DefineFrameDefaultObjects(frame);
            }

            return(frame);
        }
Ejemplo n.º 7
0
        ///Set the signature of the current frame to a reciprocal frame
        private GaFrame translate_Frame_Signature_Reciprocal(ParseTreeNode node)
        {
            var baseFrame =
                (GMacFrame)GMacValueAccessGenerator.Translate_Direct(Context, node.ChildNodes[0], RoleNames.Frame);

            if (baseFrame.VSpaceDimension != _vSpaceDim)
            {
                CompilationLog.RaiseGeneratorError <int>("Base frame must be of dimension " + _vSpaceDim, node.ChildNodes[0]);
            }

            _baseFrame = baseFrame;

            var derivedFrameSystem = GaFrame.CreateReciprocalCbmFrameSystem(baseFrame.AssociatedSymbolicFrame);

            return(derivedFrameSystem.DerivedFrame);
        }
Ejemplo n.º 8
0
        internal GMacFrame(string frameName, LanguageScope parentScope, GaFrame attachedFrame)
            : base(frameName, parentScope, RoleNames.Frame)
        {
            AssociatedSymbolicFrame = attachedFrame;

            FrameBasisVectors =
                ChildSymbolScope.Symbols(RoleNames.FrameBasisVector).Cast <GMacFrameBasisVector>();

            ChildConstants =
                ChildSymbolScope.Symbols(RoleNames.Constant).Cast <GMacConstant>();

            ChildMacros =
                ChildSymbolScope.Symbols(RoleNames.Macro).Cast <GMacMacro>();

            FrameSubspaces =
                ChildSymbolScope.Symbols(RoleNames.FrameSubspace).Cast <GMacFrameSubspace>();

            Structures =
                ChildSymbolScope.Symbols(RoleNames.Structure).Cast <GMacStructure>();

            Transforms =
                ChildSymbolScope.Symbols(RoleNames.Transform).Cast <GMacMultivectorTransform>();
        }
Ejemplo n.º 9
0
        ///Set the signature of the current frame to a base frame with a change of basis matrix
        private GaFrame translate_Frame_Signature_CBM(ParseTreeNode node)
        {
            var baseFrame =
                (GMacFrame)GMacValueAccessGenerator.Translate_Direct(Context, node.ChildNodes[0], RoleNames.Frame);

            if (baseFrame.VSpaceDimension != _vSpaceDim)
            {
                CompilationLog.RaiseGeneratorError <int>("Base frame must be of dimension " + _vSpaceDim, node.ChildNodes[0]);
            }

            var cbmMatrix = MathematicaMatrix.Create(Cas, GenUtils.Translate_StringLiteral(node.ChildNodes[1]));

            if (cbmMatrix.IsInvertable() == false || cbmMatrix.Rows != _vSpaceDim)
            {
                CompilationLog.RaiseGeneratorError <int>("Expecting a square invertable matrix with " + _vSpaceDim + " rows", node.ChildNodes[1]);
            }

            _baseFrame = baseFrame;

            var derivedFrameSystem = GaFrame.CreateDerivedCbmFrameSystem(baseFrame.AssociatedSymbolicFrame, cbmMatrix);

            return(derivedFrameSystem.DerivedFrame);
        }