Exemple #1
0
        public void GetIndexTest()
        {
            Model mshe = new Model(@"..\..\..\TestData\TestModelDemo.she");

            int Column;
            int Row;

            Assert.IsTrue(mshe.GridInfo.TryGetIndex(11, 11, out Column, out Row));
            Assert.AreEqual(1, Column);
            Assert.AreEqual(1, Row);

            Assert.IsTrue(mshe.GridInfo.TryGetIndex(19, 19, out Column, out Row));
            Assert.AreEqual(1, Column);
            Assert.AreEqual(1, Row);

            mshe.Dispose();

            DFS3 heads = new DFS3(@"..\..\..\TestData\TestModelDemo.she - Result Files\TestModelDemo_3DSZ.dfs3");

            Assert.AreEqual(1, heads.GetColumnIndex(11));

            Assert.AreEqual(2, heads.GetColumnIndex(19));

            heads.Dispose();
        }
Exemple #2
0
 public void Dispose()
 {
     if (SZ3D != null)
     {
         SZ3D.Dispose();
     }
 }
Exemple #3
0
 /// <summary>
 /// Disposes the underlying dfs files
 /// </summary>
 public void Dispose()
 {
     if (_prePro2D != null)
     {
         _prePro2D.Dispose();
     }
     if (_PreProcessed_3DSZ != null)
     {
         _PreProcessed_3DSZ.Dispose();
     }
 }
Exemple #4
0
 /// <summary>
 /// Disposes the underlying dfs-files if the object has been constructed directly from files
 /// </summary>
 public void Dispose()
 {
     //If the object has been constructed from files it is the owner of the dfs objects and
     //has to dispose them
     if (_preproDFS2 != null)
     {
         _preproDFS2.Dispose();
     }
     if (_preproDFS3 != null)
     {
         _preproDFS3.Dispose();
     }
 }
        /// <summary>
        /// Sums layers from a DFS3 into a DFS2
        /// </summary>
        /// <param name="OperationData"></param>
        public static void LayerSummation(XElement OperationData)
        {
            string Dfs3File   = OperationData.Element("DFS3FileName").Value;
            string DFS2OutPut = OperationData.Element("DFS2OutputFileName").Value;

            DFS3.MaxEntriesInBuffer = 1;
            DFS2.MaxEntriesInBuffer = 1;

            DFS3 input = new DFS3(Dfs3File);

            var Items  = ParseString(OperationData.Element("Items").Value, 1, input.Items.Count());
            var Layers = ParseString(OperationData.Element("Layers").Value, 0, input.NumberOfLayers - 1);

            DenseMatrix Sumdata = new DenseMatrix(input.NumberOfRows, input.NumberOfColumns);

            //Create the output file and copy info from input file
            DFS2 output = new DFS2(DFS2OutPut, Items.Count());

            output.CopyFromTemplate(input);
            int l = 0;

            //Create the items
            foreach (int j in Items)
            {
                int i = j - 1;
                output.Items[l].EumItem = input.Items[i].EumItem;
                output.Items[l].EumUnit = input.Items[i].EumUnit;
                output.Items[l].Name    = input.Items[i].Name;
                l++;
            }

            for (int i = 0; i < input.NumberOfTimeSteps; i++)
            {
                foreach (int j in Items)
                {
                    IMatrix3d data = input.GetData(i, j);

                    Sumdata = data[Layers[0]];

                    for (int k = 1; k < Layers.Count(); k++)
                    {
                        Sumdata = Sumdata + data[Layers[k]];
                    }
                    RecreateDeleteValues(data[Layers[0]], Sumdata, input.DeleteValue);

                    output.SetData(i, j, Sumdata);
                }
            }
            input.Dispose();
            output.Dispose();
        }
Exemple #6
0
        public void TestMethod1()
        {
            DFS3 df = new DFS3(@"C:\Users\Jacob\Documents\MIKE Zero Projects\SHEPar1.she - Result Files\SHEPar1_3DSZflow.dfs3");

            for (int i = 0; i < 30; i++)
            {
                var mat = df.GetData(i, 1);
                mat[0][1, 1] = -0.5;
                mat[1][1, 1] = -0.5;

                df.SetData(i, 1, mat);
            }
            df.Dispose();
        }
        void v_SimulationFinished(object sender, EventArgs e)
        {
            Model mshe = sender as Model;
            var   dfs  = DfsFileFactory.OpenFile(mshe.Files.SZ3DFileName);

            double[] percentiles = new double[] { 0.1 };
            string   filename    = Path.Combine(mshe.Files.ResultsDirectory, "SZ3D_percentiles.dfs3");
            var      dfsout      = DfsFileFactory.CreateFile(filename, percentiles.Count());

            dfsout.CopyFromTemplate(dfs);
            dfs.Percentile(1, dfsout, percentiles, 80000000);
            dfsout.Dispose();
            DFS3 dfsout2 = new DFS3(filename);

            Console.WriteLine(dfsout2.GetData(0, 1)[10, 10, 0]);
            dfsout2.Dispose();

            RunNext(mshe);
        }
