Exemple #1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="inpReader"></param>
        /// <param name="message">用于输出的消息说明</param>
        public Hm2Zone(StreamReader inpReader, StringBuilder message)
            : base(inpReader, message)
        {
            //
            Flac3dCommandWriters fcw    = Flac3dCommandWriters.GetUniqueInstance();
            Flac3DCommandType    fct    = Hm2Flac3DHandler.GetCommandType(ElementType.GridPoint);
            StreamWriter         swZone = fcw.GetWriter(fct, Flac3dCommandWriters.FileZone, null);

            //
            sw_Zone  = swZone;
            _message = message;

            //写入头文件信息
            // 用im zone.dat来在Flac3d中导入网格时,在zone.dat中可以先写入文件头信息,而structures.dat文件中,不能用“*”来写注释
            string strHeading =
                "* --------------------------------------------------" + "\r\n" +
                "*  INP (exported from Hypermesh) to FLAC3D " + "\r\n" +
                "*  Coded by Zengfy. Contact the developer with [email protected]." + "\r\n" +
                "*  Latest update date: 2016/11/25 " + "\r\n" +
                "* --------------------------------------------------" + "\r\n" +
                "* Generated time: " + DateTime.Today.ToString("yyyy/MM/dd") + "   " +
                DateTime.Now.ToShortTimeString() + "\r\n" + "\r\n" + "* GRIDPOINTS";

            sw_Zone.WriteLine(strHeading);
        }
Exemple #2
0
        /// <summary>
        /// 读取数据,并返回跳出循环的字符串
        /// </summary>
        /// <param name="sr_inp"></param>
        /// <param name="stringline"> 当前要读取 inp 文件中的那一行数据 </param>
        /// <remarks>在读取数据时,每一个生成单元的函数中,都会返回最后跳出循环的那个字符串,如果某行字符串没有进行任何的数据提取,或者进行单元类型的判断,则继续读取下一行字符。</remarks>
        protected override string ReadElements(StreamReader sr_inp, string stringline)
        {
            string pattern_ElementType = @"\*ELEMENT,TYPE=(.+),ELSET=(.+)"; //大致结构为: *ELEMENT,TYPE=B31,ELSET=columns-c1

            var   strLine = stringline;
            Match match   = default(Match);

            do
            {
                //在Hypermesh导出的inp文件中,可以有很多个 *ELEMENT,TYPE=B31,ELSET=columns 这样的语句,它们是按hypermesh中的Component来进行分组的。
                match = Regex.Match(strLine, pattern_ElementType);
                if (match.Success)
                {
                    //
                    string strEleType = match.Groups[1].Value;

                    string strComponentName = match.Groups[2].Value; // 当前读取到Inp中的那一个 Component(即 Hypermesh 中的 Component)

                    ElementType tp = Hm2Flac3DHandler.GetElementType(strEleType, strComponentName);

                    // 创建 Flac3D 单元
                    strLine = GenerateElement(tp, sr_inp, strComponentName);
                }
                else
                {
                    //如果某行字符串没有进行任何的数据提取,或者进行单元类型的判断,则继续读取下一行字符。
                    strLine = sr_inp.ReadLine();
                }
            } while (strLine != null);
            return(strLine);
        }
Exemple #3
0
        /// <summary>
        /// 创建节点
        /// </summary>
        /// <param name="sr">用来提取数据的inp文件</param>
        /// <returns></returns>
        protected override string Gen_Node(StreamReader sr)
        {
            string strLine = "";
            //
            Flac3dCommandWriters fcw    = Flac3dCommandWriters.GetUniqueInstance();
            Flac3DCommandType    fct    = Hm2Flac3DHandler.GetCommandType(ElementType.SelNode);
            StreamWriter         swNode = fcw.GetWriter(fct, Flac3dCommandWriters.FileSelNode, null);

            //
            strLine = sr.ReadLine(); // 节点信息在inp中的大致的结构为: "   16,  10.0     ,  6.6666666666667,  0.0     "
            while (!(strLine.StartsWith("*")))
            {
                // 写入flac文件
                swNode.WriteLine("SEL NODE cid  {0}", strLine);
                // 大致的结构为: ' SEL NODE cid  1440016  0.216969418565193E+02 -0.531659539393860E+02 -0.161000000000000E+02

                //保存节点信息,以供后面创建Liner之用
                string[] comps = strLine.Split(',');

                _allNodes.Add(int.Parse(comps[0]), new XYZ(
                                  double.Parse(comps[1]),
                                  double.Parse(comps[2]),
                                  double.Parse(comps[3])));


                // 读取下一个节点
                strLine = sr.ReadLine(); // 大致的结构为: "        16,  10.0           ,  6.6666666666667,  0.0            "
            }
            return(strLine);
        }
