2

I'm working in a FEA (Finite Element Analysis) procedure inside Rhino/Grasshopper using C#. I have lines(FDs) and mesh triangular faces (NFDs) as inputs, each one with their nodes coordinates. I'm trying to get these coordinates and resume them up at a list to index each node.

As lines and mesh faces can share the same nodes I did the following trying to avoid duplicate information:

public void NodeIndex()
    {
        List<Point3d> coord = new List<Point3d>();
        //Add all nodes
        foreach (NFD nfdens in nfd)
        {
            foreach (Node node in nfdens.nodes)
            {
                coord.Add(node.point);
            }
        }
        foreach (FD fdens in fd)
        {
            foreach (Node node in fdens.nodes)
            {
                coord.Add(node.point);
            }
        }

        //Remove Duplicates
        // 0.1 Stands for distance tolerance
        Point3d[] coordf = Point3d.CullDuplicates(coord, 0.1);
        coord = new List<Point3d>();
        foreach (Point3d pt in coordf)
        {
            coord.Add(pt);
        }

        //Set indexes
        int id = 0;
        foreach (Point3d pt in coordf)
        {
            nodes.Add(new Node(pt, id));
            id++;
        }
        foreach (NFD nfdens in nfd)
        {
            foreach (Node node in nfdens.nodes)
            {
                node.SetIndex(nodes);
            }
        }
        foreach (FD fdens in fd)
        {
            foreach (Node node in fdens.nodes)
            {
                node.SetIndex(nodes);
            }
        }
        foreach (Pload load in pointload)
        {
            load.node.SetIndex(nodes);
        }
        foreach (Supp sup in supports)
        {
            sup.node.SetIndex(nodes);
        }
    }

    public void SetIndex(List<Node> nodes)
    {
        foreach (Node node in nodes)
        {
            double dist = point.DistanceTo(node.point);
            if (dist < 0.1)
            {
                index = node.index;
            }
        }
    }

However, when I build the project I still receive duplicate information. Mesh faces duplicates are gone, but the code duplicates indexes for the lines. (For example, a 9 node problem gives me 13 nodes, sometimes 14 or 15. Looking at the meshes indexes everything is under 9, but in lines not [are between 9 and 13]).

How can I solve that?

Thanks,

Márcio

1 Answers1

1

If you have more nodes than expected then I would first check the output from Point3d.CullDuplicates to make sure it looks sensible. i.e. put a breakpoint in and inspect coordf

Also double check your input data to make sure that the line nodes are really coincident for your chosen tolerance.

In general your approach is going to be very slow for large point sets (1000s of nodes), so I would recommend a kd-tree or R-tree for this kind of thing. You could then use this for both the indexing and the duplicate culling. e.g. https://github.com/codeandcats/KdTree (not used this myself but it's the right sort of thing)

Tom Makin
  • 3,203
  • 23
  • 23