private double ShortestLine() { double len = double.MaxValue; foreach (Line l in lines) { len = Math.Min(len, Surf.LineSize(pts[l.p1].x, pts[l.p2].x)); } return len; }
public int SurftoGrid(int id_caller, double[] lo_caller, double[] hi_caller, List <int> csurfs, int max) { Surf surf = sparta.surf; id = id_caller; lo = lo_caller; hi = hi_caller; surfs = csurfs; List <Surf.Line> lines = surf.lines; int nline = surf.nline; double[] x1, x2; nsurf = 0; int m = -1; foreach (Surf.Line l in lines) { m++; x1 = l.p1; x2 = l.p2; if (Math.Max(x1[0], x2[0]) < lo[0]) { continue; } if (Math.Min(x1[0], x2[0]) > hi[0]) { continue; } if (Math.Max(x1[1], x2[1]) < lo[1]) { continue; } if (Math.Min(x1[1], x2[1]) > hi[1]) { continue; } if (Cliptest(x1, x2)) { if (nsurf == max) { return(-1); } nsurf++; surfs.Add(m); } } return(nsurf); }
private void Create() { update = new Update(this); particle = new Particle(this); domain = new Domain(this); grid = new Grid(this); surf = new Surf(this); collide = null; react = null; modify = new Modify(this); output = new Output(this); timer = new Timer(this); DumpMessage("create(): done."); }
public Cut2d(SPARTA sparta, bool axisymmetric) { this.sparta = sparta; this.axisymmetric = axisymmetric; Surf surf = sparta.surf; npushmax = 2; npushcell = new int[4]; pushlo_vec = new double[3]; pushhi_vec = new double[3]; pushvalue_vec = new double[3]; pushlo_vec[0] = -1.0; pushhi_vec[0] = 1.0; pushvalue_vec[0] = 0.0; pushlo_vec[1] = -1.0; pushhi_vec[1] = 1.0; pushvalue_vec[1] = 0.0; switch (surf.pushflag) { case 0: npushmax = 0; break; case 2: npushmax = 3; pushlo_vec[2] = surf.pushlo; pushhi_vec[2] = surf.pushhi; pushvalue_vec[2] = surf.pushvalue; break; default: break; } }
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(); }
public void SurftoGrid(bool flag, bool outflag = true) { Domain domain = sparta.domain; Surf surf = sparta.surf; ChildCell c; SplitInfo s; Cut2d cut2D; int nsurf = 0; double[] lo, hi, vols; double[] xsplit = new double[3]; int dim = domain.dimension; double[] slo = surf.bblo; double[] shi = surf.bbhi; if (dim == 3) { sparta.DumpError("Grid->SurftoGrid: 3d"); } cut2D = new Cut2d(sparta, domain.axisymmetric); for (int icell = 0; icell < nlocal; icell++) { if (cells[icell].nsplit <= 0) { continue; } lo = cells[icell].lo; hi = cells[icell].hi; if (BoxOverlap(lo, hi, slo, shi) == 0) { continue; } if (dim == 3) { sparta.DumpError("Grid->SurftoGrid: 3d"); } else { nsurf = cut2D.SurftoGrid(cells[icell].id, cells[icell].lo, cells[icell].hi, csurfs, maxsurfpercell); } if (nsurf < 0) { sparta.DumpError("Too many surfs in one cell"); } if (nsurf != 0) { cinfo[icell].type = CellType.OVERLAP; cells[icell].nsurf = nsurf; cells[icell].csurfs = csurfs.ToArray(); } } if (outflag) { SurftoGridStats(); } throw new NotImplementedException(); }