Exemple #4
0
        public void ButtonNoLiner_Click(object sender, EventArgs e)
        {
            Hide();

            Hm2Flac3DHandler.AllocConsole();

            Hm2Flac3D_V1.Main();
            // 一般情况下,当控制台被手动点击关闭(而不是通过 FreeConsole 来释放控制台)后,整个程序的进程就结束了,这里为了保险起见,再强制关闭一下。
            Close();
        }
Exemple #5
0
        /// <summary>
        /// 在某Zone的四边形 Face 表面创建分割此四边形的两个三角形 Liner 单元,
        /// 其在Flac3d中的导入格式为:sel liner id 1 em group ex1 range x 23.73 23.78 y -0.01 0.01 z 19.65 19.67
        /// </summary>
        /// <param name="sr"></param>
        /// <param name="sw"> S4类型的单元在inp文件中的格式为: 102038,    107275,    105703,    105704,    104375  </param>
        /// <param name="componentName"> 当前读取到Inp中的那一个 Component(即 Hypermesh 中的 Component) </param>
        /// <param name="groupName"> 要依托于哪一个group来生成liner单元 </param>
        /// <param name="selId"> 结构单元所属集合的Id </param>
        /// <returns>在这一区块中,最后一次读取的字符,即跳出循环的字符,比如:**HWCOLOR COMP 57   60 或者 **HMASSEM  2   6 A_M</returns>
        /// <remarks>创建方法为先找到此四边形的形心,然后将形心点向扩展1mm, 以形成一个体积为1立方毫米的立方体,然后用此立方体来作为创建 Liner 的 range。</remarks>
        private string Gen_Liner4(StreamReader sr, StreamWriter sw, string componentName, string groupName, int selId)
        {
            string pattern = @"^\s*(\d*),\s*(\d*),\s*(\d*),\s*(\d*),\s*(\d*)";
            string strLine = "";
            int    eleId;
            int    node1 = 0;
            int    node2 = 0;
            int    node3 = 0;
            int    node4 = 0;

            //
            strLine = sr.ReadLine(); // S4 类型的信息在inp中,大致的结构为: " 102038,    107275,    105703,    105704,    104375 "
            Match           match  = default(Match);
            GroupCollection groups = default(GroupCollection);

            match = Regex.Match(strLine, pattern);
            while (match.Success)
            {
                groups = match.Groups;
                eleId  = Convert.ToInt32(groups[1].Value);
                // 在 inp 中 S4 单元的id号,但是这个单元并不用来创建Flac中的 liner 单元,而是利用其四个节点来创建liner 单元。
                node1 = Convert.ToInt32(groups[2].Value);
                node2 = Convert.ToInt32(groups[3].Value);
                node3 = Convert.ToInt32(groups[4].Value);
                node4 = Convert.ToInt32(groups[5].Value);

                // 获取此四个节点所形成的共面四边形的形心点
                XYZ centroid = XYZ.FindCentroid(_allNodes[node1], _allNodes[node2], _allNodes[node3],
                                                _allNodes[node4]);

                string range = Hm2Flac3DHandler.ExtendCentroid(centroid);

                // 创建与两面都有与 zone 的接触的 Liner 单元
                // Sel Liner  id 1 em group ex1 range x 23.73 23.78 y -0.01 0.01 z 19.65 19.67
                sw.WriteLine("Sel Liner id {0} em group {1} {2}", selId, groupName, range);

                //下面这一条语句所创建的Liner,它并不会与其周围的Zone之间建立 Node-to-Zone links.
                //而且即使用"SEL NODE INIT XPOS ADD 0.0"来创建Node-Zone link,此单元上也只有一面会与Zone之间有link
                //sw.WriteLine("SEL LINERSEL cid   {0} id   {1}  ele DKT_CST  nodes  {2} {3} {4}", eleId, SelId, node1, node2, node3) ' 大致的结构为:SEL SHELLSEL cid    68341 id    68341 ele DKT_CST  nodes  1 2 3

                //Debug.Print(_allNodes(node1).ToString() & _allNodes(node2).ToString() &
                //            _allNodes(node3).ToString() & _allNodes(node4).ToString() &
                //            centroid.ToString())

                //读取下一个节点
                strLine = sr.ReadLine();
                match   = Regex.Match(strLine, pattern);
            }

            sw.WriteLine("sel group  {0} range id {1}", componentName, selId);
            // 大致的结构为:SEL PILESEL  cid   109200 id   109200 nodes  1770004 1769720
            return(strLine);
        }
