/// <summary> /// /// </summary> /// <param name="Line"></param> /// <param name="t"></param> public static void Parse(string Line, out CTRIA3 t) { string[] Parts = SplitNastranLine(Line, 9); if (!Parts[0].Equals("CTRIA3")) { throw new ArgumentException("line must start with CTRIA3", "Line"); } t.ID = int.Parse(Parts[1]); t.Grid1 = int.Parse(Parts[3]); t.Grid2 = int.Parse(Parts[4]); t.Grid3 = int.Parse(Parts[5]); }
/// <summary> /// renames all ID's in <see cref="m_GRID_List"/> (see <see cref="GRID.ID"/>) /// to be equal to the index in <see cref="m_GRID_List"/> /// and applies that cahnege also to the Grid id's in <see cref="m_CTRIA3_List"/> ( /// see <see cref="CTRIA3.Grid1"/>, <see cref="CTRIA3.Grid3"/>, <see cref="CTRIA3.Grid3"/>); /// </summary> private void RenameIds() { SortedDictionary <int, int> id2index = new SortedDictionary <int, int>(); for (int i = 0; i < m_GRID_List.Count; i++) { id2index.Add(m_GRID_List[i].ID, i); GRID g = m_GRID_List[i]; g.ID = i; m_GRID_List[i] = g; } for (int j = 0; j < m_CTRIA3_List.Count; j++) { CTRIA3 t = m_CTRIA3_List[j]; t.Grid1 = id2index[t.Grid1]; t.Grid2 = id2index[t.Grid2]; t.Grid3 = id2index[t.Grid3]; t.ID = j; m_CTRIA3_List[j] = t; } }
/// <summary> /// imports a nastran file /// </summary> /// <param name="FilePath"></param> public NastranFile(string FilePath) { StreamReader rd = null; rd = new StreamReader(FilePath); string line = rd.ReadLine(); while (line != null) { if (line.StartsWith("GRID")) { GRID g; GRID.Parse(line, out g); m_GRID_List.Add(g); } if (line.StartsWith("CTRIA3")) { CTRIA3 t; CTRIA3.Parse(line, out t); m_CTRIA3_List.Add(t); } line = rd.ReadLine(); } rd.Close(); RenameIds(); }
/// <summary> /// creates some test grid /// </summary> /// <param name="N">resolution of testgrid</param> public NastranFile(int N) { double[] nodes = GenericBlas.Linspace(-3, 3, N); double dh = nodes[1] - nodes[0]; dh *= 0.5; int cnt = 0; for (int i = 0; i < N; i++) { double even = 0; if (i % 2 == 0) { even = dh; } for (int j = 0; j < N; j++) { GRID g = new GRID(); g.X1 = (float)(nodes[j] + even); g.X2 = (float)nodes[i]; g.ID = cnt; m_GRID_List.Add(g); cnt++; } } cnt = 0; for (int k = 0; k < (N - 1); k++) { int even = 0; int odd = 0; if (k % 2 == 0) { even = 1; } else { odd = 1; } for (int i = k * N; i < (k * N + N - 1); i++) { CTRIA3 tup = new CTRIA3(); tup.Grid1 = i + N + even; tup.Grid2 = i; tup.Grid3 = i + 1; tup.ID = cnt; cnt = cnt + 1; m_CTRIA3_List.Add(tup); CTRIA3 tdw = new CTRIA3(); tdw.Grid1 = i + odd; tdw.Grid2 = i + N + 1; tdw.Grid3 = i + N; tup.ID = cnt; cnt = cnt + 1; m_CTRIA3_List.Add(tdw); } } }