Esempio n. 1
0
        public string FormatQuadratic(List <ITensor> lstT)
        {
            StringBuilder sb = new StringBuilder();

            if (lstT.Count == 3)
            {
                var sortL = from element in lstT
                            orderby element.Rank
                            select element;

                PseudoRank1Tensor p1 = (PseudoRank1Tensor)sortL.ToList()[0];
                p1.IsRowOrColumn = RowColumn.Row;

                PseudoRank1Tensor p2 = (PseudoRank1Tensor)sortL.ToList()[1];
                PseudoRank2Tensor p3 = (PseudoRank2Tensor)sortL.ToList()[2];
                sb.Append(p1.Expand());
                sb.Append(p3.Expand());
                sb.Append(p2.Expand());
            }

            return(sb.ToString());
        }
        public PseudoTensor(string n, int rank, int dim, TensorType tt)
        {
            Rank      = rank;
            Dimension = dim;

            tensorType = tt;

            if (rank == 0)
            {
                Rank0Tensor            = new PseudoRank0Tensor(n);
                Rank0Tensor.tensorType = this.tensorType;
                Rank0Tensor.Dimension  = this.Dimension;
                Rank0Tensor.Rank       = this.Rank;
            }

            if (rank == 1)
            {
                Rank1Tensor = new PseudoRank1Tensor();

                Rank1Tensor.tensorType = this.tensorType;
                Rank1Tensor.Dimension  = this.Dimension;
                Rank1Tensor.Rank       = this.Rank;

                string strTensorType = (tensorType == TensorType.Contravariant) ? "^" : "_";
                for (int i = 0; i < this.Dimension; i++)
                {
                    string val = $"{n}{strTensorType}{(i + 1).ToString()}";
                    Symbol sym = new Symbol();
                    sym.Expression  = val;
                    sym.LatexString = val;
                    Rank1Tensor.Add(sym);
                }
            }

            if (rank == 2)
            {
                Rank2Tensor            = new PseudoRank2Tensor(Dimension, Dimension);
                Rank2Tensor.tensorType = this.tensorType;
                Rank2Tensor.Dimension  = this.Dimension;
                Rank2Tensor.Rank       = this.Rank;

                string strTensorType = "_{ij}";

                if (tensorType == TensorType.Contravariant)
                {
                    strTensorType = "^{ij}";
                }

                if (tensorType == TensorType.Mixed)
                {
                    strTensorType = "_i^j";
                }
                for (int i = 0; i < Rank2Tensor.Rows; i++)
                {
                    for (int j = 0; j < Rank2Tensor.Columns; j++)
                    {
                        string val = n + strTensorType;
                        val = val.Replace("i", (i + 1).ToString()).Replace("j", (j + 1).ToString());

                        Symbol sym = new Symbol();
                        sym.Expression    = val;
                        sym.LatexString   = val;
                        Rank2Tensor[i, j] = sym;
                    }
                }
            }
        }