Пример #1
0
 public BHTree(Quad _quad)
 {
     quad      = _quad;
     body      = null;
     NorthWest = null;
     NorthEast = null;
     SouthWest = null;
     SouthEast = null;
 }
Пример #2
0
 public bool isExternal(BHTree _bstree)
 {
     if (_bstree.NorthWest == null && _bstree.NorthEast == null && _bstree.SouthWest == null && _bstree.SouthEast == null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
        private void run()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            startTheBodies(N);
            for (int i = 0; i < 10; i++)
            {
                tree = new BHTree(quad);
                startThreads(N);
            }
            stopwatch.Stop();

            //MessageBox.Show(stopwatch.ElapsedMilliseconds.ToString());
        }
Пример #4
0
        public void addForce(int N)
        {
            BHTree tree = new BHTree(quad);

            Parallel.For(0, N, i =>
            {
                if (bodies[i].isIn(quad))
                {
                    tree.insert(bodies[i]);
                }
            });
            Parallel.For(0, N, i =>
            {
                bodies[i].resetForce();
                if (bodies[i].isIn(quad))
                {
                    tree.updateForce(bodies[i]);
                    bodies[i].Update(1e11);
                }
            });
        }
Пример #5
0
        public void addForce(int N)
        {
            BHTree tree = new BHTree(quad);

            for (int i = 0; i < N; i++)
            {
                if (bodies[i].isIn(quad))
                {
                    tree.insert(bodies[i]);
                }
            }
            for (int i = 0; i < N; i++)
            {
                bodies[i].resetForce();
                if (bodies[i].isIn(quad))
                {
                    tree.updateForce(bodies[i]);
                    bodies[i].Update(1e11);
                }
            }
        }
Пример #6
0
        public void insert(Body _body)
        {
            try
            {
                if (body == null)
                {
                    body = _body;
                }

                else if (isExternal(this) == false)
                {
                    body = _body.addBody(body);

                    Quad nw = quad.NorthWest();
                    if (_body.isIn(nw))
                    {
                        if (NorthWest == null)
                        {
                            NorthWest = new BHTree(nw);
                        }
                        NorthWest.insert(_body);
                    }
                    else
                    {
                        Quad ne = quad.NorthEast();
                        if (_body.isIn(ne))
                        {
                            if (NorthEast == null)
                            {
                                NorthEast = new BHTree(ne);
                            }
                            NorthEast.insert(_body);
                        }

                        else
                        {
                            Quad sw = quad.SouthWest();
                            if (_body.isIn(sw))
                            {
                                if (SouthWest == null)
                                {
                                    SouthWest = new BHTree(sw);
                                }
                                SouthWest.insert(_body);
                            }

                            else
                            {
                                Quad se = quad.SouthEast();
                                if (_body.isIn(se))
                                {
                                    if (SouthEast == null)
                                    {
                                        SouthEast = new BHTree(se);
                                    }
                                    SouthEast.insert(_body);
                                }
                            }
                        }
                    }
                }

                else if (isExternal(this))
                {
                    Body _bodyC = body;
                    Quad nw     = quad.NorthWest();

                    if (_bodyC.isIn(nw))
                    {
                        if (NorthWest == null)
                        {
                            NorthWest = new BHTree(nw);
                        }
                        NorthWest.insert(_bodyC);
                    }
                    else
                    {
                        Quad ne = quad.NorthEast();
                        if (_bodyC.isIn(ne))
                        {
                            if (NorthEast == null)
                            {
                                NorthEast = new BHTree(ne);
                            }
                            NorthEast.insert(_bodyC);
                        }
                        else
                        {
                            Quad sw = quad.SouthWest();
                            if (_bodyC.isIn(sw))
                            {
                                if (SouthWest == null)
                                {
                                    SouthWest = new BHTree(sw);
                                }
                                SouthWest.insert(_bodyC);
                            }
                            else
                            {
                                Quad se = quad.SouthEast();
                                if (_bodyC.isIn(se))
                                {
                                    if (SouthEast == null)
                                    {
                                        SouthEast = new BHTree(se);
                                    }
                                    SouthEast.insert(_bodyC);
                                }
                            }
                        }
                    }
                    insert(_body);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }