Example #1
0
        /// <summary>
        /// conversion of framed index (index into this object) to full index (object which is framed).
        /// </summary>
        /// <param name="iFrame">
        /// a global index
        /// </param>
        public int Frame2Full(int iFrame)
        {
            if (FrameMap.IsInLocalRange(iFrame))
            {
                int iLoc = FrameMap.TransformIndexToLocal(iFrame);
                return(Frame2Full_Lookup[iLoc]);
            }
            else
            {
                if (!m_supportExternal)
                {
                    throw new IndexOutOfRangeException();
                }
                else
                {
                    /*
                     * int TT = ExtRangeStart.Length;
                     * Debug.Assert(ExtRangeLen.Length == TT);
                     * Debug.Assert(ExtRangeTrafo.Length == TT);
                     *
                     * for (int tt = 0; tt < TT; tt++) { // since the number of 'peer processes' is usually low, this loop should not harm to much
                     *  int iX = iFrame - ExtRangeStart[tt];
                     *  if (iX >= 0 && iX < ExtRangeLen[tt]) {
                     *      return ExtRangeTrafo[tt][iX];
                     *  }
                     * }
                     * throw new IndexOutOfRangeException();
                     */
                    var Parallel = this.FrameMap.GridDat.iParallel;

                    int N_frame = FrameMap.MaxTotalNoOfCoordinatesPerCell;
                    int N_full  = FullMap.MaxTotalNoOfCoordinatesPerCell;


                    int jCellGlob = iFrame / N_frame;
                    int jCellLoc, iSpc;
                    if (m_Last_jCellGlob != jCellGlob)
                    {
                        jCellLoc         = Parallel.Global2LocalIdx[jCellGlob];
                        iSpc             = m_Regions.GetSpeciesIndex(this.m_spcId, jCellLoc);
                        m_Last_jCellGlob = jCellGlob;
                        m_Last_jCellLoc  = jCellLoc;
                        m_Last_iSpc      = iSpc;
                    }
                    else
                    {
                        jCellLoc = m_Last_jCellLoc;
                        iSpc     = m_Last_iSpc;
                    }

                    int n_frame = iFrame - N_frame * (jCellGlob);
                    int n_full  = this.IndexTrafoWithinCell[iSpc, n_frame];

                    return(jCellGlob * N_full + n_full);
                }
            }
        }
