Example #1
0
        public void compute_line_normal(int nstart, int n)
        {
            int p1, p2;

            double[] z = new double[3], delta = new double[3], norm = new double[3];

            z[0] = 0.0; z[1] = 0.0; z[2] = 1.0;

            int m = nstart;

            for (int i = 0; i < n; i++)
            {
                p1 = lines[m].p1;
                p2 = lines[m].p2;
                MathExtra.sub3(pts[p2].x, pts[p1].x, delta);
                MathExtra.cross3(z, delta, norm);
                MathExtra.norm3(norm);
                norm[2] = 0.0;
                Line line = lines[m];
                line.norm    = new double[3];
                line.norm[0] = norm[0];
                line.norm[1] = norm[1];
                line.norm[2] = norm[2];
                lines[m]     = line;

                m++;
            }
        }
Example #2
0
        public void compute_tri_normal(int nstart, int n)
        {
            int p1, p2, p3;

            double[] delta12 = new double[3], delta13 = new double[3];

            int m = nstart;

            for (int i = 0; i < n; i++)
            {
                p1 = tris[m].p1;
                p2 = tris[m].p2;
                p3 = tris[m].p3;
                MathExtra.sub3(pts[p2].x, pts[p1].x, delta12);
                MathExtra.sub3(pts[p3].x, pts[p1].x, delta13);
                MathExtra.cross3(delta12, delta13, tris[m].norm);
                MathExtra.norm3(tris[m].norm);
                m++;
            }
        }
Example #3
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);
            }
        }