Exemplo n.º 1
0
        public int nunsplitghost;          // # of ghost unsplit cells I store

        public void AddParentCell(int id, int iparent, int nx, int ny, int nz, double[] lo, double[] hi)
        {
            GrowPcells(1);

            ParentCell p = new ParentCell();

            p.id   = id;
            p.mask = 1;
            if (iparent >= 0)
            {
                p.level = pcells[iparent].level + 1;
                p.nbits = pcells[iparent].nbits + pcells[iparent].newbits;
            }
            else
            {
                p.level = p.nbits = 0;
            }
            p.newbits     = IdBits(nx, ny, nz);
            p.iparent     = iparent;
            p.grandparent = 0;                // set by caller

            if (p.nbits + p.newbits > maxbits)
            {
                sparta.DumpError("Cell ID has too many bits");
            }

            p.nx    = nx;
            p.ny    = ny;
            p.nz    = nz;
            p.lo[0] = lo[0]; p.lo[1] = lo[1]; p.lo[2] = lo[2];
            p.hi[0] = hi[0]; p.hi[1] = hi[1]; p.hi[2] = hi[2];

            pcells.Add(p);
            nparent++;
        }
Exemplo n.º 2
0
        private void Params(int narg, string[] arg)
        {
            copyflag = false;
            bool   deleteflag = false;
            bool   fracflag   = false;
            bool   groupflag  = false;
            double fracvalue;
            int    grouparg;

            int iarg = 0;

            while (iarg < narg)
            {
                switch (arg[iarg])
                {
                case "vstream":
                    if (iarg + 4 > narg)
                    {
                        sparta.DumpError("Illegal mixture command");
                    }
                    vstream_flag    = 1;
                    vstream_user[0] = double.Parse(arg[iarg + 1]);
                    vstream_user[1] = double.Parse(arg[iarg + 2]);
                    vstream_user[2] = double.Parse(arg[iarg + 3]);
                    iarg           += 4;
                    break;

                default:
                    sparta.DumpError(string.Format("complete Mixture->params arg:{0}", arg[iarg]));
                    break;
                }
            }

            if (deleteflag)
            {
                sparta.DumpMessage("complete Mixture->params  deleteflag");
            }

            if (fracflag)
            {
                sparta.DumpMessage("complete Mixture->params  fracflag");
            }
            if (groupflag)
            {
                sparta.DumpMessage("complete Mixture->params  groupflag");
            }

            ShrinkGroup();
        }
Exemplo n.º 3
0
        private void Dimension()
        {
            Domain domain = sparta.domain;

            if (args.Length != 1)
            {
                sparta.DumpError("Illegal dimension command");
            }
            if (domain.box_exist)
            {
                sparta.DumpError("Dimension command after simulation box is defined");
            }
            domain.dimension = int.Parse(args[0]);
            if (domain.dimension != 2 && domain.dimension != 3)
            {
                sparta.DumpError("Illegal dimension command");
            }
        }
Exemplo n.º 4
0
        public void CheckPointInside()
        {
            int nbad = 0;

            double[] x;
            Domain   domain = sparta.domain;
            int      dim    = domain.dimension;

            double[] boxlo = domain.boxlo;
            double[] boxhi = domain.boxhi;
            if (dim == 2)
            {
                //parallel
                foreach (Line l in lines)
                {
                    x = l.p1;
                    if (x[0] < boxlo[0] || x[0] > boxhi[0] || x[1] < boxlo[1] || x[1] > boxhi[1] || x[2] < boxlo[2] || x[2] > boxhi[2])
                    {
                        nbad++;
                    }
                    x = l.p2;
                    if (x[0] < boxlo[0] || x[0] > boxhi[0] || x[1] < boxlo[1] || x[1] > boxhi[1] || x[2] < boxlo[2] || x[2] > boxhi[2])
                    {
                        nbad++;
                    }
                }
            }
            else
            {
                sparta.DumpError("Surf->CheckPointInside: dim==3");
            }

            if (nbad != 0)
            {
                sparta.DumpError(string.Format("{0} surface points are not inside simulation box", nbad));
            }
        }
