public static double[] XMatrix(ref BoundaryNodeList nodeList) // Zwraca ablicę X { int dim = nodeList.Length; double[] X = new double[dim]; for (int i = 0; i < dim; i++) { if (nodeList[i].BC == "Dirichlet") { X[i] = nodeList[i].T; } else { if (nodeList[i].BC == "Neumann") { X[i] = nodeList[i].Q; } else { if (nodeList[i].BC == "Robin") { X[i] = nodeList[i].Tot; } } } } return(X); }
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[,] CMatrix(double[,] U, BoundaryNodeList bNodeList) { 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++; } } double[,] C = new double[N1, N1]; int ctr1 = 0; for (int i = 0; i < N; i++) { if (bNodeList[i].BC == "Identify") { int ctr2 = 0; for (int j = 0; j < N; j++) { if (bNodeList[j].BC == "Identify") { C[ctr1, ctr2++] = -U[i, j]; } } ctr1++; } } return(C); }
public static double[] PdMatrix(double[,] U, double[] J, double[] S, BoundaryNodeList bNodeList) { 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++; } } double[] Pd = new double[N1]; int ctr = 0; for (int i = 0; i < N; i++) { if (bNodeList[i].BC == "Identify") { double sum = 0.0; int ctr1 = 0; for (int j = 0; j < N; j++) { if (bNodeList[j].BC != "Identify") { sum += J[ctr1++] * U[i, j]; } } Pd[ctr] = sum + S[ctr++]; } } return(Pd); }
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 double[] JMatrix(BoundaryNodeList bNodeList) // Zmienić tutaj przyjmowaną wartość dla WB Robina { 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++; } } double[] P = new double[N - N1]; int ctr = 0; for (int j = 0; j < N; j++) { if (bNodeList[j].BC == "Dirichlet") { P[ctr++] = bNodeList[j].T; } if (bNodeList[j].BC == "Neumann") { P[ctr++] = bNodeList[j].Q; } if (bNodeList[j].BC == "Robin") { P[ctr++] = bNodeList[j].Tot; } } return(P); }
public static Data EvaluationMEB() { // Utworzenie obiektu data Data data = new Data(); BoundaryList boundaryList = new BoundaryList(); Reader.GetGeometry(@path, ref boundaryList); // Odczytywanie listy elementów brzegowych Reader.GetBoundaryConditions(@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 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[,] A = Matrixs.A1Matrix(ref G, ref H, ref bNodeList); // Wycznaczenie macierzy A double[] F = Matrixs.FMatrix(ref G, ref H, ref bNodeList); // Wycznaczenie wektora F double[] Y = GaussianElimination.gaussianElimination(ref A, ref F); // Wyznaczenie rozwiązania bNodeList.assignSolution(Y); // Przypisanie rozwiązania do listy węzłów brzegowych data.BoundaryList = boundaryList; data.ElementList = elementList; data.BoundaryNodeList = bNodeList; data.G = G; data.H = H; data.A1 = A; data.F = F; data.Y = Y; data.binarySerialize(); // Zapis obiektu data do pliku binarnego return(data); }
public static double[] FMatrix(ref double[,] G, ref double[,] H, ref BoundaryNodeList nodeList) // Zwraca tablicę F { int dim = nodeList.Length; double[] F = new double[dim]; for (int i = 0; i < dim; i++) { for (int j = 0; j < dim; j++) { if (nodeList[j].BC == "Dirichlet") { F[i] += H[i, j] * nodeList[j].T; } else { if (nodeList[j].BC == "Neumann") { F[i] += -G[i, j] * nodeList[j].Q; } else { if (nodeList[j].BC == "Robin") { F[i] += nodeList[j].A * G[i, j] * nodeList[j].Tot; } } } } } return(F); }
public static void EvaluationMEB(Data task) { BoundaryList boundaryList = task.BoundaryList; foreach (Boundary boundary in boundaryList) // Tutaj zamiana warunków brzegowych z Identify na Dirichlet { foreach (BoundaryElement boundaryElement in boundary) { if (boundaryElement.BC == "Identify") { if (MME.whichBC == "dirichlet") { boundaryElement.BC = "Dirichlet"; } else { boundaryElement.BC = "Neumann"; } } } } BoundaryNodeList bNodeList = new BoundaryNodeList(boundaryList); // Utworzenie listy węzłów brzegowych ElementList elementList = new ElementList(boundaryList); // Utworzenie listy elementów brzegowych double[,] G = task.G; // Wycznaczenie macierzy G double[,] H = task.H; // Wycznaczenie macierzy H double[,] A = task.A1; // Wycznaczenie macierzy A double[] F = Matrixs.FMatrix(ref G, ref H, ref bNodeList); // Wycznaczenie wektora F double[] Y = GaussianElimination.gaussianElimination(ref A, ref F); // Wyznaczenie rozwiązania task.BoundaryNodeList.assignSolution(Y); // Przypisanie rozwiązania do listy węzłów brzegowych task.F = F; task.Y = Y; task.binarySerialize(); // Zapis obiektu data do pliku binarnego }
public static double[,] GdMatrix(int n, ref ElementList elemList, ref BoundaryNodeList nodeList, double lam) // Zwraca tablicę G z daszkiem { double[,] G = new double[nodeList.Length, elemList.Length]; for (int i = 0; i < nodeList.Length; i++) { for (int j = 0; j < elemList.Length; j++) { G[i, j] = GaussianQuadrature.GIntegralConstant(n, elemList[j], nodeList[i], lam); } } return(G); }
public static double[,] HpskMatrix(int n, ref ElementList elemList, ref BoundaryNodeList nodeList, string psk) // Zwraca tablicę Hp, Hs lub Hk { // psk - Zwrac albo Hp, albo Hs, albo Hk double[,] H = new double[nodeList.Length, elemList.Length]; for (int i = 0; i < nodeList.Length; i++) { for (int j = 0; j < elemList.Length; j++) { H[i, j] = GaussianQuadrature.HIntegralParabolic(n, elemList[j], nodeList[i], psk); } } return(H); }
public static double[,] HdMatrix(int n, ref ElementList elemList, ref BoundaryNodeList nodeList) // Zwraca tablicę H z daszkiem { double[,] H = new double[nodeList.Length, elemList.Length]; for (int j = 0; j < elemList.Length; j++) { for (int i = 0; i < nodeList.Length; i++) { H[i, j] = GaussianQuadrature.HIntegralConstant(n, elemList[j], nodeList[i]); } } return(H); }
public static double[,] GpskMatrix(int n, ref ElementList elemList, ref BoundaryNodeList nodeList, double lam, string psk) // Zwraca tablicę Gp, Gs lub Gk { // pk - Zwrac albo Gp, albo Gs, albo Gk double[,] G = new double[nodeList.Length, elemList.Length]; for (int i = 0; i < nodeList.Length; i++) { for (int j = 0; j < elemList.Length; j++) { G[i, j] = GaussianQuadrature.GIntegralParabolic(n, elemList[j], nodeList[i], lam, psk); } } return(G); }
public static double[,] A2MatrixMME(ref double[,] G, ref double[,] H, ref BoundaryNodeList nodeList) // Zwraca tablicę A2 { int dim = nodeList.Length; double[,] A = new double[dim, dim]; for (int j = 0; j < dim; j++) { if (nodeList[j].BC == "Dirichlet") { for (int i = 0; i < dim; i++) { A[i, j] = H[i, j]; } } else { if (nodeList[j].BC == "Neumann") { for (int i = 0; i < dim; i++) { A[i, j] = -G[i, j]; } } else { if (nodeList[j].BC == "Robin") { for (int i = 0; i < dim; i++) { A[i, j] = G[i, j] * nodeList[j].A; } } else { for (int i = 0; i < dim; i++) // Zkaładam, że identyfikuję pierwszy WB { A[i, j] = H[i, j]; } } } } } return(A); }
public dialog_dataGridView(object boundaryNodeList) { InitializeComponent(); BoundaryNodeList bNodeList = (BoundaryNodeList)boundaryNodeList; dataGridView.ColumnCount = 8; dataGridView.Columns[0].Name = "Node no."; dataGridView.Columns[1].Name = "ElementID"; dataGridView.Columns[2].Name = "BoundaryID"; dataGridView.Columns[3].Name = "Boundary conditions"; dataGridView.Columns[4].Name = "T"; dataGridView.Columns[5].Name = "q"; dataGridView.Columns[6].Name = "Coordinates"; dataGridView.Columns[7].Name = "NodeType"; for (int i = 0; i < bNodeList.Length; i++) { string nt = null; if (bNodeList[i].NodeType == 1) { nt = "Singular"; } if (bNodeList[i].NodeType == 2) { nt = "Dual"; } if (bNodeList[i].NodeType == 3) { nt = "Singular (p)"; } if (bNodeList[i].NodeType == 4) { nt = "Internal"; } dataGridView.Rows.Add( bNodeList[i].NodeID.ToString(), bNodeList[i].ElemID.ToString(), bNodeList[i].BoundaryID.ToString(), bNodeList[i].BC, bNodeList[i].T.ToString(), bNodeList[i].Q.ToString(), bNodeList[i].Coordinates[0].ToString() + " ; " + bNodeList[i].Coordinates[1].ToString(), nt ); } }
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 void InternalTemperaturs(int nb, ElementList elemList, BoundaryNodeList boundaryNodeList, double lam) // Wyznacza temperaturę w punkcie wewnętrznym { BoundaryNodeList nodeList = new BoundaryNodeList(this); if (BoundaryElement.ElemType == "Constant") { double[,] Hd = Matrixs.HdMatrix(nb, ref elemList, ref nodeList); double[,] G = Matrixs.GdMatrix(nb, ref elemList, ref nodeList, lam); int i = 0; foreach (InternalPoint ip in this) { double sumHT = 0.0, sumGq = 0.0; for (int j = 0; j < boundaryNodeList.Length; j++) { sumHT += (Hd[i, j] * boundaryNodeList[j].T); sumGq += (G[i, j] * boundaryNodeList[j].Q); } this[i++].Temperature = sumHT - sumGq; } } else { double[,] H = Matrixs.HMatrixForInternalPoints(nb, ref elemList, ref nodeList, ref boundaryNodeList); double[,] G = Matrixs.GMatrixForInternalPoints(nb, ref elemList, ref nodeList, ref boundaryNodeList, lam); int i = 0; foreach (InternalPoint ip in this) { double sumHT = 0.0, sumGq = 0.0; for (int j = 0; j < boundaryNodeList.Length; j++) { sumHT += (H[i, j] * boundaryNodeList[j].T); sumGq += (G[i, j] * boundaryNodeList[j].Q); } this[i++].Temperature = sumHT - sumGq; } } }
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[,] A1Matrix(ref double[,] G, ref double[,] H, ref BoundaryNodeList nodeList) // Zwraca tablicę A1 { int dim = nodeList.Length; double[,] A = new double[dim, dim]; for (int j = 0; j < dim; j++) { if (nodeList[j].BC == "Dirichlet") { for (int i = 0; i < dim; i++) { A[i, j] = G[i, j]; } } else { if (nodeList[j].BC == "Neumann") { for (int i = 0; i < dim; i++) { A[i, j] = -H[i, j]; } } else { if (nodeList[j].BC == "Robin") { for (int i = 0; i < dim; i++) { A[i, j] = G[i, j] * nodeList[j].A - H[i, j]; } } } } } return(A); }
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[,] HMatrix(int n, ref ElementList elemList, ref BoundaryNodeList nodeList) // Zwraca tablicę H { // n - stopień aproksymacji // elemList - lista z elementami brzegowymi double[,] H; switch (BoundaryElement.ElemType) { case "Constant": { double[,] Hd = HdMatrix(n, ref elemList, ref nodeList); H = new double[nodeList.Length, nodeList.Length]; for (int i = 0; i < elemList.Length; i++) { for (int j = 0; j < elemList.Length; j++) { if (i == j) // Jeżeli i = j { H[i, j] = Hd[i, j] - 0.5; } else { H[i, j] = Hd[i, j]; } } } break; } case "Linear": { double[,] Hp = HpkMatrix(n, ref elemList, ref nodeList, "p"); double[,] Hk = HpkMatrix(n, ref elemList, ref nodeList, "k"); int ctr = 1; // Zmienna pomocnicza H = new double[nodeList.Length, nodeList.Length]; for (int i = 0; i < nodeList.Length; i++) { ctr = 1; if (nodeList[0].NodeType == 2) { H[i, nodeList.Length - 1] = Hk[i, elemList.Length - 1]; H[i, 0] = Hp[i, 0]; } else { H[i, 0] = Hk[i, elemList.Length - 1] + Hp[i, 0]; } for (int j = 1; j < elemList.Length; j++) { if (nodeList[ctr].NodeType == 2) { H[i, ctr++] = Hk[i, j - 1]; H[i, ctr] = Hp[i, j]; } else { H[i, ctr] = Hk[i, j - 1] + Hp[i, j]; } ctr++; } } double sum = 0.0; for (int i = 0; i < nodeList.Length; i++) { for (int j = 0; j < nodeList.Length; j++) { if (i != j) { sum += H[i, j]; } } H[i, i] = -sum; sum = 0.0; } break; } case "Parabolic": { double[,] Hp = HpskMatrix(n, ref elemList, ref nodeList, "p"); double[,] Hs = HpskMatrix(n, ref elemList, ref nodeList, "s"); double[,] Hk = HpskMatrix(n, ref elemList, ref nodeList, "k"); int ctr; // Zmienna pomocnicza H = new double[nodeList.Length, nodeList.Length]; for (int i = 0; i < nodeList.Length; i++) { ctr = 2; if (nodeList[0].NodeType == 2) { H[i, nodeList.Length - 1] = Hk[i, elemList.Length - 1]; H[i, 0] = Hp[i, 0]; } else { H[i, 0] = Hk[i, elemList.Length - 1] + Hp[i, 0]; } H[i, 1] = Hs[i, 0]; for (int j = 1; j < elemList.Length; j++) { if (nodeList[ctr].NodeType == 2) { H[i, ctr++] = Hk[i, j - 1]; H[i, ctr] = Hp[i, j]; } else { H[i, ctr] = Hk[i, j - 1] + Hp[i, j]; } ctr++; H[i, ctr] = Hs[i, j]; ctr++; } } double sum = 0.0; for (int i = 0; i < nodeList.Length; i++) { for (int j = 0; j < nodeList.Length; j++) { if (i != j) { sum += H[i, j]; } } H[i, i] = -sum; sum = 0.0; } break; } default: { H = new double[elemList.Length, elemList.Length]; throw new System.Exception("Niepoprawny rodzaj elementu podczas tworzenia tablicy H!!!"); } } return(H); }
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); }
public static double[,] GMatrix(int n, ref ElementList elemList, ref BoundaryNodeList nodeList, double lam) // Zwraca tablicę G { // n - stopień aproksymacji // elemList - lista z elementami brzegowymi double[,] G; switch (BoundaryElement.ElemType) { case "Constant": { double[,] Gd = GdMatrix(n, ref elemList, ref nodeList, lam); G = Gd; break; } case "Linear": { double[,] Gp = GpkMatrix(n, ref elemList, ref nodeList, lam, "p"); double[,] Gk = GpkMatrix(n, ref elemList, ref nodeList, lam, "k"); int ctr = 1; // Zmienna pomocnicza G = new double[nodeList.Length, nodeList.Length]; for (int i = 0; i < nodeList.Length; i++) { ctr = 1; if (nodeList[0].NodeType == 2) { G[i, nodeList.Length - 1] = Gk[i, elemList.Length - 1]; G[i, 0] = Gp[i, 0]; } else { G[i, 0] = Gk[i, elemList.Length - 1] + Gp[i, 0]; } for (int j = 1; j < elemList.Length; j++) { if (nodeList[ctr].NodeType == 2) { G[i, ctr++] = Gk[i, j - 1]; G[i, ctr] = Gp[i, j]; } else { G[i, ctr] = Gk[i, j - 1] + Gp[i, j]; } ctr++; } } break; } case "Parabolic": { double[,] Gp = GpskMatrix(n, ref elemList, ref nodeList, lam, "p"); double[,] Gs = GpskMatrix(n, ref elemList, ref nodeList, lam, "s"); double[,] Gk = GpskMatrix(n, ref elemList, ref nodeList, lam, "k"); int ctr; // Zmienna pomocnicza G = new double[nodeList.Length, nodeList.Length]; for (int i = 0; i < nodeList.Length; i++) { ctr = 2; if (nodeList[0].NodeType == 2) { G[i, nodeList.Length - 1] = Gk[i, elemList.Length - 1]; G[i, 0] = Gp[i, 0]; } else { G[i, 0] = Gk[i, elemList.Length - 1] + Gp[i, 0]; } G[i, 1] = Gs[i, 0]; for (int j = 1; j < elemList.Length; j++) { if (nodeList[ctr].NodeType == 2) { G[i, ctr++] = Gk[i, j - 1]; G[i, ctr] = Gp[i, j]; } else { G[i, ctr] = Gk[i, j - 1] + Gp[i, j]; } ctr++; G[i, ctr] = Gs[i, j]; ctr++; } } break; } default: { G = new double[elemList.Length, elemList.Length]; throw new System.Exception("Niepoprawny rodzaj elementu podczas tworzenia tablicy G!!!"); } } return(G); }
public static double[,] HMatrixForInternalPoints(int n, ref ElementList elemList, ref BoundaryNodeList internalNodeList, ref BoundaryNodeList boundaryNodeList) // Zwraca tablicę H { // n - stopień aproksymacji // elemList - lista z elementami brzegowymi double[,] H; switch (BoundaryElement.ElemType) { case "Linear": { double[,] Hp = HpkMatrix(n, ref elemList, ref internalNodeList, "p"); double[,] Hk = HpkMatrix(n, ref elemList, ref internalNodeList, "k"); int ctr = 1; // Zmienna pomocnicza H = new double[internalNodeList.Length, boundaryNodeList.Length]; for (int i = 0; i < internalNodeList.Length; i++) { ctr = 1; if (boundaryNodeList[0].NodeType == 2) { H[i, boundaryNodeList.Length - 1] = Hk[i, elemList.Length - 1]; H[i, 0] = Hp[i, 0]; } else { H[i, 0] = Hk[i, elemList.Length - 1] + Hp[i, 0]; } for (int j = 1; j < elemList.Length; j++) { if (boundaryNodeList[ctr].NodeType == 2) { H[i, ctr++] = Hk[i, j - 1]; H[i, ctr] = Hp[i, j]; } else { H[i, ctr] = Hk[i, j - 1] + Hp[i, j]; } ctr++; } } break; } case "Parabolic": { H = new double[internalNodeList.Length, boundaryNodeList.Length]; double[,] Hp = HpskMatrix(n, ref elemList, ref internalNodeList, "p"); double[,] Hs = HpskMatrix(n, ref elemList, ref internalNodeList, "s"); double[,] Hk = HpskMatrix(n, ref elemList, ref internalNodeList, "k"); int ctr; // Zmienna pomocnicza for (int i = 0; i < internalNodeList.Length; i++) { ctr = 2; if (boundaryNodeList[0].NodeType == 2) { H[i, boundaryNodeList.Length - 1] = Hk[i, elemList.Length - 1]; H[i, 0] = Hp[i, 0]; } else { H[i, 0] = Hk[i, elemList.Length - 1] + Hp[i, 0]; } H[i, 1] = Hs[i, 0]; for (int j = 1; j < elemList.Length; j++) { if (boundaryNodeList[ctr].NodeType == 2) { H[i, ctr++] = Hk[i, j - 1]; H[i, ctr] = Hp[i, j]; } else { H[i, ctr] = Hk[i, j - 1] + Hp[i, j]; } ctr++; H[i, ctr] = Hs[i, j]; ctr++; } } break; } default: { H = new double[elemList.Length, elemList.Length]; throw new System.Exception("Niepoprawny rodzaj elementu podczas tworzenia tablicy H dla punktów wewnętrznych!!!"); } } return(H); }