Exemple #1
0
 private void UpdateToolStripMenuItem_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < this.queryResult_dgv.Rows.Count; i++)
     {
         try
         {
             WellData wellData = new WellData(
                   queryResult_dgv.Rows[i].Cells[1].Value.ToString(),
                   double.Parse(queryResult_dgv.Rows[i].Cells[2].Value.ToString()),
                   double.Parse(queryResult_dgv.Rows[i].Cells[3].Value.ToString()),
                   queryResult_dgv.Rows[i].Cells[4].Value.ToString(),
                   double.Parse(queryResult_dgv.Rows[i].Cells[5].Value.ToString()),
                   double.Parse(queryResult_dgv.Rows[i].Cells[6].Value.ToString())
                   );
             int id;
             int count = 0;
             if (int.TryParse(queryResult_dgv.Rows[i].Cells[0].Value.ToString(), out id))
             {
                 count = mainForm.sqlServer.Update(wellData, id);
             }
             else if (queryResult_dgv.Rows[i].Cells[0].Value.ToString() == "")
             {
                 count = mainForm.sqlServer.Insert(wellData);
             }
             this.NumberOfLinesAffected_toolStripStatusLabel.Text = count.ToString() + " lines affected.";
         }
         catch (Exception)
         {
             MessageBox.Show("Invalid Input Data Existed.");
         }
     }
 }
Exemple #2
0
    //remember to change the well datat to well point?
    public static WellData ReadFile(string filePath)
    {
        WellData      myWell       = new WellData();
        List <double> myWellPointX = new List <double>();
        List <double> myWellPointY = new List <double>();
        List <double> myWellPointZ = new List <double>();

        try
        {
            using (StreamReader myStreamReader = new StreamReader(filePath))
            {
                String[] onePoint;
                while (!myStreamReader.EndOfStream)
                {
                    onePoint = myStreamReader.ReadLine().Split(',');
                    double myX = Double.Parse(onePoint[0]);
                    double myY = Double.Parse(onePoint[1]);
                    double myZ = Double.Parse(onePoint[2]);

                    myWellPointX.Add(myX);
                    myWellPointY.Add(myY);
                    myWellPointZ.Add(myZ);
                }
            }
            myWell.WellPointX = myWellPointX;
            myWell.WellPointY = myWellPointY;
            myWell.WellPointZ = myWellPointZ;
            return(myWell);
        }
        catch (IOException)
        {
            Console.WriteLine("Import Failed! The file includes empty entry.");
            return(null);
        }
    }
Exemple #3
0
    public static void Main()
    {
        string[] pointOfView = new string[] { "FrontView", "EndView", "VerticleView" };
        for (int i = 5; i < 6; i = i + 1)
        {
            string importFilePath = @"G:\HW5\HW5\\" + i + ".csv";

            WellData myWellData = Import.ReadFile(importFilePath);
            foreach (string point in pointOfView)
            {
                string filePath = @"G:\HW5\HW5\\" + i + point + ".txt";
                Plot.InitializeAndPlotGraph(myWellData, point, 150, 200, filePath);
            }
        }
    }
Exemple #4
0
        public double[] Run(DateTime _optimizationDate)
        {
            optimizationDate = _optimizationDate;
            double maxKGF  = graph.wells.Where(s => s.Gg != 0).Max(m => m.Gl / m.Gg),
                   min1KGF = graph.wells.Where(s => s.Gg != 0).Min(m => m.Gl / m.Gg),
                   min2KGF = graph.wells.Where(z => (z.Gg != 0) && (z.Gl / z.Gg != min1KGF)).Min(m => m.Gl / m.Gg);

            maxKGFWell  = graph.wells.First(z => z.Gl / z.Gg == maxKGF);
            min1KGFWell = graph.wells.First(z => z.Gl / z.Gg == min1KGF);
            min2KGFWell = graph.wells.First(z => z.Gl / z.Gg == min2KGF);

            evaluator.CalcGraph(optimizationDate);
            Psb = graph.endNode.P;
            Gsb = graph.endNode.G;

            return(context.Run(0.001, new [] { 0.06, 0.12, 0.08 }));
        }
