Esempio n. 1
0
        /// <summary>
        /// Visualizes the stored data using gnuplot.
        /// </summary>
        public void Plot()
        {
            Gnuplot gp = new Gnuplot();

            gp.SetXLabel("x");
            gp.SetYLabel("y");
            gp.Cmd("set terminal wxt noraise");
            if (LogX)
            {
                gp.Cmd("set logscale x");
                gp.Cmd("set format x \"10^{%L}\"");
            }
            if (LogY)
            {
                gp.Cmd("set logscale y");
                gp.Cmd("set format y \"10^{%L}\"");
            }
            gp.Cmd("set grid xtics ytics");

            int lineColor = 0;

            foreach (var group in dataGroups)
            {
                gp.PlotXY(group.Abscissas, group.Values, group.Name,
                          new PlotFormat(lineColor: ((LineColors)(++lineColor)), pointType: ((PointTypes)4), pointSize: 1.5, Style: Styles.LinesPoints));
            }
            gp.Execute();
        }
Esempio n. 2
0
        /// <summary>
        /// plot a 2D grid
        /// </summary>
        public static void Plot2DGrid(this GridCommons grd, params int[] Cells)
        {
            using (var gp = new Gnuplot()) {
                Console.WriteLine("Plotting 2D grid with gnuplot...");

                if (grd.SpatialDimension != 2)
                {
                    throw new NotSupportedException("works only for 2D grid");
                }


                int J = grd.Cells.Length;
                if (Cells == null)
                {
                    Cells = J.ForLoop(j => j);
                }

                foreach (int j in Cells)
                {
                    var Cell_j = grd.Cells[j];
                    //var Kref = grd.RefElements.Single(KK => KK.SupportedCellTypes.Contains(Cell_j.Type));

                    //var Vtx = Kref.Vertices;
                    //var _Vtx = Kref.GetSubDivTree(3).GlobalVertice;
                    //var Vtx = MultidimensionalArray.Create(_Vtx.GetLength(0), _Vtx.GetLength(1));
                    //Vtx.SetA2d(_Vtx);
                    //Vtx.Scale(1);

                    var Vtx_glob = Cell_j.TransformationParams;


                    double[] xNodes = Vtx_glob.ExtractSubArrayShallow(-1, 0).To1DArray();
                    double[] yNodes = Vtx_glob.ExtractSubArrayShallow(-1, 1).To1DArray();
                    double   xC     = xNodes.Sum() / xNodes.Length;
                    double   yC     = yNodes.Sum() / yNodes.Length;
                    for (int k = 0; k < xNodes.Length; k++)
                    {
                        double dx = xNodes[k] - xC;
                        dx       *= 0.95;
                        xNodes[k] = xC + dx;

                        double dy = yNodes[k] - yC;
                        dy       *= 0.95;
                        yNodes[k] = yC + dy;
                    }

                    double hy = yNodes.Max() - yNodes.Min();

                    gp.PlotXY(xNodes, yNodes, title: null, format: (new PlotFormat(Style: Styles.LinesPoints, lineColor: ((LineColors)j))));

                    gp.Cmd("set label \"{0}\" at {2},{3} font \"Arial,5\"", j.ToString(), Cell_j.GlobalID, xC.ToStringDot(), (yC + hy * 0.21).ToStringDot());
                    gp.Cmd("set label \"[{1}]\" at {2},{3} font \"Arial,5\"", j.ToString(), Cell_j.GlobalID, xC.ToStringDot(), (yC - hy * 0.21).ToStringDot());
                }

                gp.Execute();

                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Utility/Debug function, plots numbers at specific coordinates.
        /// </summary>
        /// <param name="X"></param>
        /// <param name="filename"></param>
        public static void PlotCoordinateLabels(this MultidimensionalArray X, string filename)
        {
            using (var gp = new Gnuplot()) {
                int L = X.NoOfRows;
                if (X.NoOfCols != 2)
                {
                    throw new NotSupportedException("works only for 2D grid");
                }

                gp.Cmd("set terminal png");
                gp.Cmd("set output \"{0}\"", filename);

                gp.SetXRange(-4, 4);
                gp.SetYRange(-4, 4);

                for (int l = 0; l < L; l++)
                {
                    gp.Cmd("set label \"{0}\" at {1},{2}", l, X[l, 0], X[l, 1]);
                }

                gp.PlotSlope(0, 0);
                gp.Execute();
            }
        }
Esempio n. 4
0
        static void Plot2dGridGnuplot(GridCommons grd)
        {
            using (var gp = new Gnuplot()) {
                int J = grd.Cells.Length;


                double xmin = double.MaxValue, xmax = double.MinValue, ymin = double.MaxValue, ymax = double.MinValue;
                for (int j = 0; j < J; j++)
                {
                    var Cell = grd.Cells[j];
                    var Kref = grd.GetRefElement(Cell.Type);

                    int[] R;
                    if (Kref.GetType() == typeof(Triangle))
                    {
                        R = new int[] { 0, 1, 2, 0 };
                    }
                    else if (Kref.GetType() == typeof(Square))
                    {
                        R = new int[] { 0, 1, 3, 2, 0 };
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    int     I        = 4;
                    int     K        = 20;
                    NodeSet LocNodes = new NodeSet(Kref, I * K * (R.Length - 1), 2);
                    var     vtx      = Kref.Vertices;
                    double  alpha    = 1.0 / (K - 1);
                    for (int iFace = 0; iFace < R.Length - 1; iFace++)
                    {
                        for (int k = 0; k < K; k++)
                        {
                            double a = alpha * k;

                            for (int d = 0; d < 2; d++)
                            {
                                LocNodes[iFace * K + k, d] = vtx[R[iFace], d] * (1 - a) + vtx[R[iFace + 1], d] * a;
                            }
                        }
                    }

                    for (int i = 0; i < I; i++)
                    {
                        int ind0  = K * (R.Length - 1) * i;
                        int indE  = K * (R.Length - 1) * (i + 1) - 1;
                        int indp0 = K * (R.Length - 1) * (i - 1);
                        int indpE = K * (R.Length - 1) * i - 1;

                        var LocNodes_i = LocNodes.ExtractSubArrayShallow(new int[] { ind0, 0 }, new int[] { indE, 1 });

                        if (i > 0)
                        {
                            var LocNodes_iP = LocNodes.ExtractSubArrayShallow(new int[] { indp0, 0 }, new int[] { indpE, 1 });
                            LocNodes_i.Set(LocNodes_iP);
                            LocNodes_i.Scale(0.65);
                        }
                        else
                        {
                            LocNodes_i.Scale(0.9);
                        }
                    }


                    LocNodes.LockForever();

                    MultidimensionalArray GlobalNodes = Transform(Kref, Cell, LocNodes);

                    xmin = Math.Min(xmin, GlobalNodes.ExtractSubArrayShallow(-1, 0).Min());
                    xmax = Math.Max(xmax, GlobalNodes.ExtractSubArrayShallow(-1, 0).Max());
                    ymin = Math.Min(ymin, GlobalNodes.ExtractSubArrayShallow(-1, 1).Min());
                    ymax = Math.Max(ymax, GlobalNodes.ExtractSubArrayShallow(-1, 1).Max());

                    gp.PlotXY(GlobalNodes.GetColumn(0), GlobalNodes.GetColumn(1), title: ("tri" + j),
                              format: new PlotFormat(lineColor: ((LineColors)j)));
                }

                gp.SetXRange(xmin - 0.1, xmax + 0.1);
                gp.SetYRange(ymin - 0.1, ymax + 0.1);

                gp.Execute();


                Console.WriteLine("press any key to continue...");
                Console.ReadKey();
            }
        }