private void UnevenCoordinates()
        {
            double x, y, z;
            double random;
            double func;
            double distancefromcenter;
            int    createdpoints = 0;

            while (createdpoints < counterofpoints)
            {
                x = radius * (1 - 2 * SphereStarCluster.dRand(0, 1));
                y = radius * (1 - 2 * SphereStarCluster.dRand(0, 1));
                z = radius * (1 - 2 * SphereStarCluster.dRand(0, 1));
                distancefromcenter = Math.Pow(x, 2) + Math.Pow(y, 2) + Math.Pow(z, 2);
                random             = SphereStarCluster.dRand(0, 1);
                func = Math.Sqrt(distancefromcenter) / radius;
                if (Math.Pow(radius, 2) >= distancefromcenter && random > func)
                {
                    this.x[createdpoints] = x;
                    this.y[createdpoints] = y;
                    this.z[createdpoints] = z;
                    createdpoints++;
                }
            }
        }
 private void RandomizeMasses()
 {
     for (int i = 0; i < counterofpoints; i++)
     {
         masses[i]    = SphereStarCluster.dRand(1, 2) * 2e30;
         massesSigma += masses[i];
     }
 }
 private void RandomizeVelocities()
 {
     for (int i = 0; i < counterofpoints; i++)
     {
         vx[i] = SphereStarCluster.dRand(-1, 1) * 1e2;
         vy[i] = SphereStarCluster.dRand(-1, 1) * 1e2;
         vz[i] = SphereStarCluster.dRand(-1, 1) * 1e2;
     }
 }
Beispiel #4
0
 public Calculate(SphereStarCluster sphere)
 {
     this.sphere        = sphere;
     speed              = 50;
     totaltime          = 0;
     currenttime        = 0;
     deltatime          = 3.1536e7 * speed;
     currentpositions   = new double[sphere.counterofpoints][];
     sumanglehorizontal = 0;
     rotatehorizontal   = false;
     move = false;
     for (int i = 0; i < sphere.counterofpoints; i++)
     {
         currentpositions[i] = new double[3];
     }
 }
        private void RandomizeCoordinates()
        {
            double x, y, z;
            double distancefromcenter;
            int    createdpoints = 0;

            while (createdpoints < counterofpoints)
            {
                x = radius * (1 - 2 * SphereStarCluster.dRand(0, 1));
                y = radius * (1 - 2 * SphereStarCluster.dRand(0, 1));
                z = radius * (1 - 2 * SphereStarCluster.dRand(0, 1));
                distancefromcenter = Math.Pow(x, 2) + Math.Pow(y, 2) + Math.Pow(z, 2);
                if (Math.Pow(radius, 2) >= distancefromcenter)
                {
                    this.x[createdpoints] = x;
                    this.y[createdpoints] = y;
                    this.z[createdpoints] = z;
                    createdpoints++;
                }
            }
        }
        public void intgr()
        {
            if (firstcall)
            {
                Firststep();
                Write();
                firstcall = false;
            }
            if (merge)
            {
                double[] vx_     = new double[counterofpoints];
                double[] vy_     = new double[counterofpoints];
                double[] vz_     = new double[counterofpoints];
                double[] x_      = new double[counterofpoints];
                double[] y_      = new double[counterofpoints];
                double[] z_      = new double[counterofpoints];
                double[] masses_ = new double[counterofpoints];
                double[,] matrixofdistances_ = new double[counterofpoints, counterofpoints];
                double[] datastorage_ = new double[(iterations + 1) * counterofpoints * 3];
                for (int i = 0; i < counterofpoints; i++)
                {
                    x_[i]      = x[i];
                    y_[i]      = y[i];
                    z_[i]      = z[i];
                    vx_[i]     = vx[i];
                    vy_[i]     = vy[i];
                    vz_[i]     = vz[i];
                    masses_[i] = masses[i];
                }
                matrixofdistances = matrixofdistances_;
                x      = x_;
                y      = y_;
                z      = z_;
                vx     = vx_;
                vy     = vy_;
                vz     = vz_;
                masses = masses_;
                CalculateDistances();
                startenergy = TotalPotentialEnergy() + TotalKineticEnergy() + mergeenergy;
                merge       = false;
                datastorage = datastorage_;

                FileStream fs = new FileStream(@"merge.txt", FileMode.Append, FileAccess.Write);
                string     s  = Convert.ToString(totaltime) + " " + "merge" + "\n";
                fs.Write(Encoding.Default.GetBytes(s), 0, s.Length);
                fs.Close();
            }
            if (fortran)
            {
                SphereStarCluster.intgr(ref counterofpoints, ref x[0], ref y[0], ref z[0], ref vx[0], ref vy[0], ref vz[0],
                                        ref masses[0], ref matrixofdistances[0, 0], ref iterations, ref datastorage[0], ref time[0], ref startenergy, ref merge, ref this.mergeenergy);
                MakeSystemStatic();
            }
            else
            {
                SphereStarCluster.cudaIntegrate(ref counterofpoints, x, y, z, vx, vy, vz, masses, iterations, datastorage, time, startenergy, ref merge, ref mergeenergy);
                CalculateDistances();
                MakeSystemStatic();
            }
            impulse_momentum = CalculateImpulseMomentum();
            totaltime       += time[time.Length - 1];
            int tempcount = evaporated.Count;

            Evaporation();
            if (tempcount != evaporated.Count)
            {
                FileStream fs = new FileStream(@"evaporation.txt", FileMode.Append, FileAccess.Write);
                string     s  = Convert.ToString(totaltime) + " " + Convert.ToString(counterofpoints - this.evaporated.Count) + "\n";
                fs.Write(Encoding.Default.GetBytes(s), 0, s.Length);
                fs.Close();
            }
            min_dst = MinimalDistance();
            if (GetVelocity(minimal_indexi) > GetVelocity(minimal_indexj))
            {
                max_velocity       = GetVelocity(minimal_indexi);
                max_velocity_index = minimal_indexi;
            }
            else
            {
                max_velocity       = GetVelocity(minimal_indexj);
                max_velocity_index = minimal_indexj;
            }
            if (boost)
            {
                vx[minimal_indexi] = -vx[minimal_indexi];
                vy[minimal_indexi] = -vy[minimal_indexi];
                vz[minimal_indexi] = -vz[minimal_indexi];
                boost = false;
            }
        }