protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA) { if (!FriedChiken.isInitialized) { Rhino.Geometry.Mesh m = null; if (!DA.GetData(0, ref m)) { return; } lGeometry = m.DuplicateMesh(); lGeometry2 = m.DuplicateMesh(); newNodes.Clear(); newNodes.AddRange(m.Vertices.ToPoint3dArray()); int nNewNodes = newNodes.Count; el = new List <int[]>(); for (int i = 0; i < m.Faces.Count; i++) { if (m.Faces[i].IsQuad) { int[] f = new int[4] { m.Faces[i].A, m.Faces[i].B, m.Faces[i].D, m.Faces[i].C }; el.Add(f); } if (m.Faces[i].IsTriangle) { int[] f = new int[3] { m.Faces[i].A, m.Faces[i].B, m.Faces[i].C }; el.Add(f); } } bool isJoin = false; mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes]; for (int i = 0; i < nNewNodes; i++) { particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]); } eM = new generalSpring(); pS = new GH_particleSystem(particles); if (!DA.GetData(3, ref isJoin)) { return; } if (isJoin) { pS.simplify(el); } lGeometry.Faces.Clear(); lGeometry2.Faces.Clear(); for (int i = 0; i < el.Count; i++) { if (el[i].Length == 4) { mikity.NumericalMethodHelper.elements.isoparametricElement e = new NumericalMethodHelper.elements.isoparametricElement(el[i]); eM.addElement(e); lGeometry.Faces.AddFace(e.el[0], e.el[1], e.el[3], e.el[2]); lGeometry2.Faces.AddFace(e.el[0], e.el[1], e.el[3], e.el[2]); } else if (el[i].Length == 3) { mikity.NumericalMethodHelper.elements.simplexElement e = new NumericalMethodHelper.elements.simplexElement(el[i]); eM.addElement(e); lGeometry.Faces.AddFace(e.el[0], e.el[1], e.el[2]); lGeometry2.Faces.AddFace(e.el[0], e.el[1], e.el[2]); } } pS.Value.addObject(eM); this.DVPW = GetDVPW(lGeometry); this.BKGT = GetBKGT(lGeometry); pS.DVPW = GetDVPW(lGeometry2); pS.UPGR = GetUPGR(lGeometry2); pS.BKGT = GetBKGT(lGeometry2); DA.SetData(0, pS); DA.SetDataList(1, newNodes); GH_material mat = null; GH_gravity gvt = null; if (!DA.GetData(1, ref mat)) { return; } if (!DA.GetData(2, ref gvt)) { return; } eM.setMaterial(mat.Value, gvt.Value); } }
protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA) { if (!FriedChiken.isInitialized) { GH_Point[] pointList = new GH_Point[4]; List <GH_Point> tmpPointList = new List <GH_Point>(); int[] nEdgeNodes = new int[_dim]; eM = new generalSpring(); DA.GetData(0, ref pointList[0]); DA.GetData(1, ref pointList[1]); DA.GetData(2, ref pointList[2]); DA.GetData(3, ref pointList[3]); DA.GetData(4, ref nEdgeNodes[0]); DA.GetData(5, ref nEdgeNodes[1]); GH_material mat = null; GH_gravity gvt = null; if (!DA.GetData(6, ref mat)) { return; } if (!DA.GetData(7, ref gvt)) { return; } for (int i = 0; i < _dim; i++) { if (nEdgeNodes[i] < 2) { AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2"); return; } } //点群生成 double[,] wt = mikity.MathUtil.bicubic(_dim, nEdgeNodes); int nNewNodes = wt.GetLength(0); mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes]; for (int i = 0; i < nNewNodes; i++) { particles[i] = new particle(0, 0, 0); for (int j = 0; j < _nNodes; j++) { particles[i][0] += pointList[j].Value.X * wt[i, j]; particles[i][1] += pointList[j].Value.Y * wt[i, j]; particles[i][2] += pointList[j].Value.Z * wt[i, j]; } } el = MathUtil.isoparametricElements(nEdgeNodes); int nElements = el.Length; pS = new GH_particleSystem(particles); bool isJoin = true; if (isJoin) { pS.simplify(el); } for (int i = 0; i < nElements; i++) { if (_subdv == subdivide.quad) { eM.addElement(new mikity.NumericalMethodHelper.elements.isoparametricElement(el[i])); } if (_subdv == subdivide.triA) { eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][0], el[i][1], el[i][3] })); eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][0], el[i][3], el[i][2] })); } if (_subdv == subdivide.triB) { int S = i % (nEdgeNodes[0] - 1); int T = (i - S) / (nEdgeNodes[0] - 1); if (T % 2 == 1) { S++; } if (S % 2 == 0) { eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][0], el[i][1], el[i][3] })); eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][0], el[i][3], el[i][2] })); } else { eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][0], el[i][1], el[i][2] })); eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][2], el[i][1], el[i][3] })); } } if (_subdv == subdivide.triC) { int S = i % (nEdgeNodes[0] - 1); if (S % 2 == 0) { eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][0], el[i][1], el[i][3] })); eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][0], el[i][3], el[i][2] })); } else { eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][0], el[i][1], el[i][2] })); eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] { el[i][2], el[i][1], el[i][3] })); } } } if (_subdv == subdivide.quad) { nElements *= 1; } else { nElements *= 2; } eM.setMaterial(mat.Value, gvt.Value); pS.Value.addObject(eM); lGeometry = new Rhino.Geometry.Mesh(); lGeometry2 = new Rhino.Geometry.Mesh(); lGeometry.Vertices.Clear(); lGeometry.Faces.Clear(); lGeometry2.Faces.Clear(); for (int i = 0; i < pS.Value.__N; i++) { lGeometry.Vertices.Add(particles[i][0], particles[i][1], particles[i][2]); } for (int i = 0; i < nElements; i++) { if (_subdv == subdivide.quad) { lGeometry.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[3], eM.elemList[i].el[2]); } else { lGeometry.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[2]); } } for (int i = 0; i < nElements; i++) { if (_subdv == subdivide.quad) { lGeometry2.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[3], eM.elemList[i].el[2]); } else { lGeometry2.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[2]); } } this.DVPW = GetDVPW(lGeometry); pS.DVPW = GetDVPW(lGeometry2); pS.UPGR = GetUPGR(lGeometry2); pS.BKGT = GetBKGT(lGeometry2); } DA.SetData(0, pS); }
protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA) { if (!FriedChiken.isInitialized) { Rhino.Geometry.Mesh m = null; if (!DA.GetData(0, ref m)) { return; } lGeometry.Clear(); lGeometry2.Clear(); var ms = mikity.GeometryProcessing.MeshStructure.CreateFrom(m); var edges = ms.edges(); var boundary = new Rhino.Geometry.Polyline(); newNodes.Clear(); newNodes.AddRange(m.Vertices.ToPoint3dArray()); int nNewNodes = newNodes.Count; el = new List <int[]>(); foreach (var e in edges) { if (!e.isNaked) { el.Add(new int[2] { e.P.N, e.next.P.N }); } } var s = ms.boundaryStart.hf_begin; do { var P = m.Vertices[s.P.N]; boundary.Add(new Rhino.Geometry.Point3d(P.X, P.Y, P.Z)); s = s.next.P.hf_begin; } while (s.P != ms.boundaryStart); boundary.Add(new Rhino.Geometry.Point3d(boundary[0])); var boundary2 = new Rhino.Geometry.PolylineCurve(boundary); bool isJoin = false; mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes]; for (int i = 0; i < nNewNodes; i++) { particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]); } eM = new generalSpring(); pS = new GH_particleSystem(particles); if (!DA.GetData(3, ref isJoin)) { return; } if (isJoin) { pS.simplify(el); } foreach (var e in el) { var ee = new mikity.NumericalMethodHelper.elements.simplexElement(e); eM.addElement(ee); lGeometry.Add(new Rhino.Geometry.Line(pS.Value.particles[e[0], 0], pS.Value.particles[e[0], 1], pS.Value.particles[e[0], 2], pS.Value.particles[e[1], 0], pS.Value.particles[e[1], 1], pS.Value.particles[e[1], 2])); } pS.Value.addObject(eM); this.DVPW = GetDVPW(lGeometry); this.BKGT = GetBKGT(lGeometry); pS.DVPW = GetDVPW(lGeometry2); pS.UPGR = GetUPGR(lGeometry2); pS.BKGT = GetBKGT(lGeometry2); DA.SetData(0, pS); DA.SetDataList(1, newNodes); DA.SetData(2, boundary); GH_material mat = null; GH_gravity gvt = null; if (!DA.GetData(1, ref mat)) { return; } if (!DA.GetData(2, ref gvt)) { return; } eM.setMaterial(mat.Value, gvt.Value); } }