예제 #1
0
        static Mesh LoadMesh(
            string pointsFile,
            string elementsFile,
            string firstBoundaryFile,
            string secondBoundaryFile,
            string thirdBoundaryFile,
            ProblemInfo info,
            IMeshBuilder builder)
        {
            // Points Parsing --------------------------------------------------------
            string[] lines      = File.ReadAllLines(pointsFile);
            int      pointCount = int.Parse(lines[0]);

            Point[] points = new Point[pointCount];

            for (int i = 0; i < pointCount; i++)
            {
                points[i] = Point.Parse(lines[i + 1]);
            }
            // -----------------------------------------------------------------------

            // Elements Parsing ------------------------------------------------------
            lines = File.ReadAllLines(elementsFile);
            int elementsCount             = int.Parse(lines[0]);
            List <FiniteElement> elements = new List <FiniteElement>();

            for (int i = 0; i < elementsCount; i++)
            {
                FiniteElement e      = new FiniteElement(info.Basis.Size);
                string[]      tokens = lines[i + 1].Split(' ');
                e.Vertices[0] = int.Parse(tokens[0]) - 1;
                e.Vertices[1] = int.Parse(tokens[1]) - 1;
                e.Vertices[2] = int.Parse(tokens[2]) - 1;
                e.Material    = info.MaterialDictionary[int.Parse(tokens[3])];

                elements.Add(e);
            }
            // -----------------------------------------------------------------------

            // First Boundary Parsing ------------------------------------------------
            lines = File.ReadAllLines(firstBoundaryFile);
            int firstBoundaryCount = int.Parse(lines[0]);
            List <FirstBoundaryEdge> firstBondary = new List <FirstBoundaryEdge>();

            for (int i = 0; i < firstBoundaryCount; i++)
            {
                FirstBoundaryEdge e      = new FirstBoundaryEdge(info.BoundaryBasis.Size);
                string[]          tokens = lines[i + 1].Split(' ');
                e.Vertices[0] = int.Parse(tokens[0]) - 1;
                e.Vertices[info.BoundaryBasis.Size - 1] = int.Parse(tokens[1]) - 1;
                e.F = info.FirstBoundaryDictionary[int.Parse(tokens[2])];

                firstBondary.Add(e);
            }
            // -----------------------------------------------------------------------

            // Second Boundary Parsing -----------------------------------------------
            lines = File.ReadAllLines(secondBoundaryFile);
            int secondBoundaryCount = int.Parse(lines[0]);
            List <SecondBoundaryEdge> secondBondary = new List <SecondBoundaryEdge>();

            for (int i = 0; i < secondBoundaryCount; i++)
            {
                SecondBoundaryEdge e      = new SecondBoundaryEdge(info.BoundaryBasis.Size);
                string[]           tokens = lines[i + 1].Split(' ');
                e.Vertices[0] = int.Parse(tokens[0]) - 1;
                e.Vertices[info.BoundaryBasis.Size - 1] = int.Parse(tokens[1]) - 1;
                e.Theta = info.SecondBoundaryDictionary[int.Parse(tokens[2])];

                secondBondary.Add(e);
            }
            // -----------------------------------------------------------------------

            // Third Boundary Parsing ------------------------------------------------
            lines = File.ReadAllLines(thirdBoundaryFile);
            int thirdBoundaryCount = int.Parse(lines[0]);
            List <ThirdBoundaryEdge> thirdBondary = new List <ThirdBoundaryEdge>();

            for (int i = 0; i < thirdBoundaryCount; i++)
            {
                ThirdBoundaryEdge e      = new ThirdBoundaryEdge(info.BoundaryBasis.Size);
                string[]          tokens = lines[i + 1].Split(' ');
                e.Vertices[0] = int.Parse(tokens[0]) - 1;
                e.Vertices[info.BoundaryBasis.Size - 1] = int.Parse(tokens[1]) - 1;

                int boundaryNo = int.Parse(tokens[2]);
                e.UBeta = info.ThirdBoundaryDictionary[boundaryNo].ubeta;
                e.Beta  = info.ThirdBoundaryDictionary[boundaryNo].beta;

                thirdBondary.Add(e);
            }
            // -----------------------------------------------------------------------

            builder.AddPoints(points);
            builder.AddElements(elements);
            builder.AddFirstBoundary(firstBondary);
            builder.AddSecondBoundary(secondBondary);
            builder.AddThirdBoundary(thirdBondary);
            return(builder.Build());
        }