Exemple #8
0
        public void CreateFile()
        {
            DFS3 df = new DFS3("test.dfs3", 1);

            df.NumberOfColumns     = 5;
            df.NumberOfRows        = 7;
            df.NumberOfLayers      = 3;
            df.XOrigin             = 9000;
            df.YOrigin             = 6000;
            df.Orientation         = 1;
            df.GridSize            = 15;
            df.TimeOfFirstTimestep = DateTime.Now;
            df.TimeStep            = TimeSpan.FromHours(2);

            df.FirstItem.Name    = "SGS Kriged dyn. corr.precip";
            df.FirstItem.EumItem = eumItem.eumIPrecipitationRate;
            df.FirstItem.EumUnit = eumUnit.eumUmillimeterPerDay;


            Matrix3d m3 = new Matrix3d(df.NumberOfRows, df.NumberOfColumns, df.NumberOfLayers);

            m3[0] = new DenseMatrix(df.NumberOfRows, df.NumberOfColumns);
            m3[1] = new DenseMatrix(df.NumberOfRows, df.NumberOfColumns, 3);
            m3[2] = new DenseMatrix(df.NumberOfRows, df.NumberOfColumns, 2);

            m3[3, 4, 0] = 25;


            df.SetData(0, 1, m3);
            m3[3, 4, 0] = 24;
            m3[3, 4, 1] = 100;
            m3[3, 4, 2] = 110;
            df.SetData(1, 1, m3);
            df.Dispose();

            df = new DFS3("test.dfs3");

            Assert.AreEqual(eumItem.eumIPrecipitationRate, df.FirstItem.EumItem);

            Matrix m2 = df.GetData(0, 1)[0];

            Assert.AreEqual(25, m2[3, 4]);
        }
