public static Line ToLine(this SharpSLO.Types.Molecular molecular, int barIndex) { var pt1 = molecular.Nodes[molecular.Bars[barIndex].Start]; var pt2 = molecular.Nodes[molecular.Bars[barIndex].End]; return(new Line(new Point3d(pt1.X, pt1.Y, pt1.Z), new Point3d(pt2.X, pt2.Y, pt2.Z))); }
public static BoundingBox GetBoundingBox(this SharpSLO.Types.Molecular molecular) { if (!molecular.IsValid) { return(BoundingBox.Empty); } BoundingBox result = new BoundingBox(molecular.ToPoint3dArray()); result.MakeValid(); return(result); }
public static Line[] ToLineArray(this SharpSLO.Types.Molecular molecular) { Line[] lines = new Line[molecular.Bars.Count]; for (int i = 0; i < lines.Length; i++) { var pt1 = molecular.Nodes[molecular.Bars[i].Start]; var pt2 = molecular.Nodes[molecular.Bars[i].End]; lines[i] = new Line(new Point3d(pt1.X, pt1.Y, pt1.Z), new Point3d(pt2.X, pt2.Y, pt2.Z)); } return(lines); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Mesh mesh = null; double max_distance = Rhino.RhinoMath.UnsetValue; if (!DA.GetData <Mesh>(0, ref mesh)) { return; } if (!DA.GetData <double>(1, ref max_distance)) { return; } int n = mesh.Vertices.Count; var molecular = new Molecular(n); var points = mesh.Vertices.Select(v => (Point3d)v.Position); foreach (var pt in points) { molecular.Add(pt.X, pt.Y, pt.Z); } var node3List = new Node3List(points); Node3Tree node3Tree = node3List.CreateTree(0.0, false, 10); if (node3Tree == null) { return; } int max_results = n - 1; double min_distance = 0; for (int i = 0; i < n; i++) { Node3Proximity node3Proximity = new Node3Proximity(node3List[i], i, max_results, min_distance, max_distance); node3Tree.SolveProximity(node3Proximity); foreach (var j in node3Proximity.IndexList) { molecular.Add(i, j); } } DA.SetData(0, molecular); DA.SetDataList(1, points); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Collect inputs SharpSLO.Types.Molecular molecular = null; bool filter = true; if (!DA.GetData(0, ref molecular)) { m_lines = null; m_colours = null; m_thicknesses = null; this.ExpirePreview(true); return; } DA.GetData <bool>(1, ref filter); // Filter out unstressed bars IEnumerable <int> subset; if (filter) { subset = molecular.Bars.Select((bar, index) => new { Bar = bar, Index = index }) .Where(b => Math.Abs(b.Bar.Stress) > 1E-6) .Select(b => b.Index); } else { subset = Enumerable.Range(0, molecular.Bars.Count); } m_lines = subset.Select(i => molecular.ToLine(i)).ToArray(); m_colours = subset.Select(i => molecular.Bars[i].Colour).ToArray(); m_thicknesses = subset.Select(i => (int)Math.Floor(Math.Abs(molecular.Bars[i].Stress * 5)) + 1).ToArray(); DA.SetDataList(0, m_lines); DA.SetDataList(1, m_colours); DA.SetDataList(2, subset.Select(i => Math.Abs(molecular.Bars[i].Stress * 5)).ToArray()); DA.SetDataList(3, molecular.Nodes.Select(n => (n.Displacement ?? new SharpSLO.Geometry.Vector()).ToVector3d())); }
public static SharpSLO.Types.Molecular ToMolecular(this Buckminster.Types.Mesh mesh) { var molecular = new SharpSLO.Types.Molecular(mesh.Vertices.Count); foreach (var vertex in mesh.Vertices.Select(v => v.Position)) { molecular.Add(vertex.X, vertex.Y, vertex.Z); } Dictionary <string, int> vlookup = new Dictionary <string, int>(); for (int i = 0; i < mesh.Vertices.Count; i++) { vlookup.Add(mesh.Vertices[i].Name, i); } foreach (var edge in mesh.Halfedges.GetUnique()) { molecular.Add(vlookup[edge.Vertex.Name], vlookup[edge.Prev.Vertex.Name]); } return(molecular); }
public static Point3d[] ToPoint3dArray(this SharpSLO.Types.Molecular molecular) { return(molecular.Nodes.Select(n => new Point3d(n.X, n.Y, n.Z)).ToArray()); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Collect inputs SharpSLO.Types.Molecular molecular = null; SharpSLO.Types.Molecular pcl = null; List <Vector3d> fixities = new List <Vector3d>(); List <Vector3d> forces = new List <Vector3d>(); double limitT, limitC, jCost; limitT = limitC = jCost = double.NaN; bool reset = true; if (!DA.GetData(0, ref molecular)) { return; } DA.GetData(1, ref pcl); // Optional if (!DA.GetDataList <Vector3d>(2, fixities)) { return; } if (!DA.GetDataList <Vector3d>(3, forces)) { return; } if (!DA.GetData <double>(4, ref limitT)) { return; } if (!DA.GetData <double>(5, ref limitC)) { return; } if (!DA.GetData <double>(6, ref jCost)) { return; } if (!DA.GetData <bool>(7, ref reset)) { return; } if (reset || m_triggerReset) // Rebuild model from external source { var copy = molecular.Duplicate(); // Add boundary conditions for (int i = 0; i < molecular.Nodes.Count; i++) { copy.Nodes[i].Fixity = new SharpSLO.Geometry.Vector(fixities[i].X, fixities[i].Y, fixities[i].Z); copy.Nodes[i].Force = new SharpSLO.Geometry.Vector(forces[i].X, forces[i].Y, forces[i].Z); } if (pcl == null) { m_optimiser = new SharpSLO.Optimiser(copy, m_solType); } else { var potentials = pcl.Bars.Select(b => new Tuple <int, int>(b.Start, b.End)).ToArray(); m_optimiser = new SharpSLO.Optimiser(copy, potentials, m_solType); } m_optimiser.TensileStressLimit = limitT; m_optimiser.CompressiveStressLimit = limitC; m_optimiser.JointCost = jCost; if (m_output.Count > 0) { m_output.Clear(); } m_runtime = 0.0; m_triggerReset = false; } // solve int members_added = m_optimiser.SolveStep(); if (members_added < 0) { return; } if (members_added == 0) { this.StopTimer(); // Disable timer if solution converges } m_output.Add(string.Format("{0,3:D}: vol.: {1,9:F6} add. :{2,4:D} ({3,2:F3}s)", m_output.Count, m_optimiser.Volume, members_added, m_optimiser.Runtime)); m_runtime += m_optimiser.Runtime; // set outputs DA.SetDataList(0, m_output); DA.SetData(1, m_optimiser.Volume); DA.SetData(2, m_optimiser.GroundStructure); }