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