Esempio n. 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private void button_OpenWorkDirectory_Click(object sender, EventArgs e)
        {
            string workingDirectory = Flac3dCommandWriters.GetWorkDirectory();

            // 打开文件夹
            System.Diagnostics.Process.Start("Explorer.exe", workingDirectory);
        }
Esempio n. 4
0
 public static Flac3dCommandWriters GetUniqueInstance()
 {
     if (_uniqueInstance == null)
     {
         _uniqueInstance = new Flac3dCommandWriters();
     }
     return(_uniqueInstance);
 }
Esempio n. 5
0
        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //
            _message.AppendLine();
            _message.AppendLine("--------------------------------------------------------  转换结束");
            LabelHello.Text = _message.ToString();

            // 关闭所有打开的文本
            Flac3dCommandWriters fcw = Flac3dCommandWriters.GetUniqueInstance();

            fcw.CloseAllWriters(true);
            Flac3dCommandWriters.WorkingStartTime = null;
            //
            ProgressBar1.Visible = false;
            WarmUp();
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
 /// <summary> 将所有的 StreamWriter 文本文件关闭 </summary>
 /// <param name="writeMain">是否要新增一个命令文本,用来统领整个建模过程</param>
 public void CloseAllWriters(bool writeMain)
 {
     if (_openedWriters != null)
     {
         foreach (WriterInfo wi in _openedWriters.Values)
         {
             StreamWriter sw = wi.Writer;
             if (sw != null)
             {
                 sw.Close();
                 sw.Dispose();
             }
         }
         //
         if (writeMain)
         {
             WriteMain();
         }
         //
         _openedWriters.Clear();
         _openedWriters  = null;
         _uniqueInstance = null;
     }
 }
Esempio n. 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);
        }