Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <iostream>
00008 #include <fstream>
00009 #include <stdio.h>
00010 #include <string>
00011 #include <sstream>
00012
00013 #include <boost/config.hpp>
00014 #include <boost/graph/graph_traits.hpp>
00015 #include <boost/graph/adjacency_list.hpp>
00016 #include <boost/graph/dijkstra_shortest_paths.hpp>
00017 #include <boost/lexical_cast.hpp>
00018 #include <boost/numeric/conversion/cast.hpp>
00019
00020 #include "topology/Topology.h"
00021
00022 using namespace boost;
00023
00024 int main(int ac, char* av[]){
00025
00026 typedef adjacency_list < listS, vecS, undirectedS,no_property, property < edge_weight_t, int > > graph_t;
00027 typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
00028 typedef stk::mesh::Entity Entity;
00029 typedef std::pair<int, int> Edge;
00030
00031
00032
00033
00034
00035 Teuchos::CommandLineProcessor command_line_processor;
00036
00037 command_line_processor.setDocString("Test of barycentric subdivision.\n"
00038 "Reads in a mesh and applies the barycentric subdivision algorithm.\n"
00039 "Restricted to simplicial complexes.\n");
00040
00041 std::string input_file = "input.e";
00042 command_line_processor.setOption("input", &input_file, "Input File Name");
00043
00044 std::string output_file = "output.e";
00045 command_line_processor.setOption("output", &output_file, "Output File Name");
00046
00047
00048 command_line_processor.recogniseAllOptions(true);
00049
00050
00051 command_line_processor.throwExceptions(false);
00052
00053
00054 Teuchos::CommandLineProcessor::EParseCommandLineReturn parse_return =
00055 command_line_processor.parse(ac, av);
00056
00057 if (parse_return == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) {
00058 return 0;
00059 }
00060
00061 if (parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00062 return 1;
00063 }
00064
00065
00066
00067
00068
00069 Teuchos::GlobalMPISession mpiSession(&ac, &av);
00070 LCM::Topology topology(input_file, output_file);
00071
00072
00073
00074
00075
00076 stk::mesh::BulkData* bulkData_ = topology.getBulkData();
00077 std::vector<Entity*> MeshNodes = topology.getEntitiesByRank(
00078 *(bulkData_), 0);
00079
00080
00081
00082 const int TotalNumberNodes = MeshNodes.size();
00083 std::vector<int> _nodeNames = topology.nodeNames();
00084
00085
00086 std::vector<Entity*> MeshEdges = topology.getEntitiesByRank(
00087 *(bulkData_), 1);
00088
00089
00090 const int ArraySize = MeshEdges.size();
00091 Edge* EdgesArray;
00092 EdgesArray = new Edge[ArraySize];
00093
00094
00095 double* EdgesWeights;
00096 EdgesWeights = new double[ArraySize];
00097
00098 for (unsigned int i = 0; i < MeshEdges.size();++i){
00099
00100 std::vector<Entity*> EdgeBoundaryNodes(2);
00101 EdgeBoundaryNodes = topology.getDirectlyConnectedEntities((*MeshEdges[i]),0);
00102 EdgesArray[i] = Edge((EdgeBoundaryNodes[0]->identifier())-1,
00103 (EdgeBoundaryNodes[1]->identifier())-1);
00104
00105 EdgesWeights[i] = (topology.getDistanceBetweenNodes(
00106 EdgeBoundaryNodes[0],EdgeBoundaryNodes[1]));
00107 }
00108
00109
00110
00111 graph_t Graph(EdgesArray, EdgesArray + ArraySize, EdgesWeights, TotalNumberNodes);
00112
00113 std::vector<vertex_descriptor> predecessor(num_vertices(Graph));
00114 std::vector<int> dis(num_vertices(Graph));
00115 vertex_descriptor source = vertex(3, Graph);
00116 dijkstra_shortest_paths(Graph, source, predecessor_map(&predecessor[0]).distance_map(&dis[0]));
00117
00118 delete [] EdgesArray;
00119 delete [] EdgesWeights;
00120
00121
00122
00123
00124
00125 std::cout << "Display distances to all graph vertices from source" << std::endl;
00126 graph_traits < graph_t >::vertex_iterator VertexIterator, vend;
00127 for (boost::tie(VertexIterator, vend) = vertices(Graph); VertexIterator != vend; ++VertexIterator) {
00128 std::cout << "distance(" << _nodeNames[*VertexIterator] << ") = " << dis[*VertexIterator] << std::endl;
00129 }
00130 std::cout << std::endl;
00131
00132 std::vector< graph_traits< graph_t >::vertex_descriptor > ShortestPath;
00133
00134
00135 vertex_descriptor sourceVertex = vertex(3,Graph);
00136 vertex_descriptor goalVertex = vertex(4, Graph);
00137
00138
00139 graph_traits< graph_t >::vertex_descriptor currentVertex=goalVertex;
00140 while(currentVertex!=sourceVertex) { ShortestPath.push_back(currentVertex);
00141 currentVertex=predecessor[currentVertex];
00142 }
00143
00144
00145 ShortestPath.push_back(sourceVertex);
00146
00147
00148 std::vector<int> FV;
00149 std::vector<unsigned long int>::const_iterator I_points;
00150 for (I_points = ShortestPath.begin();I_points != ShortestPath.end();++I_points){
00151 int i =boost::numeric_cast<int>(*I_points);
00152 FV.push_back(i);
00153 }
00154
00155
00156 std::vector< graph_traits< graph_t >::vertex_descriptor >::iterator Iterator_;
00157 std::cout << "From end node to start node"<< std::endl;
00158 for (Iterator_=ShortestPath.begin(); Iterator_ != ShortestPath.end(); ++Iterator_) {
00159 std::cout << _nodeNames[*Iterator_] << " ";}
00160 std::cout << std::endl;
00161
00162
00163 return 0;
00164 }