Example #1
0
 internal void AcquireGhosts()
 {
     if (cutoff < 0.0)
     {
         sparta.DumpMessage("Grid.AcquireGhost: cutoff <0.0");
     }
     else if (clumped)
     {
         sparta.DumpMessage("Grid.AcquireGhost: clumped");
     }
     else
     {
         sparta.DumpMessage("Grid.AcquireGhost: complete");
     }
 }
Example #2
0
        public Mixture(SPARTA sparta, string userid)
        {
            this.sparta = sparta;
            Particle particle = sparta.particle;

            this.userid  = userid;
            vstream      = new double[3];
            vstream_user = new double[3];
            id           = string.Copy(userid);
            activeflag   = false;
            foreach (char c in id)
            {
                if (!char.IsLetterOrDigit(c))
                {
                    sparta.DumpMessage("Mixture ID must be alphanumeric or underscore characters");
                }
            }

            all_default = species_default = false;
            switch (id)
            {
            case "all": all_default = true; break;

            case "species": species_default = true; break;

            default:
                break;
            }



            active = new List <int>();

            Allocate();
        }
Example #3
0
        public int ExpandArgs(int narg, string[] arg, int mode, out string[] earg)
        {
            string str = null;

            foreach (string s in arg)
            {
                if (s.Contains('*'))
                {
                    str = s.Substring(s.IndexOf('*'));
                    break;
                }
            }
            if (string.IsNullOrEmpty(str))
            {
                earg = arg;
                return(narg);
            }
            sparta.DumpMessage("complete input->expand_args: args has char * ");
            earg = arg;
            return(narg);
        }
Example #4
0
        private void AddMixture(int narg, string[] arg)
        {
            if (narg < 1)
            {
                sparta.DumpMessage("Illegal mixture command");
            }

            // imix = index if mixture ID already exists
            // else instantiate a new mixture

            int imix = FindMixture(arg[0]);

            if (imix < 0)
            {
                imix = nmixture;
                nmixture++;
                mixture.Add(new Mixture(sparta, arg[0]));
            }

            mixture[imix].Command(narg, arg);
        }
Example #5
0
        public double Uniform()
        {
            if (!initflag)
            {
                sparta.DumpMessage("Seed command has not been used");
            }

            double uni = u[i97] - u[j97];

            if (uni < 0.0)
            {
                uni += 1.0;
            }
            u[i97] = uni;
            i97--;
            if (i97 == 0)
            {
                i97 = 97;
            }
            j97--;
            if (j97 == 0)
            {
                j97 = 97;
            }
            c -= cd;
            if (c < 0.0)
            {
                c += cm;
            }
            uni -= c;
            if (uni < 0.0)
            {
                uni += 1.0;
            }
            return(uni);
        }
Example #6
0
        public void Command(int narg, string[] arg)
        {
            if (narg < 1)
            {
                sparta.DumpMessage("Illegal mixture command");
            }

            // nsp = # of species listed before optional keywords
            // iarg = start of optional keywords

            int iarg;

            for (iarg = 1; iarg < narg; iarg++)
            {
                bool breakflag = false;
                switch (arg[iarg])
                {
                case "nrho": breakflag = true; break;

                case "vstream": breakflag = true; break;

                case "temp": breakflag = true; break;

                case "trot": breakflag = true; break;

                case "tvib": breakflag = true; break;

                case "frac": breakflag = true; break;

                case "group": breakflag = true; break;

                case "copy": breakflag = true; break;

                case "delete": breakflag = true; break;

                default:
                    break;
                }
                if (breakflag)
                {
                    break;
                }
            }
            int nsp = iarg - 1;

            // add_species() processes list of species
            // params() processes remaining optional keywords
            string[] arg1;
            string[] arg2;
            if (arg.Length > 1)
            {
                arg1 = new string[arg.Length - 1];
                arg2 = new string[arg.Length - iarg];
                Array.Copy(arg, 1, arg1, 0, arg1.Length);
                Array.Copy(arg, iarg, arg2, 0, arg2.Length);
                AddSpecies(nsp, arg1);
                Params(narg - iarg, arg2);
            }


            // if copy keyword was used, create a new mixture via add_mixture()
            // then invoke its copy() method, passing it this mixture

            if (copyflag)
            {
                sparta.DumpMessage("Mixture->Command: copyflag");
                //particle.add_mixture(1, &arg[iarg + copyarg]);
                //particle.mixture[particle.nmixture - 1].copy(this);
            }
        }
Example #7
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());
        }
Example #8
0
 public void CheckWatertight2d(int nline)
 {
     //todo:Check if the
     //throw new NotImplementedException();
     sparta.DumpMessage("Surf->CheckWatertight2d: this is the function that checks if the surf is closed");
 }
Example #9
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();
        }
Example #10
0
        public void Global(string[] arg)
        {
            int narg = arg.Length;

            if (narg < 1)
            {
                sparta.DumpError("Illegal global command");
            }
            int iarg = 0;

            while (iarg < narg)
            {
                switch (arg[iarg])
                {
                case "fnum":
                    if (iarg + 2 > narg)
                    {
                        sparta.DumpError("Illegal global command");
                    }
                    fnum = double.Parse(arg[iarg + 1]);
                    if (fnum <= 0.0)
                    {
                        sparta.DumpError("Illegal global command");
                    }
                    iarg += 2;
                    break;

                case "nrho":
                    if (iarg + 2 > narg)
                    {
                        sparta.DumpError("Illegal global command");
                    }
                    nrho = double.Parse(arg[iarg + 1]);
                    if (nrho <= 0.0)
                    {
                        sparta.DumpError("Illegal global command");
                    }
                    iarg += 2;
                    break;

                case "gridcut":
                    Grid grid = sparta.grid;
                    if (iarg + 2 > narg)
                    {
                        sparta.DumpError("Illegal global command");
                    }
                    grid.cutoff = double.Parse(arg[iarg + 1]);
                    if (grid.cutoff < 0.0 && grid.cutoff != -1.0)
                    {
                        sparta.DumpError("Illegal global command");
                    }
                    // force ghost info to be regenerated with new cutoff
                    sparta.DumpMessage("grid.remove_ghosts()");
                    iarg += 2;
                    break;

                case "comm/sort":
                    if (iarg + 2 > narg)
                    {
                        sparta.DumpError("Illegal global command");
                    }
                    if (arg[iarg + 1].Equals("yes"))
                    {
                        sparta.DumpMessage("comm sort yes");
                    }
                    else if (arg[iarg + 1].Equals("no"))
                    {
                        sparta.DumpMessage("comm sort no");
                    }
                    else
                    {
                        sparta.DumpError("Illegal global command");
                    }
                    iarg += 2;
                    break;

                default:
                    sparta.DumpError(string.Format("Unknown Global arguments {0}", arg[iarg]));
                    break;
                }
            }
        }
Example #11
0
        public void PrintBox(string str)
        {
            string format = string.Format("{0}orthogonal box = ({1} {2} {3}) to ({4} {5} {6})", str, boxlo[0], boxlo[1], boxlo[2], boxhi[0], boxhi[1], boxhi[2]);

            sparta.DumpMessage(format);
        }