Example #1
0
        public ParticleSpring makeSpring(Particle a, Particle b, double restLength, double springConstant, double damping)
        {
            ParticleSpring s = new ParticleSpring(springID++, a, b, restLength, springConstant, damping);

            springs.Add(s);
            return(s);
        }
Example #2
0
        //public ParticleSpring makeOrUpdateSpring(int ID, Particle a, Particle b, double restLength, double springConstant, double damping)
        //{
        //    bool found = false;
        //    for (int i = 0; i < springs.Count(); ++i)
        //    {
        //        if (ID != null && (springs[i].ID() != null))
        //        {
        //            if (ID == springs[i].ID())
        //            {
        //                found = true;
        //                return springs[i];

        //            }
        //        }
        //    }
        //    if (found == false)
        //    {
        //        ParticleSpring s = new ParticleSpring(ID++, a, b, restLength, springConstant, damping);
        //        springs.Add(s);
        //        return s;
        //    }
        //    return null;
        //}

        public void applyForces()
        {
            maxResidualForce = -1000000000.0;
            maxNodalVelocity = -1000000000.0;

            for (int i = 0; i < particles.Count(); ++i)
            {
                //if (!isFaceConstrained)
                //{
                particles[i].addForce(gravity);
                //}

                particles[i].addForce(particles[i].getVelocity() * -drag);

                maxNodalVelocity = Math.Max(maxNodalVelocity, particles[i].getVelocity().GetLength());
            }

            //test whether we are converged according to the threshold criteria
            //make sure the simulation has a couple of steps computed so we don't
            //bail at time step 0 when the structure hasn't started moving yet.
            if (maxNodalVelocity < threshold && stepCount > 10)
            {
                converged = true;
            }

            //F=kd, calculate the maximum residual force in any member
            for (int i = 0; i < springs.Count(); i++)
            {
                ParticleSpring f = springs[i];
                f.apply();

                maxResidualForce = Math.Max(maxResidualForce, f.getResidualForce());
            }

            /*
             * if (isFaceConstrained && constraintFace != null)
             * {
             *  for (int i = 0; i < particles.Count(); ++i)
             *  {
             *      //get the component of force that is tangent
             *      //to the surface at the point
             *      IntersectionResult ir = constraintFace.Project(particles[i].getPosition());
             *      if (ir != null)
             *      {
             *          XYZ n = constraintFace.ComputeNormal(ir.UVPoint);
             *          n = n.Normalize();
             *          XYZ force = particles[i].getForce();
             *          //XYZ normalForce = new XYZ(force.X * n.X, force.Y * n.Y, force.Z * n.Z);
             *          double normalForce = force.DotProduct(n);
             *          //XYZ normalForce2 = new XYZ(normalForce.X * n.X, normalForce.Y * n.Y, normalForce.Z * n.Z);
             *          XYZ normalForce2 = normalForce * n;
             *          particles[i].clearForce();
             *          particles[i].addForce(force - normalForce2);
             *      }
             *  }
             * }
             */
        }
