コード例 #1
0
        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
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: BoundaryList.cs プロジェクト: b1es/BEW
        public ElementList(BoundaryList bList)
        {
            int ctr = 0;

            foreach (Boundary b in bList)
            {
                ctr += b.Count;
            }

            elementList = new BoundaryElement[ctr];

            ctr = 0;
            foreach (Boundary b in bList)
            {
                foreach (BoundaryElement be in b)
                {
                    elementList[ctr] = be; ctr++;
                }
            }
        }
コード例 #4
0
 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));
     }
 }
コード例 #5
0
ファイル: BoundaryNodeList.cs プロジェクト: b1es/BEW
        public BoundaryNodeList(BoundaryList boundaryList)   // Konstruktor
        {
            switch (BoundaryElement.ElemType)
            {
            case "Constant":
            {
                int ctr = 0;
                foreach (Boundary boundary in boundaryList)
                {
                    ctr += boundary.Count;
                }

                nList = new BoundaryNode[ctr];

                ctr = 0;
                foreach (Boundary boundary in boundaryList)
                {
                    foreach (BoundaryElement bElement in boundary)
                    {
                        nList[ctr] = new BoundaryNode(bElement, bElement.Node[0], 1, ctr++);
                    }
                }
                break;
            }

            case "Linear":
            {
                int R = 0;
                foreach (Boundary boundary in boundaryList)
                {
                    if ((!AuxiliaryFunctions.Parallelism(boundary[0], boundary[boundary.Count - 1])) &&
                        (boundary[0].BC != boundary[boundary.Count - 1].BC))
                    {
                        R += 2;
                    }
                    else
                    {
                        R++;
                    }
                    for (int i = 1; i < boundary.Count; i++)
                    {
                        if ((!AuxiliaryFunctions.Parallelism(boundary[i], boundary[i - 1])) && (boundary[i].BC != boundary[i - 1].BC))
                        {
                            R += 2;
                        }
                        else
                        {
                            R++;
                        }
                    }
                }

                nList = new BoundaryNode[R];
                int ctr = 0;
                foreach (Boundary boundary in boundaryList)
                {
                    bool isFirstDouble = false;
                    if ((!AuxiliaryFunctions.Parallelism(boundary[0], boundary[boundary.Count - 1])) &&
                        (boundary[0].BC != boundary[boundary.Count - 1].BC))
                    {
                        nList[ctr]    = new BoundaryNode(boundary[0], boundary[0].XP, 2, ctr);
                        isFirstDouble = true;
                    }
                    else
                    {
                        nList[ctr] = new BoundaryNode(boundary[0], boundary[0].XP, 1, ctr);
                    }
                    ctr++;
                    for (int i = 1; i < boundary.Count; i++)
                    {
                        if ((!AuxiliaryFunctions.Parallelism(boundary[i], boundary[i - 1])) && (boundary[i].BC != boundary[i - 1].BC))
                        {
                            nList[ctr] = new BoundaryNode(boundary[i - 1], boundary[i - 1].XK, 2, ctr);
                            ctr++;
                            nList[ctr] = new BoundaryNode(boundary[i], boundary[i].XP, 2, ctr);
                        }
                        else
                        {
                            nList[ctr] = new BoundaryNode(boundary[i], boundary[i].XP, 1, ctr);
                        }
                        ctr++;
                    }
                    if (isFirstDouble)
                    {
                        nList[ctr++] = new BoundaryNode(boundary[boundary.Count - 1], boundary[boundary.Count - 1].XK, 2, ctr - 1);
                    }
                }
                break;
            }

            case "Parabolic":
            {
                int R = 0;
                foreach (Boundary boundary in boundaryList)
                {
                    if ((!AuxiliaryFunctions.Parallelism(boundary[0], boundary[boundary.Count - 1])) &&
                        (boundary[0].BC != boundary[boundary.Count - 1].BC))
                    {
                        R += 2;
                    }
                    else
                    {
                        R++;
                    }
                    R++;
                    for (int i = 1; i < boundary.Count; i++)
                    {
                        if ((!AuxiliaryFunctions.Parallelism(boundary[i], boundary[i - 1])) && (boundary[i].BC != boundary[i - 1].BC))
                        {
                            R += 2;
                        }
                        else
                        {
                            R++;
                        }
                        R++;
                    }
                }

                nList = new BoundaryNode[R];

                int ctr = 0;
                foreach (Boundary boundary in boundaryList)
                {
                    bool isFirstDouble = false;
                    if ((!AuxiliaryFunctions.Parallelism(boundary[0], boundary[boundary.Count - 1])) &&
                        (boundary[0].BC != boundary[boundary.Count - 1].BC))
                    {
                        nList[ctr]    = new BoundaryNode(boundary[0], boundary[0].XP, 2, ctr);
                        isFirstDouble = true;
                    }
                    else
                    {
                        nList[ctr] = new BoundaryNode(boundary[0], boundary[0].XP, 1, ctr);
                    }
                    ctr++;
                    nList[ctr] = new BoundaryNode(boundary[0], boundary[0].Node[1], 3, ctr);
                    ctr++;
                    for (int i = 1; i < boundary.Count; i++)
                    {
                        if ((!AuxiliaryFunctions.Parallelism(boundary[i], boundary[i - 1])) && (boundary[i].BC != boundary[i - 1].BC))
                        {
                            nList[ctr] = new BoundaryNode(boundary[i - 1], boundary[i - 1].XK, 2, ctr);
                            ctr++;
                            nList[ctr] = new BoundaryNode(boundary[i], boundary[i].XP, 2, ctr);
                        }
                        else
                        {
                            nList[ctr] = new BoundaryNode(boundary[i], boundary[i].XP, 1, ctr);
                        }
                        ctr++;
                        nList[ctr] = new BoundaryNode(boundary[i], boundary[i].Node[1], 3, ctr);
                        ctr++;
                    }
                    if (isFirstDouble)
                    {
                        nList[ctr++] = new BoundaryNode(boundary[boundary.Count - 1], boundary[boundary.Count - 1].XK, 2, ctr - 1);
                    }
                }
                break;
            }

            default:
                throw new System.Exception("Niepoprawny rodzaj elementu w konstruktorze NodeList!!!");
            }
        }