Example #2
0
        void Setup_Frame2Full()
        {
            //if (FrameMap.Rank == 0)
            //    Debugger.Launch();
            //csMPI.Raw.Barrier(csMPI.Raw._COMM.WORLD);
            //FrameMap.GridDat.Cells.NoOfLocalUpdatedCells


            int L = FrameMap.LocalLength;

            Frame2Full_Lookup = new int[L];


            Basis[]    BasisS  = FullMap.BasisS.ToArray();
            XDGBasis[] XBasisS = new XDGBasis[BasisS.Length];
            for (int i = 0; i < BasisS.Length; i++)
            {
                XBasisS[i] = BasisS[i] as XDGBasis;
            }



            var GridDat = this.FullMap.GridDat;

            Frame2Full_Lookup = new int[L];
            Frame2Full_Lookup.SetAll(int.MinValue);
            int Jup  = FrameMap.GridDat.iLogicalCells.NoOfLocalUpdatedCells;
            int Jtot = FrameMap.GridDat.iLogicalCells.Count;
            int G    = BasisS.Length;

            for (int j = 0; j < Jup; j++)   // loop over all cells ...
            {
                int NoOfSpc = m_Regions.GetNoOfSpecies(j);
                int iSpc    = m_Regions.GetSpeciesIndex(m_spcId, j);

                for (int g = 0; g < G; g++)   // loop over all basises
                {
                    Basis    b             = BasisS[g];
                    XDGBasis xb            = XBasisS[g];
                    bool     b_is_XDGbasis = (xb != null);

                    int n0, N;
                    if (b_is_XDGbasis)
                    {
                        if (iSpc < 0)
                        {
                            n0 = int.MaxValue;
                            N  = int.MinValue;
                        }
                        else
                        {
                            N  = xb.DOFperSpeciesPerCell;
                            n0 = N * iSpc;
                        }
                    }
                    else
                    {
                        n0 = 0;
                        N  = b.GetLength(j);
                    }

                    if (N >= 0)
                    {
                        int iFull = (int)FullMap.GlobalUniqueCoordinateIndex(g, j, n0);
                        int iLoc  = FrameMap.LocalUniqueCoordinateIndex(g, j, 0);

                        for (int n = 0; n < N; n++)
                        {
                            Frame2Full_Lookup[iLoc + n] = iFull + n;
                            Debug.Assert(Frame2Full_Lookup[iLoc + n] < 0 || FullMap.IsInLocalRange(Frame2Full_Lookup[iLoc + n]));
                        }
                    }
                }
            }

#if DEBUG
            var _Frame2Full_Lookup = new int[L];
            for (int iLoc = 0; iLoc < L; iLoc++)   // loop over all indices of the frame...
            {
                int j, g, n;
                FrameMap.LocalFieldCoordinateIndex(iLoc, out g, out j, out n);

                int      NoOfSpc       = m_Regions.GetNoOfSpecies(j);
                Basis    b             = BasisS[g];
                XDGBasis xb            = XBasisS[g];
                bool     b_is_XDGbasis = (xb != null);
                int      iSpc          = m_Regions.GetSpeciesIndex(m_spcId, j);

                if (b_is_XDGbasis)
                {
                    if (iSpc < 0)
                    {
                        _Frame2Full_Lookup[iLoc] = int.MinValue;
                    }
                    else
                    {
                        int Nsep = xb.DOFperSpeciesPerCell;
                        _Frame2Full_Lookup[iLoc] = (int)(FullMap.GlobalUniqueCoordinateIndex(g, j, iSpc * Nsep + n));
                    }
                }
                else
                {
                    _Frame2Full_Lookup[iLoc] = (int)(FullMap.GlobalUniqueCoordinateIndex(g, j, n));
                }
                Debug.Assert(_Frame2Full_Lookup[iLoc] == Frame2Full_Lookup[iLoc]);
            }

            for (int l = 0; l < L; l++)
            {
                Debug.Assert(Frame2Full_Lookup[l] < 0 || FullMap.IsInLocalRange(Frame2Full_Lookup[l]));
            }
#endif


            /*
             * if (m_supportExternal) {
             *  int[] PeerProcess = GridDat.Parallel.ProcessesToReceiveFrom;
             *  int TT = PeerProcess.Length;
             *  int DOFperCell = FrameMap.MaxTotalNoOfCoordinatesPerCell;
             *
             *  ExtRangeStart = new int[TT];
             *  ExtRangeLen = new int[TT];
             *  ExtRangeTrafo = new int[TT][];
             *
             *  for(int tt = 0; tt < TT; tt++) {
             *      int otherRank = PeerProcess[tt];
             *      int jFristCell = GridDat.Parallel.m_RcvCommListsInsertIndex[otherRank];
             *      int Jrank = GridDat.Parallel.m_RcvCommListsNoOfItems[otherRank];
             *
             *
             *      int offset = (int)(FrameMap.GlobalUniqueCoordinateIndex(0, jFristCell, 0));
             *      ExtRangeStart[tt] = offset;
             *      ExtRangeLen[tt] = Jrank*DOFperCell;
             *
             *
             *      ExtRangeTrafo[tt] = new int[ExtRangeLen[tt]];
             *      ExtRangeTrafo[tt].SetAll(int.MinValue);
             *
             *      for (int j = 0; j < Jrank; j++) { // loop over all external cells that this process receives from 'otherRank' ...
             *          int jCell = j + jFristCell;
             *          Debug.Assert(jCell >= Jup);
             *          Debug.Assert(jCell < Jtot);
             *          ReducedRegionCode rrc;
             *          int NoOfSpc = m_lsTrk.GetNoOfSpecies(jCell, out rrc);
             *          int iSpc = m_lsTrk.GetSpeciesIndexFromId(rrc, m_spcId);
             *
             *          for (int g = 0; g < G; g++) { // loop over all basises
             *              Basis b = BasisS[g];
             *              XDGBasis xb = XBasisS[g];
             *              bool b_is_XDGbasis = (xb != null);
             *
             *              int n0, N;
             *              if (b_is_XDGbasis) {
             *                  if (iSpc < 0) {
             *                      n0 = int.MaxValue;
             *                      N = int.MinValue;
             *                  } else {
             *                      N = xb.DOFperSpeciesPerCell;
             *                      n0 = N*iSpc;
             *                  }
             *              } else {
             *                  n0 = 0;
             *                  N = b.GetLength(j);
             *              }
             *
             *              if (N >= 0) {
             *                  int iFull = (int)(FullMap.GlobalUniqueCoordinateIndex(g, jCell, n0));
             *                  int iFrame = (int)(FrameMap.GlobalUniqueCoordinateIndex(g, jCell, 0));
             *
             *                  for (int n = 0; n < N; n++) {
             *                      ExtRangeTrafo[tt][iFrame + n - offset] = iFull + n;
             *                  }
             *              }
             *          }
             *      }
             *  }
             * }
             */

            {
                int NoOfSpc    = this.m_Regions.SpeciesIdS.Count;
                int N_frame    = this.FrameMap.MaxTotalNoOfCoordinatesPerCell;
                var FramBasisS = this.FrameMap.BasisS.ToArray();
                var FullBasisS = this.FullMap.BasisS.ToArray();


                int[] NBs = FramBasisS.Select(b => b.Length).ToArray();
                int[] NBf = FullBasisS.Select(b => b.MaximalLength).ToArray();

                Debug.Assert(NBf.Length == NBs.Length);
                for (int i = 0; i < NBf.Length; i++)
                {
                    Debug.Assert(NBf[i] % NBs[i] == 0);
                }

                bool[] XBasis = FullBasisS.Select(b => b is XDGBasis).ToArray();

                this.IndexTrafoWithinCell = new int[NoOfSpc, this.FrameMap.MaxTotalNoOfCoordinatesPerCell];

                for (int iSpc = 0; iSpc < NoOfSpc; iSpc++)   // loop over all possible species indices
                {
                    int n_frame = 0;
                    int n_full  = 0;

                    for (int ifld = 0; ifld < NBs.Length; ifld++)   // loop over all basises in the mapping

                    {
                        if (XBasis[ifld])
                        {
                            for (int n = 0; n < NBs[ifld]; n++)
                            {
                                this.IndexTrafoWithinCell[iSpc, n_frame + n] = n_full + iSpc * NBs[ifld] + n;
                            }
                        }
                        else
                        {
                            for (int n = 0; n < NBs[ifld]; n++)
                            {
                                this.IndexTrafoWithinCell[iSpc, n_frame + n] = n_full + n;
                            }
                        }

                        n_frame += NBs[ifld];
                        n_full  += NBf[ifld];
                    }
                }
            }
        }