I'm trying to optimize structures by using FEM and genetic algorithms (GA), the FEM solver is a commercial one, and I'm programming the GA.
Something like this.
My first approach is simple, just erasing elements and computing the result, but I'm getting a lot of unfeasible solutions because some parts of the mesh become disconnected. How can I detect unconnected structures in my 2D mesh?
This calls for some graph theory. Begin by visiting an arbitrary vertex; add each vertex it's connected to (all the things around a face, or along edges, that include the vertex), to your itinerary. Then visit a node in your itinerary and add its neighbors, that you haven't visited, to the itinerary. When you've run out of itinerary, you've found a complete connected component. If that complete connected component doesn't cover the whole mesh, then the mesh is disconnected.
If instead you want the mesh to be fully edge-connected, use edges as the things you visit instead of vertices.