コード例 #1
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            eumQuantity eq = Items.SelectedValue as eumQuantity;

            if (eq != null)
            {
                eq.Unit = (eumUnit)Enum.Parse(typeof(eumUnit), Units.SelectedItem.ToString());
            }


            foreach (var f in FileNames)
            {
                DFSBase dfs = HydroNumerics.MikeSheTools.DFS.DfsFileFactory.OpenFile(f);
                foreach (var i in dfs.Items)
                {
                    if (eq != null)
                    {
                        i.EumItem = eq.Item;
                        i.EumUnit = eq.Unit;
                    }
                    if (Type.SelectedItem != null)
                    {
                        i.ValueType = (DataValueType)Enum.Parse(typeof(DataValueType), Type.SelectedItem.ToString());
                    }
                }
                dfs.Dispose();
            }

            this.Close();
        }
コード例 #2
0
ファイル: ExamplesDfsu.cs プロジェクト: DHI/MIKECore-Examples
        /// <summary>
        /// Introductory example of how to load a dfsu file.
        /// <para>
        /// The method assumes that the OresundHD.dfsu test file
        /// is the input file.
        /// </para>
        /// </summary>
        /// <param name="filename">path and name of OresundHD.dfsu test file</param>
        public static void ReadingDfsuFile(string filename)
        {
            IDfsuFile file = DfsuFile.Open(filename);

            // Read geometry
            int    numberOfElements     = file.NumberOfElements; // 3636
            int    numberOfNodes        = file.NumberOfNodes;    // 2057
            double firstNodeXCoordinate = file.X[0];             // 359978.8

            int[] firstElementNodes = file.ElementTable[0];      // [1, 2, 3]

            // Read dynamic item info
            string      firstItemName = file.ItemInfo[0].Name;     // "Surface elevation"
            eumQuantity quantity      = file.ItemInfo[0].Quantity; // eumISurfaceElevation in eumUmeter

            // load data for the first item, 6th timestep
            float[] itemTimeStepData = (float[])file.ReadItemTimeStep(1, 5).Data;
            // Read the value of the third element
            float thirdElementValue = itemTimeStepData[2]; // 0.0014070312

            file.Close();
        }
コード例 #3
0
        /// <summary>
        /// Process the incoming mesh file names
        /// </summary>
        /// <param name="files">List of mesh file names to merge</param>
        /// <param name="fileBoundaryCodesToRemove">List of boundary codes to remove for each mesh. Must match the size of the files argument</param>
        public void Process(List <string> files, List <List <int> > fileBoundaryCodesToRemove = null)
        {
            // Extent of entire domain, all meshes
            Extent extent = new Extent();

            // Load all meshes
            List <MeshFile> meshes = new List <MeshFile>(files.Count);

            for (int i = 0; i < files.Count; i++)
            {
                MeshFile mesh = MeshFile.ReadMesh(files[i]);
                meshes.Add(mesh);
                for (int j = 0; j < mesh.NumberOfNodes; j++)
                {
                    extent.Include(mesh.X[j], mesh.Y[j]);
                }
            }
            // grow it a littl bit, in case of rounding errors
            extent.XMin = extent.XMin - NodeTolerance;
            extent.XMax = extent.XMax + NodeTolerance;
            extent.YMin = extent.YMin - NodeTolerance;
            extent.YMax = extent.YMax + NodeTolerance;

            // Initialize search tree
            _nodeSearchTree = new QuadSearchTree(extent);

            // Create new mesh nodes and elements
            for (int i = 0; i < files.Count; i++)
            {
                int        prevNodeMergeCount    = NodeMergeCount;
                List <int> boundaryCodesToRemove = fileBoundaryCodesToRemove != null ? fileBoundaryCodesToRemove[i] : null;
                AddMesh(meshes[i], boundaryCodesToRemove);
                if (i > 0)
                {
                    Console.Out.WriteLine("Mesh {0}, number of nodes merged in: {1}", i + 1, NodeMergeCount - prevNodeMergeCount);
                }
            }
            Console.Out.WriteLine("Total number of nodes merged in  : {0}", NodeMergeCount);

            RemoveInternalBoundaryCodes(_code, _connectivity);

            // Create new mesh file
            string      projection  = meshes[0].ProjectionString;
            eumQuantity eumQuantity = meshes[0].EumQuantity;

            MeshBuilder builder = new MeshBuilder();

            builder.SetNodes(_x.ToArray(), _y.ToArray(), _z.ToArray(), _code.ToArray());
            builder.SetElements(_connectivity.ToArray());
            builder.SetProjection(projection);
            builder.SetEumQuantity(eumQuantity);

            MeshFile newMesh = builder.CreateMesh();

            MeshValidator meshValidator = new MeshValidator();

            meshValidator.ValidateMesh(newMesh.X, newMesh.Y, newMesh.Code, newMesh.ElementTable);

            foreach (string error in meshValidator.Errors)
            {
                Console.Out.WriteLine(error);
            }

            newMesh.Write(_newMeshFileName);

            //-------------------------------------
            // Do some statistics on the mesh:

            // collect number of face codes for each mesh
            SortedDictionary <int, int[]> bcCodesStats = new SortedDictionary <int, int[]>();
            List <MeshValidator>          validators   = new List <MeshValidator>();

            for (int meshIndex = 0; meshIndex < meshes.Count; meshIndex++)
            {
                MeshFile      meshFile  = meshes[meshIndex];
                MeshValidator validator = new MeshValidator();
                validator.ValidateMesh(meshFile.X, meshFile.Y, meshFile.Code, meshFile.ElementTable);
                validators.Add(validator);
                UpdateStatistics(meshes.Count + 1, meshIndex, bcCodesStats, validator.GetFaceCodeStatistics());
            }
            UpdateStatistics(meshes.Count + 1, meshes.Count, bcCodesStats, meshValidator.GetFaceCodeStatistics());

            Console.Out.Write("---------------------");
            Console.Out.Write(" Statistics of faces ");
            Console.Out.Write("---------------------");
            Console.Out.WriteLine("");
            Console.Out.Write("FaceCode  |");
            for (int i = 0; i < meshes.Count; i++)
            {
                Console.Out.Write(" mesh {0,2}  ", i + 1);
            }
            Console.Out.Write(" |  total | new mesh");
            Console.Out.WriteLine("");

            int[] totals = new int[meshes.Count + 2];
            foreach (KeyValuePair <int, int[]> keyValuePair in bcCodesStats)
            {
                Console.Out.Write("    {0,4}  |", keyValuePair.Key);
                int total = 0;
                for (int index = 0; index < keyValuePair.Value.Length - 1; index++)
                {
                    int meshCodeCount = keyValuePair.Value[index];
                    total         += meshCodeCount;
                    totals[index] += meshCodeCount;
                    Console.Out.Write(" {0,7}  ", meshCodeCount);
                }
                totals[meshes.Count]     += total;
                totals[meshes.Count + 1] += keyValuePair.Value.Last();
                Console.Out.Write(" |{0,7} | ", total);
                Console.Out.Write(" {0,7}  ", keyValuePair.Value.Last());
                Console.Out.WriteLine("");
            }
            Console.Out.Write("   total  |");
            for (int index = 0; index < meshes.Count; index++)
            {
                Console.Out.Write(" {0,7}  ", totals[index]);
            }
            Console.Out.Write(" |{0,7} | ", totals[meshes.Count]);
            Console.Out.Write(" {0,7}  ", totals[meshes.Count + 1]);
            Console.Out.WriteLine("");
            Console.Out.Write("---------------------");
            Console.Out.Write("---------------------");
            Console.Out.Write("---------------------");
            Console.Out.WriteLine("");
        }
