IndexOf() public method

I,J,K 必须>=1,将I,JK,转化为从I方向J,K顺序描述的数组坐标,即网格索引坐标, I,J,K分别为x,y,z方向上的网格坐标
public IndexOf ( int i, int j, int k ) : int
i int
j int
k int
return int
Beispiel #1
0
 /// <summary>
 /// 求出网格索引位置
 /// </summary>
 /// <param name="I">网格坐标 I方向,1起始</param>
 /// <param name="J">网格坐标 J方向,1起始</param>
 /// <param name="K">网格坐标 K方向,1起始</param>
 /// <returns></returns>
 protected int GridIndexOf(int I, int J, int K)
 {
     return(gridIndexer.IndexOf(I, J, K));
 }
        /// <summary>
        /// 初始化网格坐标
        /// </summary>
        protected override void InitGridCoordinates()
        {
            if (this.TOPS == null)
            {
                this.TOPS = ArrayHelper.NewFloatArray(this.DimenSize, 0);
            }
            //xcoords;
            int coordSize = (this.NX + 1) * (this.NY + 1) * (this.NZ + 1);
            float[] coordX = new float[coordSize];
            float[] coordY = new float[coordSize];
            float[] coordZ = new float[coordSize];

            float[] srcDX = this.DX;
            float[] srcDY = this.DY;
            float[] srcDZ = this.DZ;
            float[] tops = this.TOPS;

            int cnx = this.NX + 1;
            int cny = this.NY + 1;
            int cnz = this.NZ + 1;

            int dnx = this.NX;
            int dny = this.NY;
            int dnz = this.NZ;

            GridIndexer coordIndexer = new GridIndexer(cnx, cny, cnz);
            //dx, dy,dx 描述
            GridIndexer dIndexer = new GridIndexer(this.NX, this.NY, this.NZ);

            int coordIndex;
            int prevcIndex;
            int di, dj, dk, xGridIndex, yGridIndex, zGridIndex;
            for (int kcz = 1; kcz <= cnz; kcz++)
            {
                for (int jcy = 1; jcy <= cny; jcy++)
                {
                    for (int icx = 1; icx <= cnx; icx++)
                    {
                        coordIndex = coordIndexer.IndexOf(icx, jcy, kcz);

                        //处理x坐标
                        if (icx == 1)
                        {
                            coordX[coordIndex] = this.OX;
                        }
                        else
                        {
                            prevcIndex = coordIndexer.IndexOf(icx - 1, jcy, kcz);
                            //距离坐标
                            di = icx - 1;
                            dj = jcy > dny ? jcy - 1 : jcy;
                            dk = kcz > dnz ? kcz - 1 : kcz;
                            xGridIndex = dIndexer.IndexOf(di, dj, dk);
                            coordX[coordIndex] = coordX[prevcIndex] + srcDX[xGridIndex];
                        }

                        //计算(icx,jcy,kcz)网格的坐标
                        if (jcy == 1)
                        {
                            coordY[coordIndex] = this.OY;
                        }
                        else
                        {
                            prevcIndex = coordIndexer.IndexOf(icx, jcy - 1, kcz);
                            di = icx > dnx ? icx - 1 : icx;
                            dj = jcy - 1;
                            dk = kcz > dnz ? kcz - 1 : kcz;
                            yGridIndex = dIndexer.IndexOf(di, dj, dk);
                            coordY[coordIndex] = coordY[prevcIndex] + srcDY[yGridIndex];
                        }

                        if (kcz == 1)
                        {
                            int celli = icx > this.NX ? this.NX : icx;
                            int cellj = jcy > this.NY ? this.NY : jcy;
                            int cellk = kcz > this.NZ ? this.NZ : kcz;
                            int cellIndex = dIndexer.IndexOf(celli, cellj, cellk);
                            float topz = tops[cellIndex];
                            coordZ[coordIndex] = this.OZ + topz;
                        }
                        else
                        {
                            prevcIndex = coordIndexer.IndexOf(icx, jcy, kcz - 1);
                            di = icx > dnx ? dnx : icx;
                            dj = jcy > dny ? dny : jcy;
                            dk = kcz - 1;
                            zGridIndex = dIndexer.IndexOf(di, dj, dk);
                            coordZ[coordIndex] = coordZ[prevcIndex] + srcDZ[zGridIndex];
                        }
                    }
                }
            }
            this.xcoords = coordX;
            this.ycoords = coordY;
            this.zcoords = coordZ;
            this.coordIndexer = coordIndexer;
        }