Exemplo n.º 5
0
        public void Command(string[] arg)
        {
            Domain domain = sparta.domain;
            Grid   grid   = sparta.grid;
            int    narg   = arg.Length;

            if (!domain.box_exist)
            {
                sparta.DumpError("Cannot create grid before simulation box is defined");
            }
            if (grid.exist)
            {
                sparta.DumpError("Cannot create grid when grid is already defined");
            }
            grid.exist = true;
            if (narg < 3)
            {
                sparta.DumpError("Illegal create_grid command");
            }
            int nx = int.Parse(arg[0]);
            int ny = int.Parse(arg[1]);
            int nz = int.Parse(arg[2]);

            if (nx < 1 || ny < 1 || nz < 1)
            {
                sparta.DumpError("Illegal create_grid command");
            }
            if (domain.dimension == 2 && nz != 1)
            {
                sparta.DumpError("Create_grid nz value must be 1 for a 2d simulation");
            }
            dimension = domain.dimension;

            int    nlevels = 1;
            Bstyle bstyle  = Bstyle.NONE;
            int    px      = 0;
            int    py      = 0;
            int    pz      = 0;
            int    order;
            Inside inside = Inside.ANY;
            int    iarg   = 3;

            while (iarg < narg)
            {
                sparta.DumpError("Complete CreateGrid.Command  optional arguments");

                iarg++;
            }
            if (bstyle == Bstyle.NONE)
            {
                bstyle = Bstyle.LEVEL;
            }

            if (bstyle == Bstyle.BLOCK)
            {
                sparta.DumpError("Complete CreateGrid.Command  Bstyle.Block");
            }

            double time1 = Timer.getTime();

            int level = 1;
            int xlo, xhi, ylo, yhi, zlo, zhi;

            xlo  = xhi = ylo = yhi = zlo = zhi = 1;
            iarg = 3;
            Region region = null;

            Int64 count = 0;

            int  pnx, pny, pnz, ix, iy, iz, nbits, proc;
            bool pflag;
            int  m, nth, idgrandparent, idparent, idchild;

            double[]        lo = new double[3], hi = new double[3];
            Grid.ParentCell p;
            while (true)
            {
                if (level == 1)
                {
                    grid.AddParentCell(0, -1, nx, ny, nz, domain.boxlo, domain.boxhi);
                }
                else
                {
                    int nparent   = grid.nparent;
                    int prevlevel = level - 2;

                    for (int igrandparent = 0; igrandparent < nparent; igrandparent++)
                    {
                        if (grid.pcells[igrandparent].level != prevlevel)
                        {
                            continue;
                        }
                        p = grid.pcells[igrandparent];

                        idgrandparent = p.id;
                        nbits         = p.nbits;
                        pnx           = p.nx;
                        pny           = p.ny;
                        pnz           = p.nz;

                        m = 0;
                        for (iz = 0; iz < pnz; iz++)
                        {
                            for (iy = 0; iy < pny; iy++)
                            {
                                for (ix = 0; ix < pnx; ix++)
                                {
                                    m++;
                                    idparent = idgrandparent | (m << nbits);
                                    grid.IdChildLohi(igrandparent, m, lo, hi);
                                    if (region != null)
                                    {
                                        pflag = CellInRegion(lo, hi, region, inside);
                                    }
                                    else
                                    {
                                        pflag = true;
                                        if (ix + 1 < xlo || ix + 1 > xhi)
                                        {
                                            pflag = false;
                                        }
                                        if (iy + 1 < ylo || iy + 1 > yhi)
                                        {
                                            pflag = false;
                                        }
                                        if (iz + 1 < zlo || iz + 1 > zhi)
                                        {
                                            pflag = false;
                                        }
                                    }
                                    if (pflag)
                                    {
                                        grid.AddParentCell(idparent, igrandparent, nx, ny, nz, lo, hi);
                                    }
                                    else
                                    {
                                        if (count % 1 == 0)
                                        {
                                            grid.AddChildCell(idparent, igrandparent, lo, hi);
                                        }
                                        count++;
                                    }
                                }
                            }
                        }
                    }
                }

                // final level, add current level cells as child cells
                // loop over all parent cells to find ones at previous level
                // use their info to generate my child cells at this level
                // if BSTYLE is set, there is only 1 level, create proc's cells directly

                if (level == nlevels)
                {
                    List <Grid.ParentCell> pcells = grid.pcells;
                    int nparent   = grid.nparent;
                    int prevlevel = level - 1;
                    for (int iparent = 0; iparent < nparent; iparent++)
                    {
                        if (pcells[iparent].level != prevlevel)
                        {
                            continue;
                        }
                        p        = pcells[iparent];
                        idparent = p.id;
                        nbits    = p.nbits;
                        nx       = p.nx;
                        ny       = p.ny;
                        nz       = p.nz;

                        if (bstyle == Bstyle.LEVEL)
                        {
                            int ntotal    = (int)nx * ny * nz;
                            int firstproc = (int)count % 1;
                            int ifirst    = 0 - firstproc + 1;
                            if (ifirst <= 0)
                            {
                                ifirst += 1;
                            }
                            for (m = ifirst; m <= ntotal; m += 1)
                            {
                                idchild = idparent | (m << nbits);
                                grid.IdChildLohi(iparent, m, lo, hi);
                                grid.AddChildCell(idchild, iparent, lo, hi);
                            }
                            count += ntotal;

                            // loop over all child cells
                            // convert M to Nth based on order
                            // assign each cell to proc based on Nth and STRIDE or CLUMP
                        }
                        else
                        {
                            sparta.DumpError("CreateGrid->Command: more Bstyle");
                        }
                    }
                    break;
                }
                if (level == nlevels)
                {
                    break;
                }
                level++;

                switch (arg[iarg])
                {
                //case "level"
                default:
                    sparta.DumpError("CreateGrid->Command: complete this");
                    break;
                }
            }
            List <Grid.ParentCell> pcells1 = grid.pcells;
            int nparent1 = grid.nparent;

            for (int i = 1; i < nparent1; i++)
            {
                pcells1[pcells1[i].iparent].grandparent = 1;
            }

            if (bstyle == Bstyle.CLUMP || bstyle == Bstyle.BLOCK)
            {
                grid.clumped = true;
            }
            else
            {
                grid.clumped = false;
            }

            double time2 = Timer.getTime();

            grid.SetupOwned();
            grid.AcquireGhosts();
            grid.FindNeighbors();
            grid.CheckUniform();

            double time3 = Timer.getTime();

            double time_total = time3 - time1;

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Create {0} child grid cells\n", grid.ncell);
            sb.AppendFormat("  parent cells = {0}\n", grid.nparent);
            sb.AppendFormat("  CPU time = {0} secs\n", time_total);
            sb.AppendFormat("  create/ghost percent = {0} {1}\n", 100.0 * (time2 - time1) / time_total, 100.0 * (time3 - time2) / time_total);
            sparta.DumpMessage(sb.ToString());
        }