Exemple #5
0
    public static void InitializeAndPlotGraph(WellData myWell, string pointOfView, int rangeX, int rangeY, string filePath)
    {
        double maxX = myWell.WellPointX.Max();
        double maxY = myWell.WellPointY.Max();
        double maxZ = myWell.WellPointZ.Max();

        double minX = myWell.WellPointX.Min();
        double minY = myWell.WellPointY.Min();
        double minZ = myWell.WellPointZ.Min();

        int[] adjustedWellPointX, adjustedWellPointZ, adjustedWellPointY;

        switch (pointOfView)
        {
        //XZ
        case "FrontView":
            adjustedWellPointX         = ResizePointToFitPlot(myWell.WellPointX, rangeX, minX, maxX);
            adjustedWellPointZ         = ResizePointToFitPlot(myWell.WellPointZ, rangeY, minZ, maxZ);
            myWell.WellTrajectoryGraph = PlotWellTrajectory(adjustedWellPointX, adjustedWellPointZ, myWell.WellPointX, myWell.WellPointY, myWell.WellPointZ, rangeX, rangeY);
            //myWell.WellTrajectoryGraph = PlotAixs(myWell.WellTrajectoryGraph, "x", "z", spaceForAxis);
            Output.PrintFileAsTxt(filePath, myWell.WellTrajectoryGraph);
            break;

        //yz
        case "EndView":
            adjustedWellPointY         = ResizePointToFitPlot(myWell.WellPointY, rangeX, minY, maxY);
            adjustedWellPointZ         = ResizePointToFitPlot(myWell.WellPointZ, rangeY, minZ, maxZ);
            myWell.WellTrajectoryGraph = PlotWellTrajectory(adjustedWellPointY, adjustedWellPointZ, myWell.WellPointX, myWell.WellPointY, myWell.WellPointZ, rangeX, rangeY);
            //myWell.WellTrajectoryGraph = PlotAixs(myWell.WellTrajectoryGraph, "y", "z", spaceForAxis);
            Output.PrintFileAsTxt(filePath, myWell.WellTrajectoryGraph);
            break;

        //xy
        case "VerticleView":
            adjustedWellPointX         = ResizePointToFitPlot(myWell.WellPointX, rangeX, minX, maxX);
            adjustedWellPointY         = ResizePointToFitPlot(myWell.WellPointY, rangeY, minY, maxY);
            myWell.WellTrajectoryGraph = PlotWellTrajectory(adjustedWellPointX, adjustedWellPointY, myWell.WellPointX, myWell.WellPointY, myWell.WellPointZ, rangeX, rangeY);
            //myWell.WellTrajectoryGraph = PlotAixs(myWell.WellTrajectoryGraph, "x", "z", spaceForAxis);
            Output.PrintFileAsTxt(filePath, myWell.WellTrajectoryGraph);
            break;
        }
    }