Example #3
0
        public void Draw()
        {
            if (this.RenderDescription == null)
            {
                this.RenderDescription = new Nodes.RenderDescription();
            }

            if (particleSystem == null)
            {
                return;
            }

            for (int i = 0; i < particleSystem.numberOfParticles(); i++)
            {
                Particle p   = particleSystem.getParticle(i);
                XYZ      pos = p.getPosition();
                if (i < this.RenderDescription.points.Count())
                {
                    this.RenderDescription.points[i] = new Point3D(pos.X, pos.Y, pos.Z);
                }
                else
                {
                    Point3D pt = new System.Windows.Media.Media3D.Point3D(pos.X, pos.Y, pos.Z);
                    this.RenderDescription.points.Add(pt);
                }
            }

            for (int i = 0; i < particleSystem.numberOfSprings(); i++)
            {
                ParticleSpring ps   = particleSystem.getSpring(i);
                XYZ            pos1 = ps.getOneEnd().getPosition();
                XYZ            pos2 = ps.getTheOtherEnd().getPosition();

                if (i * 2 + 1 < this.RenderDescription.lines.Count())
                {
                    this.RenderDescription.lines[i * 2]     = new Point3D(pos1.X, pos1.Y, pos1.Z);
                    this.RenderDescription.lines[i * 2 + 1] = new Point3D(pos2.X, pos2.Y, pos2.Z);
                }
                else
                {
                    Point3D pt1 = new System.Windows.Media.Media3D.Point3D(pos1.X, pos1.Y, pos1.Z);
                    Point3D pt2 = new System.Windows.Media.Media3D.Point3D(pos2.X, pos2.Y, pos2.Z);

                    this.RenderDescription.lines.Add(pt1);
                    this.RenderDescription.lines.Add(pt2);
                }
            }
        }
        public void Draw()
        {
            if (RenderDescription == null)
            {
                RenderDescription = new RenderDescription();
            }

            if (ParticleSystem == null)
            {
                return;
            }

            for (int i = 0; i < ParticleSystem.numberOfParticles(); i++)
            {
                Particle p   = ParticleSystem.getParticle(i);
                XYZ      pos = p.getPosition();
                if (i < RenderDescription.points.Count())
                {
                    RenderDescription.points[i] = new Point3D(pos.X, pos.Y, pos.Z);
                }
                else
                {
                    var pt = new Point3D(pos.X, pos.Y, pos.Z);
                    RenderDescription.points.Add(pt);
                }
            }

            for (int i = 0; i < ParticleSystem.numberOfSprings(); i++)
            {
                ParticleSpring ps   = ParticleSystem.getSpring(i);
                XYZ            pos1 = ps.getOneEnd().getPosition();
                XYZ            pos2 = ps.getTheOtherEnd().getPosition();

                if (i * 2 + 1 < RenderDescription.lines.Count())
                {
                    RenderDescription.lines[i * 2]     = new Point3D(pos1.X, pos1.Y, pos1.Z);
                    RenderDescription.lines[i * 2 + 1] = new Point3D(pos2.X, pos2.Y, pos2.Z);
                }
                else
                {
                    var pt1 = new Point3D(pos1.X, pos1.Y, pos1.Z);
                    var pt2 = new Point3D(pos2.X, pos2.Y, pos2.Z);

                    RenderDescription.lines.Add(pt1);
                    RenderDescription.lines.Add(pt2);
                }
            }
        }
Example #5
0
 private void UpdateSystem()
 {
     //update the spring values
     for (int j = 0; j < particleSystem.numberOfSprings(); j++)
     {
         ParticleSpring spring = particleSystem.getSpring(j);
         spring.setDamping(_d);
         if (!_use_rl)
         {
             spring.setRestLength(_r);
         }
         spring.setSpringConstant(_s);
     }
     for (int j = 0; j < particleSystem.numberOfParticles(); j++)
     {
         Particle p = particleSystem.getParticle(j);
         p.setMass(_m);
     }
 }
