public static double[] FdMatrix(double[] Z, InternalPointList iPointList) { double[] F = new double[iPointList.Count]; for (int i = 0; i < iPointList.Count; i++) { F[i] = iPointList[i].Temperature - Z[i]; } return(F); }
public BoundaryNodeList(InternalPointList ipList) // Konstruktor dla punktów wewnętrznych { int ctr = ipList.Count; nList = new BoundaryNode[ctr]; ctr = 0; foreach (InternalPoint ip in ipList) { nList[ctr] = new BoundaryNode(ip.Coordinates, 4, ctr++); } }
private static InternalPointList GetInternalPoints() // Pętla do wczytywania punktów wewnętrznych { InternalPointList iPointList = new InternalPointList(); Console.WriteLine("Wyznaczyć temperatury w pkt. wew. ? (t / n):"); /*string tn = Console.ReadLine(); * if (tn == "t" || tn == "T") * { Console.WriteLine("Aby zakończyć, zamiast wsp. podaj \"n\":"); } * double x1 = 0.0, x2 = 0.0, temp = 0.0; * while (tn != "n" && tn != "N") * { * Console.WriteLine("x1:"); * tn = Console.ReadLine(); * if (tn != "n" && tn != "N") * { x1 = double.Parse(tn); } * else * { break; } * Console.WriteLine("x2:"); * tn = Console.ReadLine(); * if (tn != "n" && tn != "N") * { x2 = double.Parse(tn); } * else * { break; } * Console.WriteLine("T:"); * tn = Console.ReadLine(); * if (tn != "n" && tn != "N") * { temp = double.Parse(tn); } * iPointList.Add(new InternalPoint(x1, x2, temp)); * }*/ //iPointList.Add(new InternalPoint(1, 1, 150)); //iPointList.Add(new InternalPoint(2, 1, 100)); //iPointList.Add(new InternalPoint(3, 1, 50)); //iPointList.Add(new InternalPoint(1, 3, 150)); //iPointList.Add(new InternalPoint(2, 3, 100)); //iPointList.Add(new InternalPoint(3, 3, 50)); //iPointList.Add(new InternalPoint(1, 2, 150)); //iPointList.Add(new InternalPoint(3, 2, 50)); //iPointList.Add(new InternalPoint(2, 2, 100)); iPointList.Add(new InternalPoint(1, 1, 68.138944464657598)); iPointList.Add(new InternalPoint(1, 2, 62.636409610026632)); iPointList.Add(new InternalPoint(1, 3, 67.126922825109702)); return(iPointList); }
public static void GetInternalTemperaturesMME(string path, InternalPointList iPointList) // Wczytuje temperatury z sensorów { FileInfo thesourceFile = new FileInfo(@path); StreamReader reader = thesourceFile.OpenText(); string text = reader.ReadToEnd(); reader.Close(); string[] s = { "\r\n" }; string[] Lines = text.Split(s, StringSplitOptions.None); for (int i = 0; i < Lines.Length; i++) { if (Lines[i].IndexOf("# startInternalTemperatures") >= 0) { i++; while (Lines[i].IndexOf("# endInternalTemperatures") < 0) { if (Lines[i].IndexOf("//") == -1) { Regex theReg = new Regex(@"\S+"); MatchCollection theMatches = theReg.Matches(Lines[i]); if (theMatches.Count == 3) { double x1, x2, T; x1 = double.Parse(theMatches[0].ToString()); x2 = double.Parse(theMatches[1].ToString()); T = double.Parse(theMatches[2].ToString()); iPointList.Add(new InternalPoint(x1, x2, T)); } } if (++i >= Lines.Length) { break; } } } } }
public Data(ref BoundaryList bl, ref ElementList el, ref BoundaryNodeList bnl, ref InternalPointList ipl, ref double[,] Garr, ref double[,] Harr, ref double[,] A1arr, ref double[,] A2arr, ref double[] Farr, ref double[] Yarr, ref double[] Xarr) { this.boundaryList = bl; this.elementList = el; this.bNodeList = bnl; this.iPointList = ipl; this.g = Garr; this.h = Harr; this.a1 = A1arr; this.a2 = A2arr; this.f = Farr; this.y = Yarr; this.x = Xarr; if (!GaussJordanElimination.gaussJordanElimination(A1, out this.b)) { throw new System.Exception("Macierz A1 jest nieodwracalna!!!"); } else { u = AuxiliaryFunctions.MMMultiplication(ref b, ref a2, (int)Math.Sqrt(b.Length), (int)Math.Sqrt(b.Length)); } }
public static double[,] WMatrix(double[,] Hw, double[,] Gw, double[,] U, BoundaryNodeList bNodeList, InternalPointList iPointList) { int N = bNodeList.Length; int N1 = 0; // N1 - ilość elementów brzegowych, na których identyfikuję for (int j = 0; j < N; j++) { if (bNodeList[j].BC == "Identify") { N1++; } } int M = iPointList.Count; // M - ilość sensorów double[,] W = new double[M, N]; for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0, sum4 = 0.0; for (int k = 0; k < N; k++) { if (bNodeList[k].BC == "Identify" && MME.whichBC == "dirichlet") { sum1 += Gw[i, k] * U[j, k]; } if (bNodeList[k].BC == "Identify" && MME.whichBC == "neumann") { sum1 += Hw[i, k] * U[j, k]; } if (bNodeList[k].BC == "Dirichlet") { sum2 += Gw[i, k] * U[j, k]; } if (bNodeList[k].BC == "Neumann") { sum3 += Hw[i, k] * U[j, k]; } if (bNodeList[k].BC == "Robin") { sum4 += (Hw[i, k] - Gw[i, k] * bNodeList[k].A) * U[k, j]; } } if (MME.whichBC == "dirichlet") { W[i, j] = Hw[i, j] - sum1 - sum2 + sum3 + sum4; } else { W[i, j] = -Gw[i, j] + sum1 - sum2 + sum3 + sum4; } } } double[,] WI = new double[M, N1]; int ctr = 0; for (int j = 0; j < N; j++) { if (bNodeList[j].BC == "Identify") { for (int i = 0; i < M; i++) { WI[i, ctr] = W[i, j]; } ctr++; } } return(WI); }
public static double[,] Dw1Matrix(double[,] Gw, double[,] Hw, BoundaryNodeList bNodeList, InternalPointList iPointList) { int N1 = 0; // N1 - ilość elementów brzegowych, na których identyfikuję for (int j = 0; j < bNodeList.Length; j++) { if (bNodeList[j].BC == "Identify") { N1++; } } double[,] D = new double[iPointList.Count, N1]; for (int i = 0; i < iPointList.Count; i++) { int ctr = 0; for (int j = 0; j < bNodeList.Length; j++) { if (bNodeList[j].BC == "Identify" && MME.whichBC == "dirichlet") { D[i, ctr++] = Hw[i, j]; } if (bNodeList[j].BC == "Identify" && MME.whichBC == "neumann") { D[i, ctr++] = -Gw[i, j]; } } } return(D); }
public static double[,] DwMatrix(double[,] Gw, double[,] Hw, double[,] U, BoundaryNodeList bNodeList, InternalPointList iPointList) { int N = bNodeList.Length; // N - ilość elementów brzegowych int M = iPointList.Count; // M - ilość sensorów double[,] D = new double[M, N]; for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0, sum4 = 0.0; for (int k = 0; k < N; k++) { if (bNodeList[k].BC == "Identify" && MME.whichBC == "dirichlet") { sum1 += Gw[i, k] * U[k, j]; } if (bNodeList[k].BC == "Identify" && MME.whichBC == "neumann") { sum1 += Hw[i, k] * U[k, j]; } if (bNodeList[k].BC == "Dirichlet") { sum2 += Gw[i, k] * U[k, j]; } if (bNodeList[k].BC == "Neumann") { sum3 += Hw[i, k] * U[k, j]; } if (bNodeList[k].BC == "Robin") { sum4 += (Hw[i, k] - Gw[i, k] * bNodeList[k].A) * U[k, j]; } } D[i, j] = -sum1 - sum2 + sum3 + sum4; } } return(D); }
public static double[] ZMatrix(double[,] Dw, double[] P, double[] E, BoundaryNodeList bNodeList, InternalPointList iPointList) { int M = iPointList.Count; double[] Z = new double[M]; for (int i = 0; i < M; i++) { double sum1 = 0.0; int ctr = 0; for (int j = 0; j < bNodeList.Length; j++) { if (bNodeList[j].BC != "Identify") { sum1 += Dw[i, j] * P[ctr++]; } } E[i] = sum1 + E[i]; } return(E); }
public static double[] EMatrix(double[,] Gw, double[,] Hw, double[] P, BoundaryNodeList bNodeList, InternalPointList iPointList) { int M = iPointList.Count; double[] E = new double[M]; for (int i = 0; i < M; i++) { double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0; int ctr = 0; for (int j = 0; j < bNodeList.Length; j++) { if (bNodeList[j].BC == "Dirichlet") { sum1 += Hw[i, j] * P[ctr++]; } if (bNodeList[j].BC == "Neumann") { sum2 += Gw[i, j] * P[ctr++]; } if (bNodeList[j].BC == "Robin") { sum3 += bNodeList[j].A * Gw[i, j] * P[ctr++]; } } E[i] = sum1 - sum2 + sum3; } return(E); }
public static Data EvaluationMME() { // Utworzenie obiektu data Data data = new Data(); BoundaryList boundaryList = new BoundaryList(); Reader.GetGeometry(@path, ref boundaryList); // Odczytywanie listy elementów brzegowych Reader.GetBoundaryConditionsMME(@path, ref boundaryList); // Odczytywanie warunków brzegowych BoundaryNodeList bNodeList = new BoundaryNodeList(boundaryList); // Utworzenie listy węzłów brzegowych ElementList elementList = new ElementList(boundaryList); // Utworzenie listy elementów brzegowych InternalPointList iPointList = constValue.MMEiternalPointList; BoundaryNodeList nodeList = new BoundaryNodeList(iPointList); // Wyznaczanie listy węzłów dla elementów brzegowych double[,] G = Matrixs.GMatrix(nb, ref elementList, ref bNodeList, lam); // Wycznaczenie macierzy G double[,] H = Matrixs.HMatrix(nb, ref elementList, ref bNodeList); // Wycznaczenie macierzy H double[,] B; double[,] A1 = Matrixs.A1MatrixMME(ref G, ref H, ref bNodeList); // Wycznaczenie macierzy A1 if (!GaussJordanElimination.gaussJordanElimination(A1, out B)) { data.Error = "Macierz A1 jest nieodwracalna.\n\n" + AuxiliaryFunctions.PrintArray(A1, (int)Math.Sqrt(A1.Length), (int)Math.Sqrt(A1.Length)); data.binarySerialize(); // Zapis obiektu data do pliku binarnego return(data); } double[,] A2 = Matrixs.A2MatrixMME(ref G, ref H, ref bNodeList); // Wycznaczenie macierzy A2 double[,] Hw; double[,] Gw; if (BoundaryElement.ElemType == "Constant") { Hw = Matrixs.HdMatrix(nb, ref elementList, ref nodeList); Gw = Matrixs.GdMatrix(nb, ref elementList, ref nodeList, lam); } else { Hw = Matrixs.HMatrixForInternalPoints(nb, ref elementList, ref nodeList, ref bNodeList); Gw = Matrixs.GMatrixForInternalPoints(nb, ref elementList, ref nodeList, ref bNodeList, lam); } data.BoundaryList = boundaryList; data.ElementList = elementList; data.BoundaryNodeList = bNodeList; data.IntenralPointList = iPointList; data.G = G; data.Gw = Gw; data.H = H; data.Hw = Hw; data.A1 = A1; data.B = B; data.A2 = A2; data.R = Matrixs.RMatrix(Gw, Hw, data.B, data.BoundaryNodeList, data.IntenralPointList); data.Dw = Matrixs.DwMatrix(Gw, Hw, data.U, data.BoundaryNodeList, data.IntenralPointList); data.Dw1 = Matrixs.Dw1Matrix(Gw, Hw, data.BoundaryNodeList, data.IntenralPointList); data.W = Matrixs.WMatrix(data.Hw, data.Gw, data.U, data.BoundaryNodeList, data.IntenralPointList); data.P = Matrixs.PMatrix(data.BoundaryNodeList); data.E = Matrixs.EMatrix(Gw, Hw, data.P, data.BoundaryNodeList, data.IntenralPointList); data.Z = Matrixs.ZMatrix(data.Dw, data.P, data.E, data.BoundaryNodeList, data.IntenralPointList); data.Fd = Matrixs.FdMatrix(data.Z, data.IntenralPointList); //double[] fff = { 11.327, 21.561, 25, 21.561, 11.327 }; //data.Fd = fff; data.J = Matrixs.JMatrix(data.BoundaryNodeList); data.S = Matrixs.SMatrix(data.U, data.P, data.BoundaryNodeList); data.Pd = Matrixs.PdMatrix(data.U, data.J, data.S, data.BoundaryNodeList); data.C = Matrixs.CMatrix(data.U, data.BoundaryNodeList); // WOLFE int n = (int)Math.Sqrt(data.C.Length); // Ilość zmiennych decyzyjnych int m = (int)((data.W.Length / n) * 2); // Ilość ograniczeń double[,] A = new double[m, n]; double[] b = new double[m]; double[,] C; double[] p; if (precision == -1) { for (int i = 0; i < m / 2; i++) { for (int j = 0; j < n; j++) { A[i, j] = data.W[i, j]; } b[i] = data.Fd[i] + epsilon; } for (int i = 0; i < m / 2; i++) { for (int j = 0; j < n; j++) { A[i + m / 2, j] = -data.W[i, j]; } b[i + m / 2] = epsilon - data.Fd[i]; } C = new double[n, n]; p = new double[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { C[i, j] = data.C[i, j]; } p[i] = data.Pd[i]; } } else { for (int i = 0; i < m / 2; i++) { for (int j = 0; j < n; j++) { A[i, j] = Math.Round(data.W[i, j], precision); } b[i] = Math.Round(data.Fd[i] + epsilon, precision); } for (int i = 0; i < m / 2; i++) { for (int j = 0; j < n; j++) { A[i + m / 2, j] = Math.Round(-data.W[i, j], precision); } b[i + m / 2] = Math.Round(epsilon - data.Fd[i], precision); } C = new double[n, n]; p = new double[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { C[i, j] = Math.Round(data.C[i, j], precision); } p[i] = Math.Round(data.Pd[i], precision); } } InitialTask iTask = new InitialTask(n, m, C, p, A, b); SubstituteTask sTask = new SubstituteTask(iTask); Wolfe wolfe = new Wolfe(sTask); wolfe.Evaluation(); data.Error = wolfe.Error; if (data.Error == null) { AssignSolution(wolfe, ref data); MEB.EvaluationMEB(data); } // wolfe data.binarySerialize(); // Zapis obiektu data do pliku binarnego return(data); }