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 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[,] 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); }
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); }