Exemple #6
0
        public double[] Calc(DateTime _optimizationDate)
        {
            optimizationDate = _optimizationDate;
            double maxKGF  = graph.wells.Where(s => s.Gg != 0).Max(m => m.Gl / m.Gg),
                   min1KGF = graph.wells.Where(s => s.Gg != 0).Min(m => m.Gl / m.Gg),
                   min2KGF = graph.wells.Where(z => (z.Gg != 0) && (z.Gl / z.Gg != min1KGF)).Min(m => m.Gl / m.Gg);

            maxKGFWell  = graph.wells.First(z => z.Gl / z.Gg == maxKGF);
            min1KGFWell = graph.wells.First(z => z.Gl / z.Gg == min1KGF);
            min2KGFWell = graph.wells.First(z => z.Gl / z.Gg == min2KGF);

            maxKGFWell.d_sht  = maxKGFWell.Shtutzer.d_sht_current;
            min1KGFWell.d_sht = min1KGFWell.Shtutzer.d_sht_current;
            min2KGFWell.d_sht = min2KGFWell.Shtutzer.d_sht_current;

            double eps = 0.001;

            //maxKGFWell.Name = "99999999";
            //Подставить начальные значения dшт
            //foreach (var well in graph.wells)
            //{
            //	well.d_sht = 0.06;
            //	well.Gl = 400;
            //	well.Gg = 1300;
            //}
            //Вычислить по модели штуцера и сети
            //Определить скважину с max КГФ и две с min КГФ

            //Перейти к новому решению для этих скважин
            evaluator.CalcGraph(optimizationDate);
            Psb = graph.endNode.P;
            Gsb = graph.endNode.G;
            double          alpha = 1, beta = 0.5, gamma = 2;
            List <double[]> x = new List <double[]>();

            double[] f = new double[n + 1];

            //начальные значения x
            x.Add(new [] { d_shts[0], d_shts[1], d_shts[2] });
            x.Add(new [] { d_shts[0], d_shts[0], d_shts[2] });
            x.Add(new [] { d_shts[2], d_shts[3], d_shts[4] });
            x.Add(new[] { d_shts[2], d_shts[3], d_shts[1] });

            int xh_ind;                  //индекс наибольшего f
            int xg_ind;                  //индекс второго максимума
            int xl_ind;                  //индекс наименьшего f

            double[] xr;                 //отраженная точка
            double[] xe;                 //точка после растяжения
            double[] xc = new double[n]; //точка после сжатия

            double[] x0 = new double[n]; //центр тяжести

            do
            {
                //Вычисляем F в точках х
                for (int i = 0; i < f.Length; i++)
                {
                    f[i] = F(x[i]);
                }

                x0 = new double[n];

                xh_ind = Array.IndexOf(f, f.Max());
                xg_ind = Array.IndexOf(f, f.Where(y => y != f[xh_ind]).Max());
                xl_ind = Array.IndexOf(f, f.Min());

                for (int i = 0; i < n + 1; i++)
                {
                    if (i != xh_ind)
                    {
                        for (int j = 0; j < x0.Length; j++)
                        {
                            x0[j] += x[i][j] / n;
                        }
                    }
                }
                double Fx0 = F(x0);

                double[] x0_ = x0.Select(y => y * (1 + alpha)).ToArray();
                double[] xh_ = x[xh_ind].Select(y => y * alpha).ToArray();
                xr = x0_.Select((y, i) => y - xh_[i]).ToArray();

                if (F(xr) < F(x[xl_ind]))
                {
                    double[] xr_ = xr.Select(y => y * gamma).ToArray();
                    x0_ = x0.Select(y => y * (1 - gamma)).ToArray();
                    xe  = xr_.Select((y, i) => y + x0_[i]).ToArray();
                    if (F(xe) < F(x[xl_ind]))
                    {
                        x[xh_ind] = xe;
                        f[xh_ind] = F(xe);
                        if (Сonvergence(eps, f))
                        {
                            return(x[xl_ind]);
                        }
                        continue;
                    }
                    else
                    {
                        x[xh_ind] = xr;
                        f[xh_ind] = F(xr);
                        if (Сonvergence(eps, f))
                        {
                            return(x[xl_ind]);
                        }
                        continue;
                    }
                }
                else
                {
                    if (F(xr) < f[xg_ind])
                    {
                        x[xh_ind] = xr;
                        f[xh_ind] = F(xr);
                        if (Сonvergence(eps, f))
                        {
                            return(x[xl_ind]);
                        }
                        continue;
                    }
                    else
                    {
                        //шаг Е
                        if (F(xr) > f[xh_ind])
                        {
                        }
                        else
                        {
                            x[xh_ind] = xr;
                            f[xh_ind] = F(xr);
                        }
                        double[] xh_beta = x[xh_ind].Select(y => y * beta).ToArray();
                        double[] x0_beta = x0.Select(y => y * (1 - beta)).ToArray();
                        xc = xh_beta.Select((y, i) => y + x0_beta[i]).ToArray();
                    }
                }
                if (F(xc) < f[xh_ind])
                {
                    x[xh_ind] = xc;
                    f[xh_ind] = F(xc);
                    if (Сonvergence(eps, f))
                    {
                        return(x[xl_ind]);
                    }
                }
                else
                {
                    //уменьшаем размер симплекса Ж3
                    for (int i = 0; i < n + 1; i++)
                    {
                        x[i] = x[i].Select((m, j) => (m - x[xl_ind][j]) / 2).ToArray();
                        f[i] = F(x[i]);
                    }
                    if (Сonvergence(eps, f))
                    {
                        return(x[xl_ind]);
                    }
                }
            }while (!Сonvergence(eps, f));

            return(x[xh_ind]);
        }