Ejemplo n.º 1
0
        public bool Create(string filename_)
        {
            double[,] points = null;
            double[,] polys  = null;
            double[,] bound  = null;


            Dictionary <string, Face> facedic = new Dictionary <string, Face>();


            if (!LoadFromFile(filename_, ref points, ref polys, ref bound))
            {
                return(false);
            }
            count = 0;
            SetParameters();
            elementcount = polys.GetLength(1);
            int vertexcount = polys.GetLength(0) - 1;

            elements = new Element[elementcount];

            int faceid = 0;
            int e      = 0;

            for (e = 0; e < elementcount; e++)
            {
                Element elem;
                elements[e] = new Element(vertexcount);
                elem        = elements[e]; elem.id = e; elem.k = 1;
                Vector2[] vertex = new Vector2[vertexcount];
                for (int v = 0; v < vertexcount; v++)
                {
                    int pointindex = (int)polys[v, e];
                    vertex[v] = new Vector2(points[0, pointindex], points[1, pointindex]);
                    int p1index = pointindex;
                    int p2index = 0;
                    if (v < vertexcount - 1)
                    {
                        p2index = (int)polys[v + 1, e];
                    }
                    else
                    {
                        p2index = (int)polys[0, e];
                    }
                    int    p1      = p1index;
                    int    p2      = p2index;
                    string facestr = Face.GetFaceStrId(p1index, p2index);
                    if (!facedic.ContainsKey(facestr))
                    {
                        Face face = new Face(new Vector2(points[0, p1], points[1, p1]), new Vector2(points[0, p2], points[1, p2]));
                        face.id       = faceid;
                        face.pointid1 = p1;
                        face.pointid2 = p2;
                        face.owner    = elem;
                        faceid++;
                        facedic.Add(facestr, face);
                        elem.faces[v] = face;
                    }
                    else
                    {
                        Face face = facedic[facestr];
                        face.nbelem   = elem;
                        elem.faces[v] = face;
                        Element owner = face.owner;
                        elem.nbs[v] = owner;
                        owner.nbs[owner.FaceLocalId(face)] = elem;
                    }
                }
                elem.SetPolygon(vertex);
                elem.PreCalc();
            }

            faces    = new Face[facedic.Count];
            bndfaces = new Face[bound.GetLength(1)];

            foreach (var pair in facedic)
            {
                Face face = pair.Value;
                faces[face.id] = face;
            }

            for (e = 0; e < elementcount; e++)
            {
                elements[e].Calc();
            }

            int f;

            for (f = 0; f < bound.GetLength(1); f++)
            {
                string facestr = Face.GetFaceStrId((int)bound[0, f], (int)bound[1, f]);
                Face   face    = facedic[facestr];
                face.bnddomain  = (int)bound[5, f];
                face.bndgroup   = (int)bound[4, f];
                face.isboundary = true;
                bndfaces[f]     = face;
            }

            SetInitialBoundary();

            //for (e = 0; e < elementcount; e++)
            //    elements[e].CalcFluxes();


            return(true);
        }