Beispiel #1
0
            internal UnstructuredZone_t(CGNSBase_t owner, CgnsDriver cg, int index_file, int index_base, int index_zone)
            {
                m_owner = owner;

                // general info about the zone
                // ===========================
                {
                    char[] zonename = new char[1000];
                    if (cg.zone_read(index_file, index_base, index_zone, zonename, isize) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    ZoneName = zonename.FromNullTermCharAry();

                    if (cg.zone_type(index_file, index_base, index_zone, out zone_type) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    if (this.zone_type != ZoneType_t.Unstructured)
                    {
                        throw new NotSupportedException("supporting only unstructured grids");
                    }

                    if (cg.ncoords(index_file, index_base, index_zone, out ncoords) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                }

                // x,y, and z - Nodes
                // ==================
                {
                    int D = m_owner.CellDimension;

                    coordname = new string[3];
                    data_type = new DataType_t[3];

                    for (int d = 0; d < 3; d++)
                    {
                        char[] _coordname = new char[1000];
                        if (cg.coord_info(index_file, index_base, index_zone, d + 1, out data_type[d], _coordname) != (int)Error.CG_OK)
                        {
                            ThrowError(index_file, cg);
                        }
                        coordname[d] = _coordname.FromNullTermCharAry();
                    }

                    coord = new double[3][];
                    for (int d = 0; d < 3; d++)
                    {
                        if (data_type[d] != DataType_t.RealDouble)
                        {
                            throw new NotSupportedException();
                        }

                        coord[d] = new double[isize[0, 0]];

                        int[] irmin = new int[] { 1 };
                        int[] irmax = new int[] { coord[d].Length };

                        if (cg.coord_read1(index_file, index_base, index_zone, coordname[d].ToNullTermCharAry(), data_type[d], irmin, irmax, coord[d]) != (int)Error.CG_OK)
                        {
                            ThrowError(index_file, cg);
                        }
                    }
                    if (D < 3)
                    {
                        double[] coordNorm = coord.Select(coord_d => coord_d.L2Norm()).ToArray();

                        int SkipDimFound = 0;
                        for (int d = 0; d < 3; d++)
                        {
                            if (coordNorm[d] == 0)
                            {
                                SkipDimFound++;

                                ArrayTools.RemoveAt(ref coordname, d);
                                ArrayTools.RemoveAt(ref data_type, d);
                                ArrayTools.RemoveAt(ref coord, d);
                            }
                        }

                        if ((SkipDimFound + D) != 3)
                        {
                            throw new ArgumentException("CGNS node index out of range.");
                        }
                    }
                }

                // sections
                // ========

                {
                    int nsections;
                    if (cg.nsections(index_file, index_base, index_zone, out nsections) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }

                    elements = new Elements_t[nsections];
                    for (int index_section = 1; index_section <= nsections; index_section++)
                    {
                        elements[index_section - 1] = new Elements_t(this, cg, index_file, index_base, index_zone, index_section);
                    }
                }

                // boundary conditions
                // ===================
                {
                    int nbocos;
                    if (cg.nbocos(index_file, index_base, index_zone, out nbocos) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }

                    bcs = new BC_t[nbocos];
                    for (int index_bc = 1; index_bc <= nbocos; index_bc++)
                    {
                        bcs[index_bc - 1] = new BC_t(this, cg, index_file, index_base, index_zone, index_bc);
                    }
                }
            }