Exemple #9
0
        public void TimeMaxTest()
        {
            new XElement("GridOperations");

            XElement Op = new XElement("GridOperation", new XAttribute("Type", "TimeMax"),
                                       new XElement("DFSFileName", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_3DSZflow.dfs3"),
                                       new XElement("Items", ""),
                                       new XElement("TimeInterval", "Year"),
                                       new XElement("DFSOutputFileName", @"..\..\..\TestData\TestModel.she - Result Files\YearlyMax.dfs3")
                                       );

            GridFunctions.TimeMax(Op);

            DFS3 dfs = new DFS3(@"..\..\..\TestData\TestModel.she - Result Files\YearlyMax.dfs3");

            Assert.AreEqual(1, dfs.NumberOfTimeSteps);
            Assert.AreEqual(2.000215e-005, dfs.GetData(0, 1)[19, 14, 0], 1e-7);
            Assert.AreEqual(2.527396e-007, dfs.GetData(0, 4)[21, 17, 0], 1e-9);
            dfs.Dispose();
        }
Exemple #10
0
        public void TimeMinTest()
        {
            new XElement("GridOperations");

            XElement Op = new XElement("GridOperation", new XAttribute("Type", "TimeMin"),
                                       new XElement("DFSFileName", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_3DSZflow.dfs3"),
                                       new XElement("Items", ""),
                                       new XElement("TimeInterval", "Year"),
                                       new XElement("DFSOutputFileName", @"..\..\..\TestData\TestModel.she - Result Files\YearlyMin.dfs3")
                                       );

            GridFunctions.TimeMin(Op);

            DFS3 dfs = new DFS3(@"..\..\..\TestData\TestModel.she - Result Files\YearlyMin.dfs3");

            Assert.AreEqual(1, dfs.NumberOfTimeSteps);
            Assert.AreEqual(5, dfs.NumberOfItems);
            Assert.AreEqual(-1.601641e-007, dfs.GetData(0, 1)[24, 7, 0], 1e-10);
            Assert.AreEqual(-100.7973, dfs.GetData(0, 3)[18, 11, 0], 1e-2);
            dfs.Dispose();
        }
Exemple #11
0
        public void TimeSummationTest()
        {
            new XElement("GridOperations");

            XElement Op = new XElement("GridOperation", new XAttribute("Type", "TimeSummation"),
                                       new XElement("DFSFileName", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_3DSZflow.dfs3"),
                                       new XElement("Items", ""),
                                       new XElement("TimeInterval", "Year"),
                                       new XElement("DFSOutputFileName", @"..\..\..\TestData\TestModel.she - Result Files\YearlySum.dfs3")
                                       );

            GridFunctions.TimeSummation(Op);

            DFS3 dfs = new DFS3(@"..\..\..\TestData\TestModel.she - Result Files\YearlySum.dfs3");

            Assert.AreEqual(1, dfs.NumberOfTimeSteps);
            Assert.AreEqual(5, dfs.NumberOfItems);
            Assert.AreEqual(-6.925168e-007, dfs.GetData(0, 1)[25, 6, 0], 1e-10);
            Assert.AreEqual(-3.86626e-005, dfs.GetData(0, 4)[21, 16, 0], 1e-8);
            dfs.Dispose();
        }
Exemple #12
0
 public void Destruct()
 {
     _dfs.Dispose();
     _dfsWrite.Dispose();
 }
        private void MakePlots()
        {
            if (!PlotsMade) //Only do this once
            {
                Model mShe = new Model(SheFileName);
                DFS3  dfs  = new DFS3(Dfs3FileName);
                Item  dfsI = dfs.Items[ItemNumber - 1];

                List <TimestampSeries> well_Concentration = new List <TimestampSeries>();

                int[] TimeSteps   = ParseString(TimeStepsAsString, 0, dfs.NumberOfTimeSteps - 1);
                int[] WellNumbers = ParseString(WellsAsString, 0, mShe.ExtractionWells.Count - 1);

                List <MikeSheWell> wells = new List <MikeSheWell>();
                foreach (int j in WellNumbers)
                {
                    wells.Add(mShe.ExtractionWells[j]);
                }

                foreach (int i in TimeSteps)
                {
                    int k = 0;
                    foreach (var w in wells)
                    {
                        if (i == TimeSteps[0])
                        {
                            well_Concentration.Add(new TimestampSeries(w.ID, new Unit(dfsI.EumQuantity.UnitAbbreviation, 1, 0)));
                        }
                        well_Concentration[k].Items.Add(new TimestampValue(dfs.TimeSteps[i], (dfs.GetData(i, ItemNumber)[w.Row, w.Column, w.Layer])));
                        k++;
                    }
                }

                //Sets the upper title
                Header.Content = dfsI.Name;

                //Sets the title of the y-axis
                var ytitle = new VerticalAxisTitle();
                ytitle.Content = dfsI.EumQuantity.ItemDescription + " [" + dfsI.EumQuantity.UnitAbbreviation + "]";
                TheChart.Children.Add(ytitle);

                int l = 0;
                //Loop the wells for plotting
                foreach (var w in wells)
                {
                    if (g != null)
                    {
                        TheChart.Children.Remove(g);
                        TheChart.FitToView();
                    }

                    var axis = new Microsoft.Research.DynamicDataDisplay.Charts.HorizontalDateTimeAxis();
                    TheChart.MainHorizontalAxis = axis;
                    TheChart.MainVerticalAxis   = new Microsoft.Research.DynamicDataDisplay.Charts.VerticalAxis();
                    //set the data source
                    EnumerableDataSource <TimestampValue> ds = new EnumerableDataSource <TimestampValue>(well_Concentration[l].Items);
                    ds.SetXMapping(var => axis.ConvertToDouble(var.Time));
                    ds.SetYMapping(var => var.Value);
                    //create the graph
                    g = TheChart.AddLineGraph(ds, new Pen(Brushes.Black, 3), new PenDescription(w.ID));
                    //create a filename
                    outfile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Dfs3FileName), "Well_No" + "_" + WellNumbers[l].ToString() + "_" + dfsI.EumQuantity.ItemDescription);
                    //now save to file
                    this.UpdateLayout();

                    MainWindow.SaveScreen(this, outfile + ".jpg", (int)ActualWidth, (int)ActualHeight);


                    //Now create the dfs0-file
                    using (DFS0 dfs0 = new DFS0(outfile + ".dfs0", 1))
                    {
                        dfs0.FirstItem.Name      = dfsI.Name;
                        dfs0.FirstItem.EumItem   = dfsI.EumItem;
                        dfs0.FirstItem.EumUnit   = dfsI.EumUnit;
                        dfs0.FirstItem.ValueType = dfsI.ValueType;

                        int t = 0;
                        foreach (var v in well_Concentration[l].Items)
                        {
                            dfs0.InsertTimeStep(v.Time);
                            dfs0.SetData(t, 1, v.Value);
                            t++;
                        }
                    }

                    //Now create the text-file
                    using (StreamWriter sw = new StreamWriter(outfile + ".txt", false))
                    {
                        foreach (var v in well_Concentration[l].Items)
                        {
                            sw.WriteLine(v.Time + "; " + v.Value);
                        }
                    }
                    l++;
                }
                mShe.Dispose();
                dfs.Dispose();
                PlotsMade = true;
            }
        }