protected override void BuildLocalMatrix(FiniteElement e) { Point a = points[e[0]]; Point b = points[e[1]]; Point c = points[e[2]]; Point center = (a + b + c) / 3; double D = Math.Abs(Utilities.Det(a, b, c)); double[] alpha = Alpha(a, b, c); (double a1, double a2)[] grads = new (double, double)[3]
private void AddLocalToGlobal(IMatrix A, double[] b, FiniteElement e) { for (int i = 0; i < info.Basis.Size; i++) { for (int j = 0; j < info.Basis.Size; j++) { A.Add(e[i], e[j], local[i, j]); } } for (int i = 0; i < info.Basis.Size; i++) { b[e[i]] += localb[i]; } }
protected virtual void BuildLocalMatrix(FiniteElement e) { Point a = points[e[0]]; Point b = points[e[1]]; Point c = points[e[2]]; double D = Math.Abs(Utilities.Det(a, b, c)); for (int i = 0; i < info.Basis.Size; i++) { for (int j = 0; j < info.Basis.Size; j++) { double G = Quadratures.TriangleGauss18(GetGrad(i, j, a, b, c)); double M = Quadratures.TriangleGauss18((double ksi, double etta) => psi[i](ksi, etta) * psi[j](ksi, etta)); local[i, j] = (e.Material.Lambda * G + e.Material.RoCp * M) * D; } } }
protected virtual void BuildLocalB(FiniteElement e) { // TODO: implement this method Point a = points[e[0]]; Point b = points[e[1]]; Point c = points[e[2]]; double D = Math.Abs(Utilities.Det(a, b, c)); for (int i = 0; i < info.Basis.Size; i++) { localb[i] = Quadratures.TriangleGauss18((double ksi, double etta) => { double x = a.X * ksi + b.X * etta + c.X * (1 - ksi - etta); double y = a.Y * ksi + b.Y * etta + c.Y * (1 - ksi - etta); return(e.Material.F(x, y, 0) * psi[i](ksi, etta)); }); localb[i] *= D; } }
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()); }