public override bool Execute(ExecutionInfo exInfo = null) { TopChordElements = new LinearElementCollection(); BottomChordElements = new LinearElementCollection(); PostElements = new LinearElementCollection(); BracingElements = new LinearElementCollection(); if (TopChord != null && BottomChord != null) { int divisions; double maxLength = Math.Max(TopChord.Length, BottomChord.Length); if (NodeSpacing <= 0 || maxLength / NodeSpacing > 1000) { //Auto-determine appropriate node spacing Vector[] samplePointsT = TopChord.Divide(4); Vector[] samplePointsB = BottomChord.Divide(4); double tDist = 0; for (int i = 0; i < 5; i++) { tDist += samplePointsB[i].DistanceTo(samplePointsT[i]); } tDist /= 5; divisions = (int)(maxLength / tDist).Round(2); } else { divisions = (int)Math.Ceiling(maxLength / NodeSpacing); } if (divisions > 0) { Vector[] topPts = TopChord.Divide(divisions); Vector[] bottomPts = BottomChord.Divide(divisions); //foreach (Vector v in topPts) TopChordNodes.Add(Model.Create.Node(v, 0, exInfo)); //foreach (Vector v in bottomPts) BottomChordNodes.Add(Model.Create.Node(v, 0, exInfo)); for (int i = 0; i < topPts.Length - 1; i++) { //Node tNode0 = TopChordNodes[i]; //Node tNode1 = TopChordNodes[i + 1]; //Node bNode0 = BottomChordNodes[i]; //Node bNode1 = BottomChordNodes[i + 1]; Vector tNode0 = topPts[i]; Vector tNode1 = topPts[i + 1]; Vector bNode0 = bottomPts[i]; Vector bNode1 = bottomPts[i + 1]; TopChordElements.Add(Model.Create.LinearElement(tNode0, tNode1, ChordSection, exInfo)); BottomChordElements.Add(Model.Create.LinearElement(bNode0, bNode1, ChordSection, exInfo)); if (i > 0) { PostElements.Add(Model.Create.LinearElement(tNode0, bNode0, PostSection, exInfo)); } if (i < topPts.Length / 2) { BracingElements.Add(Model.Create.LinearElement(tNode0, bNode1, BracingSection, exInfo)); } else { BracingElements.Add(Model.Create.LinearElement(bNode0, tNode1, BracingSection, exInfo)); } } TopChordElements.GenerateNodes(new NodeGenerationParameters()); BottomChordElements.GenerateNodes(new NodeGenerationParameters()); PostElements.GenerateNodes(new NodeGenerationParameters()); BracingElements.GenerateNodes(new NodeGenerationParameters()); TopChordNodes = TopChordElements.GetNodes(); BottomChordNodes = BottomChordElements.GetNodes(); TopChordNodes.ClearAttachedData(); BottomChordNodes.ClearAttachedData(); } } return(true); }
public override bool Execute(ExecutionInfo exInfo = null) { var elements = new LinearElementCollection(); if (Struts != null) { elements.AddRange(Struts); } if (Ties != null) { elements.AddRange(Ties); } if (elements.Count > 0) { elements.ClearAttachedData(typeof(Spring)); var nodes = elements.GetNodes(); nodes.ClearAttachedData(typeof(Particle)); var motion = new KineticDampingComponent(nodes); //motion.SpeedLimit = SpeedLimit; var gravity = new ParticleGravityComponent(nodes); var springForces = new SpringForceComponent(elements); if (Struts != null) { foreach (var strut in Struts) { if (strut.HasData <Spring>()) { strut.GetData <Spring>().Compression = true; strut.GetData <Spring>().Tension = true; } } } //Set ties (temp): if (Ties != null) { foreach (var tie in Ties) { if (tie.HasData <Spring>()) { tie.GetData <Spring>().Compression = false; tie.GetData <Spring>().Tension = true; } } } var engine = new PhysicsEngine(); engine.Components.Add(gravity); engine.Components.Add(springForces); engine.Components.Add(motion); engine.Start(); for (int i = 0; i < Cycles; i++) { engine.Cycle(1.0); } // Outputs: StrutDeformation = new CurveCollection(); TieDeformation = new CurveCollection(); StrutForces = new List <double>(); TieForces = new List <double>(); if (Struts != null) { foreach (var lEl in Struts) { if (!lEl.IsDeleted) { StrutDeformation.Add( new Line( lEl.StartNode.GetData <Particle>().Position, lEl.EndNode.GetData <Particle>().Position)); StrutForces.Add( lEl.GetData <Spring>().AxialForce()); } } } if (Ties != null) { foreach (var lEl in Ties) { if (!lEl.IsDeleted) { TieDeformation.Add( new Line( lEl.StartNode.GetData <Particle>().Position, lEl.EndNode.GetData <Particle>().Position)); TieForces.Add( lEl.GetData <Spring>().AxialForce()); } } } } return(true); }