public static NodalStructureInfo  MergeDuplicate(NodalStructureInfo infoA, NodalStructureInfo infoB)
        {
            NodalStructureInfo mergedInfo = new NodalStructureInfo(infoA.NodeNum,
                                                                   (infoA.StressTen + infoB.StressTen) / 2,
                                                                   (infoA.StressCom + infoB.StressCom) / 2,
                                                                   (infoA.Nx + infoB.Nx) / 2,
                                                                   (infoA.Ny + infoB.Ny) / 2
                                                                   );

            return(mergedInfo);
        }
Exemple #2
0
        static public List <NodalStructureInfo> CheckDuplicate(List <NodalStructureInfo> nodalInfo)
        {
            List <NodalStructureInfo> CondensedNodalStructureInfo = new List <NodalStructureInfo>();

            for (int i = 0; i < nodalInfo.Count; i++)
            {
                if ((i + 1 < nodalInfo.Count) && (nodalInfo[i].NodeNum == nodalInfo[i + 1].NodeNum))
                {
                    NodalStructureInfo mergedNodalIndo = NodalStructureInfo.MergeDuplicate(nodalInfo[i], nodalInfo[i + 1]);
                    CondensedNodalStructureInfo.Add(mergedNodalIndo);
                    i += 1;
                }

                else
                {
                    CondensedNodalStructureInfo.Add(nodalInfo[i]);
                }
            }
            return(CondensedNodalStructureInfo);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <double> node  = new List <double>();
            List <double> nodeX = new List <double>();
            List <double> nodeY = new List <double>();
            List <double> nodeZ = new List <double>();

            List <double> nodeNum     = new List <double>();
            List <double> stressesTen = new List <double>();
            List <double> stressesCom = new List <double>();
            List <double> nx          = new List <double>();
            List <double> ny          = new List <double>();

            List <Fiber> Fibers = new List <Fiber>();

            Surface Srf4Nodes = null;

            DA.GetDataList("X", nodeX);
            DA.GetDataList("Y", nodeY);
            DA.GetDataList("Z", nodeZ);
            DA.GetDataList("Node", node);           // small

            DA.GetDataList("Node Number", nodeNum); // big (duplicate)
            DA.GetDataList("Nodal Tension Stress", stressesTen);
            DA.GetDataList("Nodal Compression Stress", stressesCom);
            DA.GetDataList("Nodal Force Nx", nx);
            DA.GetDataList("Nodal Force Ny", ny);

            DA.GetDataList("Custom Fibers", Fibers);
            DA.GetData("Surface", ref Srf4Nodes);

            // SoFiNode: structure info assambly
            List <SoFiNode> SoFiNodesOnSrf = new List <SoFiNode>();

            for (int i = 0; i < nodeX.Count; i++)
            {
                SoFiNode inode = new SoFiNode(node[i], nodeX[i], nodeY[i], nodeZ[i]);
                double   u;
                double   v;
                Srf4Nodes.ClosestPoint(inode.Node, out u, out v);
                Point3d closestPt = Srf4Nodes.PointAt(u, v);

                if (closestPt.DistanceTo(inode.Node) < 0.01)  // on surface
                {
                    SoFiNodesOnSrf.Add(inode);
                }
            }
            // so far the sofiNodes have no structure info

            // ====================== structure info big list ===================================
            // node number, compression stress, tension stress, force in  local x, force in local y

            List <NodalStructureInfo> NodalStructureInfo = new List <NodalStructureInfo>();

            for (int i = 0; i < nodeNum.Count; i++)
            {
                NodalStructureInfo inodal = new NodalStructureInfo(nodeNum[i], stressesTen[i], stressesCom[i], nx[i], ny[i]);
                NodalStructureInfo.Add(inodal);
            }
            // ==================================================================================

            // abandom the nodes not on the srf
            // list.RemoveAll(item => !list2.Contains(item))
            List <double> nodeNumOnSrf = SoFiNodesOnSrf.Select(o => o.NodeNum).ToList();

            NodalStructureInfo.RemoveAll(o => !nodeNumOnSrf.Contains(o.NodeNum)); // remove structure info not on srf
            List <NodalStructureInfo> CondensedNodalStructureInfo = new List <RP1516.NodalStructureInfo>();

            for (int i = 0; i < SoFiNodesOnSrf.Count; i++)
            {
                double iNodeNumber = SoFiNodesOnSrf[i].NodeNum;
                List <NodalStructureInfo> iNodalinfo = NodalStructureInfo.Where(o => o.NodeNum == iNodeNumber).ToList();
                double iNodeCount = iNodalinfo.Count();

                // Com
                double iComStress = iNodalinfo
                                    .Select(o => o.StressCom).ToList().Sum()
                                    / iNodeCount;

                // Ten
                double iTenStress = iNodalinfo
                                    .Select(o => o.StressTen).ToList().Sum()
                                    / iNodeCount;

                // NX
                double iNX = iNodalinfo
                             .Select(o => o.Nx).ToList().Sum()
                             / iNodeCount;

                // NY
                double iNY = iNodalinfo
                             .Select(o => o.Ny).ToList().Sum()
                             / iNodeCount;

                NodalStructureInfo.Except(iNodalinfo);

                SoFiNodesOnSrf[i].StressCom = iComStress;
                SoFiNodesOnSrf[i].StressTen = iTenStress;
                SoFiNodesOnSrf[i].Nx        = iNX;
                SoFiNodesOnSrf[i].Ny        = iNY;
            }
            //List<NodalStructureInfo> CondensedNodalStructureInfo = Utils.CheckDuplicate(NodalStructureInfo);

            // SoFiNode.InfoRead(SoFiNodesOnSrf, CondensedNodalStructureInfo);

            // calculate structure significance
            Fibers.ForEach(o => o.StrutureValue(SoFiNodesOnSrf));

            List <Fiber> CriticleFibers = Fibers
                                          .OrderByDescending(o => o.StructureFactor)
                                          //.Take((int)(Fibers.Count * 0.2))
                                          .ToList();

            // Output
            DA.SetDataList("SoFiNodes", SoFiNodesOnSrf);
            DA.SetDataList("Node Positions", SoFiNodesOnSrf.Select(o => o.Node).ToList());
            DA.SetDataList("Node Number", SoFiNodesOnSrf.Select(o => o.NodeNum).ToList());
            DA.SetDataList("Info Number", CondensedNodalStructureInfo.Select(o => o.NodeNum).ToList());
            DA.SetDataList("Criticle Fibers", CriticleFibers.Select(o => o.FiberCrv).ToList());
            DA.SetDataList("Value", SoFiNodesOnSrf.Select(o => o.StressCom).ToList());
        }