public virtual int test_collision(int icell, int igroup, int jgroup, Particle.OnePart ip, Particle.OnePart jp) { Console.WriteLine("Collide virtual test_collision"); return(0); }
public static Particle.OnePart Bytes2OnePart(byte[] buf) { Particle.OnePart part = new Particle.OnePart(); int size = Marshal.SizeOf(buf); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(buf, 0, ptr, size); part = (Particle.OnePart)Marshal.PtrToStructure(ptr, part.GetType()); return(part); }
public static byte[] GetBytes(Particle.OnePart part) { int size = Marshal.SizeOf(part); byte[] buf = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(part, ptr, true); Marshal.Copy(ptr, buf, 0, size); Marshal.FreeHGlobal(ptr); return(buf); }
public virtual void boundary_tally(int iface, int istyle, Particle.OnePart iorig, Particle.OnePart?ip, Particle.OnePart?jp) { System.Console.WriteLine("Copmute virtual boundary_tally"); }
public virtual void surf_tally(int isurf, Particle.OnePart iorig, Particle.OnePart?ip, Particle.OnePart?jp) { System.Console.WriteLine("Copmute virtual surf_tally"); }
//public int periodic(int*); //public void boundary_modify(int, char**); public virtual int collide(Particle.OnePart?ip, int face, int icell, double[] xnew, double dtremain, Particle.OnePart?jp) { Particle.OnePart p; jp = null; if (ip != null) { p = (Particle.OnePart)ip; } else { p = new Particle.OnePart(); } switch (bflag[face]) { // outflow boundary, particle deleted by caller case (int)Enum2.OUTFLOW: return((int)Enum2.OUTFLOW); // periodic boundary // set x to be on periodic box face // adjust xnew by periodic box length case (int)Enum2.PERIODIC: { double[] x = p.x; switch (face) { case (int)Enum1.XLO: x[0] = boxhi[0]; xnew[0] += xprd; break; case (int)Enum1.XHI: x[0] = boxlo[0]; xnew[0] -= xprd; break; case (int)Enum1.YLO: x[1] = boxhi[1]; xnew[1] += yprd; break; case (int)Enum1.YHI: x[1] = boxlo[1]; xnew[1] -= yprd; break; case (int)Enum1.ZLO: x[2] = boxhi[2]; xnew[2] += zprd; break; case (int)Enum1.ZHI: x[2] = boxlo[2]; xnew[2] -= zprd; break; } return((int)Enum2.PERIODIC); } // specular reflection boundary // adjust xnew and velocity case (int)Enum2.REFLECT: { double[] v = p.v; double[] lo = sparta.grid.cells[icell].lo; double[] hi = sparta.grid.cells[icell].hi; int dim = face / 2; if (face % 2 == 0) { xnew[dim] = lo[dim] + (lo[dim] - xnew[dim]); v[dim] = -v[dim]; } else { xnew[dim] = hi[dim] - (xnew[dim] - hi[dim]); v[dim] = -v[dim]; } return((int)Enum2.REFLECT); } // treat global boundary as a surface // particle velocity is changed by surface collision model // dtremain may be changed by collision model // reset all components of xnew, in case dtremain changed // if axisymmetric, caller will reset again, including xnew[2] case (int)Enum2.SURFACE: { double[] tmp = new double[3]; for (int i = 0; i < 3; i++) { tmp[i] = norm[face, i]; } jp = sparta.surf.sc[surf_collide[face]]. collide(ref ip, tmp, dtremain, surf_react[face]); if (ip != null) { double[] x = p.x; double[] v = p.v; xnew[0] = x[0] + dtremain * v[0]; xnew[1] = x[1] + dtremain * v[1]; if (dimension == 3) { xnew[2] = x[2] + dtremain * v[2]; } } return((int)Enum2.SURFACE); } } ip = p; return(0); }
protected RanPark random; // RNG for particle reflection void diffuse(Particle.OnePart p, double[] norm) { // specular reflection // reflect incident v around norm if (random.uniform() > acc) { MathExtra.reflect3(p.v, norm); // diffuse reflection // vrm = most probable speed of species, eqns (4.1) and (4.7) // vperp = velocity component perpendicular to surface along norm, eqn (12.3) // vtan12 = 2 velocity components tangential to surface // tangent1 = component of particle v tangential to surface, // check if tangent1 = 0 (normal collision), set randomly // tangent2 = norm x tangent1 = orthogonal tangential direction // tangent12 are both unit vectors } else { double[] tangent1 = new double[3], tangent2 = new double[3]; List <Particle.Species> species = sparta.particle.species; int ispecies = p.ispecies; double vrm = Math.Sqrt(2.0 * sparta.update.boltz * twall / species[ispecies].mass); double vperp = vrm * Math.Sqrt(-Math.Log(random.uniform())); double theta = MyConst.MY_2PI * random.uniform(); double vtangent = vrm * Math.Sqrt(-Math.Log(random.uniform())); double vtan1 = vtangent * Math.Sin(theta); double vtan2 = vtangent * Math.Cos(theta); double[] v = p.v; double dot = MathExtra.dot3(v, norm); double beta_un, normalized_distbn_fn; tangent1[0] = v[0] - dot * norm[0]; tangent1[1] = v[1] - dot * norm[1]; tangent1[2] = v[2] - dot * norm[2]; if (MathExtra.lensq3(tangent1) == 0.0) { tangent2[0] = random.uniform(); tangent2[1] = random.uniform(); tangent2[2] = random.uniform(); MathExtra.cross3(norm, tangent2, tangent1); } MathExtra.norm3(tangent1); MathExtra.cross3(norm, tangent1, tangent2); // add in translation or rotation vector if specified // only keep portion of vector tangential to surface element if (trflag != 0) { double vxdelta, vydelta, vzdelta; if (tflag != 0) { vxdelta = vx; vydelta = vy; vzdelta = vz; double adot = vxdelta * norm[0] + vydelta * norm[1] + vzdelta * norm[2]; if (Math.Abs(adot) > 0.001) { adot /= vrm; do { do { beta_un = (6.0 * random.uniform() - 3.0); } while (beta_un + adot < 0.0); normalized_distbn_fn = 2.0 * (beta_un + adot) / (adot + Math.Sqrt(adot * adot + 2.0)) * Math.Exp(0.5 + (0.5 * adot) * (adot - Math.Sqrt(adot * adot + 2.0)) - beta_un * beta_un); } while (normalized_distbn_fn < random.uniform()); vperp = beta_un * vrm; } } else { double[] x = p.x; vxdelta = wy * (x[2] - pz) - wz * (x[1] - py); vydelta = wz * (x[0] - px) - wx * (x[2] - pz); vzdelta = wx * (x[1] - py) - wy * (x[0] - px); double adot = vxdelta * norm[0] + vydelta * norm[1] + vzdelta * norm[2]; vxdelta -= adot * norm[0]; vydelta -= adot * norm[1]; vzdelta -= adot * norm[2]; } v[0] = vperp * norm[0] + vtan1 * tangent1[0] + vtan2 * tangent2[0] + vxdelta; v[1] = vperp * norm[1] + vtan1 * tangent1[1] + vtan2 * tangent2[1] + vydelta; v[2] = vperp * norm[2] + vtan1 * tangent1[2] + vtan2 * tangent2[2] + vzdelta; // no translation or rotation } else { v[0] = vperp * norm[0] + vtan1 * tangent1[0] + vtan2 * tangent2[0]; v[1] = vperp * norm[1] + vtan1 * tangent1[1] + vtan2 * tangent2[1]; v[2] = vperp * norm[2] + vtan1 * tangent1[2] + vtan2 * tangent2[2]; } p.erot = sparta.particle.erot(ispecies, twall, random); p.evib = sparta.particle.evib(ispecies, twall, random); } }
public virtual void setup_collision(Particle.OnePart ip, Particle.OnePart jp) { Console.WriteLine("Collide virtual setup_collision"); }