Exemple #1
0
        /// <summary>
        /// Takes a specialized multivector specification (G25.SMV) and converts it into a symbolic multivector.
        /// The symbolic weights of the multivector are the coordinates of the SMV, labelled according to 'smvName'.
        ///
        /// An example is <c>A.c[0]*e1 + A.c[1]*e2 + A.c[2]*e3</c>.
        /// </summary>
        /// <param name="S">Specification of the algebra. Used for the access convention (. or ->) and for how to name the coordinates ([0] or e1, e2, e3).</param>
        /// <param name="smv">The specification of the specialized multivector.</param>
        /// <param name="smvName">Name the variable should have.</param>
        /// <param name="ptr">Is 'smvName' a pointer? This changes the way the variable is accessed.</param>
        /// <returns></returns>
        public static RefGA.Multivector SMVtoSymbolicMultivector(Specification S, G25.SMV smv, string smvName, bool ptr)
        {
            int idx = 0; // index into 'L'

            RefGA.BasisBlade[] L = new RefGA.BasisBlade[smv.NbConstBasisBlade + smv.NbNonConstBasisBlade];


            string[] AL = CodeUtil.GetAccessStr(S, smv, smvName, ptr);
            // get non-const coords
            for (int i = 0; i < smv.NbNonConstBasisBlade; i++)
            {
                // get basis blade of coordinate
                RefGA.BasisBlade B = smv.NonConstBasisBlade(i);

                // merge
                L[idx++] = new RefGA.BasisBlade(B.bitmap, B.scale, AL[i]);
            }

            // get const coords
            for (int i = 0; i < smv.NbConstBasisBlade; i++)
            {
                // get value of coordinate
                double value = smv.ConstBasisBladeValue(i);

                // get basis blade of coordinate
                RefGA.BasisBlade B = smv.ConstBasisBlade(i);

                // merge
                L[idx++] = new RefGA.BasisBlade(B.bitmap, B.scale * value);
            }

            return(new RefGA.Multivector(L));
        } // end of SMVtoSymbolicMultivector()
Exemple #2
0
        /// <summary>
        /// Writes code for m_name = m_value.
        /// </summary>
        /// <param name="SB">Where the code goes.</param>
        /// <param name="S">Specification of algebra.</param>
        /// <param name="cgd">Not used yet.</param>
        public override void Write(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd)
        {
            if (m_type is G25.SMV)
            {
                G25.SMV dstSmv = m_type as G25.SMV;

                if (m_declareVariable)
                {
                    SB.AppendLine("/* cannot yet assign and declare SMV type at the same time */");
                }

                RefGA.BasisBlade[] BL        = BasisBlade.GetNonConstBladeList(dstSmv);
                string[]           accessStr = CodeUtil.GetAccessStr(S, dstSmv, m_name, m_ptr);
                bool     writeZeros          = true;
                string[] valueStr            = CodeUtil.GetAssignmentStrings(S, m_floatType, m_mustCast, BL, m_value, writeZeros);

                // apply post operation (like "/ n2")
                ApplyPostOp(S, cgd, BL, valueStr);

                SB.AppendLine(CodeUtil.GenerateAssignmentCode(S, accessStr, valueStr, m_nbTabs, writeZeros));
            }
            else if (m_type is G25.FloatType)
            {
                // temp hack to override float type.
                G25.FloatType FT = this.m_floatType; // m_type as G25.FloatType;

                AppendTabs(SB);

                if (m_declareVariable)
                { // also declare the variable right here?
                    // output "/t type "
                    SB.Append(FT.type + " ");
                }

                // output name = ....;
                RefGA.BasisBlade[] BL = new RefGA.BasisBlade[1] {
                    RefGA.BasisBlade.ONE
                };
                String[] accessStr = new String[1] {
                    m_name
                };
                bool     writeZeros = true;
                String[] valueStr   = CodeUtil.GetAssignmentStrings(S, FT, m_mustCast, BL, m_value, writeZeros);

                // apply post operation (like "/ n2")
                ApplyPostOp(S, cgd, BL, valueStr);

                SB.AppendLine(CodeUtil.GenerateAssignmentCode(S, accessStr, valueStr, 0, writeZeros));
            }
            else
            {
                SB.AppendLine("/* to do: implement " + GetType().ToString() + " for type " + m_type.GetType().ToString() + " */");
            }
        }