コード例 #6
0
        public static void GetBoundaryConditions(string path, ref BoundaryList bList)   // Wczytuje warunki brzegowe
        {
            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);

            List <string>      nazwa    = new List <string>();
            List <double[]>    wartosc  = new List <double[]>();
            List <List <int> > elementy = new List <List <int> >();

            for (int i = 0; i < Lines.Length; i++)
            {
                if (Lines[i].IndexOf("# startBoundaryConditions") >= 0)
                {
                    i++;
                    while (Lines[i].IndexOf("# endBoundaryConditions") < 0)
                    {
                        if (Lines[i].IndexOf("Dirichlet") >= 0 && Lines[i].IndexOf("//") == -1)
                        {
                            nazwa.Add("Dirichlet");
                            double[] t = new double[1];
                            if (Lines[i].IndexOf("=") >= 0)
                            {
                                t[0] = Double.Parse(Lines[i].Substring(Lines[i].IndexOf("=") + 1));
                            }
                            wartosc.Add(t);
                            List <int>      ele        = new List <int>();
                            Regex           theReg     = new Regex(@"\d+");
                            MatchCollection theMatches = theReg.Matches(Lines[++i]);
                            foreach (Match theMach in theMatches)
                            {
                                ele.Add(int.Parse(theMach.ToString()) - 1);
                            }
                            elementy.Add(ele);
                        }
                        if (Lines[i].IndexOf("Neumann") >= 0 && Lines[i].IndexOf("//") == -1)
                        {
                            nazwa.Add("Neumann");
                            double[] q = new double[1];
                            q[0] = Double.Parse(Lines[i].Substring(Lines[i].IndexOf("=") + 1));
                            wartosc.Add(q);
                            List <int>      ele        = new List <int>();
                            Regex           theReg     = new Regex(@"\d+");
                            MatchCollection theMatches = theReg.Matches(Lines[++i]);
                            foreach (Match theMach in theMatches)
                            {
                                ele.Add(int.Parse(theMach.ToString()) - 1);
                            }
                            elementy.Add(ele);
                        }
                        if (Lines[i].IndexOf("Robin") >= 0 && Lines[i].IndexOf("//") == -1)
                        {
                            nazwa.Add("Robin");
                            double[] aTot = new double[2];
                            int      tmp1 = Lines[i].IndexOf("=");
                            int      tmp2 = Lines[i].IndexOf("T");
                            aTot[0] = Double.Parse(Lines[i].Substring(tmp1 + 1, tmp2 - tmp1 - 2));     // Pobiera wartość wsp. wnikania
                            aTot[1] = Double.Parse(Lines[i].Substring(Lines[i].LastIndexOf("=") + 1)); // Pobiera wartość wsp. wnikania
                            wartosc.Add(aTot);
                            List <int>      ele        = new List <int>();
                            Regex           theReg     = new Regex(@"\d+");
                            MatchCollection theMatches = theReg.Matches(Lines[++i]);
                            foreach (Match theMach in theMatches)
                            {
                                ele.Add(int.Parse(theMach.ToString()) - 1);
                            }
                            elementy.Add(ele);
                        }
                        if (++i >= Lines.Length)
                        {
                            break;
                        }
                    }
                }
            }


            int elemNo = 0;

            foreach (Boundary boundary in bList)
            {
                foreach (BoundaryElement bElement in boundary)
                {
                    for (int i = 0; i < elementy.Count; i++)
                    {
                        List <int> L = elementy[i];
                        for (int j = 0; j < L.Count; j++)
                        {
                            if (elemNo == L[j])
                            {
                                bElement.BC = nazwa[i];
                                if (nazwa[i] == "Dirichlet")
                                {
                                    bElement.T = wartosc[i][0];
                                }
                                if (nazwa[i] == "Neumann")
                                {
                                    bElement.Q = wartosc[i][0];
                                }
                                if (nazwa[i] == "Robin")
                                {
                                    bElement.A   = wartosc[i][0];
                                    bElement.Tot = wartosc[i][1];
                                }
                                break;
                            }
                        }
                    }
                    elemNo++;
                }
            }
        }
