Example #1
0
        protected virtual void AddSecondBoundary(IMatrix A, double[] b, SecondBoundaryEdge edge)
        {
            Func <double, double, double, double> thetatime = edge.Theta;
            Func <double, double, double>         theta     = (double x, double y) => thetatime(x, y, 0);

            Point p1 = info.Mesh.Points[edge[0]];
            Point p2 = info.Mesh.Points[edge[edge.NodeCount - 1]];

            double x0 = p1.X;
            double y0 = p1.Y;
            double x1 = p2.X;
            double y1 = p2.Y;

            double h = Point.Distance(p1, p2);

            for (int i = 0; i < info.BoundaryBasis.Size; i++)
            {
                b[edge[i]] += h * Quadratures.NewtonCotes(0.0, 1.0, (double ksi) => theta(x0 + ksi * (x1 - x0), y0 + ksi * (y1 - y0)) * boundaryPsi[i](ksi));
            }
        }
Example #2
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());
        }