示例#1
0
文件: Cgns.cs 项目: xyuan/BoSSS
            internal CGNSBase_t(CgnsDriver cg, int index_file, int index_base)
            {
                char[] basename = new char[1000];
                if (cg.base_read(index_file, index_base, basename, out CellDimension, out PhysicalDimension) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
                this.BaseName = basename.FromNullTermCharAry();

                int nzones;

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

                zones = new Zone_t[nzones];
                for (int index_zone = 1; index_zone <= nzones; index_zone++)
                {
                    ZoneType_t zone_type;
                    if (cg.zone_type(index_file, index_base, index_zone, out zone_type) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }

                    switch (zone_type)
                    {
                    case ZoneType_t.Unstructured: zones[index_zone - 1] = new UnstructuredZone_t(this, cg, index_file, index_base, index_zone); break;

                    default:
                        throw new NotImplementedException("Zone type " + zone_type + " not implemented for CGNS.");
                    }
                }
            }
示例#2
0
        private void ThrowError(String s, int index_file, CgnsDriver cg)
        {
            if (cg.close(index_file) != (int)Error.CG_OK)
            {
                s = s + " " + cg.get_error();
            }

            throw new ApplicationException(s);
        }
示例#3
0
文件: Cgns.cs 项目: xyuan/BoSSS
        /// <summary>
        /// reads the CGNS tree from a file
        /// </summary>
        public Cgns(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("Given grid file does not exist -- no import started.", filePath);
            }

            bool hdf5 = filePath.ToLowerInvariant().EndsWith(".hdf") || filePath.ToLowerInvariant().EndsWith(".hdf5");

            using (CgnsDriver cg = new CgnsDriver(hdf5)) {
                // open file
                int index_file = 1;
                if (cg.open(filePath.ToNullTermCharAry(), (int)Mode.MODE_READ, out index_file) != (int)Error.CG_OK)
                {
                    Console.WriteLine("Critical error opening cgns file -- application may be unrecoverable.");
                    Console.Out.Flush();
                    ThrowError(index_file, cg);
                }

                //try {

                // load all base-nodes
                int nbases;
                if (cg.nbases(index_file, out nbases) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }

                this.base_t = new CGNSBase_t[nbases];
                for (int i = 1; i <= nbases; i++)
                {
                    this.base_t[i - 1] = new CGNSBase_t(cg, index_file, i);
                }

                //} catch (Exception e) {
                //    throw e;
                //} finally {
                // close file
                if (cg.close(index_file) != (int)Error.CG_OK)
                {
                    ThrowError(cg);
                }
                //}
            }
        }
示例#4
0
文件: Cgns.cs 项目: xyuan/BoSSS
            internal Elements_t(Zone_t Owner, CgnsDriver cg, int index_file, int index_base, int index_zone, int index_section)
            {
                m_Owner = Owner;

                char[] secname = new char[1000];
                if (cg.section_read(index_file, index_base, index_zone, index_section, secname, out element_type, out start, out end, out nbndry, out parent_flag) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
                this.Name = secname.FromNullTermCharAry();

                ielem = new int[end - start + 1, element_type.NoOfNodes()];

                if (cg.elements_read2(index_file, index_base, index_zone, index_section, ielem, null) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
            }
示例#5
0
文件: Cgns.cs 项目: xyuan/BoSSS
            internal BC_t(Zone_t Owner, CgnsDriver cg, int index_file, int index_base, int index_zone, int index_bc)
            {
                m_Owner = Owner;

                char[] boconame = new char[1000];
                normal_index = new int[3];
                int        normal_list_flag, nbcelement, ndataset; // bc definition
                DataType_t data_type;

                if (cg.boco_info(index_file, index_base, index_zone, index_bc, boconame, out bc_type, out pointset_type, out nbcelement, normal_index, out normal_list_flag, out data_type, out ndataset) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
                Name = boconame.FromNullTermCharAry();

                bcelement = new int[nbcelement];
                if (cg.boco_read1(index_file, index_base, index_zone, index_bc, bcelement, null) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
            }
示例#6
0
文件: Cgns.cs 项目: xyuan/BoSSS
 static private void ThrowError(String s, int index_file, CgnsDriver cg)
 {
     throw new ApplicationException(s);
 }
示例#7
0
文件: Cgns.cs 项目: xyuan/BoSSS
        static private void ThrowError(int index_file, CgnsDriver cg)
        {
            String s = cg.get_error();

            throw new ApplicationException(s);
        }
示例#8
0
文件: Cgns.cs 项目: xyuan/BoSSS
 static private void ThrowError(CgnsDriver cg)
 {
     throw new ApplicationException(cg.get_error());
 }
示例#9
0
文件: Cgns.cs 项目: xyuan/BoSSS
            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);
                    }
                }
            }
