| 2571 | } |
| 2572 | |
| 2573 | int |
| 2574 | Domain::buildNodeGraph(Graph *theNodeGraph) |
| 2575 | { |
| 2576 | int numVertex = this->getNumNodes(); |
| 2577 | |
| 2578 | if (numVertex == 0) { |
| 2579 | return 0; |
| 2580 | } |
| 2581 | |
| 2582 | Node *nodPtr; |
| 2583 | MAP_INT theNodeTagVertices; |
| 2584 | |
| 2585 | // now create the vertices with a reference equal to the node number. |
| 2586 | // and a tag which ranges from START_VERTEX_NUM through |
| 2587 | // numNodes+START_VERTEX_NUM |
| 2588 | |
| 2589 | NodeIter &nodeIter2 = this->getNodes(); |
| 2590 | int count = START_VERTEX_NUM; |
| 2591 | while ((nodPtr = nodeIter2()) != 0) { |
| 2592 | int nodeTag = nodPtr->getTag(); |
| 2593 | Vertex *vertexPtr = new Vertex(count,nodeTag); |
| 2594 | |
| 2595 | if (vertexPtr == 0) { |
| 2596 | opserr << "WARNING Domain::buildNodeGraph"; |
| 2597 | opserr << " - Not Enough Memory to create "; |
| 2598 | opserr << count << "th Vertex\n"; |
| 2599 | return -1; |
| 2600 | } |
| 2601 | |
| 2602 | // add the vertex to the graph |
| 2603 | theNodeGraph->addVertex(vertexPtr); |
| 2604 | theNodeTagVertices[nodeTag] = count++; |
| 2605 | } |
| 2606 | |
| 2607 | // now add the edges, by looping over the Elements, getting their |
| 2608 | // IDs and adding edges between all elements who share a node. |
| 2609 | |
| 2610 | Element *elePtr; |
| 2611 | ElementIter &eleIter = this->getElements(); |
| 2612 | |
| 2613 | while((elePtr = eleIter()) != 0) { |
| 2614 | const ID &id = elePtr->getExternalNodes(); |
| 2615 | |
| 2616 | int size = id.Size(); |
| 2617 | for (int i=0; i<size; i++) { |
| 2618 | int node1 = id(i); |
| 2619 | int vertexTag1 = theNodeTagVertices[node1]; |
| 2620 | |
| 2621 | for (int j=0; j<size; j++) |
| 2622 | if (i != j) { |
| 2623 | |
| 2624 | int node2 = id(j); |
| 2625 | int vertexTag2 = theNodeTagVertices[node2]; |
| 2626 | |
| 2627 | // addEdge() adds for both vertices - do only once |
| 2628 | if (vertexTag1 > vertexTag2) |
| 2629 | theNodeGraph->addEdge(vertexTag1,vertexTag2); |
| 2630 | } |
no test coverage detected