Exemple #6
0
        /// <summary> 从NSet(Node Set)中提取出节点编号,并写入一个单独的文本,用来执行Merge操作</summary>
        /// <param name="sr"></param>
        /// <param name="groupName"> group的名称必须以LM开头 </param>
        /// <param name="swGpMerge"> 要写入哪一个文本 </param>
        /// <returns></returns>
        private string Gen_GpMerge(StreamReader sr, StreamWriter swGpMerge, string groupName)
        {
            string pattern = @"^\s*(\d+)";
            // set 集合在inp文件中的格式为: 132,       133,       134,       135,       136,       137,       138,       139,
            // 但是在最后一行时,也有可能不足8个节点编号,所以在正则表达式中,只能判断这一行中是否有至少一个数值编号

            // 每一个节点编号都对应了一条语句,即 generate merge 0.001 Range x= (23.73, 23.78) y =( -0.01, 0.01)  z= ( 19.65, 19.67)
            List <int> listNdId = new List <int>();  // Node Set 中所有的节点编号

            //先写入标志语句
            //
            Match  match;
            string strLine;

            strLine = sr.ReadLine(); // 大致的结构为:  单元id, 节点1 2 3 4 5 6
            match   = Regex.Match(strLine, pattern);
            while (match.Success)
            {
                string[] elementIds = strLine.Split(',');
                // 当此行为“ 132,       133,       134,       135,       136,       137,       138,       139,”时,Split()后数组中有9个元素,最后一个为空字符。

                //将此行中所有的单元id添加到集合中
                listNdId.AddRange(elementIds.Where(r => !string.IsNullOrEmpty(r)).Select(int.Parse).ToArray());

                //读取下一个节点
                strLine = sr.ReadLine();
                match   = Regex.Match(strLine, pattern);
            }

            //将此Node Set中的每一个节点都生成一条 Generate Merge 命令
            XYZ    node;
            string mergeCommand = "Generate Merge " + Hm2Flac3DHandler.CubeRangePrecision * 2 + "  ";

            foreach (int nodeId in listNdId)
            {
                node = _allGridPoints[nodeId];
                string range = Hm2Flac3DHandler.ExtendCentroid(node);

                swGpMerge.WriteLine(mergeCommand + range);
            }

            //
            return(strLine);
        }
Exemple #7
0
        protected override string GenerateElement(ElementType type, StreamReader sr_inp, string componentName)
        {
            //
            Flac3dCommandWriters fcw   = Flac3dCommandWriters.GetUniqueInstance();
            Flac3DCommandType    fct   = Hm2Flac3DHandler.GetCommandType(type);
            StreamWriter         swSel = fcw.GetWriter(fct, componentName, _selId);
            //
            // 结构单元
            string strLine;

            if (type == ElementType.BEAM)
            {
                strLine = Gen_Beam(sr_inp, swSel, componentName, _selId);
            }
            else if (type == ElementType.PILE)
            {
                strLine = Gen_Pile(sr_inp, swSel, componentName, _selId);
            }
            else if (type == ElementType.SHELL3)
            {
                strLine = Gen_Shell3(sr_inp, swSel, componentName, _selId);
            }
            else if (type == (ElementType.Liner3 | ElementType.Liner4))
            {
                strLine = Gen_Liner(sr_inp, swSel, componentName, _selId, true);
            }
            else if (type == ElementType.Liner4)
            {
                strLine = Gen_Liner(sr_inp, swSel, componentName, _selId, false);
            } //Hypermesh中的类型在Flac3d中没有设置对应的类型
            else
            {
                _message.AppendLine($"Warning : Can not match element type \" {type} \"(in component {componentName}) with a corresponding type in Flac3D.");

                //如果某行字符串没有进行任何的数据提取,或者进行单元类型的判断,则继续读取下一行字符。
                strLine = sr_inp.ReadLine();
            }
            _selId++;
            return(strLine);
        }