示例#10
0
        /// <summary>
        /// loads an adf or hdf5 file from or to a specified path
        /// </summary>
        void Build(string filePath, bool hdf5)
        {
            using (CgnsDriver cg = new CgnsDriver(hdf5)) {
                int    index_file    = 0;
                int    index_base    = 0;
                int    index_zone    = 0;
                int    index_section = 0;
                int    index_bc      = 0;
                int    nbases;
                int    nzones;
                int    ncoords;
                int    nsections;
                int    nbocos;
                char[] basename   = new char[100];
                char[] zonename   = new char[100];
                char[] coordnameX = new char[100];
                char[] coordnameY = new char[100];
                char[] coordnameZ = new char[100];
                char[] flow       = new char[100];
                char[] secname    = new char[100];
                char[] boconame;
                char[] solname = new char[100];
                int[,] isize = new int[3, 3];
                int[,] ielem;
                int[]          irmin = new int[3];
                int[]          irmax = new int[3];
                int            celldim, physdim;                       // zone definition
                int            start, end, nbndry, parent_flag;        // element definition
                int            normal_list_flag, nbcelement, ndataset; // bc definition
                DataType_t     data_type;
                ElementType_t  element_type;
                ZoneType_t     zone_type;
                BCType_t       bc_type;
                GridLocation_t gridlocation_type;
                PointSetType_t pointset_type;

                index_file = index_base = 1;

                if (cg.open(filePath.ToNullTermCharAry(), (int)Mode.MODE_READ, out index_file) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
                if (cg.nbases(index_file, out nbases) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
                if (nbases != 1)
                {
                    ThrowError("Only one base allowed", index_file, cg);
                }
                if (cg.base_read(index_file, index_base, basename, out celldim, out physdim) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
                if (cg.nzones(index_file, index_base, out nzones) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }

                x_of_all_zones                  = new double[nzones][, , ];
                y_of_all_zones                  = new double[nzones][, , ];
                z_of_all_zones                  = new double[nzones][, , ];
                bcelements_of_all_zones         = new int[nzones][][][];
                normal_indices_of_all_zones     = new int[nzones][][][];
                starts_of_all_zones             = new int[nzones][];
                ends_of_all_zones               = new int[nzones][];
                nbndrys_of_all_zones            = new int[nzones][];
                pointset_types_of_all_zones     = new PointSetType_t[nzones][][];
                gridlocation_types_of_all_zones = new GridLocation_t[nzones][][];
                bc_types_of_all_zones           = new BCType_t[nzones][][];
                element_types_of_all_zones      = new ElementType_t[nzones][];
                elements_of_all_zones           = new int[nzones][][, ];
                boconames_of_all_zones          = new char[nzones][][][];
                zone_types_of_all_zones         = new ZoneType_t[nzones];

                for (index_zone = 1; index_zone <= nzones; index_zone++)
                {
                    int zone_offset = 0;

                    if (cg.zone_type(index_file, index_base, index_zone, out zone_type) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    zone_types_of_all_zones[index_zone - 1 - zone_offset] = zone_type;
                    if (cg.zone_read(index_file, index_base, index_zone, zonename, isize) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    if (cg.ncoords(index_file, index_base, index_zone, out ncoords) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    if (cg.coord_info(index_file, index_base, index_zone, 1, out data_type, coordnameX) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    if (cg.coord_info(index_file, index_base, index_zone, 2, out data_type, coordnameY) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    if (celldim > 2)
                    {
                        if (cg.coord_info(index_file, index_base, index_zone, 3, out data_type, coordnameZ) != (int)Error.CG_OK)
                        {
                            ThrowError(index_file, cg);
                        }
                    }

                    irmin[0] = 1;
                    irmin[1] = 1;
                    irmin[2] = 1;
                    irmax[0] = isize[0, 0];
                    irmax[1] = isize[0, 1];
                    irmax[2] = isize[0, 2];

                    double[, ,] x = null;
                    double[, ,] y = null;
                    double[, ,] z = null;

                    if ((int)zone_type == (int)ZoneType_t.Unstructured)
                    {
                        x = new double[isize[0, 0], 1, 1];
                        y = new double[isize[0, 0], 1, 1];
                        z = new double[isize[0, 0], 1, 1];
                    }
                    else
                    {
                        x = new double[isize[0, 2], isize[0, 1], isize[0, 0]];
                        y = new double[isize[0, 2], isize[0, 1], isize[0, 0]];
                        z = new double[isize[0, 2], isize[0, 1], isize[0, 0]];
                    }

                    char[][][]         boconames            = null;
                    char[][]           boconametemp         = null;
                    int[][][]          bcelements           = null;
                    int[][]            bcelementtemp        = null;
                    int[]              bcelement            = null;
                    int[][][]          normal_indices       = null;
                    int[][]            normal_indextemp     = null;
                    int[]              normal_index         = null;
                    int[]              starts               = null;
                    int[]              ends                 = null;
                    int[]              nbndrys              = null;
                    PointSetType_t[][] pointset_types       = null;
                    PointSetType_t[]   pointset_typtemp     = null;
                    GridLocation_t[][] gridlocation_types   = null;
                    GridLocation_t[]   gridlocation_typtemp = null;
                    BCType_t[][]       bc_types             = null;
                    BCType_t[]         bc_typtemp           = null;
                    ElementType_t[]    element_types        = null;
                    int[][,] elements = null;

                    if (cg.coord_read3(index_file, index_base, index_zone, coordnameX, data_type, irmin, irmax, x) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    if (cg.coord_read3(index_file, index_base, index_zone, coordnameY, data_type, irmin, irmax, y) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    if (celldim > 2)
                    {
                        if (cg.coord_read3(index_file, index_base, index_zone, coordnameZ, data_type, irmin, irmax, z) != (int)Error.CG_OK)
                        {
                            ThrowError(index_file, cg);
                        }
                    }
                    if (cg.nsections(index_file, index_base, index_zone, out nsections) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }

                    if ((int)zone_type == (int)ZoneType_t.Unstructured)
                    {
                        boconames          = new char[nsections][][];
                        bcelements         = new int[nsections][][];
                        normal_indices     = new int[nsections][][];
                        pointset_types     = new PointSetType_t[nsections][];
                        gridlocation_types = new GridLocation_t[nsections][];
                        bc_types           = new BCType_t[nsections][];
                        starts             = new int[nsections];
                        ends          = new int[nsections];
                        nbndrys       = new int[nsections];
                        element_types = new ElementType_t[nsections];
                        elements      = new int[nsections][, ];


                        //



                        for (index_section = 1; index_section <= nsections; index_section++)
                        {
                            if (cg.section_read(index_file, index_base, index_zone, index_section, secname, out element_type, out start, out end, out nbndry, out parent_flag) != (int)Error.CG_OK)
                            {
                                ThrowError(index_file, cg);
                            }

                            starts[index_section - 1]        = start;
                            ends[index_section - 1]          = end;
                            nbndrys[index_section - 1]       = nbndry;
                            element_types[index_section - 1] = element_type;

                            char[] c = element_type.ToString().ToNullTermCharAry();

                            ielem = new int[end - start + 1, c[c.Length - 1] - 48];

                            if (cg.elements_read2(index_file, index_base, index_zone, index_section, ielem, null) != (int)Error.CG_OK)
                            {
                                ThrowError(index_file, cg);
                            }

                            elements[index_section - 1] = ielem;

                            if (cg.nbocos(index_file, index_base, index_zone, out nbocos) != (int)Error.CG_OK)
                            {
                                ThrowError(index_file, cg);
                            }
                            boconametemp         = new char[nbocos][];
                            bcelementtemp        = new int[nbocos][];
                            normal_indextemp     = new int[nbocos][];
                            pointset_typtemp     = new PointSetType_t[nbocos];
                            gridlocation_typtemp = new GridLocation_t[nbocos];
                            bc_typtemp           = new BCType_t[nbocos];

                            int      depht  = 3;
                            char[]   label0 = "Zone_t".ToNullTermCharAry(), label1 = "ZoneBC_t".ToNullTermCharAry(), label2 = "BC_t".ToNullTermCharAry();
                            string[] labels = new string[depht];
                            labels[0] = new String(label0);
                            labels[1] = new String(label1);
                            labels[2] = new String(label2);

                            int[] num = new int[depht];

                            num[0] = index_zone;
                            num[1] = 1;
                            for (index_bc = 1; index_bc <= nbocos; index_bc++)
                            {
                                boconame     = new char[100];
                                normal_index = new int[3];
                                if (cg.boco_info(index_file, index_base, index_zone, index_bc, boconame, out bc_type, out pointset_type, out nbcelement, normal_index, out normal_list_flag, out data_type, out ndataset) != (int)Error.CG_OK)
                                {
                                    ThrowError(index_file, cg);
                                }
                                bcelement = new int[nbcelement];
                                if (cg.boco_read1(index_file, index_base, index_zone, index_bc, bcelement, null) != (int)Error.CG_OK)
                                {
                                    ThrowError(index_file, cg);
                                }
                                num[2] = index_bc;
                                if (pointset_type.Equals(PointSetType_t.ElementList) || pointset_type.Equals(PointSetType_t.ElementRange))
                                {
                                    gridlocation_type = GridLocation_t.FaceCenter;
                                }
                                else
                                {
                                    if (cg.golist(index_file, index_base, depht, labels, num) != (int)Error.CG_OK)
                                    {
                                        ThrowError(index_file, cg);
                                    }
                                    if (cg.gridlocation_read(out gridlocation_type) != (int)Error.CG_OK)
                                    {
                                        ThrowError(index_file, cg);
                                    }
                                }
                                boconametemp[index_bc - 1]         = boconame;
                                bcelementtemp[index_bc - 1]        = bcelement;
                                normal_indextemp[index_bc - 1]     = normal_index;
                                pointset_typtemp[index_bc - 1]     = pointset_type;
                                bc_typtemp[index_bc - 1]           = bc_type;
                                gridlocation_typtemp[index_bc - 1] = gridlocation_type;
                            }
                            boconames[index_section - 1]          = boconametemp;
                            bcelements[index_section - 1]         = bcelementtemp;
                            normal_indices[index_section - 1]     = normal_indextemp;
                            pointset_types[index_section - 1]     = pointset_typtemp;
                            bc_types[index_section - 1]           = bc_typtemp;
                            gridlocation_types[index_section - 1] = gridlocation_typtemp;
                        }
                    }
                    else
                    {
                        need_struct_conversion = true;
                        // insert here ...
                    }
                    x_of_all_zones[index_zone - 1 - zone_offset]                  = x;
                    y_of_all_zones[index_zone - 1 - zone_offset]                  = y;
                    z_of_all_zones[index_zone - 1 - zone_offset]                  = z;
                    bcelements_of_all_zones[index_zone - 1 - zone_offset]         = bcelements;
                    normal_indices_of_all_zones[index_zone - 1 - zone_offset]     = normal_indices;
                    starts_of_all_zones[index_zone - 1 - zone_offset]             = starts;
                    ends_of_all_zones[index_zone - 1 - zone_offset]               = ends;
                    nbndrys_of_all_zones[index_zone - 1 - zone_offset]            = nbndrys;
                    pointset_types_of_all_zones[index_zone - 1 - zone_offset]     = pointset_types;
                    bc_types_of_all_zones[index_zone - 1 - zone_offset]           = bc_types;
                    element_types_of_all_zones[index_zone - 1 - zone_offset]      = element_types;
                    elements_of_all_zones[index_zone - 1 - zone_offset]           = elements;
                    boconames_of_all_zones[index_zone - 1 - zone_offset]          = boconames;
                    gridlocation_types_of_all_zones[index_zone - 1 - zone_offset] = gridlocation_types;
                }
                if (cg.close(index_file) != (int)Error.CG_OK)
                {
                    ThrowError(cg);
                }
            }
        }
示例#11
0
文件: CgnsFile.cs 项目: xyuan/BoSSS
        /// <summary>
        /// loads or saves an adf or hdf5 file from or to a specified path
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="hdf5"></param>
        public CgnsFile(string filePath, bool hdf5)
        {
            using (CgnsDriver cg = new CgnsDriver(hdf5)) {
                int index_file = 0;
                int index_base = 0;
                int index_zone = 0;
                //int index_section = 0;
                //int index_bc = 0;
                int nbases;
                int nzones;
                //int ncoords;
                //int nsections;
                //int nbocos;
                char[] basename = new char[100];
                //char[] zonename = new char[100];
                //char[] coordnameX = new char[100];
                //char[] coordnameY = new char[100];
                //char[] coordnameZ = new char[100];
                //char[] flow = new char[100];
                //char[] secname = new char[100];
                //char[] boconame;
                //char[] solname = new char[100];
                //int[,] isize = new int[3, 3];
                //int[,] ielem;
                //int[] irmin = new int[3];
                //int[] irmax = new int[3];
                // zone definition
                //int start, end, nbndry, parent_flag; // element definition
                //int normal_list_flag, nbcelement, ndataset; // bc definition
                //DataType_t data_type;
                //ElementType_t element_type;
                //ZoneType_t zone_type;
                //BCType_t bc_type;
                //GridLocation_t gridlocation_type;
                //PointSetType_t pointset_type;

                index_file = index_base = 1;

                if (cg.open(filePath.ToNullTermCharAry(), (int)Mode.MODE_READ, out index_file) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
                if (cg.nbases(index_file, out nbases) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
                if (nbases != 1)
                {
                    ThrowError("Only one base allowed", index_file, cg);
                }
                if (cg.base_read(index_file, index_base, basename, out celldim, out physdim) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }
                if (cg.nzones(index_file, index_base, out nzones) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }

                //x_of_all_zones = new double[nzones][, ,];
                //y_of_all_zones = new double[nzones][, ,];
                //z_of_all_zones = new double[nzones][, ,];
                //bcelements_of_all_zones = new int[nzones][][][];
                //normal_indices_of_all_zones = new int[nzones][][][];
                //starts_of_all_zones = new int[nzones][];
                //ends_of_all_zones = new int[nzones][];
                //nbndrys_of_all_zones = new int[nzones][];
                //pointset_types_of_all_zones = new PointSetType_t[nzones][][];
                //gridlocation_types_of_all_zones = new GridLocation_t[nzones][][];
                //bc_types_of_all_zones = new BCType_t[nzones][][];
                //element_types_of_all_zones = new ElementType_t[nzones][];
                //elements_of_all_zones = new int[nzones][][,];
                //boconames_of_all_zones = new char[nzones][][][];
                //zone_types_of_all_zones = new ZoneType_t[nzones];


                for (index_zone = 1; index_zone <= nzones; index_zone++)
                {
                    this.Zones.Add(new CgnsZone(this, index_file, index_base, index_zone, cg));
                }


                if (cg.close(index_file) != (int)Error.CG_OK)
                {
                    ThrowError(cg);
                }
            }
        }
示例#12
0
文件: CgnsFile.cs 项目: xyuan/BoSSS
            internal CgnsZone(CgnsFile owna, int index_file, int index_base, int index_zone, CgnsDriver cg)
            {
                owner = owna;
                int index_section = 0;
                int index_bc      = 0;
                int ncoords;
                int nsections;
                int nbocos;

                char[] basename   = new char[100];
                char[] zonename   = new char[100];
                char[] coordnameX = new char[100];
                char[] coordnameY = new char[100];
                char[] coordnameZ = new char[100];
                char[] flow       = new char[100];
                char[] secname    = new char[100];
                char[] boconame;
                char[] solname = new char[100];
                int[,] isize = new int[3, 3];
                int[,] ielem;
                int[]         irmin = new int[3];
                int[]         irmax = new int[3];
                int           start, end, nbndry, parent_flag;        // element definition
                int           normal_list_flag, nbcelement, ndataset; // bc definition
                DataType_t    data_type;
                ElementType_t element_type;

                BCType_t       bc_type;
                GridLocation_t gridlocation_type;
                PointSetType_t pointset_type;

                //index_zone = 4; int zone_offset = index_zone - 1;
                //{

                if (cg.zone_type(index_file, index_base, index_zone, out zone_type) != (int)Error.CG_OK)
                {
                    owner.ThrowError(index_file, cg);
                }
                //zone_types_of_all_zones[index_zone - 1 - zone_offset] = zone_type;
                if (cg.zone_read(index_file, index_base, index_zone, zonename, isize) != (int)Error.CG_OK)
                {
                    owner.ThrowError(index_file, cg);
                }
                if (cg.ncoords(index_file, index_base, index_zone, out ncoords) != (int)Error.CG_OK)
                {
                    owner.ThrowError(index_file, cg);
                }
                if (cg.coord_info(index_file, index_base, index_zone, 1, out data_type, coordnameX) != (int)Error.CG_OK)
                {
                    owner.ThrowError(index_file, cg);
                }
                if (cg.coord_info(index_file, index_base, index_zone, 2, out data_type, coordnameY) != (int)Error.CG_OK)
                {
                    owner.ThrowError(index_file, cg);
                }
                if (owner.celldim > 2)
                {
                    if (cg.coord_info(index_file, index_base, index_zone, 3, out data_type, coordnameZ) != (int)Error.CG_OK)
                    {
                        owner.ThrowError(index_file, cg);
                    }
                }

                irmin[0] = 1;
                irmin[1] = 1;
                irmin[2] = 1;
                irmax[0] = isize[0, 0];
                irmax[1] = isize[0, 1];
                irmax[2] = isize[0, 2];



                if ((int)zone_type == (int)ZoneType_t.Unstructured)
                {
                    x = new double[isize[0, 0], 1, 1];
                    y = new double[isize[0, 0], 1, 1];
                    z = new double[isize[0, 0], 1, 1];
                }
                else
                {
                    x = new double[isize[0, 2], isize[0, 1], isize[0, 0]];
                    y = new double[isize[0, 2], isize[0, 1], isize[0, 0]];
                    z = new double[isize[0, 2], isize[0, 1], isize[0, 0]];
                }

                char[][]         boconametemp         = null;
                int[][]          bcelementtemp        = null;
                int[]            bcelement            = null;
                int[][]          normal_indextemp     = null;
                int[]            normal_index         = null;
                PointSetType_t[] pointset_typtemp     = null;
                GridLocation_t[] gridlocation_typtemp = null;
                BCType_t[]       bc_typtemp           = null;


                // read coordinates of this zone
                // =============================

                // x - coordinates
                if (cg.coord_read3(index_file, index_base, index_zone, coordnameX, data_type, irmin, irmax, x) != (int)Error.CG_OK)
                {
                    owner.ThrowError(index_file, cg);
                }

                // y - coordinates
                if (cg.coord_read3(index_file, index_base, index_zone, coordnameY, data_type, irmin, irmax, y) != (int)Error.CG_OK)
                {
                    owner.ThrowError(index_file, cg);
                }

                // optionally, if running in 3D, z - coordinates
                if (owner.celldim > 2)
                {
                    if (cg.coord_read3(index_file, index_base, index_zone, coordnameZ, data_type, irmin, irmax, z) != (int)Error.CG_OK)
                    {
                        owner.ThrowError(index_file, cg);
                    }
                }
                if (cg.nsections(index_file, index_base, index_zone, out nsections) != (int)Error.CG_OK)
                {
                    owner.ThrowError(index_file, cg);
                }

                if ((int)zone_type == (int)ZoneType_t.Unstructured)
                {
                    //{
                    //    // fk test anfang
                    //    int nBoco = -1;
                    //    cg.nbocos(index_file, index_base, index_zone, out nBoco);

                    //    for (int iBoco = 1; iBoco <= nBoco; iBoco++) {
                    //        char[] _Boconame = new char[1000];
                    //        BCType_t BocoType;
                    //        PointSetType_t BocoPointsetType;
                    //        int nPnts;
                    //        int[] NormalIndex = new int[666]; ArrayTools.Set(NormalIndex, -666);
                    //        int NormalListFlag;
                    //        DataType_t NormalDataType;
                    //        int _ndataset;
                    //        cg.boco_info(index_file, index_base, index_zone, iBoco, _Boconame, out BocoType, out BocoPointsetType, out nPnts, NormalIndex,
                    //            out NormalListFlag, out NormalDataType, out _ndataset);

                    //        //string sBocoName = new string(_Boconame,);


                    //        Console.WriteLine();
                    //    }

                    //    // fk test ende
                    //}


                    boconames          = new char[nsections][][];
                    bcelements         = new int[nsections][][];
                    normal_indices     = new int[nsections][][];
                    pointset_types     = new PointSetType_t[nsections][];
                    gridlocation_types = new GridLocation_t[nsections][];
                    bc_types           = new BCType_t[nsections][];
                    starts             = new int[nsections];
                    ends          = new int[nsections];
                    nbndrys       = new int[nsections];
                    element_types = new ElementType_t[nsections];
                    elements      = new int[nsections][, ];


                    //



                    // Original Scheerer for reading bc
                    for (index_section = 1; index_section <= nsections; index_section++)
                    {
                        if (cg.section_read(index_file, index_base, index_zone, index_section, secname, out element_type, out start, out end, out nbndry, out parent_flag) != (int)Error.CG_OK)
                        {
                            owner.ThrowError(index_file, cg);
                        }

                        starts[index_section - 1]        = start;
                        ends[index_section - 1]          = end;
                        nbndrys[index_section - 1]       = nbndry;
                        element_types[index_section - 1] = element_type;

                        char[] c = element_type.ToString().ToNullTermCharAry();

                        ielem = new int[end - start + 1, c[c.Length - 2] - 48];

                        if (cg.elements_read2(index_file, index_base, index_zone, index_section, ielem, null) != (int)Error.CG_OK)
                        {
                            owner.ThrowError(index_file, cg);
                        }

                        elements[index_section - 1] = ielem;

                        if (cg.nbocos(index_file, index_base, index_zone, out nbocos) != (int)Error.CG_OK)
                        {
                            owner.ThrowError(index_file, cg);
                        }
                        boconametemp         = new char[nbocos][];
                        bcelementtemp        = new int[nbocos][];
                        normal_indextemp     = new int[nbocos][];
                        pointset_typtemp     = new PointSetType_t[nbocos];
                        gridlocation_typtemp = new GridLocation_t[nbocos];
                        bc_typtemp           = new BCType_t[nbocos];

                        int      depht  = 3;
                        char[]   label0 = "Zone_t".ToNullTermCharAry(), label1 = "ZoneBC_t".ToNullTermCharAry(), label2 = "BC_t".ToNullTermCharAry();
                        string[] labels = new string[depht];
                        labels[0] = new String(label0);
                        labels[1] = new String(label1);
                        labels[2] = new String(label2);

                        int[] num = new int[depht];

                        num[0] = index_zone;
                        num[1] = 1;
                        for (index_bc = 1; index_bc <= nbocos; index_bc++)
                        {
                            boconame     = new char[100];
                            normal_index = new int[3];
                            if (cg.boco_info(index_file, index_base, index_zone, index_bc, boconame, out bc_type, out pointset_type, out nbcelement, normal_index, out normal_list_flag, out data_type, out ndataset) != (int)Error.CG_OK)
                            {
                                owner.ThrowError(index_file, cg);
                            }
                            bcelement = new int[nbcelement];
                            if (cg.boco_read1(index_file, index_base, index_zone, index_bc, bcelement, null) != (int)Error.CG_OK)
                            {
                                owner.ThrowError(index_file, cg);
                            }
                            num[2] = index_bc;
                            if (pointset_type.Equals(PointSetType_t.ElementList) || pointset_type.Equals(PointSetType_t.ElementRange))
                            {
                                gridlocation_type = GridLocation_t.FaceCenter;
                            }
                            else
                            {
                                if (cg.golist(index_file, index_base, depht, labels, num) != (int)Error.CG_OK)
                                {
                                    owner.ThrowError(index_file, cg);
                                }
                                if (cg.gridlocation_read(out gridlocation_type) != (int)Error.CG_OK)
                                {
                                    owner.ThrowError(index_file, cg);
                                }
                            }
                            boconametemp[index_bc - 1]         = boconame;
                            bcelementtemp[index_bc - 1]        = bcelement;
                            normal_indextemp[index_bc - 1]     = normal_index;
                            pointset_typtemp[index_bc - 1]     = pointset_type;
                            bc_typtemp[index_bc - 1]           = bc_type;
                            gridlocation_typtemp[index_bc - 1] = gridlocation_type;
                        }
                        boconames[index_section - 1]          = boconametemp;
                        bcelements[index_section - 1]         = bcelementtemp;
                        normal_indices[index_section - 1]     = normal_indextemp;
                        pointset_types[index_section - 1]     = pointset_typtemp;
                        bc_types[index_section - 1]           = bc_typtemp;
                        gridlocation_types[index_section - 1] = gridlocation_typtemp;
                    }
                }
                else
                {
                    //need_struct_conversion = true;
                    // insert here ...

                    throw new NotImplementedException("no structured CGNS grids supported until now");
                }



                //bcelements_of_all_zones[index_zone - 1 - zone_offset] = bcelements;
                //normal_indices_of_all_zones[index_zone - 1 - zone_offset] = normal_indices;
                //starts_of_all_zones[index_zone - 1 - zone_offset] = starts;
                //ends_of_all_zones[index_zone - 1 - zone_offset] = ends;
                //nbndrys_of_all_zones[index_zone - 1 - zone_offset] = nbndrys;
                //pointset_types_of_all_zones[index_zone - 1 - zone_offset] = pointset_types;
                //bc_types_of_all_zones[index_zone - 1 - zone_offset] = bc_types;
                //element_types_of_all_zones[index_zone - 1 - zone_offset] = element_types;
                //elements_of_all_zones[index_zone - 1 - zone_offset] = elements;
                //boconames_of_all_zones[index_zone - 1 - zone_offset] = boconames;
                //gridlocation_types_of_all_zones[index_zone - 1 - zone_offset] = gridlocation_types;
            }