| 2885 | } |
| 2886 | |
| 2887 | int |
| 2888 | Domain::buildNodeGraph(Graph *theNodeGraph) |
| 2889 | { |
| 2890 | int numVertex = this->getNumNodes(); |
| 2891 | |
| 2892 | if (numVertex == 0) { |
| 2893 | return 0; |
| 2894 | } |
| 2895 | |
| 2896 | Node *nodPtr; |
| 2897 | MAP_INT theNodeTagVertices; |
| 2898 | |
| 2899 | // now create the vertices with a reference equal to the node number. |
| 2900 | // and a tag which ranges from START_VERTEX_NUM through |
| 2901 | // numNodes+START_VERTEX_NUM |
| 2902 | |
| 2903 | NodeIter &nodeIter2 = this->getNodes(); |
| 2904 | int count = START_VERTEX_NUM; |
| 2905 | while ((nodPtr = nodeIter2()) != 0) { |
| 2906 | int nodeTag = nodPtr->getTag(); |
| 2907 | Vertex *vertexPtr = new Vertex(count,nodeTag); |
| 2908 | |
| 2909 | if (vertexPtr == 0) { |
| 2910 | opserr << "WARNING Domain::buildNodeGraph"; |
| 2911 | opserr << " - Not Enough Memory to create "; |
| 2912 | opserr << count << "th Vertex\n"; |
| 2913 | return -1; |
| 2914 | } |
| 2915 | |
| 2916 | // add the vertex to the graph |
| 2917 | theNodeGraph->addVertex(vertexPtr); |
| 2918 | theNodeTagVertices[nodeTag] = count++; |
| 2919 | } |
| 2920 | |
| 2921 | // now add the edges, by looping over the Elements, getting their |
| 2922 | // IDs and adding edges between all elements who share a node. |
| 2923 | |
| 2924 | Element *elePtr; |
| 2925 | ElementIter &eleIter = this->getElements(); |
| 2926 | |
| 2927 | while((elePtr = eleIter()) != 0) { |
| 2928 | const ID &id = elePtr->getExternalNodes(); |
| 2929 | |
| 2930 | int size = id.Size(); |
| 2931 | for (int i=0; i<size; i++) { |
| 2932 | int node1 = id(i); |
| 2933 | int vertexTag1 = theNodeTagVertices[node1]; |
| 2934 | |
| 2935 | for (int j=0; j<size; j++) |
| 2936 | if (i != j) { |
| 2937 | |
| 2938 | int node2 = id(j); |
| 2939 | int vertexTag2 = theNodeTagVertices[node2]; |
| 2940 | |
| 2941 | // addEdge() adds for both vertices - do only once |
| 2942 | if (vertexTag1 > vertexTag2) |
| 2943 | theNodeGraph->addEdge(vertexTag1,vertexTag2); |
| 2944 | } |
no test coverage detected