Exemple #8
0
        /// <summary>
        /// 读取数据,并返回跳出循环的字符串
        /// </summary>
        /// <param name="sr_inp"></param>
        /// <param name="stringline"> 当前要读取 inp 文件中的那一行数据 </param>
        /// <returns>如果数据提取成功,则返回True,否则返回False</returns>
        /// <remarks>在读取数据时,每一个生成单元的函数中,都会返回最后跳出循环的那个字符串,如果某行字符串没有进行任何的数据提取,或者进行单元类型的判断,则继续读取下一行字符。</remarks>
        protected override string ReadElements(StreamReader sr_inp, string stringline)
        {
            const string pattern_ElementType           = @"\*ELEMENT,TYPE=(.+),ELSET=(.+)"; //大致结构为: *ELEMENT,TYPE=B31,ELSET=columns-c1
            const string pattern_ElementSet_LinerGroup = @"\*ELSET, ELSET=(LG.*)";          // 大致结构为:*ELSET, ELSET=LG_C2Wall
            const string pattern_NodeSet_Merge         = @"\*NSET, NSET=(LM.*)";            // 大致结构为:*NSET, NSET=LM_WallBottom

            //表示 Hypermesh 中的 SetBrowser 里面的 Element 组,用来作为 在Flac3D 中创建 Liner 时的 group 区间。

            string strLine = stringline;
            Match  match;

            do
            {
                //在Hypermesh导出的inp文件中,可以有很多个 *ELEMENT,TYPE=B31,ELSET=columns 这样的语句,它们是按hypermesh中的Component来进行分组的。
                match = Regex.Match(strLine, pattern_ElementType, RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    //
                    string strEleType = match.Groups[1].Value;

                    string strComponentName = match.Groups[2].Value;
                    // 当前读取到Inp中的那一个 Component(即 Hypermesh 中的 Component)

                    ElementType tp = Hm2Flac3DHandler.GetElementType(strEleType, strComponentName);

                    // 创建 Flac3D 单元
                    strLine = GenerateElement(tp, sr_inp, strComponentName);
                }
                else if ((match = Regex.Match(strLine, pattern_ElementSet_LinerGroup, RegexOptions.IgnoreCase)).Success)
                {
                    string groupName = match.Groups[1].Value;

                    if (groupName.Contains("-")) // set 的名称中不能包含“-”
                    {
                        _message.AppendLine($"Warning : Can not export element set : \" {groupName} \", make sure the set name starts with \"LG\"(case ignored) and excludes \"-\" if you want to bind the set to the creation of Liner elements.");
                    }
                    else
                    {
                        // 创建 Group 用来依附 Liner单元
                        strLine = Gen_LinerGroup(sr_inp, groupName);
                    }
                }
                else if ((match = Regex.Match(strLine, pattern_NodeSet_Merge, RegexOptions.IgnoreCase)).Success)
                {
                    string groupName = match.Groups[1].Value;

                    if (groupName.Contains("-")) // set 的名称中不能包含“-”
                    {
                        _message.AppendLine($"Warning : Can not export element set : \" {groupName} \", make sure the set name starts with \"LM\"(case ignored).");
                    }
                    else
                    {
                        //
                        Flac3dCommandWriters fcw       = Flac3dCommandWriters.GetUniqueInstance();
                        Flac3DCommandType    fct       = Hm2Flac3DHandler.GetCommandType(ElementType.MERGEPOINT);
                        StreamWriter         swMergeGp = fcw.GetWriter(fct, groupName, null);
                        //
                        // 节点耦合
                        strLine = Gen_GpMerge(sr_inp, swMergeGp, groupName);
                    }
                }
                else
                {
                    //如果某行字符串没有进行任何的数据提取,或者进行单元类型的判断,则继续读取下一行字符。
                    strLine = sr_inp.ReadLine();
                }
            } while (strLine != null);

            return(strLine);
        }