Exemple #1
0
        public void InitialisePlasticity(List <Particle> plst, float smoothing_radius, float k)
        {
            int   pindex1, pindex2;
            float distance, tempfloat;

            if (SpringArray.Springarray == null)
            {
                ResetSprings();
            }

            pindex1 = 0;
            foreach (Particle p in plst)
            {
                //if the particle is boundary move on to the next particle since we don't want moving particles to attach to the boundary
                if (p.Ismovingboundary || p.Isstationaryboundary)
                {
                    continue;
                }

                pindex2 = 0;
                foreach (Particle p2 in plst)
                {
                    //if the particle is a boundary move on to the next particle
                    if (p2.Ismovingboundary || p2.Isstationaryboundary)
                    {
                        continue;
                    }

                    Spring  spring = new Spring();
                    Vector2 vector_between_particle_neighbour = new Vector2();
                    vector_between_particle_neighbour.X = p2.Position.X - p.Position.X;
                    vector_between_particle_neighbour.Y = p2.Position.Y - p.Position.Y;
                    distance = vector_between_particle_neighbour.Length();

                    if (0 < distance && distance < smoothing_radius && !SpringArray.Springarray[pindex1, pindex2])
                    {
                        spring.Point1     = pindex1;
                        spring.Point2     = pindex2;
                        spring.Restlength = distance;
                        tempfloat         = rand.Next((int)(k * 10), (int)(k * 10 + 3));
                        if (p.Mass == 1 && p2.Mass == 1)
                        {
                            spring.Coefficient = tempfloat / 10;
                        }
                        else if (p.Mass == 0 && p2.Mass == 0)
                        {
                            spring.Coefficient = tempfloat / 20;
                        }
                        else
                        {
                            spring.Coefficient = k;
                        }
                        SpringArray.Springlst.Add(spring);
                        SpringArray.Springarray[pindex1, pindex2] = true;
                        SpringArray.Springarray[pindex2, pindex1] = true;
                    }
                    pindex2++;
                }
                pindex1++;
            }
        }
Exemple #2
0
        public void CalculateViscoElasticity(List <Particle> plst, float smoothing_radius, float k, float yield_ratio, float pconst, float dt)
        {
            int   pindex, sindex, sp1index, sp2index;
            float restlength, tolerable_def, distance_between_neighbour_particle, tempfloat;

            Vector2 sdisplacement;
            Vector2 temp;

            //create springs
            pindex = 0;
            foreach (Particle p in plst)
            {
                foreach (N_Particle n in p.Neighbourlist)
                {
                    N_Particle nparticle = new N_Particle();
                    Spring     spring    = new Spring();
                    nparticle = n;


                    if (!SpringArray.Springarray[pindex, nparticle.Particleindex])
                    {
                        SpringArray.Springarray[pindex, nparticle.Particleindex] = true;
                        spring.Point1      = pindex;
                        spring.Point2      = nparticle.Particleindex;
                        spring.Restlength  = smoothing_radius;
                        tempfloat          = rand.Next((int)(k * 10), (int)(k * 10 + 3));
                        spring.Coefficient = tempfloat / 10;
                        //spring.Coefficient = k;
                        SpringArray.Springlst.Add(spring);
                    }
                }


                pindex++;
            }

            //Alter the rest length of springs
            sindex = 0;
            foreach (Spring s in SpringArray.Springlst.ToList())
            {
                sp1index      = s.Point1;
                sp2index      = s.Point2;
                restlength    = s.Restlength;
                tolerable_def = yield_ratio * restlength;
                temp.X        = plst.ElementAt(sp2index).Position.X - plst.ElementAt(sp1index).Position.X;
                temp.Y        = plst.ElementAt(sp2index).Position.Y - plst.ElementAt(sp1index).Position.Y;
                distance_between_neighbour_particle = temp.Length();

                if (distance_between_neighbour_particle > (restlength + tolerable_def))
                {
                    s.Restlength += dt * dt_scalefactor * pconst * (distance_between_neighbour_particle - restlength - tolerable_def);
                }
                else if (distance_between_neighbour_particle < (restlength - tolerable_def))
                {
                    s.Restlength -= dt * dt_scalefactor * pconst * (restlength - tolerable_def - distance_between_neighbour_particle);
                }

                if (s.Restlength > smoothing_radius && sindex < plst.Count)
                {
                    SpringArray.Springarray[sindex, sindex] = false;
                    SpringArray.Springlst.RemoveAt(sindex);
                    sindex--;
                }
                sindex++;
            }

            //update position of particle due to spring forces
            sindex = 0;
            foreach (Spring s in SpringArray.Springlst)
            {
                Vector2 sforce = new Vector2(0, 0);
                sp1index   = s.Point1;
                sp2index   = s.Point2;
                restlength = s.Restlength;
                sforce     = s.CalculateForce(sforce, s, plst.ElementAt(sp1index), plst.ElementAt(sp2index));

                sdisplacement = sforce * (1.0f - restlength / smoothing_radius) * dt * dt_scalefactor * dt * dt_scalefactor;
                if (plst.ElementAt(sp1index).Ismovingboundary == false && plst.ElementAt(sp1index).Isstationaryboundary == false)
                {
                    plst.ElementAt(sp1index).Position -= sdisplacement;
                }
                if (plst.ElementAt(sp2index).Ismovingboundary == false && plst.ElementAt(sp2index).Isstationaryboundary == false)
                {
                    plst.ElementAt(sp2index).Position += sdisplacement;
                }

                sindex++;
            }
        }