Beispiel #1
0
        public void WriteMesh(string filename, GMSH_VERSION version = GMSH_VERSION.MSH_1)
        {
            List <string> lines = new List <string>();

            switch (version)
            {
            case GMSH_VERSION.MSH_1:
            {
                lines.Add("$NOD");
                lines.Add(_nodes.Count.ToString());
                _nodes.ForEach(n => lines.Add(n.ToString()));
                lines.Add("$ENDNOD");
                lines.Add("$ELM");
                lines.Add(_elements.Count.ToString());
                _elements.ForEach(e => lines.Add(e.ToString(version)));
                lines.Add("$ENDELM");
                lines.Add("");
                if (_nodeData != null)
                {
                    Console.WriteLine("GMSH version 1 does not support data in the msh file. Skipping node data.");
                }
            }
            break;

            case GMSH_VERSION.MSH_2_2:
            {
                lines.Add("$MeshFormat");
                lines.Add("2.2 0 8");
                lines.Add("$EndMeshFormat");
                lines.Add("$Nodes");
                lines.Add(_nodes.Count.ToString());
                _nodes.ForEach(n => lines.Add(n.ToString()));
                lines.Add("$EndNodes");
                lines.Add("$Elements");
                lines.Add(_elements.Count.ToString());
                _elements.ForEach(e => lines.Add(e.ToString(version)));
                lines.Add("$EndElements");
                if (_nodeData != null)
                {
                    lines.Add("$NodeData");
                    _nodeData.ForEach(nd => { if (nd.Sane)
                                              {
                                                  lines.AddRange(nd.GetStrings());
                                              }
                                      });
                    lines.Add("$EndNodeData");
                }
                lines.Add("");
            }
            break;

            default:
            {
                throw new Exception(String.Format("Unknown Mesh format {0}.", version.ToString()));
            }
            }

            File.WriteAllLines(filename, lines);
        }
Beispiel #2
0
        /// <summary>
        /// Write out the Element data in gmsh 2.15 format.
        /// </summary>
        /// <returns>The Element data in gmsh 2.15 format</returns>
        public string ToString(GMSH_VERSION version = GMSH_VERSION.MSH_1)
        {
            switch (version)
            {
            case GMSH_VERSION.MSH_1:
            {
                string s = ID.ToString(Format) + " " + ElementCode.ToString(Format);
                s += " " + PhysicalTag.ToString(Format);
                s += " " + ElementaryTag.ToString(Format);
                s += " " + NumberOfNodes.ToString(Format);
                for (int i = 0; i < NumberOfNodes; ++i)
                {
                    s += " " + _nodes[i].ToString(Format);
                }

                return(s);
            }

            case GMSH_VERSION.MSH_2_2:
            {
                string s = ID.ToString(Format) + " " + ElementCode.ToString(Format) + " " + "2";
                s += " " + PhysicalTag.ToString(Format);
                s += " " + ElementaryTag.ToString(Format);
                for (int i = 0; i < NumberOfNodes; ++i)
                {
                    s += " " + _nodes[i].ToString(Format);
                }

                return(s);
            }

            default:
            {
                throw new Exception(String.Format("Unknown Mesh format {0}.", version.ToString()));
            }
            }
        }