コード例 #7
0
        public static void GetGeometry(string path, ref BoundaryList bList) // Wczytuje geometrię obszaru
        {
            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++)   // Przechodzi przez wszystkie linie tekstu
            {
                if (Lines[i++].IndexOf("# startGeometry") >= 0)
                {
                    while (Lines[i].IndexOf("# endGeometry") < 0)
                    {
                        if (Lines[i].IndexOf("Brzeg") >= 0 && Lines[i].IndexOf("//") == -1)
                        {
                            Boundary boundary = new Boundary();
                            int      num      = 0;
                            int.TryParse(Lines[i].Substring(Lines[i].IndexOf("Brzeg") + 5), out num);
                            boundary.BoundaryNumber = num;
                            i++;
                            List <double> pointList = new List <double>();
                            while (Lines[i].IndexOf("Brzeg") < 0 && Lines[i].IndexOf("# endGeometry") < 0)
                            {
                                MatchCollection theMatches = new Regex(@"\S+").Matches(Lines[i]);
                                if (theMatches.Count == 2 && Lines[i].IndexOf("//") == -1)
                                {
                                    double x1, x2;
                                    Double.TryParse(theMatches[0].ToString(), out x1);
                                    Double.TryParse(theMatches[1].ToString(), out x2);
                                    pointList.Add(x1);
                                    pointList.Add(x2);
                                }
                                i++;
                                if (i >= Lines.Length || Lines[i].IndexOf("# endGeometry") >= 0 || Lines[i].IndexOf("Brzeg") >= 0)
                                {
                                    if (Lines[i].IndexOf("Brzeg") >= 0)
                                    {
                                        i--;
                                    }
                                    break;
                                }
                            }
                            for (int j = 0; j < pointList.Count - 2; j += 2)
                            {
                                boundary.Add(new BoundaryElement(pointList[j], pointList[j + 1], pointList[j + 2], pointList[j + 3]));
                                boundary[boundary.Count - 1].BoundaryID = boundary.BoundaryNumber;
                            }
                            pointList.Clear();
                            if (boundary.Count != 0)
                            {
                                bList.Add(boundary);
                            }
                        }
                        if (i >= Lines.Length || Lines[i].IndexOf("# endGeometry") >= 0)
                        {
                            break;
                        }
                        i++;
                    }
                }
            }
        }
コード例 #8
0
        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);
        }