Exemplo n.º 6
0
        public void Command(string[] arg)
        {
            Grid grid = sparta.grid;
            Surf surf = sparta.surf;
            Domain domain = sparta.domain;
            Particle particle = sparta.particle;
            int narg = arg.Length;
            filename = arg[0];

            double[] origion = new double[3];
            if (!grid.exist)
            {
                sparta.DumpError("Cannot read_surf before grid is defined");
            }
            surf.exist = true;
            dim = domain.dimension;
            if (narg < 1)
            {
                sparta.DumpError("Illegal read_surf command");
            }
            Console.WriteLine("Reading surf file ...\n");
            try
            {
                fp = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            catch (Exception e)
            {

                throw e;
            }
            double time1 = Timer.getTime();
            Header();

            pts = new List<Point>(npoint);
            lines = new List<Line>(nline);

            ParseKeyword(true);

            ParseKeyword(false);
            PartFlag pf = PartFlag.NONE;
            bool grouparg = false;

            int iarg = 1;
            while (iarg < narg)
            {
                switch (arg[iarg])
                {

                    default:
                        sparta.DumpError(string.Format("ReadSurf->Command: complete args {0}", arg[iarg]));
                        break;
                }
            }

            if (particle.exist && pf == PartFlag.NONE)
            {
                sparta.DumpError("Using read_surf particle none when particles exist");
            }

            //if (grouparg)
            //{
            //    int igroup=surf.FindGroup
            //}
            // extent of surfs after geometric transformations
            // compute sizes of smallest surface elements

            double[,] extent = new double[3, 2];
            extent[0, 0] = extent[1, 0] = extent[2, 0] = double.MaxValue;
            extent[0, 1] = extent[1, 1] = extent[2, 1] = -double.MaxValue;

            foreach (Point p in pts)
            {
                extent[0, 0] = Math.Min(extent[0, 0], p.x[0]);
                extent[0, 1] = Math.Max(extent[0, 1], p.x[0]);
                extent[1, 0] = Math.Min(extent[1, 0], p.x[1]);
                extent[1, 1] = Math.Max(extent[1, 1], p.x[1]);
                extent[2, 0] = Math.Min(extent[2, 0], p.x[2]);
                extent[2, 1] = Math.Max(extent[2, 1], p.x[2]);
            }

            double minlen=0, minarea=0;
            if (dim == 2)
            {
                minlen = ShortestLine();
            }
            if (dim == 3)
            {
                sparta.DumpError("Readsurf->Command: complete dimension3");
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("  {0:G6} {1:G6} xlo xhi\n", extent[0, 0], extent[0, 1]);
            sb.AppendFormat("  {0:G6} {1:G6} ylo yhi\n", extent[1, 0], extent[1, 1]);
            sb.AppendFormat("  {0:G6} {1:G6} zlo zhi\n", extent[2, 0], extent[2, 1]);
            if (dim==2)
            {
                sb.AppendFormat("  {0:G6} min line length\n", minlen);
            }
            else
            {
                sparta.DumpError("Readsurf->Command: complete dimension3");
            }
            sparta.DumpMessage(sb.ToString());

            if (dim == 2)
            {
                surf.nline = nline;
                surf.Grow();
                List<Surf.Line> newlines = surf.lines;

                int m = 0;
                foreach (Line line in lines)
                {
                    Surf.Line l = new Surf.Line();
                    l.id = m + 1;  // check for overflow when allow distributed surfs
                    l.type = line.type;
                    l.mask = line.mask;
                    l.isc = l.isr = -1;
                    Array.Copy(pts[line.p1].x, l.p1,  3);
                    Array.Copy(pts[line.p2].x, l.p2,  3);
                    newlines.Add(l);
                    m++;
                }


            }
            else if (dim==3)
            {
                sparta.DumpError("Readsurf->Command: complete dimension3");
            }


            if (dim==2)
            {
                surf.ComputeLineNormal();
            }
            else
            {
                sparta.DumpError("Readsurf->Command: complete dimension3");
            }

            if (dim == 2)
            {
                surf.CheckPointInside();
            }
            else
            {
                sparta.DumpError("Readsurf->Command: complete dimension3");
            }

            double time2 = Timer.getTime();

            if (particle.exist)
            {
                particle.Sort();
            }

            surf.SetupSurf();
            //todo:not necessary
            grid.UnsetNeighbors();
            grid.RemoveGhosts();

            if (particle.exist&&grid.nsplitlocal!=0)
            {
                throw new NotImplementedException();

            }

            grid.ClearSurf();

            double time3 = Timer.getTime();
            if (dim==2)
            {
                surf.CheckWatertight2d(nline);
                CheckNeighborNorm2d();
            }

            double time4 = Timer.getTime();
            //todo:continue
            grid.SurftoGrid(true);

            throw new NotImplementedException();
        }
Exemplo n.º 7
0
        private void SetUnit(string str)
        {
            switch (str)
            {
            case "cgs":
                boltz = 1.3806488e-16;
                mvv2e = 1.0;
                dt    = 1.0;
                break;

            case "si":
                boltz = 1.3806488e-23;
                mvv2e = 1.0;
                dt    = 1.0;
                break;

            default:
                sparta.DumpError("Illegal units command");
                break;
            }
            unit_style = str;
        }
Exemplo n.º 8
0
        public void SetBoundry(string[] arg)
        {
            int narg = arg.Length;

            if (box_exist)
            {
                sparta.DumpError("Boundary command after simulation box is defined");
            }
            if (narg != 3)
            {
                sparta.DumpError("Illegal boundary command");
            }

            char c;
            int  m = 0;

            for (int idim = 0; idim < 3; idim++)
            {
                for (int iside = 0; iside < 2; iside++)
                {
                    if (iside == 0)
                    {
                        c = arg[idim][0];
                    }
                    else if (iside == 1 && arg[idim].Length == 1)
                    {
                        c = arg[idim][0];
                    }
                    else
                    {
                        c = arg[idim][1];
                    }

                    if (c == 'o')
                    {
                        bflag[m] = bc.OUTFLOW;
                    }
                    else if (c == 'p')
                    {
                        bflag[m] = bc.PERIODIC;
                    }
                    else if (c == 'r')
                    {
                        bflag[m] = bc.REFLECT;
                    }
                    else if (c == 's')
                    {
                        bflag[m] = bc.SURFACE;
                    }
                    else if (c == 'a')
                    {
                        bflag[m] = bc.AXISYM;
                    }
                    else
                    {
                        sparta.DumpError("Illegal boundary command");
                    }

                    surf_collide[m] = surf_react[m] = -1;
                    m++;
                }
            }

            if (dimension == 2 && (bflag[(int)bd.ZLO] != bc.PERIODIC || bflag[(int)bd.ZHI] != bc.PERIODIC))
            {
                sparta.DumpError("Z dimension must be periodic for 2d simulation");
            }

            if (bflag[(int)bd.XLO] == bc.AXISYM || bflag[(int)bd.XHI] == bc.AXISYM ||
                bflag[(int)bd.YHI] == bc.AXISYM || bflag[(int)bd.ZLO] == bc.AXISYM || bflag[(int)bd.ZHI] == bc.AXISYM)
            {
                sparta.DumpError("Only ylo boundary can be axi-symmetric");
            }

            if (bflag[(int)bd.YLO] == bc.AXISYM)
            {
                axisymmetric = true;
                if (bflag[(int)bd.YHI] == bc.PERIODIC)
                {
                    sparta.DumpError("Y cannot be periodic for axi-symmetric");
                }
            }

            for (m = 0; m < 6; m += 2)
            {
                if (bflag[m] == bc.PERIODIC || bflag[m + 1] == bc.PERIODIC)
                {
                    if (bflag[m] != bc.PERIODIC || bflag[m + 1] != bc.PERIODIC)
                    {
                        sparta.DumpError("Both sides of boundary must be periodic");
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void Command(string[] arg)
        {
            Grid grid = sparta.grid;
            int  narg = arg.Length;

            if (!grid.exist)
            {
                sparta.DumpError("Cannot balance grid before grid is defined");
            }

            if (narg < 1)
            {
                sparta.DumpError("Illegal balance_grid command");
            }

            Bstyle  bstyle = Bstyle.NONE;
            Order   order;
            int     px, py, pz;
            RCBtype rcbwt = RCBtype.CELL;
            int     rcbflip;

            switch (arg[0])
            {
            case "rcb":
                if (narg != 2 && narg != 3)
                {
                    sparta.DumpError("Illegal balance_grid command");
                }
                bstyle = Bstyle.BISECTION;
                switch (arg[1])
                {
                case "cell": rcbwt = RCBtype.CELL; break;

                case "part": rcbwt = RCBtype.PARTICLE; break;

                default:
                    sparta.DumpError("Illegal balance_grid command");
                    break;
                }

                // undocumented optional 3rd arg
                // rcbflip = 3rd arg = 1 forces rcb.compute() to flip sign
                //           of all grid cell "dots" to force totally different
                //           assignment of grid cells to procs and induce
                //           complete rebalance data migration
                rcbflip = 0;
                if (narg == 3)
                {
                    rcbflip = int.Parse(arg[2]);
                }
                break;

            default:
                sparta.DumpError("BalanceGrid.Command(): complete arguments");
                break;
            }
            if (bstyle == Bstyle.STRIDE || bstyle == Bstyle.CLUMP || bstyle == Bstyle.BLOCK)
            {
                if (!grid.uniform)
                {
                    sparta.DumpError("Invalid balance_grid style for non-uniform grid");
                }
            }

            double time1 = Timer.getTime();

            List <Grid.ChildCell> cells = grid.cells;
            List <Grid.ChildInfo> cinfo = grid.cinfo;
            int nglocal = grid.nlocal;

            switch (bstyle)
            {
            case Bstyle.NONE:
                break;

            case Bstyle.STRIDE:
                break;

            case Bstyle.CLUMP:
                break;

            case Bstyle.BLOCK:
                break;

            case Bstyle.RANDOM:
                break;

            case Bstyle.PROC:
                break;

            case Bstyle.BISECTION:
                RCB rcb = new RCB(sparta);

                double[,] x;
                x = new double[nglocal, 3];

                double[] lo, hi;

                int nbalance = 0;
                for (int icell = 0; icell < nglocal; icell++)
                {
                    if (cells[icell].nsplit <= 0)
                    {
                        continue;
                    }
                    lo             = cells[icell].lo;
                    hi             = cells[icell].hi;
                    x[nbalance, 0] = 0.5 * (lo[0] + hi[0]);
                    x[nbalance, 1] = 0.5 * (lo[1] + hi[1]);
                    x[nbalance, 2] = 0.5 * (lo[2] + hi[2]);
                    nbalance++;
                }

                double[] wt;
                if (rcbwt == RCBtype.PARTICLE)
                {
                    //sparta.particle.Sort();
                    //int zero = 0;
                    //int n;
                    //wt = new double[nglocal];
                    //nbalance = 0;
                    //for (int icell = 0; icell < nglocal; icell++)
                    //{
                    //    if (cells[icell].nsplit <= 0) continue;
                    //    n = cinfo[icell].count;
                    //    if (n!=0) wt[nbalance++] = n;
                    //    else
                    //    {
                    //        wt[nbalance++] = ZEROPARTICLE;
                    //        zero++;
                    //    }
                    //}
                    sparta.DumpError("BalanceGrid->Command: complete sorted by particle");
                }

                //rcb.Compute(nbalance, x, wt, rcbflip);
                //rcb.Invert();

                //nbalance = 0;
                //int[] sendproc = rcb.Sendproc;
                //for (int icell = 0; icell < nglocal; icell++)
                //{
                //    if (cells[icell].nsplit <= 0) continue;
                //    cells[icell].proc = sendproc[nbalance++];
                //}
                //nmigrate = nbalance - rcb.nkeep;

                break;

            default:
                break;
            }
        }