示例#1
0
        private List <TriangleCell> ReadEleFromFile(string path, List <Node> nodes)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("Error_ele_path");
            }
            var result = new List <TriangleCell>();
            Func <Point, Point> abs = (Point p) => new Point(Math.Abs(p.X), Math.Abs(p.Y));

            using (var fs = new StreamReader(File.Open(path, FileMode.Open))) {
                result = fs.ReadToEnd()
                         .Split('\n')
                         .Skip(1)
                         .Where(x => !(string.IsNullOrWhiteSpace(x) || x[0] == '#'))
                         .Select(x => {
                    var nums = x
                               .Split(' ')
                               .Where(y => !string.IsNullOrWhiteSpace(y))
                               .Select(s => int.Parse(s))
                               .ToArray();
                    var cell = new TriangleCell {
                        Id     = nums[0],
                        NCount = 3,
                        ECount = 3,
                        Node   = new List <Node> {
                            nodes[nums[1] - 1],
                            nodes[nums[2] - 1],
                            nodes[nums[3] - 1]
                        },
                        Type = nums[4]
                    };
                    AddToDict(cell.Node[0], cell);
                    AddToDict(cell.Node[1], cell);
                    AddToDict(cell.Node[2], cell);
                    cell.C = (cell.Node[0] + cell.Node[1] + cell.Node[2]) / 3;
                    cell.H = new Vector {
                        X = new[] {
                            Math.Abs(cell.Node[0].X - cell.Node[1].X),
                            Math.Abs(cell.Node[1].X - cell.Node[2].X),
                            Math.Abs(cell.Node[0].X - cell.Node[2].X)
                        }.Max(),
                        Y = new[] {
                            Math.Abs(cell.Node[0].Y - cell.Node[1].Y),
                            Math.Abs(cell.Node[1].Y - cell.Node[2].Y),
                            Math.Abs(cell.Node[0].Y - cell.Node[2].Y)
                        }.Max()
                    };
                    return(cell);
                })
                         .ToList();
            }
            return(result);
        }
示例#2
0
 private void AddToDict(Node node, TriangleCell cell)
 {
     if (DictCells.ContainsKey(node))
     {
         DictCells[node].Add(cell);
     }
     else
     {
         DictCells.Add(node, new List <TriangleCell> {
             cell
         });
     }
 }