Пример #1
0
        private void IndexColumns()
        {
            // assume first row is header with names
            var header = _sheet.Rows[0];

            for (var index = 0; index < header.Cells.Length; index++)
            {
                var name = header.TextCells[index];
                if (!String.IsNullOrWhiteSpace(name))
                {
                    var column = _columns.FirstOrDefault(x => String.Compare(x, name, true) == 0);
                    if (column == null)
                    {
                        UnknownColumns.Add(column);                         // unknown column
                    }
                    else
                    {
                        ColumnIndex.Add(column, index);
                    }
                }
            }

            // figure out which columns are missing
            foreach (var col in _columns)
            {
                if (!ColumnIndex.ContainsKey(col))
                {
                    MissingColumns.Add(col);
                }
            }
        }
 protected virtual void AddFields(int i, string name, PropertyInfo propertyInfo)
 {
     ColumnNames.Add(name, propertyInfo);
     ColumnIndex.Add(i, propertyInfo);
     IndexToName.Add(i, name);
     NameToIndex.Add(name, i);
 }
Пример #3
0
        /// <summary>
        /// provides data collected during a solver run in tabular form
        /// </summary>
        /// <param name="ErrorOrResidual">
        /// - true: output is error against exact solution (if provided) during each iteration
        /// - false: output is residual against exact solution (if provided) during each iteration
        /// </param>
        /// <param name="SepVars">
        /// - true: separate column for each variable
        /// - false:  l2-norm over all variables
        /// </param>
        /// <param name="SepPoly">
        /// - true:   separate column for each polynomial degree
        /// - false:  l2-norm over all polynomial degrees
        /// </param>
        /// <param name="SepLev">
        /// - true:   separate column for each multi-grid level
        /// - false:  l2-norm over all multi-grid levels
        /// </param>
        /// <param name="Titels">
        /// Column names/titles
        /// </param>
        /// <param name="ConvTrendData">
        /// data table:
        /// - columns: correspond to <paramref name="Titels"/>
        /// - rows: solver iterations
        /// </param>
        public void WriteTrendToTable(bool ErrorOrResidual, bool SepVars, bool SepPoly, bool SepLev, out string[] Titels, out MultidimensionalArray ConvTrendData)
        {
            var data = ErrorOrResidual ? ErrNormTrend : ResNormTrend;

            List <string> titleS = new List <string>();
            int           iCol   = 0;
            Dictionary <(int MGlevel, int iVar, int deg), int> ColumnIndex = new Dictionary <(int, int, int), int>();

            foreach (var kv in data)
            {
                int iLevel = kv.Key.Item1;
                int pDG    = kv.Key.Item3;
                int iVar   = kv.Key.Item2;

                string title;
                {
                    if (SepVars)
                    {
                        title = $"Var{iVar}";
                    }
                    else
                    {
                        title = "";
                    }

                    if (SepLev)
                    {
                        if (title.Length > 0)
                        {
                            title = title + ",";
                        }
                        title = title + $"Mglv{iLevel}";
                    }

                    if (SepPoly)
                    {
                        if (title.Length > 0)
                        {
                            title = title + ",";
                        }
                        title = title + $"p={pDG}";
                    }

                    if (title.Length > 0)
                    {
                        title = "_" + title;
                    }

                    if (ErrorOrResidual)
                    {
                        title = "Err" + title;
                    }
                    else
                    {
                        title = "Res" + title;
                    }
                }

                /*
                 * if (SepPoly == false && SepLev == false) {
                 *  title = string.Format("(var#{0})", iVar);
                 * } else if (SepPoly == false && SepLev == true) {
                 *  title = string.Format("(var#{0},mg.lev.{1})", iVar, iLevel);
                 * } else if (SepPoly == true && SepLev == false) {
                 *  title = string.Format("(var#{0},p={1})", iVar, pDG);
                 * } else if (SepPoly == true && SepLev == true) {
                 *  title = string.Format("(var#{0},mg.lev.{1},p={2})", iVar, iLevel, pDG);
                 * } else {
                 *  throw new ApplicationException();
                 * }
                 */

                int iColKv = titleS.IndexOf(title);
                if (iColKv < 0)
                {
                    titleS.Add(title);
                    iColKv = iCol;
                    iCol++;
                }
                ColumnIndex.Add(kv.Key, iColKv);
            }
            Titels        = titleS.ToArray();
            ConvTrendData = MultidimensionalArray.Create(data.First().Value.Count, titleS.Count);

            foreach (var kv in data)   // over all data columns

            {
                double[] ColumnSquared = kv.Value.Select(val => val.Pow2()).ToArray();

                if (ConvTrendData.GetLength(0) != ColumnSquared.Length)
                {
                    throw new ApplicationException();
                }

                int iColkv = ColumnIndex[kv.Key]; // output column index in which we sum up the column
                ConvTrendData.ExtractSubArrayShallow(-1, iColkv).AccVector(1.0, ColumnSquared);
            }
            ConvTrendData.ApplyAll(x => Math.Sqrt(x));
        }