コード例 #4
0
        /// <summary> Write dfs2 file </summary>
        private void Write(string dfsFilename, string projectionString)
        {
            DfsFactory  factory = new DfsFactory();
            Dfs2Builder builder = new Dfs2Builder();

            // Data type
            builder.SetDataType(0);

            // Projection and spatial axis
            double lon0; double lat0; double dx; double dy;
            int    flip;

            FindAxisProperties(out lon0, out lat0, out dx, out dy, out flip);
            builder.SetGeographicalProjection(factory.CreateProjectionGeoOrigin(projectionString, lon0, lat0, 0));
            builder.SetSpatialAxis(factory.CreateAxisEqD2(eumUnit.eumUdegree, _dimensions[0], 0, dx, _dimensions[1], 0, dy));

            // Time axis
            eumUnit  timeUnit;
            DateTime startDateTime;
            double   timeStep;

            FindTimeProperties(out timeUnit, out startDateTime, out timeStep);
            builder.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(timeUnit, startDateTime, 0, timeStep));

            // Add dynamic items
            foreach (Variable item in _items)
            {
                eumQuantity quantity = GetQuantityFromItem(item);
                builder.AddDynamicItem(item.Name, quantity, DfsSimpleType.Float, DataValueType.Instantaneous);
            }

            // Create and get file (no static items there)
            builder.CreateFile(dfsFilename);
            Dfs2File dfs2File = builder.GetFile();

            // Write data to file
            int itemSize = _dimensions[0] * _dimensions[1];

            float[] values        = new float[itemSize];
            float[] valuesFlipped = new float[itemSize];
            for (int i = 0; i < _time.Array.Length; i++)
            {
                for (int j = 0; j < _items.Count; j++)
                {
                    // Time of time step
                    double time = (double)_time.Array.GetValue(i);
                    // Values for all time steps
                    float[] allfloats = (float[])_items[j].Array;
                    // Copy single time step data from allFloats to values
                    Array.Copy(allfloats, i * itemSize, values, 0, itemSize);
                    // Flip values, if necessary
                    float[] actual;
                    if (flip == 0)
                    {
                        actual = values;
                    }
                    else
                    {
                        PerformFlip(flip, values, valuesFlipped);
                        actual = valuesFlipped;
                    }
                    // Save values to file
                    dfs2File.WriteItemTimeStepNext(time, actual);
                }
            }
            dfs2File.Close();
        }