Example #6
0
        //public override void Evaluate(FSharpList<Value> args, Dictionary<PortData, Value> outPuts)
        //{
        //    _points = ((Value.List)args[0]).Item;//point list
        //    _curves = ((Value.List)args[1]).Item;//spring list
        //    _d = ((Value.Number)args[2]).Item;//dampening
        //    _s = ((Value.Number)args[3]).Item;//spring constant
        //    _r = ((Value.Number)args[4]).Item;//rest length
        //    _useRl = Convert.ToBoolean(((Value.Number)args[5]).Item);//use rest length
        //    _rlf = ((Value.Number)args[6]).Item;//rest length factor
        //    _m = ((Value.Number)args[7]).Item;//nodal mass
        //    _g = ((Value.Number)args[8]).Item;//gravity z component
        //    _threshold = ((Value.Number) args[9]).Item; //convergence threshold

        //    //if we are in the evaluate, this has been
        //    //marked dirty and we should set it to unconverged
        //    //in case one of the inputs has changed.
        //    ParticleSystem.setConverged(false);
        //    ParticleSystem.setGravity(_g);
        //    ParticleSystem.setThreshold(_threshold);

        //    //if the particle system has a different layout, then
        //    //clear it instead of updating
        //    if(ParticleSystem.numberOfParticles() == 0 ||
        //        _fixPtCount != _points.Count() ||
        //        _curves.Count() != ParticleSystem.numberOfSprings() ||
        //        _reset)
        //    {
        //        ResetSystem(_points, _curves);
        //    }
        //    else
        //    {
        //        UpdateSystem();
        //    }

        //    outPuts[_psPort] = Value.NewContainer(ParticleSystem);
        //    outPuts[_forcesPort] = Value.NewList(Utils.SequenceToFSharpList(
        //        ParticleSystem.Springs.Select(s => Value.NewNumber(s.getResidualForce()))));
        //}

        private void UpdateSystem()
        {
            //update the spring values
            for (int j = 0; j < ParticleSystem.numberOfSprings(); j++)
            {
                ParticleSpring spring = ParticleSystem.getSpring(j);
                spring.setDamping(d);
                if (!useRl)
                {
                    spring.setRestLength(r);
                }
                spring.setSpringConstant(s);
            }
            for (int j = 0; j < ParticleSystem.numberOfParticles(); j++)
            {
                Particle p = ParticleSystem.getParticle(j);
                p.setMass(m);
            }
        }
        public override Value Evaluate(FSharpList <Value> args)
        {
            var particleSystem = (ParticleSystem)((Value.Container)args[0]).Item;

            var result = FSharpList <Value> .Empty;

            //create a geometry curve from each spring
            for (int i = 0; i < particleSystem.numberOfSprings(); i++)
            {
                ParticleSpring s          = particleSystem.getSpring(i);
                Particle       springEnd1 = s.getOneEnd();
                Particle       springEnd2 = s.getTheOtherEnd();

                XYZ  springXYZ1 = springEnd1.getPosition();
                XYZ  springXYZ2 = springEnd2.getPosition();
                Line springLine = dynRevitSettings.Doc.Application.Application.Create.NewLineBound(springXYZ1, springXYZ2);

                result = FSharpList <Value> .Cons(Value.NewContainer(springLine), result);
            }

            return(Value.NewList(result));
        }
Example #8
0
        public ParticleSpring makeSpringFromElementID(ElementId eid, Particle a, Particle b, double restLength, double springConstant, double damping)
        {
            bool found = false;

            for (int i = 0; i < springs.Count(); ++i)
            {
                if (eid != null && (springs[i].getElementID() != null))
                {
                    if (eid == springs[i].getElementID())
                    {
                        found = true;
                        return(springs[i]);
                    }
                }
            }
            if (found == false)
            {
                ParticleSpring s = new ParticleSpring(springID++, eid, a, b, restLength, springConstant, damping);
                springs.Add(s);
                return(s);
            }
            return(null);
        }
Example #9
0
        public ParticleSpring makeSpringFromElementID(ElementId eid, Particle a, Particle b, double restLength, double springConstant, double damping)
        {
            bool found = false;
            for (int i = 0; i < springs.Count(); ++i)
            {
                if (eid != null && (springs[i].getElementID() != null))
                {
                    if (eid == springs[i].getElementID())
                    {
                        found = true;
                        return springs[i];

                    }
                }
            }
            if (found == false)
            {
                ParticleSpring s = new ParticleSpring(springID++, eid, a, b, restLength, springConstant, damping);
                springs.Add(s);
                return s;
            }
            return null;
        }
Example #10
0
 public ParticleSpring makeSpring(Particle a, Particle b, double restLength, double springConstant, double damping)
 {
     ParticleSpring s = new ParticleSpring(springID++, a, b, restLength, springConstant, damping);
     springs.Add(s);
     return s;
 }
Example #11
0
        public ParticleSpring makeOrUpdateSpring(int ID, Particle a, Particle b, double restLength, double springConstant, double damping)
        {
            bool found = false;
            for (int i = 0; i < springs.Count(); ++i)
            {
                if (ID != null && (springs[i].ID() != null))
                {
                    if (ID == springs[i].ID())
                    {
                        found = true;
                        return springs[i];

                    }
                }
            }
            if (found == false)
            {
                ParticleSpring s = new ParticleSpring(ID++, a, b, restLength, springConstant, damping);
                springs.Add(s);
                return s;
            }
            return null;
        }